Add support for Prepare, Review and Migrate pre-check in participant 53/138553/3
authorFrancescoFioraEst <francesco.fiora@est.tech>
Tue, 23 Jul 2024 11:45:09 +0000 (12:45 +0100)
committerFrancesco Fiora <francesco.fiora@est.tech>
Tue, 23 Jul 2024 15:16:00 +0000 (15:16 +0000)
Add support for Prepare, Review and Migrate pre-check
in ACM participant simulator.

Issue-ID: POLICY-5088
Change-Id: Ibad54aacc6102654f93a86169212d91ba3a59b8b
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
12 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/SimulatorService.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/model/SimConfig.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
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/impl/AcElementListenerV1.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.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/AcElementListenerV2Test.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java [deleted file]
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java [deleted file]

index aa9d90e..ef8db0e 100644 (file)
@@ -27,7 +27,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantInterme
 import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-import org.onap.policy.models.base.PfModelException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@@ -48,59 +47,56 @@ public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 {
     }
 
     @Override
-    public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
-            throws PfModelException {
+    public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) {
         LOGGER.debug("deploy call instanceId: {}, element: {}, properties: {}", instanceId, element, properties);
         simulatorService.deploy(instanceId, element.getId());
     }
 
     @Override
-    public void undeploy(UUID instanceId, UUID elementId) throws PfModelException {
+    public void undeploy(UUID instanceId, UUID elementId) {
         LOGGER.debug("undeploy call instanceId: {}, elementId: {}", instanceId, elementId);
         simulatorService.undeploy(instanceId, elementId);
     }
 
     @Override
-    public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+    public void lock(UUID instanceId, UUID elementId) {
         LOGGER.debug("lock call instanceId: {}, elementId: {}", instanceId, elementId);
         simulatorService.lock(instanceId, elementId);
     }
 
     @Override
-    public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+    public void unlock(UUID instanceId, UUID elementId) {
         LOGGER.debug("unlock call instanceId: {}, elementId: {}", instanceId, elementId);
         simulatorService.unlock(instanceId, elementId);
     }
 
     @Override
-    public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+    public void delete(UUID instanceId, UUID elementId) {
         LOGGER.debug("delete call instanceId: {}, elementId: {}", instanceId, elementId);
         simulatorService.delete(instanceId, elementId);
     }
 
     @Override
-    public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
-            throws PfModelException {
+    public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) {
         LOGGER.debug("update call instanceId: {}, element: {}, properties: {}", instanceId, element, properties);
         simulatorService.update(instanceId, element.getId());
     }
 
     @Override
-    public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
-            throws PfModelException {
+    public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) {
         LOGGER.debug("prime call compositionId: {}, elementDefinitionList: {}", compositionId, elementDefinitionList);
         simulatorService.prime(compositionId);
     }
 
     @Override
-    public void deprime(UUID compositionId) throws PfModelException {
+    public void deprime(UUID compositionId) {
         LOGGER.debug("deprime call compositionId: {}", compositionId);
         simulatorService.deprime(compositionId);
     }
 
     @Override
     public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId,
-        Map<String, Object> properties) throws PfModelException {
+        Map<String, Object> properties) {
         LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
                 instanceId, element, compositionTargetId, properties);
         simulatorService.migrate(instanceId, element.getId());
index eaad5d9..5f866eb 100644 (file)
@@ -53,11 +53,9 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
      *
      * @param compositionElement the information of the Automation Composition Definition Element
      * @param instanceElement the information of the Automation Composition Instance Element
-     * @throws PfModelException from Policy framework
      */
     @Override
-    public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-            throws PfModelException {
+    public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
         LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
         simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId());
     }
@@ -67,52 +65,47 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
      *
      * @param compositionElement the information of the Automation Composition Definition Element
      * @param instanceElement the information of the Automation Composition Instance Element
-     * @throws PfModelException from Policy framework
      */
     @Override
-    public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-            throws PfModelException {
+    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)
-            throws PfModelException {
+    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)
-            throws PfModelException {
+    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)
-            throws PfModelException {
+    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) throws PfModelException {
+                       InstanceElementDto instanceElementUpdated) {
         LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}",
                 compositionElement, instanceElement, instanceElementUpdated);
         simulatorService.update(instanceElement.instanceId(), instanceElement.elementId());
     }
 
     @Override
-    public void prime(CompositionDto composition) throws PfModelException {
+    public void prime(CompositionDto composition) {
         LOGGER.debug("prime call composition: {}", composition);
         simulatorService.prime(composition.compositionId());
     }
 
     @Override
-    public void deprime(CompositionDto composition) throws PfModelException {
+    public void deprime(CompositionDto composition) {
         LOGGER.debug("deprime call composition: {}", composition);
         simulatorService.deprime(composition.compositionId());
     }
@@ -126,4 +119,26 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
                 compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
         simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId());
     }
+
+    @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 d37edf7..e1e3ad4 100644 (file)
@@ -342,4 +342,67 @@ public class SimulatorService {
                     DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
         }
     }
+
+    /**
+     * Handle a Migrate Precheck on a automation composition element.
+     *
+     * @param instanceId the instanceId
+     * @param elementId the elementId
+     */
+    public void migratePrecheck(UUID instanceId, UUID elementId) {
+        if (!execution(config.getMigratePrecheckTimerMs(),
+                "Current Thread migrate precheck is Interrupted during execution {}", elementId)) {
+            return;
+        }
+
+        if (config.isMigratePrecheck()) {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migration precheck completed");
+        } else {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migration precheck failed");
+        }
+    }
+
+    /**
+     * Handle a Prepare on a automation composition element.
+     *
+     * @param instanceId the instanceId
+     * @param elementId the elementId
+     */
+    public void prepare(UUID instanceId, UUID elementId) {
+        if (!execution(config.getPrepareTimerMs(),
+                "Current Thread prepare is Interrupted during execution {}", elementId)) {
+            return;
+        }
+
+        if (config.isPrepare()) {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Prepare completed");
+        } else {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Prepare failed");
+        }
+    }
+
+    /**
+     * Handle a Review on a automation composition element.
+     *
+     * @param instanceId the instanceId
+     * @param elementId the elementId
+     */
+    public void review(UUID instanceId, UUID elementId) {
+        if (!execution(config.getReviewTimerMs(),
+                "Current Thread review is Interrupted during execution {}", elementId)) {
+            return;
+        }
+
+        if (config.isReview()) {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Review completed");
+        } else {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Review failed");
+        }
+    }
 }
index f4d4c6e..f38f307 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
+ *  Copyright (C) 2023-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.
@@ -38,6 +38,12 @@ public class SimConfig {
 
     private boolean migrateSuccess = true;
 
+    private boolean migratePrecheck = true;
+
+    private boolean prepare = true;
+
+    private boolean review = true;
+
     private boolean primeSuccess = true;
 
     private boolean deprimeSuccess = true;
@@ -54,6 +60,12 @@ public class SimConfig {
 
     private int migrateTimerMs = 100;
 
+    private int migratePrecheckTimerMs = 100;
+
+    private int prepareTimerMs = 100;
+
+    private int reviewTimerMs = 100;
+
     private int deleteTimerMs = 100;
 
     private int primeTimerMs = 100;
index 51e3906..1e2ec2c 100644 (file)
@@ -42,7 +42,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 class AutomationCompositionElementHandlerV2Test {
 
     @Test
-    void testDeploy() throws PfModelException {
+    void testDeploy() {
         var config = new SimConfig();
         config.setDeployTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -65,7 +65,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testUndeploy() throws PfModelException {
+    void testUndeploy() {
         var config = new SimConfig();
         config.setUndeployTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -88,7 +88,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testLock() throws PfModelException {
+    void testLock() {
         var config = new SimConfig();
         config.setLockTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -111,7 +111,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testUnlock() throws PfModelException {
+    void testUnlock() {
         var config = new SimConfig();
         config.setUnlockTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -134,7 +134,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testUpdate() throws PfModelException {
+    void testUpdate() {
         var config = new SimConfig();
         config.setUpdateTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -160,7 +160,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testDelete() throws PfModelException {
+    void testDelete() {
         var config = new SimConfig();
         config.setDeleteTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -183,7 +183,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testPrime() throws PfModelException {
+    void testPrime() {
         var config = new SimConfig();
         config.setPrimeTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -203,7 +203,7 @@ class AutomationCompositionElementHandlerV2Test {
     }
 
     @Test
-    void testDeprime() throws PfModelException {
+    void testDeprime() {
         var config = new SimConfig();
         config.setDeprimeTimerMs(1);
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -251,4 +251,82 @@ class AutomationCompositionElementHandlerV2Test {
         verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
                 DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
     }
+
+    @Test
+    void testMigratePrecheck() {
+        var config = new SimConfig();
+        config.setUpdateTimerMs(1);
+        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(),
+                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(),
+                null, Map.of("key", "value"), Map.of());
+        acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
+                instanceElement, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+                DeployState.DEPLOYED, null,
+                StateChangeResult.NO_ERROR, "Migration precheck completed");
+
+        config.setMigratePrecheck(false);
+        acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
+                instanceElement, instanceElementMigrated);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+                DeployState.DEPLOYED, null,
+                StateChangeResult.FAILED, "Migration precheck failed");
+    }
+
+    @Test
+    void testPrepare() {
+        var config = new SimConfig();
+        config.setDeployTimerMs(1);
+        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,
+                null, StateChangeResult.NO_ERROR, "Prepare completed");
+
+        config.setPrepare(false);
+        acElementHandler.prepare(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+                null, StateChangeResult.FAILED, "Prepare failed");
+    }
+
+    @Test
+    void testReview() {
+        var config = new SimConfig();
+        config.setDeployTimerMs(1);
+        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,
+                null, StateChangeResult.NO_ERROR, "Review completed");
+
+        config.setReview(false);
+        acElementHandler.review(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+                null, StateChangeResult.FAILED, "Review failed");
+    }
 }
index 6f40392..cbcd8dd 100644 (file)
@@ -97,4 +97,13 @@ public interface AutomationCompositionElementListener {
      */
     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 cf5ac41..6bc3f92 100644 (file)
@@ -224,4 +224,29 @@ public abstract class AcElementListenerV1
         intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(),
             DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
     }
+
+    @Override
+    public void migratePrecheck(CompositionElementDto compositionElement,
+        CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
+        InstanceElementDto instanceElementMigrate) throws PfModelException {
+        intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
+            instanceElementMigrate.elementId(), DeployState.DEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Migration Precheck completed");
+    }
+
+    @Override
+    public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+        throws PfModelException {
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.DEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Review completed");
+    }
+
+    @Override
+    public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+        throws PfModelException {
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.UNDEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Prepare completed");
+    }
 }
index 3fe3319..6e6f96e 100644 (file)
@@ -103,4 +103,29 @@ public abstract class AcElementListenerV2 implements AutomationCompositionElemen
         intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
             instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
     }
+
+    @Override
+    public void migratePrecheck(CompositionElementDto compositionElement,
+                                CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
+                                InstanceElementDto instanceElementMigrate) throws PfModelException {
+        intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
+            instanceElementMigrate.elementId(), DeployState.DEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Migration Precheck completed");
+    }
+
+    @Override
+    public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+        throws PfModelException {
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.DEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Review completed");
+    }
+
+    @Override
+    public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+        throws PfModelException {
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+            instanceElement.elementId(), DeployState.UNDEPLOYED, null,
+            StateChangeResult.NO_ERROR, "Prepare completed");
+    }
 }
index 7355b03..e6a3091 100644 (file)
@@ -163,17 +163,55 @@ class AcElementListenerV1Test {
             StateChangeResult.NO_ERROR, "Migrated");
     }
 
+    @Test
+    void migratePrecheckTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV1 = createAcElementListenerV1(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 = createAcElementListenerV1(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 = createAcElementListenerV1(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 AcElementListenerV1 createAcElementListenerV1(ParticipantIntermediaryApi intermediaryApi) {
         return new AcElementListenerV1(intermediaryApi) {
             @Override
-            public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
-                throws PfModelException {
-
+            public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) {
+                // dummy implementation
             }
 
             @Override
-            public void undeploy(UUID instanceId, UUID elementId) throws PfModelException {
-
+            public void undeploy(UUID instanceId, UUID elementId) {
+                // dummy implementation
             }
         };
     }
index c8ab9e2..be8275c 100644 (file)
@@ -140,16 +140,55 @@ class AcElementListenerV2Test {
             StateChangeResult.NO_ERROR, "Migrated");
     }
 
+    @Test
+    void migratePrecheckTest() throws PfModelException {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var acElementListenerV1 = createAcElementListenerV2(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 = createAcElementListenerV2(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 = createAcElementListenerV2(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 AcElementListenerV2 createAcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) {
         return new AcElementListenerV2(intermediaryApi) {
             @Override
-            public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-                throws PfModelException {
+            public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+                // dummy implementation
             }
 
             @Override
-            public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-                throws PfModelException {
+            public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+                // dummy implementation
             }
         };
     }
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java
deleted file mode 100644 (file)
index b01065d..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-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.assertj.core.api.Assertions.assertThatCode;
-
-import java.util.Map;
-import java.util.UUID;
-import org.junit.jupiter.api.Test;
-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.handler.DummyAcElementListener;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
-class AutomationCompositionElementListenerTest {
-
-    @Test
-    void defaultTest() {
-        var listener = new DummyAcElementListener();
-        var compositionElementDto = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
-            Map.of(), Map.of());
-        var instanceElementDto = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null,
-            Map.of(), Map.of());
-        assertThatCode(() -> listener.lock(compositionElementDto, instanceElementDto)).doesNotThrowAnyException();
-        assertThatCode(() -> listener.unlock(compositionElementDto, instanceElementDto)).doesNotThrowAnyException();
-    }
-}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java
deleted file mode 100644 (file)
index 173ed03..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-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.handler;
-
-import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
-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 class DummyAcElementListener implements AutomationCompositionElementListener {
-    @Override
-    public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-        throws PfModelException {
-
-    }
-
-    @Override
-    public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-        throws PfModelException {
-
-    }
-
-    @Override
-    public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-        throws PfModelException {
-
-    }
-
-    @Override
-    public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-        throws PfModelException {
-
-    }
-
-    @Override
-    public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
-        throws PfModelException {
-    }
-
-    @Override
-    public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
-                       InstanceElementDto instanceElementUpdated)
-            throws PfModelException {
-    }
-
-    @Override
-    public void prime(CompositionDto composition) throws PfModelException {
-    }
-
-    @Override
-    public void deprime(CompositionDto composition) throws PfModelException {
-    }
-
-    @Override
-    public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
-                        InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
-        throws PfModelException {
-    }
-}