diff options
author | Jim Hahn <jrh3@att.com> | 2018-07-05 14:24:36 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-07-05 15:47:42 -0400 |
commit | bb8821635720574be3c4c7146657fc8082c7d54b (patch) | |
tree | 1f8a7f8081590cab35181806bcdb99a60cc94a87 | |
parent | 48dcb76d2895029d72298b0f81eb0cff71a4ea69 (diff) |
Clean up objects for deleted rules
When rules for a closed loop are deleted, associated working memory
elements may be left around.
Modified the code to retract the various elements.
Re-added code to unlock when retracting TargetLock.
Add junit tests for new methods.
Forgot the junit test for request id.
Change-Id: Iec2805adbdb147a643f6163badee05ea353ada88
Issue-ID: POLICY-872
Signed-off-by: Jim Hahn <jrh3@att.com>
3 files changed, 79 insertions, 42 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index 4817bec40..fa608ca08 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java @@ -101,6 +101,10 @@ public class ControlLoopEventManager implements LockCallback, Serializable { this.requestID = requestID; } + public String getClosedLoopControlName() { + return closedLoopControlName; + } + public String getControlLoopResult() { return controlLoopResult; } @@ -145,6 +149,10 @@ public class ControlLoopEventManager implements LockCallback, Serializable { return this.processor; } + public UUID getRequestID() { + return requestID; + } + /** * Activate a control loop event. * diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java index 02dda2048..0c626e247 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java @@ -459,7 +459,11 @@ public class ControlLoopEventManagerTest { @Test public void testMethods() { - ControlLoopEventManager clem = new ControlLoopEventManager("MyClosedLoopName", UUID.randomUUID()); + UUID requestId = UUID.randomUUID(); + ControlLoopEventManager clem = new ControlLoopEventManager("MyClosedLoopName", requestId); + + assertEquals("MyClosedLoopName", clem.getClosedLoopControlName()); + assertEquals(requestId, clem.getRequestID()); clem.setActivated(true); assertEquals(true, clem.isActivated()); 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 1274d6c16..290a22270 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 @@ -121,7 +121,9 @@ end * */ rule "${policyName}.SETUP" + salience 1 when + not( Params( getClosedLoopControlName() == "${closedLoopControlName}", getControlLoopYaml() == "${controlLoopYaml}" ) ) then Params params = new Params(); @@ -138,6 +140,23 @@ end /* * +* This rule removes an old Params object that has the wrong YAML. +* +*/ +rule "${policyName}.PARAMS.CEANUP" + salience 1 + when + $params : Params( getClosedLoopControlName() == "${closedLoopControlName}", getControlLoopYaml() != "${controlLoopYaml}" ) + then + + Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); + logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), drools.getRule().getName(), $params.getControlLoopYaml()); + + retract($params); +end + +/* +* * This rule responds to DCAE Events where there is no manager yet. Either it is * the first ONSET, or a subsequent badly formed Event (i.e. Syntax error, or is-closed-loop-disabled) * @@ -1173,26 +1192,14 @@ rule "${policyName}.EVENT.MANAGER.TIMEOUT" $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName() ) $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() ) $clTimer : ControlLoopTimer ( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString(), $to : getDelay() ) - $operations : LinkedList() - from collect( ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() ) ) - $opTimers : LinkedList() - from collect( OperationTimer( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId().toString() ) ) - $locks : LinkedList() - from collect( TargetLock (requestID == $event.getRequestId()) ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); logger.info("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName()); - if ($operations == null) { - logger.debug("{}: {}: event={} manager={} clTimer={} operations=0", - $params.getClosedLoopControlName(), drools.getRule().getName(), - $event, $manager, $clTimer); - } else { - logger.debug("{}: {}: event={} manager={} clTimer={} operations={}", - $params.getClosedLoopControlName(), drools.getRule().getName(), - $event, $manager, $clTimer, $operations.size()); - } + logger.debug("{}: {}: event={}", + $params.getClosedLoopControlName(), drools.getRule().getName(), + $event); // // Tell the Event Manager it has timed out // @@ -1208,38 +1215,56 @@ rule "${policyName}.EVENT.MANAGER.TIMEOUT" PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); } // - // Retract EVERYTHING + // Retract the event // retract($event); +end + +/* +* +* This rule cleans up the manager and other objects after an event has +* been retracted. +* +*/ +rule "${policyName}.EVENT.MANAGER.CLEANUP" + when + $manager : ControlLoopEventManager( $clName : getClosedLoopControlName(), $requestId : getRequestID() ) + $clTimer : ControlLoopTimer ( closedLoopControlName == $clName, requestID == $requestId.toString() ) + $operations : LinkedList() + from collect( ControlLoopOperationManager( onset.closedLoopControlName == $clName, onset.getRequestId() == $requestId ) ) + $opTimers : LinkedList() + from collect( OperationTimer( closedLoopControlName == $clName, requestID == $requestId.toString() ) ) + $locks : LinkedList() + from collect( TargetLock (requestID == $requestId) ) + not( VirtualControlLoopEvent( closedLoopControlName == $clName, requestId == $requestId ) ) + then + + Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); + logger.info("{}: {}", $clName, drools.getRule().getName()); + + logger.debug("{}: {}: manager={} clTimer={} operations={}", + $clName, drools.getRule().getName(), + $manager, $clTimer, $operations.size()); + + // + // Retract EVERYTHING + // retract($manager); retract($clTimer); - if ($operations != null && $operations.size() > 0) { - Iterator<ControlLoopOperationManager> iter = $operations.iterator(); - while (iter.hasNext()) { - ControlLoopOperationManager manager = iter.next(); - retract(manager); - } + + for(Object manager: $operations) { + retract((ControlLoopOperationManager) manager); } - if ($opTimers != null && $opTimers.size() > 0) { - Iterator<OperationTimer> iter = $opTimers.iterator(); - while (iter.hasNext()) { - OperationTimer opTimer = iter.next(); - retract(opTimer); - } + for(Object opTimer: $opTimers) { + retract((OperationTimer) opTimer); } - if ($locks != null && $locks.size() > 0) { - Iterator<TargetLock> iter = $locks.iterator(); - while (iter.hasNext()) { - TargetLock lock = iter.next(); - // - // Ensure we release the lock - // - PolicyGuard.unlockTarget(lock); - // - // - // - retract(lock); - } + for(Object lock: $locks) { + TargetLock tgt = (TargetLock) lock; + // + // Ensure we release the lock + // + PolicyGuard.unlockTarget(tgt); + retract(tgt); } end |