예제 #1
0
  public AlertConditionCacheStats checkConditions(CallTimeData... callTime) {
    if ((callTime == null) || (callTime.length == 0)) {
      return new AlertConditionCacheStats();
    }

    AlertConditionCacheStats stats = new AlertConditionCacheStats();
    try {
      HashMap<Integer, HashMap<String, ArrayList<CallTimeDataValue>>> order =
          produceOrderedCallTimeDataStructure(callTime);
      for (Integer scheduleId : order.keySet()) {
        List<? extends CallTimeDataCacheElement> conditionCacheElements =
            lookupCallTimeDataCacheElements(scheduleId);
        for (String callDest : order.get(scheduleId).keySet()) {
          for (CallTimeDataValue provided : order.get(scheduleId).get(callDest)) {
            processCacheElements(
                conditionCacheElements, provided, provided.getBeginTime(), stats, callDest);
          }
        }
      }
      AlertConditionCacheMonitor.getMBean().incrementCallTimeCacheElementMatches(stats.matched);
      AlertConditionCacheMonitor.getMBean().incrementCallTimeProcessingTime(stats.getAge());
    } catch (Throwable t) {
      // don't let any exceptions bubble up to the calling SLSB layer
      log.error("Error during calltime cache processing for agent[id=" + agentId + "]", t);
    }

    return stats;
  }
예제 #2
0
  /*
   * internal method, do not expose to the remote API
   */
  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  public void insertCallTimeDataValues(Set<CallTimeData> callTimeDataSet) {
    int[] results;
    String insertValueSql;
    PreparedStatement ps = null;
    Connection conn = null;

    try {
      conn = rhqDs.getConnection();
      DatabaseType dbType = DatabaseTypeFactory.getDatabaseType(conn);

      if (dbType instanceof Postgresql83DatabaseType) {
        Statement st = null;
        try {
          // Take advantage of async commit here
          st = conn.createStatement();
          st.execute("SET synchronous_commit = off");
        } finally {
          JDBCUtil.safeClose(st);
        }
      }

      if (dbType instanceof PostgresqlDatabaseType
          || dbType instanceof OracleDatabaseType
          || dbType instanceof H2DatabaseType) {
        String valueNextvalSql = JDBCUtil.getNextValSql(conn, "RHQ_calltime_data_value");
        insertValueSql = String.format(CALLTIME_VALUE_INSERT_STATEMENT, valueNextvalSql);
      } else if (dbType instanceof SQLServerDatabaseType) {
        insertValueSql = CALLTIME_VALUE_INSERT_STATEMENT_AUTOINC;
      } else {
        throw new IllegalArgumentException("Unknown database type, can't continue: " + dbType);
      }

      ps = conn.prepareStatement(insertValueSql);
      for (CallTimeData callTimeData : callTimeDataSet) {
        ps.setInt(7, callTimeData.getScheduleId());
        Set<String> callDestinations = callTimeData.getValues().keySet();
        for (String callDestination : callDestinations) {
          CallTimeDataValue callTimeDataValue = callTimeData.getValues().get(callDestination);
          ps.setLong(1, callTimeDataValue.getBeginTime());
          ps.setLong(2, callTimeDataValue.getEndTime());
          ps.setDouble(3, callTimeDataValue.getMinimum());
          ps.setDouble(4, callTimeDataValue.getMaximum());
          ps.setDouble(5, callTimeDataValue.getTotal());
          ps.setLong(6, callTimeDataValue.getCount());
          ps.setString(8, callDestination);
          ps.addBatch();
        }
      }

      results = ps.executeBatch();

      int insertedRowCount = 0;
      for (int i = 0; i < results.length; i++) {
        if ((results[i] != 1)
            && (results[i]
                != -2)) // Oracle likes to return -2 becuase it doesn't track batch update counts
        {
          throw new MeasurementStorageException(
              "Failed to insert call-time data value rows - result ["
                  + results[i]
                  + "] for batch command ["
                  + i
                  + "] does not equal 1.");
        }

        insertedRowCount +=
            results[i] == -2 ? 1 : results[i]; // If Oracle returns -2, just count 1 row;
      }

      notifyAlertConditionCacheManager(
          "insertCallTimeDataValues",
          callTimeDataSet.toArray(new CallTimeData[callTimeDataSet.size()]));

      if (insertedRowCount > 0) {
        MeasurementMonitor.getMBean().incrementCalltimeValuesInserted(insertedRowCount);

        log.debug("Inserted " + insertedRowCount + " call-time data value rows.");
      }

    } catch (SQLException e) {
      logSQLException("Failed to persist call-time data values", e);
    } catch (Throwable t) {
      log.error("Failed to persist call-time data values", t);
    } finally {
      JDBCUtil.safeClose(conn, ps, null);
    }
  }