summaryrefslogtreecommitdiffstats
path: root/rules
diff options
context:
space:
mode:
authorMehreen Kaleem <mehreen.kaleem@us.fujitsu.com>2020-06-30 17:18:56 +0000
committerMehreen Kaleem <mehreen.kaleem@us.fujitsu.com>2020-06-30 17:19:03 +0000
commita5aaba7b73ac78a5ad03367b9cbdd3bd9151de71 (patch)
tree42e75718107b6e7ebbd8a89751f860b7a1412f4c /rules
parent18a28b93a3c41df917865ee897bd0f51bed760d6 (diff)
Drools Rule file for MDONS use case
Change-Id: Iec9416b83e7e112875942b160a5aa480389ddc88 Issue-ID: HOLMES-312 Signed-off-by: Mehreen Kaleem <mehreen.kaleem@us.fujitsu.com>
Diffstat (limited to 'rules')
-rw-r--r--rules/mdons-rule.drl130
1 files changed, 130 insertions, 0 deletions
diff --git a/rules/mdons-rule.drl b/rules/mdons-rule.drl
new file mode 100644
index 0000000..c4bc803
--- /dev/null
+++ b/rules/mdons-rule.drl
@@ -0,0 +1,130 @@
+package org.onap.holmes.mdonsPnf;
+
+dialect "java"
+import org.onap.holmes.common.api.stat.VesAlarm;
+import org.onap.holmes.common.api.stat.AlarmAdditionalField;
+import org.onap.holmes.common.aai.AaiQueryMdons;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.dmaap.entity.PolicyMsg;
+import org.onap.holmes.common.dmaap.DmaapService;
+import org.onap.holmes.common.utils.DroolsLog;
+import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.UUID;
+
+function Map<String, String> processAlarm(String sourceId) {
+ AaiQueryMdons mdons = AaiQueryMdons.newInstance();
+ DroolsLog.printInfo("Alarm pnf id " + sourceId);
+ String pnfName = mdons.getPnfNameFromPnfId(sourceId);
+ DroolsLog.printInfo("Pnf name from AAI" + pnfName);
+ mdons.updatePnfOperationalStatus(pnfName, "down");
+ Map<String, String> accessMap = mdons.processPnf(pnfName);
+ DroolsLog.printInfo("Access List from AAI" + accessMap.toString());
+ mdons.updateLinksForAccessService(accessMap);
+ return accessMap;
+}
+
+function void processAlarmCleared(String sourceId) {
+ AaiQueryMdons mdons = AaiQueryMdons.newInstance();
+ DroolsLog.printInfo("Alarm pnf id " + sourceId);
+ String pnfName = mdons.getPnfNameFromPnfId(sourceId);
+ DroolsLog.printInfo("Pnf name from AAI" + pnfName);
+ mdons.updatePnfOperationalStatus(pnfName, "up");
+}
+
+function PolicyMsg createPolicyMsg(VesAlarm alarm, String serviceInstanceId, String serviceName) {
+ PolicyMsg m = new PolicyMsg();
+ m.setPolicyVersion("1.0.0");
+ m.setVersion("0.0.1");
+ m.setPolicyName("mdons");
+ m.setPolicyScope("service=OTNService,type=SampleType,closedLoopControlName=ControlLoop-MDONS-2179b738-fd36-4843-a71a-a8c24c70c66b");
+ m.setClosedLoopControlName("ControlLoop-MDONS-2179b738-fd36-4843-a71a-a8c24c70c66b");
+ m.setRequestID(UUID.randomUUID().toString());
+ m.setClosedLoopAlarmStart(alarm.getStartEpochMicrosec());
+ m.setClosedLoopAlarmEnd(alarm.getLastEpochMicrosec());
+ m.setTarget("vserver.vserver-name");
+ m.setAai(getAaiObjectPolicy(serviceName, serviceInstanceId));
+
+ DmaapService.alarmUniqueRequestID.put(alarm.getEventId(), m.getRequestID());
+ return m;
+ }
+
+function Map<String, Object> getAaiObjectPolicy(String serviceName, String serviceInstanceId){
+ Map<String, Object> aaiMap = new HashMap<String, Object>();
+ aaiMap.put("service-name", serviceName);
+ aaiMap.put("request-id" , serviceInstanceId);
+ aaiMap.put("service-type" , "MDONS_OTN");
+ return aaiMap;
+}
+
+rule "Process Alarms MSA"
+ no-loop true
+ salience 200
+ when
+ $a: VesAlarm(sourceId.contains("OWBSPDRNE"),
+ rootFlag != 1, eventSeverity.equals("MAJOR"))
+ then
+ DroolsLog.printInfo("MSA Alarm: ID for alarm raised=" + $a.getEventId() + ", Event Name=" + $a.getSourceId());
+ Map<String, String> map = processAlarm($a.getSourceId() + "-XPDR1");
+ for(Map.Entry<String,String> entry : map.entrySet()){
+ PolicyMsg msg = createPolicyMsg($a, entry.getKey(), entry.getValue());
+ DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class);
+ dmaapService.publishPolicyMsg(msg, "unauthenticated.DCAE_Output_Event");
+ DroolsLog.printInfo("Published to policy=" + msg.toString());
+
+ }
+ $a.setRootFlag(1);
+
+end
+
+rule "Process Alarms TAPI"
+ no-loop true
+ salience 200
+ when
+ $a: VesAlarm(eventId.contains("FW950074SDN"),
+ rootFlag != 1, eventSeverity.equals("MINOR"))
+ then
+ DroolsLog.printInfo("TAPI Alarm: ID for alarm raised=" + $a.getEventId() + ", Event Name=" + $a.getSourceId());
+ Map<String, String> map = processAlarm($a.getEventId());
+ for(Map.Entry<String,String> entry : map.entrySet()){
+ PolicyMsg msg = createPolicyMsg($a, entry.getKey(), entry.getValue());
+ DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class);
+ dmaapService.publishPolicyMsg(msg, "unauthenticated.DCAE_Output_Event");
+ DroolsLog.printInfo("Published to policy=" + msg.toString());
+
+ }
+ $a.setRootFlag(1);
+
+end
+
+rule "Process Alarms cleared MSA"
+ no-loop true
+ salience 200
+ when
+ $a: VesAlarm(sourceId.contains("OWBSPDRNE"),
+ rootFlag != 1, eventSeverity.equals("NORMAL"))
+ then
+ DroolsLog.printInfo("MSA Alarm: ID for Alarm cleared =" + $a.getEventId() + ", Event Name=" + $a.getSourceId());
+ processAlarmCleared($a.getSourceId() + "-XPDR1");
+ $a.setRootFlag(1);
+
+end
+
+rule "Process Alarms cleared TAPI"
+ no-loop true
+ salience 200
+ when
+ $a: VesAlarm(eventId.contains("FW950074SDN"),
+ rootFlag != 1, eventSeverity.equals("NORMAL"))
+ then
+ DroolsLog.printInfo("TAPI Alarm: ID for Alarm cleared =" + $a.getEventId() + ", Event Name=" + $a.getSourceId());
+ processAlarmCleared($a.getEventId());
+ $a.setRootFlag(1);
+
+end \ No newline at end of file