aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-simulator/src/test/java
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-10 21:51:48 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-18 14:58:42 +0100
commitd0a1bcee60c43a736a0526d49c07c564632c4f02 (patch)
tree32d46f33307a9bb65215a1f52eb626ae7db3d1ee /participant/participant-impl/participant-impl-simulator/src/test/java
parenta37bd982693785af5fc791df0baaa49dda039846 (diff)
Updated ControlLoop component messages
Updated controlloop messages (ParticipantUpdate, ControlLoopUpdate, ParticipantStatus) according to the following Wiki and added implementation for the corresponding updates in runtime-controlloop and participant components https://wiki.onap.org/display/DW/The+CLAMP+Control+Loop+Participant+Protocol Issue-ID: POLICY-3417 Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech> Change-Id: I80d96a7553a89ca47de2aa35e09df5a5c792acfa
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator/src/test/java')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java5
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java166
2 files changed, 144 insertions, 27 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
index beb50da37..a9dea1748 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
@@ -105,7 +105,6 @@ class ParticipantSimulatorTest {
ControlLoopUpdate controlLoopUpdateMsg =
TestListenerUtils.createControlLoopUpdateMsg();
- controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
}
@@ -275,10 +274,6 @@ class ParticipantSimulatorTest {
UUID uuid = controlLoopElements.keySet().iterator().next();
ControlLoopElement controlLoopElement = controlLoopElements.get(uuid);
- // Check the initial state on the ControlLoopElement, which is UNINITIALISED
- assertEquals(ControlLoopOrderedState.UNINITIALISED, controlLoopElement.getOrderedState());
-
- // Change the state of the ControlLoopElement to PASSIVE from UNINITIALISED
controlLoopElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
// PUT REST call for updating ControlLoopElement
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
index 999feb1e1..2b8de6ae1 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
@@ -25,17 +25,22 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileNotFoundException;
import java.time.Instant;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -54,6 +59,7 @@ public class TestListenerUtils {
private static final Coder CODER = new StandardCoder();
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
+ private static final String CONTROL_LOOP_ELEMENT = "ControlLoopElement";
private TestListenerUtils() {}
@@ -125,43 +131,159 @@ public class TestListenerUtils {
*/
public static ControlLoopUpdate createControlLoopUpdateMsg() {
final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
- ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
- ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0");
+ ToscaConceptIdentifier controlLoopId =
+ new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ ToscaConceptIdentifier participantId =
+ new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
clUpdateMsg.setControlLoopId(controlLoopId);
clUpdateMsg.setParticipantId(participantId);
- clUpdateMsg.setParticipantType(participantId);
+ clUpdateMsg.setMessageId(UUID.randomUUID());
+ clUpdateMsg.setTimestamp(Instant.now());
- ControlLoop controlLoop = new ControlLoop();
Map<UUID, ControlLoopElement> elements = new LinkedHashMap<>();
ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead();
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- ControlLoopElement clElement = new ControlLoopElement();
- clElement.setId(UUID.randomUUID());
+ if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ ControlLoopElement clElement = new ControlLoopElement();
+ clElement.setId(UUID.randomUUID());
+ ToscaConceptIdentifier clParticipantId;
+ try {
+ clParticipantId = CODER.decode(
+ toscaInputEntry.getValue().getProperties().get("participant_id").toString(),
+ ToscaConceptIdentifier.class);
+ } catch (CoderException e) {
+ throw new RuntimeException("cannot get ParticipantId from toscaNodeTemplate", e);
+ }
- ToscaConceptIdentifier clElementParticipantId = new ToscaConceptIdentifier();
- clElementParticipantId.setName(toscaInputEntry.getKey());
- clElementParticipantId.setVersion(toscaInputEntry.getValue().getVersion());
- clElement.setParticipantId(clElementParticipantId);
- clElement.setParticipantType(clElementParticipantId);
+ clElement.setParticipantId(clParticipantId);
+ clElement.setParticipantType(clParticipantId);
- clElement.setDefinition(clElementParticipantId);
- clElement.setState(ControlLoopState.UNINITIALISED);
- clElement.setDescription(toscaInputEntry.getValue().getDescription());
- clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
- elements.put(clElement.getId(), clElement);
+ clElement.setDefinition(new ToscaConceptIdentifier(toscaInputEntry.getKey(),
+ toscaInputEntry.getValue().getVersion()));
+ clElement.setState(ControlLoopState.UNINITIALISED);
+ clElement.setDescription(toscaInputEntry.getValue().getDescription());
+ clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ elements.put(clElement.getId(), clElement);
+ }
}
- controlLoop.setElements(elements);
- controlLoop.setName("PMSHInstance0");
- controlLoop.setVersion("1.0.0");
- controlLoop.setDefinition(controlLoopId);
- clUpdateMsg.setControlLoop(controlLoop);
+ List<ParticipantUpdates> participantUpdates = new ArrayList<>();
+ for (ControlLoopElement element : elements.values()) {
+ prepareParticipantUpdateForControlLoop(element, participantUpdates);
+ }
+ clUpdateMsg.setParticipantUpdatesList(participantUpdates);
return clUpdateMsg;
}
+ private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
+ List<ParticipantUpdates> participantUpdates) {
+ if (participantUpdates.isEmpty()) {
+ participantUpdates.add(getControlLoopElementList(clElement));
+ } else {
+ boolean participantExists = false;
+ for (ParticipantUpdates participantUpdate : participantUpdates) {
+ if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) {
+ participantUpdate.getControlLoopElementList().add(clElement);
+ participantExists = true;
+ }
+ }
+ if (!participantExists) {
+ participantUpdates.add(getControlLoopElementList(clElement));
+ }
+ }
+ }
+
+ private static ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) {
+ ParticipantUpdates participantUpdate = new ParticipantUpdates();
+ List<ControlLoopElement> controlLoopElementList = new ArrayList<>();
+ participantUpdate.setParticipantId(clElement.getParticipantId());
+ controlLoopElementList.add(clElement);
+ participantUpdate.setControlLoopElementList(controlLoopElementList);
+ return participantUpdate;
+ }
+
+ /**
+ * Method to create participantUpdateMsg.
+ *
+ * @return ParticipantUpdate message
+ */
+ public static ParticipantUpdate createParticipantUpdateMsg() {
+ final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
+ ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
+ ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(
+ "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+
+ participantUpdateMsg.setParticipantId(participantId);
+ participantUpdateMsg.setTimestamp(Instant.now());
+ participantUpdateMsg.setParticipantType(participantType);
+ participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
+ participantUpdateMsg.setMessageId(UUID.randomUUID());
+
+ ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead();
+ // Add policies to the toscaServiceTemplate
+
+ List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
+ toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
+ if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ ToscaConceptIdentifier clParticipantId;
+ try {
+ clParticipantId = CODER.decode(
+ toscaInputEntry.getValue().getProperties().get("participant_id").toString(),
+ ToscaConceptIdentifier.class);
+ } catch (CoderException e) {
+ throw new RuntimeException("cannot get ParticipantId from toscaNodeTemplate", e);
+ }
+ prepareParticipantDefinitionUpdate(clParticipantId, toscaInputEntry.getKey(),
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
+ }
+ }
+
+ participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate);
+ return participantUpdateMsg;
+ }
+
+ private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantId, String entryKey,
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+
+ var clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
+ entryKey, entryValue.getVersion()));
+ clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
+
+ if (participantDefinitionUpdates.isEmpty()) {
+ participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantId,
+ controlLoopElementDefinitionList));
+ } else {
+ boolean participantExists = false;
+ for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
+ if (participantDefinitionUpdate.getParticipantId().equals(clParticipantId)) {
+ participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
+ participantExists = true;
+ }
+ }
+ if (!participantExists) {
+ participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantId,
+ controlLoopElementDefinitionList));
+ }
+ }
+ }
+
+ private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
+ ToscaConceptIdentifier clParticipantId,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ParticipantDefinition participantDefinition = new ParticipantDefinition();
+ participantDefinition.setParticipantId(clParticipantId);
+ controlLoopElementDefinitionList.add(clDefinition);
+ participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
+ return participantDefinition;
+ }
+
/**
* Method to create ControlLoopUpdate using the arguments passed.
*