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 | |
parent | b35be71f283c75d937619651ef086047349e93f4 (diff) | |
parent | 1df4475d60d9c6d46087f8284dd2e0697d59c071 (diff) |
Merge "Fix parsing of type heirarchy for nodetypes"
Diffstat (limited to 'participant/participant-impl')
13 files changed, 143 insertions, 50 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. * diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java index f18885f0f..cfe786865 100644 --- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java @@ -88,8 +88,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl * @throws PfModelException in case of a model exception */ @Override - public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState, - ControlLoopOrderedState newState) throws PfModelException { + public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, UUID controlLoopElementId, + ControlLoopState currentState, ControlLoopOrderedState newState) throws PfModelException { // Implementation not needed for http participant } @@ -100,7 +100,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl * @param nodeTemplate toscaNodeTemplate */ @Override - public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate nodeTemplate) { + public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element, + ToscaNodeTemplate nodeTemplate) { try { var configRequest = CODER.convert(nodeTemplate.getProperties(), ConfigRequest.class); Set<ConstraintViolation<ConfigRequest>> violations = Validation.buildDefaultValidatorFactory() diff --git a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java index 46ed355de..0de25072d 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java @@ -66,6 +66,7 @@ class ClElementHandlerTest { serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); assertDoesNotThrow(() -> controlLoopElementHandler - .controlLoopElementUpdate(element, nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT))); + .controlLoopElementUpdate(commonTestData.getControlLoopId(), element, + nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT))); } } diff --git a/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java b/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java index c546648aa..0ebf9212a 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java @@ -134,6 +134,14 @@ public class CommonTestData { } /** + * Get controlloop id. + * @return ToscaConceptIdentifier controlLoopId + */ + public ToscaConceptIdentifier getControlLoopId() { + return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0"); + } + + /** * Get headers for config request. * @return Map of headers */ diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java index da0ef134a..a12fdcaac 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java @@ -44,6 +44,7 @@ import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; 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; @@ -87,8 +88,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * @param newState the state to which the control loop element is changing to */ @Override - public synchronized void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState, - ControlLoopOrderedState newState) { + public synchronized void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, + UUID controlLoopElementId, ControlLoopState currentState, ControlLoopOrderedState newState) { switch (newState) { case UNINITIALISED: ChartInfo chart = chartMap.get(controlLoopElementId); @@ -96,8 +97,9 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName()); try { chartService.uninstallChart(chart); - intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, - ControlLoopState.UNINITIALISED, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.UNINITIALISED, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); chartMap.remove(controlLoopElementId); podStatusMap.remove(chart.getReleaseName()); } catch (ServiceException se) { @@ -106,11 +108,13 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { } 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: @@ -128,8 +132,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * @throws PfModelException in case of an exception */ @Override - public synchronized void controlLoopElementUpdate(ControlLoopElement element, - ToscaNodeTemplate nodeTemplate) throws PfModelException { + public synchronized void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, + ControlLoopElement element, ToscaNodeTemplate nodeTemplate) throws PfModelException { @SuppressWarnings("unchecked") Map<String, Object> chartData = (Map<String, Object>) nodeTemplate.getProperties().get("chart"); diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java index 2d4439a45..1f8e76952 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandlerTest.java @@ -47,6 +47,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.Participan import org.onap.policy.clamp.controlloop.participant.kubernetes.exception.ServiceException; import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartInfo; import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartList; +import org.onap.policy.clamp.controlloop.participant.kubernetes.parameters.CommonTestData; import org.onap.policy.clamp.controlloop.participant.kubernetes.service.ChartService; import org.onap.policy.clamp.controlloop.participant.kubernetes.utils.TestUtils; import org.onap.policy.common.utils.coder.Coder; @@ -69,7 +70,7 @@ class ControlLoopElementHandlerTest { private static ToscaServiceTemplate toscaServiceTemplate; private static final String K8S_CONTROL_LOOP_ELEMENT = "org.onap.domain.database.PMSH_K8SMicroserviceControlLoopElement"; - + private CommonTestData commonTestData = new CommonTestData(); @InjectMocks @Spy @@ -98,19 +99,19 @@ class ControlLoopElementHandlerTest { doNothing().when(chartService).uninstallChart(charts.get(0)); - controlLoopElementHandler.controlLoopElementStateChange(controlLoopElementId1, ControlLoopState.PASSIVE, - ControlLoopOrderedState.UNINITIALISED); + controlLoopElementHandler.controlLoopElementStateChange(commonTestData.getControlLoopId(), + controlLoopElementId1, ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED); doThrow(new ServiceException("Error uninstalling the chart")).when(chartService) .uninstallChart(charts.get(0)); assertDoesNotThrow(() -> controlLoopElementHandler - .controlLoopElementStateChange(controlLoopElementId1, ControlLoopState.PASSIVE, - ControlLoopOrderedState.UNINITIALISED)); + .controlLoopElementStateChange(commonTestData.getControlLoopId(), controlLoopElementId1, + ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED)); assertDoesNotThrow(() -> controlLoopElementHandler - .controlLoopElementStateChange(controlLoopElementId1, ControlLoopState.PASSIVE, - ControlLoopOrderedState.RUNNING)); + .controlLoopElementStateChange(commonTestData.getControlLoopId(), controlLoopElementId1, + ControlLoopState.PASSIVE, ControlLoopOrderedState.RUNNING)); } @@ -125,7 +126,8 @@ class ControlLoopElementHandlerTest { Map<String, ToscaNodeTemplate> nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - controlLoopElementHandler.controlLoopElementUpdate(element, nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT)); + controlLoopElementHandler.controlLoopElementUpdate(commonTestData.getControlLoopId(), element, + nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT)); assertThat(controlLoopElementHandler.getChartMap()).hasSize(1).containsKey(elementId1); @@ -134,7 +136,8 @@ class ControlLoopElementHandlerTest { UUID elementId2 = UUID.randomUUID(); element.setId(elementId2); - controlLoopElementHandler.controlLoopElementUpdate(element, nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT)); + controlLoopElementHandler.controlLoopElementUpdate(commonTestData.getControlLoopId(), element, + nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT)); assertThat(controlLoopElementHandler.getChartMap().containsKey(elementId2)).isFalse(); } diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/CommonTestData.java index 98c086205..f6ec401b8 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/CommonTestData.java @@ -150,4 +150,12 @@ public class CommonTestData { topicParams.setServers(Arrays.asList("localhost")); return topicParams; } + + /** + * Get controlloop id. + * @return ToscaConceptIdentifier controlLoopId + */ + public ToscaConceptIdentifier getControlLoopId() { + return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0"); + } } diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java index 4f8dcf1f9..9054788f9 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java @@ -38,6 +38,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.Participan import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyApiHttpClient; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; @@ -79,22 +80,25 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * @throws PfModelException in case of an exception */ @Override - public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState, + public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, + UUID controlLoopElementId, ControlLoopState currentState, ControlLoopOrderedState newState) throws PfModelException { switch (newState) { case UNINITIALISED: try { - deletePolicyData(controlLoopElementId, newState); + deletePolicyData(controlLoopId, controlLoopElementId, newState); } catch (PfModelRuntimeException e) { LOGGER.debug("Deleting policy data failed", e); } 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: @@ -103,7 +107,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { } } - private void deletePolicyData(UUID controlLoopElementId, ControlLoopOrderedState newState) { + private void deletePolicyData(ToscaConceptIdentifier controlLoopId, + UUID controlLoopElementId, ControlLoopOrderedState newState) { // Delete all policies of this controlLoop from policy framework for (Entry<String, String> policy : policyMap.entrySet()) { apiHttpClient.deletePolicy(policy.getKey(), policy.getValue()); @@ -114,7 +119,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { apiHttpClient.deletePolicyType(policyType.getKey(), policyType.getValue()); } policyTypeMap.clear(); - intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.UNINITIALISED, + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.UNINITIALISED, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); } @@ -126,9 +132,10 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { * @throws PfModelException in case of an exception */ @Override - public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate clElementDefinition) + public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element, + ToscaNodeTemplate clElementDefinition) throws PfModelException { - intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(), + intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(), ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE); ToscaServiceTemplate controlLoopDefinition = element.getToscaServiceTemplateFragment(); if (controlLoopDefinition.getToscaTopologyTemplate() != null) { diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java index a33fa0a58..fe7cb3c96 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java @@ -154,7 +154,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; @@ -187,6 +187,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 populateToscaNodeTemplateFragment(ControlLoopElement clElement, ToscaServiceTemplate toscaServiceTemplate) { ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate @@ -263,7 +279,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( diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/simulation/SimulationProvider.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/simulation/SimulationProvider.java index a7d21164f..688f7df6b 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/simulation/SimulationProvider.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/simulation/SimulationProvider.java @@ -79,8 +79,8 @@ public class SimulationProvider { */ public TypedSimpleResponse<ControlLoopElement> updateControlLoopElement(ControlLoopElement element) { TypedSimpleResponse<ControlLoopElement> response = new TypedSimpleResponse<>(); - response.setResponse(intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(), - element.getState(), ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE)); + response.setResponse(intermediaryApi.updateControlLoopElementState(null, element.getId(), + element.getOrderedState(), element.getState(), ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE)); return response; } 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 56be0817f..7439ccd5b 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 @@ -146,7 +146,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; @@ -178,6 +178,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()) { @@ -228,7 +244,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( |