JAH-1891 Threshold Engine will not update State properly if user has changed state via the API
Set the new oldState and unchangedExpressions fields in the AlarmCreatedEvent
This commit is contained in:
parent
47e90183cb
commit
4a25ae2f59
@ -80,6 +80,8 @@ public class AlarmService {
|
||||
Map<String, AlarmSubExpression> oldAlarmSubExpressions;
|
||||
/** Sub expressions which have had their operator or threshold changed. */
|
||||
Map<String, AlarmSubExpression> changedSubExpressions;
|
||||
/** Sub expressions which have not changed. */
|
||||
Map<String, AlarmSubExpression> unchangedSubExpressions;
|
||||
/** Sub expressions which have been added to an updated alarm expression. */
|
||||
Map<String, AlarmSubExpression> newAlarmSubExpressions;
|
||||
}
|
||||
@ -207,8 +209,9 @@ public class AlarmService {
|
||||
|
||||
// Notify interested parties of updated alarm
|
||||
String event = Serialization.toJson(new AlarmUpdatedEvent(tenantId, alarmId, name,
|
||||
description, expression, newState, enabled, subExpressions.oldAlarmSubExpressions,
|
||||
subExpressions.changedSubExpressions, subExpressions.newAlarmSubExpressions));
|
||||
description, expression, newState, oldState, enabled, subExpressions.oldAlarmSubExpressions,
|
||||
subExpressions.changedSubExpressions, subExpressions.unchangedSubExpressions,
|
||||
subExpressions.newAlarmSubExpressions));
|
||||
producer.send(new KeyedMessage<>(config.eventsTopic, tenantId, event));
|
||||
|
||||
// Notify interested parties of transitioned alarm state
|
||||
@ -252,6 +255,11 @@ public class AlarmService {
|
||||
}
|
||||
}
|
||||
|
||||
// Create the list of unchanged expressions
|
||||
BiMap<String, AlarmSubExpression> unchangedExpressions = HashBiMap.create(oldExpressions);
|
||||
unchangedExpressions.values().removeAll(oldOrChangedExpressions);
|
||||
unchangedExpressions.keySet().removeAll(changedExpressions.keySet());
|
||||
|
||||
// Remove old sub expressions
|
||||
oldExpressions.values().retainAll(oldOrChangedExpressions);
|
||||
|
||||
@ -263,6 +271,7 @@ public class AlarmService {
|
||||
SubExpressions subExpressions = new SubExpressions();
|
||||
subExpressions.oldAlarmSubExpressions = oldExpressions;
|
||||
subExpressions.changedSubExpressions = changedExpressions;
|
||||
subExpressions.unchangedSubExpressions = unchangedExpressions;
|
||||
subExpressions.newAlarmSubExpressions = newExpressions;
|
||||
return subExpressions;
|
||||
}
|
||||
|
@ -137,6 +137,10 @@ public class AlarmServiceTest {
|
||||
assertEquals(expressions.changedSubExpressions,
|
||||
Collections.singletonMap("222", AlarmSubExpression.of("avg(foo{instance_id=456}) <= 22")));
|
||||
|
||||
// Assert unchanged expressions
|
||||
assertEquals(expressions.unchangedSubExpressions,
|
||||
Collections.singletonMap("111", AlarmSubExpression.of("avg(foo{instance_id=123}) > 1")));
|
||||
|
||||
// Assert new expressions
|
||||
assertTrue(expressions.newAlarmSubExpressions.containsValue(AlarmSubExpression.of("avg(foo{instance_id=444}) > 4")));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user