From 243d345e2b908c4e969652b04c3ad9f4a4b5d0e6 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Tue, 27 Apr 2021 16:51:45 +0100 Subject: Fixing issue where PdpHeartbeats are incorrectly processed by PAP The below 2 issues are fixed in this review: 1) When updating the policiesToBeUndeployed, the policies list in the message itself was getting removed, which resulted in incorrect processing. This was the reason for continuos UPDATE and STATE_CHANGE messages from PAP to PDP. 2) In case if the policy list in heartbeat doesn't include one or more policies that are supposed to be deployed(as per DB), the PAP should send UPDATE messages to PDP asking to deploy them too. But this was not working as the policiesToBeDeployed list was not getting initialized properly before getting processed. Change-Id: I06dbfd1d40bae8a510fc5500fbd38fb87c203c0d Issue-ID: POLICY-3248 Signed-off-by: a.sreekumar (cherry picked from commit cc70129c67ed6284c3d13593e6b19e19d73d3084) --- .../org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java index b692a2a5..5ec9aba0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java @@ -233,11 +233,13 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { // all policies policies = getToscaPolicies(pdpSubGroup, databaseProvider); + policiesToBeDeployed = + policies.stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy)); // all (-) policies that the PDP already has policiesToBeDeployed.keySet().removeAll(message.getPolicies()); // policies that the PDP already has (-) all - policiesToBeUndeployed = message.getPolicies(); + policiesToBeUndeployed = new LinkedList<>(message.getPolicies()); policiesToBeUndeployed.removeAll(policies.stream().map(ToscaPolicy::getIdentifier) .collect(Collectors.toList())); @@ -256,8 +258,10 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { } } else { LOGGER.debug("PdpInstance details are not correct. Sending PdpUpdate message - {}", pdpInstance); + LOGGER.debug("Policy list in DB - {}. Policy list in heartbeat - {}", pdpSubGroup.getPolicies(), + message.getPolicies()); sendPdpMessage(pdpGroup.getName(), pdpSubGroup, pdpInstance.getInstanceId(), pdpInstance.getPdpState(), - databaseProvider); + databaseProvider); } } -- cgit 1.2.3-korg