summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-18 17:41:15 -0400
committerJim Hahn <jrh3@att.com>2021-06-22 15:05:27 -0400
commit00e9e19f5ac50cb5ce4cd09a9c403797a6e8f2b3 (patch)
treeafd61e2422ad3c8a71ebc1c0939d555cecc0f0aa /main
parent8672dbc24a711798a9ac3098b24ac135e656f08e (diff)
Update timestamp of PDP record
Modified the code to update the record timestamp when a heartbeat is received from a PDP. Also used Map operations instead of List operations to construct policy deploy/undeploy lists so they can be constructed in O(N) instead of O(N^2). Issue-ID: POLICY-2898 Change-Id: Ic7b2b9a249fa0563b625e98855c79f96c6ee81d4 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java27
1 files changed, 18 insertions, 9 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 1099a4dc..adbc554d 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
@@ -22,6 +22,7 @@
package org.onap.policy.pap.main.comm;
+import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
@@ -156,7 +157,10 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
policiesToBeUndeployed = null;
LOGGER.debug("Found pdpGroup - {}, going for registration of PDP - {}", finalizedPdpGroup, message);
- if (!findPdpInstance(message, subGroup.get()).isPresent()) {
+ Optional<Pdp> pdp = findPdpInstance(message, subGroup.get());
+ if (pdp.isPresent()) {
+ updatePdpHealthStatus(message, subGroup.get(), pdp.get(), finalizedPdpGroup, databaseProvider);
+ } else {
updatePdpSubGroup(finalizedPdpGroup, subGroup.get(), message, databaseProvider);
}
sendPdpMessage(finalizedPdpGroup.getName(), subGroup.get(), message.getName(), null, databaseProvider);
@@ -173,13 +177,14 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
pdpInstance.setPdpState(PdpState.ACTIVE);
pdpInstance.setHealthy(message.getHealthy());
pdpInstance.setMessage(message.getDescription());
+ pdpInstance.setLastUpdate(Instant.now());
pdpSubGroup.getPdpInstances().add(pdpInstance);
pdpSubGroup.setCurrentInstanceCount(pdpSubGroup.getCurrentInstanceCount() + 1);
databaseProvider.updatePdpSubGroup(pdpGroup.getName(), pdpSubGroup);
- LOGGER.debug("Updated PdpSubGroup in DB - {} belonging to PdpGroup - {}", pdpSubGroup, pdpGroup);
+ LOGGER.debug("Updated PdpSubGroup in DB - {} belonging to PdpGroup - {}", pdpSubGroup, pdpGroup.getName());
}
private void handlePdpHeartbeat(final PdpStatus message, final PolicyModelsProvider databaseProvider)
@@ -231,15 +236,16 @@ 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());
+ Map<ToscaConceptIdentifier, ToscaPolicy> policyMap =
+ policies.stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy));
// policies that the PDP already has (-) all
- policiesToBeUndeployed = new LinkedList<>(message.getPolicies());
- policiesToBeUndeployed.removeAll(policies.stream().map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList()));
+ policiesToBeUndeployed = message.getPolicies().stream().filter(policyId -> !policyMap.containsKey(policyId))
+ .collect(Collectors.toList());
+
+ // all (-) policies that the PDP already has
+ policiesToBeDeployed = policyMap;
+ policiesToBeDeployed.keySet().removeAll(message.getPolicies());
if (PdpState.TERMINATED.equals(message.getState())) {
processPdpTermination(pdpSubGroup, pdpInstance, pdpGroup, databaseProvider);
@@ -258,6 +264,7 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
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());
+ updatePdpHealthStatus(message, pdpSubGroup, pdpInstance, pdpGroup, databaseProvider);
sendPdpMessage(pdpGroup.getName(), pdpSubGroup, pdpInstance.getInstanceId(), pdpInstance.getPdpState(),
databaseProvider);
}
@@ -309,6 +316,8 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
private void updatePdpHealthStatus(final PdpStatus message, final PdpSubGroup pdpSubgroup, final Pdp pdpInstance,
final PdpGroup pdpGroup, final PolicyModelsProvider databaseProvider) throws PfModelException {
pdpInstance.setHealthy(message.getHealthy());
+ pdpInstance.setMessage(message.getDescription());
+ pdpInstance.setLastUpdate(Instant.now());
databaseProvider.updatePdp(pdpGroup.getName(), pdpSubgroup.getPdpType(), pdpInstance);
LOGGER.debug("Updated Pdp in DB - {}", pdpInstance);