diff options
Diffstat (limited to 'models/src')
10 files changed, 246 insertions, 112 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java index afbd61bd1..8f8a54f39 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java @@ -32,9 +32,6 @@ import lombok.ToString; public class AcElementDeployAck { // State of the AutomationCompositionElement - private AutomationCompositionState state; - - // State of the AutomationCompositionElement private DeployState deployState; // State of the AutomationCompositionElement diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java index 65b72c436..25d72cb06 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java @@ -29,6 +29,8 @@ import javax.ws.rs.core.Response.Status; import lombok.NonNull; import lombok.RequiredArgsConstructor; 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.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; @@ -180,4 +182,19 @@ public class ParticipantProvider { return ProviderUtils.asEntityList(nodeTemplateStateRepository .findByParticipantId(participantId.toString())); } + + /** + * Reset the Deploy and Lock states of all the ac elements associated with a participant. + * + * @param participantId the participant id associated with the automation composition elements + */ + public void resetParticipantAcElementState(@NonNull final UUID participantId) { + var participantAcElementList = automationCompositionElementRepository + .findByParticipantId(participantId.toString()); + participantAcElementList.forEach(e -> { + e.setDeployState(DeployState.UNDEPLOYED); + e.setLockState(LockState.NONE); + }); + automationCompositionElementRepository.saveAll(participantAcElementList); + } } 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 af29deb3f..35482b9bb 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 @@ -37,13 +37,13 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; 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.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; 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; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationResult; @@ -67,38 +67,6 @@ public final class AcmUtils { public static final String ENTRY = "entry "; /** - * Prepare participant updates map. - * - * @param acElement automation composition element - * @param participantUpdates list of participantUpdates - */ - public static void prepareParticipantUpdate(AutomationCompositionElement acElement, - List<ParticipantDeploy> participantUpdates) { - if (participantUpdates.isEmpty()) { - participantUpdates.add(getAutomationCompositionElementList(acElement)); - return; - } - - var participantExists = false; - for (ParticipantDeploy participantUpdate : participantUpdates) { - if (participantUpdate.getParticipantId().equals(acElement.getParticipantId())) { - participantUpdate.getAutomationCompositionElementList().add(acElement); - participantExists = true; - } - } - if (!participantExists) { - participantUpdates.add(getAutomationCompositionElementList(acElement)); - } - } - - private static ParticipantDeploy getAutomationCompositionElementList(AutomationCompositionElement acElement) { - var participantUpdate = new ParticipantDeploy(); - participantUpdate.setParticipantId(acElement.getParticipantId()); - participantUpdate.getAutomationCompositionElementList().add(acElement); - return participantUpdate; - } - - /** * Get the Policy information in the service template for the deploy message to participants. * * @param toscaServiceTemplate ToscaServiceTemplate @@ -196,7 +164,7 @@ public final class AcmUtils { public static List<Entry<String, ToscaNodeTemplate>> extractAcElementsFromServiceTemplate( ToscaServiceTemplate serviceTemplate) { return serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet().stream().filter( - nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), + nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), serviceTemplate)) .collect(Collectors.toList()); } @@ -309,7 +277,6 @@ public final class AcmUtils { // @formatter:on } - /** * Return true if DeployState and LockState are in a Transitional State. * @@ -321,6 +288,79 @@ public final class AcmUtils { } /** + * Get DeployOrder from transitional DeployState. + * + * @param deployState the Deploy State + * @return the DeployOrder + */ + public static DeployOrder stateDeployToOrder(DeployState deployState) { + if (DeployState.DEPLOYING.equals(deployState)) { + return DeployOrder.DEPLOY; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return DeployOrder.UNDEPLOY; + } + return DeployOrder.NONE; + } + + /** + * Get LockOrder from transitional LockState. + * + * @param lockState the Lock State + * @return the LockOrder + */ + public static LockOrder stateLockToOrder(LockState lockState) { + if (LockState.LOCKING.equals(lockState)) { + return LockOrder.LOCK; + } else if (LockState.UNLOCKING.equals(lockState)) { + return LockOrder.UNLOCK; + } + return LockOrder.NONE; + } + + /** + * Get final DeployState from transitional DeployState. + * + * @param deployState the DeployState + * @return the DeployState + */ + public static DeployState deployCompleted(DeployState deployState) { + if (DeployState.DEPLOYING.equals(deployState)) { + return DeployState.DEPLOYED; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return DeployState.UNDEPLOYED; + } + return deployState; + } + + /** + * Get final LockState from transitional LockState. + * + * @param lockState the LockState + * @return the LockState + */ + public static LockState lockCompleted(DeployState deployState, LockState lockState) { + if (LockState.LOCKING.equals(lockState) || DeployState.DEPLOYING.equals(deployState)) { + return LockState.LOCKED; + } else if (LockState.UNLOCKING.equals(lockState)) { + return LockState.UNLOCKED; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return LockState.NONE; + } + return lockState; + } + + /** + * Return true if transition states is Forward. + * + * @param deployState the DeployState + * @param lockState the LockState + * @return true if transition if Forward + */ + public static boolean isForward(DeployState deployState, LockState lockState) { + return DeployState.DEPLOYING.equals(deployState) || LockState.UNLOCKING.equals(lockState); + } + + /** * Set the states on the automation composition and on all its automation composition elements. * * @param deployState the DeployState we want the automation composition to transition to diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java index 9f235d6ac..e044a2f22 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java @@ -25,7 +25,6 @@ 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.assertTrue; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -43,28 +42,13 @@ class AutomationCompositionElementTest { ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); ace1.setDescription("Description"); ace1.setId(UUID.randomUUID()); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getParticipantId()); - ace1.setState(AutomationCompositionState.UNINITIALISED); var ace2 = new AutomationCompositionElement(ace1); assertEquals(ace1, ace2); } @Test - void testAutomationCompositionState() { - var ace0 = new AutomationCompositionElement(); - - assertTrue( - ace0.getOrderedState() - .equalsAutomationCompositionState(AutomationCompositionState.UNINITIALISED)); - - assertTrue( - ace0.getOrderedState().asState() - .equalsAutomationCompositionOrderedState(AutomationCompositionOrderedState.UNINITIALISED)); - } - - @Test void testAutomationCompositionElementLombok() { var ace0 = new AutomationCompositionElement(); @@ -78,9 +62,7 @@ class AutomationCompositionElementTest { ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); ace1.setDescription("Description"); ace1.setId(UUID.randomUUID()); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getParticipantId()); - ace1.setState(AutomationCompositionState.UNINITIALISED); assertThat(ace1.toString()).contains("AutomationCompositionElement("); assertNotEquals(0, ace1.hashCode()); @@ -94,9 +76,7 @@ class AutomationCompositionElementTest { // @formatter:off assertThatThrownBy(() -> ace2.setDefinition(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ace2.setId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ace2.setOrderedState(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ace2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ace2.setState(null)). isInstanceOf(NullPointerException.class); // @formatter:on assertNotEquals(ace2, ace0); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java index e32735f07..64dc6f792 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java @@ -60,8 +60,6 @@ class AutomationCompositionTest { ac1.setDescription("Description"); ac1.setElements(new LinkedHashMap<>()); ac1.setName("Name"); - ac1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - ac1.setState(AutomationCompositionState.UNINITIALISED); ac1.setVersion("0.0.1"); assertThat(ac1.toString()).contains("AutomationComposition("); @@ -76,20 +74,11 @@ class AutomationCompositionTest { // @formatter:off assertThatThrownBy(() -> ac2.setCompositionId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class); // @formatter:on assertEquals(ac2, ac0); - ac1.setCascadedOrderedState(AutomationCompositionOrderedState.PASSIVE); - assertEquals(AutomationCompositionOrderedState.PASSIVE, ac1.getOrderedState()); - ac1.getElements().put(UUID.randomUUID(), new AutomationCompositionElement()); - ac1.setCascadedOrderedState(AutomationCompositionOrderedState.RUNNING); - assertEquals(AutomationCompositionOrderedState.RUNNING, ac1.getOrderedState()); - assertEquals(AutomationCompositionOrderedState.RUNNING, - ac1.getElements().values().iterator().next().getOrderedState()); assertNull(ac0.getElements().get(UUID.randomUUID())); assertNull(ac1.getElements().get(UUID.randomUUID())); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java index 6e5b504af..8c50b01b6 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java @@ -29,7 +29,8 @@ import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; -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.utils.CommonTestData; import org.onap.policy.common.utils.coder.CoderException; @@ -49,7 +50,7 @@ class AutomationCompositionDeployAckTest { // verify with all values orig.setAutomationCompositionId(UUID.randomUUID()); orig.setParticipantId(CommonTestData.getParticipantId()); - var acElementResult = new AcElementDeployAck(AutomationCompositionState.UNINITIALISED, null, null, + var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, true, "AutomationCompositionElement result"); final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult); orig.setAutomationCompositionResultMap(automationCompositionResultMap); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java index 2912dee9b..3f64eadd5 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java @@ -30,9 +30,7 @@ import java.util.List; 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.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.utils.CommonTestData; import org.onap.policy.common.utils.coder.CoderException; @@ -55,16 +53,10 @@ class AutomationCompositionDeployTest { orig.setMessageId(UUID.randomUUID()); orig.setTimestamp(Instant.ofEpochMilli(3000)); - var acElement = new AutomationCompositionElement(); + var acElement = new AcElementDeploy(); acElement.setId(UUID.randomUUID()); var id = new ToscaConceptIdentifier("id", "1.2.3"); acElement.setDefinition(id); - acElement.setDescription("Description"); - acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - acElement.setState(AutomationCompositionState.PASSIVE); - - var participantId = CommonTestData.getParticipantId(); - acElement.setParticipantId(participantId); var property = new ToscaProperty(); property.setName("test"); @@ -75,8 +67,8 @@ class AutomationCompositionDeployTest { acElement.setProperties(propertiesMap); var participantDeploy = new ParticipantDeploy(); - participantDeploy.setParticipantId(participantId); - participantDeploy.setAutomationCompositionElementList(List.of(acElement)); + participantDeploy.setParticipantId(CommonTestData.getParticipantId()); + participantDeploy.setAcElementList(List.of(acElement)); orig.setParticipantUpdatesList(List.of(participantDeploy)); var other = new AutomationCompositionDeploy(orig); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java index 52e90b53a..968ad31bb 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java @@ -36,6 +36,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; 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.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; @@ -57,6 +59,9 @@ class ParticipantProviderTest { private static final String AUTOMATION_COMPOSITION_JSON = "src/test/resources/providers/TestAutomationCompositions.json"; + private static final String AUTOMATION_COMPOSITION_JSON_DEREGISTER = + "src/test/resources/providers/TestAutomationCompositionsDeregister.json"; + private static final String NODE_TEMPLATE_STATE_JSON = "src/test/resources/providers/NodeTemplateState.json"; private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; private static final UUID INVALID_ID = UUID.randomUUID(); @@ -69,6 +74,10 @@ class ParticipantProviderTest { private List<JpaAutomationComposition> inputAutomationCompositionsJpa; private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON); + private AutomationCompositions inputAutomationCompositionsDeregister; + private List<JpaAutomationComposition> inputAutomationCompositionsJpaDeregister; + private final String deregisterAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON_DEREGISTER); + private final String nodeTemplateStatesJson = ResourceUtils.getResourceAsString(NODE_TEMPLATE_STATE_JSON); private List<NodeTemplateState> nodeTemplateStateList = new ArrayList<>(); @@ -84,6 +93,11 @@ class ParticipantProviderTest { ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(), JpaAutomationComposition::new, "automation compositions"); + inputAutomationCompositionsDeregister = CODER.decode(deregisterAcJson, AutomationCompositions.class); + inputAutomationCompositionsJpaDeregister = + ProviderUtils.getJpaAndValidateList(inputAutomationCompositionsDeregister.getAutomationCompositionList(), + JpaAutomationComposition::new, "automation compositions"); + nodeTemplateStateList.add(CODER.decode(nodeTemplateStatesJson, NodeTemplateState.class)); nodeTemplateStateList.get(0).setState(AcTypeState.COMMISSIONED); jpaNodeTemplateStateList = ProviderUtils.getJpaAndValidateList(nodeTemplateStateList, @@ -238,8 +252,7 @@ class ParticipantProviderTest { assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null)); assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null)); assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null)); - - + assertThrows(NullPointerException.class, () -> participantProvider.resetParticipantAcElementState(null)); } @Test @@ -254,4 +267,32 @@ class ParticipantProviderTest { var result = participantProvider.getSupportedElementMap(); assertThat(result).hasSize(2); } + + @Test + void testResetParticipantAcElementState() { + var participantRepository = mock(ParticipantRepository.class); + var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class); + + var acElementList = inputAutomationCompositionsJpaDeregister + .stream().map(c -> c.getElements()).collect(Collectors.toList()); + + when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0)); + + var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class); + var participantProvider = new ParticipantProvider(participantRepository, + automationCompositionElementRepository, nodeTemplateStateRepository); + + acElementList.get(0).stream().forEach(e -> { + assertThat(e.getDeployState().equals(DeployState.DEPLOYED)); + assertThat(e.getLockState().equals(LockState.LOCKED)); + }); + + participantProvider.resetParticipantAcElementState(UUID.randomUUID()); + + acElementList.get(0).stream().forEach(e -> { + assertThat(e.getDeployState().equals(DeployState.UNDEPLOYED)); + assertThat(e.getLockState().equals(LockState.NONE)); + }); + + } } 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 index c16beaf87..b332d7d44 100644 --- 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 @@ -24,13 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -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 static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -41,8 +40,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; 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.ParticipantDeploy; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +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.utils.coder.StandardCoder; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; @@ -69,25 +69,6 @@ class AcmUtilsTest { } @Test - void testCommonUtilsParticipantUpdate() { - var acElement = new AutomationCompositionElement(); - List<ParticipantDeploy> participantUpdates = new ArrayList<>(); - assertThat(participantUpdates).isEmpty(); - - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - assertThat(participantUpdates).isNotEmpty(); - assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0)); - - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - var participantId = CommonTestData.getParticipantId(); - assertNotEquals(participantId, participantUpdates.get(0).getParticipantId()); - - acElement.setParticipantId(participantId); - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - assertEquals(participantId, participantUpdates.get(1).getParticipantId()); - } - - @Test void testCheckIfNodeTemplateIsAutomationCompositionElement() { var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML); var nodeTemplate = new ToscaNodeTemplate(); @@ -109,12 +90,12 @@ class AcmUtilsTest { Map<ToscaConceptIdentifier, UUID> map = new HashMap<>(); var participantId = UUID.randomUUID(); assertThatThrownBy(() -> AcmUtils.prepareParticipantPriming(acElements, map)).hasMessageMatching( - "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.1 not supported"); - map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"), + "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.0 not supported"); + map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"), participantId); map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", - "1.0.1"), participantId); - map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"), + "1.0.0"), participantId); + map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"), participantId); var result = AcmUtils.prepareParticipantPriming(acElements, map); assertThat(result).isNotEmpty().hasSize(1); @@ -159,6 +140,47 @@ class AcmUtilsTest { assertFalse(result.isValid()); } + @Test + void testStateDeployToOrder() { + // from transitional state to order state + assertEquals(DeployOrder.DEPLOY, AcmUtils.stateDeployToOrder(DeployState.DEPLOYING)); + assertEquals(DeployOrder.UNDEPLOY, AcmUtils.stateDeployToOrder(DeployState.UNDEPLOYING)); + assertEquals(DeployOrder.NONE, AcmUtils.stateDeployToOrder(DeployState.DEPLOYED)); + } + + @Test + void testStateLockToOrder() { + // from transitional state to order state + assertEquals(LockOrder.LOCK, AcmUtils.stateLockToOrder(LockState.LOCKING)); + assertEquals(LockOrder.UNLOCK, AcmUtils.stateLockToOrder(LockState.UNLOCKING)); + assertEquals(LockOrder.NONE, AcmUtils.stateLockToOrder(LockState.NONE)); + } + + @Test + void testDeployCompleted() { + // from transitional state to final state + assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYING)); + assertEquals(DeployState.UNDEPLOYED, AcmUtils.deployCompleted(DeployState.UNDEPLOYING)); + assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYED)); + } + + @Test + void testLockCompleted() { + // from transitional state to final state + assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYING, LockState.NONE)); + assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.LOCKING)); + assertEquals(LockState.UNLOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.UNLOCKING)); + assertEquals(LockState.NONE, AcmUtils.lockCompleted(DeployState.UNDEPLOYING, LockState.LOCKED)); + } + + @Test + void testIsForward() { + assertTrue(AcmUtils.isForward(DeployState.DEPLOYING, LockState.NONE)); + assertTrue(AcmUtils.isForward(DeployState.DEPLOYED, LockState.UNLOCKING)); + assertFalse(AcmUtils.isForward(DeployState.DEPLOYED, LockState.LOCKING)); + assertFalse(AcmUtils.isForward(DeployState.UNDEPLOYING, LockState.LOCKED)); + } + private AutomationComposition getDummyAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setCompositionId(UUID.randomUUID()); diff --git a/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json b/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json new file mode 100644 index 000000000..0da9cdeef --- /dev/null +++ b/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json @@ -0,0 +1,55 @@ +{ + "automationCompositionList": [ + { + "compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40", + "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c89", + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "elements": { + "709c62b3-8918-41b9-a747-e21eb79c6c20": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "DCAE automation composition element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c21": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "Monitoring Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c22": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "Operational Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c23": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c23", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement", + "version": "1.2.3" + }, + "deployState": "DEPLOYED", + "lockState": "UNLOCKED", + "description": "CDS automation composition element for the PMSH instance 0 automation composition" + } + }, + "name": "PMSHInstance0", + "version": "1.0.1", + "description": "PMSH automation composition instance 0" + } + ] +} |