diff options
author | Xin Miao <xin.miao@huawei.com> | 2018-10-01 18:09:24 -0500 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2018-10-05 11:32:44 -0400 |
commit | 4498fc2617e0003b7d2f53a6b09051fd216c840e (patch) | |
tree | 70238cb07b5bde82625e63f2aa3b337a05438f29 /controlloop/templates | |
parent | 8c87163466a4eb5a010a9977adf8a365faec8631 (diff) |
Add new actor SDNC to support CCVPN Closed Loop
Issue-ID: POLICY-1183
Change-Id: I1b77b5b9cefca104382d9d84dd00bbd63b20e0f2
Signed-off-by: Xin Miao <xin.miao@huawei.com>
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'controlloop/templates')
6 files changed, 216 insertions, 0 deletions
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 @@ <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> <artifactId>so</artifactId> <version>${dependenciesVersion}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> + <artifactId>sdnc</artifactId> + <version>${dependenciesVersion}</version> </dependency> <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> @@ -134,6 +139,11 @@ <version>${dependenciesVersion}</version> </dependency> <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId> + <artifactId>actor.sdnc</artifactId> + <version>${dependenciesVersion}</version> + </dependency> + <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common</groupId> <artifactId>policy-yaml</artifactId> <version>${dependenciesVersion}</version> 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 { // @@ -1166,6 +1177,83 @@ 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. * Due to a bug in the drools code, the drools timer needed to be split from most of the objects in the when clause * 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 @@ -90,6 +90,11 @@ </dependency> <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> + <artifactId>sdnc</artifactId> + <version>${dependenciesVersion}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> <artifactId>trafficgenerator</artifactId> <version>${dependenciesVersion}</version> </dependency> @@ -134,6 +139,11 @@ <version>${dependenciesVersion}</version> </dependency> <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId> + <artifactId>actor.sdnc</artifactId> + <version>${dependenciesVersion}</version> + </dependency> + <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common</groupId> <artifactId>policy-yaml</artifactId> <version>${dependenciesVersion}</version> 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 { // @@ -1137,6 +1148,79 @@ 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. * Due to a bug in the drools code, the drools timer needed to be split from most of the objects in the when clause * 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 @@ -98,6 +98,12 @@ </dependency> <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> + <artifactId>sdnc</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> <artifactId>events</artifactId> <version>${project.version}</version> <scope>provided</scope> @@ -184,6 +190,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId> + <artifactId>actor.sdnc</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> 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 @@ -98,6 +98,12 @@ </dependency> <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> + <artifactId>sdnc</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId> <artifactId>events</artifactId> <version>${project.version}</version> <scope>provided</scope> @@ -195,6 +201,12 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId> + <artifactId>actor.sdnc</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> |