本文整理匯總了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));
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
}
示例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());
}
示例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);
}
示例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);
}
示例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();
}
}
}
示例10: setOperator
import monasca.common.model.alarm.AlarmOperator; //導入依賴的package包/類
public SubAlarmDefinitionDb setOperator(final AlarmOperator operator) {
return this.setOperator(operator.name().toUpperCase());
}