Commit addf0ede2789be19a53a51f0816ce6c56fe42c92
Committed by
Andrew Shvayka
1 parent
2b95d6cb
added buildAlarmDetails for clearAlarmByAlarmOriginator method
Showing
1 changed file
with
15 additions
and
12 deletions
@@ -58,7 +58,7 @@ public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfig | @@ -58,7 +58,7 @@ public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfig | ||
58 | protected ListenableFuture<AlarmResult> processAlarm(TbContext ctx, TbMsg msg) { | 58 | protected ListenableFuture<AlarmResult> processAlarm(TbContext ctx, TbMsg msg) { |
59 | String alarmType = TbNodeUtils.processPattern(this.config.getAlarmType(), msg.getMetaData()); | 59 | String alarmType = TbNodeUtils.processPattern(this.config.getAlarmType(), msg.getMetaData()); |
60 | if (msg.getOriginator().getEntityType().equals(EntityType.ALARM)) { | 60 | if (msg.getOriginator().getEntityType().equals(EntityType.ALARM)) { |
61 | - return clearAlarmFromOriginator(ctx, msg); | 61 | + return clearAlarmByAlarmOriginator(ctx, msg); |
62 | } else { | 62 | } else { |
63 | ListenableFuture<Alarm> latest = ctx.getAlarmService().findLatestByOriginatorAndType(ctx.getTenantId(), msg.getOriginator(), alarmType); | 63 | ListenableFuture<Alarm> latest = ctx.getAlarmService().findLatestByOriginatorAndType(ctx.getTenantId(), msg.getOriginator(), alarmType); |
64 | return Futures.transformAsync(latest, a -> { | 64 | return Futures.transformAsync(latest, a -> { |
@@ -70,21 +70,24 @@ public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfig | @@ -70,21 +70,24 @@ public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfig | ||
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | - private ListenableFuture<AlarmResult> clearAlarmFromOriginator(TbContext ctx, TbMsg msg) { | 73 | + private ListenableFuture<AlarmResult> clearAlarmByAlarmOriginator(TbContext ctx, TbMsg msg) { |
74 | ListenableFuture<Alarm> alarmByIdAsync = ctx.getAlarmService().findAlarmByIdAsync(ctx.getTenantId(), new AlarmId(msg.getOriginator().getId())); | 74 | ListenableFuture<Alarm> alarmByIdAsync = ctx.getAlarmService().findAlarmByIdAsync(ctx.getTenantId(), new AlarmId(msg.getOriginator().getId())); |
75 | return Futures.transformAsync(alarmByIdAsync, alarm -> { | 75 | return Futures.transformAsync(alarmByIdAsync, alarm -> { |
76 | if (alarm != null && !alarm.getStatus().isCleared()) { | 76 | if (alarm != null && !alarm.getStatus().isCleared()) { |
77 | - long clearTs = System.currentTimeMillis(); | ||
78 | - ListenableFuture<Boolean> clearAlarmFuture = ctx.getAlarmService().clearAlarm(ctx.getTenantId(), alarm.getId(), alarm.getDetails(), clearTs); | ||
79 | - return Futures.transformAsync(clearAlarmFuture, cleared -> { | ||
80 | - if (cleared) { | ||
81 | - alarm.setClearTs(clearTs); | ||
82 | - AlarmStatus oldStatus = alarm.getStatus(); | ||
83 | - AlarmStatus newStatus = oldStatus.isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK; | ||
84 | - alarm.setStatus(newStatus); | 77 | + ctx.logJsEvalRequest(); |
78 | + ListenableFuture<JsonNode> asyncDetails = buildAlarmDetails(ctx, msg, alarm.getDetails()); | ||
79 | + return Futures.transformAsync(asyncDetails, details -> { | ||
80 | + ctx.logJsEvalRequest(); | ||
81 | + long clearTs = System.currentTimeMillis(); | ||
82 | + ListenableFuture<Boolean> clearAlarmFuture = ctx.getAlarmService().clearAlarm(ctx.getTenantId(), alarm.getId(), details, clearTs); | ||
83 | + return Futures.transformAsync(clearAlarmFuture, cleared -> { | ||
84 | + if (cleared) { | ||
85 | + alarm.setClearTs(clearTs); | ||
86 | + alarm.setDetails(details); | ||
87 | + } | ||
88 | + alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK); | ||
85 | return Futures.immediateFuture(new AlarmResult(false, false, true, alarm)); | 89 | return Futures.immediateFuture(new AlarmResult(false, false, true, alarm)); |
86 | - } | ||
87 | - return Futures.immediateFuture(new AlarmResult(false, false, false, alarm)); | 90 | + }, ctx.getDbCallbackExecutor()); |
88 | }, ctx.getDbCallbackExecutor()); | 91 | }, ctx.getDbCallbackExecutor()); |
89 | } | 92 | } |
90 | return Futures.immediateFuture(new AlarmResult(false, false, false, null)); | 93 | return Futures.immediateFuture(new AlarmResult(false, false, false, null)); |