diff options
author | 2023-07-04 09:26:41 +0100 | |
---|---|---|
committer | 2023-07-25 10:32:16 +0100 | |
commit | 80deb353657ecb47383a080185e5bc6ae52fcc32 (patch) | |
tree | 9fd89c067dc4fcc54128544386c29efafa7e1412 /participant/participant-impl/participant-impl-a1pms/src | |
parent | 842dad71f3f10d524b72c4f76262d76c6e4d1cc5 (diff) |
Add restart support inside participants
Issue-ID: POLICY-4747
Change-Id: I15a6c584062d0fcf0c0c0a6b15a8f3c2c96f7c98
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-a1pms/src')
2 files changed, 101 insertions, 2 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java index d653c5ad3..e2a5367f6 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java @@ -21,10 +21,10 @@ package org.onap.policy.clamp.acm.participant.a1pms.handler; import java.lang.invoke.MethodHandles; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import javax.validation.Validation; import javax.validation.ValidationException; import lombok.AccessLevel; @@ -42,6 +42,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDef import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; +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; import org.onap.policy.common.utils.coder.StandardCoder; @@ -67,7 +68,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio // Map of acElement Id and A1PMS services @Getter(AccessLevel.PACKAGE) - private final Map<UUID, ConfigurationEntity> configRequestMap = new HashMap<>(); + private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>(); /** * Handle a automation composition element state change. @@ -162,4 +163,39 @@ public class AutomationCompositionElementHandler implements AutomationCompositio intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); } + + @Override + public void handleRestartComposition(UUID compositionId, + List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) + throws PfModelException { + var finalState = AcTypeState.PRIMED.equals(state) || AcTypeState.PRIMING.equals(state) ? AcTypeState.PRIMED + : AcTypeState.COMMISSIONED; + intermediaryApi.updateCompositionState(compositionId, finalState, StateChangeResult.NO_ERROR, "Restarted"); + } + + @Override + public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, + Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { + if (DeployState.DEPLOYING.equals(deployState)) { + deploy(automationCompositionId, element, properties); + return; + } + if (DeployState.UNDEPLOYING.equals(deployState) || DeployState.DEPLOYED.equals(deployState) + || DeployState.UPDATING.equals(deployState)) { + try { + var configurationEntity = CODER.convert(properties, ConfigurationEntity.class); + configRequestMap.put(element.getId(), configurationEntity); + } catch (ValidationException | CoderException e) { + throw new A1PolicyServiceException(HttpStatus.SC_BAD_REQUEST, "Invalid Configuration", e); + } + } + if (DeployState.UNDEPLOYING.equals(deployState)) { + undeploy(automationCompositionId, element.getId()); + return; + } + deployState = AcmUtils.deployCompleted(deployState); + lockState = AcmUtils.lockCompleted(deployState, lockState); + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState, + lockState, StateChangeResult.NO_ERROR, "Restarted"); + } } diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java index 50f493299..dec11fd4e 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java @@ -213,4 +213,67 @@ class AcElementHandlerTest { verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); } + + @Test + void testHandleRestartComposition() throws PfModelException { + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient); + + var compositionId = UUID.randomUUID(); + automationCompositionElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED); + + verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, + StateChangeResult.NO_ERROR, "Restarted"); + } + + @Test + void testHandleRestartInstanceDeploying() throws PfModelException { + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient); + + var automationCompositionId = UUID.randomUUID(); + var element = commonTestData.getAutomationCompositionElement(); + var automationCompositionElementId = element.getId(); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + automationCompositionElementHandler.handleRestartInstance(automationCompositionId, element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYING, + LockState.NONE); + verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); + } + + @Test + void testHandleRestartInstanceDeployed() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(intermediaryApi, acA1PmsClient); + + var automationCompositionId = UUID.randomUUID(); + var element = commonTestData.getAutomationCompositionElement(); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + automationCompositionElementHandler.handleRestartInstance(automationCompositionId, element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYED, + LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(automationCompositionId, element.getId(), + DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted"); + } + + @Test + void testHandleRestartInstanceUndeployed() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(intermediaryApi, acA1PmsClient); + + var automationCompositionId = UUID.randomUUID(); + var element = commonTestData.getAutomationCompositionElement(); + var automationCompositionElementId = element.getId(); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + automationCompositionElementHandler.handleRestartInstance(automationCompositionId, element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.UNDEPLOYING, + LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); + } } |