diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-07-04 09:26:41 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-07-13 13:20:31 +0000 |
commit | ef0a60deb046c5bf5ed1a6209493dfde6a6457a9 (patch) | |
tree | 3e92ffecd8579cfb0ddabef80dee5586c695eda1 /participant/participant-impl/participant-impl-simulator | |
parent | 51ef04415186a0de3e50339b7fca04fb5ef079c9 (diff) |
Add restart support inside participants
Issue-ID: POLICY-4747
Change-Id: I09ca3e373f8271fbfe612c031920058b744cf413
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator')
2 files changed, 122 insertions, 4 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java index 7554c0b3c..eaf94552b 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java @@ -40,6 +40,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; 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.models.base.PfModelException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -188,7 +189,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio @Override public void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) throws PfModelException { - LOGGER.debug("updat call"); + LOGGER.debug("update call"); if (!execution(config.getUpdateTimerMs(), "Current Thread update is Interrupted during execution {}", element.getId())) { @@ -233,6 +234,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio @Override public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) throws PfModelException { + LOGGER.debug("prime call"); if (!execution(config.getPrimeTimerMs(), "Current Thread prime is Interrupted during execution {}", compositionId)) { @@ -250,6 +252,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio @Override public void deprime(UUID compositionId) throws PfModelException { + LOGGER.debug("deprime call"); if (!execution(config.getDeprimeTimerMs(), "Current Thread deprime is Interrupted during execution {}", compositionId)) { @@ -287,4 +290,57 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } return result; } + + @Override + public void handleRestartComposition(UUID compositionId, + List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) + throws PfModelException { + LOGGER.debug("restart composition definition call"); + switch (state) { + case PRIMING: + prime(compositionId, elementDefinitionList); + break; + + case DEPRIMING: + deprime(compositionId); + break; + + default: + intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.NO_ERROR, "Restarted"); + } + } + + @Override + public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, + Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { + LOGGER.debug("restart instance call"); + if (!AcmUtils.isInTransitionalState(deployState, lockState)) { + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), + deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); + return; + } + if (DeployState.DEPLOYING.equals(deployState)) { + deploy(automationCompositionId, element, properties); + return; + } + if (DeployState.UNDEPLOYING.equals(deployState)) { + undeploy(automationCompositionId, element.getId()); + return; + } + if (DeployState.UPDATING.equals(deployState)) { + update(automationCompositionId, element, properties); + return; + } + if (DeployState.DELETING.equals(deployState)) { + delete(automationCompositionId, element.getId()); + return; + } + if (LockState.LOCKING.equals(lockState)) { + lock(automationCompositionId, element.getId()); + return; + } + if (LockState.UNLOCKING.equals(lockState)) { + unlock(automationCompositionId, element.getId()); + } + } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java index 977b9d8e4..70111cb52 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java @@ -192,9 +192,9 @@ class AutomationCompositionElementHandlerTest { when(intermediaryApi.getAutomationCompositions()).thenReturn(map); var result = acElementHandler.getDataList(); var data = result.getList().get(0); - var autocomposition = map.values().iterator().next(); - assertEquals(autocomposition.getInstanceId(), data.getAutomationCompositionId()); - var element = autocomposition.getElements().values().iterator().next(); + var automationcomposition = map.values().iterator().next(); + assertEquals(automationcomposition.getInstanceId(), data.getAutomationCompositionId()); + var element = automationcomposition.getElements().values().iterator().next(); assertEquals(element.getId(), data.getAutomationCompositionElementId()); } @@ -233,4 +233,66 @@ class AutomationCompositionElementHandlerTest { verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!"); } + + @Test + void testHandleRestartComposition() throws PfModelException { + var config = new SimConfig(); + config.setPrimeTimerMs(1); + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); + acElementHandler.setConfig(config); + var compositionId = UUID.randomUUID(); + acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMING); + verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, + "Primed"); + + acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED); + verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, + "Restarted"); + + acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.DEPRIMING); + verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED, + StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Test + void testHandleRestartInstance() throws PfModelException { + var config = new SimConfig(); + config.setDeployTimerMs(1); + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); + acElementHandler.setConfig(config); + var instanceId = UUID.randomUUID(); + var element = new AcElementDeploy(); + element.setId(UUID.randomUUID()); + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYING, LockState.NONE); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); + + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted"); + + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.UPDATING, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); + + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.UNDEPLOYING, + LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); + + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DELETING, LockState.NONE); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), null, + LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + + acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, + LockState.UNLOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), null, + LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + } } |