- Created by user-4e793, last modified on Sep 10, 2020
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 2 Next »
To illustrate implementation of Control Loop automation using ONAP, following sections contain use case specific code belonging to main components.
Alarming Analytic
Drools rule implementing the detection of the problem
rules.drl Expand source
package ca.bell.kjar; //list any import classes here. import ca.bell.json.ves.model.CommonEventFormat3010; import ca.bell.dcae.controlloop.VirtualControlLoopEvent; import ca.bell.dcae.controlloop.ControlLoopTargetType; import ca.bell.dcae.controlloop.ControlLoopEventStatus import java.util.ArrayList; import java.util.UUID import java.util.HashMap import java.util.Map import java.math.BigDecimal; import java.util.Date; //declare any global variables here global org.apache.nifi.logging.ComponentLog LOG; function long getTimestamp(String hostname){ long timestamp = 0; int index = 0; long mult = 1; char c = hostname.charAt(hostname.length()-1-index); while(c >= '0' && c <= '9'){ timestamp += (c-'0')*mult; mult = mult*10; c = hostname.charAt(hostname.length()-1-(++index)); } return timestamp; } rule "Empty hostname" no-loop true salience 10 when $event :CommonEventFormat3010( $hostname: event.otherFields.hashMap.additionalProperties.get("hostname"), $hostname == "UNDEFINED", $pnf_id: event.commonEventHeader.sourceId ) then $event.getEvent().getOtherFields().getHashMap().setAdditionalProperty("pnfId",$pnf_id); channels["VesMessage"].send($event); retract($event); end //The 2 rules have same action and can be merged into 1 rule, but is kept separated for modular purpose rule "Check timestamp" no-loop true salience 2 when $event :CommonEventFormat3010( $hostname : event.otherFields.hashMap.additionalProperties.get("hostname"), $hostname != "UNDEFINED", $epochMilli : event.commonEventHeader.lastEpochMicrosec, ($epochMilli - getTimestamp($hostname)) >= (5*60*1000), $pnf_id: event.commonEventHeader.sourceId ) then $event.getEvent().getOtherFields().getHashMap().setAdditionalProperty("pnfId",$pnf_id); channels["VesMessage"].send($event); retract($event); end rule "No issue detected" no-loop true salience 1 when $event :CommonEventFormat3010( $hostname : event.otherFields.hashMap.additionalProperties.get("hostname"), $hostname != "UNDEFINED", $epochMilli : event.commonEventHeader.lastEpochMicrosec, ($epochMilli - getTimestamp($hostname)) < (5*60*1000) ) then retract($event); end
State Analytic
Drools rule responsible to detect a state change
rules.drl Expand source
package ca.bell.kjar; //list any import classes here. import ca.bell.json.ves.model.CommonEventFormat3010; import ca.bell.dcae.controlloop.VirtualControlLoopEvent; import ca.bell.dcae.controlloop.ControlLoopTargetType; import ca.bell.dcae.controlloop.ControlLoopEventStatus import java.util.ArrayList; import java.util.UUID import java.util.HashMap import java.util.Map import java.math.BigDecimal; import java.time.Instant; import java.util.Date; //declare any global variables here global org.apache.nifi.logging.ComponentLog LOG; declare Memory previousHostname : String end rule "Initialize memory" salience 10 when not Memory() then Memory mem = new Memory(); mem.setPreviousHostname(null); insert(mem); LOG.info("Initialized memory"); end rule "Hostname changed" no-loop true salience 2 when $mem : Memory($previousHostname : previousHostname) $event: CommonEventFormat3010( $newHostname : event.otherFields.hashMap.additionalProperties.get("hostname") != $previousHostname) then $mem.setPreviousHostname($newHostname); String stateDBvalue = "{\"hostname\" : \"" + $newHostname + "\"}"; $event.getEvent().getOtherFields().getHashMap().setAdditionalProperty("hostname",stateDBvalue); channels["VesMessage"].send($event); LOG.info("Hostname changed!"); retract($event); update($mem); end rule "Hostname unchanged" salience 3 no-loop true when $mem : Memory($previousHostname : previousHostname) $event: CommonEventFormat3010( $newHostname : event.otherFields.hashMap.additionalProperties.get("hostname") == $previousHostname || $newHostname == null) then retract($event); end
Policy
APEX policy responsible to generate the new hostname and request for CDS remediation
config/ApexConfig.json Expand source
{ "engineServiceParameters": { "name": "MyApexEngine", "version": "0.0.1", "id": 45, "instanceCount": 4, "deploymentPort": 12561, "engineParameters": { "executorParameters": { "JAVASCRIPT": { "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" } }, "contextParameters": { "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters", "schemaParameters": { "Avro": { "parameterClassName": "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters" } } }, "taskParameters": [ { "key": "logUrl", "value": "http://message-router:3904/events/POLICY-CL-MGT" } ] } }, "eventInputParameters": { "DCAEConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTCLIENT", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", "parameters": { "url": "http://message-router:3904/events/unauthenticated.DCAE_CL_OUTPUT/cl/apex?timeout=30000" } }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventName": "VesEvent", "eventNameFilter": "VesEvent" }, "AAISuccessResponseConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://aai:8443/aai/v14/network/pnfs/pnf?pnf-id={pnfId}", "httpMethod": "GET", "httpCodeFilter" : "[2][0-1][0-9]", "httpHeaders" : [ ["Accept", "application/json"], ["Content-Type", "application/json"], ["X-FromAppId", "dcae-curl"], ["x-transactionId", "9998"], ["Authorization", "Basic QUFJOkFBSQ=="] ] } }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventName": "AAISuccessResponseEvent", "eventNameFilter": "AAISuccessResponseEvent", "requestorMode": true, "requestorPeer": "AAIProducer1", "requestorTimeout": 2000 }, "AAIFailureResponseConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://aai:8443/aai/v14/network/pnfs/pnf?pnf-id={pnfId}", "httpMethod": "GET", "httpCodeFilter" : "[4-5][0-1][0-9]", "httpHeaders" : [ ["Accept", "application/json"], ["Content-Type", "application/json"], ["X-FromAppId", "dcae-curl"], ["x-transactionId", "9998"], ["Authorization", "Basic QUFJOkFBSQ=="] ] } }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventName": "AAIFailureResponseEvent", "eventNameFilter": "AAIFailureResponseEvent", "requestorMode": true, "requestorPeer": "AAIProducer2", "requestorTimeout": 2000 }, "CDSConfigModifySuccessResponseConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "GRPC", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventName": "CDSConfigModifySuccessResponseEvent", "eventNameFilter": "CDSConfigModifySuccessResponseEvent", "requestorMode": true, "requestorPeer": "CDSConfigModifyRequestProducer1", "requestorTimeout": 500 } }, "eventOutputParameters": { "AAIProducer1": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventNameFilter": "AAIRequestEvent", "requestorMode": true, "requestorPeer": "AAISuccessResponseConsumer", "requestorTimeout": 2000 }, "AAIProducer2": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventNameFilter": "AAIRequestEvent", "requestorMode": true, "requestorPeer": "AAIFailureResponseConsumer", "requestorTimeout": 2000 }, "CDSConfigModifyRequestProducer1": { "carrierTechnologyParameters": { "carrierTechnology": "GRPC", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters", "parameters": { "host": "cds-blueprints-processor-grpc", "port": 9111, "username": "ccsdkapps", "password": "ccsdkapps", "timeout": 60 } }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventNameFilter": "CDSConfigModifyRequestEvent", "requestorMode": true, "requestorPeer": "CDSConfigModifySuccessResponseConsumer", "requestorTimeout": 500 }, "CDSReplyProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTCLIENT", "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", "parameters": { "url": "http://message-router:3904/events/POLICY-CL-MGT" } }, "eventProtocolParameters": { "eventProtocol": "JSON" }, "eventNameFilter": "LogStatusEvent" }, "logOutputter": { "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { "fileName": "outputevents.log" } }, "eventProtocolParameters": { "eventProtocol": "JSON" } } } }
- No labels