From 1aa30b7d83f97103097c7f5d3e4cbd2fad92f659 Mon Sep 17 00:00:00 2001 From: Ritu Sood Date: Mon, 11 Sep 2017 14:20:13 -0700 Subject: Add VFC Response in Working Memory & JUNIT Adding code to insert VFC reponse in working memory and handling that response. Also adding JUNIT and yaml file for VoLTE usecase. Issue-Id: POLICY-212 Change-Id: I74a13272ccd931478d27d80715d8c3ac756fb5c7 Signed-off-by: Ritu Sood --- .../resources/ControlLoop_Template_xacml_guard.drl | 92 ++++++++++++++++++++-- 1 file changed, 86 insertions(+), 6 deletions(-) (limited to 'controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl') 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 { // @@ -1002,6 +1003,85 @@ rule "${policyName}.SO.RESPONSE" 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. -- cgit 1.2.3-korg