diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-05-28 16:18:42 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-04 10:40:23 +0100 |
commit | 6563ce72688dacd99c7badd0c9e94ad7fa22da23 (patch) | |
tree | 2cba7962384b4c39d58404f5afca8dcb29182ad0 /runtime-acm | |
parent | 74101c625cfaa5592c9219782f5919c02bd4bbb7 (diff) |
Remove Map in ACM-R for timeout Priming/Depriming
Issue-ID: POLICY-5025
Change-Id: I779d57715a82986bd19f541bc88b12163362b396
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
5 files changed, 18 insertions, 25 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java index ad39a68d4..74ccb9cc6 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java @@ -39,6 +39,7 @@ import org.onap.policy.clamp.models.acm.messages.rest.commissioning.Commissionin import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AcTypeStateResolver; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; @@ -209,7 +210,6 @@ public class CommissioningProvider { } private void prime(AutomationCompositionDefinition acmDefinition) { - acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR); var preparation = participantPrimePublisher.prepareParticipantPriming(acmDefinition); acDefinitionProvider.updateAcDefinition(acmDefinition, acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName()); @@ -232,6 +232,7 @@ public class CommissioningProvider { acmParticipantProvider.verifyParticipantState(participantIds); } acmDefinition.setState(AcTypeState.DEPRIMING); + acmDefinition.setLastMsg(TimestampHelper.now()); acDefinitionProvider.updateAcDefinition(acmDefinition, acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java index 881969a90..96e75df62 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java @@ -23,9 +23,7 @@ package org.onap.policy.clamp.acm.runtime.supervision; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; @@ -40,6 +38,7 @@ import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; 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.utils.AcmUtils; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +54,8 @@ public class SupervisionScanner { private final TimeoutHandler<UUID> acTimeout = new TimeoutHandler<>(); private final Map<UUID, Integer> phaseMap = new HashMap<>(); + private final long maxStatusWaitMs; + private final AutomationCompositionProvider automationCompositionProvider; private final AcDefinitionProvider acDefinitionProvider; private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher; @@ -80,6 +81,7 @@ public class SupervisionScanner { this.automationCompositionDeployPublisher = automationCompositionDeployPublisher; acTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); + this.maxStatusWaitMs = acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs(); } /** @@ -92,9 +94,6 @@ public class SupervisionScanner { for (var acDefinition : acDefinitionList) { scanAutomationCompositionDefinition(acDefinition); } - Set<UUID> set = new HashSet<>(); - set.addAll(acDefinitionList - .stream().map(AutomationCompositionDefinition::getCompositionId).collect(Collectors.toSet())); var acList = automationCompositionProvider.getAcInstancesInTransition(); HashMap<UUID, AutomationCompositionDefinition> acDefinitionMap = new HashMap<>(); @@ -106,8 +105,7 @@ public class SupervisionScanner { } scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate()); } - set.addAll( - acList.stream().map(AutomationComposition::getInstanceId).collect(Collectors.toSet())); + var set = acList.stream().map(AutomationComposition::getInstanceId).collect(Collectors.toSet()); acTimeout.removeIfNotPresent(set); LOGGER.debug("Automation composition scan complete . . ."); @@ -116,19 +114,9 @@ public class SupervisionScanner { private void scanAutomationCompositionDefinition(AutomationCompositionDefinition acDefinition) { if (StateChangeResult.FAILED.equals(acDefinition.getStateChangeResult())) { LOGGER.debug("automation definition {} scanned, OK", acDefinition.getCompositionId()); - - // Clear Timeout on ac Definition - acTimeout.remove(acDefinition.getCompositionId()); return; } - if (acTimeout.isTimeout(acDefinition.getCompositionId()) - && StateChangeResult.NO_ERROR.equals(acDefinition.getStateChangeResult())) { - // retry by the user - LOGGER.debug("clearing Timeout for the ac definition"); - acTimeout.clear(acDefinition.getCompositionId()); - } - boolean completed = true; var finalState = AcTypeState.PRIMING.equals(acDefinition.getState()) || AcTypeState.PRIMED.equals(acDefinition.getState()) ? AcTypeState.PRIMED : AcTypeState.COMMISSIONED; @@ -140,7 +128,6 @@ public class SupervisionScanner { if (completed) { acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), finalState, StateChangeResult.NO_ERROR, null); - acTimeout.remove(acDefinition.getCompositionId()); } else { handleTimeout(acDefinition); } @@ -252,15 +239,14 @@ public class SupervisionScanner { } private void handleTimeout(AutomationCompositionDefinition acDefinition) { - var compositionId = acDefinition.getCompositionId(); - if (acTimeout.isTimeout(compositionId)) { + if (StateChangeResult.TIMEOUT.equals(acDefinition.getStateChangeResult())) { LOGGER.debug("The ac definition is in timeout {}", acDefinition.getCompositionId()); return; } - - if (acTimeout.getDuration(compositionId) > acTimeout.getMaxWaitMs()) { + var now = TimestampHelper.nowEpochMilli(); + var lastMsg = TimestampHelper.toEpochMilli(acDefinition.getLastMsg()); + if ((now - lastMsg) > maxStatusWaitMs) { LOGGER.debug("Report timeout for the ac definition {}", acDefinition.getCompositionId()); - acTimeout.setTimeout(compositionId); acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT); acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), acDefinition.getStateChangeResult(), acDefinition.getRestarting()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java index 67246a5db..89763a2b6 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java @@ -35,9 +35,11 @@ import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider; 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.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrime; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.utils.AcmUtils; +import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,7 +86,9 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part * @return list of ParticipantDefinition */ public List<ParticipantDefinition> prepareParticipantPriming(AutomationCompositionDefinition acmDefinition) { + acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR); acmDefinition.setState(AcTypeState.PRIMING); + acmDefinition.setLastMsg(TimestampHelper.now()); var acElements = AcmUtils.extractAcElementsFromServiceTemplate(acmDefinition.getServiceTemplate(), acRuntimeParameterGroup.getAcmParameters().getToscaElementName()); Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>(); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index 7d0b4252a..8ed250fba 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -51,6 +50,7 @@ import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; 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.utils.TimestampHelper; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; class SupervisionScannerTest { @@ -66,6 +66,7 @@ class SupervisionScannerTest { acDefinition.setState(acTypeState); acDefinition.setStateChangeResult(stateChangeResult); acDefinition.setCompositionId(compositionId); + acDefinition.setLastMsg(TimestampHelper.now()); acDefinition.setServiceTemplate(serviceTemplate); var node = new NodeTemplateState(); node.setState(AcTypeState.PRIMING); 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 431a1ba55..e031e0f5a 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 @@ -121,6 +121,7 @@ public class CommonTestData { var acDefinition = new AutomationCompositionDefinition(); acDefinition.setCompositionId(UUID.randomUUID()); acDefinition.setState(state); + acDefinition.setLastMsg(TimestampHelper.now()); acDefinition.setServiceTemplate(serviceTemplate); var acElements = AcmUtils .extractAcElementsFromServiceTemplate(serviceTemplate, TOSCA_ELEMENT_NAME); |