From c95f74758ccc2aa680bcd7477b10cb47f3b5080e Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Fri, 8 Apr 2022 16:22:17 +0100 Subject: Fix wrong APEX-PDP behaviour during state change 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 --- .../apex/services/onappf/handler/PdpUpdateMessageHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'services/services-onappf/src/main/java/org') diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java index 1bcb8970b..b8e361e1e 100644 --- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java +++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java @@ -103,6 +103,7 @@ public class PdpUpdateMessageHandler { List 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 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) { -- cgit 1.2.3-korg