From 4498fc2617e0003b7d2f53a6b09051fd216c840e Mon Sep 17 00:00:00 2001 From: Xin Miao Date: Mon, 1 Oct 2018 18:09:24 -0500 Subject: Add new actor SDNC to support CCVPN Closed Loop Issue-ID: POLICY-1183 Change-Id: I1b77b5b9cefca104382d9d84dd00bbd63b20e0f2 Signed-off-by: Xin Miao Signed-off-by: Pamela Dragosh --- .../src/main/resources/archetype-resources/pom.xml | 10 +++ .../main/resources/__closedLoopControlName__.drl | 88 ++++++++++++++++++++++ .../src/main/resources/archetype-resources/pom.xml | 10 +++ .../main/resources/__closedLoopControlName__.drl | 84 +++++++++++++++++++++ controlloop/templates/template.demo.clc/pom.xml | 12 +++ controlloop/templates/template.demo/pom.xml | 12 +++ 6 files changed, 216 insertions(+) (limited to 'controlloop/templates') diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/pom.xml b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/pom.xml index ecbf90399..f39acc1fe 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/pom.xml +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/pom.xml @@ -72,6 +72,11 @@ org.onap.policy.drools-applications.controlloop.common.model-impl so ${dependenciesVersion} + + + org.onap.policy.drools-applications.controlloop.common.model-impl + sdnc + ${dependenciesVersion} org.onap.policy.drools-applications.controlloop.common.model-impl @@ -133,6 +138,11 @@ actor.vfc ${dependenciesVersion} + + org.onap.policy.drools-applications.controlloop.common.actors + actor.sdnc + ${dependenciesVersion} + org.onap.policy.drools-applications.controlloop.common policy-yaml diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl index 9a1a29239..5e49010d7 100644 --- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl +++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl @@ -56,6 +56,9 @@ import org.onap.policy.so.SORelatedInstanceListElement; import org.onap.policy.so.SORelatedInstance; import org.onap.policy.so.SOResponse; import org.onap.policy.so.SOResponseWrapper; +import org.onap.policy.sdnc.SdncRequest; +import org.onap.policy.sdnc.SdncManager; +import org.onap.policy.sdnc.SdncResponse; import org.onap.policy.guard.PolicyGuard; import org.onap.policy.guard.PolicyGuard.LockResult; import org.onap.policy.guard.TargetLock; @@ -580,6 +583,14 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" t.start(); } break; + + case "SDNC": + if (request instanceof SdncRequest) { + // Start SDNC thread + Thread t = new Thread(new SdncManager(drools.getWorkingMemory(), (SdncRequest)request)); + t.start(); + } + break; } } else { // @@ -1164,6 +1175,83 @@ rule "${policyName}.VFC.RESPONSE" end +/* +* +* This rule responds to SDNC Response Events +* +*/ + +rule "${policyName}.SDNC.RESPONSE" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), + closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + onset.getRequestId() == $event.getRequestId() ) + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId().toString(), timerType == "Operation", !expired ) + $lock : TargetLock (requestID == $event.getRequestId()) + $response : SdncResponse( requestId.toString() == $event.getRequestId().toString() ) + then + Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); + logger.info("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName()); + logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + $params.getClosedLoopControlName(), drools.getRule().getName(), + $event, $manager, $operation, $lock, $operation, $opTimer, $response); + + // Get the result of the operation + // + PolicyResult policyResult = $operation.onResponse($response); + if (policyResult != null) { + // + // This Operation has completed, construct a notification showing our results + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); + // + // Ensure the operation is complete + // + if ($operation.isOperationComplete()) { + // + // 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 + /* * * This manages a single timer. 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 aa56082bd..e44ebb20e 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 @@ -88,6 +88,11 @@ sdnr ${dependenciesVersion} + + org.onap.policy.drools-applications.controlloop.common.model-impl + sdnc + ${dependenciesVersion} + org.onap.policy.drools-applications.controlloop.common.model-impl trafficgenerator @@ -133,6 +138,11 @@ actor.vfc ${dependenciesVersion} + + org.onap.policy.drools-applications.controlloop.common.actors + actor.sdnc + ${dependenciesVersion} + org.onap.policy.drools-applications.controlloop.common policy-yaml 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 f2fe23162..11855d47d 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 @@ -61,6 +61,9 @@ import org.onap.policy.so.SORelatedInstanceListElement; import org.onap.policy.so.SORelatedInstance; import org.onap.policy.so.SOResponse; import org.onap.policy.so.SOResponseWrapper; +import org.onap.policy.sdnc.SdncRequest; +import org.onap.policy.sdnc.SdncManager; +import org.onap.policy.sdnc.SdncResponse; import org.onap.policy.guard.PolicyGuard; import org.onap.policy.guard.PolicyGuard.LockResult; import org.onap.policy.guard.TargetLock; @@ -550,6 +553,14 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" PolicyEngine.manager.deliver("SDNR-CL", request); } break; + + case "SDNC": + if (request instanceof SdncRequest) { + // Start SDNC thread + Thread t = new Thread(new SdncManager(drools.getWorkingMemory(), (SdncRequest)request)); + t.start(); + } + break; } } else { // @@ -1135,6 +1146,79 @@ rule "VFC.RESPONSE" end +/* +* +* This rule responds to SDNC Response Events +* +*/ +rule "SDNC.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 : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId().toString(), timerType == "Operation", !expired ) + $lock : TargetLock (requestID == $event.getRequestId()) + $response : SdncResponse( requestId.toString() == $event.getRequestId().toString() ) + 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) { + // + // This Operation has completed, construct a notification showing our results + // + 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()); + // + // Ensure the operation is complete + // + if ($operation.isOperationComplete()) { + // + // 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 + /* * * This manages a single timer. diff --git a/controlloop/templates/template.demo.clc/pom.xml b/controlloop/templates/template.demo.clc/pom.xml index 9295d78f7..574d1ced2 100644 --- a/controlloop/templates/template.demo.clc/pom.xml +++ b/controlloop/templates/template.demo.clc/pom.xml @@ -96,6 +96,12 @@ ${project.version} provided + + org.onap.policy.drools-applications.controlloop.common.model-impl + sdnc + ${project.version} + provided + org.onap.policy.drools-applications.controlloop.common.model-impl events @@ -183,6 +189,12 @@ ${project.version} provided + + org.onap.policy.drools-applications.controlloop.common.actors + actor.sdnc + ${project.version} + provided + junit junit diff --git a/controlloop/templates/template.demo/pom.xml b/controlloop/templates/template.demo/pom.xml index 6b1302240..138bfc735 100644 --- a/controlloop/templates/template.demo/pom.xml +++ b/controlloop/templates/template.demo/pom.xml @@ -96,6 +96,12 @@ ${project.version} provided + + org.onap.policy.drools-applications.controlloop.common.model-impl + sdnc + ${project.version} + provided + org.onap.policy.drools-applications.controlloop.common.model-impl events @@ -194,6 +200,12 @@ ${project.version} provided + + org.onap.policy.drools-applications.controlloop.common.actors + actor.sdnc + ${project.version} + provided + junit junit -- cgit 1.2.3-korg