From 712274e8d332181729c06c31dcf58d49f2a4d8f7 Mon Sep 17 00:00:00 2001 From: jhh Date: Tue, 9 Apr 2019 14:24:34 -0500 Subject: deploy and undeploy as audits. Change-Id: Iea1766d5d8075394e1dccc109f4477bd2c270c36 Issue-ID: POLICY-1624 Signed-off-by: jhh --- .../java/org/onap/policy/drools/lifecycle/LifecycleFsm.java | 4 ++++ .../onap/policy/drools/lifecycle/LifecycleStateActive.java | 8 +++++--- .../onap/policy/drools/lifecycle/LifecycleStateRunning.java | 11 +++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'feature-lifecycle/src/main') diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java index b99953ed..97f3574e 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java @@ -283,6 +283,10 @@ public class LifecycleFsm implements Startable { policiesMap.put(policy.getIdentifier(), policy); } + protected void undeployedPolicyAction(@NonNull ToscaPolicy policy) { + policiesMap.remove(policy.getIdentifier()); + } + /* ** Action Helpers ** */ private boolean startIo() { diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java index d481b8bd..38ea0917 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateActive.java @@ -61,8 +61,6 @@ public class LifecycleStateActive extends LifecycleStateRunning { protected boolean deployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) { logger.info("{}: deploy {} into {}", this, policy.getIdentifier(), controller.getName()); - // TODO: This is the latest version - retract policy with same id but different version - if (!controller.offer(policy)) { return false; } @@ -75,8 +73,12 @@ public class LifecycleStateActive extends LifecycleStateRunning { protected boolean undeployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) { logger.info("{}: undeploy {} from {}", this, policy.getIdentifier(), controller.getName()); - // TODO: retract policy. + if (!controller.getDrools().delete(policy)) { + logger.warn("Policy {}:{}:{}:{} was not deployed.", + policy.getType(), policy.getTypeVersion(), policy.getName(), policy.getVersion()); + } + fsm.undeployedPolicyAction(policy); return true; } } diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java index 405dbeba..ed200ea6 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java @@ -134,8 +134,15 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { return true; } - boolean success = deployPolicies(policies); - return undeployPolicies(policies) && success; + // Note that PAP sends the list of all ACTIVE policies with every + // UPDATE message. First, we will undeploy all policies that are + // running but are not present in this list. This will include + // policies that are overridden by a different version. Second, + // we will deploy those policies that are not installed but + // resent in this list. + + boolean success = undeployPolicies(policies); + return deployPolicies(policies) && success; } protected boolean deployPolicies(List policies) { -- cgit 1.2.3-korg