diff options
Diffstat (limited to 'controlloop/common/controller-usecases/src/main/resources')
-rw-r--r-- | controlloop/common/controller-usecases/src/main/resources/usecases.drl | 317 |
1 files changed, 161 insertions, 156 deletions
diff --git a/controlloop/common/controller-usecases/src/main/resources/usecases.drl b/controlloop/common/controller-usecases/src/main/resources/usecases.drl index 4adf74064..fb6812a88 100644 --- a/controlloop/common/controller-usecases/src/main/resources/usecases.drl +++ b/controlloop/common/controller-usecases/src/main/resources/usecases.drl @@ -35,6 +35,7 @@ import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NewEventStatus; import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager; +import org.onap.policy.controlloop.eventmanager.LockCallbackWorkingMemory; import org.onap.policy.controlloop.utils.ControlLoopUtils; import org.onap.policy.controlloop.actor.so.SoActorServiceProvider; import org.onap.policy.controlloop.actor.cds.CdsActorServiceProvider; @@ -53,6 +54,7 @@ import org.onap.policy.appclcm.LcmCommonHeader; import org.onap.policy.cds.CdsResponse; import org.onap.policy.cds.client.CdsProcessorGrpcClient; import org.onap.policy.cds.properties.CdsServerProperties; +import org.onap.policy.drools.utils.Pair; import org.onap.policy.sdnr.PciRequestWrapper; import org.onap.policy.sdnr.PciResponseWrapper; import org.onap.policy.sdnr.PciRequest; @@ -66,10 +68,7 @@ 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; -import org.onap.policy.guard.GuardResult; +import org.onap.policy.drools.core.lock.Lock; import org.onap.policy.guard.PolicyGuardRequest; import org.onap.policy.guard.PolicyGuardResponse; import org.onap.policy.guard.PolicyGuardXacmlRequestAttributes; @@ -113,7 +112,7 @@ rule "INSERT.PARAMS" then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), $params.getPolicyName() + "." + logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), $params.getPolicyName() + "." + drools.getRule().getName(), $params.getControlLoopYaml()); end @@ -164,7 +163,7 @@ rule "EVENT" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) - not ( ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + not ( ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) ) then @@ -204,7 +203,7 @@ rule "EVENT" // ControlLoopEventManager manager = new ControlLoopEventManager($clName, $event.getRequestId()); // - // Determine if EventManager can actively process the event + // Determine if EventManager can actively process the event // (i.e. syntax, is_closed_loop_disabled checks etc.) // VirtualControlLoopNotification notification = manager.activate($params.getControlLoopYaml(), $event); @@ -283,9 +282,9 @@ rule "EVENT.MANAGER" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "ClosedLoop", !expired ) then @@ -362,10 +361,10 @@ rule "EVENT.MANAGER" // // Unlock the target // - TargetLock lock = $manager.unlockCurrentOperation(); - if (lock != null) { - logger.debug("{}: {}: retracting lock=", $clName, - $params.getPolicyName() + "." + drools.getRule().getName(), lock); + Lock lock = $manager.unlockCurrentOperation(); + if(lock != null) { + logger.debug("{}: {}.{}: retracting lock={}", $clName, + $params.getPolicyName(), drools.getRule().getName(), lock); retract(lock); } // @@ -375,9 +374,9 @@ rule "EVENT.MANAGER" $clName, $params.getPolicyName() + "." + drools.getRule().getName()); retract($manager.getOnsetEvent()); - + // don't retract manager, etc. - a clean-up rule will do that - + // // TODO - what if we get subsequent Events for this RequestId? // By default, it will all start over again. May be confusing for Ruby. @@ -407,10 +406,10 @@ rule "EVENT.MANAGER" // // Unlock the target // - TargetLock lock = $manager.unlockCurrentOperation(); - if (lock != null) { - logger.debug("{}: {}: retracting lock=", $clName, - $params.getPolicyName() + "." + drools.getRule().getName(), lock); + Lock lock = $manager.unlockCurrentOperation(); + if(lock != null) { + logger.debug("{}: {}.{}: retracting lock={}", $clName, + $params.getPolicyName(), drools.getRule().getName(), lock); retract(lock); } // @@ -420,7 +419,7 @@ rule "EVENT.MANAGER" $clName, $params.getPolicyName() + "." + drools.getRule().getName()); retract($manager.getOnsetEvent()); - + // don't retract manager, etc. - a clean-up rule will do that } } @@ -433,57 +432,39 @@ rule "EVENT.MANAGER" // // Let's ask for a lock right away // - LockResult<GuardResult, TargetLock> result = $manager.lockCurrentOperation(); - logger.info("{}: {}: guard lock acquired={}", - $clName, $params.getPolicyName() + "." + 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()); - Integer timeout = operation.getOperationTimeout(); - opTimer.setDelay(timeout > 0 ? timeout.toString() + "s" : $clTimer.getDelay()); - insert(opTimer); - - // - // Insert lock into memory - // - insert(result.getB()); + logger.info("{}: {}.{}: requesting lock for operation={}", + $clName, $params.getPolicyName(), drools.getRule().getName(), + operation); + + Pair<Lock,Lock> oldNew = $manager.lockCurrentOperation( + new LockCallbackWorkingMemory($params.getClosedLoopControlName(), drools.getWorkingMemory())); + if(oldNew.first() != null) { + logger.debug("{}: {}.{}: retracting lock={}", $clName, + $params.getPolicyName(), drools.getRule().getName(), oldNew.first()); + retract(oldNew.first()); + } + if(oldNew.second() != null) { + logger.debug("{}: {}.{}: inserting lock={}", $clName, + $params.getPolicyName(), drools.getRule().getName(), oldNew.second()); + insert(oldNew.second()); } - 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($params.getPolicyName() + "." + drools.getRule().getName()); - notification.setPolicyScope($params.getPolicyScope()); - notification.setPolicyVersion($params.getPolicyVersion()); - PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification); + // + // insert the operation into memory + // + insert(operation); - retract($event); - - // don't retract manager, etc. - a clean-up rule will do that + // + // insert operation timeout object + // + ControlLoopTimer opTimer = new ControlLoopTimer(); + opTimer.setTimerType("Operation"); + opTimer.setClosedLoopControlName($event.getClosedLoopControlName()); + opTimer.setRequestId($event.getRequestId().toString()); + Integer timeout = operation.getOperationTimeout(); + opTimer.setDelay(timeout > 0 ? timeout.toString() + "s" : $clTimer.getDelay()); + insert(opTimer); - if(result.getB() != null) { - retract(result.getB()); - } - } - logger.info("{}: {}: starting operation={}", - $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - operation); } else { // // Probably waiting for abatement @@ -508,7 +489,7 @@ rule "EVENT.MANAGER" PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification); retract($event); - + // don't retract manager, etc. - a clean-up rule will do that } @@ -516,6 +497,43 @@ end /* * +* Lock denied +* +*/ +rule "EVENT.MANAGER.OPERATION.LOCK.DENIED" + when + $params : ControlLoopParams( $clName : getClosedLoopControlName() ) + $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + requestId == $event.getRequestId() ) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + onset.getRequestId() == $event.getRequestId(), "None".equalsIgnoreCase(getGuardApprovalStatus()) ) + $lock : Lock (ownerKey == $event.getRequestId().toString(), isUnavailable()) + then + + Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); + logger.info("{}: {}.{}: event={} manager={} operation={} lock={}", + $clName, $params.getPolicyName(), drools.getRule().getName(), + $event, $manager, $operation, $lock); + + logger.debug("The target resource {} is already processing", $event.getAai().get($event.getTarget())); + VirtualControlLoopNotification 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($params.getPolicyName() + "." + drools.getRule().getName()); + notification.setPolicyScope($params.getPolicyScope()); + notification.setPolicyVersion($params.getPolicyVersion()); + + PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification); + + retract($event); + + // don't retract manager, etc. - a clean-up rule will do that +end + +/* +* * Guard Permitted, let's send request to the actor. * */ @@ -523,19 +541,18 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $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(), + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "Operation", !expired ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {}: event={} manager={} operation={} lock={}", + logger.info("{}: {}: event={} manager={} operation={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock); + $event, $manager, $operation); Object request = null; boolean caughtException = false; @@ -573,7 +590,7 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" } break; case "SO": - // at this point the AAI named query request should have already been made, the response + // 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) { @@ -583,8 +600,8 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" drools.getWorkingMemory().insert(wrapper); } } - SoActorServiceProvider.sendRequest($event.getRequestId().toString(), - new mySoCallback(), + SoActorServiceProvider.sendRequest($event.getRequestId().toString(), + new mySoCallback(), request, PolicyEngineConstants.getManager().getEnvironmentProperty("so.url"), PolicyEngineConstants.getManager().getEnvironmentProperty("so.username"), @@ -594,7 +611,7 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" case "VFC": if (request instanceof VfcRequest) { class myVfcCallback implements VfcManager.VfcCallback { - + public void onResponse(VfcResponse responseError) { drools.getWorkingMemory().insert(responseError); } @@ -613,23 +630,23 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" PolicyEngineConstants.getManager().deliver("SDNR-CL", request); } break; - + case "SDNC": if (request instanceof SdncRequest) { class mySdncCallback implements SdncManager.SdncCallback { public void onCallback(SdncResponse response) { drools.getWorkingMemory().insert(response); } - } + } // Start SDNC thread - Thread t = new Thread(new SdncManager(new mySdncCallback(), + Thread t = new Thread(new SdncManager(new mySdncCallback(), (SdncRequest)request, PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.url"), PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.username"), PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.password"))); t.start(); } - break; + break; case "CDS": @@ -656,7 +673,6 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" } } break; - } } else { // @@ -728,11 +744,11 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $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()) + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + onset.getRequestId() == $event.getRequestId(), "None".equalsIgnoreCase(getGuardApprovalStatus()) ) + $lock : Lock (ownerKey == $event.getRequestId().toString(), isActive()) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -745,7 +761,7 @@ rule "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() + " " + notification.setMessage("Sending guard query for " + $operation.policy.getActor() + " " + $operation.policy.getRecipe()); notification.setHistory($operation.getHistory()); notification.setFrom("policy"); @@ -813,22 +829,21 @@ end rule "GUARD.RESPONSE" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) - $event : VirtualControlLoopEvent( closedLoopControlName == $clName, + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $lock : TargetLock (requestId == $event.getRequestId()) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "Operation", !expired ) $guardResponse : PolicyGuardResponse(requestId == $event.getRequestId(), $operation.policy.recipe == operation) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {}: event={} manager={} operation={} lock={} opTimer={} guardResponse={}", + logger.info("{}: {}: event={} manager={} operation={} opTimer={} guardResponse={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $opTimer, $guardResponse); + $event, $manager, $operation, $opTimer, $guardResponse); //we will permit the operation if there was no Guard for it @@ -882,23 +897,22 @@ end rule "APPC.RESPONSE" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) - $event : VirtualControlLoopEvent( closedLoopControlName == $clName, + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "Operation", !expired ) - $lock : TargetLock (requestId == $event.getRequestId()) $response : Response( getCommonHeader().RequestId == $event.getRequestId() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); - logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $opTimer, $response); + $event, $manager, $operation, $opTimer, $response); // // Get the result of the operation // @@ -1000,23 +1014,22 @@ end rule "APPC.LCM.RESPONSE" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) - $event : VirtualControlLoopEvent( closedLoopControlName == $clName, + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $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 Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); - logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer, $response); + $event, $manager, $operation, $operation, $opTimer, $response); // // Get the result of the operation @@ -1109,23 +1122,22 @@ end rule "SO.RESPONSE" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) - $event : VirtualControlLoopEvent( closedLoopControlName == $clName, + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $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("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); - logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer, $response); + $event, $manager, $operation, $operation, $opTimer, $response); // Get the result of the operation // @@ -1197,22 +1209,21 @@ end rule "VFC.RESPONSE" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) - $event : VirtualControlLoopEvent( closedLoopControlName == $clName, + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $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("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); - logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer, $response); + $event, $manager, $operation, $operation, $opTimer, $response); // Get the result of the operation // @@ -1276,16 +1287,15 @@ rule "SDNC.RESPONSE" $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(), + $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={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer, $response); + $event, $manager, $operation, $operation, $opTimer, $response); // Get the result of the operation // @@ -1353,16 +1363,15 @@ rule "${policyName}.CDS.RESPONSE" onset.getRequestId() == $event.getRequestId() ) $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "Operation", !expired ) - $lock : TargetLock (requestId == $event.getRequestId()) $response : CdsResponse( requestId == $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={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $params.getClosedLoopControlName(), drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer, $response); + $event, $manager, $operation, $operation, $opTimer, $response); // Get the result of the operation PolicyResult policyResult = $operation.onResponse($response); @@ -1444,20 +1453,19 @@ rule "EVENT.MANAGER.OPERATION.TIMEOUT" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "Operation", expired ) - $lock : TargetLock (requestId == $event.getRequestId()) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); - logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer); + $event, $manager, $operation, $operation, $opTimer); // // Tell it its timed out @@ -1511,9 +1519,9 @@ rule "EVENT.MANAGER.TIMEOUT" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) $event : VirtualControlLoopEvent( closedLoopControlName == $clName ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $clTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "ClosedLoop", expired ) then @@ -1553,13 +1561,11 @@ rule "EVENT.MANAGER.CLEANUP" when $manager : ControlLoopEventManager( $clName : getClosedLoopControlName(), $requestId : getRequestId() ) $operations : LinkedList() - from collect( ControlLoopOperationManager( onset.closedLoopControlName == $clName, + from collect( ControlLoopOperationManager( onset.closedLoopControlName == $clName, onset.getRequestId() == $requestId ) ) $timers : LinkedList() - from collect( ControlLoopTimer( closedLoopControlName == $clName, + from collect( ControlLoopTimer( closedLoopControlName == $clName, requestId == $requestId.toString() ) ) - $locks : LinkedList() - from collect( TargetLock (requestId == $requestId) ) not( VirtualControlLoopEvent( closedLoopControlName == $clName, requestId == $requestId ) ) then @@ -1571,6 +1577,14 @@ rule "EVENT.MANAGER.CLEANUP" $manager, $timers.size(), $operations.size()); // + // Retract lock by invoking unlock() + // + Lock lock = $manager.unlockCurrentOperation(); + if(lock != null) { + retract(lock); + } + + // // Retract EVERYTHING // retract($manager); @@ -1581,14 +1595,6 @@ rule "EVENT.MANAGER.CLEANUP" for(Object timer: $timers) { retract((ControlLoopTimer) timer); } - for(Object lock: $locks) { - TargetLock tgt = (TargetLock) lock; - // - // Ensure we release the lock - // - PolicyGuard.unlockTarget(tgt); - retract(tgt); - } end /* @@ -1619,23 +1625,22 @@ end rule "SDNR.RESPONSE" when $params : ControlLoopParams( $clName : getClosedLoopControlName() ) - $event : VirtualControlLoopEvent( closedLoopControlName == $clName, + $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET ) - $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), + $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId() ) - $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), + $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) - $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), + $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestId == $event.getRequestId().toString(), timerType == "Operation", !expired ) - $lock : TargetLock (requestId == $event.getRequestId()) $response : PciResponseWrapper( getBody().getCommonHeader().getRequestId() == $event.getRequestId() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName()); - logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", + logger.debug("{}: {}: event={} manager={} operation={} opTimer={} response={}", $clName, $params.getPolicyName() + "." + drools.getRule().getName(), - $event, $manager, $operation, $lock, $operation, $opTimer, $response); + $event, $manager, $operation, $operation, $opTimer, $response); // // Get the result of the operation |