Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-2941

Let jdbc be more robust against broken data sources

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.0, 3.0.2, 2.3.6, 4.0.0.M3
    • Component/s: karaf-shell
    • Labels:
      None

      Description

      Currently if you call jdbc:datasources with a broken datasource it will output nothing useful.

      It should be more robust. To make it easy I have a patch for you (version 3.0.1). Have a look at it:

      diff --git a/jdbc/command/src/main/java/org/apache/karaf/jdbc/command/DataSourcesCommand.java b/jdbc/command/src/main/java/org/apache/karaf/jdbc/command/DataSourcesCommand.java
      index 36df691..dd3a599 100644
      — a/jdbc/command/src/main/java/org/apache/karaf/jdbc/command/DataSourcesCommand.java
      +++ b/jdbc/command/src/main/java/org/apache/karaf/jdbc/command/DataSourcesCommand.java
      @@ -21,10 +21,14 @@

      import java.util.List;
      import java.util.Map;
      +import java.util.logging.Level;
      +import java.util.logging.Logger;

      @Command(scope = "jdbc", name = "datasources", description = "List the JDBC datasources")
      public class DataSourcesCommand extends JdbcCommandSupport {

      + Logger LOG = Logger.getLogger(DataSourcesCommand.class.getName());
      +
      public Object doExecute() throws Exception {
      ShellTable table = new ShellTable();

      @@ -35,8 +39,14 @@

      List<String> datasources = this.getJdbcService().datasources();
      for (String datasource : datasources) {

      • Map<String, String> info = this.getJdbcService().info(datasource);
      • table.addRow().addContent(datasource, info.get("db.product"), info.get("db.version"), info.get("url"));
        + try { + Map<String, String> info = this.getJdbcService().info(datasource); + table.addRow().addContent(datasource, info.get("db.product"), info.get("db.version"), info.get("url")); + }

        catch (Throwable t)

        { + LOG.log(Level.WARNING,"Working on datasource: " + datasource,t); + table.addRow().addContent(datasource, "error", "", t.getMessage()); + + }

        }

      table.print(System.out);

        Activity

        Show
        jbonofre Jean-Baptiste Onofré added a comment - Fixed on karaf-2.3.x: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=70159256601ca4d623ca69a49c701eb1580ef7e8
        Show
        jbonofre Jean-Baptiste Onofré added a comment - Fixed on karaf-2.x: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=857d0735dd8c9a625ff9196e51291af0aae13d00
        Show
        jbonofre Jean-Baptiste Onofré added a comment - Fixed on karaf-3.0.x: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=40c804f296acf8a6f796aa043ea06c05e03b2015
        Show
        jbonofre Jean-Baptiste Onofré added a comment - Fixed on master: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=13158bdbf898193f9be05338339f67b829992a8f
        Hide
        jbonofre Jean-Baptiste Onofré added a comment -

        I will do the following fix:

        • add a status column to display the current datasource status (OK, error)
        • add a log message in the JDBC service on the info() method
        • do the same in the JdbcMBean
        Show
        jbonofre Jean-Baptiste Onofré added a comment - I will do the following fix: add a status column to display the current datasource status (OK, error) add a log message in the JDBC service on the info() method do the same in the JdbcMBean

          People

          • Assignee:
            jbonofre Jean-Baptiste Onofré
            Reporter:
            mhu Mike Hummel
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development