From 54155ebf6232417d264159acf9fbfcdc08c11244 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 26 Sep 2023 14:31:58 +0100 Subject: Add migration message support Issue-ID: POLICY-4822 Change-Id: Ibde7c14424c63a96c64378d8897e8887935d6c79 Signed-off-by: FrancescoFioraEst --- .../models/acm/concepts/AutomationComposition.java | 3 + .../clamp/models/acm/concepts/DeployState.java | 3 +- .../AutomationCompositionMigration.java | 43 ++++++ .../dmaap/participant/ParticipantMessageType.java | 8 +- .../messages/rest/instantiation/DeployOrder.java | 3 +- .../concepts/JpaAutomationComposition.java | 22 ++- .../provider/AcInstanceStateResolver.java | 14 +- .../policy/clamp/models/acm/utils/AcmUtils.java | 76 +++++----- .../concepts/JpaAutomationCompositionTest.java | 160 +++++++++++---------- .../clamp/models/acm/utils/AcmUtilsTest.java | 17 ++- 10 files changed, 223 insertions(+), 126 deletions(-) mode change 100644 => 100755 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java mode change 100644 => 100755 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java create mode 100755 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionMigration.java mode change 100644 => 100755 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java mode change 100644 => 100755 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java mode change 100644 => 100755 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java mode change 100644 => 100755 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java mode change 100644 => 100755 models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java (limited to 'models') diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java old mode 100644 new mode 100755 index b92b03fba..0cf1f99ec --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -42,6 +42,8 @@ public class AutomationComposition extends ToscaEntity implements Comparable participantUpdatesList = new ArrayList<>(); + + public AutomationCompositionMigration() { + super(ParticipantMessageType.AUTOMATION_COMPOSITION_MIGRATION); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java old mode 100644 new mode 100755 index c42778aae..7609accee --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java @@ -104,5 +104,11 @@ public enum ParticipantMessageType { /** * Used by runtime to send composition and instances to a restarted participant. */ - PARTICIPANT_RESTART + PARTICIPANT_RESTART, + + /** + * Used by acm runtime to migrate from a composition to another one in participants, triggers a + * AUTOMATION_COMPOSITION_MIGRATION message with result of AUTOMATION_COMPOSITION_STATE_CHANGE operation. + */ + AUTOMATION_COMPOSITION_MIGRATION } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java old mode 100644 new mode 100755 index 24197f1ab..758a5057f --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java @@ -26,5 +26,6 @@ public enum DeployOrder { DEPLOY, DELETE, UPDATE, - RESTARTING + RESTARTING, + MIGRATE } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java index 104792143..5e27fde53 100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java @@ -80,6 +80,9 @@ public class JpaAutomationComposition extends Validated @NotNull private String compositionId; + @Column + private String compositionTargetId; + @Column private Boolean restarting; @@ -106,8 +109,8 @@ public class JpaAutomationComposition extends Validated * The Default Constructor creates a {@link JpaAutomationComposition} object with a null key. */ public JpaAutomationComposition() { - this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(), - new ArrayList<>(), DeployState.UNDEPLOYED, LockState.NONE); + this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(), new ArrayList<>(), + DeployState.UNDEPLOYED, LockState.NONE); } /** @@ -121,8 +124,7 @@ public class JpaAutomationComposition extends Validated * @param lockState the Lock State */ public JpaAutomationComposition(@NonNull final String instanceId, @NonNull final PfConceptKey key, - @NonNull final String compositionId, - @NonNull final List elements, + @NonNull final String compositionId, @NonNull final List elements, @NonNull final DeployState deployState, @NonNull final LockState lockState) { this.instanceId = instanceId; this.name = key.getName(); @@ -143,6 +145,7 @@ public class JpaAutomationComposition extends Validated this.name = copyConcept.name; this.version = copyConcept.version; this.compositionId = copyConcept.compositionId; + this.compositionTargetId = copyConcept.compositionTargetId; this.restarting = copyConcept.restarting; this.deployState = copyConcept.deployState; this.lockState = copyConcept.lockState; @@ -168,6 +171,9 @@ public class JpaAutomationComposition extends Validated automationComposition.setName(name); automationComposition.setVersion(version); automationComposition.setCompositionId(UUID.fromString(compositionId)); + if (compositionTargetId != null) { + automationComposition.setCompositionTargetId(UUID.fromString(compositionTargetId)); + } automationComposition.setRestarting(restarting); automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); @@ -187,6 +193,9 @@ public class JpaAutomationComposition extends Validated this.name = automationComposition.getName(); this.version = automationComposition.getVersion(); this.compositionId = automationComposition.getCompositionId().toString(); + if (automationComposition.getCompositionTargetId() != null) { + this.compositionTargetId = automationComposition.getCompositionTargetId().toString(); + } this.restarting = automationComposition.getRestarting(); this.deployState = automationComposition.getDeployState(); this.lockState = automationComposition.getLockState(); @@ -230,6 +239,11 @@ public class JpaAutomationComposition extends Validated return result; } + result = ObjectUtils.compare(compositionTargetId, other.compositionTargetId); + if (result != 0) { + return result; + } + result = ObjectUtils.compare(restarting, other.restarting); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java old mode 100644 new mode 100755 index e2f4fdf9b..7fed8a756 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java @@ -38,6 +38,7 @@ public class AcInstanceStateResolver { private static final String UNDEPLOYING = DeployState.UNDEPLOYING.name(); private static final String UPDATING = DeployState.UPDATING.name(); private static final String DELETING = DeployState.DELETING.name(); + private static final String MIGRATING = DeployState.MIGRATING.name(); private static final String LOCKED = LockState.LOCKED.name(); private static final String LOCKING = LockState.LOCKING.name(); @@ -58,6 +59,7 @@ public class AcInstanceStateResolver { public static final String DELETE = DeployOrder.DELETE.name(); public static final String LOCK = LockOrder.LOCK.name(); public static final String UNLOCK = LockOrder.UNLOCK.name(); + public static final String MIGRATE = DeployOrder.MIGRATE.name(); public static final String NONE = "NONE"; /** @@ -72,22 +74,24 @@ public class AcInstanceStateResolver { this.graph.put(new String[] {DELETE, LOCK_NONE, UNDEPLOYED, LOCK_NONE, NO_ERROR}, DELETE); this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED, NO_ERROR}, UNLOCK); this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED, NO_ERROR}, LOCK); + this.graph.put(new String[] {MIGRATE, LOCK_NONE, DEPLOYED, LOCKED, NO_ERROR}, MIGRATE); // failed this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); - this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); + + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, LOCKED, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, MIGRATING, LOCKED, FAILED}, UNDEPLOY); this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); this.graph.put(new String[] {DELETE, LOCK_NONE, DELETING, LOCK_NONE, FAILED}, DELETE); this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKING, FAILED}, UNLOCK); - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK); this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, FAILED}, LOCK); - this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK); // timeout this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, DEPLOY); 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 258c6dc93..fe44050d5 100755 --- 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 @@ -45,6 +45,7 @@ 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.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.parameters.BeanValidationResult; @@ -289,7 +290,8 @@ public final class AcmUtils { public static boolean isInTransitionalState(DeployState deployState, LockState lockState) { return DeployState.DEPLOYING.equals(deployState) || DeployState.UNDEPLOYING.equals(deployState) || LockState.LOCKING.equals(lockState) || LockState.UNLOCKING.equals(lockState) - || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState); + || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState) + || DeployState.MIGRATING.equals(deployState); } /** @@ -299,24 +301,12 @@ public final class AcmUtils { * @return the DeployOrder */ public static DeployOrder stateDeployToOrder(DeployState deployState) { - DeployOrder result = null; - switch (deployState) { - case DEPLOYING: - result = DeployOrder.DEPLOY; - break; - - case UNDEPLOYING: - result = DeployOrder.UNDEPLOY; - break; - - case DELETING: - result = DeployOrder.DELETE; - break; - - default: - result = DeployOrder.NONE; - } - return result; + return switch (deployState) { + case DEPLOYING -> DeployOrder.DEPLOY; + case UNDEPLOYING -> DeployOrder.UNDEPLOY; + case DELETING -> DeployOrder.DELETE; + default -> DeployOrder.NONE; + }; } /** @@ -341,24 +331,12 @@ public final class AcmUtils { * @return the DeployState */ public static DeployState deployCompleted(DeployState deployState) { - DeployState result = null; - switch (deployState) { - case UPDATING, DEPLOYING: - result = DeployState.DEPLOYED; - break; - - case UNDEPLOYING: - result = DeployState.UNDEPLOYED; - break; - - case DELETING: - result = DeployState.DELETED; - break; - - default: - return deployState; - } - return result; + return switch (deployState) { + case MIGRATING, UPDATING, DEPLOYING -> DeployState.DEPLOYED; + case UNDEPLOYING -> DeployState.UNDEPLOYED; + case DELETING -> DeployState.DELETED; + default -> deployState; + }; } /** @@ -426,6 +404,30 @@ public final class AcmUtils { return acElementDeploy; } + /** + * Create a list of AcElementDeploy for update/migrate message. + * + * @param automationComposition the AutomationComposition + * @param deployOrder the DeployOrder + */ + public static List createParticipantDeployList(AutomationComposition automationComposition, + DeployOrder deployOrder) { + Map> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + var acElementDeploy = createAcElementDeploy(element, deployOrder); + map.putIfAbsent(element.getParticipantId(), new ArrayList<>()); + map.get(element.getParticipantId()).add(acElementDeploy); + } + List participantDeploys = new ArrayList<>(); + for (var entry : map.entrySet()) { + var participantDeploy = new ParticipantDeploy(); + participantDeploy.setParticipantId(entry.getKey()); + participantDeploy.setAcElementList(entry.getValue()); + participantDeploys.add(participantDeploy); + } + return participantDeploys; + } + /** * Create a new AcElementRestart from an AutomationCompositionElement. * diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java old mode 100644 new mode 100755 index 04a874419..697b4e148 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java @@ -62,28 +62,28 @@ class JpaAutomationCompositionTest { }).hasMessageMatching(NULL_INSTANCE_ID_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, null, null, new ArrayList<>(), - DeployState.UNDEPLOYED, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, null, null, new ArrayList<>(), DeployState.UNDEPLOYED, + LockState.LOCKED); }).hasMessageMatching("key" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null, - new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null, new ArrayList<>(), + DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching("compositionId" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - null, DeployState.UNDEPLOYED, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), null, + DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching("elements" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - new ArrayList<>(), null, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), new ArrayList<>(), + null, LockState.LOCKED); }).hasMessageMatching("deployState" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - new ArrayList<>(), DeployState.UNDEPLOYED, null); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), new ArrayList<>(), + DeployState.UNDEPLOYED, null); }).hasMessageMatching("lockState" + NULL_TEXT_ERROR); assertNotNull(new JpaAutomationComposition()); @@ -93,29 +93,34 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationComposition() { - var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + var jpaAutomationComposition = createJpaAutomationCompositionInstance(); + + var automationComposition = createAutomationCompositionInstance(); + assertEquals(automationComposition, jpaAutomationComposition.toAuthorative()); - var participant = createAutomationCompositionInstance(); - assertEquals(participant, testJpaAutomationComposition.toAuthorative()); + var target = UUID.randomUUID(); + jpaAutomationComposition.setCompositionTargetId(target.toString()); + automationComposition.setCompositionTargetId(target); + assertEquals(automationComposition, jpaAutomationComposition.toAuthorative()); assertThatThrownBy(() -> { - testJpaAutomationComposition.fromAuthorative(null); + jpaAutomationComposition.fromAuthorative(null); }).hasMessageMatching("automationComposition is marked .*ull but is null"); assertThatThrownBy(() -> new JpaAutomationComposition((JpaAutomationComposition) null)) .isInstanceOf(NullPointerException.class); - var testJpaAutomationCompositionFa = new JpaAutomationComposition(); - testJpaAutomationCompositionFa.setInstanceId(null); - testJpaAutomationCompositionFa.fromAuthorative(participant); - assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + var jpaAutomationCompositionFa = new JpaAutomationComposition(); + jpaAutomationCompositionFa.setInstanceId(null); + jpaAutomationCompositionFa.fromAuthorative(automationComposition); + assertEquals(jpaAutomationComposition, jpaAutomationCompositionFa); - assertEquals("automation-composition", testJpaAutomationComposition.getName()); + assertEquals("automation-composition", jpaAutomationComposition.getName()); assertEquals("automation-composition", new JpaAutomationComposition(createAutomationCompositionInstance()).getName()); - var testJpaAutomationComposition2 = new JpaAutomationComposition(testJpaAutomationComposition); - assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2); + var jpaAutomationComposition2 = new JpaAutomationComposition(jpaAutomationComposition); + assertEquals(jpaAutomationComposition, jpaAutomationComposition2); } @Test @@ -130,60 +135,65 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationCompositionCompareTo() { - var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); - - var otherJpaAutomationComposition = new JpaAutomationComposition(testJpaAutomationComposition); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - assertEquals(-1, testJpaAutomationComposition.compareTo(null)); - assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition)); - assertNotEquals(0, testJpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild())); - - testJpaAutomationComposition.setInstanceId("BadValue"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setInstanceId(INSTANCE_ID); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setCompositionId(UUID.randomUUID().toString()); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setCompositionId(COMPOSITION_ID); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setName("BadValue"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setName("automation-composition"); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setVersion("0.0.0"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setVersion("0.0.1"); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setDeployState(DeployState.DEPLOYED); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setLockState(LockState.UNLOCKED); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setLockState(LockState.NONE); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setDescription("A description"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setDescription(null); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setRestarting(true); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setRestarting(null); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setStateChangeResult(null); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - assertEquals(testJpaAutomationComposition, new JpaAutomationComposition(testJpaAutomationComposition)); + var jpaAutomationComposition = createJpaAutomationCompositionInstance(); + + var otherJpaAutomationComposition = new JpaAutomationComposition(jpaAutomationComposition); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + assertEquals(-1, jpaAutomationComposition.compareTo(null)); + assertEquals(0, jpaAutomationComposition.compareTo(jpaAutomationComposition)); + assertNotEquals(0, jpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild())); + + jpaAutomationComposition.setInstanceId("BadValue"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setInstanceId(INSTANCE_ID); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setCompositionId(UUID.randomUUID().toString()); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setCompositionId(COMPOSITION_ID); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setCompositionTargetId(UUID.randomUUID().toString()); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setCompositionTargetId(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setName("BadValue"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setName("automation-composition"); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setVersion("0.0.0"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setVersion("0.0.1"); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setDeployState(DeployState.DEPLOYED); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setLockState(LockState.UNLOCKED); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setLockState(LockState.NONE); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setDescription("A description"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setDescription(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setRestarting(true); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setRestarting(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setStateChangeResult(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + assertEquals(jpaAutomationComposition, new JpaAutomationComposition(jpaAutomationComposition)); } @Test diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java old mode 100644 new mode 100755 index a9bd25f81..e0e5a2edc --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -68,6 +68,7 @@ class AcmUtilsTest { assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.UNLOCKING)).isTrue(); assertThat(AcmUtils.isInTransitionalState(DeployState.DELETING, LockState.NONE)).isTrue(); assertThat(AcmUtils.isInTransitionalState(DeployState.UPDATING, LockState.LOCKED)).isTrue(); + assertThat(AcmUtils.isInTransitionalState(DeployState.MIGRATING, LockState.LOCKED)).isTrue(); } @Test @@ -194,6 +195,18 @@ class AcmUtilsTest { assertEquals(element.getDefinition(), result.getDefinition()); } + @Test + void testCreateAcElementDeployList() { + var automationComposition = getDummyAutomationComposition(); + var result = AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.DEPLOY); + assertThat(result).hasSameSizeAs(automationComposition.getElements().values()); + for (var participantDeploy : result) { + for (var element : participantDeploy.getAcElementList()) { + assertEquals(DeployOrder.DEPLOY, element.getOrderedState()); + } + } + } + @Test void testCreateAcElementRestart() { var element = getDummyAutomationComposition().getElements().values().iterator().next(); @@ -210,8 +223,8 @@ class AcmUtilsTest { Map map = new LinkedHashMap<>(); try { var element = new StandardCoder().decode( - new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), - AutomationCompositionElement.class); + new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), + AutomationCompositionElement.class); map.put(UUID.randomUUID(), element); } catch (Exception e) { fail("Cannot read or decode " + e.getMessage()); -- cgit 1.2.3-korg