當前位置: 首頁>>代碼示例>>Java>>正文


Java AlarmOperator類代碼示例

本文整理匯總了Java中monasca.common.model.alarm.AlarmOperator的典型用法代碼示例。如果您正苦於以下問題:Java AlarmOperator類的具體用法?Java AlarmOperator怎麽用?Java AlarmOperator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AlarmOperator類屬於monasca.common.model.alarm包,在下文中一共展示了AlarmOperator類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDimensions

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
/**
 * This test is here because this case happened in the Threshold Engine. The AlarmExpression
 * resulted in a MetricDefinition with null dimensions and SubAlarm had empty dimensions and that
 * didn't match causing an IllegalArgumentException. The AlarmSubExpressionListener has been
 * changed to always generate empty dimensions and not null. This test will verify that logic
 * is still working.
 */
public void testDimensions() {
  final AlarmExpression expression = AlarmExpression.of("max(cpu_system_perc) > 1");
  final MetricDefinition metricDefinition =
      new MetricDefinition("cpu_system_perc", new HashMap<String, String>());
  final AlarmSubExpression ase =
      new AlarmSubExpression(AggregateFunction.MAX, metricDefinition, AlarmOperator.GT, 1, 60, 1);
  final SubAlarm subAlarm = new SubAlarm("123", "456", new SubExpression(UUID.randomUUID().toString(), ase));
  final Map<AlarmSubExpression, Boolean> subExpressionValues =
      new HashMap<>();
  subExpressionValues.put(subAlarm.getExpression(), true);
  assertEquals(expression.getSubExpressions().get(0).getMetricDefinition().hashCode(),
      metricDefinition.hashCode());

  // Handle ALARM state
  assertTrue(expression.evaluate(subExpressionValues));
}
 
開發者ID:openstack,項目名稱:monasca-thresh,代碼行數:24,代碼來源:AlarmTest.java

示例2: newSubAlarmDefinition

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
private SubAlarmDefinitionDb newSubAlarmDefinition(final Session session, final String id, final AlarmDefinitionDb alarmDefinition) {
  final DateTime now = DateTime.now();
  final SubAlarmDefinitionDb db = new SubAlarmDefinitionDb(
      id,
      alarmDefinition,
      String.format("f_%s", id),
      String.format("m_%s", id),
      AlarmOperator.GT.toString(),
      0.0,
      1,
      2,
      now,
      now
  );
  session.save(db);
  return db;
}
 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:18,代碼來源:AlarmSqlRepositoryImplTest.java

示例3: shouldFindSubExpressions

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
@Test(groups = "database")
public void shouldFindSubExpressions() {
  // This test won't work without the real mysql database so use mini-mon.
  // Warning, this will truncate your mini-mon database
  db = new DBI("jdbc:mysql://192.168.10.4/mon", "monapi", "password");
  handle = db.open();
  repo = new AlarmDefinitionMySqlRepoImpl(db, new PersistUtils());
  beforeMethod();

  assertEquals(
      repo.findSubExpressions("123").get("111"),
      new AlarmSubExpression(AggregateFunction.AVG, new MetricDefinition("hpcs.compute",
          ImmutableMap.<String, String>builder().put("flavor_id", "777").put("image_id", "888")
              .put("metric_name", "cpu").put("device", "1").build()), AlarmOperator.GT, 10, 60, 1));

  assertEquals(repo.findSubExpressions("234").get("223"), new AlarmSubExpression(
      AggregateFunction.AVG, new MetricDefinition("hpcs.compute", new HashMap<String, String>()), AlarmOperator.LT, 100,
      60, 1));

  assertTrue(repo.findSubAlarmMetricDefinitions("asdfasdf").isEmpty());
}
 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:22,代碼來源:AlarmDefinitionMySqlRepositoryImplTest.java

示例4: findSubExpressions

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
private List<SubExpression> findSubExpressions(Handle h, String alarmDefId) {
  List<Map<String, Object>> rows =
      h.createQuery(SUB_ALARM_SQL).bind("alarmDefId", alarmDefId).list();
  final List<SubExpression> subExpressions = new ArrayList<>(rows.size());
  int index = 0;
  while (index < rows.size()) {
    Map<String, Object> row = rows.get(index);
    String id = (String) row.get("id");
    AggregateFunction function = AggregateFunction.fromJson((String) row.get("function"));
    String metricName = (String) row.get("metric_name");
    AlarmOperator operator = AlarmOperator.fromJson((String) row.get("operator"));
    Double threshold = (Double) row.get("threshold");
    // MySQL connector returns an Integer, Drizzle returns a Long for period and periods.
    // Need to convert the results appropriately based on type.
    Integer period = Conversions.variantToInteger(row.get("period"));
    Integer periods = Conversions.variantToInteger(row.get("periods"));
    Boolean deterministic = BOOLEAN_MAPPER_FUNCTION.apply(row.get("is_deterministic"));
    Map<String, String> dimensions = new HashMap<>();
    while (addedDimension(dimensions, id, rows, index)) {
      index++;
    }
    subExpressions.add(
        new SubExpression(id,
            new AlarmSubExpression(
                function,
                new MetricDefinition(metricName, dimensions),
                operator,
                threshold,
                period,
                periods,
                deterministic
            )
        )
    );
  }

  return subExpressions;
}
 
開發者ID:openstack,項目名稱:monasca-thresh,代碼行數:39,代碼來源:AlarmDefinitionDAOImpl.java

示例5: findSubExpressions

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
@Override
public Map<String, AlarmSubExpression> findSubExpressions(String alarmDefId) {
  try (Handle h = db.open()) {
    List<Map<String, Object>> rows =
        h.createQuery(SUB_ALARM_SQL).bind("alarmDefId", alarmDefId).list();
    Map<String, AlarmSubExpression> subExpressions = new HashMap<>();
    for (Map<String, Object> row : rows) {
      String id = (String) row.get("id");
      AggregateFunction function = AggregateFunction.fromJson((String) row.get("function"));
      String metricName = (String) row.get("metric_name");
      AlarmOperator operator = AlarmOperator.fromJson((String) row.get("operator"));
      Double threshold = (Double) row.get("threshold");
      // MySQL connector returns an Integer, Drizzle returns a Long for period and periods.
      // Need to convert the results appropriately based on type.
      Integer period = Conversions.variantToInteger(row.get("period"));
      Integer periods = Conversions.variantToInteger(row.get("periods"));
      Boolean isDeterministic = Conversions.variantToBoolean(row.get("is_deterministic"));
      Map<String, String> dimensions =
          DimensionQueries.dimensionsFor((String) row.get("dimensions"));

      subExpressions.put(
          id,
          new AlarmSubExpression(
              function,
              new MetricDefinition(metricName, dimensions),
              operator,
              threshold,
              period,
              periods,
              isDeterministic
          )
      );

    }

    return subExpressions;
  }
}
 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:39,代碼來源:AlarmDefinitionMySqlRepoImpl.java

示例6: shouldFindSubExpressions

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
@Test(groups = "orm")
public void shouldFindSubExpressions() {

  assertEquals(repo.findSubExpressions("123").get("111"), new AlarmSubExpression(AggregateFunction.AVG, new MetricDefinition("hpcs.compute",
      ImmutableMap.<String, String>builder().put("flavor_id", "777").put("image_id", "888").put("metric_name", "cpu").put("device", "1").build()),
      AlarmOperator.GT, 10, 60, 1));

  assertEquals(repo.findSubExpressions("234").get("223"), new AlarmSubExpression(AggregateFunction.AVG, new MetricDefinition("hpcs.compute",
      new HashMap<String, String>()), AlarmOperator.LT, 100, 60, 1));

  assertTrue(repo.findSubAlarmMetricDefinitions("asdfasdf").isEmpty());
}
 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:13,代碼來源:AlarmDefinitionSqlRepositoryImplTest.java

示例7: validateMetricDefUpdatedOperator

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
public void validateMetricDefUpdatedOperator() {
  final SubAlarmStats stats =
      updateEnsureMeasurementsKept(subExpr2, "avg(hpcs.compute.mem{id=5}, 60) < 80");
  assertEquals(stats.getSubAlarm().getExpression().getOperator(), AlarmOperator.LT);
}
 
開發者ID:openstack,項目名稱:monasca-thresh,代碼行數:6,代碼來源:MetricAggregationBoltTest.java

示例8: validateMetricDefReplacedFunction

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
public void validateMetricDefReplacedFunction() {
  final SubAlarmStats stats =
      updateEnsureMeasurementsFlushed(subExpr2, "max(hpcs.compute.mem{id=5}, 60) < 80");
  assertEquals(stats.getSubAlarm().getExpression().getOperator(), AlarmOperator.LT);
}
 
開發者ID:openstack,項目名稱:monasca-thresh,代碼行數:6,代碼來源:MetricAggregationBoltTest.java

示例9: findSubExpressions

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public Map<String, AlarmSubExpression> findSubExpressions(String alarmDefId) {
  logger.trace(ORM_LOG_MARKER, "findSubExpressions(...) entering...");

  Session session = null;
  Map<String, AlarmSubExpression> subExpressions = Maps.newHashMap();
  try {

    session = sessionFactory.openSession();

    List<SubAlarmDefinitionDb> subAlarmDefList = session
        .getNamedQuery(SubAlarmDefinitionDb.Queries.BY_ALARMDEFINITION_ID)
        .setString("id", alarmDefId)
        .list();

    Query querySybAlarmDefDimension = session
        .getNamedQuery(SubAlarmDefinitionDb.Queries.BY_ALARMDEFINITIONDIMENSION_SUBEXPRESSION_ID)
        .setString("id", alarmDefId);

    List<SubAlarmDefinitionDimensionDb> subAlarmDefDimensionList = querySybAlarmDefDimension.list();

    Map<String, Map<String, String>> subAlarmDefDimensionMapExpression = mapAlarmDefDimensionExpression(subAlarmDefDimensionList);

    for (SubAlarmDefinitionDb subAlarmDef : subAlarmDefList) {
      String id = subAlarmDef.getId();
      AggregateFunction function = AggregateFunction.fromJson(subAlarmDef.getFunction());
      String metricName = subAlarmDef.getMetricName();
      AlarmOperator operator = AlarmOperator.fromJson(subAlarmDef.getOperator());
      double threshold = subAlarmDef.getThreshold();
      int period = subAlarmDef.getPeriod();
      int periods = subAlarmDef.getPeriods();
      boolean isDeterministic = subAlarmDef.isDeterministic();
      Map<String, String> dimensions = Collections.emptyMap();

      if (subAlarmDefDimensionMapExpression.containsKey(id)) {
        dimensions = subAlarmDefDimensionMapExpression.get(id);
      }

      subExpressions.put(id,
          new AlarmSubExpression(
              function,
              new MetricDefinition(metricName, dimensions),
              operator,
              threshold,
              period,
              periods,
              isDeterministic
          )
      );
    }

    return subExpressions;

  } finally {
    if (session != null) {
      session.close();
    }
  }
}
 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:61,代碼來源:AlarmDefinitionSqlRepoImpl.java

示例10: setOperator

import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
public SubAlarmDefinitionDb setOperator(final AlarmOperator operator) {
  return this.setOperator(operator.name().toUpperCase());
}
 
開發者ID:openstack,項目名稱:monasca-common,代碼行數:4,代碼來源:SubAlarmDefinitionDb.java


注:本文中的monasca.common.model.alarm.AlarmOperator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。