From a5aaba7b73ac78a5ad03367b9cbdd3bd9151de71 Mon Sep 17 00:00:00 2001 From: Mehreen Kaleem Date: Tue, 30 Jun 2020 17:18:56 +0000 Subject: Drools Rule file for MDONS use case Change-Id: Iec9416b83e7e112875942b160a5aa480389ddc88 Issue-ID: HOLMES-312 Signed-off-by: Mehreen Kaleem --- rules/mdons-rule.drl | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 rules/mdons-rule.drl 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 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 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 getAaiObjectPolicy(String serviceName, String serviceInstanceId){ + Map aaiMap = new HashMap(); + 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 map = processAlarm($a.getSourceId() + "-XPDR1"); + for(Map.Entry 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 map = processAlarm($a.getEventId()); + for(Map.Entry 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 -- cgit 1.2.3-korg