Add migrationState to support add remove elements in migration 59/142059/3 master
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 17 Sep 2025 08:13:48 +0000 (09:13 +0100)
committerFrancesco Fiora <francesco.fiora@est.tech>
Wed, 17 Sep 2025 14:53:48 +0000 (14:53 +0000)
Issue-ID: POLICY-5454
Change-Id: I6daf0921653781bd83d423be52b0b71416c81f1c
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/MigrationState.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
runtime-acm/src/main/resources/db/changelog/changelog-1800.yaml

index 7684fec..1ab8456 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2023-2025 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.
@@ -49,6 +49,9 @@ public class AcElementDeploy {
     @NonNull
     private DeployOrder orderedState = DeployOrder.DEPLOY;
 
+    @NonNull
+    private MigrationState migrationState = MigrationState.DEFAULT;
+
     // backward compatibility
     private ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
 
@@ -67,6 +70,7 @@ public class AcElementDeploy {
         this.orderedState = otherElement.orderedState;
         this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
         this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
+        this.migrationState = otherElement.migrationState;
     }
 
     @Override
@@ -76,6 +80,7 @@ public class AcElementDeploy {
                 + "id=" + id
                 + ", definition=" + definition
                 + ", orderedState=" + orderedState
+                + ", migrationState=" + migrationState
                 + ", toscaServiceTemplateFragment="
                 + toscaServiceTemplateFragment + '}';
     }
index d3c655b..54ab132 100644 (file)
@@ -56,6 +56,8 @@ public class AutomationCompositionElement {
     @NonNull
     private SubState subState = SubState.NONE;
 
+    private MigrationState migrationState = MigrationState.DEFAULT;
+
     private Integer stage;
 
     private String operationalState;
@@ -88,5 +90,6 @@ public class AutomationCompositionElement {
         this.useState = otherElement.useState;
         this.stage = otherElement.stage;
         this.message = otherElement.message;
+        this.migrationState = otherElement.migrationState;
     }
 }
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/MigrationState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/MigrationState.java
new file mode 100644 (file)
index 0000000..e124723
--- /dev/null
@@ -0,0 +1,27 @@
+/*-
+ * ============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.concepts;
+
+public enum MigrationState {
+    DEFAULT,
+    REMOVED,
+    NEW
+}
index 2255aed..ab3a4c3 100644 (file)
@@ -30,7 +30,6 @@ import jakarta.persistence.Id;
 import jakarta.persistence.Inheritance;
 import jakarta.persistence.InheritanceType;
 import jakarta.persistence.Table;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.UUID;
 import java.util.function.UnaryOperator;
@@ -41,6 +40,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
 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.MigrationState;
 import org.onap.policy.clamp.models.acm.concepts.SubState;
 import org.onap.policy.common.parameters.annotations.NotNull;
 import org.onap.policy.common.parameters.annotations.Valid;
@@ -94,6 +94,10 @@ public class JpaAutomationCompositionElement extends Validated
     @NotNull
     private SubState subState;
 
+    @Column
+    @NotNull
+    private MigrationState migrationState;
+
     @Column
     private String operationalState;
 
@@ -135,30 +139,13 @@ public class JpaAutomationCompositionElement extends Validated
      * @param instanceId The id of the automation composition instance
      */
     public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
-        this(elementId, instanceId, new PfConceptKey(),
-            DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE);
-    }
-
-    /**
-     * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
-     *
-     * @param elementId The id of the automation composition instance Element
-     * @param instanceId The id of the automation composition instance
-     * @param definition the TOSCA definition of the automation composition element
-     * @param deployState the Deploy State of the automation composition
-     * @param lockState the Lock State of the automation composition
-     * @param subState the Sub State of the automation composition
-     */
-    public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
-            @NonNull final PfConceptKey definition,
-            @NonNull final DeployState deployState, @NonNull final LockState lockState,
-            @NonNull final SubState subState) {
         this.elementId = elementId;
         this.instanceId = instanceId;
-        this.definition = definition;
-        this.deployState = deployState;
-        this.lockState = lockState;
-        this.subState = subState;
+        this.definition = new PfConceptKey();
+        this.deployState = DeployState.UNDEPLOYED;
+        this.lockState = LockState.NONE;
+        this.subState = SubState.NONE;
+        this.migrationState = MigrationState.DEFAULT;
     }
 
     /**
@@ -177,6 +164,7 @@ public class JpaAutomationCompositionElement extends Validated
         this.deployState = copyConcept.deployState;
         this.lockState = copyConcept.lockState;
         this.subState = copyConcept.subState;
+        this.migrationState = copyConcept.migrationState;
         this.operationalState = copyConcept.operationalState;
         this.useState = copyConcept.useState;
         this.stage = copyConcept.stage;
@@ -205,6 +193,7 @@ public class JpaAutomationCompositionElement extends Validated
         element.setDeployState(deployState);
         element.setLockState(lockState);
         element.setSubState(subState);
+        element.setMigrationState(migrationState);
         element.setOperationalState(operationalState);
         element.setUseState(useState);
         element.setStage(stage);
@@ -223,6 +212,7 @@ public class JpaAutomationCompositionElement extends Validated
         this.deployState = element.getDeployState();
         this.lockState = element.getLockState();
         this.subState = element.getSubState();
+        this.migrationState = element.getMigrationState();
         this.operationalState = element.getOperationalState();
         this.useState = element.getUseState();
         this.stage = element.getStage();
@@ -273,6 +263,11 @@ public class JpaAutomationCompositionElement extends Validated
             return result;
         }
 
+        result = ObjectUtils.compare(migrationState, other.migrationState);
+        if (result != 0) {
+            return result;
+        }
+
         result = ObjectUtils.compare(useState, other.useState);
         if (result != 0) {
             return result;
index dfe213f..c424bed 100644 (file)
@@ -423,6 +423,7 @@ public final class AcmUtils {
         acElementDeploy.setId(element.getId());
         acElementDeploy.setDefinition(new ToscaConceptIdentifier(element.getDefinition()));
         acElementDeploy.setOrderedState(deployOrder);
+        acElementDeploy.setMigrationState(element.getMigrationState());
         acElementDeploy.setProperties(PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()));
         return acElementDeploy;
     }
index 19937a4..2d63343 100644 (file)
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
 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.MigrationState;
 import org.onap.policy.clamp.models.acm.concepts.SubState;
 import org.onap.policy.clamp.models.acm.utils.CommonTestData;
 import org.onap.policy.models.base.PfConceptKey;
@@ -51,8 +52,6 @@ class JpaAutomationCompositionElementTest {
     private static final String KEY = "key";
     private static final String BAD_VALUE = "BadValue";
 
-    private static final PfConceptKey CONCEPT_KEY = new PfConceptKey();
-
     @Test
     void testJpaAutomationCompositionElementConstructor() {
         assertThatThrownBy(() -> {
@@ -75,39 +74,8 @@ class JpaAutomationCompositionElementTest {
             new JpaAutomationCompositionElement(null, null);
         }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
 
-        assertThatThrownBy(() -> {
-            new JpaAutomationCompositionElement(null, null, null, null, null, null);
-        }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
-
-        assertThatThrownBy(() -> {
-            new JpaAutomationCompositionElement(KEY, null, null,
-                DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE);
-        }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
-
-        assertThatThrownBy(() -> {
-            new JpaAutomationCompositionElement(KEY, KEY, null,
-                DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE);
-        }).hasMessageMatching("definition" + NULL_ERROR);
-
-        assertThatThrownBy(() -> {
-            new JpaAutomationCompositionElement(KEY, KEY, CONCEPT_KEY,
-                    null, LockState.LOCKED, SubState.NONE);
-        }).hasMessageMatching("deployState" + NULL_ERROR);
-
-        assertThatThrownBy(() -> {
-            new JpaAutomationCompositionElement(KEY, KEY, CONCEPT_KEY,
-                DeployState.UNDEPLOYED, null, SubState.NONE);
-        }).hasMessageMatching("lockState" + NULL_ERROR);
-
-        assertThatThrownBy(() -> {
-            new JpaAutomationCompositionElement(KEY, KEY, CONCEPT_KEY,
-                    DeployState.UNDEPLOYED, LockState.NONE, null);
-        }).hasMessageMatching("subState" + NULL_ERROR);
-
         assertDoesNotThrow(() -> new JpaAutomationCompositionElement());
         assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY));
-        assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY,
-            new PfConceptKey(), DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE));
     }
 
     @Test
@@ -207,6 +175,11 @@ class JpaAutomationCompositionElementTest {
         testJpaAcElement.setSubState(SubState.NONE);
         assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
 
+        testJpaAcElement.setMigrationState(MigrationState.REMOVED);
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setMigrationState(MigrationState.DEFAULT);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
         testJpaAcElement.setUseState(BAD_VALUE);
         assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
         testJpaAcElement.setUseState("IDLE");
index dc98915..d2ae729 100644 (file)
@@ -34,3 +34,17 @@ databaseChangeLog:
         - dropColumn:
             tableName: NodeTemplateState
             columnName: restarting
+
+  - changeSet:
+      author: policy
+      id: 1800-3
+      changes:
+        - addColumn:
+            tableName: AutomationCompositionElement
+            columns:
+              - column:
+                  name: migrationState
+                  type: SMALLINT
+                  defaultValue: 0
+                  constraints:
+                    nullable: false