aboutsummaryrefslogtreecommitdiffstats
path: root/models-sim/policy-models-sim-pdp
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2021-05-27 09:12:05 +0100
committerWayneDunican <wayne.dunican@est.tech>2021-05-27 20:03:00 +0100
commit64ce7957251a5de6fa57204e41e2699939adae47 (patch)
tree42bec72d6b6d876d86dae5f4fcff4821f2de177a /models-sim/policy-models-sim-pdp
parentd00c73842c6f8e7bb00b29d2fb5dd63b9cde4bfe (diff)
Remove policies field from PdpUpdate message
Issue-ID: POLICY-3323 Change-Id: I14dafe4a20f95e2ebe4279e5b6ae141e2ee4fc48 Signed-off-by: waynedunican <wayne.dunican@est.tech> Signed-off-by: WayneDunican <wayne.dunican@est.tech>
Diffstat (limited to 'models-sim/policy-models-sim-pdp')
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java25
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java2
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java4
3 files changed, 21 insertions, 10 deletions
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java
index 2262ee938..a90f74fba 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.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. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,9 @@
package org.onap.policy.models.sim.pdp.handler;
+import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
@@ -31,6 +33,7 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
* This class supports the handling of pdp update messages.
@@ -62,13 +65,19 @@ public class PdpUpdateMessageHandler {
}
pdpStatusContext.setPdpGroup(pdpUpdateMsg.getPdpGroup());
pdpStatusContext.setPdpSubgroup(pdpUpdateMsg.getPdpSubgroup());
- pdpStatusContext
- .setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
- if (pdpStatusContext.getState().equals(PdpState.ACTIVE) && !pdpUpdateMsg.getPolicies().isEmpty()) {
+ @SuppressWarnings("unchecked")
+ List<ToscaPolicy> policies = Registry.getOrDefault(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST,
+ List.class, new ArrayList<>());
+ policies.addAll(pdpUpdateMsg.getPoliciesToBeDeployed());
+ policies.removeIf(policy -> pdpUpdateMsg.getPoliciesToBeUndeployed().contains(policy.getIdentifier()));
+ pdpStatusContext.setPolicies(policies.stream().map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList()));
+ if (pdpStatusContext.getState().equals(PdpState.ACTIVE)
+ && !pdpUpdateMsg.getPoliciesToBeDeployed().isEmpty()) {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running.");
}
- Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies());
+ Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, policies);
if (null == pdpResponseDetails) {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful.");
@@ -102,8 +111,10 @@ public class PdpUpdateMessageHandler {
return false;
}
- return null != pdpStatusContext.getPolicies() && new PdpMessageHandler()
- .getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()).equals(pdpStatusContext.getPolicies());
+ return null != pdpStatusContext.getPolicies() && (pdpStatusContext.getPolicies()
+ .containsAll(new PdpMessageHandler().getToscaPolicyIdentifiers(
+ pdpUpdateMsg.getPoliciesToBeDeployed()))) && pdpStatusContext.getPolicies()
+ .stream().noneMatch(pdpUpdateMsg.getPoliciesToBeUndeployed()::contains);
}
/**
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
index 93015e94e..20c9cc1b0 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
@@ -133,7 +133,7 @@ public class TestPdpStateChangeListener {
toscaPolicy.setProperties(propertiesMap);
final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
- pdpUpdateMsg.setPolicies(toscaPolicies);
+ pdpUpdateMsg.setPoliciesToBeDeployed(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
return pdpUpdateMsg;
}
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
index 7bf70ddc1..0827f2619 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
@@ -125,11 +125,11 @@ public class TestPdpUpdateListener {
toscaPolicy.setProperties(propertiesMap);
final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
- pdpUpdateMsg.setPolicies(toscaPolicies);
+ pdpUpdateMsg.setPoliciesToBeDeployed(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
}
}