From cc95aa4f9966f014f45e32f177bf622b3ef7a8b7 Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Mon, 10 Sep 2018 14:47:40 +0800 Subject: Correted UT Coverage Issues Change-Id: Id89d4c600683646958e7e0b4b2982506e1bf7db4 Issue-ID: HOLMES-159 Signed-off-by: GuangrongFu --- rules/ccvnp-rule.drl | 184 --------------------------------------------------- rules/ccvpn-rule.drl | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+), 184 deletions(-) delete mode 100644 rules/ccvnp-rule.drl create mode 100644 rules/ccvpn-rule.drl (limited to 'rules') diff --git a/rules/ccvnp-rule.drl b/rules/ccvnp-rule.drl deleted file mode 100644 index e006dbb..0000000 --- a/rules/ccvnp-rule.drl +++ /dev/null @@ -1,184 +0,0 @@ -package org.onap.holmes.ccvpn; - -dialect "java" - -import org.onap.holmes.common.api.stat.VesAlarm; -import org.onap.holmes.common.api.stat.AlarmAdditionalField; -import org.onap.holmes.common.aai.AaiQuery4Ccvpn; -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 String getAdditionalField(VesAlarm a, String field) { - List fields = a.getAlarmAdditionalInformation(); - for (AlarmAdditionalField f : fields) { - if (f.getName().equals(field)) { - return f.getValue(); - } - } - return null; -} - -function String getLogicLink(VesAlarm alarm) { - AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); - return aai.getLogicLink( - getAdditionalField(alarm, "networkId"), - getAdditionalField(alarm, "node"), - getAdditionalField(alarm, "tp-id"), - null - ); -} - -function boolean isCorrelated(VesAlarm a, VesAlarm b) { - String logicLinkA = getLogicLink(a); - if (logicLinkA == null) { - return false; - } - - String logicLinkB = getLogicLink(b); - if (logicLinkB == null) { - return false; - } - - return logicLinkA.equals(logicLinkB); -} - -function void updateAaiLinkStatus(String linkName, String status) { - AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); - Map body = new HashMap(){ - { - put("operational-status", status); - } - }; - aai.updateLogicLinkStatus(linkName, body); -} - -function void updateAaiTpStatus(String networkId, String pnfName, String ifName, String status) { - AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); - Map body = new HashMap(){ - { - put("operational-status", status); - } - }; - aai.updateTerminalPointStatus(networkId, pnfName, ifName, body); -} - -function Map getAdditionalResourceInfo(String networkId, String pnfName, String ifName, String status) { - AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); - JSONArray instances = aai.getServiceInstances(networkId, pnfName, ifName, status); - - Map ret = new HashMap(); - - StringBuilder sbn = new StringBuilder(); - StringBuilder sbi = new StringBuilder(); - for(int i = 0; i < instances.size(); ++i) { - JSONObject o = instances.getJSONObject(i); - String name = o.getString("service-instance-name"); - String id = o.getString("service-instance-id"); - ret.put(id + ".input-parameters", o.getString("input-parameters")); - sbn.append(name).append(","); - sbi.append(id).append(","); - } - ret.put("service-instance.service-instance-name", sbn.substring(0, sbn.length() -1).toString()); - ret.put("service-instance.service-instance-id", sbi.substring(0, sbi.length() -1).toString()); - ret.put("vserver.vserver-name", "TBD"); - ret.put("globalSubscriberId", instances.getJSONObject(0).getString("globalSubscriberId")); - ret.put("serviceType", instances.getJSONObject(0).getString("serviceType")); - - return ret; -} - -function PolicyMsg createPolicyMsg(VesAlarm alarm) { - PolicyMsg m = new PolicyMsg(); - m.setPolicyVersion("1.0.0.5"); - m.setPolicyName("CCVPN"); - m.setPolicyScope("service=SOTNService,type=SampleType,closedLoopControlName=CL-CCVPN-d925ed73-8231-4d02-9545-db4e101f88f8"); - m.setClosedLoopControlName(DmaapService.loopControlNames.get("org.onap.holmes.ccvpn")); - m.setRequestID(UUID.randomUUID().toString()); - m.setClosedLoopAlarmStart(alarm.getStartEpochMicrosec()); - m.setClosedLoopAlarmEnd(alarm.getLastEpochMicrosec()); - m.setTarget("vserver.vserver-name"); - m.setAai(getAdditionalResourceInfo( - getAdditionalField(alarm, "networkId"), - getAdditionalField(alarm, "node"), - getAdditionalField(alarm, "tp-id"), - getAdditionalField(alarm, "oper-status") - )); - - DmaapService.alarmUniqueRequestID.put(alarm.getEventId(), m.getRequestID()); - - return m; -} - -rule "Update AAI Information" - no-loop true - salience 300 - when - $a: VesAlarm(eventName.indexOf("Fault_Route_Status") != -1) - then - updateAaiTpStatus ( - getAdditionalField($a, "networkId"), - getAdditionalField($a, "node"), - getAdditionalField($a, "tp-id"), - getAdditionalField($a, "oper-status") - ); -end - -rule "Set Up Correlation" - no-loop true - salience 200 - when - $a: VesAlarm($id: eventId, - $start: startEpochMicrosec, - eventName.indexOf("Fault_Route_Status") != -1) - $b: VesAlarm(eventId != $id, - eventName.indexOf("Fault_Route_Status") != -1, - Math.abs(startEpochMicrosec - $start) < 60000) - then - String status = "down"; - if (status.equalsIgnoreCase(getAdditionalField($a, "oper-status")) - && status.equalsIgnoreCase(getAdditionalField($b, "oper-status"))) { - if (isCorrelated($a, $b)){ - // If any of the alarms have been marked as root, a policy message has ever been created and sent. Do NOT send it again. - if ($a.getRootFlag() != 1 && $b.getRootFlag() != 1) { - PolicyMsg msg = createPolicyMsg($a); - DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class); - dmaapService.publishPolicyMsg(msg, "unauthenticated.DCAE_CL_OUTPUT"); - updateAaiLinkStatus(getLogicLink($a), status); - } - $a.setRootFlag(1); - $b.setRootFlag(1); - update($a); - update($b); - } - } -end - -rule "Clear Alarms" - no-loop true - salience 100 - when - $a: VesAlarm(eventName.indexOf("Fault_Route_Status") != -1) - then - if ("up".equalsIgnoreCase(getAdditionalField($a, "oper-status"))) { - if (DmaapService.alarmUniqueRequestID.containsKey($a.getEventId())) { - DmaapService.alarmUniqueRequestID.remove($a.getEventId()); - } - - //TODO: send alarm clearing message to Policy - for now it's not needed. - //... - - retract($a); - } -end \ No newline at end of file diff --git a/rules/ccvpn-rule.drl b/rules/ccvpn-rule.drl new file mode 100644 index 0000000..e006dbb --- /dev/null +++ b/rules/ccvpn-rule.drl @@ -0,0 +1,184 @@ +package org.onap.holmes.ccvpn; + +dialect "java" + +import org.onap.holmes.common.api.stat.VesAlarm; +import org.onap.holmes.common.api.stat.AlarmAdditionalField; +import org.onap.holmes.common.aai.AaiQuery4Ccvpn; +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 String getAdditionalField(VesAlarm a, String field) { + List fields = a.getAlarmAdditionalInformation(); + for (AlarmAdditionalField f : fields) { + if (f.getName().equals(field)) { + return f.getValue(); + } + } + return null; +} + +function String getLogicLink(VesAlarm alarm) { + AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); + return aai.getLogicLink( + getAdditionalField(alarm, "networkId"), + getAdditionalField(alarm, "node"), + getAdditionalField(alarm, "tp-id"), + null + ); +} + +function boolean isCorrelated(VesAlarm a, VesAlarm b) { + String logicLinkA = getLogicLink(a); + if (logicLinkA == null) { + return false; + } + + String logicLinkB = getLogicLink(b); + if (logicLinkB == null) { + return false; + } + + return logicLinkA.equals(logicLinkB); +} + +function void updateAaiLinkStatus(String linkName, String status) { + AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); + Map body = new HashMap(){ + { + put("operational-status", status); + } + }; + aai.updateLogicLinkStatus(linkName, body); +} + +function void updateAaiTpStatus(String networkId, String pnfName, String ifName, String status) { + AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); + Map body = new HashMap(){ + { + put("operational-status", status); + } + }; + aai.updateTerminalPointStatus(networkId, pnfName, ifName, body); +} + +function Map getAdditionalResourceInfo(String networkId, String pnfName, String ifName, String status) { + AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); + JSONArray instances = aai.getServiceInstances(networkId, pnfName, ifName, status); + + Map ret = new HashMap(); + + StringBuilder sbn = new StringBuilder(); + StringBuilder sbi = new StringBuilder(); + for(int i = 0; i < instances.size(); ++i) { + JSONObject o = instances.getJSONObject(i); + String name = o.getString("service-instance-name"); + String id = o.getString("service-instance-id"); + ret.put(id + ".input-parameters", o.getString("input-parameters")); + sbn.append(name).append(","); + sbi.append(id).append(","); + } + ret.put("service-instance.service-instance-name", sbn.substring(0, sbn.length() -1).toString()); + ret.put("service-instance.service-instance-id", sbi.substring(0, sbi.length() -1).toString()); + ret.put("vserver.vserver-name", "TBD"); + ret.put("globalSubscriberId", instances.getJSONObject(0).getString("globalSubscriberId")); + ret.put("serviceType", instances.getJSONObject(0).getString("serviceType")); + + return ret; +} + +function PolicyMsg createPolicyMsg(VesAlarm alarm) { + PolicyMsg m = new PolicyMsg(); + m.setPolicyVersion("1.0.0.5"); + m.setPolicyName("CCVPN"); + m.setPolicyScope("service=SOTNService,type=SampleType,closedLoopControlName=CL-CCVPN-d925ed73-8231-4d02-9545-db4e101f88f8"); + m.setClosedLoopControlName(DmaapService.loopControlNames.get("org.onap.holmes.ccvpn")); + m.setRequestID(UUID.randomUUID().toString()); + m.setClosedLoopAlarmStart(alarm.getStartEpochMicrosec()); + m.setClosedLoopAlarmEnd(alarm.getLastEpochMicrosec()); + m.setTarget("vserver.vserver-name"); + m.setAai(getAdditionalResourceInfo( + getAdditionalField(alarm, "networkId"), + getAdditionalField(alarm, "node"), + getAdditionalField(alarm, "tp-id"), + getAdditionalField(alarm, "oper-status") + )); + + DmaapService.alarmUniqueRequestID.put(alarm.getEventId(), m.getRequestID()); + + return m; +} + +rule "Update AAI Information" + no-loop true + salience 300 + when + $a: VesAlarm(eventName.indexOf("Fault_Route_Status") != -1) + then + updateAaiTpStatus ( + getAdditionalField($a, "networkId"), + getAdditionalField($a, "node"), + getAdditionalField($a, "tp-id"), + getAdditionalField($a, "oper-status") + ); +end + +rule "Set Up Correlation" + no-loop true + salience 200 + when + $a: VesAlarm($id: eventId, + $start: startEpochMicrosec, + eventName.indexOf("Fault_Route_Status") != -1) + $b: VesAlarm(eventId != $id, + eventName.indexOf("Fault_Route_Status") != -1, + Math.abs(startEpochMicrosec - $start) < 60000) + then + String status = "down"; + if (status.equalsIgnoreCase(getAdditionalField($a, "oper-status")) + && status.equalsIgnoreCase(getAdditionalField($b, "oper-status"))) { + if (isCorrelated($a, $b)){ + // If any of the alarms have been marked as root, a policy message has ever been created and sent. Do NOT send it again. + if ($a.getRootFlag() != 1 && $b.getRootFlag() != 1) { + PolicyMsg msg = createPolicyMsg($a); + DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class); + dmaapService.publishPolicyMsg(msg, "unauthenticated.DCAE_CL_OUTPUT"); + updateAaiLinkStatus(getLogicLink($a), status); + } + $a.setRootFlag(1); + $b.setRootFlag(1); + update($a); + update($b); + } + } +end + +rule "Clear Alarms" + no-loop true + salience 100 + when + $a: VesAlarm(eventName.indexOf("Fault_Route_Status") != -1) + then + if ("up".equalsIgnoreCase(getAdditionalField($a, "oper-status"))) { + if (DmaapService.alarmUniqueRequestID.containsKey($a.getEventId())) { + DmaapService.alarmUniqueRequestID.remove($a.getEventId()); + } + + //TODO: send alarm clearing message to Policy - for now it's not needed. + //... + + retract($a); + } +end \ No newline at end of file -- cgit 1.2.3-korg