From 20e2a1787c703a7957728e0c9a190a556b0ae536 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Mon, 9 Aug 2021 16:27:25 +0100 Subject: Fix serialization of messages in Control Loop and Participants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: POLICY-3536 Change-Id: I72207ba8b3894238412bf19c32b799b661a23c21 Signed-off-by: FrancescoFioraEst --- .../runtime/supervision/SupervisionHandler.java | 24 ++++++++++++---------- .../comm/ParticipantUpdatePublisher.java | 5 ++--- .../supervision/comm/SupervisionMessagesTest.java | 17 ++++++++------- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'runtime-controlloop') diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java index 16dba0f07..9180cedb3 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java @@ -27,7 +27,6 @@ import lombok.AllArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; 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.ControlLoopInfo; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; @@ -312,17 +311,20 @@ public class SupervisionHandler { private void superviseControlLoops(ParticipantStatus participantStatusMessage) throws PfModelException, ControlLoopException { - for (Map.Entry clEntry : - participantStatusMessage.getControlLoopInfoMap().entrySet()) { - var dbControlLoop = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier( - clEntry.getKey().getName(), clEntry.getKey().getVersion())); - if (dbControlLoop == null) { - exceptionOccured(Response.Status.NOT_FOUND, - "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getKey()); + if (participantStatusMessage.getControlLoopInfoMap() != null) { + for (Map.Entry clEntry : participantStatusMessage.getControlLoopInfoMap() + .entrySet()) { + String[] key = clEntry.getKey().split(" "); + var dbControlLoop = controlLoopProvider.getControlLoop( + new ToscaConceptIdentifier(key[0], key[1])); + if (dbControlLoop == null) { + exceptionOccured(Response.Status.NOT_FOUND, + "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getKey()); + } + dbControlLoop.setState(clEntry.getValue().getState()); + monitoringProvider.createClElementStatistics(clEntry.getValue().getControlLoopStatistics() + .getClElementStatisticsList().getClElementStatistics()); } - dbControlLoop.setState(clEntry.getValue().getState()); - monitoringProvider.createClElementStatistics(clEntry.getValue() - .getControlLoopStatistics().getClElementStatisticsList().getClElementStatistics()); } } diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java index 88cf90d02..cfc0e3932 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java @@ -71,9 +71,8 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher controlLoopElementDefinitionMap = new LinkedHashMap<>(); controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition); - Map> participantDefinitionUpdateMap = - new LinkedHashMap<>(); - participantDefinitionUpdateMap.put(participantId, controlLoopElementDefinitionMap); + Map> participantDefinitionUpdateMap = new LinkedHashMap<>(); + participantDefinitionUpdateMap.put(participantId.toString(), controlLoopElementDefinitionMap); message.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap); LOGGER.debug("Participant Update sent {}", message); 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..e74af7901 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 @@ -79,8 +79,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 +95,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,8 +115,8 @@ 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 listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null); commissioningProvider.createControlLoopDefinitions(serviceTemplate); @@ -189,10 +188,10 @@ class SupervisionMessagesTest extends CommonRestController { clDefinition.setCommonPropertiesMap(commonPropertiesMap); Map controlLoopElementDefinitionMap = - Map.of(UUID.randomUUID(), clDefinition); + Map.of(UUID.randomUUID(), clDefinition); - Map> - participantDefinitionUpdateMap = Map.of(getParticipantId(), controlLoopElementDefinitionMap); + Map> participantDefinitionUpdateMap = + Map.of(getParticipantId().toString(), controlLoopElementDefinitionMap); participantUpdateMsg.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap); synchronized (lockit) { -- cgit 1.2.3-korg