summaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-07-18 13:47:55 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-07-18 12:49:59 +0000
commit1a5a1f51875433be47a697a2f2498a428c23d7e5 (patch)
tree4fda87f9b24cade9f62c0dd45c96ddd0cd6f2180 /runtime-acm
parent7815def0c52559f8c64b70f5f4df9648c7b8f70d (diff)
Fix OFF_LINE issue when Status message upcoming
Issue-ID: POLICY-4770 Change-Id: If5812e689fab5ebfcf3eb23c89dcbd556ad8f331 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java14
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/main/resources/application.yaml2
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java58
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java13
4 files changed, 73 insertions, 14 deletions
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
index e0d11ed9f..f8bc233e9 100644..100755
--- 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
index faef54af0..8dd4b574a 100644..100755
--- 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
index ed8a85664..49aa03096 100644..100755
--- 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
index 5c82713b0..270f1e0be 100644..100755
--- 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");
}