public void execute() throws BuildException {
   Connection conn = null;
   Statement stmt = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     stmt = conn.createStatement();
     MeasRangeObj ranges = MeasRangeObj.getInstance();
     log(SCHEMA_MOD_IN_PROGRESS);
     for (Iterator i = ranges.getRanges().iterator(); i.hasNext(); ) {
       MeasRange range = (MeasRange) i.next();
       long max = range.getMaxTimestamp(), min = range.getMinTimestamp();
       String table = range.getTable();
       String sql =
           "INSERT into "
               + table
               + " (measurement_id, timestamp, value)"
               + " SELECT measurement_id, timestamp, value"
               + " FROM "
               + TAB_COMPAT
               + " WHERE timestamp BETWEEN "
               + min
               + " AND "
               + max;
       int rows = stmt.executeUpdate(sql);
       log(
           "Moved "
               + rows
               + " rows from "
               + TAB_COMPAT
               + " to "
               + table
               + " min -> "
               + TimeUtil.toString(min)
               + " ("
               + min
               + ")"
               + " max -> "
               + TimeUtil.toString(max)
               + " ("
               + max
               + ")");
     }
     stmt.execute("TRUNCATE TABLE " + TAB_COMPAT);
   } catch (SQLException e) {
     throw new BuildException(logCtx + ": " + e.getMessage(), e);
   } finally {
     DBUtil.closeJDBCObjects(logCtx, null, stmt, rs);
   }
 }
Exemplo n.º 2
0
  // Discover Oracle services
  @Override
  protected List discoverServices(ConfigResponse config) throws PluginException {
    // HHQ-3577 allow listener names in tnsnames.ora to be used in the url
    String tnsDir =
        getTnsNamesDir(
            config.getValue(ProductPlugin.PROP_INSTALLPATH), config.getValue(PROP_TNSNAMES));
    if (log.isDebugEnabled()) log.debug("using tns dir as " + tnsDir);
    System.setProperty("oracle.net.tns_admin", tnsDir);

    String url = config.getValue(OracleMeasurementPlugin.PROP_URL);
    if (url == null) {
      log.warn(
          "No value for config property "
              + OracleMeasurementPlugin.PROP_URL
              + ", no services will be discovered.");
      return null;
    }

    String user = config.getValue(OracleMeasurementPlugin.PROP_USER);
    if (user == null) {
      log.info("No value for config property " + OracleMeasurementPlugin.PROP_USER);
    }

    String pass = config.getValue(OracleMeasurementPlugin.PROP_PASSWORD);
    if (pass == null) {
      log.info("No value for config property " + OracleMeasurementPlugin.PROP_PASSWORD);
    }

    ArrayList services = new ArrayList();
    Connection conn = null;
    Statement stmt = null;
    try {
      String instance = url.substring(url.lastIndexOf(':') + 1);
      conn = DriverManager.getConnection(url, user, pass);
      stmt = conn.createStatement();
      services.addAll(getUserServices(stmt, instance));
      services.addAll(getTablespaceServices(stmt, instance));
      // turning this off by default.
      // There are too many table that this will discover
      // most of which the user probably won't care about.
      // Also work needs to be done by the user to enable
      // scheduled control actions to do an Anaylze per table
      // so that the system info gets updated before the
      // size is calc'd.
      // services.addAll(getSegmentServices(stmt, instance));
      services.addAll(getProcessServices(config));
      // this requires extra config on the user side to set ORACLE_HOME
      // env var, so to avoid confusion disabling
      // services.addAll(getTnsServices(config));
      setCustomProps(stmt);
    } catch (SQLException e) {
      // Try to do some investigation of what went wrong
      if (e.getMessage().indexOf("table or view does not exist") != -1) {
        log.error(
            "System table does not exist, make sure that "
                + " the Oracle user specified has the correct "
                + " privileges.  See the HQ server configuration "
                + " page for more information");
        return services;
      }
      // Otherwise, dump the error.
      throw new PluginException("Error querying for Oracle " + "services: " + e.getMessage(), e);
    } finally {
      DBUtil.closeJDBCObjects(log, conn, stmt, null);
    }
    return services;
  }