summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2021-04-28 16:24:44 -0500
committerjhh <jorge.hernandez-herrero@att.com>2021-05-03 15:46:00 -0500
commitc2e25b77402244fdc9f443628ec127e03606c9f6 (patch)
tree8135ed26db0b38214bc3f3429462a465fe6350e9 /feature-lifecycle/src
parent20a3082d4423a7b432187cd02b172b696e8f5f61 (diff)
support for PAP delta updates
Issue-ID: POLICY-3187 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I91b343feb28fdff6b2391387e51defbdcfbe7b0f Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java38
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java16
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java27
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java26
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java144
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java26
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java29
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java14
8 files changed, 200 insertions, 120 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
index ea5e49f4..c4f2f873 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
@@ -268,7 +268,7 @@ public class LifecycleFsm implements Startable {
List<PolicyTypeDroolsController> opControllers =
policyTypesMap.values().stream()
- .filter(typeController -> typeController instanceof PolicyTypeDroolsController)
+ .filter(PolicyTypeDroolsController.class::isInstance)
.map(PolicyTypeDroolsController.class::cast)
.filter(opController -> opController.getControllers().containsKey(controller.getName()))
.collect(Collectors.toList());
@@ -522,13 +522,43 @@ public class LifecycleFsm implements Startable {
.flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList());
}
- protected String getPolicyIdsMessage(List<ToscaPolicy> policies) {
+ /**
+ * Get the policy identifiers.
+ */
+ public List<ToscaConceptIdentifier> getPolicyIds(List<ToscaPolicy> policies) {
return policies.stream()
+ .map(ToscaPolicy::getIdentifier)
.distinct()
- .map(ToscaPolicy::getIdentifier).collect(Collectors.toList())
- .toString();
+ .collect(Collectors.toList());
+ }
+
+ protected String getPolicyIdsMessage(List<ToscaPolicy> policies) {
+ return getPolicyIds(policies).toString();
+ }
+
+ protected List<ToscaPolicy> removeByPolicyId(@NonNull List<ToscaPolicy> policies,
+ @NonNull List<ToscaConceptIdentifier> toRemoveList) {
+ policies.removeIf(policy -> toRemoveList.contains(policy.getIdentifier()));
+ return policies;
}
+ protected List<ToscaPolicy> removeByPolicyId(@NonNull List<ToscaConceptIdentifier> toRemoveList) {
+ return removeByPolicyId(getActivePolicies(), toRemoveList);
+ }
+
+ protected List<ToscaPolicy> mergePolicies(@NonNull List<ToscaPolicy> addPolicies,
+ @NonNull List<ToscaConceptIdentifier> removePolicies) {
+
+ if (addPolicies.isEmpty() && removePolicies.isEmpty()) {
+ return getActivePolicies();
+ }
+
+ List<ToscaPolicy> policies = getActivePolicies();
+ policies.addAll(addPolicies);
+ return removeByPolicyId(new ArrayList<>(new HashSet<>(policies)), removePolicies);
+ }
+
+
/**
* Do I support the mandatory policy types?.
*/
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java
index dacb6058..4c92b67b 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java
@@ -122,9 +122,6 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
@Override
public boolean update(@NonNull PdpUpdate update) {
- // UPDATE messages contain the complete universe of active policies in this PDP-D
- // regardless if they were already functioning in the PDP-D or new.
-
synchronized (fsm) {
if (update.getPdpHeartbeatIntervalMs() != null
&& !fsm.setStatusIntervalAction(update.getPdpHeartbeatIntervalMs() / 1000)) {
@@ -137,6 +134,15 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
fsm.setSubGroup(update.getPdpSubgroup());
+ // Compute the desired final policy set after processing this update.
+ // Delta policies allows for the PAP to send us just the policies to deploy and undeploy
+ // Note that in this mode of operation, there may be dependent policies in the
+ // active inventory. For example a request to remove a controller policy in a
+ // delta request, may affect operational or artifact policies in use.
+
+ List<ToscaPolicy> desiredPolicyInventory =
+ fsm.mergePolicies(update.getPoliciesToBeDeployed(), update.getPoliciesToBeUndeployed());
+
// snapshot the active policies previous to apply the new set of active
// policies as given by the PAP in the update message
@@ -144,9 +150,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
Map<String, List<ToscaPolicy>> activePoliciesPreUpdateMap =
fsm.groupPoliciesByPolicyType(activePoliciesPreUpdate);
- // update policies with the current set of active policies
-
- Pair<List<ToscaPolicy>, List<ToscaPolicy>> results = updatePoliciesWithResults(update.getPolicies());
+ Pair<List<ToscaPolicy>, List<ToscaPolicy>> results = updatePoliciesWithResults(desiredPolicyInventory);
// summary message to return in the update response to the PAP
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
index 9af78ae6..381fd600 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
@@ -26,7 +26,6 @@ import io.swagger.annotations.ApiParam;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
-import java.util.stream.Collectors;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -284,11 +283,7 @@ public class RestLifecycleManager {
return Response.status(Response.Status.NOT_FOUND).build();
}
- List<ToscaPolicy> policies =
- LifecycleFeature.getFsm().getPoliciesMap().values().stream().collect(Collectors.toList());
- policies.add(toscaPolicy);
-
- boolean updateResult = LifecycleFeature.getFsm().update(getPolicyUpdate(policies));
+ boolean updateResult = LifecycleFeature.getFsm().update(getDeployPolicyUpdate(List.of(toscaPolicy)));
return Response.status((updateResult ? Response.Status.OK : Response.Status.NOT_ACCEPTABLE))
.entity(updateResult)
.build();
@@ -345,11 +340,8 @@ public class RestLifecycleManager {
return Response.status(Response.Status.NOT_FOUND).build();
}
- List<ToscaPolicy> policies =
- LifecycleFeature.getFsm().getPoliciesMap().values().stream().collect(Collectors.toList());
- policies.removeIf(otherPolicy -> policy.getIdentifier().equals(otherPolicy.getIdentifier()));
return Response.status(Response.Status.OK)
- .entity(LifecycleFeature.getFsm().update(getPolicyUpdate(policies)))
+ .entity(LifecycleFeature.getFsm().update(getUndeployPolicyUpdate(List.of(policy))))
.build();
}
@@ -448,12 +440,23 @@ public class RestLifecycleManager {
return LifecycleFeature.getFsm().getPolicyTypesMap().get(policy.getTypeIdentifier());
}
- private PdpUpdate getPolicyUpdate(List<ToscaPolicy> policies) {
+ private PdpUpdate getPolicyUpdate() {
PdpUpdate update = new PdpUpdate();
update.setName(LifecycleFeature.getFsm().getName());
update.setPdpGroup(LifecycleFeature.getFsm().getGroup());
update.setPdpSubgroup(LifecycleFeature.getFsm().getSubGroup());
- update.setPolicies(policies);
+ return update;
+ }
+
+ private PdpUpdate getDeployPolicyUpdate(List<ToscaPolicy> policies) {
+ PdpUpdate update = getPolicyUpdate();
+ update.setPoliciesToBeDeployed(policies);
+ return update;
+ }
+
+ private PdpUpdate getUndeployPolicyUpdate(List<ToscaPolicy> policies) {
+ PdpUpdate update = getPolicyUpdate();
+ update.setPoliciesToBeUndeployed(LifecycleFeature.fsm.getPolicyIds(policies));
return update;
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
index 9d36f2ed..73d265c2 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
@@ -242,6 +242,32 @@ public class LifecycleFsmTest {
assertEquals(5, status.getStatistics().getPolicyExecutedSuccessCount());
}
+ @Test
+ public void testMergePolicies() {
+ assertEquals(List.of(), fsm.getActivePolicies());
+ assertEquals(List.of(), fsm.mergePolicies(List.of(), List.of()));
+
+ fsm.deployedPolicyAction(opPolicy);
+ fsm.deployedPolicyAction(controllerPolicy);
+ assertEquals(List.of(opPolicy, controllerPolicy), fsm.getActivePolicies());
+ assertEquals(List.of(opPolicy, controllerPolicy), fsm.mergePolicies(List.of(), List.of()));
+ assertEquals(List.of(opPolicy), fsm.mergePolicies(List.of(), List.of(controllerPolicy.getIdentifier())));
+
+ assertEquals(List.of(controllerPolicy, op2Policy, valPolicy, opPolicy, unvalPolicy),
+ fsm.mergePolicies(List.of(op2Policy, valPolicy, unvalPolicy), List.of()));
+ assertEquals(List.of(controllerPolicy, op2Policy, valPolicy, opPolicy, unvalPolicy),
+ fsm.mergePolicies(List.of(controllerPolicy, opPolicy, op2Policy, valPolicy, unvalPolicy), List.of()));
+ assertEquals(List.of(op2Policy, valPolicy, unvalPolicy),
+ fsm.mergePolicies(List.of(op2Policy, valPolicy, unvalPolicy),
+ List.of(controllerPolicy.getIdentifier(), opPolicy.getIdentifier())));
+ }
+
+ @Test
+ public void testGetPolicyIdsMessages() {
+ assertEquals("[operational.modifyconfig 1.0.0, example.controller 1.0.0]",
+ fsm.getPolicyIds(List.of(opPolicy, controllerPolicy)).toString());
+ }
+
protected void deployAllPolicies() {
fsm.deployedPolicyAction(controllerPolicy);
fsm.deployedPolicyAction(controller2Policy);
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
index 9ae43e21..74d20898 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
@@ -209,148 +209,127 @@ public class LifecycleFsmUpdateTest {
@Test
public void testUpdate() throws CoderException {
- assertEquals(0, fsm.getPoliciesMap().size());
- assertEquals("ACTIVE", fsm.state().toString());
- assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
- verifyDeployStats(0, 0, 0);
+ verifyInitState();
// native controller policy - deploy
// Delta: +controllerPolicy
- assertTrue(fsm.update(getPdpUpdate(List.of(controllerPolicy))));
- verifyActivePolicies(List.of(controllerPolicy));
- verifyDeployStats(1, 1, 0);
+ deltaUpdate(List.of(controllerPolicy), List.of(), List.of(controllerPolicy), 1, 1, 0);
// no policies - undeploy
- // Delta: []
- assertTrue(fsm.update(getPdpUpdate(Collections.emptyList())));
- verifyActivePolicies(Collections.emptyList());
- verifyDeployStats(2, 2, 0);
+ // Delta: -controllerPolicy
+ deltaUpdate(List.of(), List.of(controllerPolicy), List.of(), 2, 2, 0);
// native controller + artifact policy (out of order) - deploy
// Delta: +artifactPolicy, +controllerPolicy
- assertTrue(fsm.update(getPdpUpdate(List.of(artifactPolicy, controllerPolicy))));
- verifyActivePolicies(List.of(artifactPolicy, controllerPolicy));
- verifyDeployStats(4, 4, 0);
+ deltaUpdate(List.of(artifactPolicy, controllerPolicy), List.of(),
+ List.of(artifactPolicy, controllerPolicy), 4, 4, 0);
// attempt to deploy opPolicy but invalid controller
// Delta: +opPolicy
- assertFalse(fsm.update(getPdpUpdate(List.of(artifactPolicy, opPolicy, controllerPolicy))));
+ assertFalse(fsm.update(getPdpUpdate(List.of(opPolicy), List.of())));
assertEquals(1, PolicyControllerConstants.getFactory().inventory().size());
assertFalse(fsm.getActivePolicies().contains(opPolicy));
verifyExists(false, "lifecycle", List.of(opPolicy));
- verifyActivePolicies(List.of(artifactPolicy, controllerPolicy));
- verifyDeployStats(5, 4, 1);
+ verifyDeploy(List.of(artifactPolicy, controllerPolicy), 5, 4, 1);
// Delta: +opPolicy
opPolicy.getProperties().remove("controllerName");
- assertTrue(fsm.update(getPdpUpdate(List.of(artifactPolicy, opPolicy, controllerPolicy))));
+ deltaUpdate(List.of(opPolicy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy), 6, 5, 1);
verifyExists(true, "lifecycle", List.of(opPolicy));
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
- verifyDeployStats(6, 5, 1);
// Delta: -opPolicy
- assertTrue(fsm.update(getPdpUpdate(List.of(artifactPolicy, controllerPolicy))));
+ deltaUpdate(List.of(), List.of(opPolicy),
+ List.of(controllerPolicy, artifactPolicy), 7, 6, 1);
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().exists(opPolicy));
- verifyActivePolicies(List.of(controllerPolicy, artifactPolicy));
- verifyDeployStats(7, 6, 1);
// Delta: -artifactPolicy
- assertTrue(fsm.update(getPdpUpdate(List.of(controllerPolicy))));
+ deltaUpdate(List.of(), List.of(artifactPolicy), List.of(controllerPolicy), 8, 7, 1);
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
- verifyActivePolicies(List.of(controllerPolicy));
- verifyDeployStats(8, 7, 1);
// Delta: -controllerPolicy
- assertTrue(fsm.update(getPdpUpdate(Collections.emptyList())));
+ deltaUpdate(List.of(), List.of(controllerPolicy), List.of(), 9, 8, 1);
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
- assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
- verifyActivePolicies(Collections.emptyList());
- verifyDeployStats(9, 8, 1);
// Delta: +controllerPolicy, +artifactPolicy, and +opPolicy
- assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, artifactPolicy, controllerPolicy))));
+ deltaUpdate(List.of(opPolicy, artifactPolicy, controllerPolicy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy), 12, 11, 1);
verifyExists(true, "lifecycle", List.of(opPolicy));
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
- verifyDeployStats(12, 11, 1);
// Delta: -artifactPolicy
- assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, controllerPolicy))));
+ assertTrue(fsm.update(getPdpUpdate(List.of(), List.of(artifactPolicy))));
assertEquals(1, PolicyControllerConstants.getFactory().inventory().size());
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
verifyDeployStats(13, 12, 1);
// Delta: +artifactPolicy
// from deltas, all delta updates should be successfully applied
- assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, controllerPolicy, artifactPolicy))));
+ deltaUpdate(List.of(artifactPolicy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy), 14, 13, 1);
verifyExists(true, "lifecycle", List.of(opPolicy));
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
- verifyDeployStats(14, 13, 1);
// Delta: -controllerPolicy
// from deltas, all delta updates should be successfully applied
- assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, artifactPolicy))));
+ assertTrue(fsm.update(getPdpUpdate(List.of(), List.of(controllerPolicy))));
assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
verifyDeployStats(15, 14, 1);
// Delta: +controllerPolicy
// from deltas, all delta updates should be successfully applied
- assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, controllerPolicy, artifactPolicy))));
+ deltaUpdate(List.of(controllerPolicy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy), 16, 15, 1);
verifyExists(true, "lifecycle", List.of(opPolicy));
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
- verifyDeployStats(16, 15, 1);
// Delta: +op2Policy, +controller2Policy
// from deltas, all delta updates should be successfully applied
op2Policy.getProperties().put("controllerName", "lifecycle");
- assertTrue(fsm.update(getPdpUpdate(
- List.of(opPolicy, controllerPolicy, artifactPolicy, op2Policy, controller2Policy))));
+ deltaUpdate(List.of(op2Policy, controller2Policy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy),
+ 18, 17, 1);
+ verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy));
+ assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained());
+
+ // same operation with duplicates - idempotent operation
+ deltaUpdate(List.of(op2Policy, controller2Policy, opPolicy), List.of(valPolicy, unvalPolicy),
+ List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy),
+ 18, 17, 1);
verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy));
assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained());
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy));
- verifyDeployStats(18, 17, 1);
// Delta: +artifact2policy, +valPolicy, +unvalPolicy
// from deltas, all delta updates should be successfully applied
- assertTrue(fsm.update(getPdpUpdate(
- List.of(opPolicy, controllerPolicy, artifactPolicy,
- op2Policy, controller2Policy, valPolicy, unvalPolicy, artifact2Policy))));
+ deltaUpdate(List.of(valPolicy, unvalPolicy, artifact2Policy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy, valPolicy,
+ unvalPolicy, artifact2Policy), 21, 20, 1);
verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy, valPolicy, unvalPolicy));
verifyExists(true, "foo", List.of(valPolicy, unvalPolicy));
verifyExists(false, "foo", List.of(opPolicy, op2Policy));
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy,
- controller2Policy, valPolicy, unvalPolicy, artifact2Policy));
- verifyDeployStats(21, 20, 1);
- // Delta: -artifact2Policy, +valPolicy
+ // Delta: -artifact2Policy, -unvalPolicy
// from deltas, all delta updates should be successfully applied, and unvalPolicy disabled
- assertTrue(fsm.update(getPdpUpdate(
- List.of(opPolicy, controllerPolicy, artifactPolicy,
- op2Policy, controller2Policy, valPolicy))));
+ deltaUpdate(List.of(), List.of(artifact2Policy, unvalPolicy),
+ List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy, valPolicy),
+ 23, 22, 1);
verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy, valPolicy));
verifyExists(false, "lifecycle", List.of(unvalPolicy));
assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained());
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy,
- controller2Policy, valPolicy));
- verifyDeployStats(23, 22, 1);
// Delta: +artifact2Policy
// from deltas, all delta updates should be successfully applied, opPolicy, op2Policy and unvalPolicy
// should be reapplied.
- assertTrue(fsm.update(getPdpUpdate(
- List.of(opPolicy, controllerPolicy, artifactPolicy,
- op2Policy, controller2Policy, valPolicy, artifact2Policy))));
+ assertTrue(fsm.update(getPdpUpdate(List.of(artifact2Policy), List.of())));
+ deltaUpdate(List.of(artifact2Policy), List.of(),
+ List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy,
+ valPolicy, artifact2Policy),
+ 24, 23, 1);
verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy, valPolicy));
verifyExists(false, "lifecycle", List.of(unvalPolicy));
verifyExists(true, "foo", List.of(valPolicy));
verifyExists(false, "foo", List.of(opPolicy, op2Policy, unvalPolicy));
- verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy,
- controller2Policy, valPolicy, artifact2Policy));
- verifyDeployStats(24, 23, 1);
- // Delta: -controllerPolicy, +artifactPolicy, +unvalPolicy
+ // Delta: -controllerPolicy, -artifactPolicy, +unvalPolicy
// from deltas, all delta updates should be successful
- assertTrue(fsm.update(getPdpUpdate(
- List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy))));
+ assertTrue(fsm.update(getPdpUpdate(List.of(unvalPolicy), List.of(controllerPolicy, artifactPolicy))));
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
verifyExists(true, "foo", List.of(valPolicy, unvalPolicy));
verifyExists(false, "foo", List.of(opPolicy, op2Policy));
@@ -364,25 +343,46 @@ public class LifecycleFsmUpdateTest {
// Delta: -opPolicy, -op2Policy, -controller2Policy, -valPolicy, -artifact2Policy, -unvalPolicy
// from deltas, -opPolicy and -op2Policy undeploys will fail since there is not controller with that
// policy type supported
- assertFalse(fsm.update(getPdpUpdate(Collections.emptyList())));
+ assertFalse(fsm.update(getPdpUpdate(List.of(),
+ List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy))));
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("foo"));
assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
- verifyActivePolicies(Collections.emptyList());
- verifyDeployStats(33, 30, 3);
+ verifyDeploy(List.of(), 33, 30, 3);
fsm.shutdown();
}
- protected PdpUpdate getPdpUpdate(List<ToscaPolicy> policies) {
+ private void verifyInitState() {
+ assertEquals(0, fsm.getPoliciesMap().size());
+ assertEquals("ACTIVE", fsm.state().toString());
+ assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
+ verifyDeployStats(0, 0, 0);
+ }
+
+ protected PdpUpdate getPdpUpdate(List<ToscaPolicy> policiesToDeploy, List<ToscaPolicy> policiesToUndeploy) {
PdpUpdate update = new PdpUpdate();
update.setName(NetworkUtil.getHostname());
update.setPdpGroup("A");
update.setPdpSubgroup("a");
- update.setPolicies(policies);
+ update.setPolicies(List.of());
+ update.setPoliciesToBeDeployed(policiesToDeploy);
+ update.setPoliciesToBeUndeployed(fsm.getPolicyIds(policiesToUndeploy));
return update;
}
+ protected void deltaUpdate(List<ToscaPolicy> deploy, List<ToscaPolicy> undeploy, List<ToscaPolicy> active,
+ long count, long success, long failures) throws CoderException {
+ assertTrue(fsm.update(getPdpUpdate(deploy, undeploy)));
+ verifyDeploy(active, count, success, failures);
+ }
+
+ private void verifyDeploy(List<ToscaPolicy> active, long count, long success, long failures)
+ throws CoderException {
+ verifyActivePolicies(active);
+ verifyDeployStats(count, success, failures);
+ }
+
protected void verifyExists(boolean exists, String controller, List<ToscaPolicy> policies) {
assertTrue(PolicyControllerConstants.getFactory().get(controller).getDrools().isBrained());
for (ToscaPolicy policy : policies) {
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
index 2b105f91..b56d21fa 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
@@ -30,7 +30,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -120,7 +119,7 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
update.setName(NetworkUtil.getHostname());
update.setPdpGroup("W");
update.setPdpSubgroup("w");
- update.setPolicies(List.of(policyNativeController));
+ update.setPoliciesToBeDeployed(List.of(policyNativeController));
assertFalse(fsm.update(update));
assertEquals(0, fsm.getPoliciesMap().size());
@@ -146,13 +145,13 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
Map<String, String> controllerMap =
(Map<String, String>) policyNativeArtifact.getProperties().get("controller");
controllerMap.put("name", "xyz987");
- update.setPolicies(List.of(policyNativeController, policyNativeArtifact));
+ update.setPoliciesToBeDeployed(List.of(policyNativeController, policyNativeArtifact));
assertFalse(fsm.update(update));
// add a registered controller
controllerMap.put("name", "lifecycle");
- update.setPolicies(List.of(policyNativeController, policyNativeArtifact));
+ update.setPoliciesToBeDeployed(List.of(policyNativeController, policyNativeArtifact));
assertTrue(fsm.update(update));
assertEquals(2, fsm.getPoliciesMap().size());
@@ -165,7 +164,7 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
ToscaPolicy opPolicyRestart =
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
- update.setPolicies(List.of(policyNativeController, policyNativeArtifact, opPolicyRestart));
+ update.setPoliciesToBeDeployed(List.of(policyNativeController, policyNativeArtifact, opPolicyRestart));
assertFalse(fsm.update(update));
assertEquals(2, fsm.getPoliciesMap().size());
@@ -212,7 +211,8 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
opPolicyRestartV2.setVersion("2.0.0");
opPolicyRestartV2.getProperties().put("controllerName", "lifecycle");
- update.setPolicies(List.of(policyNativeController, policyNativeArtifact, opPolicyRestartV2));
+ update.setPoliciesToBeDeployed(List.of(policyNativeController, policyNativeArtifact, opPolicyRestartV2));
+ update.setPoliciesToBeUndeployed(List.of(opPolicyRestart.getIdentifier()));
assertTrue(fsm.update(update));
assertEquals(3, fsm.getPoliciesMap().size());
@@ -225,7 +225,8 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
assertEquals(1, factPolicies.size());
assertEquals(opPolicyRestartV2, factPolicies.get(0));
- update.setPolicies(List.of(policyNativeController, policyNativeArtifact));
+ update.setPoliciesToBeDeployed(List.of());
+ update.setPoliciesToBeUndeployed(List.of(opPolicyRestartV2.getIdentifier()));
assertTrue(fsm.update(update));
assertEquals(2, fsm.getPoliciesMap().size());
@@ -238,7 +239,9 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
assertEquals(0, factPolicies.size());
assertTrue(controllerSupport.getController().getDrools().isBrained());
- update.setPolicies(List.of(policyNativeController));
+ update.setPoliciesToBeDeployed(List.of());
+ update.setPoliciesToBeUndeployed(List.of(policyNativeArtifact.getIdentifier(),
+ opPolicyRestartV2.getIdentifier()));
assertTrue(fsm.update(update));
assertFalse(controllerSupport.getController().getDrools().isBrained());
assertEquals(1, fsm.getPoliciesMap().size());
@@ -249,13 +252,16 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
ToscaPolicy policyNativeFooController =
getPolicyFromFile(FOO_NATIVE_DROOLS_POLICY_JSON, FOO_NATIVE_DROOLS_CONTROLLER_POLICY_NAME);
- update.setPolicies(List.of(policyNativeController, policyNativeFooController));
+ update.setPoliciesToBeUndeployed(List.of());
+ update.setPoliciesToBeDeployed(List.of(policyNativeFooController));
assertTrue(fsm.update(update));
assertEquals(2, fsm.getPoliciesMap().size());
assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
assertEquals(policyNativeFooController, fsm.getPoliciesMap().get(policyNativeFooController.getIdentifier()));
- update.setPolicies(Collections.emptyList());
+ update.setPoliciesToBeDeployed(List.of());
+ update.setPoliciesToBeUndeployed(List.of(policyNativeController.getIdentifier(),
+ policyNativeFooController.getIdentifier()));
assertTrue(fsm.update(update));
assertThatIllegalArgumentException().isThrownBy(() -> controllerSupport.getController().getDrools());
assertNull(fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
index ac0859e7..bd6b392d 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
@@ -33,8 +33,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -194,7 +192,6 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
update.setName(NetworkUtil.getHostname());
update.setPdpGroup("W");
update.setPdpSubgroup("w");
- update.setPolicies(Collections.emptyList());
fsm.start(controllerSupport.getController());
assertTrue(fsm.update(update));
@@ -206,7 +203,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
ToscaPolicy toscaPolicyRestartV1 =
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
toscaPolicyRestartV1.getProperties().put("controllerName", "lifecycle");
- update.setPolicies(Collections.singletonList(toscaPolicyRestartV1));
+ update.setPoliciesToBeDeployed(List.of(toscaPolicyRestartV1));
int qlength = fsm.client.getSink().getRecentEvents().length;
@@ -248,7 +245,9 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
// undeploy operational.restart policy
- update.setPolicies(Collections.emptyList());
+ update.setPolicies(List.of());
+ update.setPoliciesToBeDeployed(List.of());
+ update.setPoliciesToBeUndeployed(List.of(toscaPolicyRestartV1.getIdentifier()));
assertTrue(fsm.update(update));
assertEquals(qlength + 3, fsm.client.getSink().getRecentEvents().length);
assertEquals(3, fsm.policyTypesMap.size());
@@ -262,7 +261,9 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
// redeploy operational.restart policy
- update.setPolicies(Collections.singletonList(toscaPolicyRestartV1));
+ update.setPolicies(List.of());
+ update.setPoliciesToBeUndeployed(List.of());
+ update.setPoliciesToBeDeployed(List.of(toscaPolicyRestartV1));
assertTrue(fsm.update(update));
assertEquals(qlength + 4, fsm.client.getSink().getRecentEvents().length);
assertEquals(3, fsm.policyTypesMap.size());
@@ -281,7 +282,9 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
toscaPolicyRestartV2.setVersion("2.0.0");
toscaPolicyRestartV2.getProperties().put("controllerName", "lifecycle");
- update.setPolicies(Collections.singletonList(toscaPolicyRestartV2));
+ update.setPolicies(List.of());
+ update.setPoliciesToBeUndeployed(List.of(toscaPolicyRestartV1.getIdentifier()));
+ update.setPoliciesToBeDeployed(List.of(toscaPolicyRestartV2));
assertTrue(fsm.update(update));
assertEquals(qlength + 5, fsm.client.getSink().getRecentEvents().length);
assertEquals(3, fsm.policyTypesMap.size());
@@ -300,7 +303,9 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
ToscaPolicy toscaPolicyFirewall =
getExamplesPolicy("policies/vFirewall.policy.operational.input.tosca.json", "operational.modifyconfig");
toscaPolicyFirewall.getProperties().put("controllerName", "lifecycle");
- update.setPolicies(Arrays.asList(toscaPolicyRestartV2, toscaPolicyFirewall));
+ update.setPolicies(List.of());
+ update.setPoliciesToBeUndeployed(List.of());
+ update.setPoliciesToBeDeployed(List.of(toscaPolicyRestartV2, toscaPolicyFirewall));
assertTrue(fsm.update(update));
assertEquals(qlength + 6, fsm.client.getSink().getRecentEvents().length);
assertEquals(3, fsm.policyTypesMap.size());
@@ -319,6 +324,9 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
long interval = 10 * originalInterval;
update.setPdpHeartbeatIntervalMs(interval * 1000L);
+ update.setPolicies(List.of());
+ update.setPoliciesToBeUndeployed(List.of());
+ update.setPoliciesToBeDeployed(List.of());
assertTrue(fsm.update(update));
assertEquals(PdpState.ACTIVE, fsm.state());
@@ -329,7 +337,10 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
String badIntegerPolicy =
Files.readString(Paths.get(POLICY_COMPLIANT_VCPE_BAD_INTEGER_JSON), StandardCharsets.UTF_8);
ToscaPolicy toscaPolicyRestartBad = new StandardCoder().decode(badIntegerPolicy, ToscaPolicy.class);
- update.setPolicies(Collections.singletonList(toscaPolicyRestartBad));
+ update.setPolicies(List.of());
+ update.setPoliciesToBeUndeployed(List.of(toscaPolicyRestartV2.getIdentifier(),
+ toscaPolicyFirewall.getIdentifier()));
+ update.setPoliciesToBeDeployed(List.of(toscaPolicyRestartBad));
assertFalse(fsm.update(update));
assertTrue(controllerSupport.getController().getDrools().delete(ToscaPolicy.class));
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
index ef01a593..13d65915 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
@@ -30,8 +30,7 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -148,7 +147,6 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
update.setName(NetworkUtil.getHostname());
update.setPdpGroup("Z");
update.setPdpSubgroup("z");
- update.setPolicies(Collections.emptyList());
long interval = 2 * fsm.getStatusTimerSeconds();
update.setPdpHeartbeatIntervalMs(interval * 1000L);
@@ -171,7 +169,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
ToscaPolicy toscaPolicy =
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
toscaPolicy.getProperties().put("controllerName", "lifecycle");
- update.setPolicies(Arrays.asList(toscaPolicy));
+ update.setPoliciesToBeDeployed(List.of(toscaPolicy));
assertFalse(fsm.update(update));
@@ -229,7 +227,8 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
ToscaPolicy toscaPolicy2 =
getExamplesPolicy("policies/vFirewall.policy.operational.input.tosca.json", "operational.modifyconfig");
toscaPolicy.getProperties().remove("controllerName");
- update.setPolicies(Arrays.asList(toscaPolicy2));
+ update.setPoliciesToBeUndeployed(List.of(toscaPolicy.getIdentifier()));
+ update.setPoliciesToBeDeployed(List.of(toscaPolicy2));
assertTrue(fsm.update(update));
assertEquals(3, fsm.policyTypesMap.size());
assertEquals(1, fsm.policiesMap.size());
@@ -239,7 +238,8 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
update.setPdpGroup(null);
update.setPdpSubgroup(null);
- update.setPolicies(Collections.emptyList());
+ update.setPoliciesToBeUndeployed(List.of(toscaPolicy2.getIdentifier()));
+ update.setPolicies(List.of());
assertTrue(fsm.update(update));
assertEquals(3, fsm.policyTypesMap.size());
assertEquals(0, fsm.policiesMap.size());
@@ -277,7 +277,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
ToscaPolicy toscaPolicy =
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
toscaPolicy.getProperties().put("controllerName", "lifecycle");
- update.setPolicies(Arrays.asList(toscaPolicy));
+ update.setPoliciesToBeDeployed(List.of(toscaPolicy));
controllerSupport.getController().start();
fsm.start(controllerSupport.getController());