diff options
author | Liam Fallon <liam.fallon@est.tech> | 2021-09-08 09:00:36 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-09-08 09:00:36 +0000 |
commit | 22b02a0536c4cad7fb6d1a838df197415682fef2 (patch) | |
tree | 936b7454011a17f8d20fc26a281996b5b0a19b23 /participant/participant-impl/participant-impl-dcae | |
parent | b35be71f283c75d937619651ef086047349e93f4 (diff) | |
parent | 1df4475d60d9c6d46087f8284dd2e0697d59c071 (diff) |
Merge "Fix parsing of type heirarchy for nodetypes"
Diffstat (limited to 'participant/participant-impl/participant-impl-dcae')
3 files changed, 44 insertions, 15 deletions
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java index 221635db0..ca763f119 100644 --- a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java @@ -39,6 +39,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoo import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,23 +93,27 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * @param newState the state to which the control loop element is changing to */ @Override - public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState, + public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, + UUID controlLoopElementId, ControlLoopState currentState, ControlLoopOrderedState newState) { switch (newState) { case UNINITIALISED: var loop = clampClient.getstatus(LOOP); if (loop != null) { clampClient.undeploy(LOOP); - intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.UNINITIALISED, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); } break; case PASSIVE: - intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.PASSIVE, + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); break; case RUNNING: - intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.RUNNING, + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.RUNNING, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); break; default: @@ -145,8 +150,9 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * @throws PfModelException in case of an exception */ @Override - public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate nodeTemplate) - throws PfModelException { + public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, + ControlLoopElement element, ToscaNodeTemplate nodeTemplate) + throws PfModelException { try { var loop = getStatus(); @@ -159,16 +165,18 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { loop = getStatus(); String status = ClampHttpClient.getStatusCode(loop); if (MICROSERVICE_INSTALLED_SUCCESSFULLY.equals(status)) { - intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(), - ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE); + intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), + element.getOrderedState(), ControlLoopState.PASSIVE, + ParticipantMessageType.CONTROL_LOOP_UPDATE); deployedFlag = true; break; } } if (!deployedFlag) { LOGGER.warn("DCAE is not deployed properly, ClElement state will be UNINITIALISED2PASSIVE"); - intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(), - ControlLoopState.UNINITIALISED2PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE); + intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), + element.getOrderedState(), ControlLoopState.UNINITIALISED2PASSIVE, + ParticipantMessageType.CONTROL_LOOP_UPDATE); } } } catch (PfModelException e) { 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 02c04a0e6..0b8d1b30f 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 @@ -102,7 +102,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); @@ -135,7 +136,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")); @@ -167,7 +168,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<String, ToscaNodeTemplate> nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); for (Map.Entry<String, ToscaNodeTemplate> 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> participantUpdates) { if (participantUpdates.isEmpty()) { @@ -221,7 +237,7 @@ public class TestListenerUtils { List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>(); for (Map.Entry<String, ToscaNodeTemplate> 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. * |