Allow migration to be performed in stages in ACM participant 15/138615/2
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 31 Jul 2024 12:16:30 +0000 (13:16 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Fri, 2 Aug 2024 08:20:11 +0000 (09:20 +0100)
Issue-ID: POLICY-5092
Change-Id: I47efc0fd6abf62c3a1cc6c12f0971b4460468733
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
20 files changed:
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java [new file with mode: 0644]
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/comm/CommonTestData.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java [new file with mode: 0644]
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java [new file with mode: 0644]
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerV2.java [new file with mode: 0644]
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1Test.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java [new file with mode: 0644]
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java

index ef8db0e..534b01b 100644 (file)
@@ -99,6 +99,6 @@ public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 {
         Map<String, Object> properties) {
         LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
                 instanceId, element, compositionTargetId, properties);
-        simulatorService.migrate(instanceId, element.getId());
+        simulatorService.migrate(instanceId, element.getId(), 0, Map.of());
     }
 }
index 7eff849..a7f72ec 100644 (file)
@@ -25,7 +25,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElement
 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
 import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
-import org.onap.policy.models.base.PfModelException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@@ -34,7 +33,7 @@ import org.springframework.stereotype.Component;
 /**
  * This class handles implementation of automationCompositionElement updates.
  */
-@ConditionalOnExpression("'${element.handler:AcElementHandlerV2}' == 'AcElementHandlerV2'")
+@ConditionalOnExpression("'${element.handler}'=='AcElementHandlerV2'")
 @Component
 public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
 
@@ -112,21 +111,22 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
 
     @Override
     public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
-                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
-            throws PfModelException {
+                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) {
         LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
                         + " instanceElementMigrate: {}",
                 compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
-        if (instanceElement.newElement()) {
-            simulatorService.migrate(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId());
 
-        } else if (instanceElementMigrate.removedElement()) {
+        if (instanceElementMigrate.newElement()) {
+            LOGGER.debug("new element scenario");
+
+        }
+        if (instanceElementMigrate.removedElement()) {
             simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
             simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
         } else {
-            simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId());
+            simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(),
+                    0, compositionElementTarget.inProperties());
         }
-
     }
 
     @Override
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java
new file mode 100644 (file)
index 0000000..66f4c30
--- /dev/null
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.sim.main.handler;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV3;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class handles implementation of automationCompositionElement updates.
+ */
+@Getter
+@Setter
+@ConditionalOnExpression("'${element.handler:AcElementHandlerV3}' == 'AcElementHandlerV3'")
+@Component
+public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV3.class);
+
+    private final SimulatorService simulatorService;
+
+    public AutomationCompositionElementHandlerV3(ParticipantIntermediaryApi intermediaryApi,
+        SimulatorService simulatorService) {
+        super(intermediaryApi);
+        this.simulatorService = simulatorService;
+    }
+
+    /**
+     * Handle a deploy on a automation composition element.
+     *
+     * @param compositionElement the information of the Automation Composition Definition Element
+     * @param instanceElement the information of the Automation Composition Instance Element
+     */
+    @Override
+    public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    /**
+     * Handle a automation composition element state change.
+     *
+     * @param compositionElement the information of the Automation Composition Definition Element
+     * @param instanceElement the information of the Automation Composition Instance Element
+     */
+    @Override
+    public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("undeploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("lock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.lock(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("unlock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.unlock(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("delete call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
+                       InstanceElementDto instanceElementUpdated) {
+        LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}",
+                compositionElement, instanceElement, instanceElementUpdated);
+        simulatorService.update(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void prime(CompositionDto composition) {
+        LOGGER.debug("prime call composition: {}", composition);
+        simulatorService.prime(composition.compositionId());
+    }
+
+    @Override
+    public void deprime(CompositionDto composition) {
+        LOGGER.debug("deprime call composition: {}", composition);
+        simulatorService.deprime(composition.compositionId());
+    }
+
+    @Override
+    public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
+                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate, int stage) {
+        LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
+                + " instanceElementMigrate: {}, stage: {}",
+            compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate, stage);
+
+        if (instanceElementMigrate.newElement()) {
+            LOGGER.debug("new element scenario");
+        }
+        if (instanceElementMigrate.removedElement()) {
+            simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
+            simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
+        } else {
+            simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(), stage,
+                    compositionElementTarget.inProperties());
+        }
+    }
+
+    @Override
+    public void migratePrecheck(CompositionElementDto compositionElement,
+            CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
+            InstanceElementDto instanceElementMigrate) {
+        LOGGER.debug("migrate precheck call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
+                        + " instanceElementMigrate: {}",
+                compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
+        simulatorService.migratePrecheck(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("prepare call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.prepare(instanceElement.instanceId(), instanceElement.elementId());
+    }
+
+    @Override
+    public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+        LOGGER.debug("review call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+        simulatorService.review(instanceElement.instanceId(), instanceElement.elementId());
+    }
+}
index e1e3ad4..b0006f7 100644 (file)
@@ -35,6 +35,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
 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.ParticipantUtils;
 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.slf4j.Logger;
@@ -327,18 +328,34 @@ public class SimulatorService {
      *
      * @param instanceId the instanceId
      * @param elementId the elementId
+     * @param stage the stage
      */
-    public void migrate(UUID instanceId, UUID elementId) {
+    public void migrate(UUID instanceId, UUID elementId, int stage, Map<String, Object> compositionInProperties) {
         if (!execution(getConfig().getMigrateTimerMs(),
                 "Current Thread migrate is Interrupted during execution {}", elementId)) {
             return;
         }
 
-        if (getConfig().isMigrateSuccess()) {
-            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
-                    DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+        if (config.isMigrateSuccess()) {
+            var stageSet = ParticipantUtils.findStageSet(compositionInProperties);
+            var nextStage = 1000;
+            for (var s : stageSet) {
+                if (s > stage) {
+                    nextStage = Math.min(s, nextStage);
+                }
+            }
+            if (nextStage == 1000) {
+                intermediaryApi.updateAutomationCompositionElementState(
+                        instanceId, elementId,
+                        DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+            } else {
+                intermediaryApi.updateAutomationCompositionElementStage(
+                        instanceId, elementId,
+                        StateChangeResult.NO_ERROR, nextStage, "stage " + stage + " Migrated");
+            }
         } else {
-            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+            intermediaryApi.updateAutomationCompositionElementState(
+                    instanceId, elementId,
                     DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
         }
     }
index 5499931..f73f759 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
 import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
+import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
 import org.onap.policy.clamp.acm.participant.sim.parameters.ParticipantSimParameters;
 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
@@ -102,7 +103,7 @@ public class CommonTestData {
      * @return topic parameters
      */
     private static TopicParameters getSinkTopicParams() {
-        final TopicParameters topicParams = new TopicParameters();
+        final var topicParams = new TopicParameters();
         topicParams.setTopic("policy-acruntime-participant");
         topicParams.setTopicCommInfrastructure("NOOP");
         topicParams.setServers(List.of("localhost"));
@@ -115,7 +116,7 @@ public class CommonTestData {
      * @return topic parameters
      */
     private static TopicParameters getSyncTopicParams() {
-        final TopicParameters topicParams = new TopicParameters();
+        final var topicParams = new TopicParameters();
         topicParams.setTopic("acm-ppnt-sync");
         topicParams.setTopicCommInfrastructure("NOOP");
         topicParams.setServers(List.of("localhost"));
@@ -135,8 +136,6 @@ public class CommonTestData {
      * Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
      *
      * @return automationCompositionMap
-     *
-     * @throws CoderException if there is an error with .json file.
      */
     public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
         var automationComposition = getTestAutomationComposition();
@@ -147,8 +146,6 @@ public class CommonTestData {
      * Returns List of AutomationComposition for test cases.
      *
      * @return AutomationCompositions
-     *
-     * @throws CoderException if there is an error with .json file.
      */
     public static AutomationComposition getTestAutomationComposition() {
         var automationComposition = new AutomationComposition();
@@ -158,4 +155,26 @@ public class CommonTestData {
         automationComposition.setElements(Map.of(element.getId(), element));
         return automationComposition;
     }
+
+    /**
+     * Create a new SimConfig.
+     *
+     * @return a new SimConfig
+     */
+    public static SimConfig createSimConfig() {
+        var config = new SimConfig();
+        config.setPrepareTimerMs(1);
+        config.setDeployTimerMs(1);
+        config.setReviewTimerMs(1);
+        config.setUndeployTimerMs(1);
+        config.setLockTimerMs(1);
+        config.setUnlockTimerMs(1);
+        config.setUpdateTimerMs(1);
+        config.setDeleteTimerMs(1);
+        config.setPrimeTimerMs(1);
+        config.setDeprimeTimerMs(1);
+        config.setMigrateTimerMs(1);
+        config.setMigratePrecheckTimerMs(1);
+        return config;
+    }
 }
index 300caa5..d78b851 100644 (file)
@@ -28,194 +28,178 @@ import java.util.Map;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
+import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
 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.clamp.models.acm.concepts.StateChangeResult;
-import org.onap.policy.models.base.PfModelException;
 
 class AutomationCompositionElementHandlerV1Test {
 
+    private static final UUID COMPOSITION_ID = UUID.randomUUID();
+    private static final UUID INSTANCE_ID = UUID.randomUUID();
+    private static final UUID ELEMENT_ID = UUID.randomUUID();
+
+    private AcElementDeploy createAcElementDeploy() {
+        var element = new AcElementDeploy();
+        element.setId(ELEMENT_ID);
+        return element;
+    }
+
     @Test
-    void testDeploy() throws PfModelException {
-        var config = new SimConfig();
-        config.setDeployTimerMs(1);
+    void testDeploy() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var element = new AcElementDeploy();
-        element.setId(UUID.randomUUID());
-        acElementHandler.deploy(instanceId, element, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        var element = createAcElementDeploy();
+        acElementHandler.deploy(INSTANCE_ID, element, Map.of());
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
                 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
 
         config.setDeploySuccess(false);
-        acElementHandler.deploy(instanceId, element, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.deploy(INSTANCE_ID, element, Map.of());
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
                 DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!");
     }
 
     @Test
-    void testUndeploy() throws PfModelException {
-        var config = new SimConfig();
-        config.setUndeployTimerMs(1);
+    void testUndeploy() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        acElementHandler.undeploy(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.undeploy(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.UNDEPLOYED,
                 null, StateChangeResult.NO_ERROR, "Undeployed");
 
         config.setUndeploySuccess(false);
-        acElementHandler.undeploy(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+        acElementHandler.undeploy(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.DEPLOYED,
                 null, StateChangeResult.FAILED, "Undeploy failed!");
     }
 
     @Test
-    void testLock() throws PfModelException {
-        var config = new SimConfig();
-        config.setLockTimerMs(1);
+    void testLock() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        acElementHandler.lock(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
-                StateChangeResult.NO_ERROR, "Locked");
+        acElementHandler.lock(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+                null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
 
         config.setLockSuccess(false);
-        acElementHandler.lock(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
-                StateChangeResult.FAILED, "Lock failed!");
+        acElementHandler.lock(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+                null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!");
     }
 
     @Test
-    void testUnlock() throws PfModelException {
-        var config = new SimConfig();
-        config.setUnlockTimerMs(1);
+    void testUnlock() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        acElementHandler.unlock(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
-                StateChangeResult.NO_ERROR, "Unlocked");
+        acElementHandler.unlock(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+                null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
 
         config.setUnlockSuccess(false);
-        acElementHandler.unlock(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
-                StateChangeResult.FAILED, "Unlock failed!");
+        acElementHandler.unlock(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+                null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!");
     }
 
     @Test
-    void testUpdate() throws PfModelException {
-        var config = new SimConfig();
-        config.setUpdateTimerMs(1);
+    void testUpdate() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var element = new AcElementDeploy();
-        element.setId(UUID.randomUUID());
-        acElementHandler.update(instanceId, element, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        var element = createAcElementDeploy();
+        acElementHandler.update(INSTANCE_ID, element, Map.of());
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
                 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
 
         config.setUpdateSuccess(false);
-        acElementHandler.update(instanceId, element, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.update(INSTANCE_ID, element, Map.of());
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
                 DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
     }
 
     @Test
-    void testDelete() throws PfModelException {
-        var config = new SimConfig();
-        config.setDeleteTimerMs(1);
+    void testDelete() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        acElementHandler.delete(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED,
+        acElementHandler.delete(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.DELETED,
                 null, StateChangeResult.NO_ERROR, "Deleted");
 
         config.setDeleteSuccess(false);
-        acElementHandler.delete(instanceId, elementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.delete(INSTANCE_ID, ELEMENT_ID);
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.UNDEPLOYED,
                 null, StateChangeResult.FAILED, "Delete failed!");
     }
 
     @Test
-    void testPrime() throws PfModelException {
-        var config = new SimConfig();
-        config.setPrimeTimerMs(1);
+    void testPrime() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionId = UUID.randomUUID();
-        acElementHandler.prime(compositionId, List.of());
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
+        acElementHandler.prime(COMPOSITION_ID, List.of());
+        verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
                 "Primed");
 
         config.setPrimeSuccess(false);
-        acElementHandler.prime(compositionId, List.of());
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+        acElementHandler.prime(COMPOSITION_ID, List.of());
+        verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.COMMISSIONED,
                 StateChangeResult.FAILED, "Prime failed!");
     }
 
     @Test
-    void testDeprime() throws PfModelException {
-        var config = new SimConfig();
-        config.setDeprimeTimerMs(1);
+    void testDeprime() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionId = UUID.randomUUID();
-        acElementHandler.deprime(compositionId);
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+        acElementHandler.deprime(COMPOSITION_ID);
+        verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.COMMISSIONED,
                 StateChangeResult.NO_ERROR, "Deprimed");
 
         config.setDeprimeSuccess(false);
-        acElementHandler.deprime(compositionId);
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED,
+        acElementHandler.deprime(COMPOSITION_ID);
+        verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.PRIMED, StateChangeResult.FAILED,
                 "Deprime failed!");
     }
 
     @Test
-    void testMigrate() throws PfModelException {
-        var config = new SimConfig();
-        config.setUpdateTimerMs(1);
+    void testMigrate() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var instanceId = UUID.randomUUID();
-        var element = new AcElementDeploy();
-        element.setId(UUID.randomUUID());
-        acElementHandler.migrate(instanceId, element, UUID.randomUUID(), Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        var element = createAcElementDeploy();
+        acElementHandler.migrate(INSTANCE_ID, element, COMPOSITION_ID, Map.of());
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
                 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
 
         config.setMigrateSuccess(false);
-        acElementHandler.migrate(instanceId, element, UUID.randomUUID(), Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.migrate(INSTANCE_ID, element, COMPOSITION_ID, Map.of());
+        verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
                 DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
     }
 }
index 1e2ec2c..e8e9b76 100644 (file)
@@ -30,303 +30,303 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
 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.clamp.models.acm.concepts.StateChangeResult;
-import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class AutomationCompositionElementHandlerV2Test {
 
+    private static final CompositionElementDto COMPOSITION_ELEMENT =
+            new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of());
+    private static final InstanceElementDto INSTANCE_ELEMENT =
+            new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+    private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of());
+
     @Test
     void testDeploy() {
-        var config = new SimConfig();
-        config.setDeployTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.deploy(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+        acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
                 null, StateChangeResult.NO_ERROR, "Deployed");
 
         config.setDeploySuccess(false);
-        acElementHandler.deploy(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
                 null, StateChangeResult.FAILED, "Deploy failed!");
     }
 
     @Test
     void testUndeploy() {
-        var config = new SimConfig();
-        config.setUndeployTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.undeploy(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
                 null, StateChangeResult.NO_ERROR, "Undeployed");
 
         config.setUndeploySuccess(false);
-        acElementHandler.undeploy(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+        acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
                 null, StateChangeResult.FAILED, "Undeploy failed!");
     }
 
     @Test
     void testLock() {
-        var config = new SimConfig();
-        config.setLockTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.lock(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+        acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
                 StateChangeResult.NO_ERROR, "Locked");
 
         config.setLockSuccess(false);
-        acElementHandler.lock(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+        acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
                 StateChangeResult.FAILED, "Lock failed!");
     }
 
     @Test
     void testUnlock() {
-        var config = new SimConfig();
-        config.setUnlockTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.unlock(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+        acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
                 StateChangeResult.NO_ERROR, "Unlocked");
 
         config.setUnlockSuccess(false);
-        acElementHandler.unlock(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+        acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
                 StateChangeResult.FAILED, "Unlock failed!");
     }
 
     @Test
     void testUpdate() {
-        var config = new SimConfig();
-        config.setUpdateTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var element = new AcElementDeploy();
-        element.setId(UUID.randomUUID());
-        var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
-        var instanceElementUpdated = new InstanceElementDto(instanceId, element.getId(), null,
+        var instanceElementUpdated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null,
                 Map.of("key", "value"), Map.of());
-        acElementHandler.update(compositionElement, instanceElement, instanceElementUpdated);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
 
         config.setUpdateSuccess(false);
-        acElementHandler.update(compositionElement, instanceElement, instanceElementUpdated);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
     }
 
     @Test
     void testDelete() {
-        var config = new SimConfig();
-        config.setDeleteTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.delete(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED,
+        acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DELETED,
                 null, StateChangeResult.NO_ERROR, "Deleted");
 
         config.setDeleteSuccess(false);
-        acElementHandler.delete(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
                 null, StateChangeResult.FAILED, "Delete failed!");
     }
 
     @Test
     void testPrime() {
-        var config = new SimConfig();
-        config.setPrimeTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionId = UUID.randomUUID();
-        var composition = new CompositionDto(compositionId, Map.of(), Map.of());
-        acElementHandler.prime(composition);
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
-                "Primed");
+        acElementHandler.prime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
 
         config.setPrimeSuccess(false);
-        acElementHandler.prime(composition);
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
-                StateChangeResult.FAILED, "Prime failed!");
+        acElementHandler.prime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!");
     }
 
     @Test
     void testDeprime() {
-        var config = new SimConfig();
-        config.setDeprimeTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionId = UUID.randomUUID();
-        var composition = new CompositionDto(compositionId, Map.of(), Map.of());
-        acElementHandler.deprime(composition);
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
-                StateChangeResult.NO_ERROR, "Deprimed");
+        acElementHandler.deprime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
 
         config.setDeprimeSuccess(false);
-        acElementHandler.deprime(composition);
-        verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED,
-                "Deprime failed!");
+        acElementHandler.deprime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!");
     }
 
     @Test
-    void testMigrate() throws PfModelException {
-        var config = new SimConfig();
-        config.setUpdateTimerMs(1);
+    void testMigrate() {
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var compositionElementTraget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+        var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
                 Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var element = new AcElementDeploy();
-        element.setId(UUID.randomUUID());
-        var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
-        var instanceElementMigrated = new InstanceElementDto(instanceId, element.getId(),
+        var instanceElementMigrated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 null, Map.of("key", "value"), Map.of());
         acElementHandler
-                .migrate(compositionElement, compositionElementTraget, instanceElement, instanceElementMigrated);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+            .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
 
         config.setMigrateSuccess(false);
         acElementHandler
-                .migrate(compositionElement, compositionElementTraget, instanceElement, instanceElementMigrated);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+            .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
     }
 
+    @Test
+    void testMigrateAdd() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        var compoElTargetAdd = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of(), true, false);
+        var inElMigratedAdd = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of("key", "value"), Map.of(), true, false);
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compoElTargetAdd, INSTANCE_ELEMENT, inElMigratedAdd);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+    }
+
+    @Test
+    void testMigrateRemove() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+
+        var compoElTargetRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of(), false, true);
+        var inElMigratedRemove = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of("key", "value"), Map.of(), false, true);
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+    }
+
     @Test
     void testMigratePrecheck() {
-        var config = new SimConfig();
-        config.setUpdateTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+        var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
                 Map.of(), Map.of());
-        var compositionElementTraget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var element = new AcElementDeploy();
-        element.setId(UUID.randomUUID());
-        var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
-        var instanceElementMigrated = new InstanceElementDto(instanceId, element.getId(),
+        var instanceElementMigrated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 null, Map.of("key", "value"), Map.of());
-        acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
-                instanceElement, instanceElementMigrated);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+                INSTANCE_ELEMENT, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 DeployState.DEPLOYED, null,
                 StateChangeResult.NO_ERROR, "Migration precheck completed");
 
         config.setMigratePrecheck(false);
-        acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
-                instanceElement, instanceElementMigrated);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+        acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+                INSTANCE_ELEMENT, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
                 DeployState.DEPLOYED, null,
                 StateChangeResult.FAILED, "Migration precheck failed");
     }
 
     @Test
     void testPrepare() {
-        var config = new SimConfig();
-        config.setDeployTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.prepare(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
                 null, StateChangeResult.NO_ERROR, "Prepare completed");
 
         config.setPrepare(false);
-        acElementHandler.prepare(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+        acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
                 null, StateChangeResult.FAILED, "Prepare failed");
     }
 
     @Test
     void testReview() {
-        var config = new SimConfig();
-        config.setDeployTimerMs(1);
+        var config = CommonTestData.createSimConfig();
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var simulatorService = new SimulatorService(intermediaryApi);
         var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
         simulatorService.setConfig(config);
-        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-                Map.of(), Map.of());
-        var instanceId = UUID.randomUUID();
-        var elementId = UUID.randomUUID();
-        var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
-        acElementHandler.review(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+        acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
                 null, StateChangeResult.NO_ERROR, "Review completed");
 
         config.setReview(false);
-        acElementHandler.review(compositionElement, instanceElement);
-        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+        acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
                 null, StateChangeResult.FAILED, "Review failed");
     }
 }
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java
new file mode 100644 (file)
index 0000000..3a7af24
--- /dev/null
@@ -0,0 +1,352 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.sim.main.handler;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
+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.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class AutomationCompositionElementHandlerV3Test {
+
+    private static final CompositionElementDto COMPOSITION_ELEMENT =
+            new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of());
+    private static final InstanceElementDto INSTANCE_ELEMENT =
+            new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+    private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of());
+
+    @Test
+    void testDeploy() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+                null, StateChangeResult.NO_ERROR, "Deployed");
+
+        config.setDeploySuccess(false);
+        acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+                null, StateChangeResult.FAILED, "Deploy failed!");
+    }
+
+    @Test
+    void testUndeploy() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+                null, StateChangeResult.NO_ERROR, "Undeployed");
+
+        config.setUndeploySuccess(false);
+        acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+                null, StateChangeResult.FAILED, "Undeploy failed!");
+    }
+
+    @Test
+    void testLock() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
+                StateChangeResult.NO_ERROR, "Locked");
+
+        config.setLockSuccess(false);
+        acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
+                StateChangeResult.FAILED, "Lock failed!");
+    }
+
+    @Test
+    void testUnlock() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
+                StateChangeResult.NO_ERROR, "Unlocked");
+
+        config.setUnlockSuccess(false);
+        acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
+                StateChangeResult.FAILED, "Unlock failed!");
+    }
+
+    @Test
+    void testUpdate() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        var instanceElementUpdated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null,
+                Map.of("key", "value"), Map.of());
+        acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
+
+        config.setUpdateSuccess(false);
+        acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
+    }
+
+    @Test
+    void testDelete() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DELETED,
+                null, StateChangeResult.NO_ERROR, "Deleted");
+
+        config.setDeleteSuccess(false);
+        acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+                null, StateChangeResult.FAILED, "Delete failed!");
+    }
+
+    @Test
+    void testPrime() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.prime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+
+        config.setPrimeSuccess(false);
+        acElementHandler.prime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!");
+    }
+
+    @Test
+    void testDeprime() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.deprime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
+
+        config.setDeprimeSuccess(false);
+        acElementHandler.deprime(COMPOSITION);
+        verify(intermediaryApi).updateCompositionState(
+                COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!");
+    }
+
+    @Test
+    void testMigrate() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of());
+        var instanceElementMigrated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of("key", "value"), Map.of());
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+
+        config.setMigrateSuccess(false);
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
+    }
+
+    @Test
+    void testMigrateStage() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of("stage", List.of(1, 2)), Map.of());
+        var instanceElementMigrated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of(), Map.of());
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 1);
+        verify(intermediaryApi).updateAutomationCompositionElementStage(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                StateChangeResult.NO_ERROR, 2, "stage 1 Migrated");
+    }
+
+    @Test
+    void testMigrateAdd() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        var compoElTargetAdd = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of(), true, false);
+        var inElMigratedAdd = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of("key", "value"), Map.of(), true, false);
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compoElTargetAdd, INSTANCE_ELEMENT, inElMigratedAdd, 0);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+    }
+
+    @Test
+    void testMigrateRemove() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+
+        var compoElTargetRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of(), false, true);
+        var inElMigratedRemove = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of("key", "value"), Map.of(), false, true);
+        acElementHandler
+                .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove, 0);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+    }
+
+    @Test
+    void testMigratePrecheck() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of());
+        var instanceElementMigrated = new InstanceElementDto(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                null, Map.of("key", "value"), Map.of());
+        acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+                INSTANCE_ELEMENT, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null,
+                StateChangeResult.NO_ERROR, "Migration precheck completed");
+
+        config.setMigratePrecheck(false);
+        acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+                INSTANCE_ELEMENT, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+                DeployState.DEPLOYED, null,
+                StateChangeResult.FAILED, "Migration precheck failed");
+    }
+
+    @Test
+    void testPrepare() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+                null, StateChangeResult.NO_ERROR, "Prepare completed");
+
+        config.setPrepare(false);
+        acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+                null, StateChangeResult.FAILED, "Prepare failed");
+    }
+
+    @Test
+    void testReview() {
+        var config = CommonTestData.createSimConfig();
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+        simulatorService.setConfig(config);
+        acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+                null, StateChangeResult.NO_ERROR, "Review completed");
+
+        config.setReview(false);
+        acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+        verify(intermediaryApi).updateAutomationCompositionElementState(
+                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+                null, StateChangeResult.FAILED, "Review failed");
+    }
+}
index cbcd8dd..5994328 100644 (file)
@@ -89,14 +89,16 @@ public interface AutomationCompositionElementListener {
     /**
      * Handle an update on a automation composition element.
      *
-     * @param compositionElement the information of the Automation Composition Definition Element
+     * @param compositionElement       the information of the Automation Composition Definition Element
      * @param compositionElementTarget the information of the Automation Composition Definition Element Target
-     * @param instanceElement the information of the Automation Composition Instance Element
-     * @param instanceElementMigrate the information of the Automation Composition Instance Element updated
+     * @param instanceElement          the information of the Automation Composition Instance Element
+     * @param instanceElementMigrate   the information of the Automation Composition Instance Element updated
+     * @param nextStage                    the next stage
      * @throws PfModelException from Policy framework
      */
     void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
-            InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException;
+            InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate,
+            int nextStage) throws PfModelException;
 
     void migratePrecheck(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
             InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException;
index 9b32792..c06ffe6 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-2024 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,41 +38,52 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 public interface ParticipantIntermediaryApi {
 
     /**
-     * Update the state of a automation composition element.
+     * Update the state of a AutomationComposition Instance Element.
      *
-     * @param automationCompositionId the ID of the automation composition to update the state on
-     * @param elementId the ID of the automation composition element to update the state on
-     * @param deployState the Deploy State of the automation composition element
-     * @param lockState the Lock State of the automation composition element
+     * @param instance the ID of the AutomationComposition Instance to update the state on
+     * @param elementId the ID of the AutomationComposition Instance element to update the state on
+     * @param deployState the Deploy State of the AutomationComposition Instance element
+     * @param lockState the Lock State of the AutomationComposition Instance element
      * @param stateChangeResult the indicator if error occurs
      * @param message the message
      */
-    void updateAutomationCompositionElementState(UUID automationCompositionId, UUID elementId, DeployState deployState,
+    void updateAutomationCompositionElementState(UUID instance, UUID elementId, DeployState deployState,
             LockState lockState, StateChangeResult stateChangeResult, String message);
 
     /**
-     * Get a copy of all AutomationCompositions.
+     * Update the stage of a AutomationComposition Instance Element.
      *
-     * @return get all AutomationCompositions
+     * @param instance the ID of the AutomationComposition Instance to update the state on
+     * @param elementId the ID of the AutomationComposition Instance Element to update the state on
+     * @param stateChangeResult the indicator if error occurs
+     * @param message the message
+     */
+    void updateAutomationCompositionElementStage(UUID instance, UUID elementId, StateChangeResult stateChangeResult,
+            int stage, String message);
+
+    /**
+     * Get a copy of all AutomationComposition Instances.
+     *
+     * @return get all AutomationComposition Instances
      */
     Map<UUID, AutomationComposition> getAutomationCompositions();
 
     /**
-     * Get a copy of the AutomationComposition by automationCompositionId.
+     * Get a copy of the AutomationComposition Instance by AutomationComposition Instance Id.
      *
-     * @param automationCompositionId the ID of the automation composition to update the state on
-     * @return get the AutomationComposition
+     * @param instanceId the ID of the AutomationComposition Instance to update the state on
+     * @return get the AutomationComposition Instance
      */
-    AutomationComposition getAutomationComposition(UUID automationCompositionId);
+    AutomationComposition getAutomationComposition(UUID instanceId);
 
     /**
-     * Get a copy of the AutomationCompositionElement by automationCompositionId and elementId.
+     * Get a copy of the AutomationCompositionElement by AutomationComposition Instance Id and elementId.
      *
-     * @param automationCompositionId the ID of the automation composition to update the state on
-     * @param elementId the ID of the automation composition element to update the state on
+     * @param instanceId the ID of the AutomationComposition Instance to update the state on
+     * @param elementId the ID of the AutomationComposition Instance Element to update the state on
      * @return get the AutomationCompositionElement
      */
-    AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId);
+    AutomationCompositionElement getAutomationCompositionElement(UUID instanceId, UUID elementId);
 
     /**
      * Get a copy of all AutomationCompositionElementDefinition from all primed compositions.
@@ -99,15 +110,15 @@ public interface ParticipantIntermediaryApi {
     AutomationCompositionElementDefinition getAcElementDefinition(UUID compositionId, ToscaConceptIdentifier elementId);
 
     /**
-     * Send Automation Composition Element update Info to AC-runtime.
+     * Send AutomationComposition Instance Element update Info to AC-runtime.
      *
-     * @param automationCompositionId the ID of the automation composition to update the states
-     * @param elementId the ID of the automation composition element to update the states
+     * @param instanceId the ID of the AutomationComposition Instance to update the states
+     * @param elementId the ID of the AutomationComposition Instance Element to update the states
      * @param useState the use State
      * @param operationalState the operational State
      * @param outProperties the output Properties Map
      */
-    void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState, String operationalState,
+    void sendAcElementInfo(UUID instanceId, UUID elementId, String useState, String operationalState,
             Map<String, Object> outProperties);
 
     /**
index 6bc3f92..34bdc34 100644 (file)
@@ -209,7 +209,8 @@ public abstract class AcElementListenerV1
 
     @Override
     public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
-        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException {
+                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate,
+                        int stage) throws PfModelException {
         var element = new  AcElementDeploy();
         element.setId(instanceElementMigrate.elementId());
         element.setDefinition(compositionElementTarget.elementDefinitionId());
index 6e6f96e..7db2200 100644 (file)
@@ -36,7 +36,8 @@ import org.onap.policy.models.base.PfModelException;
  * Wrapper of AutomationCompositionElementListener.
  * Valid since 7.1.1 release.
  */
-public abstract class AcElementListenerV2 implements AutomationCompositionElementListener {
+public abstract class AcElementListenerV2
+        implements AutomationCompositionElementListener, AutomationCompositionElementListenerV2 {
     protected final ParticipantIntermediaryApi intermediaryApi;
 
     private static final String NOT_SUPPORTED = "not supported!";
@@ -96,6 +97,13 @@ public abstract class AcElementListenerV2 implements AutomationCompositionElemen
         throw new PfModelException(Response.Status.BAD_REQUEST, NOT_SUPPORTED);
     }
 
+    @Override
+    public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
+                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate, int stage)
+        throws PfModelException {
+        migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
+    }
+
     @Override
     public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
                         InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java
new file mode 100644 (file)
index 0000000..d63323d
--- /dev/null
@@ -0,0 +1,119 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ *  Copyright (C) 2024 Nordix Foundation.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * SPDX-License-Identifier: Apache-2.0\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.clamp.acm.participant.intermediary.api.impl;\r
+\r
+import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;\r
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;\r
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;\r
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;\r
+import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;\r
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;\r
+import org.onap.policy.clamp.models.acm.concepts.DeployState;\r
+import org.onap.policy.clamp.models.acm.concepts.LockState;\r
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;\r
+import org.onap.policy.models.base.PfModelException;\r
+\r
+/**\r
+ * Wrapper of AutomationCompositionElementListener.\r
+ * Valid since 8.0.1 release.\r
+ */\r
+public abstract class AcElementListenerV3 implements AutomationCompositionElementListener {\r
+    protected final ParticipantIntermediaryApi intermediaryApi;\r
+\r
+    protected AcElementListenerV3(ParticipantIntermediaryApi intermediaryApi) {\r
+        this.intermediaryApi = intermediaryApi;\r
+    }\r
+\r
+    @Override\r
+    public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)\r
+        throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),\r
+            instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");\r
+    }\r
+\r
+    @Override\r
+    public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)\r
+        throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),\r
+            instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");\r
+    }\r
+\r
+    @Override\r
+    public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement)\r
+        throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),\r
+            instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");\r
+    }\r
+\r
+    @Override\r
+    public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,\r
+                       InstanceElementDto instanceElementUpdated) throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),\r
+            instanceElement.elementId(), DeployState.DEPLOYED, null,\r
+            StateChangeResult.NO_ERROR, "Update not supported");\r
+\r
+    }\r
+\r
+    @Override\r
+    public void prime(CompositionDto composition) throws PfModelException {\r
+        intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED,\r
+            StateChangeResult.NO_ERROR, "Primed");\r
+    }\r
+\r
+    @Override\r
+    public void deprime(CompositionDto composition) throws PfModelException {\r
+        intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED,\r
+            StateChangeResult.NO_ERROR, "Deprimed");\r
+    }\r
+\r
+    @Override\r
+    public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,\r
+                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate, int stage)\r
+        throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),\r
+            instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");\r
+    }\r
+\r
+    @Override\r
+    public void migratePrecheck(CompositionElementDto compositionElement,\r
+            CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,\r
+            InstanceElementDto instanceElementMigrate) throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),\r
+                instanceElementMigrate.elementId(), DeployState.DEPLOYED, null,\r
+                StateChangeResult.NO_ERROR, "Migration Precheck completed");\r
+    }\r
+\r
+    @Override\r
+    public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement)\r
+            throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),\r
+                instanceElement.elementId(), DeployState.DEPLOYED, null,\r
+                StateChangeResult.NO_ERROR, "Review completed");\r
+    }\r
+\r
+    @Override\r
+    public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement)\r
+            throws PfModelException {\r
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),\r
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null,\r
+                StateChangeResult.NO_ERROR, "Prepare completed");\r
+    }\r
+}\r
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerV2.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerV2.java
new file mode 100644 (file)
index 0000000..721caa8
--- /dev/null
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
+
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
+import org.onap.policy.models.base.PfModelException;
+
+public interface AutomationCompositionElementListenerV2 {
+
+    void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException;
+
+    void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException;
+
+    void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException;
+
+    void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException;
+
+    void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException;
+
+    void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
+            InstanceElementDto instanceElementUpdated) throws PfModelException;
+
+    void prime(CompositionDto composition) throws PfModelException;
+
+    void deprime(CompositionDto composition) throws PfModelException;
+
+    void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
+            InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException;
+
+    void migratePrecheck(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
+            InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException;
+
+    void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+            throws PfModelException;
+
+    void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+            throws PfModelException;
+}
index 5cdbaca..e1bd064 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-2024 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -50,16 +50,22 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
     private final CacheProvider cacheProvider;
 
     @Override
-    public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState,
+    public void updateAutomationCompositionElementState(UUID instance, UUID elementId, DeployState deployState,
             LockState lockState, StateChangeResult stateChangeResult, String message) {
-        automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState,
-                lockState, stateChangeResult, message);
+        automationCompositionHandler.updateAutomationCompositionElementState(instance, elementId, deployState,
+            lockState, stateChangeResult, message);
     }
 
     @Override
-    public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState,
+    public void updateAutomationCompositionElementStage(UUID instance, UUID elementId,
+            StateChangeResult stateChangeResult, int stage, String message) {
+        //
+    }
+
+    @Override
+    public void sendAcElementInfo(UUID instance, UUID elementId, String useState,
             String operationalState, Map<String, Object> outProperties) {
-        automationCompositionHandler.sendAcElementInfo(automationCompositionId, elementId, useState, operationalState,
+        automationCompositionHandler.sendAcElementInfo(instance, elementId, useState, operationalState,
                 outProperties);
     }
 
@@ -75,8 +81,8 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
     }
 
     @Override
-    public AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId) {
-        var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
+    public AutomationCompositionElement getAutomationCompositionElement(UUID instanceId, UUID elementId) {
+        var automationComposition = cacheProvider.getAutomationCompositions().get(instanceId);
         if (automationComposition == null) {
             return null;
         }
@@ -91,8 +97,8 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
     }
 
     @Override
-    public AutomationComposition getAutomationComposition(UUID automationCompositionId) {
-        var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
+    public AutomationComposition getAutomationComposition(UUID instanceId) {
+        var automationComposition = cacheProvider.getAutomationCompositions().get(instanceId);
         return automationComposition != null ? new AutomationComposition(automationComposition) : null;
     }
 
@@ -107,7 +113,7 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
             UUID compositionId) {
         var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
         if (acElementDefinitions == null) {
-            return null;
+            return Map.of();
         }
         return PfUtils.mapMap(acElementDefinitions, AutomationCompositionElementDefinition::new);
     }
index e6c2d37..24b7f3a 100644 (file)
@@ -309,7 +309,7 @@ public class ThreadHandler implements Closeable {
         CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
         InstanceElementDto instanceElementMigrate) {
         try {
-            listener.migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
+            listener.migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate, 0);
         } catch (PfModelException e) {
             LOGGER.error("Automation composition element migrate failed {} {}",
                 instanceElement.elementId(), e.getMessage());
index e6a3091..12acdbb 100644 (file)
@@ -157,7 +157,7 @@ class AcElementListenerV1Test {
         var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
             Map.of(), Map.of());
         var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
-        acElementListenerV1.migrate(compositionElement, compositionElement, instanceElement, instanceElement);
+        acElementListenerV1.migrate(compositionElement, compositionElement, instanceElement, instanceElement, 0);
         verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
             instanceElement.elementId(), DeployState.DEPLOYED, null,
             StateChangeResult.NO_ERROR, "Migrated");
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java
new file mode 100644 (file)
index 0000000..1385f43
--- /dev/null
@@ -0,0 +1,180 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+  * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+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.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class AcElementListenerV3Test {
+
+    @Test
+    void lockTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+            Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV2.lock(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
+    }
+
+    @Test
+    void deleteTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+            Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV2.delete(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+    }
+
+    @Test
+    void updateTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+            Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV2.update(compositionElement, instanceElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.DEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Update not supported");
+    }
+
+    @Test
+    void unlockTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+            Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV2.unlock(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
+    }
+
+    @Test
+    void primeTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionId = UUID.randomUUID();
+        var toscaConceptIdentifier = new ToscaConceptIdentifier();
+        var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of());
+        acElementListenerV2.prime(composition);
+        verify(intermediaryApi)
+            .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+    }
+
+    @Test
+    void deprimeTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionId = UUID.randomUUID();
+        var toscaConceptIdentifier = new ToscaConceptIdentifier();
+        var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of());
+        acElementListenerV2.deprime(composition);
+        verify(intermediaryApi)
+            .updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
+    }
+
+    @Test
+    void migrateTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+            Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV2.migrate(compositionElement, compositionElement, instanceElement, instanceElement, 0);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.DEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Migrated");
+    }
+
+    @Test
+    void migratePrecheckTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV1 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV1.migratePrecheck(compositionElement, compositionElement, instanceElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.DEPLOYED, null,
+                StateChangeResult.NO_ERROR, "Migration Precheck completed");
+    }
+
+    @Test
+    void reviewTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV1 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV1.review(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.DEPLOYED, null,
+                StateChangeResult.NO_ERROR, "Review completed");
+    }
+
+    @Test
+    void prepareTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV1 = createAcElementListenerV3(intermediaryApi);
+        var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+                Map.of(), Map.of());
+        var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+        acElementListenerV1.prepare(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null,
+                StateChangeResult.NO_ERROR, "Prepare completed");
+    }
+
+    private AcElementListenerV3 createAcElementListenerV3(ParticipantIntermediaryApi intermediaryApi) {
+        return new AcElementListenerV3(intermediaryApi) {
+            @Override
+            public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+                // dummy implementation
+            }
+
+            @Override
+            public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+                // dummy implementation
+            }
+        };
+    }
+}
index 529ae7a..71af77f 100644 (file)
@@ -134,7 +134,7 @@ class ParticipantIntermediaryApiImplTest {
         assertEquals(map, mapResult);
 
         var result = apiImpl.getAcElementsDefinitions(UUID.randomUUID());
-        assertThat(result).isNull();
+        assertThat(result).isEmpty();
 
         result = apiImpl.getAcElementsDefinitions(COMPOSITION_ID);
         assertEquals(elementsDefinitions, result);
index 57b0659..90d011f 100644 (file)
@@ -119,7 +119,7 @@ class ThreadHandlerTest {
             threadHandler.migrate(messageId, compositionElement, compositionElementTarget,
                 instanceElement, instanceElementUpdated);
             verify(listener, timeout(TIMEOUT)).migrate(compositionElement, compositionElementTarget,
-                instanceElement, instanceElementUpdated);
+                instanceElement, instanceElementUpdated, 0);
 
             clearInvocations(listener);
             threadHandler.undeploy(messageId, compositionElement, instanceElement);
@@ -168,7 +168,7 @@ class ThreadHandlerTest {
             var compositionElementTarget = new CompositionElementDto(compositionTargetId, new ToscaConceptIdentifier(),
                 properties, properties);
             doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener)
-                .migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementUpdated);
+                .migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementUpdated, 0);
             threadHandler.migrate(messageId, compositionElement, compositionElementTarget,
                 instanceElement, instanceElementUpdated);
             verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,