diff options
author | waynedunican <wayne.dunican@est.tech> | 2021-02-10 12:00:04 +0000 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2021-02-22 20:52:37 +0000 |
commit | ef2a2a1c93a78377e9bffe47d4d974d15bad4810 (patch) | |
tree | f7657b279fd9c95ba8f958650ff63340a279797d /main/src/test/java/org/onap | |
parent | 80a4d78e798bee6379961008c2d49b7fae5f2924 (diff) |
Support Policy updates between PAP and PDPs
Change to send only the policies that need to be updated (deployed/undeployed)
rather than full of policies to DMaap via the PDP_UPDATE message
Issue-ID: POLICY-2112
Change-Id: I65f8bf46f230afb9d4b6937cb89af1d9f05d2fbd
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'main/src/test/java/org/onap')
4 files changed, 141 insertions, 9 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java index 01edbdcf..d2dc1955 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java @@ -21,14 +21,18 @@ package org.onap.policy.pap.main.comm; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.utils.coder.CoderException; @@ -37,9 +41,12 @@ import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpStatus; import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.concepts.PdpUpdate; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; 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.CommonTestData; import org.onap.policy.pap.main.parameters.PdpParameters; import org.onap.policy.pap.main.rest.e2e.End2EndBase; @@ -202,6 +209,29 @@ public class PdpHeartbeatListenerTest extends End2EndBase { status9.setPolicies(idents9); pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status9); verifyPdpGroup(DEFAULT_GROUP, 0); + + // Test policy lists updated in createUpdate + ToscaPolicy polA = new ToscaPolicy(); + polA.setName("pol-a-1.1.1"); + polA.setVersion("1.1.1"); + ToscaPolicy polB = new ToscaPolicy(); + polB.setName("pol-b-1.1.1"); + polB.setVersion("1.1.1"); + List<ToscaPolicy> policies = new ArrayList<>(); + policies.add(polA); + policies.add(polB); + final CommonTestData testData = new CommonTestData(); + PdpParameters params = testData.getPapParameterGroup(1).getPdpParameters(); + List<ToscaConceptIdentifier> polsUndep = policies.stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params); + PdpUpdate update10 = handler.createPdpUpdateMessage( + status3.getPdpGroup(), new PdpSubGroup(), "pdp_2", + null, policies, policies, polsUndep); + assertSame(update10.getPolicies(), policies); + assertSame(update10.getPoliciesToBeDeployed(), policies); + assertSame(update10.getPoliciesToBeUndeployed(), polsUndep); + assertThat(update10.getPoliciesToBeDeployed()).isInstanceOf(List.class); } @Test diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java index ca6a62ca..d85bf737 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java @@ -20,8 +20,10 @@ package org.onap.policy.pap.main.comm.msgdata; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -32,6 +34,8 @@ import static org.mockito.Mockito.verify; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedList; +import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; @@ -40,6 +44,7 @@ import org.junit.Test; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpStatus; 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.comm.CommonRequestBase; @@ -185,7 +190,7 @@ public class UpdateReqTest extends CommonRequestBase { // same content - should succeed, but leave message unchanged PdpUpdate msg2 = new PdpUpdate(update); assertTrue(data.reconfigure(msg2)); - assertSame(update, data.getMessage()); + assertNotSame(update, data.getMessage()); // different content - should succeed and install NEW message msg2.setPdpGroup(DIFFERENT); @@ -194,15 +199,106 @@ public class UpdateReqTest extends CommonRequestBase { } @Test + public void testReconfigureIsFullSameAsDeployList() { + PdpUpdate msg2 = new PdpUpdate(update); + ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies()); + + msg2.setPolicies(policies); + msg2.setPoliciesToBeDeployed(policies); + assertTrue(data.reconfigure(msg2)); + assertThat(data.getMessage().getPolicies()).containsAll(msg2.getPolicies()); + } + + @Test + public void testListsNewVsResult() { + PdpUpdate msg2 = new PdpUpdate(update); + ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies()); + + // some items in both deploy and newMessage.deploy + msg2.setPoliciesToBeDeployed(policies); + policies.remove(0); + data.getMessage().setPolicies(policies); + assertTrue(data.reconfigure(msg2)); + assertThat(data.getMessage().getPoliciesToBeDeployed()).containsAll(msg2.getPoliciesToBeDeployed()); + + // some items in both deploy and newMessage.undeploy + policies = new ArrayList<>(); + policies.add(makePolicy("policy-z-1", "1.0.0")); + policies.add(makePolicy("policy-y-1", "1.0.0")); + data.getMessage().setPoliciesToBeDeployed(policies); + + policies.clear(); + policies = new ArrayList<>(update.getPolicies()); + List<ToscaConceptIdentifier> polsToUndep = policies.parallelStream() + .map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + msg2.setPoliciesToBeUndeployed(polsToUndep); + + assertTrue(data.reconfigure(msg2)); + + List<ToscaConceptIdentifier> dataPols = data.getMessage().getPoliciesToBeDeployed().stream() + .map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + assertThat(dataPols).doesNotContainAnyElementsOf(data.getMessage().getPoliciesToBeUndeployed()); + + // some items only in deploy + policies = new ArrayList<>(update.getPolicies()); + msg2.setPoliciesToBeDeployed(policies); + data.getMessage().setPoliciesToBeDeployed(new LinkedList<>()); + assertTrue(data.reconfigure(msg2)); + assertThat(data.getMessage().getPoliciesToBeDeployed()).containsAll(msg2.getPoliciesToBeDeployed()); + + // some items in both undeploy and newMessage.undeploy + List<ToscaConceptIdentifier> pols = policies.stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + msg2.setPoliciesToBeUndeployed(pols); + pols.remove(0); + data.getMessage().setPoliciesToBeUndeployed(pols); + assertTrue(data.reconfigure(msg2)); + assertThat(data.getMessage().getPoliciesToBeUndeployed()).containsAll(msg2.getPoliciesToBeUndeployed()); + + // some items in both undeploy and newMessage.deploy + policies = new ArrayList<>(update.getPolicies()); + List<ToscaConceptIdentifier> polsToUndep2 = policies.parallelStream() + .map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + data.getMessage().setPoliciesToBeUndeployed(polsToUndep2); + + List<ToscaPolicy> polsToDep2 = new LinkedList<>(); + polsToDep2.add(makePolicy("policy-m-1", "1.0.0")); + polsToDep2.add(makePolicy("policy-n-1", "1.0.0")); + msg2.setPoliciesToBeDeployed(polsToDep2); + + assertTrue(data.reconfigure(msg2)); + + List<ToscaConceptIdentifier> dataPols2 = data.getMessage().getPoliciesToBeDeployed().stream() + .map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + assertThat(data.getMessage().getPoliciesToBeUndeployed()) + .doesNotContainAnyElementsOf(dataPols2); + + // some items only in undeploy + pols = policies.stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); + msg2.setPoliciesToBeUndeployed(pols); + data.getMessage().setPoliciesToBeUndeployed(new LinkedList<>()); + assertTrue(data.reconfigure(msg2)); + assertThat(data.getMessage().getPoliciesToBeUndeployed()).containsAll(msg2.getPoliciesToBeUndeployed()); + } + + @Test public void testIsSameContent() { + data = new UpdateReq(reqParams, MY_REQ_NAME, update); + data.setNotifier(notifier); + PdpUpdate msg2 = new PdpUpdate(update); msg2.setName("world"); - assertTrue(data.isSameContent(msg2)); + assertFalse(data.isSameContent(msg2)); // both policy lists null update.setPolicies(null); msg2.setPolicies(null); - assertTrue(data.isSameContent(msg2)); + assertEquals(data.getMessage().getPolicies(), msg2.getPolicies()); } @Test @@ -210,7 +306,7 @@ public class UpdateReqTest extends CommonRequestBase { PdpUpdate msg2 = new PdpUpdate(update); msg2.setPdpGroup(null); update.setPdpGroup(null); - assertTrue(data.isSameContent(msg2)); + assertEquals(data.getMessage().getPdpGroup(), msg2.getPdpGroup()); } @Test @@ -218,7 +314,7 @@ public class UpdateReqTest extends CommonRequestBase { PdpUpdate msg2 = new PdpUpdate(update); msg2.setPdpSubgroup(null); update.setPdpSubgroup(null); - assertTrue(data.isSameContent(msg2)); + assertEquals(data.getMessage().getPdpSubgroup(), msg2.getPdpSubgroup()); } @Test diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java index b2c67c93..2bf4f3df 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java @@ -361,11 +361,13 @@ public class TestProviderBase extends ProviderSuper { // queue indicated that the update should succeed subgroup.getPolicies().add(ident1); - data.trackDeploy(ident1, Collections.singleton(PDP1), GROUP1_NAME, PDP1_TYPE); + ToscaPolicy testPolicy1 = data.getPolicy(new ToscaConceptIdentifierOptVersion(ident1)); + data.trackDeploy(testPolicy1, Collections.singleton(PDP1), GROUP1_NAME, PDP1_TYPE); data.trackUndeploy(ident1, Collections.singleton(PDP2), GROUP1_NAME, PDP2_TYPE); ToscaConceptIdentifier ident2 = new ToscaConceptIdentifier(POLICY1_NAME, "9.9.9"); - data.trackDeploy(ident2, Collections.singleton(PDP3), GROUP1_NAME, PDP3_TYPE); + ToscaPolicy testPolicy2 = data.getPolicy(new ToscaConceptIdentifierOptVersion(ident2)); + data.trackDeploy(testPolicy2, Collections.singleton(PDP3), GROUP1_NAME, PDP3_TYPE); data.trackUndeploy(ident2, Collections.singleton(PDP4), GROUP1_NAME, PDP4_TYPE); return true; diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java index 6b76c258..ad249164 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestSessionData.java @@ -577,15 +577,19 @@ public class TestSessionData extends ProviderSuper { ToscaConceptIdentifier policyId = new ToscaConceptIdentifier(POLICY_NAME, POLICY_VERSION); List<String> pdps = Arrays.asList(PDP1, PDP2); + ToscaPolicy testPolicy = session.getPolicy(new ToscaConceptIdentifierOptVersion(policyId)); + if (deploy) { - session.trackDeploy(policyId, pdps, GROUP_NAME, PDP_TYPE); + session.trackDeploy(testPolicy, pdps, GROUP_NAME, PDP_TYPE); + assertThat(session.getPoliciesToBeDeployed()).contains(testPolicy); } else { session.trackUndeploy(policyId, pdps, GROUP_NAME, PDP_TYPE); + assertThat(session.getPoliciesToBeUndeployed()).contains(policyId); } // should be called just once verify(status).deleteDeployment(any(), anyBoolean()); - verify(status).deleteDeployment(policyId, !deploy); + verify(status, times(1)).deleteDeployment(policyId, !deploy); // should be called for each PDP verify(status, times(2)).deploy(any(), any(), any(), any(), any(), anyBoolean()); |