Commit 4528e2230f9b9f53d01dba6d7ec9622c7ec1a282

Authored by Andrew Shvayka
1 parent ade282fd

Added support of new alarm flaf in Alarm Processor

1 /** 1 /**
2 * Copyright © 2016-2017 The Thingsboard Authors 2 * Copyright © 2016-2017 The Thingsboard Authors
3 - * 3 + * <p>
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 - *  
8 - * http://www.apache.org/licenses/LICENSE-2.0  
9 - * 7 + * <p>
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + * <p>
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -53,6 +53,8 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration @@ -53,6 +53,8 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration
53 static final String IS_NEW_ALARM = "isNewAlarm"; 53 static final String IS_NEW_ALARM = "isNewAlarm";
54 static final String IS_EXISTING_ALARM = "isExistingAlarm"; 54 static final String IS_EXISTING_ALARM = "isExistingAlarm";
55 static final String IS_CLEARED_ALARM = "isClearedAlarm"; 55 static final String IS_CLEARED_ALARM = "isClearedAlarm";
  56 + static final String IS_NEW_OR_CLEARED_ALARM = "isNewOrClearedAlarm";
  57 +
56 58
57 protected NashornJsEvaluator newAlarmEvaluator; 59 protected NashornJsEvaluator newAlarmEvaluator;
58 protected NashornJsEvaluator clearAlarmEvaluator; 60 protected NashornJsEvaluator clearAlarmEvaluator;
@@ -133,6 +135,7 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration @@ -133,6 +135,7 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration
133 if (existing.getStartTs() == alarm.getStartTs()) { 135 if (existing.getStartTs() == alarm.getStartTs()) {
134 log.debug("[{}][{}] New Active Alarm detected", ctx.getRuleId(), existing.getId()); 136 log.debug("[{}][{}] New Active Alarm detected", ctx.getRuleId(), existing.getId());
135 md.put(IS_NEW_ALARM, Boolean.TRUE); 137 md.put(IS_NEW_ALARM, Boolean.TRUE);
  138 + md.put(IS_NEW_OR_CLEARED_ALARM, Boolean.TRUE);
136 } else { 139 } else {
137 log.debug("[{}][{}] Existing Active Alarm detected", ctx.getRuleId(), existing.getId()); 140 log.debug("[{}][{}] Existing Active Alarm detected", ctx.getRuleId(), existing.getId());
138 md.put(IS_EXISTING_ALARM, Boolean.TRUE); 141 md.put(IS_EXISTING_ALARM, Boolean.TRUE);
@@ -144,10 +147,10 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration @@ -144,10 +147,10 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration
144 ctx.clearAlarm(alarm.get().getId(), System.currentTimeMillis()); 147 ctx.clearAlarm(alarm.get().getId(), System.currentTimeMillis());
145 log.debug("[{}][{}] Existing Active Alarm cleared"); 148 log.debug("[{}][{}] Existing Active Alarm cleared");
146 md.put(IS_CLEARED_ALARM, Boolean.TRUE); 149 md.put(IS_CLEARED_ALARM, Boolean.TRUE);
  150 + md.put(IS_NEW_OR_CLEARED_ALARM, Boolean.TRUE);
147 existing = alarm.get(); 151 existing = alarm.get();
148 } 152 }
149 } 153 }
150 - //TODO: handle cleared alarms  
151 154
152 if (existing != null) { 155 if (existing != null) {
153 md.put("alarmId", existing.getId().getId()); 156 md.put("alarmId", existing.getId().getId());