From a475aac49b3b029acf28174117a6423f6dd5eed7 Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Sat, 14 Jul 2018 10:42:32 +0800 Subject: Remove alarms from DB when they are cleared Change-Id: I56fe8356a10b25ccf2d9d3d4f73db8715701693f Issue-ID: HOLMES-143 Signed-off-by: GuangrongFu --- .../onap/holmes/engine/manager/DroolsEngine.java | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java index 3740f18..dcc40fd 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java @@ -223,16 +223,22 @@ public class DroolsEngine { } } - public void putRaisedIntoStream(VesAlarm raiseAlarm) { - FactHandle factHandle = this.kieSession.getFactHandle(raiseAlarm); + public void putRaisedIntoStream(VesAlarm alarm) { + FactHandle factHandle = this.kieSession.getFactHandle(alarm); if (factHandle != null) { Object obj = this.kieSession.getObject(factHandle); if (obj != null && obj instanceof VesAlarm) { - raiseAlarm.setRootFlag(((VesAlarm) obj).getRootFlag()); + alarm.setRootFlag(((VesAlarm) obj).getRootFlag()); } this.kieSession.delete(factHandle); + + if (alarm.getAlarmIsCleared() == 1) { + alarmInfoDao.deleteClearedAlarm(convertVesAlarm2AlarmInfo(alarm)); + } + } else { + this.kieSession.insert(alarm); } - this.kieSession.insert(raiseAlarm); + this.kieSession.fireAllRules(); } @@ -294,4 +300,18 @@ public class DroolsEngine { return vesAlarm; } + private AlarmInfo convertVesAlarm2AlarmInfo(VesAlarm vesAlarm){ + AlarmInfo alarmInfo = new AlarmInfo(); + alarmInfo.setEventId(vesAlarm.getEventId()); + alarmInfo.setEventName(vesAlarm.getEventName()); + alarmInfo.setStartEpochMicroSec(vesAlarm.getStartEpochMicrosec()); + alarmInfo.setLastEpochMicroSec(vesAlarm.getLastEpochMicrosec()); + alarmInfo.setSourceId(vesAlarm.getSourceId()); + alarmInfo.setSourceName(vesAlarm.getSourceName()); + alarmInfo.setAlarmIsCleared(vesAlarm.getAlarmIsCleared()); + alarmInfo.setRootFlag(vesAlarm.getRootFlag()); + + return alarmInfo; + } + } -- cgit 1.2.3-korg