diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-05-28 14:28:52 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-05-29 10:44:16 +0100 |
commit | f2ed4877b7cfba7bcf224cbe9d7e739ec637a055 (patch) | |
tree | 3e1fbcc0321e73d99404837a1b911a3054d2e903 /runtime-acm/src | |
parent | 6d8ebc3dfe0ee496e009eec4db39babcde51a289 (diff) |
Remove Map in ACM-R for timeout Participant
Issue-ID: POLICY-5024
Change-Id: Ibb8a93be55380b110c84ec4580690f43e624d125
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src')
8 files changed, 24 insertions, 67 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java index 0d814bff5..8f3a4c2eb 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java @@ -28,8 +28,6 @@ import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; @@ -72,11 +70,6 @@ public class SupervisionAspect implements Closeable { } } - @Before("@annotation(MessageIntercept) && args(participantStatusMsg,..)") - public void handleParticipantStatus(ParticipantStatus participantStatusMsg) { - executor.execute(() -> partecipantScanner.handleParticipantStatus(participantStatusMsg.getParticipantId())); - } - @Override public void close() throws IOException { executor.shutdown(); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java index c07c584cd..4d2a22f26 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,11 @@ package org.onap.policy.clamp.acm.runtime.supervision; -import java.util.UUID; import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; 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.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -36,7 +36,7 @@ import org.springframework.stereotype.Component; public class SupervisionPartecipantScanner { private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class); - private final TimeoutHandler<UUID> participantStatusTimeout = new TimeoutHandler<>(); + private final long maxWaitMs; private final ParticipantProvider participantProvider; @@ -49,8 +49,7 @@ public class SupervisionPartecipantScanner { public SupervisionPartecipantScanner(final ParticipantProvider participantProvider, final AcRuntimeParameterGroup acRuntimeParameterGroup) { this.participantProvider = participantProvider; - - participantStatusTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); + this.maxWaitMs = acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs(); } /** @@ -68,29 +67,16 @@ public class SupervisionPartecipantScanner { private void scanParticipantStatus(Participant participant) { var id = participant.getParticipantId(); - if (participantStatusTimeout.isTimeout(id)) { - if (ParticipantState.ON_LINE.equals(participant.getParticipantState())) { - // restart scenario - LOGGER.debug("Participant is back ON_LINE {}", id); - participantStatusTimeout.clear(id); - } else { - LOGGER.debug("report Participant is still OFF_LINE {}", id); - return; - } + if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) { + LOGGER.debug("report Participant is still OFF_LINE {}", id); + return; } - if (participantStatusTimeout.getDuration(id) > participantStatusTimeout.getMaxWaitMs()) { + var now = TimestampHelper.nowEpochMilli(); + var lastMsg = TimestampHelper.toEpochMilli(participant.getLastMsg()); + if ((now - lastMsg) > maxWaitMs) { LOGGER.debug("report Participant OFF_LINE {}", id); - participantStatusTimeout.setTimeout(id); participant.setParticipantState(ParticipantState.OFF_LINE); participantProvider.updateParticipant(participant); } } - - /** - * handle participant Status message. - */ - public void handleParticipantStatus(UUID id) { - LOGGER.debug("Participant is ON_LINE {}", id); - participantStatusTimeout.clear(id); - } } 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 24c256fa4..d1efb6ac0 100644 --- 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 @@ -46,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantSt import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -159,8 +160,9 @@ public class SupervisionParticipantHandler { private void checkOnline(Participant participant) { if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) { participant.setParticipantState(ParticipantState.ON_LINE); - participantProvider.saveParticipant(participant); } + participant.setLastMsg(TimestampHelper.now()); + participantProvider.saveParticipant(participant); } private void handleRestart(UUID participantId) { @@ -226,6 +228,7 @@ public class SupervisionParticipantHandler { participant.setParticipantId(participantId); participant.setParticipantSupportedElementTypes(participantSupportedElementType); participant.setParticipantState(ParticipantState.ON_LINE); + participant.setLastMsg(TimestampHelper.now()); return participant; } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java index 35dedb7ca..f78344bcb 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java @@ -26,8 +26,6 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.acm.runtime.util.CommonTestData; -import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus; class SupervisionAspectTest { @@ -52,17 +50,4 @@ class SupervisionAspectTest { verify(supervisionScanner, timeout(500).times(2)).run(); } } - - @Test - void testHandleParticipantStatus() throws Exception { - var participantStatusMessage = new ParticipantStatus(); - participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); - - var supervisionScanner = mock(SupervisionScanner.class); - var partecipantScanner = mock(SupervisionPartecipantScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { - supervisionAspect.handleParticipantStatus(participantStatusMessage); - verify(partecipantScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId()); - } - } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java index 4bab85bf5..3c9f91785 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,26 +31,25 @@ import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; -import org.onap.policy.models.base.PfModelException; class SupervisionParticipantScannerTest { @Test - void testScanParticipant() throws PfModelException { + void testScanParticipant() { var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant"); acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); - participant.setParticipantState(ParticipantState.OFF_LINE); var participantProvider = mock(ParticipantProvider.class); when(participantProvider.getParticipants()).thenReturn(List.of(participant)); var supervisionScanner = new SupervisionPartecipantScanner(participantProvider, acRuntimeParameterGroup); - supervisionScanner.handleParticipantStatus(participant.getParticipantId()); + participant.setParticipantState(ParticipantState.OFF_LINE); supervisionScanner.run(); - verify(participantProvider, times(0)).saveParticipant(any()); + verify(participantProvider, times(0)).updateParticipant(any()); + participant.setParticipantState(ParticipantState.ON_LINE); supervisionScanner.run(); verify(participantProvider, times(1)).updateParticipant(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 8329d050b..431a1ba55 100644 --- 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ package org.onap.policy.clamp.acm.runtime.util; import jakarta.ws.rs.core.Response.Status; -import java.util.List; import java.util.UUID; import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; import org.onap.policy.clamp.acm.runtime.main.parameters.AcmParameters; @@ -32,6 +31,7 @@ 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.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -80,18 +80,6 @@ public class CommonTestData { } /** - * Create a List of Participants. - * - * @return a List of Participants - */ - public static List<Participant> createParticipants() { - var participant1 = createParticipant(UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c02")); - var participant2 = createParticipant(UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c01")); - var participant3 = createParticipant(UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03")); - return List.of(participant1, participant2, participant3); - } - - /** * Create a new Participant. * * @param participantId the participant id @@ -101,6 +89,7 @@ public class CommonTestData { var participant = new Participant(); participant.setParticipantId(participantId); participant.setParticipantState(ParticipantState.ON_LINE); + participant.setLastMsg(TimestampHelper.now()); return participant; } diff --git a/runtime-acm/src/test/resources/providers/TestParticipant.json b/runtime-acm/src/test/resources/providers/TestParticipant.json index fe06ba091..b9002423a 100644 --- a/runtime-acm/src/test/resources/providers/TestParticipant.json +++ b/runtime-acm/src/test/resources/providers/TestParticipant.json @@ -8,6 +8,7 @@ "participantState": "ON_LINE", "description": "A dummy PMSH participant1", "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6", + "lastMsg": "2024-05-22 10:04:37.6020187", "participantType": { "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition", "version": "1.0.0" diff --git a/runtime-acm/src/test/resources/providers/TestParticipant2.json b/runtime-acm/src/test/resources/providers/TestParticipant2.json index 9a341844a..f1495bd7d 100644 --- a/runtime-acm/src/test/resources/providers/TestParticipant2.json +++ b/runtime-acm/src/test/resources/providers/TestParticipant2.json @@ -8,6 +8,7 @@ "participantState": "ON_LINE", "description": "A dummy PMSH participant2", "participantId": "cac01d0a-7ba8-4dda-b9be-6983c46c0546", + "lastMsg": "2024-05-22 10:04:37.6020187", "participantType": { "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition2", "version": "1.0.0" |