diff options
Diffstat (limited to 'controlloop/templates/archetype-cl-amsterdam/src')
2 files changed, 98 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 * |