aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-policy/src
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-07-04 09:26:41 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-07-13 13:20:31 +0000
commitef0a60deb046c5bf5ed1a6209493dfde6a6457a9 (patch)
tree3e92ffecd8579cfb0ddabef80dee5586c695eda1 /participant/participant-impl/participant-impl-policy/src
parent51ef04415186a0de3e50339b7fca04fb5ef079c9 (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-policy/src')
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java32
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java49
2 files changed, 81 insertions, 0 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 29622149a..6b94a79ad 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -40,6 +40,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.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -244,4 +245,35 @@ 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)) {
+ var automationCompositionDefinition = element.getToscaServiceTemplateFragment();
+ serviceTemplateMap.put(element.getId(), automationCompositionDefinition);
+ }
+ 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-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index 84ddeed74..16530d69f 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
@@ -218,4 +218,53 @@ class AutomationCompositionElementHandlerTest {
verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
"Deprimed");
}
+
+ @Test
+ void testHandleRestartComposition() throws PfModelException {
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class), intermediaryApi);
+
+ var compositionId = UUID.randomUUID();
+ automationCompositionElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED);
+
+ verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, "Restarted");
+ }
+
+ @Test
+ void testHandleRestartInstanceDeploying() throws PfModelException {
+ // Mock success scenario for policy creation and deployment
+ var api = mock(PolicyApiHttpClient.class);
+ doReturn(Response.ok().build()).when(api).createPolicyType(any());
+ doReturn(Response.ok().build()).when(api).createPolicy(any());
+
+ var pap = mock(PolicyPapHttpClient.class);
+ doReturn(Response.accepted().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
+
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
+ var element = getTestingAcElement();
+
+ handler.handleRestartInstance(AC_ID, element, Map.of(), DeployState.DEPLOYING, LockState.NONE);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
+
+ handler.handleRestartInstance(AC_ID, element, Map.of(), DeployState.UNDEPLOYING, LockState.LOCKED);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+ }
+
+ @Test
+ void testHandleRestartInstanceDeployed() throws PfModelException {
+ var api = mock(PolicyApiHttpClient.class);
+ var pap = mock(PolicyPapHttpClient.class);
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
+ var element = getTestingAcElement();
+ handler.handleRestartInstance(AC_ID, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKED);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
+ }
}