From 2f0734e78e355122e80d03c0cbd70f2343e9fed2 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 18 Jul 2023 13:47:55 +0100 Subject: Fix OFF_LINE issue when Status message upcoming Issue-ID: POLICY-4770 Change-Id: If5812e689fab5ebfcf3eb23c89dcbd556ad8f331 Signed-off-by: FrancescoFioraEst (cherry picked from commit 1a5a1f51875433be47a697a2f2498a428c23d7e5) --- .../main/resources/etc/AcRuntimeParameters.yaml | 2 +- .../supervision/SupervisionParticipantHandler.java | 14 ++++-- runtime-acm/src/main/resources/application.yaml | 2 +- .../SupervisionParticipantHandlerTest.java | 58 ++++++++++++++++++---- .../clamp/acm/runtime/util/CommonTestData.java | 13 +++++ 5 files changed, 74 insertions(+), 15 deletions(-) mode change 100644 => 100755 packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml mode change 100644 => 100755 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java mode change 100644 => 100755 runtime-acm/src/main/resources/application.yaml mode change 100644 => 100755 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java mode change 100644 => 100755 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml old mode 100644 new mode 100755 index a8e45ff0a..ea8ae2e74 --- a/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml +++ b/packages/policy-clamp-tarball/src/main/resources/etc/AcRuntimeParameters.yaml @@ -40,7 +40,7 @@ server: runtime: participantParameters: heartBeatMs: 20000 - maxStatusWaitMs: 100000 + maxStatusWaitMs: 200000 topicParameterGroup: topicSources: - diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java old mode 100644 new mode 100755 index e0d11ed9f..f8bc233e9 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java @@ -76,10 +76,7 @@ public class SupervisionParticipantHandler { if (participantOpt.isPresent()) { var participant = participantOpt.get(); - if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) { - participant.setParticipantState(ParticipantState.ON_LINE); - participantProvider.saveParticipant(participant); - } + checkOnline(participant); handleRestart(participant.getParticipantId()); } else { var participant = createParticipant(participantRegisterMsg.getParticipantId(), @@ -127,12 +124,21 @@ public class SupervisionParticipantHandler { var participant = createParticipant(participantStatusMsg.getParticipantId(), listToMap(participantStatusMsg.getParticipantSupportedElementType())); participantProvider.saveParticipant(participant); + } else { + checkOnline(participantOpt.get()); } if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) { automationCompositionProvider.upgradeStates(participantStatusMsg.getAutomationCompositionInfoList()); } } + private void checkOnline(Participant participant) { + if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) { + participant.setParticipantState(ParticipantState.ON_LINE); + participantProvider.saveParticipant(participant); + } + } + private void handleRestart(UUID participantId) { var compositionIds = participantProvider.getCompositionIds(participantId); for (var compositionId : compositionIds) { diff --git a/runtime-acm/src/main/resources/application.yaml b/runtime-acm/src/main/resources/application.yaml old mode 100644 new mode 100755 index faef54af0..8dd4b574a --- a/runtime-acm/src/main/resources/application.yaml +++ b/runtime-acm/src/main/resources/application.yaml @@ -42,7 +42,7 @@ server: runtime: participantParameters: heartBeatMs: 20000 - maxStatusWaitMs: 100000 + maxStatusWaitMs: 200000 topicParameterGroup: topicSources: - diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java old mode 100644 new mode 100755 index ed8a85664..49aa03096 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java @@ -82,9 +82,7 @@ class SupervisionParticipantHandlerTest { var participantRegisterMessage = new ParticipantRegister(); participantRegisterMessage.setMessageId(UUID.randomUUID()); participantRegisterMessage.setParticipantId(CommonTestData.getParticipantId()); - var supportedElementType = new ParticipantSupportedElementType(); - supportedElementType.setTypeName("Type"); - supportedElementType.setTypeVersion("1.0.0"); + var supportedElementType = CommonTestData.createParticipantSupportedElementType(); participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType)); var participantProvider = mock(ParticipantProvider.class); @@ -105,9 +103,7 @@ class SupervisionParticipantHandlerTest { participantRegisterMessage.setMessageId(UUID.randomUUID()); var participantId = CommonTestData.getParticipantId(); participantRegisterMessage.setParticipantId(participantId); - var supportedElementType = new ParticipantSupportedElementType(); - supportedElementType.setTypeName("Type"); - supportedElementType.setTypeVersion("1.0.0"); + var supportedElementType = CommonTestData.createParticipantSupportedElementType(); participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType)); var participant = new Participant(); @@ -156,9 +152,7 @@ class SupervisionParticipantHandlerTest { var participantStatusMessage = new ParticipantStatus(); participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); participantStatusMessage.setState(ParticipantState.ON_LINE); - var supportedElementType = new ParticipantSupportedElementType(); - supportedElementType.setTypeName("Type"); - supportedElementType.setTypeVersion("1.0.0"); + var supportedElementType = CommonTestData.createParticipantSupportedElementType(); participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType)); participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); @@ -175,4 +169,50 @@ class SupervisionParticipantHandlerTest { verify(automationCompositionProvider).upgradeStates(any()); } + + @Test + void testHandleParticipantStatusNotRegisterd() { + var participantStatusMessage = new ParticipantStatus(); + participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); + participantStatusMessage.setState(ParticipantState.ON_LINE); + var supportedElementType = CommonTestData.createParticipantSupportedElementType(); + participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType)); + participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); + + var participantProvider = mock(ParticipantProvider.class); + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var handler = + new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, + mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class)); + handler.handleParticipantMessage(participantStatusMessage); + + verify(participantProvider).saveParticipant(any()); + verify(automationCompositionProvider).upgradeStates(any()); + } + + @Test + void testHandleParticipantStatusCheckOnline() { + var participantStatusMessage = new ParticipantStatus(); + participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); + participantStatusMessage.setState(ParticipantState.ON_LINE); + var supportedElementType = CommonTestData.createParticipantSupportedElementType(); + participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType)); + participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); + + var participantProvider = mock(ParticipantProvider.class); + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var handler = + new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, + mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class)); + var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); + participant.setParticipantState(ParticipantState.OFF_LINE); + when(participantProvider.findParticipant(CommonTestData.getParticipantId())) + .thenReturn(Optional.of(participant)); + handler.handleParticipantMessage(participantStatusMessage); + + verify(participantProvider).saveParticipant(any()); + verify(automationCompositionProvider).upgradeStates(any()); + } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java old mode 100644 new mode 100755 index 5c82713b0..270f1e0be --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java @@ -29,6 +29,7 @@ import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -97,6 +98,18 @@ public class CommonTestData { return participant; } + /** + * Create a new ParticipantSupportedElementType. + * + * @return a new ParticipantSupportedElementType + */ + public static ParticipantSupportedElementType createParticipantSupportedElementType() { + var supportedElementType = new ParticipantSupportedElementType(); + supportedElementType.setTypeName("Type"); + supportedElementType.setTypeVersion("1.0.0"); + return supportedElementType; + } + public static UUID getParticipantId() { return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03"); } -- cgit 1.2.3-korg