From a24a985d328b97f50a41d3448d235866af625ca9 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 21 Sep 2018 20:08:11 -0400 Subject: Fix checkstyle declarations I fixed what I thought would be tolerable for this release. Same issue as policy/common I had to defined the checkstyle in each repo where the suppressions were needed. Issue-ID: POLICY-1135 Change-Id: I8f30bee7e9cddc692ddad3cf88acedb2e6b4781b Signed-off-by: Pamela Dragosh --- .../main/resources/__closedLoopControlName__.drl | 591 +++++++++++---------- 1 file changed, 318 insertions(+), 273 deletions(-) (limited to 'controlloop/templates/archetype-cl-amsterdam') 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 87a477406..9a1a29239 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 @@ -31,7 +31,7 @@ import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NEW_EVENT_STATUS; import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager; -import org.onap.policy.controlloop.actor.so.SOActorServiceProvider; +import org.onap.policy.controlloop.actor.so.SoActorServiceProvider; import org.onap.policy.aai.AaiNqResponseWrapper; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -128,7 +128,8 @@ end rule "${policyName}.SETUP" salience 1 when - not( Params( getClosedLoopControlName() == "${closedLoopControlName}", getControlLoopYaml() == "${controlLoopYaml}" ) ) + not( Params( getClosedLoopControlName() == "${closedLoopControlName}", + getControlLoopYaml() == "${controlLoopYaml}" ) ) then Params params = new Params(); @@ -140,7 +141,8 @@ rule "${policyName}.SETUP" // hence explicitly getting the logger vs using a global Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", params.getClosedLoopControlName(), drools.getRule().getName(), params.getControlLoopYaml()); + logger.info("{}: {} : YAML=[{}]", params.getClosedLoopControlName(), drools.getRule().getName(), + params.getControlLoopYaml()); end /* @@ -153,7 +155,8 @@ rule "${policyName}.EVENT" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - not ( ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) ) + not ( ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId() ) ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -185,14 +188,16 @@ rule "${policyName}.EVENT" // retract($event); } else if ($event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET) { - throw new ControlLoopException($event.getClosedLoopEventStatus() + " received with no prior onset"); + throw new ControlLoopException($event.getClosedLoopEventStatus() + " received with no prior onset"); } else { // // Create an EventManager // - ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), $event.getRequestId()); + ControlLoopEventManager manager = new ControlLoopEventManager($params.getClosedLoopControlName(), + $event.getRequestId()); // - // Determine if EventManager can actively process the event (i.e. syntax, is_closed_loop_disabled checks etc.) + // Determine if EventManager can actively process the event + // (i.e. syntax, is_closed_loop_disabled checks etc.) // VirtualControlLoopNotification notification = manager.activate($params.getControlLoopYaml(), $event); notification.setFrom("pdp-0001-controller=controlloop"); // Engine.getInstanceName() @@ -270,8 +275,10 @@ rule "${policyName}.EVENT.MANAGER" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) - $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString(), timerType == "ClosedLoop", !expired ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId() ) + $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId().toString(), timerType == "ClosedLoop", !expired ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -280,47 +287,47 @@ rule "${policyName}.EVENT.MANAGER" $event, $manager, $clTimer); try { - // - // Check which event this is. - // - ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event); - // - // Check what kind of event this is - // - if (eventStatus == NEW_EVENT_STATUS.SUBSEQUENT_ONSET) { - // - // We don't care about subsequent onsets - // - logger.info("{}: {}: subsequent onset", - $params.getClosedLoopControlName(), drools.getRule().getName()); - retract($event); - return; - } - if (eventStatus == NEW_EVENT_STATUS.SYNTAX_ERROR) { - // - // Ignore any bad syntax events - // - logger.warn("{}: {}: syntax error", - $params.getClosedLoopControlName(), drools.getRule().getName()); - retract($event); - return; - } - // - // We only want the initial ONSET event in memory, - // all the other events need to be retracted to support - // cleanup and avoid the other rules being fired for this event. - // - if (eventStatus != NEW_EVENT_STATUS.FIRST_ONSET) { - logger.warn("{}: {}: not first onset", - $params.getClosedLoopControlName(), drools.getRule().getName()); - retract($event); - } - - logger.debug("{}: {}: target={}", $params.getClosedLoopControlName(), - drools.getRule().getName(), $event.getTarget()); - // - // Now start seeing if we need to process this event - // + // + // Check which event this is. + // + ControlLoopEventManager.NEW_EVENT_STATUS eventStatus = $manager.onNewEvent($event); + // + // Check what kind of event this is + // + if (eventStatus == NEW_EVENT_STATUS.SUBSEQUENT_ONSET) { + // + // We don't care about subsequent onsets + // + logger.info("{}: {}: subsequent onset", + $params.getClosedLoopControlName(), drools.getRule().getName()); + retract($event); + return; + } + if (eventStatus == NEW_EVENT_STATUS.SYNTAX_ERROR) { + // + // Ignore any bad syntax events + // + logger.warn("{}: {}: syntax error", + $params.getClosedLoopControlName(), drools.getRule().getName()); + retract($event); + return; + } + // + // We only want the initial ONSET event in memory, + // all the other events need to be retracted to support + // cleanup and avoid the other rules being fired for this event. + // + if (eventStatus != NEW_EVENT_STATUS.FIRST_ONSET) { + logger.warn("{}: {}: not first onset", + $params.getClosedLoopControlName(), drools.getRule().getName()); + retract($event); + } + + logger.debug("{}: {}: target={}", $params.getClosedLoopControlName(), + drools.getRule().getName(), $event.getTarget()); + // + // Now start seeing if we need to process this event + // // // Check if this is a Final Event @@ -426,46 +433,45 @@ rule "${policyName}.EVENT.MANAGER" $params.getClosedLoopControlName(), drools.getRule().getName(), result.getB()); if (result.getA().equals(GuardResult.LOCK_ACQUIRED)) { - // - // insert the operation into memory - // - insert(operation); - - // - // insert operation timeout object - // - ControlLoopTimer opTimer = new ControlLoopTimer(); - opTimer.setTimerType("Operation"); - opTimer.setClosedLoopControlName($event.getClosedLoopControlName()); - opTimer.setRequestID($event.getRequestId().toString()); - opTimer.setDelay(operation.getOperationTimeout().toString() + "s"); - insert(opTimer); + // + // insert the operation into memory + // + insert(operation); + // + // insert operation timeout object + // + ControlLoopTimer opTimer = new ControlLoopTimer(); + opTimer.setTimerType("Operation"); + opTimer.setClosedLoopControlName($event.getClosedLoopControlName()); + opTimer.setRequestID($event.getRequestId().toString()); + opTimer.setDelay(operation.getOperationTimeout().toString() + "s"); + insert(opTimer); - // - // Insert lock into memory - // - insert(result.getB()); - } - else { - logger.debug("The target resource {} is already processing", - $event.getAai().get($event.getTarget())); - notification = new VirtualControlLoopNotification($event); - notification.setNotification(ControlLoopNotificationType.REJECTED); - notification.setMessage("The target " + $event.getAai().get($event.getTarget()) + " is already locked"); - notification.setFrom("policy"); - notification.setPolicyName(drools.getRule().getName()); - notification.setPolicyScope("${policyScope}"); - notification.setPolicyVersion("${policyVersion}"); + // + // Insert lock into memory + // + insert(result.getB()); + } else { + logger.debug("The target resource {} is already processing", + $event.getAai().get($event.getTarget())); + notification = new VirtualControlLoopNotification($event); + notification.setNotification(ControlLoopNotificationType.REJECTED); + notification.setMessage("The target " + $event.getAai().get($event.getTarget()) + + " is already locked"); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); - PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); - - retract($event); - retract($manager); - retract($clTimer); - - if(result.getB() != null) { - retract(result.getB()); - } + PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); + + retract($event); + retract($manager); + retract($clTimer); + + if (result.getB() != null) { + retract(result.getB()); + } } logger.info("{}: {}: starting operation={}", $params.getClosedLoopControlName(), drools.getRule().getName(), @@ -479,23 +485,23 @@ rule "${policyName}.EVENT.MANAGER" } } } catch (Exception e) { - logger.warn("{}: {}: unexpected", + logger.warn("{}: {}: unexpected", $params.getClosedLoopControlName(), drools.getRule().getName(), e); - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE); - notification.setMessage(e.getMessage()); - notification.setFrom("policy"); - notification.setPolicyName(drools.getRule().getName()); - notification.setPolicyScope("${policyScope}"); - notification.setPolicyVersion("${policyVersion}"); + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE); + notification.setMessage(e.getMessage()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); - PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); - - retract($event); - retract($manager); - retract($clTimer); + PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); + + retract($event); + retract($manager); + retract($clTimer); } end @@ -509,10 +515,13 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId(), "Permit".equalsIgnoreCase(getGuardApprovalStatus()) ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + onset.getRequestId() == $event.getRequestId(), "Permit".equalsIgnoreCase(getGuardApprovalStatus()) ) $lock : TargetLock (requestID == $event.getRequestId()) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString(), timerType == "Operation", !expired ) + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId().toString(), timerType == "Operation", !expired ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -526,70 +535,71 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" try { request = $operation.startOperation($event); - if (request != null) { - logger.debug("{}: {}: starting operation ..", - $params.getClosedLoopControlName(), drools.getRule().getName()); - // - // Tell interested parties we are performing this Operation - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.setNotification(ControlLoopNotificationType.OPERATION); - notification.setMessage($operation.getOperationMessage()); - notification.setHistory($operation.getHistory()); - notification.setFrom("policy"); - notification.setPolicyName(drools.getRule().getName()); - notification.setPolicyScope("${policyScope}"); - notification.setPolicyVersion("${policyVersion}"); - - PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); - - switch ($operation.policy.getActor()){ - - case "APPC": - - if (request instanceof Request) { - PolicyEngine.manager.deliver("APPC-CL", request); - } - else if (request instanceof LcmRequestWrapper) { - PolicyEngine.manager.deliver("APPC-LCM-READ", request); - } - break; - case "SO": - // at this point the AAI named query request should have already been made, the response recieved and used - // in the construction of the SO Request which is stored in operationRequest - - if(request instanceof SORequest) { - // Call SO. The response will be inserted into memory once it's received - SOActorServiceProvider.sendRequest($event.getRequestId().toString(), drools.getWorkingMemory(), request); - } - break; - case "VFC": - if (request instanceof VFCRequest) { - // Start VFC thread - Thread t = new Thread(new VFCManager(drools.getWorkingMemory(), (VFCRequest)request)); - t.start(); - } - break; - } - } else { - // - // What happens if its null? - // - logger.warn("{}: {}: unexpected null operation request", - $params.getClosedLoopControlName(), - drools.getRule().getName()); - if ("SO".equals($operation.policy.getActor())) { - retract($opTimer); - retract($operation); - modify($manager) {finishOperation($operation)}; - } - else if ("vfc".equalsIgnoreCase($operation.policy.getActor())) { - retract($opTimer); - retract($operation); - modify($manager) {finishOperation($operation)}; - } - } - + if (request != null) { + logger.debug("{}: {}: starting operation ..", + $params.getClosedLoopControlName(), drools.getRule().getName()); + // + // Tell interested parties we are performing this Operation + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setNotification(ControlLoopNotificationType.OPERATION); + notification.setMessage($operation.getOperationMessage()); + notification.setHistory($operation.getHistory()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + + PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); + + switch ($operation.policy.getActor()){ + + case "APPC": + if (request instanceof Request) { + PolicyEngine.manager.deliver("APPC-CL", request); + } + else if (request instanceof LcmRequestWrapper) { + PolicyEngine.manager.deliver("APPC-LCM-READ", request); + } + break; + case "SO": + // at this point the AAI named query request should have already been made, + // the response recieved and used + // in the construction of the SO Request which is stored in operationRequest + + if(request instanceof SORequest) { + // Call SO. The response will be inserted into memory once it's received + SoActorServiceProvider.sendRequest($event.getRequestId().toString(), drools.getWorkingMemory(), + request); + } + break; + case "VFC": + if (request instanceof VFCRequest) { + // Start VFC thread + Thread t = new Thread(new VFCManager(drools.getWorkingMemory(), (VFCRequest)request)); + t.start(); + } + break; + } + } else { + // + // What happens if its null? + // + logger.warn("{}: {}: unexpected null operation request", + $params.getClosedLoopControlName(), + drools.getRule().getName()); + if ("SO".equals($operation.policy.getActor())) { + retract($opTimer); + retract($operation); + modify($manager) {finishOperation($operation)}; + } + else if ("vfc".equalsIgnoreCase($operation.policy.getActor())) { + retract($opTimer); + retract($operation); + modify($manager) {finishOperation($operation)}; + } + } + } catch (Exception e) { String msg = e.getMessage(); logger.warn("{}: {}: operation={}: AAI failure: {}", @@ -598,17 +608,17 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" $operation.setOperationHasException(msg); if(request != null) { - // - // Create a notification for it ("DB Write - end operation") - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.setFrom("policy"); - notification.setPolicyName(drools.getRule().getName()); - notification.setPolicyScope("${policyScope}"); - notification.setPolicyVersion("${policyVersion}"); - notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); - notification.setMessage($operation.getOperationHistory()); - notification.setHistory($operation.getHistory()); + // + // Create a notification for it ("DB Write - end operation") + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); } @@ -635,8 +645,10 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId(), getGuardApprovalStatus() == "NONE" ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + onset.getRequestId() == $event.getRequestId(), getGuardApprovalStatus() == "NONE" ) $lock : TargetLock (requestID == $event.getRequestId()) then @@ -650,7 +662,8 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); notification.setNotification(ControlLoopNotificationType.OPERATION); - notification.setMessage("Sending guard query for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe()); + notification.setMessage("Sending guard query for " + $operation.policy.getActor() + " " + + $operation.policy.getRecipe()); notification.setHistory($operation.getHistory()); notification.setFrom("policy"); notification.setPolicyName(drools.getRule().getName()); @@ -699,11 +712,15 @@ end rule "${policyName}.GUARD.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() ) + $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() ) $lock : TargetLock (requestID == $event.getRequestId()) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString(), timerType == "Operation", !expired ) + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId().toString(), timerType == "Operation", !expired ) $guardResponse : PolicyGuardResponse(requestID == $event.getRequestId(), $operation.policy.recipe == operation) then @@ -723,7 +740,8 @@ rule "${policyName}.GUARD.RESPONSE" // VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); notification.setNotification(ControlLoopNotificationType.OPERATION); - notification.setMessage("Guard result for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe() + " is " + $guardResponse.getResult()); + notification.setMessage("Guard result for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe() + + " is " + $guardResponse.getResult()); notification.setHistory($operation.getHistory()); notification.setFrom("policy"); notification.setPolicyName(drools.getRule().getName()); @@ -763,10 +781,14 @@ end rule "${policyName}.APPC.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 ) + $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 : Response( getCommonHeader().RequestId == $event.getRequestId() ) then @@ -877,10 +899,14 @@ end rule "${policyName}.APPC.LCM.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 ) + $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 : LcmResponseWrapper( getBody().getCommonHeader().getRequestId() == $event.getRequestId() ) then @@ -982,14 +1008,18 @@ end rule "${policyName}.SO.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 ) + $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 : SOResponseWrapper(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={}", @@ -1064,69 +1094,73 @@ end * */ rule "${policyName}.VFC.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 ) + 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 : VFCResponse( 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() == 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); + $response : VFCResponse( 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() == 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 @@ -1155,9 +1189,12 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.TIMEOUT" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $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(), expired, timerType == "Operation" ) + $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(), expired, timerType == "Operation" ) $lock : TargetLock (requestID == $event.getRequestId()) then @@ -1219,8 +1256,10 @@ rule "${policyName}.EVENT.MANAGER.TIMEOUT" when $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" ) $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) - $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString(), expired, timerType == "ClosedLoop" ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId() ) + $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + requestID == $event.getRequestId().toString(), expired, timerType == "ClosedLoop" ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -1259,9 +1298,11 @@ rule "${policyName}.EVENT.MANAGER.CLEANUP" when $manager : ControlLoopEventManager( $clName : getClosedLoopControlName(), $requestId : getRequestID() ) $operations : LinkedList() - from collect( ControlLoopOperationManager( onset.closedLoopControlName == $clName, onset.getRequestId() == $requestId ) ) + from collect( ControlLoopOperationManager( onset.closedLoopControlName == $clName, + onset.getRequestId() == $requestId ) ) $timers : LinkedList() - from collect( ControlLoopTimer( closedLoopControlName == $clName, requestID == $requestId.toString() ) ) + from collect( ControlLoopTimer( closedLoopControlName == $clName, + requestID == $requestId.toString() ) ) $locks : LinkedList() from collect( TargetLock (requestID == $requestId) ) not( VirtualControlLoopEvent( closedLoopControlName == $clName, requestId == $requestId ) ) @@ -1355,11 +1396,13 @@ end rule "${policyName}.CLEANER.ACTIVE" salience 2 when - $cleaner: ParamsCleaner( getClosedLoopControlName() == "${closedLoopControlName}", getControlLoopYaml() == "${controlLoopYaml}" ) + $cleaner: ParamsCleaner( getClosedLoopControlName() == "${closedLoopControlName}", + getControlLoopYaml() == "${controlLoopYaml}" ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $cleaner.getClosedLoopControlName(), drools.getRule().getName(), $cleaner.getControlLoopYaml()); + logger.info("{}: {} : YAML=[{}]", $cleaner.getClosedLoopControlName(), drools.getRule().getName(), + $cleaner.getControlLoopYaml()); retract($cleaner); end @@ -1381,7 +1424,8 @@ rule "${policyName}.PARAMS.CLEANUP" then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), drools.getRule().getName(), $params.getControlLoopYaml()); + logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), drools.getRule().getName(), + $params.getControlLoopYaml()); retract($params); @@ -1400,7 +1444,8 @@ rule "${policyName}.CLEANER.CLEANUP" then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $cleaner.getClosedLoopControlName(), drools.getRule().getName(), $cleaner.getControlLoopYaml()); + logger.info("{}: {} : YAML=[{}]", $cleaner.getClosedLoopControlName(), drools.getRule().getName(), + $cleaner.getControlLoopYaml()); retract($cleaner); end -- cgit 1.2.3-korg