aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/templates/archetype-cl-amsterdam
diff options
context:
space:
mode:
authordaniel <dc443y@att.com>2017-10-17 17:56:08 -0500
committerdaniel <dc443y@att.com>2017-10-17 18:08:10 -0500
commitb2d602aaedfcc9356e07dd94b6baec70c38815b8 (patch)
tree1e1afee15dbaedbc3b5bcb1db95724a86d806110 /controlloop/templates/archetype-cl-amsterdam
parent2a5af723adf9c71d919d701313e7809f8160ef3a (diff)
Fix Target Entity Lock
This fix enables the pdp to stop events with different requestId's/controlLoopNames from being processed if the target entity specified is already being processed by another event/controlloop. The lock timeout rule is removed to stop the event from waiting to obtain a lock if it was not already required. Handling of the lock denied case is taken care of in the event manager rule instead of in a seperate rule to avoid further unneccessary computation. A new control loop test case was created that is for testing general control loop errors. The test case included is for testing that the lock will deny a request with a duplicate target entity. Issue-ID: POLICY-341 Change-Id: Ib62286eff74ec22b2c645f32f385cb331fb1dff3 Signed-off-by: Daniel Cruz <dc443y@att.com>
Diffstat (limited to 'controlloop/templates/archetype-cl-amsterdam')
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl96
1 files changed, 37 insertions, 59 deletions
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 44501bf5e..3d6d89c69 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
@@ -428,36 +428,53 @@ rule "${policyName}.EVENT.MANAGER"
//
ControlLoopOperationManager operation = $manager.processControlLoop();
if (operation != null) {
- logger.info("{}: {}: starting operation={}",
- $params.getClosedLoopControlName(), drools.getRule().getName(),
- operation);
- //
- // insert into memory
- //
- insert(operation);
- //
- // insert operation timeout object
- //
- OperationTimer opTimer = new OperationTimer();
- opTimer.setClosedLoopControlName($event.closedLoopControlName);
- opTimer.setRequestID($event.requestID.toString());
- opTimer.setDelay(operation.getOperationTimeout().toString() + "s");
- insert(opTimer);
-
//
// Let's ask for a lock right away
//
LockResult<GuardResult, TargetLock> result = $manager.lockCurrentOperation();
- if (result.getA().equals(GuardResult.LOCK_ACQUIRED)) {
- logger.info("{}: {}: guard lock acquired={}",
+ logger.info("{}: {}: guard lock acquired={}",
$params.getClosedLoopControlName(), drools.getRule().getName(),
result.getB());
-
+ if (result.getA().equals(GuardResult.LOCK_ACQUIRED)) {
//
- // Insert into memory
+ // insert the operation into memory
+ //
+ insert(operation);
+
+ //
+ // insert operation timeout object
+ //
+ OperationTimer opTimer = new OperationTimer();
+ opTimer.setClosedLoopControlName($event.closedLoopControlName);
+ opTimer.setRequestID($event.requestID.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.AAI.get($event.target));
+ notification = new VirtualControlLoopNotification($event);
+ notification.notification = ControlLoopNotificationType.REJECTED;
+ notification.message = "The target " + $event.AAI.get($event.target) + " is already locked";
+ notification.from = "policy";
+ notification.policyName = drools.getRule().getName();
+ notification.policyScope = "${policyScope}";
+ notification.policyVersion = "${policyVersion}";
+
+ PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+
+ retract($event);
+ retract($manager);
+ retract($clTimer);
+ }
+ logger.info("{}: {}: starting operation={}",
+ $params.getClosedLoopControlName(), drools.getRule().getName(),
+ operation);
} else {
//
// Probably waiting for abatement
@@ -478,45 +495,6 @@ rule "${policyName}.EVENT.MANAGER"
end
-
-
-/*
-*
-*
-*
-*/
-rule "${policyName}.EVENT.MANAGER.OPERATION.NOT_LOCKED.TIMEOUT"
- timer (int: 5s 5s)
- when
- $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
- $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() )
- $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID )
- $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
- not ( TargetLock (requestID == $event.requestID) )
- then
-
- Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
- logger.info("{}: {}: event={} manager={} operation={}",
- $params.getClosedLoopControlName(), drools.getRule().getName(),
- $event, $manager, $operation);
-
- //
- // Need to ask for a Lock
- //
- LockResult<GuardResult, TargetLock> result = $manager.lockCurrentOperation();
- if (result.getA().equals(GuardResult.LOCK_ACQUIRED)) {
- logger.info("{}: {}: guard lock acquired={}",
- $params.getClosedLoopControlName(), drools.getRule().getName(),
- result.getB());
-
- //
- // Insert into memory
- //
- insert(result.getB());
- }
-
-end
-
/*
*
* Guard Permitted, let's send request to the actor.