From c28ef7b282ab4378935387314f1a57d18e02fcf4 Mon Sep 17 00:00:00 2001 From: waynedunican Date: Wed, 14 Apr 2021 13:19:35 +0100 Subject: Support delta policies in apex-pdp Remove scanning of policy list from apex engine. Use the policiesToBeDeployed and policiesToBeUndeployed lists from PDP_UPDATE message instead. Issue-ID: POLICY-3170 Change-Id: Icdde66ef87d9feab83ccb1cf99a64d7870bcaaaa Signed-off-by: waynedunican --- .../services/onappf/comm/TestListenerUtils.java | 12 +++++--- .../onappf/comm/TestPdpStateChangeListener.java | 18 +++++++---- .../onappf/comm/TestPdpUpdateListener.java | 36 ++++++++++++++-------- 3 files changed, 43 insertions(+), 23 deletions(-) (limited to 'services/services-onappf/src/test/java/org/onap') diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java index 19af43fc8..104977995 100644 --- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java +++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ 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.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; public class TestListenerUtils { @@ -39,18 +40,21 @@ public class TestListenerUtils { * Method to create PdpUpdate message from the arguments passed. * * @param pdpStatus pdp status - * @param toscaPolicies list of tosca policies + * @param toscaPoliciesToBeDeployed list of tosca policies to deploy + * @param toscaPoliciesToBeUnDeployed list of tosca policies to undeploy * * @return PdpUpdate message */ - public static PdpUpdate createPdpUpdateMsg(final PdpStatus pdpStatus, List toscaPolicies) { + public static PdpUpdate createPdpUpdateMsg(final PdpStatus pdpStatus, List toscaPoliciesToBeDeployed, + List toscaPoliciesToBeUnDeployed) { final PdpUpdate pdpUpdateMsg = new PdpUpdate(); pdpUpdateMsg.setDescription("dummy pdp status for test"); pdpUpdateMsg.setPdpGroup("pdpGroup"); pdpUpdateMsg.setPdpSubgroup("pdpSubgroup"); pdpUpdateMsg.setName(pdpStatus.getName()); pdpUpdateMsg.setPdpHeartbeatIntervalMs(Long.valueOf(3000)); - pdpUpdateMsg.setPolicies(toscaPolicies); + pdpUpdateMsg.setPoliciesToBeDeployed(toscaPoliciesToBeDeployed); + pdpUpdateMsg.setPoliciesToBeUndeployed(toscaPoliciesToBeUnDeployed); return pdpUpdateMsg; } diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java index 1d491ea03..f04cf04f6 100644 --- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java +++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.services.onappf.comm; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -123,7 +124,8 @@ public class TestPdpStateChangeListener { public void testPdpStateChangeMessageListener_passivetopassive() { final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, - TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList())); + TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(), + new ArrayList<>())); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.PASSIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg); @@ -135,7 +137,8 @@ public class TestPdpStateChangeListener { public void testPdpStateChangeMessageListener_activetoactive() { final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, - TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList())); + TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(), + new ArrayList<>())); pdpStatus.setState(PdpState.ACTIVE); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); @@ -150,7 +153,8 @@ public class TestPdpStateChangeListener { System.setOut(new PrintStream(outContent)); final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, - TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList())); + TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(), + new ArrayList<>())); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg); @@ -160,9 +164,10 @@ public class TestPdpStateChangeListener { TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json"); final List toscaPolicies = new ArrayList(); toscaPolicies.add(toscaPolicy); - final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies); + final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies, + new ArrayList<>()); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg); - assertTrue(outContent.toString().contains("Apex engine started and policies are running.")); + assertThat(outContent.toString()).contains("Apex engine started and policies are running."); assertEquals(PdpState.ACTIVE, pdpStatus.getState()); final ApexPolicyStatisticsManager policyCounterManager = ApexPolicyStatisticsManager.getInstanceFromRegistry(); @@ -183,7 +188,8 @@ public class TestPdpStateChangeListener { TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json"); final List toscaPolicies = new ArrayList(); toscaPolicies.add(toscaPolicy); - final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies); + final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies, + new ArrayList<>()); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java index d9b8fc09c..636cdb0fc 100644 --- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java +++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -22,6 +22,7 @@ package org.onap.policy.apex.services.onappf.comm; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -31,7 +32,9 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -124,12 +127,13 @@ public class TestPdpUpdateListener { TestListenerUtils.createToscaPolicy("apex policy name", "1.0", "src/test/resources/dummyProperties.json"); final List toscaPolicies = new ArrayList(); toscaPolicies.add(toscaPolicy); - final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies); + final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies, + new LinkedList<>()); 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())); } @Test @@ -138,7 +142,8 @@ public class TestPdpUpdateListener { System.setOut(new PrintStream(outContent)); final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, - TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList())); + TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(), + new ArrayList<>())); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg); @@ -146,21 +151,23 @@ public class TestPdpUpdateListener { TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json"); final List toscaPolicies = new ArrayList(); toscaPolicies.add(toscaPolicy); - final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies); + final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies, + new LinkedList<>()); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg); final String outString = outContent.toString(); assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup()); assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup()); assertEquals(pdpStatus.getPolicies(), - new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies())); - assertTrue(outString.contains("Apex engine started and policies are running.")); + new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed())); + assertThat(outString).contains("Apex engine started and policies are running."); } @Test public void testPdpUpdateMssageListener_undeploy() throws InterruptedException, CoderException { final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, - TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList())); + TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(), + new ArrayList<>())); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg); @@ -168,15 +175,17 @@ public class TestPdpUpdateListener { TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json"); final List toscaPolicies = new ArrayList(); toscaPolicies.add(toscaPolicy); - final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies); + final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies, + new ArrayList<>()); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg); OutputStream outContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, - TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList())); + TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(), + toscaPolicies.stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()))); final String outString = outContent.toString(); - assertTrue(outString.contains("Pdp update successful. No policies are running.")); - + assertThat(outString).contains("Pdp update successful. No policies are running."); } @Test @@ -192,7 +201,8 @@ public class TestPdpUpdateListener { final List toscaPolicies = new ArrayList(); toscaPolicies.add(toscaPolicy); toscaPolicies.add(toscaPolicy2); - final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies); + final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies, + new LinkedList<>()); pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg); PdpStateChange pdpStateChangeMsg = TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName()); -- cgit 1.2.3-korg