Fix wrong APEX-PDP behaviour during state change 00/128400/1
authora.sreekumar <ajith.sreekumar@bell.ca>
Fri, 8 Apr 2022 15:22:17 +0000 (16:22 +0100)
committera.sreekumar <ajith.sreekumar@bell.ca>
Fri, 8 Apr 2022 15:22:22 +0000 (16:22 +0100)
When a policy is deployed & undeployed, and then on doing
PDP_STATE_CHANGE to passive and then active, previously undeployed
policies are taken from memory and tried to be deployed. Any undeployed
policies should be cleared from the engine memory.
This is fixed here.

Change-Id: I8f6fbc64d29bd8d89e906376d0770d375ffd8b82
Issue-ID: POLICY-4087
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java

index 1bcb897..b8e361e 100644 (file)
@@ -103,6 +103,7 @@ public class PdpUpdateMessageHandler {
         List<ToscaPolicy> policies = Registry.getOrDefault(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST,
                 List.class, new ArrayList<>());
         policies.addAll(pdpUpdateMsg.getPoliciesToBeDeployed());
+        policies.removeIf(policy -> pdpUpdateMsg.getPoliciesToBeUndeployed().contains(policy.getIdentifier()));
         Set<ToscaConceptIdentifier> policiesInDeployment = policies.stream().map(ToscaPolicy::getIdentifier)
                 .collect(Collectors.toSet());
         policiesInDeployment.removeAll(pdpUpdateMsg.getPoliciesToBeUndeployed());
@@ -118,9 +119,12 @@ public class PdpUpdateMessageHandler {
             // if some policy fails, that shouldn't go in the heartbeat.
             // If no policies are running, then the policy list in the heartbeat can be empty
             if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
-                pdpStatusContext.setPolicies(apexEngineHandler.getRunningPolicies());
+                var runningPolicies = apexEngineHandler.getRunningPolicies();
+                pdpStatusContext.setPolicies(runningPolicies);
+                policies.removeIf(policy -> !runningPolicies.contains(policy.getIdentifier()));
             } else {
                 pdpStatusContext.setPolicies(Collections.emptyList());
+                policies.clear();
             }
         }
         if (null == pdpResponseDetails) {