本文整理汇总了Java中org.hawkular.alerts.api.model.condition.CompareCondition类的典型用法代码示例。如果您正苦于以下问题:Java CompareCondition类的具体用法?Java CompareCondition怎么用?Java CompareCondition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompareCondition类属于org.hawkular.alerts.api.model.condition包,在下文中一共展示了CompareCondition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCompareCondition
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Override
public ClientResponse<List<CompareCondition>> setCompareCondition(
String triggerId, String triggerMode, List<CompareCondition> conditions) {
Response serverResponse = null;
try {
serverResponse = restApi().setCompareCondition(triggerId, triggerMode, conditions);
JavaType javaType = collectionResolver().get(List.class, CompareCondition.class);
return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.UPDATE_SUCCESS_200);
} finally {
if (serverResponse != null) {
serverResponse.close();
}
}
}
示例2: setStringCondition
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Override
public ClientResponse<List<StringCondition>> setStringCondition(
String triggerId, String triggerMode, List<StringCondition> conditions) {
Response serverResponse = null;
try {
serverResponse = restApi().setStringCondition(triggerId, triggerMode, conditions);
JavaType javaType = collectionResolver().get(List.class, CompareCondition.class);
return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.UPDATE_SUCCESS_200);
} finally {
if (serverResponse != null) {
serverResponse.close();
}
}
}
示例3: jsonCompareConditionEvalTest
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Test
public void jsonCompareConditionEvalTest() throws Exception {
String str = "{\"evalTimestamp\":1,\"dataTimestamp\":1,\"type\":\"COMPARE\","
+ "\"condition\":"
+ "{\"triggerId\":\"test\",\"triggerMode\":\"FIRING\",\"type\":\"COMPARE\","
+ "\"dataId\":\"Default1\",\"operator\":\"LT\",\"data2Id\":\"Default2\",\"data2Multiplier\":1.2},"
+ "\"value1\":10.0,\"value2\":15.0,"
+ "\"context\":{\"n1\":\"v1\",\"n2\":\"v2\"},\"context2\":{\"n1\":\"v1\",\"n2\":\"v2\"}}";
CompareConditionEval eval = objectMapper.readValue(str, CompareConditionEval.class);
assertTrue(eval.getEvalTimestamp() == 1);
assertTrue(eval.getDataTimestamp() == 1);
assertTrue(eval.getCondition().getType().equals(Condition.Type.COMPARE));
assertTrue(eval.getCondition().getTriggerId().equals("test"));
assertTrue(eval.getCondition().getTriggerMode().equals(Mode.FIRING));
assertTrue(eval.getCondition().getDataId().equals("Default1"));
assertTrue(eval.getCondition().getOperator().equals(CompareCondition.Operator.LT));
assertTrue(eval.getValue1().equals(10.0));
assertTrue(eval.getValue2().equals(15.0));
assertTrue(eval.getContext().size() == 2);
assertTrue(eval.getContext().get("n1").equals("v1"));
assertTrue(eval.getContext().get("n2").equals("v2"));
assertTrue(eval.getContext2().size() == 2);
assertTrue(eval.getContext2().get("n1").equals("v1"));
assertTrue(eval.getContext2().get("n2").equals("v2"));
}
示例4: setCompareCondition
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Test
public void setCompareCondition() {
String triggerId = "New-Trigger-" + RandomStringGenerator.getRandomId();
@SuppressWarnings("unchecked")
SetConitionMethod method = (triggerId1, triggerMode, conditions) -> client()
.alerts()
.triggers()
.setCompareCondition(triggerId1, triggerMode, conditions);
CompareCondition compareCondition =
new CompareCondition(triggerId, Mode.AUTORESOLVE, "no-data-id", CompareCondition.Operator.GTE, 1.0, "no-data-id-2");
executeConditionTest(triggerId, Arrays.asList(compareCondition), Mode.AUTORESOLVE, method);
}
示例5: detailedCheck
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Test
public void detailedCheck() throws Exception {
List<FullTrigger> fullTriggers = importManager.getFullTriggers();
List<ActionDefinition> actionDefinitions = importManager.getActionDefinitions();
assertTrue(fullTriggers.size() > 0);
assertTrue(actionDefinitions.size() > 0);
// Check trigger-1
assertEquals("value1", fullTriggers.get(0).getTrigger().getContext().get("name1"));
assertEquals("tvalue2", fullTriggers.get(0).getTrigger().getTags().get("tname2"));
assertEquals(Dampening.Type.STRICT, fullTriggers.get(0).getDampenings().get(0).getType());
assertTrue(fullTriggers.get(0).getConditions().get(0) instanceof ThresholdCondition);
// Check trigger-2
assertEquals(2, fullTriggers.get(1).getConditions().size());
assertEquals("NumericData-01", fullTriggers.get(1).getConditions().get(0).getDataId());
assertEquals("NumericData-02", fullTriggers.get(1).getConditions().get(1).getDataId());
// Check trigger-3
assertEquals("NumericData-03", fullTriggers.get(2).getConditions().get(0).getDataId());
// Check trigger-4
assertTrue(fullTriggers.get(3).getConditions().get(0) instanceof CompareCondition);
// Check trigger-5
assertEquals("StringData-01", fullTriggers.get(4).getConditions().get(0).getDataId());
// Check trigger-6
assertEquals("Availability-01", fullTriggers.get(5).getConditions().get(0).getDataId());
// Check trigger-7
assertTrue(fullTriggers.get(6).getTrigger().isGroup());
// Check trigger-8
assertEquals("NumericData-01", fullTriggers.get(7).getConditions().get(0).getDataId());
// Check trigger-9
assertTrue(fullTriggers.get(8).getConditions().get(0) instanceof RateCondition);
}
示例6: description
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
private String description(Condition condition) {
if (condition == null)
return null;
switch (condition.getType()) {
case AVAILABILITY:
return availability((AvailabilityCondition) condition);
case COMPARE:
return compare((CompareCondition) condition);
case EXTERNAL:
return external((ExternalCondition) condition);
case EVENT:
return events((EventCondition) condition);
case MISSING:
return missing((MissingCondition) condition);
case NELSON:
return nelson((NelsonCondition) condition);
case RANGE:
return range((ThresholdRangeCondition) condition);
case RATE:
return rate((RateCondition) condition);
case STRING:
return string((StringCondition) condition);
case THRESHOLD:
return threshold((ThresholdCondition) condition);
default:
return null;
}
}
示例7: compare
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
/**
* Create a description for an CompareCondition object.
* It supports Condition.context properties:
* - "description": Description of the dataId used for this condition, if not present, description will use
* dataId literal
* i.e. "description": "Response Time"
*
* - "description2": Description of the data2Id used for this comparition, if not present, description will use
* data2Id literal
* i.e. "description2": "Response Time 2"
*
* @param condition the condition
* @return a description to be used on email templates
*/
public String compare(CompareCondition condition) {
String description;
if (condition.getContext() != null && condition.getContext().get(CONTEXT_PROPERTY_DESCRIPTION) != null) {
description = condition.getContext().get(CONTEXT_PROPERTY_DESCRIPTION);
} else {
description = condition.getDataId();
}
CompareCondition.Operator operator = condition.getOperator();
switch (operator) {
case LT:
description += " less than ";
break;
case LTE:
description += " less or equals than ";
break;
case GT:
description += " greater than ";
break;
case GTE:
description += " greater or equals than ";
break;
default:
throw new IllegalArgumentException(operator.name());
}
if (condition.getData2Multiplier() != 1.0) {
description += "( " + decimalFormat.format(condition.getData2Multiplier()) + " ";
}
if (condition.getContext() != null && condition.getContext().get(CONTEXT_PROPERTY_DESCRIPTION2) != null) {
description += condition.getContext().get(CONTEXT_PROPERTY_DESCRIPTION2);
} else {
description += condition.getData2Id();
}
if (condition.getData2Multiplier() != 1.0) {
description += " )";
}
return description;
}
示例8: setCompareCondition
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@PUT
@Path("/{triggerId}/conditions/{triggerMode}")
Response setCompareCondition(
@PathParam("triggerId") final String triggerId, @PathParam("triggerMode") final String triggerMode,
List<CompareCondition> conditions);
示例9: updateCondition
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
private void updateCondition(Condition condition) {
if (null == condition) {
throw new IllegalArgumentException("condition must be not null");
}
switch (condition.getType()) {
case AVAILABILITY:
this.condition = new AvailabilityCondition((AvailabilityCondition) condition);
break;
case COMPARE:
this.condition = new CompareCondition((CompareCondition) condition);
break;
case EVENT:
this.condition = new EventCondition((EventCondition) condition);
break;
case EXTERNAL:
this.condition = new ExternalCondition((ExternalCondition) condition);
break;
case MISSING:
this.condition = new MissingCondition((MissingCondition) condition);
break;
case NELSON:
this.condition = new NelsonCondition((NelsonCondition) condition);
break;
case RANGE:
this.condition = new ThresholdRangeCondition((ThresholdRangeCondition) condition);
break;
case RATE:
this.condition = new RateCondition((RateCondition) condition);
break;
case STRING:
this.condition = new StringCondition((StringCondition) condition);
break;
case THRESHOLD:
this.condition = new ThresholdCondition((ThresholdCondition) condition);
break;
default:
throw new IllegalArgumentException("Unknown condition type: " + condition.getType());
}
this.tenantId = condition.getTenantId();
this.triggerId = condition.getTriggerId();
this.triggerMode = condition.getTriggerMode();
}
示例10: addDataDrivenMemberTrigger
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Override
public Trigger addDataDrivenMemberTrigger(String tenantId, String groupId, String source) throws Exception {
if (isEmpty(tenantId)) {
throw new IllegalArgumentException("TenantId must be not null");
}
if (isEmpty(groupId)) {
throw new IllegalArgumentException("TriggerId must be not null");
}
if (isEmpty(source)) {
throw new IllegalArgumentException("source must be not null");
}
if (Data.SOURCE_NONE.equals(source)) {
throw new IllegalArgumentException("source is required (can not be none)");
}
try {
deferNotifications();
// fetch the group trigger (or throw NotFoundException)
Trigger group = getTrigger(tenantId, groupId);
// fetch the group conditions and generate a dataIdMap that just uses the same tokens as found in the
// group conditions. That is what we want in this use case, the source provides the differentiator
Map<String, String> dataIdMap = new HashMap<>();
Collection<Condition> conditions = getTriggerConditions(tenantId, groupId, null);
for (Condition c : conditions) {
dataIdMap.put(c.getDataId(), c.getDataId());
if (Condition.Type.COMPARE == c.getType()) {
dataIdMap.put(((CompareCondition) c).getData2Id(), ((CompareCondition) c).getData2Id());
}
}
// create a member trigger like the group trigger
String memberId = group.getId() + "_" + source;
Trigger member = new Trigger(tenantId, memberId, group.getName());
copyGroupTrigger(group, member, true);
member.setSource(source);
// add source tag (not sure if we really need this)
member.getTags().put("source", source);
addTrigger(member);
// add any conditions
List<Condition> memberConditions = conditions.stream()
.map(c -> getMemberCondition(member, c, dataIdMap))
.collect(Collectors.toList());
setAllConditions(tenantId, memberId, memberConditions);
// add any dampening
Collection<Dampening> dampenings = getTriggerDampenings(tenantId, groupId, null);
for (Dampening d : dampenings) {
Dampening newDampening = new Dampening(member.getTenantId(), member.getId(), d.getTriggerMode(),
d.getType(), d.getEvalTrueSetting(), d.getEvalTotalSetting(), d.getEvalTimeSetting());
addDampening(newDampening);
}
return member;
} finally {
releaseNotifications();
}
}
示例11: setConditions
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
private Collection<Condition> setConditions(String tenantId, String triggerId, Mode triggerMode,
Collection<Condition> conditions, Set<String> dataIds) throws Exception {
// Get rid of the prior condition set
removeConditions(tenantId, triggerId, triggerMode);
// Now add the new condition set
try {
Map<String, IspnCondition> newConditions = new HashMap<>();
int indexCondition = 0;
for (Condition cond : conditions) {
cond.setTenantId(tenantId);
cond.setTriggerId(triggerId);
cond.setTriggerMode(triggerMode);
cond.setConditionSetSize(conditions.size());
cond.setConditionSetIndex(++indexCondition);
dataIds.add(cond.getDataId());
switch (cond.getType()) {
case COMPARE:
CompareCondition cCond = (CompareCondition) cond;
dataIds.add(cCond.getData2Id());
break;
case AVAILABILITY:
case EVENT:
case EXTERNAL:
case MISSING:
case NELSON:
case RANGE:
case RATE:
case STRING:
case THRESHOLD:
break;
default:
throw new IllegalArgumentException("Unexpected ConditionType: " + cond);
}
newConditions.put(pk(cond), new IspnCondition(cond));
}
backend.putAll(newConditions);
} catch (Exception e) {
log.errorDatabaseException(e.getMessage());
throw e;
}
return conditions;
}
示例12: reloadTrigger
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
private void reloadTrigger(Trigger trigger) {
if (null == trigger) {
throw new IllegalArgumentException("Trigger must be not null");
}
if (log.isDebugEnabled()) {
log.debug("Reloading " + trigger);
}
// Look for the Trigger in the rules engine, if it is there then remove everything about it
// Note that removeTrigger relies only on tenatId+triggerId.
removeTrigger(trigger);
try {
if (distributed) {
trigger = definitions.getTrigger(trigger.getTenantId(), trigger.getId());
}
if (trigger != null && trigger.isLoadable()) {
Collection<Condition> conditionSet = definitions.getTriggerConditions(trigger.getTenantId(),
trigger.getId(), null);
Collection<Dampening> dampenings = definitions.getTriggerDampenings(trigger.getTenantId(),
trigger.getId(), null);
/*
Cache dataId from conditions, Handle MissingCondition's MissingState
*/
for (Condition c : conditionSet) {
if (distributed) {
DataEntry entry = new DataEntry(c.getTenantId(), c.getTriggerId(), c.getDataId());
alertsEngineCache.add(entry);
if (Condition.Type.COMPARE == c.getType()) {
String data2Id = ((CompareCondition) c).getData2Id();
DataEntry entry2 = new DataEntry(c.getTenantId(), c.getTriggerId(), data2Id);
alertsEngineCache.add(entry2);
}
}
if (c instanceof MissingCondition) {
// MissingState keeps a reference to the Trigger fact to check active trigger mode
MissingState missingState = new MissingState(trigger, (MissingCondition) c);
// MissingStates are modified inside the rules engine
synchronized (missingStates) {
missingStates.remove(missingState);
missingStates.add(missingState);
rules.addFact(missingState);
}
}
}
rules.addFact(trigger);
rules.addFacts(conditionSet);
if (!dampenings.isEmpty()) {
rules.addFacts(dampenings);
}
}
} catch (Exception e) {
log.debug(e.getMessage(), e);
log.errorDefinitionsService("Conditions/Dampening", e.getMessage());
}
}
示例13: updateCache
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
private synchronized void updateCache() {
log.debug("Updating cache...");
try {
updating = true;
while (updateRequested) {
updateRequested = false;
log.debug("Cache update in progress..");
Collection<Trigger> allTriggers = definitions.getAllTriggers();
Set<Trigger> ddGroupTriggers = new HashSet<>();
for (Trigger t : allTriggers) {
if (TriggerType.DATA_DRIVEN_GROUP == t.getType()) {
ddGroupTriggers.add(t);
}
}
log.debugf("Updating [%s] data-driven triggers out of [%s] total triggers...", ddGroupTriggers.size(),
allTriggers.size());
for (Trigger groupTrigger : ddGroupTriggers) {
String tenantId = groupTrigger.getTenantId();
Set<String> sources = new HashSet<>();
for (Trigger memberTrigger : definitions.getMemberTriggers(tenantId, groupTrigger.getId(),
false)) {
sources.add(memberTrigger.getSource());
}
for (Condition c : definitions.getTriggerConditions(tenantId, groupTrigger.getId(), null)) {
CacheKey key = new CacheKey(tenantId, c.getDataId());
sourcesMap.put(key, sources);
Set<String> triggers = triggersMap.get(key);
if (null == triggers) {
triggers = new HashSet<>();
}
triggers.add(groupTrigger.getId());
triggersMap.put(key, triggers);
if (c instanceof CompareCondition) {
key = new CacheKey(tenantId, ((CompareCondition) c).getData2Id());
sourcesMap.put(key, sources);
triggers = triggersMap.get(key);
if (null == triggers) {
triggers = new HashSet<>();
}
triggers.add(groupTrigger.getId());
triggersMap.put(key, triggers);
}
}
}
}
} catch (Exception e) {
log.error("FAILED to updateCache. Unable to generate data-driven member triggers!", e);
sourcesMap = new HashMap<>();
} finally {
log.debugf("Cache updates complete. sourceMap: %s", sourcesMap);
updating = false;
}
}
示例14: compareTest2
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
@Test
public void compareTest2() {
Trigger t1 = new Trigger("tenant", "trigger-1", "Compare-D1-LT-Half-D2");
CompareCondition t1c1 = new CompareCondition("tenant", "trigger-1", 1, 1,
"NumericData-01",
CompareCondition.Operator.LT, 0.5, "NumericData-02");
Dampening t1d = Dampening.forRelaxedCount("tenant", "trigger-1", Mode.FIRING, 2, 3);
t1.setEnabled(true);
rulesEngine.addFact(t1);
rulesEngine.addFact(t1c1);
rulesEngine.addFact(t1d);
// Test Adding 1 datum at a time, with some repetition
// T1: D1=10, D2 unset : no condition eval
datums.add(Data.forNumeric("tenant", "NumericData-01", 1000, 10.0));
rulesEngine.addData(datums);
rulesEngine.fire();
assertEquals(alerts.toString(), 0, alerts.size());
// T2: D1=15, D2 unset : no condition eval
datums.clear();
datums.add(Data.forNumeric("tenant", "NumericData-01", 2000, 15.0));
rulesEngine.addData(datums);
rulesEngine.fire();
assertEquals(alerts.toString(), 0, alerts.size());
// T3: D1=15, D2=25 : Eval False, dampening 0 for 1
datums.clear();
datums.add(Data.forNumeric("tenant", "NumericData-02", 3000, 25.0));
rulesEngine.addData(datums);
rulesEngine.fire();
assertEquals(alerts.toString(), 0, alerts.size());
// T4: D1=15, D2=50 : Eval True, dampening 1 for 2
datums.clear();
datums.add(Data.forNumeric("tenant", "NumericData-02", 4000, 50.0));
rulesEngine.addData(datums);
rulesEngine.fire();
assertEquals(alerts.toString(), 0, alerts.size());
// T5: D1=20, D2=50 : Eval True, dampening 2 for 3 -> fire
datums.clear();
datums.add(Data.forNumeric("tenant", "NumericData-01", 5000, 20.0));
rulesEngine.addData(datums);
rulesEngine.fire();
assertEquals(alerts.toString(), 1, alerts.size());
Alert a = alerts.get(0);
assertTrue(a.getTriggerId(), a.getTriggerId().equals("trigger-1"));
assertEquals(2, a.getEvalSets().size());
Set<ConditionEval> evals = a.getEvalSets().get(0);
assertEquals(evals.toString(), 1, evals.size());
CompareConditionEval e = (CompareConditionEval) evals.iterator().next();
assertEquals(1, e.getConditionSetIndex());
assertEquals(1, e.getConditionSetSize());
assertTrue(e.toString(), e.getTriggerId().equals("trigger-1"));
assertTrue(e.isMatch());
Double v1 = e.getValue1();
Double v2 = e.getValue2();
assertTrue(e.toString(), v1.equals(15.0D));
assertTrue(e.toString(), v2.equals(50.0D));
assertTrue(e.getCondition().toString(), e.getCondition().getDataId().equals("NumericData-01"));
assertTrue(e.getCondition().toString(), e.getCondition().getData2Id().equals("NumericData-02"));
evals = a.getEvalSets().get(1);
assertEquals(evals.toString(), 1, evals.size());
e = (CompareConditionEval) evals.iterator().next();
assertEquals(1, e.getConditionSetIndex());
assertEquals(1, e.getConditionSetSize());
assertTrue(e.toString(), e.getTriggerId().equals("trigger-1"));
assertTrue(e.isMatch());
v1 = e.getValue1();
v2 = e.getValue2();
assertTrue(e.toString(), v1.equals(20.0D));
assertTrue(e.toString(), v2.equals(50.0D));
assertTrue(e.getCondition().toString(), e.getCondition().getDataId().equals("NumericData-01"));
assertTrue(e.getCondition().toString(), e.getCondition().getData2Id().equals("NumericData-02"));
}
示例15: setCompareCondition
import org.hawkular.alerts.api.model.condition.CompareCondition; //导入依赖的package包/类
/**
* Set the conditions for the trigger.
*
* @param triggerId
* @param triggerMode
* @param conditions
* @return
*/
ClientResponse<List<CompareCondition>> setCompareCondition(String triggerId, String triggerMode, List<CompareCondition> conditions);