...
To illustrate, the content field in the above rule is presented as readable format in the following. We need to convert it to valid json string when uploading to Holmes.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
package org.onap.holmes.droolsRuleccvpn; dialect "java" import org.onap.holmes.common.api.dmaapstat.DmaapServiceVesAlarm; import org.onap.holmes.common.api.stat.VesAlarmAlarmAdditionalField; import org.onap.holmes.common.aai.CorrelationUtil.AaiQuery4Ccvpn; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.dropwizard.ioc.dmaap.DmaapService; import org.onap.holmes.common.utils.ServiceLocatorHolderDroolsLog; import org.onap.holmes.common.dropwizard.ioc.utils.DroolsLogServiceLocatorHolder; import com.alibaba.fastjson.JSONArray; rule "Relation_analysis_Rule" salience 200 no-loop true when $root : VesAlarm(alarmIsCleared == 0, $sourceId: sourceId, sourceId != null && !sourceId.equals(""), $sourceName: sourceName, sourceName != null && !sourceName.equals(""), $startEpochMicrosec: startEpochMicrosec, specificProblem in ("Fault_SOTN_Service_Failure"), $eventId: eventId) $child : VesAlarm( eventId != $eventId, parentId == null, specificProblem in ("Fault_SOTN_Service_Failure"), startEpochMicrosec < $startEpochMicrosec + 60000 && startEpochMicrosec > $startEpochMicrosec - 60000 ) then $child.setParentId($root.getEventId()); update($child); end rule "root_has_child_handle_Rule" salience 150 no-loop true when $root : VesAlarm(alarmIsCleared == 0, rootFlag == 0, $eventId: eventId) $child : VesAlarm(eventId != $eventId, parentId == $eventId) then DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class); PolicyMsg policyMsg = dmaapService.getPolicyMsg($root, $child, "org.onap.holmes.droolsRule"); dmaapService.publishPolicyMsg(policyMsg, "unauthenticated.DCAE_CL_OUTPUT"); $root.setRootFlag(1); update($root); end rule "root_no_child_handle_Rule" salience 100 no-loop true when $root : VesAlarm(alarmIsCleared == 0, rootFlag == 0, sourceId != null && !sourceId.equals(""), sourceName != null && !sourceName.equals(""), specificProblem in ("Fault_SOTN_Service_Failure")) then DmaapService dmaapService = ServiceLocatorHolder.getLocator().getService(DmaapService.class); PolicyMsg policyMsg = dmaapService.getPolicyMsg($root, null, "org.onap.holmes.droolsRule"); dmaapService.publishPolicyMsg(policyMsg, "unauthenticated.DCAE_CL_OUTPUT"); $root.setRootFlag(1); update($root); nend rule "root_cleared_handle_Rule" salience 100 no-loop true when $root : VesAlarm(alarmIsCleared == 1, rootFlag == 1) then 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<AlarmAdditionalField> 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"), getAdditionalField(alarm, "oper-status") ); } 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 updateAaiStatus(String networkId, String pnfName, String ifName, String linkName, String status) { AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); Map<String, Object> body = new HashMap<String, Object>(){ { put("operational-status", status); } }; aai.updateLogicLinkStatus(linkName, body); aai.updateTerminalPointStatus(networkId, pnfName, ifName, body); } function Map<String, Object> getAdditionalResourceInfo(String networkId, String pnfName, String ifName, String status) { AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); JSONArray instances = aai.getServiceInstances(networkId, pnfName, ifName, status); Map<String, Object> ret = new HashMap<String, Object>(); StringBuilder sb = new StringBuilder(); for(int i = 0; i < instances.size(); ++i) { JSONObject o = instances.getJSONObject(i); String name = o.getString("service-instance-name"); ret.put(name + ".input-parameters", o.getString("input-parameters")); sb.append(name).append(","); } ret.put("service-instance.service-instance-name", sb.substring(0, sb.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 updateAaiStatus ( getAdditionalField($a, "networkId"), getAdditionalField($a, "node"), getAdditionalField($a, "tp-id"), getLogicLink($a), 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 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); PolicyMsg policyMsg = dmaapService.getPolicyMsg($root, nullpublishPolicyMsg(msg, "org.onap.holmes.droolsRuleunauthenticated.DCAE_CL_OUTPUT"); } dmaapService$a.publishPolicyMsg(policyMsg, "unauthenticated.DCAE_CL_OUTPUT"); setRootFlag(1); $b.setRootFlag(1); update($a); retractupdate($root$b); end rule "child_handle_Rule" salience 100 no-loop true when $child : VesAlarm(alarmIsCleared == 1, rootFlag == 0) then retract($child } end rule "Clear Alarms" no-loop true salience 100 when $a: VesAlarm(alarmIsCleared == 1, eventName.indexOf("Fault_Route_Status") != -1) then 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 |
Rule Execution
After the correlation is done successfully, there should be a corresponding control loop event defined in the following section published on the unauthenticated.DCAE_CL_OUTPUT topic of DMaaP.
...