Support stage in Prepare event in ACM model 95/140695/2
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 5 Feb 2025 09:55:31 +0000 (09:55 +0000)
committerFrancesco Fiora <francesco.fiora@est.tech>
Tue, 15 Apr 2025 09:13:55 +0000 (09:13 +0000)
Issue-ID: POLICY-5263
Change-Id: Ifdf08cfd552ece43515d8ba2e9893ea9d4e98f60
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java
models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionPrepare.java
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java
models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionPrepareTest.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-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/scanner/StageScanner.java

index 12c21f5..5cb5d3f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,6 +31,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class ParticipantUtils {
+    private static final String STAGE_MIGRATE = "migrate";
+    private static final String STAGE_PREPARE = "prepare";
+
     /**
      * Get the First StartPhase.
      *
@@ -66,13 +69,15 @@ public final class ParticipantUtils {
      * @param toscaServiceTemplate the ToscaServiceTemplate
      * @return the First stage
      */
-    public static int getFirstStage(
-        AutomationComposition automationComposition, ToscaServiceTemplate toscaServiceTemplate) {
+    public static int getFirstStage(AutomationComposition automationComposition,
+            ToscaServiceTemplate toscaServiceTemplate) {
         Set<Integer> minStage = new HashSet<>();
         for (var element : automationComposition.getElements().values()) {
             var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
                 .get(element.getDefinition().getName());
-            var stage = ParticipantUtils.findStageSet(toscaNodeTemplate.getProperties());
+            var stage = DeployState.MIGRATING.equals(automationComposition.getDeployState())
+                    ? ParticipantUtils.findStageSetMigrate(toscaNodeTemplate.getProperties())
+                    : ParticipantUtils.findStageSetPrepare(toscaNodeTemplate.getProperties());
             minStage.addAll(stage);
         }
         return minStage.stream().min(Integer::compare).orElse(0);
@@ -92,19 +97,40 @@ public final class ParticipantUtils {
         return 0;
     }
 
+    /**
+     * Finds stage from a map of properties for Prepare.
+     *
+     * @param properties Map of properties
+     * @return stage
+     */
+    public static Set<Integer> findStageSetPrepare(Map<String, Object> properties) {
+        var objStage = properties.get("stage");
+        if (objStage instanceof Map<?, ?>) {
+            objStage = ((Map<?, ?>) objStage).get(STAGE_PREPARE);
+            return findStageSet(objStage);
+        }
+        return Set.of(0);
+    }
 
     /**
-     * Finds stage from a map of properties.
+     * Finds stage from a map of properties for Migrate.
      *
      * @param properties Map of properties
      * @return stage
      */
-    public static Set<Integer> findStageSet(Map<String, Object> properties) {
+    public static Set<Integer> findStageSetMigrate(Map<String, Object> properties) {
         var objStage = properties.get("stage");
+        if (objStage instanceof Map<?, ?>) {
+            objStage = ((Map<?, ?>) objStage).get(STAGE_MIGRATE);
+        }
+        return findStageSet(objStage);
+    }
+
+    private static Set<Integer> findStageSet(Object objStage) {
         if (objStage instanceof List<?> stageSet) {
             return stageSet.stream()
-                .map(obj -> Integer.valueOf(obj.toString()))
-                .collect(Collectors.toSet());
+                    .map(obj -> Integer.valueOf(obj.toString()))
+                    .collect(Collectors.toSet());
         }
         return Set.of(0);
     }
index 343143e..3a78ad5 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ public class AutomationCompositionPrepare extends ParticipantMessage {
 
     private List<ParticipantDeploy> participantList = new ArrayList<>();
     private boolean preDeploy = true;
+    private Integer stage = 0;
 
     /**
      * Constructor for instantiating class with message name.
@@ -52,6 +53,7 @@ public class AutomationCompositionPrepare extends ParticipantMessage {
     public AutomationCompositionPrepare(AutomationCompositionPrepare source) {
         super(source);
         this.preDeploy = source.preDeploy;
+        this.stage = source.stage;
         this.participantList = PfUtils.mapList(source.participantList, ParticipantDeploy::new);
     }
 }
index 09f1b09..27c0d40 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2024 Nordix Foundation.
+ *  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,6 +43,8 @@ public class AcInstanceStateResolver {
     private static final String MIGRATING = DeployState.MIGRATING.name();
     private static final String MIGRATION_PRECHECKING = SubState.MIGRATION_PRECHECKING.name();
     private static final String SUB_STATE_NONE = SubState.NONE.name();
+    private static final String PREPARING = SubState.PREPARING.name();
+    private static final String REVIEWING = SubState.REVIEWING.name();
 
     private static final String LOCKED = LockState.LOCKED.name();
     private static final String LOCKING = LockState.LOCKING.name();
@@ -78,98 +80,95 @@ public class AcInstanceStateResolver {
         this.graph = new StateDefinition<>(7, NONE);
 
         // make an order when there are no fails
-        this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE,
-            UNDEPLOYED, STATE_LOCKED_NONE, SUB_STATE_NONE, NO_ERROR}, DEPLOY);
-        this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
-            DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UNDEPLOY);
-        this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE,
-            UNDEPLOYED, LOCK_NONE, SUB_STATE_NONE, NO_ERROR}, DELETE);
-        this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
-            DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UNLOCK);
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE,
-            DEPLOYED, UNLOCKED, SUB_STATE_NONE, NO_ERROR}, LOCK);
-        this.graph.put(new String[] {MIGRATE, LOCK_NONE, SUB_NONE,
-            DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, MIGRATE);
-        this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE,
-            DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UPDATE);
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, REVIEW,
-            DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, REVIEW);
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, PREPARE,
-            UNDEPLOYED, STATE_LOCKED_NONE, SUB_STATE_NONE, NO_ERROR}, PREPARE);
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK,
-            DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, MIGRATE_PRECHECK);
-
-        // make an order in a failed scenario
+        addDeployOrder(DEPLOY, UNDEPLOYED, STATE_LOCKED_NONE);
+        addDeployOrder(UNDEPLOY, DEPLOYED, LOCKED);
+        addDeployOrder(DELETE, UNDEPLOYED, STATE_LOCKED_NONE);
+        addDeployOrder(MIGRATE, DEPLOYED, LOCKED);
+        addDeployOrder(UPDATE, DEPLOYED, LOCKED);
+
+        addLockOrder(UNLOCK, LOCKED);
+        addLockOrder(LOCK, UNLOCKED);
+
+        addSubOrder(REVIEW, DEPLOYED, LOCKED);
+        addSubOrder(PREPARE, UNDEPLOYED, STATE_LOCKED_NONE);
+        addSubOrder(MIGRATE_PRECHECK, DEPLOYED, LOCKED);
+
+        // failed or timeout scenario
         setAllowed(DEPLOY);
         setAllowed(UNDEPLOY);
-        this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
-            UPDATING, LOCKED, SUB_STATE_NONE, FAILED}, UNDEPLOY);
-        this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
-            MIGRATING, LOCKED, SUB_STATE_NONE, FAILED}, UNDEPLOY);
 
-        this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE,
-            DELETING, LOCK_NONE, SUB_STATE_NONE, FAILED}, DELETE);
+        // undeploy order in a failed or timeout scenario
+        addDeployOrderWithFail(UNDEPLOY, UPDATING, LOCKED, SUB_STATE_NONE);
+        addDeployOrderWithFail(UNDEPLOY, MIGRATING, LOCKED, SUB_STATE_NONE);
+        addDeployOrderWithFail(UNDEPLOY, MIGRATION_PRECHECKING, LOCKED, SUB_STATE_NONE);
+        addDeployOrderWithFail(UNDEPLOY, REVIEWING, LOCKED, SUB_STATE_NONE);
+
+        // delete order in a failed or timeout scenario
+        addDeployOrderWithFail(DELETE, DELETING, LOCK_NONE, SUB_STATE_NONE);
+        addDeployOrderWithFail(DELETE, UNDEPLOYED, LOCK_NONE, PREPARING);
+
+        // update order in a failed or timeout scenario
+        addDeployOrderWithFail(UPDATE, UPDATING, LOCKED, SUB_STATE_NONE);
+
+        // unlock order in a failed or timeout scenario
+        addLockOrderWithFail(UNLOCK, LOCKING);
+        addLockOrderWithFail(UNLOCK, UNLOCKING);
 
-        this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
-            DEPLOYED, LOCKING, SUB_STATE_NONE, FAILED}, UNLOCK);
-        this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
-            DEPLOYED, UNLOCKING, SUB_STATE_NONE, FAILED}, UNLOCK);
+        // lock order in a failed or timeout scenario
+        addLockOrderWithFail(LOCK, LOCKING);
+        addLockOrderWithFail(LOCK, UNLOCKING);
 
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, DEPLOYED, LOCKING, SUB_STATE_NONE, FAILED}, LOCK);
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, DEPLOYED, UNLOCKING, SUB_STATE_NONE, FAILED}, LOCK);
+        // migrate-precheck order in a failed or timeout scenario
+        addSubOrderWithFail(MIGRATE_PRECHECK, DEPLOYED, LOCKED, MIGRATION_PRECHECKING);
 
-        this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, UPDATING, LOCKED, SUB_STATE_NONE, FAILED}, UPDATE);
+        // prepare order in a failed or timeout scenario
+        addSubOrderWithFail(PREPARE, UNDEPLOYED, LOCK_NONE, PREPARING);
 
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK,
-            DEPLOYED, LOCKED, MIGRATION_PRECHECKING, FAILED}, MIGRATE_PRECHECK);
+        // review order in a failed or timeout scenario
+        addSubOrderWithFail(REVIEW, DEPLOYED, LOCKED, REVIEWING);
+    }
 
-        // timeout
-        this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
-            UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
-        this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
-            MIGRATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
-        this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
-            MIGRATION_PRECHECKING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+    private void addDeployOrder(String deployOrder, String deployState, String lockState) {
+        this.graph.put(new String[] {
+            deployOrder, LOCK_NONE, SUB_NONE, deployState, lockState, STATE_LOCKED_NONE, NO_ERROR}, deployOrder);
+    }
 
-        this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE,
-            DELETING, LOCK_NONE, SUB_STATE_NONE, TIMEOUT}, DELETE);
+    private void addDeployOrderWithFail(String deployOrder, String deployState, String lockState, String subState) {
+        this.graph.put(new String[] {
+            deployOrder, LOCK_NONE, SUB_NONE, deployState, lockState, subState, FAILED}, deployOrder);
+        this.graph.put(new String[] {
+            deployOrder, LOCK_NONE, SUB_NONE, deployState, lockState, subState, TIMEOUT}, deployOrder);
+    }
 
-        this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
-            DEPLOYED, LOCKING, SUB_STATE_NONE, TIMEOUT}, UNLOCK);
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE,
-            DEPLOYED, LOCKING, SUB_STATE_NONE, TIMEOUT}, LOCK);
+    private void addSubOrder(String subOrder, String deployState, String lockState) {
+        this.graph.put(new String[] {
+            DEPLOY_NONE, LOCK_NONE, subOrder, deployState, lockState, SUB_STATE_NONE, NO_ERROR}, subOrder);
+    }
 
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE,
-            DEPLOYED, UNLOCKING, SUB_STATE_NONE, TIMEOUT}, LOCK);
-        this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
-            DEPLOYED, UNLOCKING, SUB_STATE_NONE, TIMEOUT}, UNLOCK);
+    private void addSubOrderWithFail(String subOrder, String deployState, String lockState, String subState) {
+        this.graph.put(new String[] {
+            DEPLOY_NONE, LOCK_NONE, subOrder, deployState, lockState, subState, FAILED}, subOrder);
+        this.graph.put(new String[] {
+            DEPLOY_NONE, LOCK_NONE, subOrder, deployState, lockState, subState, TIMEOUT}, subOrder);
+    }
 
-        this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UPDATE);
+    private void addLockOrder(String lockOrder, String lockState) {
+        this.graph.put(new String[] {
+            DEPLOY_NONE, lockOrder, SUB_NONE, DEPLOYED, lockState, SUB_STATE_NONE, NO_ERROR}, lockOrder);
+    }
 
-        this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK,
-            DEPLOYED, LOCKED, MIGRATION_PRECHECKING, TIMEOUT}, MIGRATE_PRECHECK);
+    private void addLockOrderWithFail(String lockOrder, String lockState) {
+        this.graph.put(new String[] {
+            DEPLOY_NONE, lockOrder, SUB_NONE, DEPLOYED, lockState, SUB_STATE_NONE, FAILED}, lockOrder);
+        this.graph.put(new String[] {
+            DEPLOY_NONE, lockOrder, SUB_NONE, DEPLOYED, lockState, SUB_STATE_NONE, TIMEOUT}, lockOrder);
     }
 
     private void setAllowed(String deployOrder) {
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, deployOrder);
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            UNDEPLOYING, LOCKED, SUB_STATE_NONE, FAILED}, deployOrder);
-
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, deployOrder);
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            UNDEPLOYING, LOCKED, SUB_STATE_NONE, TIMEOUT}, deployOrder);
-
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, deployOrder);
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            DEPLOYING, LOCKED, SUB_STATE_NONE, FAILED}, deployOrder);
-
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, deployOrder);
-        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
-            DEPLOYING, LOCKED, SUB_STATE_NONE, TIMEOUT}, deployOrder);
+        addDeployOrderWithFail(deployOrder, UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE);
+        addDeployOrderWithFail(deployOrder, UNDEPLOYING, LOCKED, SUB_STATE_NONE);
+        addDeployOrderWithFail(deployOrder, DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE);
+        addDeployOrderWithFail(deployOrder, DEPLOYING, LOCKED, SUB_STATE_NONE);
     }
 
     /**
index 9a8316c..3f692b5 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-2023,2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -37,6 +37,13 @@ class ParticipantUtilsTest {
     private static final String AUTOMATION_COMPOSITION_JSON =
         "src/test/resources/providers/TestAutomationCompositions.json";
 
+    private static final String PROPERTIES = """
+            stage:
+              prepare: [1,2]
+              migrate: [2,3]
+            """;
+
+
     @Test
     void testFindStartPhase() {
         var identifier = 13;
@@ -108,10 +115,40 @@ class ParticipantUtilsTest {
     @Test
     void testGetFirstStage() throws CoderException {
         var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
-        var automationCompositions =
-            CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class);
-        var result = ParticipantUtils.getFirstStage(automationCompositions.getAutomationCompositionList().get(0),
-            serviceTemplate);
+        var automationComposition =
+            CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class)
+                    .getAutomationCompositionList().get(0);
+        automationComposition.setDeployState(DeployState.MIGRATING);
+        var result = ParticipantUtils.getFirstStage(automationComposition, serviceTemplate);
+        assertThat(result).isZero();
+
+        automationComposition.setDeployState(DeployState.UNDEPLOYED);
+        automationComposition.setSubState(SubState.PREPARING);
+        result = ParticipantUtils.getFirstStage(automationComposition, serviceTemplate);
         assertThat(result).isZero();
     }
+
+    @Test
+    void testFindStageSetPrepare() {
+        var result = ParticipantUtils.findStageSetPrepare(Map.of());
+        assertThat(result).hasSize(1).contains(0);
+        result = ParticipantUtils.findStageSetPrepare(Map.of("stage", 1));
+        assertThat(result).hasSize(1).contains(0);
+
+        Map<String, Object> map = CommonTestData.getObject(PROPERTIES, Map.class);
+        result = ParticipantUtils.findStageSetPrepare(map);
+        assertThat(result).hasSize(2).contains(1).contains(2);
+    }
+
+    @Test
+    void testFindStageSetMigrate() {
+        var result = ParticipantUtils.findStageSetMigrate(Map.of());
+        assertThat(result).hasSize(1).contains(0);
+        result = ParticipantUtils.findStageSetMigrate(Map.of("stage", 1));
+        assertThat(result).hasSize(1).contains(0);
+
+        Map<String, Object> map = CommonTestData.getObject(PROPERTIES, Map.class);
+        result = ParticipantUtils.findStageSetMigrate(map);
+        assertThat(result).hasSize(2).contains(2).contains(3);
+    }
 }
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionPrepareTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionPrepareTest.java
new file mode 100644 (file)
index 0000000..82c8ff0
--- /dev/null
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
+ * ================================================================================
+ * 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.models.acm.messages.kafka.participant;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializable;
+import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.util.List;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
+import org.onap.policy.common.utils.coder.CoderException;
+
+class AutomationCompositionPrepareTest {
+
+    @Test
+    void testCopyConstructor() throws CoderException {
+        var orig = new AutomationCompositionPrepare();
+        orig.setCompositionId(UUID.randomUUID());
+        orig.setAutomationCompositionId(UUID.randomUUID());
+        orig.setStage(0);
+        orig.setParticipantId(null);
+        orig.setPreDeploy(false);
+        orig.setParticipantList(List.of(new ParticipantDeploy()));
+        var other = new AutomationCompositionPrepare(orig);
+
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
+        assertSerializable(orig, AutomationCompositionPrepare.class);
+    }
+}
index b1bbb69..b689a78 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2024-2025 Nordix Foundation.
+ *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -367,7 +367,7 @@ public class SimulatorService {
         }
 
         if (config.isMigrateSuccess()) {
-            var stageSet = ParticipantUtils.findStageSet(compositionInProperties);
+            var stageSet = ParticipantUtils.findStageSetMigrate(compositionInProperties);
             var nextStage = 1000;
             for (var s : stageSet) {
                 if (s > stage) {
index 7388887..920f39f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -192,7 +192,7 @@ public class AutomationCompositionHandler {
         for (var element : participantDeploy.getAcElementList()) {
             var compositionInProperties =
                     cacheProvider.getCommonProperties(compositionTargetId, element.getDefinition());
-            var stageSet = ParticipantUtils.findStageSet(compositionInProperties);
+            var stageSet = ParticipantUtils.findStageSetMigrate(compositionInProperties);
             if (stageSet.contains(stage)) {
                 var acElement = acElementList.get(element.getId());
                 if (acElement == null) {
@@ -326,7 +326,7 @@ public class AutomationCompositionHandler {
         for (var acElement : acElements) {
             var compositionInProperties = cacheProvider
                     .getCommonProperties(compositionTargetId, acElement.getDefinition());
-            var stageSet = ParticipantUtils.findStageSet(compositionInProperties);
+            var stageSet = ParticipantUtils.findStageSetMigrate(compositionInProperties);
             if (stageSet.contains(stage)) {
                 if (instanceElementMap.get(acElement.getId()) == null) {
                     var compositionElementDto =
index 7893032..f05df6b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2025 Nordix Foundation.
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class StageScanner extends AbstractScanner {
                     element.getSubState())) {
                 var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
                         .get(element.getDefinition().getName());
-                var stageSet = ParticipantUtils.findStageSet(toscaNodeTemplate.getProperties());
+                var stageSet = ParticipantUtils.findStageSetMigrate(toscaNodeTemplate.getProperties());
                 var minStage = stageSet.stream().min(Comparator.comparing(Integer::valueOf)).orElse(0);
                 int stage = element.getStage() != null ? element.getStage() : minStage;
                 minStageNotCompleted = Math.min(minStageNotCompleted, stage);