diff options
Diffstat (limited to 'runtime-controlloop/src/test')
4 files changed, 113 insertions, 31 deletions
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java index 5f00706e1..10116a240 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java @@ -21,7 +21,9 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm; import java.time.Instant; +import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -30,6 +32,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ClElementStatisticsProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; @@ -41,6 +44,7 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck; import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider; +import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup; import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider; import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler; @@ -48,6 +52,9 @@ import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; +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.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; @@ -63,12 +70,15 @@ class SupervisionMessagesTest extends CommonRestController { private static final Object lockit = new Object(); private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; private static final String TOPIC = "my-topic"; - private static final long interval = 1000; private static SupervisionHandler supervisionHandler; private static CommissioningProvider commissioningProvider; private static ControlLoopProvider clProvider; private static PolicyModelsProvider modelsProvider; private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); + private static final String TOSCA_TEMPLATE_YAML = + "src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml"; + private static final String CONTROL_LOOP_ELEMENT = "ControlLoopElement"; + private static final Coder CODER = new StandardCoder(); /** * setup Db Provider Parameters. @@ -79,8 +89,7 @@ class SupervisionMessagesTest extends CommonRestController { public static void setupDbProviderParameters() throws PfModelException { ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb"); - modelsProvider = - CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters()); + modelsProvider = CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters()); clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters()); var participantStatisticsProvider = new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters()); @@ -96,8 +105,8 @@ class SupervisionMessagesTest extends CommonRestController { var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class); var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class); supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider, - controlLoopUpdatePublisher, controlLoopStateChangePublisher, - participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher); + controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher, + participantDeregisterAckPublisher, participantUpdatePublisher); } @AfterAll @@ -116,10 +125,9 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantRegisterListener participantRegisterListener = new ParticipantRegisterListener(supervisionHandler); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml( + ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); - List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null); commissioningProvider.createControlLoopDefinitions(serviceTemplate); participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg); } @@ -169,6 +177,9 @@ class SupervisionMessagesTest extends CommonRestController { @Test void testSendParticipantUpdate() throws Exception { + InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider); + commissioningProvider.getToscaServiceTemplate(null, null); + final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate(); participantUpdateMsg.setParticipantId(getParticipantId()); participantUpdateMsg.setTimestamp(Instant.now()); @@ -176,32 +187,71 @@ class SupervisionMessagesTest extends CommonRestController { participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000)); participantUpdateMsg.setMessageId(UUID.randomUUID()); - ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); - toscaServiceTemplate.setName("serviceTemplate"); - toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); - toscaServiceTemplate.setDescription("Description of serviceTemplate"); - toscaServiceTemplate.setVersion("1.2.3"); + ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null); + 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); + } + } - ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); - clDefinition.setId(UUID.randomUUID()); - clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate); - Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue"); - clDefinition.setCommonPropertiesMap(commonPropertiesMap); + participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates); + participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate); + synchronized (lockit) { + ParticipantUpdatePublisher participantUpdatePublisher = + new ParticipantUpdatePublisher(commissioningProvider); + participantUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); + participantUpdatePublisher.send(participantUpdateMsg); + } + } - Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = - Map.of(UUID.randomUUID(), clDefinition); + private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantId, String entryKey, + ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) { - Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>> - participantDefinitionUpdateMap = Map.of(getParticipantId(), controlLoopElementDefinitionMap); - participantUpdateMsg.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap); + var clDefinition = new ControlLoopElementDefinition(); + clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier( + entryKey, entryValue.getVersion())); + clDefinition.setControlLoopElementToscaNodeTemplate(entryValue); + List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>(); - synchronized (lockit) { - ParticipantUpdatePublisher clUpdatePublisher = new ParticipantUpdatePublisher(commissioningProvider); - clUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); - clUpdatePublisher.send(participantUpdateMsg); + 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 ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition, + ToscaConceptIdentifier clParticipantId, + List<ControlLoopElementDefinition> controlLoopElementDefinitionList) { + ParticipantDefinition participantDefinition = new ParticipantDefinition(); + participantDefinition.setParticipantId(clParticipantId); + controlLoopElementDefinitionList.add(clDefinition); + participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); + return participantDefinition; + } + @Test void testReceiveParticipantUpdateAckMessage() throws Exception { final ParticipantUpdateAck participantUpdateAckMsg = new ParticipantUpdateAck(); diff --git a/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoops.json b/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoops.json index 13ea1bfc4..64443ff62 100644 --- a/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoops.json +++ b/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoops.json @@ -17,6 +17,10 @@ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "version": "2.3.4" + }, "participantType": { "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", "version": "2.3.4" @@ -31,6 +35,10 @@ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" + }, "participantType": { "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", "version": "2.3.1" @@ -45,6 +53,10 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" + }, "participantType": { "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", "version": "2.3.1" @@ -59,6 +71,10 @@ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", + "version": "2.2.1" + }, "participantType": { "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", "version": "2.2.1" @@ -86,6 +102,10 @@ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "version": "2.3.4" + }, "participantType": { "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", "version": "2.3.4" @@ -100,6 +120,10 @@ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" + }, "participantType": { "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", "version": "2.3.1" @@ -114,6 +138,10 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" + }, "participantType": { "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", "version": "2.3.1" @@ -128,6 +156,10 @@ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", "version": "1.2.3" }, + "participantId": { + "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", + "version": "2.2.1" + }, "participantType": { "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", "version": "2.2.1" diff --git a/runtime-controlloop/src/test/resources/rest/servicetemplates/PMSHMultipleCLTosca.yaml b/runtime-controlloop/src/test/resources/rest/servicetemplates/PMSHMultipleCLTosca.yaml index 099e2e945..dc09b4623 100644 --- a/runtime-controlloop/src/test/resources/rest/servicetemplates/PMSHMultipleCLTosca.yaml +++ b/runtime-controlloop/src/test/resources/rest/servicetemplates/PMSHMultipleCLTosca.yaml @@ -129,7 +129,7 @@ topology_template: description: Control loop element for CDS for Performance Management Subscription Handling properties: provider: Ericsson - participant_Id: + participant_id: name: org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant version: 3.2.1 cds_blueprint_id: @@ -197,7 +197,7 @@ topology_template: description: Control loop element for CDS for Performance Management Subscription Handling properties: provider: Ericsson - participant_Id: + participant_id: name: org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant version: 3.2.1 cds_blueprint_id: diff --git a/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml b/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml index 099e2e945..dc09b4623 100644 --- a/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml +++ b/runtime-controlloop/src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml @@ -129,7 +129,7 @@ topology_template: description: Control loop element for CDS for Performance Management Subscription Handling properties: provider: Ericsson - participant_Id: + participant_id: name: org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant version: 3.2.1 cds_blueprint_id: @@ -197,7 +197,7 @@ topology_template: description: Control loop element for CDS for Performance Management Subscription Handling properties: provider: Ericsson - participant_Id: + participant_id: name: org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant version: 3.2.1 cds_blueprint_id: |