From 1df4475d60d9c6d46087f8284dd2e0697d59c071 Mon Sep 17 00:00:00 2001 From: Sirisha_Manchikanti Date: Mon, 6 Sep 2021 09:15:07 +0100 Subject: Fix parsing of type heirarchy for nodetypes Fixed an issue where a ControlLoopElement with type defined in node-types is not parsed. This commit also includes changes to save the state of a controlLoopElement coming from ControlLoopAck message into runtime database. Issue-ID: POLICY-3575 Signed-off-by: Sirisha_Manchikanti Change-Id: I1249cf2cabd4a499d80b401f94f7f42f08b350e3 --- .../handler/ControlLoopElementHandlerTest.java | 7 ++++--- .../dcae/main/rest/TestListenerUtils.java | 24 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'participant/participant-impl/participant-impl-dcae/src/test') diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java index 74728a974..2d8e0acd8 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java @@ -104,7 +104,8 @@ class ControlLoopElementHandlerTest { controlLoopElementHandler.setIntermediaryApi(intermediaryApi); UUID controlLoopElementId = UUID.randomUUID(); - controlLoopElementHandler.controlLoopElementStateChange(controlLoopElementId, ControlLoopState.PASSIVE, + controlLoopElementHandler.controlLoopElementStateChange(TestListenerUtils.getControlLoopId(), + controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED); verify(clampClient).undeploy(LOOP); @@ -137,7 +138,7 @@ class ControlLoopElementHandlerTest { element.setOrderedState(ControlLoopOrderedState.PASSIVE); final ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate(); - controlLoopElementHandler.controlLoopElementUpdate(element, + controlLoopElementHandler.controlLoopElementUpdate(TestListenerUtils.getControlLoopId(), element, controlLoopDefinition.getToscaTopologyTemplate().getNodeTemplates() .get("org.onap.domain.pmsh.PMSH_DCAEMicroservice")); @@ -169,7 +170,7 @@ class ControlLoopElementHandlerTest { element.setOrderedState(ControlLoopOrderedState.PASSIVE); ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate(); - controlLoopElementHandler.controlLoopElementUpdate(element, + controlLoopElementHandler.controlLoopElementUpdate(TestListenerUtils.getControlLoopId(), element, controlLoopDefinition.getToscaTopologyTemplate().getNodeTemplates() .get("org.onap.domain.pmsh.PMSH_DCAEMicroservice")); diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java index 26f9cd4b9..df49f7c49 100644 --- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java @@ -140,7 +140,7 @@ public class TestListenerUtils { Map nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); for (Map.Entry toscaInputEntry : nodeTemplatesMap.entrySet()) { - if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) { + if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) { ControlLoopElement clElement = new ControlLoopElement(); clElement.setId(UUID.randomUUID()); ToscaConceptIdentifier clParticipantType; @@ -172,6 +172,22 @@ public class TestListenerUtils { return clUpdateMsg; } + private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate, + ToscaServiceTemplate toscaServiceTemplate) { + if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) { + return true; + } else { + var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType()); + if (nodeType != null) { + var derivedFrom = nodeType.getDerivedFrom(); + if (derivedFrom != null) { + return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false; + } + } + } + return false; + } + private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement, List participantUpdates) { if (participantUpdates.isEmpty()) { @@ -221,7 +237,7 @@ public class TestListenerUtils { List participantDefinitionUpdates = new ArrayList<>(); for (Map.Entry toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) { - if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) { + if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) { ToscaConceptIdentifier clParticipantType; try { clParticipantType = CODER.decode( @@ -276,6 +292,10 @@ public class TestListenerUtils { return participantDefinition; } + public static ToscaConceptIdentifier getControlLoopId() { + return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0"); + } + /** * Method to create a deep copy of ControlLoopUpdateMsg. * -- cgit 1.2.3-korg