diff options
11 files changed, 173 insertions, 205 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java index 1694b257b..64102e607 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java @@ -64,5 +64,6 @@ public class AutomationCompositionStateChange extends ParticipantMessage { this.deployOrderedState = source.deployOrderedState; this.lockOrderedState = source.lockOrderedState; this.startPhase = source.startPhase; + this.firstStartPhase = source.firstStartPhase; } } 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 2aacc74b6..33ec649f4 100644 --- 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 @@ -41,8 +41,6 @@ import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.common.parameters.annotations.NotNull; @@ -83,14 +81,6 @@ public class JpaAutomationComposition extends Validated @Column @NotNull - private AutomationCompositionState state; - - @Column - @NotNull - private AutomationCompositionOrderedState orderedState; - - @Column - @NotNull private DeployState deployState; @Column @@ -110,7 +100,7 @@ public class JpaAutomationComposition extends Validated */ public JpaAutomationComposition() { this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(), - AutomationCompositionState.UNINITIALISED, new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED); + new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED); } /** @@ -119,18 +109,18 @@ public class JpaAutomationComposition extends Validated * @param instanceId The UUID of the automation composition instance * @param key the key * @param compositionId the TOSCA compositionId of the automation composition definition - * @param state the state of the automation composition * @param elements the elements of the automation composition in participants + * @param deployState the Deploy State + * @param lockState the Lock State */ public JpaAutomationComposition(@NonNull final String instanceId, @NonNull final PfConceptKey key, - @NonNull final String compositionId, @NonNull final AutomationCompositionState state, + @NonNull final String compositionId, @NonNull final List<JpaAutomationCompositionElement> elements, - @NonNull final DeployState deployState, @NonNull final LockState lockState) { + @NonNull final DeployState deployState, @NonNull final LockState lockState) { this.instanceId = instanceId; this.name = key.getName(); this.version = key.getVersion(); this.compositionId = compositionId; - this.state = state; this.deployState = deployState; this.lockState = lockState; this.elements = elements; @@ -146,8 +136,6 @@ public class JpaAutomationComposition extends Validated this.name = copyConcept.name; this.version = copyConcept.version; this.compositionId = copyConcept.compositionId; - this.state = copyConcept.state; - this.orderedState = copyConcept.orderedState; this.deployState = copyConcept.deployState; this.lockState = copyConcept.lockState; this.description = copyConcept.description; @@ -171,8 +159,6 @@ public class JpaAutomationComposition extends Validated automationComposition.setName(name); automationComposition.setVersion(version); automationComposition.setCompositionId(UUID.fromString(compositionId)); - automationComposition.setState(state); - automationComposition.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); automationComposition.setDescription(description); @@ -190,8 +176,6 @@ public class JpaAutomationComposition extends Validated this.name = automationComposition.getName(); this.version = automationComposition.getVersion(); this.compositionId = automationComposition.getCompositionId().toString(); - this.state = automationComposition.getState(); - this.orderedState = automationComposition.getOrderedState(); this.deployState = automationComposition.getDeployState(); this.lockState = automationComposition.getLockState(); this.description = automationComposition.getDescription(); @@ -234,16 +218,6 @@ public class JpaAutomationComposition extends Validated return result; } - result = ObjectUtils.compare(state, other.state); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(orderedState, other.orderedState); - if (result != 0) { - return result; - } - result = ObjectUtils.compare(deployState, other.deployState); if (result != 0) { return result; 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 d0dcd797f..4c3a6a3be 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 @@ -41,8 +41,6 @@ import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.common.parameters.annotations.NotNull; @@ -75,7 +73,6 @@ public class JpaAutomationCompositionElement extends Validated @NotNull private String instanceId; - // @formatter:off @VerifyKey @NotNull @AttributeOverrides({ @@ -89,14 +86,6 @@ public class JpaAutomationCompositionElement extends Validated @Column @NotNull - private AutomationCompositionState state; - - @Column - @NotNull - private AutomationCompositionOrderedState orderedState; - - @Column - @NotNull private DeployState deployState; @Column @@ -127,7 +116,7 @@ public class JpaAutomationCompositionElement extends Validated */ public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) { this(elementId, instanceId, new PfConceptKey(), - AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED); + DeployState.UNDEPLOYED, LockState.LOCKED); } /** @@ -136,16 +125,15 @@ public class JpaAutomationCompositionElement extends Validated * @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 state the state of the automation composition + * @param deployState the Deploy State of the automation composition + * @param lockState the Lock State of the automation composition */ public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId, @NonNull final PfConceptKey definition, - @NonNull final AutomationCompositionState state, - @NonNull final DeployState deployState, @NonNull final LockState lockState) { + @NonNull final DeployState deployState, @NonNull final LockState lockState) { this.elementId = elementId; this.instanceId = instanceId; this.definition = definition; - this.state = state; this.deployState = deployState; this.lockState = lockState; } @@ -160,8 +148,6 @@ public class JpaAutomationCompositionElement extends Validated this.instanceId = copyConcept.instanceId; this.definition = new PfConceptKey(copyConcept.definition); this.participantId = copyConcept.participantId; - this.state = copyConcept.state; - this.orderedState = copyConcept.orderedState; this.description = copyConcept.description; this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null); this.deployState = copyConcept.deployState; @@ -184,8 +170,6 @@ public class JpaAutomationCompositionElement extends Validated element.setId(UUID.fromString(elementId)); element.setDefinition(new ToscaConceptIdentifier(definition)); element.setParticipantId(UUID.fromString(participantId)); - element.setState(state); - element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); element.setDescription(description); element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity())); element.setDeployState(deployState); @@ -198,10 +182,8 @@ public class JpaAutomationCompositionElement extends Validated public void fromAuthorative(@NonNull final AutomationCompositionElement element) { this.definition = element.getDefinition().asConceptKey(); this.participantId = element.getParticipantId().toString(); - this.state = element.getState(); - this.orderedState = element.getOrderedState(); this.description = element.getDescription(); - properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()); + this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()); this.deployState = element.getDeployState(); this.lockState = element.getLockState(); } @@ -235,16 +217,6 @@ public class JpaAutomationCompositionElement extends Validated return result; } - result = ObjectUtils.compare(state, other.state); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(orderedState, other.orderedState); - if (result != 0) { - return result; - } - result = ObjectUtils.compare(deployState, other.deployState); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java index 197955d3a..058feae76 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java @@ -116,7 +116,6 @@ public class AutomationCompositionProvider { */ public AutomationComposition updateAutomationComposition( @NonNull final AutomationComposition automationComposition) { - AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE); var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition, JpaAutomationComposition::new, "automation composition")); @@ -159,7 +158,6 @@ public class AutomationCompositionProvider { example.setVersion(version); example.setInstanceId(null); example.setElements(null); - example.setState(null); example.setDeployState(null); example.setLockState(null); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java index 76dcabf0e..5585e6896 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java @@ -28,8 +28,8 @@ import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.Partic import java.time.Instant; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +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.clamp.models.acm.utils.CommonTestData; import org.onap.policy.common.utils.coder.CoderException; @@ -52,8 +52,8 @@ class AutomationCompositionStateChangeTest { orig.setAutomationCompositionId(UUID.randomUUID()); orig.setParticipantId(CommonTestData.getParticipantId()); orig.setMessageId(UUID.randomUUID()); - orig.setOrderedState(AutomationCompositionOrderedState.RUNNING); - orig.setCurrentState(AutomationCompositionState.PASSIVE); + orig.setDeployOrderedState(DeployOrder.DEPLOY); + orig.setLockOrderedState(LockOrder.NONE); orig.setTimestamp(Instant.ofEpochMilli(3000)); assertEquals(removeVariableFields(orig.toString()), diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java index bbba9cbc2..711af2f81 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java @@ -31,7 +31,8 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +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.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.utils.CommonTestData; @@ -77,7 +78,8 @@ class ParticipantStatusTest { private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) { var acInfo = new AutomationCompositionInfo(); - acInfo.setState(AutomationCompositionState.PASSIVE2RUNNING); + acInfo.setDeployState(DeployState.DEPLOYED); + acInfo.setLockState(LockState.LOCKED); acInfo.setAutomationCompositionId(id); return acInfo; 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 3274833ca..e9df9b7e5 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 @@ -25,22 +25,16 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; 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.Participant; import org.onap.policy.clamp.models.acm.utils.CommonTestData; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -78,38 +72,33 @@ class JpaAutomationCompositionElementTest { }).hasMessageMatching(NULL_ELEMENT_ID_ERROR); assertThatThrownBy(() -> { - new JpaAutomationCompositionElement(null, null, null, null, null, null); + new JpaAutomationCompositionElement(null, null, null, null, null); }).hasMessageMatching(NULL_ELEMENT_ID_ERROR); assertThatThrownBy(() -> { new JpaAutomationCompositionElement("key", null, null, - AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED); + DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching(NULL_INSTANCE_ID_ERROR); assertThatThrownBy(() -> { new JpaAutomationCompositionElement("key", "key", null, - AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED); - }).hasMessageMatching("definition" + NULL_ERROR); - - assertThatThrownBy(() -> { - new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), null, DeployState.UNDEPLOYED, LockState.LOCKED); - }).hasMessageMatching("state" + NULL_ERROR); + }).hasMessageMatching("definition" + NULL_ERROR); assertThatThrownBy(() -> { new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), - AutomationCompositionState.UNINITIALISED, null, LockState.LOCKED); + null, LockState.LOCKED); }).hasMessageMatching("deployState" + NULL_ERROR); assertThatThrownBy(() -> { new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), - AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, null); + DeployState.UNDEPLOYED, null); }).hasMessageMatching("lockState" + NULL_ERROR); assertNotNull(new JpaAutomationCompositionElement()); assertNotNull(new JpaAutomationCompositionElement("key", "key")); assertNotNull(new JpaAutomationCompositionElement("key", "key", - new PfConceptKey(), AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED)); + new PfConceptKey(), DeployState.UNDEPLOYED, LockState.LOCKED)); } @Test @@ -138,29 +127,6 @@ class JpaAutomationCompositionElementTest { } @Test - void testJpaAutomationCompositionElementOrderedState() throws CoderException { - var testAutomationCompositionElement = createAutomationCompositionElementInstance(); - var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance(); - - testJpaAutomationCompositionElement.setOrderedState(null); - assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative()); - testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - - var noOrderedStateAce = new StandardCoder().decode( - new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), - AutomationCompositionElement.class); - - var noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce); - assertNull(noOrderedStateJpaAce.getOrderedState()); - noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce); - noOrderedStateJpaAce.setInstanceId(testJpaAutomationCompositionElement.getInstanceId()); - noOrderedStateJpaAce.setElementId(testJpaAutomationCompositionElement.getElementId()); - noOrderedStateJpaAce.setParticipantId(testJpaAutomationCompositionElement.getParticipantId()); - assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce); - } - - @Test void testJpaAutomationCompositionElementValidation() { var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance(); @@ -202,16 +168,6 @@ class JpaAutomationCompositionElementTest { testJpaAutomationCompositionElement.setDescription(null); assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - testJpaAutomationCompositionElement.setState(AutomationCompositionState.PASSIVE); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setState(AutomationCompositionState.UNINITIALISED); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setDeployState(DeployState.DEPLOYED); assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); testJpaAutomationCompositionElement.setDeployState(DeployState.UNDEPLOYED); @@ -244,8 +200,6 @@ class JpaAutomationCompositionElementTest { ace1.setDefinition(new PfConceptKey("defName", "0.0.1")); ace1.setDescription("Description"); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - ace1.setState(AutomationCompositionState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getJpaParticipantId()); assertThat(ace1.toString()).contains("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 index 0f10c8c03..bc01e74be 100644 --- 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 @@ -22,25 +22,18 @@ package org.onap.policy.clamp.models.acm.persistence.concepts; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.File; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.base.PfConceptKey; /** @@ -64,43 +57,37 @@ class JpaAutomationCompositionTest { }).hasMessageMatching("authorativeConcept is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaAutomationComposition(null, null, null, null, null, null, null); + new JpaAutomationComposition(null, null, null, null, null, null); }).hasMessageMatching(NULL_INSTANCE_ID_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, null, null, null, new ArrayList<>(), + 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, - AutomationCompositionState.UNINITIALISED, new ArrayList<>(), - DeployState.UNDEPLOYED, LockState.LOCKED); + new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching("compositionId" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), null, - new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED); - }).hasMessageMatching("state" + NULL_TEXT_ERROR); - - assertThatThrownBy(() -> { new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - AutomationCompositionState.UNINITIALISED, null, DeployState.UNDEPLOYED, LockState.LOCKED); + null, DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching("elements" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - AutomationCompositionState.UNINITIALISED, new ArrayList<>(), null, LockState.LOCKED); + new ArrayList<>(), null, LockState.LOCKED); }).hasMessageMatching("deployState" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - AutomationCompositionState.UNINITIALISED, new ArrayList<>(), DeployState.UNDEPLOYED, null); + new ArrayList<>(), DeployState.UNDEPLOYED, null); }).hasMessageMatching("lockState" + NULL_TEXT_ERROR); assertNotNull(new JpaAutomationComposition()); assertNotNull(new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - AutomationCompositionState.UNINITIALISED, new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED)); + new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED)); } @Test @@ -131,36 +118,6 @@ class JpaAutomationCompositionTest { } @Test - void testJpaAutomationCompositionElementOrderedState() throws CoderException { - var testAutomationComposition = createAutomationCompositionInstance(); - var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); - - testJpaAutomationComposition.setOrderedState(null); - assertEquals(testAutomationComposition, testJpaAutomationComposition.toAuthorative()); - testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - - var noOrderedStateAc = - new StandardCoder().decode(new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"), - AutomationComposition.class); - - noOrderedStateAc.setInstanceId(UUID.fromString(INSTANCE_ID)); - var noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc); - assertNull(noOrderedStateJpaAc.getOrderedState()); - noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc); - assertEquals(testJpaAutomationComposition, noOrderedStateJpaAc); - - var acWithElements = - new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"), - AutomationCompositions.class).getAutomationCompositionList().get(0); - - acWithElements.setInstanceId(UUID.fromString(INSTANCE_ID)); - var jpaAutomationCompositionWithElements = new JpaAutomationComposition(acWithElements); - assertEquals(4, jpaAutomationCompositionWithElements.getElements().size()); - assertEquals(acWithElements, jpaAutomationCompositionWithElements.toAuthorative()); - } - - @Test void testJpaAutomationCompositionValidation() { var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); @@ -200,14 +157,14 @@ class JpaAutomationCompositionTest { testJpaAutomationComposition.setVersion("0.0.1"); assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE); + testJpaAutomationComposition.setDeployState(DeployState.DEPLOYED); assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setState(AutomationCompositionState.UNINITIALISED); + testJpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED); assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + testJpaAutomationComposition.setLockState(LockState.UNLOCKED); assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + testJpaAutomationComposition.setLockState(LockState.NONE); assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); testJpaAutomationComposition.setDescription("A description"); @@ -235,7 +192,6 @@ class JpaAutomationCompositionTest { ac1.setDescription("Description"); ac1.setElements(new ArrayList<>()); ac1.setInstanceId(INSTANCE_ID); - ac1.setState(AutomationCompositionState.UNINITIALISED); assertThat(ac1.toString()).contains("AutomationComposition("); assertNotEquals(0, ac1.hashCode()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index 62a769fdb..02e5b1ac6 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -29,8 +29,8 @@ import lombok.AllArgsConstructor; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; @@ -106,6 +106,10 @@ public class AutomationCompositionInstantiationProvider { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId); } + if (!DeployState.UNDEPLOYED.equals(acToUpdate.getDeployState())) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, + "Not allow to update for state in " + acToUpdate.getDeployState()); + } acToUpdate.setElements(automationComposition.getElements()); acToUpdate.setName(automationComposition.getName()); acToUpdate.setVersion(automationComposition.getVersion()); @@ -139,8 +143,8 @@ public class AutomationCompositionInstantiationProvider { return result; } if (!AcTypeState.PRIMED.equals(acDefinitionOpt.get().getState())) { - result.addResult(new ObjectValidationResult("ServiceTemplate", "", ValidationStatus.INVALID, - "Commissioned automation composition definition not primed")); + result.addResult(new ObjectValidationResult("ServiceTemplate", acDefinitionOpt.get().getState(), + ValidationStatus.INVALID, "Commissioned automation composition definition not primed")); return result; } result.addResult(AcmUtils.validateAutomationComposition(automationComposition, @@ -169,7 +173,7 @@ public class AutomationCompositionInstantiationProvider { var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId); if (!automationComposition.getCompositionId().equals(compositionId)) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, - "Composition Id " + compositionId + DO_NOT_MATCH + automationComposition.getCompositionId()); + automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId); } return automationComposition; } @@ -187,9 +191,9 @@ public class AutomationCompositionInstantiationProvider { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId); } - if (!AutomationCompositionState.UNINITIALISED.equals(automationComposition.getState())) { + if (!DeployState.UNDEPLOYED.equals(automationComposition.getDeployState())) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, - "Automation composition state is still " + automationComposition.getState()); + "Automation composition state is still " + automationComposition.getDeployState()); } var response = new InstantiationResponse(); automationComposition = diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java index 1acaebea6..9f39d8dc6 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java @@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.runtime.instantiation; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -33,12 +34,19 @@ import java.util.Optional; import java.util.UUID; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; +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.messages.rest.instantiation.AcInstanceStateUpdate; +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.clamp.models.acm.persistence.provider.AcDefinitionProvider; +import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -151,20 +159,21 @@ class AutomationCompositionInstantiationProviderTest { assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(wrongCompositionId, instanceId)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); - for (var state : AutomationCompositionState.values()) { - if (!AutomationCompositionState.UNINITIALISED.equals(state)) { - assertThatDeleteThrownBy(automationComposition, state); - } - } - automationComposition.setState(AutomationCompositionState.UNINITIALISED); + assertThatDeleteThrownBy(automationComposition, DeployState.DEPLOYED, LockState.LOCKED); + assertThatDeleteThrownBy(automationComposition, DeployState.DEPLOYING, LockState.NONE); + assertThatDeleteThrownBy(automationComposition, DeployState.UNDEPLOYING, LockState.LOCKED); + + automationComposition.setDeployState(DeployState.UNDEPLOYED); + automationComposition.setLockState(LockState.NONE); when(acProvider.deleteAutomationComposition(instanceId)).thenReturn(automationComposition); instantiationProvider.deleteAutomationComposition(compositionId, instanceId); } private void assertThatDeleteThrownBy(AutomationComposition automationComposition, - AutomationCompositionState state) { - automationComposition.setState(state); + DeployState deployState, LockState lockState) { + automationComposition.setDeployState(deployState); + automationComposition.setLockState(lockState); var acProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); @@ -177,7 +186,7 @@ class AutomationCompositionInstantiationProviderTest { var compositionId = automationComposition.getCompositionId(); var instanceId = automationComposition.getInstanceId(); assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(compositionId, instanceId)) - .hasMessageMatching(String.format(DELETE_BAD_REQUEST, state)); + .hasMessageMatching(String.format(DELETE_BAD_REQUEST, deployState)); } @Test @@ -236,16 +245,15 @@ class AutomationCompositionInstantiationProviderTest { } @Test - void testCreateAutomationCompositions_CommissionedAcNotFound() { + void testAcDefinitionNotFound() { var automationComposition = InstantiationUtils .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); var acProvider = mock(AutomationCompositionProvider.class); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); - var acDefinitionProvider = mock(AcDefinitionProvider.class); var provider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null); + mock(AcDefinitionProvider.class), null, null); var compositionId = automationComposition.getCompositionId(); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) @@ -253,12 +261,118 @@ class AutomationCompositionInstantiationProviderTest { assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_DEFINITION_NOT_FOUND); + } + + @Test + void testCompositionIdDoNotMatch() { + var automationComposition = InstantiationUtils + .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); + + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) + .thenReturn(automationComposition); + var provider = new AutomationCompositionInstantiationProvider(acProvider, + mock(AcDefinitionProvider.class), null, null); + var compositionId = automationComposition.getCompositionId(); var wrongCompositionId = UUID.randomUUID(); assertThatThrownBy(() -> provider.createAutomationComposition(wrongCompositionId, automationComposition)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, automationComposition)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); + + assertThatThrownBy( + () -> provider.getAutomationComposition(wrongCompositionId, automationComposition.getInstanceId())) + .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); + assertThatThrownBy(() -> provider.compositionInstanceState(wrongCompositionId, + automationComposition.getInstanceId(), new AcInstanceStateUpdate())) + .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); + } + + @Test + void testCompositionNotPrimed() { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.COMMISSIONED); + var compositionId = acDefinition.getCompositionId(); + when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); + var acProvider = mock(AutomationCompositionProvider.class); + var provider = + new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null); + + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); + automationComposition.setCompositionId(compositionId); + assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) + .hasMessageMatching("\"AutomationComposition\" INVALID, item has status INVALID\n" + + " item \"ServiceTemplate\" value \"COMMISSIONED\" INVALID," + + " Commissioned automation composition definition not primed\n"); + } + + @Test + void testUpdateBadRequest() { + var automationComposition = InstantiationUtils + .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); + + var acProvider = mock(AutomationCompositionProvider.class); + automationComposition.setDeployState(DeployState.DEPLOYED); + when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) + .thenReturn(automationComposition); + var provider = new AutomationCompositionInstantiationProvider(acProvider, + mock(AcDefinitionProvider.class), null, null); + + assertThatThrownBy(() -> provider.updateAutomationComposition(automationComposition.getCompositionId(), + automationComposition)).hasMessageMatching("Not allow to update for state in DEPLOYED"); + } + + @Test + void testCompositionInstanceState() { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.COMMISSIONED); + var compositionId = acDefinition.getCompositionId(); + when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition); + + var automationComposition = InstantiationUtils + .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); + var instanceId = UUID.randomUUID(); + automationComposition.setCompositionId(compositionId); + automationComposition.setInstanceId(instanceId); + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(instanceId)) + .thenReturn(automationComposition); + + var supervisionAcHandler = mock(SupervisionAcHandler.class); + var provider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + new AcInstanceStateResolver(), supervisionAcHandler); + + var acInstanceStateUpdate = new AcInstanceStateUpdate(); + acInstanceStateUpdate.setDeployOrder(DeployOrder.DEPLOY); + acInstanceStateUpdate.setLockOrder(LockOrder.NONE); + provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate); + verify(supervisionAcHandler).deploy(any(AutomationComposition.class), + any(AutomationCompositionDefinition.class)); + + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.LOCKED); + acInstanceStateUpdate.setDeployOrder(DeployOrder.UNDEPLOY); + provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate); + verify(supervisionAcHandler).undeploy(any(AutomationComposition.class), + any(AutomationCompositionDefinition.class)); + + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.LOCKED); + acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE); + acInstanceStateUpdate.setLockOrder(LockOrder.UNLOCK); + provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate); + verify(supervisionAcHandler).unlock(any(AutomationComposition.class), + any(AutomationCompositionDefinition.class)); + + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.UNLOCKED); + acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE); + acInstanceStateUpdate.setLockOrder(LockOrder.LOCK); + provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate); + verify(supervisionAcHandler).lock(any(AutomationComposition.class), + any(AutomationCompositionDefinition.class)); } } diff --git a/runtime-acm/src/test/resources/rest/acm/PassiveCommand.json b/runtime-acm/src/test/resources/rest/acm/PassiveCommand.json deleted file mode 100644 index 93f131cd8..000000000 --- a/runtime-acm/src/test/resources/rest/acm/PassiveCommand.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "orderedState": "PASSIVE", - "automationCompositionIdentifier": { - "name": "PMSHInstance0", - "version": "1.0.1" - } -}
\ No newline at end of file |