diff options
author | 2018-11-04 14:33:36 -0500 | |
---|---|---|
committer | 2018-11-05 21:55:45 +0000 | |
commit | 8c3455d2a0a62bf1b099578f0acadc26a68ba919 (patch) | |
tree | 443d217fc12f170a798cc0b57db39e9ba9729280 /controlloop/templates/archetype-cl-amsterdam/src/main/resources | |
parent | ff40bef8d9a824f9ff1a4647f1df800eb3f9c21e (diff) |
Cleanup all Param objects when any rules change
Fix license date for new junit test.
Updated some comments.
Ensured different control loop names in different rule sets of new junit
test.
Used different mechanism for examining facts in new junit test.
Fixed typo in comment.
Changed the way new junit checks for existence of facts.
Fixed another typo in comment.
Updated clean-up rules in CLC template and added junit test to verify
that Params are cleaned up appropriately.
Removed code that retracts $manager objects so that the manager clean-up
rule will be used, instead, thus ensuring that all associated objects are
deleted when the manager is deleted. This was done for amsterdam, CLC,
and casablanca templates.
Added an extra fireAllRules() after calls to fireUntilHalt() to enable
clean-up rules to fire in junit tests.
Address Josh's review comments.
Enhance junit test to compare actual object references to ensure that
Param objects are as expected.
Change-Id: If1fefd3f57e417180c62a3849defbaa6ae83afc1
Issue-ID: POLICY-1248
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/templates/archetype-cl-amsterdam/src/main/resources')
-rw-r--r-- | controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl | 121 |
1 files changed, 56 insertions, 65 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 cac512eac..53b4ca8bd 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 @@ -81,6 +81,8 @@ import org.slf4j.Logger; import java.time.Instant; import java.util.LinkedList; import java.util.Iterator; +import java.util.HashSet; +import java.util.Set; import org.onap.policy.drools.system.PolicyEngine; @@ -109,7 +111,8 @@ end */ declare ParamsCleaner closedLoopControlName : String - controlLoopYaml : String + identified : boolean // true if all active Params have been identified + active : Set // Params that are still active end /* @@ -127,7 +130,8 @@ end /* * -* Called once and only once to insert the parameters into working memory for this Closed Loop policy. +* Called to insert the parameters into working memory for this Closed Loop policy. This is called +* once each time a closed loop is added or its YAML is updated. * This has a higher salience so we can ensure that the Params is created before we have a chance to * discard any events. * @@ -143,6 +147,12 @@ rule "${policyName}.SETUP" params.setClosedLoopControlName("${closedLoopControlName}"); params.setControlLoopYaml("${controlLoopYaml}"); insert(params); + + ParamsCleaner cleaner = new ParamsCleaner(); + cleaner.setClosedLoopControlName("${closedLoopControlName}"); + cleaner.setIdentified(false); + cleaner.setActive(new HashSet()); + insert(cleaner); // Note: globals have bad behavior when persistence is used, // hence explicitly getting the logger vs using a global @@ -378,8 +388,9 @@ rule "${policyName}.EVENT.MANAGER" $params.getClosedLoopControlName(), drools.getRule().getName()); retract($manager.getOnsetEvent()); - retract($manager); - retract($clTimer); + + // 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. @@ -422,8 +433,8 @@ rule "${policyName}.EVENT.MANAGER" $params.getClosedLoopControlName(), drools.getRule().getName()); retract($manager.getOnsetEvent()); - retract($manager); - retract($clTimer); + + // don't retract manager, etc. - a clean-up rule will do that } } } else { @@ -473,8 +484,8 @@ rule "${policyName}.EVENT.MANAGER" PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); retract($event); - retract($manager); - retract($clTimer); + + // don't retract manager, etc. - a clean-up rule will do that if (result.getB() != null) { retract(result.getB()); @@ -507,8 +518,8 @@ rule "${policyName}.EVENT.MANAGER" PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); retract($event); - retract($manager); - retract($clTimer); + + // don't retract manager, etc. - a clean-up rule will do that } end @@ -1568,95 +1579,75 @@ rule "${policyName}.EVENT.CLEANUP" end /* -* -* When rules are deleted, the associated Params (and its subordinate objects) -* remain in working memory, because there are no longer any rules to clean -* them up. However, ANY time new rules are loaded, this rule will trigger -* a clean-up of ALL Params, regardless of their name & yaml, thus removing -* any that no longer have associated rules. -* This has a higher salience so that we immediately check Params when the -* rules change, before processing any events. -* +* Indicates to the cleaner that this Params object is still active. +* This has a higher salience so that it is fired before processing any events. */ -rule "${policyName}.PARAMS.CHECKUP" - salience 2 +rule "${policyName}.PARAMS.ACTIVE" + salience 4 when - Params( $clName: closedLoopControlName, $yaml: controlLoopYaml ) + $params: Params( getClosedLoopControlName() == "${closedLoopControlName}", + getControlLoopYaml() == "${controlLoopYaml}" ) + ParamsCleaner( !identified, $active: active ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $clName, drools.getRule().getName(), $yaml); - - ParamsCleaner cleaner = new ParamsCleaner(); - cleaner.setClosedLoopControlName($clName); - cleaner.setControlLoopYaml($yaml); + logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), drools.getRule().getName(), + $params.getControlLoopYaml()); + + $active.add($params); - insert(cleaner); + // do NOT update anything at this point end /* -* -* This rule removes "cleaner" objects for rules that are still active, thus -* preventing the associated Params objects from being removed. Any cleaners -* that are left after this rule has fired will cause their corresponding Params -* to be removed. -* This has a higher salience so that we discard the cleaner before it has -* a chance to force the removal of the associated Params. -* +* Finished identifying active Params objects. Begin deleting inactive Params. +* This has a higher salience so that it is fired before processing any events. */ -rule "${policyName}.CLEANER.ACTIVE" - salience 2 +rule "${policyName}.PARAMS.IDENTIFIED" + salience 3 when - $cleaner: ParamsCleaner( getClosedLoopControlName() == "${closedLoopControlName}", - getControlLoopYaml() == "${controlLoopYaml}" ) + $cleaner: ParamsCleaner( !identified ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $cleaner.getClosedLoopControlName(), drools.getRule().getName(), - $cleaner.getControlLoopYaml()); + logger.info("{}: {}", $cleaner.getClosedLoopControlName(), drools.getRule().getName()); - retract($cleaner); + $cleaner.setIdentified(true); + update($cleaner); end /* -* -* This rule removes Params objects that no longer have associated rules; if a -* Params still had associated rules, then the cleaner would have been removed -* by those rules and thus this rule would not fire. -* This has a higher salience so that we remove old Params before it causes any -* events to be processed. -* +* Delete Params objects that have not been identified as being active. +* This has a higher salience so that it is fired before processing any events. */ -rule "${policyName}.PARAMS.CLEANUP" - salience 1 +rule "${policyName}.PARAMS.DELETE" + salience 2 when - $params: Params( $clName: closedLoopControlName, $yaml: controlLoopYaml ) - ParamsCleaner( getClosedLoopControlName() == $clName, getControlLoopYaml() == $yaml ) + $params: Params( ) + ParamsCleaner( identified, !active.contains($params) ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), drools.getRule().getName(), + logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), drools.getRule().getName(), $params.getControlLoopYaml()); - + retract($params); - // Note: the cleaner may be needed for cleaning additional params, thus - // we do not retract it here - we'll leave that to another rule + // do NOT update anything at this point end /* -* -* This rule removes "cleaner" objects when they're no longer needed. -* +* Finished deleting inactive Params objects, so remove the cleaner. +* This has a higher salience so that it is fired before processing any events. */ -rule "${policyName}.CLEANER.CLEANUP" +rule "${policyName}.PARAMS.CLEANED" + salience 1 when - $cleaner: ParamsCleaner( ) + $cleaner: ParamsCleaner( identified ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $cleaner.getClosedLoopControlName(), drools.getRule().getName(), - $cleaner.getControlLoopYaml()); + logger.info("{}: {}", $cleaner.getClosedLoopControlName(), drools.getRule().getName()); retract($cleaner); end |