From dbecba3a4baffacf9f2da82592b3e3a9e2929f21 Mon Sep 17 00:00:00 2001 From: Saravanan A Date: Mon, 10 Sep 2018 17:31:33 +0530 Subject: Add implementation for OOF PCI use case Receive DMaaP message from PCI-Handler MS with PCI Config change recommendations through DCAE_CL_OUTPUT topic. Trigger SDN-R (if allowed by policy) by sending DMaaP request through SDNR-CL topic. When the response is received from SDNR through SDNR-CL-RSP topic, just parse and print. Code review comments addressed Change-Id: If340a23ae18367b7f98e31fe79c09a09e645b2ad Issue-ID: POLICY-1089 Signed-off-by: Saravanan A --- .../src/main/resources/archetype-resources/pom.xml | 10 ++ .../src/main/config/vPCI.pcims.onset.json | 18 ++++ .../src/main/config/vPCI.sdnr.success.json | 23 +++++ .../main/resources/__closedLoopControlName__.drl | 114 +++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.pcims.onset.json create mode 100644 controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.sdnr.success.json (limited to 'controlloop/templates/archetype-cl-casablanca/src/main') diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/pom.xml b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/pom.xml index 1fc31bae2..e458ae963 100644 --- a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/pom.xml +++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/pom.xml @@ -58,6 +58,11 @@ appc ${dependenciesVersion} + + org.onap.policy.drools-applications.controlloop.common.model-impl + sdnr + ${dependenciesVersion} + org.onap.policy.drools-applications.controlloop.common.model-impl appclcm @@ -108,6 +113,11 @@ actor.appc ${dependenciesVersion} + + org.onap.policy.drools-applications.controlloop.common.actors + actor.sdnr + ${dependenciesVersion} + org.onap.policy.drools-applications.controlloop.common.actors actor.appclcm diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.pcims.onset.json b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.pcims.onset.json new file mode 100644 index 000000000..0e67d3251 --- /dev/null +++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.pcims.onset.json @@ -0,0 +1,18 @@ +{ + "closedLoopControlName": "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459", + "closedLoopAlarmStart": 1510187409180, + "closedLoopEventClient": "microservice.PCI", + "closedLoopEventStatus": "ONSET", + "requestID": "9d2d790e-a5f0-11e8-98d0-529269fb1459", + "target_type": "VNF", + "target": "generic-vnf.vnf-id", + "AAI": { + "generic-vnf.is-closed-loop-disabled": "false", + "generic-vnf.prov-status": "ACTIVE", + "generic-vnf.vnf-id": "notused" + }, + "from": "PCIMS", + "version": "1.0.2", + "Action": "ModifyConfig", + "payload": "{ \"Configurations\":[ { \"data\":{ \"FAPService\":{ \"alias\":\"Cell1\", \"X0005b9Lte\" : { \"PhyCellIdInUse\" : \"35\", \"PnfName\" : \"cu1\" }, \"CellConfig\":{ \"LTE\":{ \"RAN\":{ \"Common\":{ \"CellIdentity\":\"1\" } } } } } } } ] }" +} diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.sdnr.success.json b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.sdnr.success.json new file mode 100644 index 000000000..74d7f60bb --- /dev/null +++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/vPCI.sdnr.success.json @@ -0,0 +1,23 @@ +{ + "body": { + "output": { + "CommonHeader": { + "TimeStamp": "2018-09-10T07:10:05.614Z", + "APIver": "1.0", + "RequestID": "9d2d790e-a5f0-11e8-98d0-529269fb1459", + "SubRequestID": "1", + "RequestTrack": [], + "Flags": [] + }, + "Status": { + "Code": 200, + "Value": "SUCCESS" + }, + "Payload": "{ \"Configurations\":[ { \"Status\": { \"Code\": 200, \"Value\": \"SUCCESS\" }, \"data\":{ \"FAPService\":{ \"alias\":\"Network1\", \"X0005b9Lte\" : { \"PnfName\" : \"cu1\" }, \"CellConfig\":{ \"LTE\":{ \"RAN\":{ \"Common\":{ \"CellIdentity\":\"1\" } } } } } } } ] }" + } + }, + "version": "1.0", + "rpc-name": "ModifyConfig", + "correlation-id": "9d2d790e-a5f0-11e8-98d0-529269fb1459-1", + "type": "response" +} diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl index 0352dec10..24f70cdd9 100644 --- a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl +++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl @@ -42,6 +42,10 @@ import org.onap.policy.appclcm.LcmResponseWrapper; import org.onap.policy.appclcm.LcmRequest; import org.onap.policy.appclcm.LcmResponse; import org.onap.policy.appclcm.LcmCommonHeader; +import org.onap.policy.sdnr.PciRequestWrapper; +import org.onap.policy.sdnr.PciResponseWrapper; +import org.onap.policy.sdnr.PciRequest; +import org.onap.policy.sdnr.PciResponse; import org.onap.policy.vfc.VFCRequest; import org.onap.policy.vfc.VFCResponse; import org.onap.policy.vfc.VFCManager; @@ -535,6 +539,11 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" t.start(); } break; + case "SDNR": + if (request instanceof PciRequestWrapper) { + PolicyEngine.manager.deliver("SDNR-CL", request); + } + break; } } else { // @@ -1268,3 +1277,108 @@ rule "EVENT.CLEANUP" retract($event); end + +/* +* +* This rule responds to SDNR Response Events. +* +*/ +rule "SDNR.RESPONSE" + when + $params : ControlLoopParams( $clName : getClosedLoopControlName() ) + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) + $opTimer : OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString() ) + $lock : TargetLock (requestID == $event.getRequestId()) + $response : PciResponseWrapper( getBody().getCommonHeader().getRequestId() == $event.getRequestId() ) + then + + Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); + logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); + logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + $clName, $params.getPolicyName() + "." + drools.getRule().getName(), + $event, $manager, $operation, $lock, $operation, $opTimer, $response); + + // + // Get the result of the operation + // + PolicyResult policyResult = $operation.onResponse($response); + if (policyResult != null) { + logger.debug("{}: {}: operation finished - result={}", + $clName, $params.getPolicyName() + "." + drools.getRule().getName(), + policyResult); + + // + // This Operation has completed, construct a notification showing our results. (DB write - end operation) + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setFrom("policy"); + notification.setPolicyName($params.getPolicyName() + "." + drools.getRule().getName()); + notification.setPolicyScope($params.getPolicyScope()); + notification.setPolicyVersion($params.getPolicyVersion()); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); + if (policyResult.equals(PolicyResult.SUCCESS)) { + notification.setNotification(ControlLoopNotificationType.OPERATION_SUCCESS); + } else { + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); + } + PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); + // + // Ensure the operation is complete + // + if ($operation.isOperationComplete() == true) { + // + // It is complete, remove it from memory + // + retract($operation); + // + // We must also retract the timer object + // NOTE: We could write a Rule to do this + // + retract($opTimer); + // + // Complete the operation + // + modify($manager) {finishOperation($operation)}; + } else { + // + // Just doing this will kick off the LOCKED rule again + // + modify($operation) {}; + } + } else { + // + // Its not finished yet (i.e. expecting more Response objects) + // + // Or possibly it is a leftover response that we timed the request out previously + // + } + // + // We are going to retract these objects from memory + // + retract($response); +end + +/* +* +* Clean Up any lingering SDNR reponses. +* +*/ +rule "SDNR.RESPONSE.CLEANUP" + when + $params : ControlLoopParams( $clName : getClosedLoopControlName() ) + $response : PciResponseWrapper($id : getBody().getCommonHeader().getRequestId ) + not ( VirtualControlLoopEvent( requestId == $id, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) ) + then + + Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); + logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); + logger.debug("{}: {}: orphan sdnr response={}", + $clName, $params.getPolicyName() + "." + drools.getRule().getName(), $id); + // + // Retract it + // + retract($response); +end -- cgit 1.2.3-korg