summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
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
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')
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java40
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java63
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java23
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java44
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java40
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java44
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java37
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java75
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java18
-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
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java58
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java68
13 files changed, 565 insertions, 26 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");
+ }
}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
index e3ebf3bef..9d4718bea 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
@@ -39,6 +39,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;
@@ -156,4 +157,26 @@ 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;
+ }
+ 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-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
index f0f991302..de0d21e6d 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
@@ -196,4 +196,48 @@ 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, mock(AcHttpClient.class));
+
+ 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 serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ var element = commonTestData.getAutomationCompositionElement();
+ map.putAll(element.getProperties());
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class));
+
+ automationCompositionElementHandler.handleRestartInstance(instanceId, element, map, DeployState.DEPLOYING,
+ LockState.NONE);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
+ }
+
+ @Test
+ void testHandleRestartInstanceDeployed() throws PfModelException {
+ var element = commonTestData.getAutomationCompositionElement();
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class));
+
+ automationCompositionElementHandler.handleRestartInstance(instanceId, element, element.getProperties(),
+ DeployState.DEPLOYED, LockState.LOCKED);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
+ }
}
diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
index ed02314cd..3a53a7aea 100755
--- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
@@ -23,10 +23,10 @@ package org.onap.policy.clamp.acm.participant.kserve.handler;
import io.kubernetes.client.openapi.ApiException;
import java.io.IOException;
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 java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -50,6 +50,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;
@@ -76,7 +77,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
private final KserveClient kserveClient;
@Getter(AccessLevel.PACKAGE)
- private final Map<UUID, ConfigurationEntity> configRequestMap = new HashMap<>();
+ private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>();
private static class ThreadConfig {
@@ -206,4 +207,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 (CoderException e) {
+ throw new KserveException(HttpStatus.SC_BAD_REQUEST, "Invalid inference service 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-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
index 6112488bf..1c1699f23 100755
--- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
@@ -49,6 +49,9 @@ import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException;
import org.onap.policy.clamp.acm.participant.kserve.k8s.KserveClient;
import org.onap.policy.clamp.acm.participant.kserve.utils.CommonTestData;
import org.onap.policy.clamp.acm.participant.kserve.utils.ToscaUtils;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -165,4 +168,45 @@ class AcElementHandlerTest {
void testDeprime() throws PfModelException {
assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
}
+
+ @Test
+ void testHandleRestartComposition() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartComposition(UUID.randomUUID(),
+ List.of(), AcTypeState.PRIMED));
+ }
+
+ @Test
+ void testHandleRestartInstanceDeploying() throws PfModelException {
+ var element = commonTestData.getAutomationCompositionElement();
+
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYING,
+ LockState.NONE));
+ assertThat(automationCompositionElementHandler.getConfigRequestMap()).containsKey(element.getId());
+ }
+
+ @Test
+ void testHandleRestartInstanceDeployed() throws PfModelException {
+ var element = commonTestData.getAutomationCompositionElement();
+
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYED,
+ LockState.LOCKED));
+ assertThat(automationCompositionElementHandler.getConfigRequestMap()).containsKey(element.getId());
+ }
+
+ @Test
+ void testHandleRestartInstanceUndeployed() throws PfModelException {
+ var element = commonTestData.getAutomationCompositionElement();
+
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.UNDEPLOYING,
+ LockState.LOCKED));
+ }
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
index 7385a1f3b..a0ea31673 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
@@ -44,6 +44,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;
@@ -212,4 +213,40 @@ 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 chartInfo = getChartInfo(properties);
+ chartMap.put(element.getId(), chartInfo);
+ } catch (AutomationCompositionException e) {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, e.getMessage());
+ }
+ }
+ 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-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
index 6b24c0f8a..6cf344feb 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
@@ -52,14 +52,13 @@ import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartList;
import org.onap.policy.clamp.acm.participant.kubernetes.parameters.CommonTestData;
import org.onap.policy.clamp.acm.participant.kubernetes.service.ChartService;
import org.onap.policy.clamp.acm.participant.kubernetes.utils.TestUtils;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -121,12 +120,7 @@ class AutomationCompositionElementHandlerTest {
void test_AutomationCompositionElementUpdate()
throws PfModelException, IOException, ServiceException, ExecutionException, InterruptedException {
doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
- var elementId1 = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(elementId1);
- element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
- element.setOrderedState(DeployOrder.DEPLOY);
-
+ var element = CommonTestData.createAcElementDeploy();
var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
doReturn(false).when(chartService).installChart(any());
@@ -137,7 +131,7 @@ class AutomationCompositionElementHandlerTest {
automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
- assertThat(automationCompositionElementHandler.getChartMap()).hasSize(1).containsKey(elementId1);
+ assertThat(automationCompositionElementHandler.getChartMap()).hasSize(1).containsKey(element.getId());
doThrow(new ServiceException("Error installing the chart")).when(chartService).installChart(Mockito.any());
@@ -154,18 +148,13 @@ class AutomationCompositionElementHandlerTest {
void test_checkPodStatus() throws ExecutionException, InterruptedException {
var chartInfo = charts.get(0);
var automationCompositionId = UUID.randomUUID();
- var element = new AutomationCompositionElement();
assertThrows(ServiceException.class, () -> automationCompositionElementHandler
- .checkPodStatus(automationCompositionId, element.getId(), chartInfo, 1, 1));
+ .checkPodStatus(automationCompositionId, UUID.randomUUID(), chartInfo, 1, 1));
}
@Test
void testUpdate() throws PfModelException {
- var elementId1 = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(elementId1);
- element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
- element.setOrderedState(DeployOrder.DEPLOY);
+ var element = CommonTestData.createAcElementDeploy();
var automationCompositionId = commonTestData.getAutomationCompositionId();
assertDoesNotThrow(
() -> automationCompositionElementHandler.update(automationCompositionId, element, Map.of()));
@@ -195,4 +184,54 @@ class AutomationCompositionElementHandlerTest {
void testDeprime() throws PfModelException {
assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
}
+
+ @Test
+ void testHandleRestartComposition() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartComposition(UUID.randomUUID(),
+ List.of(), AcTypeState.PRIMED));
+ }
+
+ @Test
+ void testHandleRestartInstanceDeploying()
+ throws PfModelException, InterruptedException, ServiceException, IOException {
+ doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
+ var element = CommonTestData.createAcElementDeploy();
+ var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+
+ doReturn(true).when(chartService).installChart(any());
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYING,
+ LockState.NONE));
+
+ assertThat(automationCompositionElementHandler.getChartMap()).containsKey(element.getId());
+ }
+
+ @Test
+ void testHandleRestartInstanceDeployed()
+ throws PfModelException, InterruptedException, ServiceException, IOException {
+ doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
+ var element = CommonTestData.createAcElementDeploy();
+ var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYED,
+ LockState.LOCKED));
+
+ assertThat(automationCompositionElementHandler.getChartMap()).containsKey(element.getId());
+ }
+
+ @Test
+ void testHandleRestartInstanceUndeploying()
+ throws PfModelException, InterruptedException, ServiceException, IOException {
+ doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
+ var element = CommonTestData.createAcElementDeploy();
+ var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+
+ assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.UNDEPLOYING,
+ LockState.LOCKED));
+ }
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java
index 8041a4ea5..8de972bfe 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java
@@ -26,10 +26,13 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
public class CommonTestData {
@@ -39,6 +42,8 @@ public class CommonTestData {
public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
public static final Coder CODER = new StandardCoder();
private static final UUID AC_ID = UUID.randomUUID();
+ private static final String KEY_NAME =
+ "org.onap.domain.database.HelloWorld_K8SMicroserviceAutomationCompositionElement";
/**
* Get ParticipantK8sParameters.
@@ -154,4 +159,17 @@ public class CommonTestData {
public UUID getAutomationCompositionId() {
return AC_ID;
}
+
+ /**
+ * Create an AcElementDeploy.
+ *
+ * @return an AcElementDeploy
+ */
+ public static AcElementDeploy createAcElementDeploy() {
+ var element = new AcElementDeploy();
+ element.setId(UUID.randomUUID());
+ element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
+ element.setOrderedState(DeployOrder.DEPLOY);
+ return element;
+ }
}
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");
+ }
}
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");
+ }
}