diff options
author | 2017-09-22 15:08:34 +0000 | |
---|---|---|
committer | 2017-09-22 15:08:34 +0000 | |
commit | 7d39eea7a0537b4a1dd6f0d1ac9d30b268e1d91d (patch) | |
tree | bd84bd4e32f6f3ff3ec48d56bc01a86adbfd2530 /controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl | |
parent | b2b8f46ab3a524eae487fa932d9ceb2b884a68f5 (diff) | |
parent | 1aa30b7d83f97103097c7f5d3e4cbd2fad92f659 (diff) |
Merge "Add VFC Response in Working Memory & JUNIT"
Diffstat (limited to 'controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl')
-rw-r--r-- | controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl | 92 |
1 files changed, 86 insertions, 6 deletions
diff --git a/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl b/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl index ff184b385..b506d8910 100644 --- a/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl +++ b/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl @@ -38,6 +38,7 @@ import org.onap.policy.appclcm.LCMRequest; import org.onap.policy.appclcm.LCMResponse; import org.onap.policy.appclcm.LCMCommonHeader; import org.onap.policy.vfc.VFCRequest; +import org.onap.policy.vfc.VFCResponse; import org.onap.policy.vfc.VFCManager; import org.onap.policy.so.SOManager; import org.onap.policy.so.SORequest; @@ -521,12 +522,12 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" } break; case "VFC": - if (request instanceof VFCRequest) { - // Start VFC thread - Thread t = new Thread(new VFCManager((VFCRequest)request)); - t.start(); - } - break; + if (request instanceof VFCRequest) { + // Start VFC thread + Thread t = new Thread(new VFCManager(drools.getWorkingMemory(), (VFCRequest)request)); + t.start(); + } + break; } } else { // @@ -1004,6 +1005,85 @@ end /* * +* This rule responds to VFC Response Events +* +*/ +rule "${policyName}.VFC.RESPONSE" + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) + $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) + $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) + $lock : TargetLock (requestID == $event.requestID) + $response : VFCResponse( requestId.toString() == $event.requestID.toString() ) + then + // + // Logging + Logger.info("------------------------------------------------------------------------------------------------"); + Logger.metrics(Instant.now() + " " + drools.getRule().getName() + " " + drools.getRule().getPackage()); + Logger.metrics($params); + Logger.metrics($event); + Logger.metrics($manager); + Logger.metrics($operation); + Logger.metrics($opTimer); + Logger.metrics($lock); + Logger.metrics($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.from = "policy"; + notification.policyName = drools.getRule().getName(); + notification.policyScope = "${policyScope}"; + notification.policyVersion = "${policyVersion}"; + notification.message = $operation.getOperationHistory(); + notification.history = $operation.getHistory(); + // + // 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 + + + +/* +* * This is the timer that manages the timeout for an individual operation. * */ |