From ea3e55a2f135f97ce2ccfb420ee9b2043b96c443 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Wed, 17 Sep 2025 09:13:48 +0100 Subject: [PATCH] Add migrationState to support add remove elements in migration Issue-ID: POLICY-5454 Change-Id: I6daf0921653781bd83d423be52b0b71416c81f1c Signed-off-by: FrancescoFioraEst --- .../clamp/models/acm/concepts/AcElementDeploy.java | 7 +++- .../acm/concepts/AutomationCompositionElement.java | 3 ++ .../clamp/models/acm/concepts/MigrationState.java | 27 ++++++++++++++ .../concepts/JpaAutomationCompositionElement.java | 41 ++++++++++------------ .../policy/clamp/models/acm/utils/AcmUtils.java | 1 + .../JpaAutomationCompositionElementTest.java | 39 ++++---------------- .../resources/db/changelog/changelog-1800.yaml | 14 ++++++++ 7 files changed, 75 insertions(+), 57 deletions(-) create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/MigrationState.java diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java index 7684fecf0..1ab8456fb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java @@ -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 + '}'; } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index d3c655be4..54ab13264 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -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 index 000000000..e1247234d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/MigrationState.java @@ -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 +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java index 2255aed5b..ab3a4c398 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -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; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index dfe213f22..c424bede3 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -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; } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java index 19937a4e1..2d63343ba 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java @@ -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"); diff --git a/runtime-acm/src/main/resources/db/changelog/changelog-1800.yaml b/runtime-acm/src/main/resources/db/changelog/changelog-1800.yaml index dc9891564..d2ae729cb 100644 --- a/runtime-acm/src/main/resources/db/changelog/changelog-1800.yaml +++ b/runtime-acm/src/main/resources/db/changelog/changelog-1800.yaml @@ -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 -- 2.16.6