summaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2021-05-10 12:12:56 +0100
committerWayneDunican <wayne.dunican@est.tech>2021-05-27 19:26:28 +0100
commit42375e6c04f82821c7daff5a059c8974a7c89a10 (patch)
tree8dc0905f6d98c5a1f5745ff0c773e71e45680c60 /main/src/main/java/org
parent47c4b4bf0940aa56bbf43b1ff7edc018b538019e (diff)
Update PAP to check for deployed policies only
Have PAP compare the returned list against the delta deployment list instead of comparing against the full list of policies as is the current behaviour. Any references to "get" or "set" policies methods have also been removed Issue-ID: POLICY-3263 Change-Id: I0efe03e835db3c4b2136f7e742bba0e78dc2ac44 Signed-off-by: waynedunican <wayne.dunican@est.tech> Signed-off-by: WayneDunican <wayne.dunican@est.tech>
Diffstat (limited to 'main/src/main/java/org')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java3
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java6
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java52
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java6
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java4
6 files changed, 31 insertions, 42 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
index 76c47544..a2829572 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
@@ -93,7 +93,7 @@ public class PdpMessageGenerator {
}
protected PdpUpdate createPdpUpdateMessage(final String pdpGroupName, final PdpSubGroup subGroup,
- final String pdpInstanceId, final List<ToscaPolicy> policies,
+ final String pdpInstanceId,
final List<ToscaPolicy> policiesToBeDeployed,
final List<ToscaConceptIdentifier> policiesToBeUndeployed) {
@@ -102,7 +102,6 @@ public class PdpMessageGenerator {
update.setName(pdpInstanceId);
update.setPdpGroup(pdpGroupName);
update.setPdpSubgroup(subGroup.getPdpType());
- update.setPolicies(policies);
update.setPoliciesToBeDeployed(policiesToBeDeployed);
update.setPoliciesToBeUndeployed(policiesToBeUndeployed);
update.setPdpHeartbeatIntervalMs(heartBeatMs);
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 79889a79..1099a4dc 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -325,12 +325,12 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator {
throws PfModelException {
final List<ToscaPolicy> polsToBeDeployed = new LinkedList<>(policiesToBeDeployed.values());
final var pdpUpdatemessage =
- createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, policies,
+ createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId,
polsToBeDeployed, policiesToBeUndeployed);
final var pdpStateChangeMessage =
createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState);
updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId, pdpStateChangeMessage.getState(),
- databaseProvider, pdpUpdatemessage.getPolicies());
+ databaseProvider, pdpUpdatemessage.getPoliciesToBeDeployed());
requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage);
LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage);
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java
index 18ae5af6..d0d1f5f0 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java
@@ -23,6 +23,7 @@ package org.onap.policy.pap.main.comm.msgdata;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -37,6 +38,8 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.parameters.RequestParams;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -44,6 +47,8 @@ import org.onap.policy.pap.main.parameters.RequestParams;
*/
public class UpdateReq extends RequestImpl {
+ private static final Logger logger = LoggerFactory.getLogger(RequestImpl.class);
+
/**
* Policies to be undeployed if the request fails.
*/
@@ -94,14 +99,19 @@ public class UpdateReq extends RequestImpl {
}
Set<ToscaConceptIdentifier> actualSet = new HashSet<>(alwaysList(response.getPolicies()));
- Set<ToscaConceptIdentifier> expectedSet = new HashSet<>(alwaysList(message.getPolicies()).stream()
+ Set<ToscaConceptIdentifier> expectedSet = new HashSet<>(alwaysList(message.getPoliciesToBeDeployed()).stream()
.map(ToscaPolicy::getIdentifier).collect(Collectors.toSet()));
getNotifier().processResponse(response.getName(), message.getPdpGroup(), expectedSet, actualSet);
- // see if the policies match
+ Set<ToscaConceptIdentifier> expectedUndeploySet =
+ new HashSet<>(alwaysList(message.getPoliciesToBeUndeployed()));
+
+ if (actualSet.stream().anyMatch(expectedUndeploySet::contains)) {
+ logger.info("some policies have failed to undeploy");
+ }
- if (!actualSet.equals(expectedSet)) {
+ if (!actualSet.containsAll(expectedSet)) {
// need to undeploy the policies that are expected, but missing from the
// response
undeployPolicies = expectedSet;
@@ -130,9 +140,6 @@ public class UpdateReq extends RequestImpl {
Map<ToscaConceptIdentifier, ToscaPolicy> newDeployMap = update.getPoliciesToBeDeployed().stream()
.collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy));
- // Merge full lists
- final List<ToscaPolicy> fullPolicies = update.getPolicies();
-
// Merge undpeloy lists
Set<ToscaConceptIdentifier> policiesToBeUndeployedSet = new HashSet<>(getMessage().getPoliciesToBeUndeployed());
policiesToBeUndeployedSet.removeAll(newDeployMap.keySet());
@@ -140,19 +147,13 @@ public class UpdateReq extends RequestImpl {
final List<ToscaConceptIdentifier> policiestoBeUndeployed = new LinkedList<>(policiesToBeUndeployedSet);
// Merge deploy lists
- final List<ToscaPolicy> policiesToBeDeployed;
- if (update.getPoliciesToBeDeployed() == update.getPolicies()) {
- policiesToBeDeployed = update.getPoliciesToBeDeployed();
- } else {
- Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployedMap = getMessage().getPoliciesToBeDeployed()
- .stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy));
- policiesToBeDeployedMap.keySet().removeAll(update.getPoliciesToBeUndeployed());
- policiesToBeDeployedMap.putAll(newDeployMap);
- policiesToBeDeployed = new LinkedList<>(policiesToBeDeployedMap.values());
- }
+ Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployedMap = getMessage().getPoliciesToBeDeployed()
+ .stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy));
+ policiesToBeDeployedMap.keySet().removeAll(update.getPoliciesToBeUndeployed());
+ policiesToBeDeployedMap.putAll(newDeployMap);
+ final List<ToscaPolicy> policiesToBeDeployed = new LinkedList<>(policiesToBeDeployedMap.values());
// Set lists in update
- update.setPolicies(fullPolicies);
update.setPoliciesToBeDeployed(policiesToBeDeployed);
update.setPoliciesToBeUndeployed(policiestoBeUndeployed);
@@ -172,24 +173,15 @@ public class UpdateReq extends RequestImpl {
}
// see if the policies are the same
- Set<ToscaPolicy> set1 = new HashSet<>(alwaysList(first.getPolicies()));
- Set<ToscaPolicy> set2 = new HashSet<>(alwaysList(second.getPolicies()));
+ Set<ToscaPolicy> set1 = new HashSet<>(alwaysList(first.getPoliciesToBeDeployed()));
+ Set<ToscaPolicy> set2 = new HashSet<>(alwaysList(second.getPoliciesToBeDeployed()));
if (!(set1.equals(set2))) {
return false;
}
- Map<ToscaConceptIdentifier, ToscaPolicy> dep1 = first.getPolicies().stream()
- .collect(Collectors.toMap(ToscaPolicy::getIdentifier, p -> p));
- Map<ToscaConceptIdentifier, ToscaPolicy> dep2 = second.getPoliciesToBeDeployed()
- .stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, p -> p));
-
- if (!(dep1.equals(dep2))) {
- return false;
- }
-
- HashSet<ToscaConceptIdentifier> undep1 = new HashSet<>(alwaysList(first.getPoliciesToBeUndeployed()));
- HashSet<ToscaConceptIdentifier> undep2 = new HashSet<>(alwaysList(second.getPoliciesToBeUndeployed()));
+ Set<ToscaConceptIdentifier> undep1 = new HashSet<>(alwaysList(first.getPoliciesToBeUndeployed()));
+ Set<ToscaConceptIdentifier> undep2 = new HashSet<>(alwaysList(second.getPoliciesToBeUndeployed()));
return undep1.equals(undep2);
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java
index f0de7f9a..c8f67d75 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -121,11 +121,11 @@ public class PdpGroupStateChangeProvider extends PdpMessageGenerator {
String pdpInstanceId = pdp.getInstanceId();
final var pdpUpdatemessage =
createPdpUpdateMessage(pdpGroup.getName(), subGroup, pdp.getInstanceId(),
- policies, policies, null);
+ policies, null);
final var pdpStateChangeMessage =
createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState);
updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId,
- pdpStateChangeMessage.getState(), databaseProvider, pdpUpdatemessage.getPolicies());
+ pdpStateChangeMessage.getState(), databaseProvider, pdpUpdatemessage.getPoliciesToBeDeployed());
requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage);
LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage);
LOGGER.debug("Sent PdpStateChange message - {}", pdpStateChangeMessage);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
index 6aefce01..a21c2a15 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
@@ -233,8 +233,6 @@ public abstract class ProviderBase {
update.setDescription(group.getDescription());
update.setPdpGroup(group.getName());
update.setPdpSubgroup(subgroup.getPdpType());
- update.setPolicies(subgroup.getPolicies().stream().map(ToscaConceptIdentifierOptVersion::new)
- .map(ident -> getPolicy(data, ident)).collect(Collectors.toList()));
update.setPoliciesToBeDeployed(data.getPoliciesToBeDeployed());
update.setPoliciesToBeUndeployed(data.getPoliciesToBeUndeployed());
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
index 923871eb..235c852e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
@@ -220,7 +220,7 @@ public class SessionData {
}
logger.info("add update and state-change {} {} {} policies={}", update.getName(), update.getPdpGroup(),
- update.getPdpSubgroup(), update.getPolicies().size());
+ update.getPdpSubgroup(), update.getPoliciesToBeDeployed().size());
pdpRequests.put(update.getName(), Pair.of(update, change));
}
@@ -231,7 +231,7 @@ public class SessionData {
*/
public void addUpdate(PdpUpdate update) {
logger.info("add update {} {} {} policies={}", update.getName(), update.getPdpGroup(), update.getPdpSubgroup(),
- update.getPolicies().size());
+ update.getPoliciesToBeDeployed().size());
pdpRequests.compute(update.getName(), (name, data) -> Pair.of(update, (data == null ? null : data.getRight())));
}