From b75038fab6ae0816413ed9f925639f3befe4fddb Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Thu, 14 Dec 2023 17:33:57 +0000 Subject: Update compositions and instances monitoring Improved performance scanning only compositions and instances that are in transition. Issue-ID: POLICY-4906 Change-Id: I7a849e921f1d97509f67ff624c715c893a1432ab Signed-off-by: FrancescoFioraEst --- .../persistence/provider/AcDefinitionProvider.java | 50 +++++++++++-- .../provider/AutomationCompositionProvider.java | 18 ++++- .../AutomationCompositionDefinitionRepository.java | 11 +-- .../AutomationCompositionRepository.java | 13 ++-- .../provider/AcDefinitionProviderTest.java | 81 +++++++++++++++------- .../AutomationCompositionProviderTest.java | 26 ++++++- 6 files changed, 158 insertions(+), 41 deletions(-) (limited to 'models/src') diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java index a9b9a0cfd..9eb5e7a32 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,14 @@ import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository; import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.models.base.PfModelRuntimeException; @@ -47,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional; public class AcDefinitionProvider { private final AutomationCompositionDefinitionRepository acmDefinitionRepository; + private final NodeTemplateStateRepository nodeTemplateStateRepository; /** * Create Automation Composition Definition. @@ -124,6 +129,43 @@ public class AcDefinitionProvider { acmDefinitionRepository.flush(); } + /** + * Update Ac Definition AcTypeState, StateChangeResult and restarting. + * + * @param compositionId The UUID of the automation composition definition to update + * @param state the AcTypeState + * @param stateChangeResult the StateChangeResult + * @param restarting restarting process + */ + public void updateAcDefinitionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult, + Boolean restarting) { + var jpaUpdate = acmDefinitionRepository.findById(compositionId.toString()); + if (jpaUpdate.isEmpty()) { + String errorMessage = "update of Automation Composition Definition \"" + compositionId + + "\" failed, Automation Composition Definition does not exist"; + throw new PfModelRuntimeException(Response.Status.NOT_FOUND, errorMessage); + } + var acDefinition = jpaUpdate.get(); + acDefinition.setState(state); + acDefinition.setStateChangeResult(stateChangeResult); + acDefinition.setRestarting(restarting); + acmDefinitionRepository.save(acDefinition); + acmDefinitionRepository.flush(); + } + + /** + * Update Ac DefinitionElement. + * + * @param nodeTemplateState the NodeTemplateState + * @param compositionId The UUID of the automation composition definition + */ + public void updateAcDefinitionElement(NodeTemplateState nodeTemplateState, UUID compositionId) { + var jpaNodeTemplateState = new JpaNodeTemplateState( + nodeTemplateState.getNodeTemplateStateId().toString(), compositionId.toString()); + jpaNodeTemplateState.fromAuthorative(nodeTemplateState); + nodeTemplateStateRepository.save(jpaNodeTemplateState); + } + /** * Delete Automation Composition Definition. * @@ -173,13 +215,13 @@ public class AcDefinitionProvider { } /** - * Get Automation Composition Definitions. + * Get Automation Composition Definitions in transition. * * @return the Automation Composition Definitions found */ @Transactional(readOnly = true) - public List getAllAcDefinitions() { - var jpaList = acmDefinitionRepository.findAll(); + public List getAllAcDefinitionsInTransition() { + var jpaList = acmDefinitionRepository.findByStateIn(List.of(AcTypeState.PRIMING, AcTypeState.DEPRIMING)); return ProviderUtils.asEntityList(jpaList); } 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 1ffcc1b6e..8be12960b 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -127,7 +127,7 @@ public class AutomationCompositionProvider { @NonNull final AutomationComposition automationComposition) { var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition, JpaAutomationComposition::new, "automation composition")); - + automationCompositionRepository.flush(); // Return the saved automation composition return result.toAuthorative(); } @@ -144,6 +144,20 @@ public class AutomationCompositionProvider { .asEntityList(automationCompositionRepository.findByCompositionId(compositionId.toString())); } + /** + * Get all automation compositions in transition.. + * + * @return all automation compositions found + */ + @Transactional(readOnly = true) + public List getAcInstancesInTransition() { + var jpaList = automationCompositionRepository.findByDeployStateIn(List.of(DeployState.DEPLOYING, + DeployState.UNDEPLOYING, DeployState.DELETING, DeployState.UPDATING, DeployState.MIGRATING)); + jpaList.addAll(automationCompositionRepository.findByLockStateIn( + List.of(LockState.LOCKING, LockState.UNLOCKING))); + return ProviderUtils.asEntityList(jpaList); + } + /** * Get automation compositions. * diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java index df4d7dffa..86de60bf2 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,16 @@ package org.onap.policy.clamp.models.acm.persistence.repository; +import java.util.Collection; +import java.util.List; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.stereotype.Repository; @Repository public interface AutomationCompositionDefinitionRepository - extends JpaRepository, - QueryByExampleExecutor { + extends JpaRepository { + + List findByStateIn(Collection states); } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java index bb8b3e6d9..d61dfb41b 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2022,2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,20 @@ package org.onap.policy.clamp.models.acm.persistence.repository; +import java.util.Collection; import java.util.List; +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.persistence.concepts.JpaAutomationComposition; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.stereotype.Repository; @Repository -public interface AutomationCompositionRepository - extends JpaRepository, QueryByExampleExecutor { +public interface AutomationCompositionRepository extends JpaRepository { List findByCompositionId(String compositionId); + + List findByDeployStateIn(Collection deployStates); + + List findByLockStateIn(Collection lockStates); } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java index 78095c907..1e067c8f6 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,9 +38,12 @@ import org.mockito.Mockito; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository; import org.onap.policy.clamp.models.acm.utils.CommonTestData; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -91,7 +94,7 @@ class AcDefinitionProviderTest { when(acmDefinitionRepository.save(any(JpaAutomationCompositionDefinition.class))) .thenReturn(new JpaAutomationCompositionDefinition(acmDefinition)); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var result = acDefinitionProvider .createAutomationCompositionDefinition(inputServiceTemplate, ELEMENT_NAME, NODE_TYPE); @@ -101,11 +104,9 @@ class AcDefinitionProviderTest { @Test void testToscaWithInvalidElement() { - var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate); - var acmDefinition = getAcDefinition(docServiceTemplate); var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); assertThatThrownBy(() -> acDefinitionProvider .createAutomationCompositionDefinition(inputServiceTemplate, INVALID_ELEMENT_NAME, NODE_TYPE)) @@ -114,11 +115,9 @@ class AcDefinitionProviderTest { @Test void testToscaWithInvalidNodeType() { - var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate); - var acmDefinition = getAcDefinition(docServiceTemplate); var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); assertThatThrownBy(() -> acDefinitionProvider .createAutomationCompositionDefinition(inputServiceTemplate, ELEMENT_NAME, INVALID_NODE_TYPE)) @@ -135,7 +134,7 @@ class AcDefinitionProviderTest { when(acmDefinitionRepository.save(any(JpaAutomationCompositionDefinition.class))) .thenReturn(new JpaAutomationCompositionDefinition(acmDefinition)); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); inputServiceTemplate.setMetadata(new HashMap<>()); var result = acDefinitionProvider .createAutomationCompositionDefinition(inputServiceTemplate, ELEMENT_NAME, NODE_TYPE); @@ -147,7 +146,7 @@ class AcDefinitionProviderTest { @Test void testUpdateServiceTemplate() { var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); acDefinitionProvider.updateServiceTemplate(UUID.randomUUID(), inputServiceTemplate, ELEMENT_NAME, NODE_TYPE); verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class)); } @@ -155,19 +154,45 @@ class AcDefinitionProviderTest { @Test void testUpdateAcDefinition() { var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)); acDefinitionProvider.updateAcDefinition(acmDefinition, NODE_TYPE); verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class)); } + @Test + void testUpdateAcDefinitionState() { + var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); + var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)); + acmDefinition.setState(AcTypeState.PRIMING); + var jpa = new JpaAutomationCompositionDefinition(acmDefinition); + when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString())) + .thenReturn(Optional.of(jpa)); + acDefinitionProvider.updateAcDefinitionState(acmDefinition.getCompositionId(), AcTypeState.PRIMED, + StateChangeResult.NO_ERROR, false); + verify(acmDefinitionRepository).save(jpa); + } + + @Test + void testUpdateAcDefinitionElement() { + var nodeTemplateState = new NodeTemplateState(); + nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier("name", "1.0.0")); + nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID()); + nodeTemplateState.setState(AcTypeState.PRIMED); + var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class); + var acDefinitionProvider = new AcDefinitionProvider(null, nodeTemplateStateRepository); + acDefinitionProvider.updateAcDefinitionElement(nodeTemplateState, UUID.randomUUID()); + verify(nodeTemplateStateRepository).save(any(JpaNodeTemplateState.class)); + } + @Test void testGetAcDefinition() { var jpa = new JpaAutomationCompositionDefinition(); jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate))); var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa)); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var result = acDefinitionProvider.getAcDefinition(UUID.fromString(jpa.getCompositionId())); assertThat(result).isNotNull(); } @@ -175,7 +200,7 @@ class AcDefinitionProviderTest { @Test void testGetAcDefinitionNotFound() { var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var compositionId = UUID.randomUUID(); assertThatThrownBy(() -> acDefinitionProvider.getAcDefinition(compositionId)) .hasMessage("Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist"); @@ -187,20 +212,24 @@ class AcDefinitionProviderTest { jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate))); var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa)); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); - var result = acDefinitionProvider.findAcDefinition(UUID.fromString(jpa.getCompositionId())); - assertThat(result).isNotNull(); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); + var compositionId = UUID.fromString(jpa.getCompositionId()); + var result = acDefinitionProvider.findAcDefinition(compositionId); + assertThat(result).isNotEmpty(); } @Test - void testGetAllAcDefinitions() { + void getAllAcDefinitionsInTransition() { + var acDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)); + acDefinition.setState(AcTypeState.PRIMING); var jpa = new JpaAutomationCompositionDefinition(); - jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate))); + jpa.fromAuthorative(acDefinition); var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - when(acmDefinitionRepository.findAll()).thenReturn(List.of(jpa)); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); - var result = acDefinitionProvider.getAllAcDefinitions(); - assertThat(result).hasSize(1); + when(acmDefinitionRepository.findByStateIn(List.of(AcTypeState.PRIMING, AcTypeState.DEPRIMING))) + .thenReturn(List.of(jpa)); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); + var result = acDefinitionProvider.getAllAcDefinitionsInTransition(); + assertThat(result).isNotEmpty(); } @Test @@ -212,7 +241,7 @@ class AcDefinitionProviderTest { when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString())) .thenReturn(Optional.of(new JpaAutomationCompositionDefinition(acmDefinition))); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var result = acDefinitionProvider.deleteAcDefintion(acmDefinition.getCompositionId()); assertThat(result).isEqualTo(docServiceTemplate.toAuthorative()); @@ -222,7 +251,7 @@ class AcDefinitionProviderTest { void testDeleteServiceTemplateEmpty() { var compositionId = UUID.randomUUID(); var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); assertThatThrownBy(() -> acDefinitionProvider.deleteAcDefintion(compositionId)) .hasMessage("delete of Automation Composition Definition \"" + compositionId + "\" failed, Automation Composition Definition does not exist"); @@ -236,7 +265,7 @@ class AcDefinitionProviderTest { when(acmDefinitionRepository.findAll(Mockito.>any())) .thenReturn(List.of(new JpaAutomationCompositionDefinition(acmDefinition))); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var result = acDefinitionProvider.getServiceTemplateList(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()); @@ -252,7 +281,7 @@ class AcDefinitionProviderTest { when(acmDefinitionRepository.findAll(Mockito.>any())) .thenReturn(List.of(new JpaAutomationCompositionDefinition(acmDefinition))); - var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository); + var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null); var result = acDefinitionProvider.getServiceTemplateList(null, inputServiceTemplate.getVersion()); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java index b09ddda74..463e958f3 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -40,6 +41,8 @@ import org.mockito.Mockito; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; 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.persistence.concepts.JpaAutomationComposition; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository; @@ -176,6 +179,27 @@ class AutomationCompositionProviderTest { assertEquals(inputAutomationCompositions.getAutomationCompositionList(), acList); } + @Test + void testGetAcInstancesInTransition() { + inputAutomationCompositions.getAutomationCompositionList().get(0).setDeployState(DeployState.DEPLOYING); + inputAutomationCompositions.getAutomationCompositionList().get(1).setLockState(LockState.LOCKING); + inputAutomationCompositionsJpa.get(0).setDeployState(DeployState.DEPLOYING); + inputAutomationCompositionsJpa.get(1).setLockState(LockState.LOCKING); + + List res1 = new ArrayList<>(); + res1.add(inputAutomationCompositionsJpa.get(0)); + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); + when(automationCompositionRepository.findByDeployStateIn(List.of(DeployState.DEPLOYING, + DeployState.UNDEPLOYING, DeployState.DELETING, DeployState.UPDATING, DeployState.MIGRATING))) + .thenReturn(res1); + when(automationCompositionRepository.findByLockStateIn(List.of(LockState.LOCKING, LockState.UNLOCKING))) + .thenReturn(List.of(inputAutomationCompositionsJpa.get(1))); + var acList = automationCompositionProvider.getAcInstancesInTransition(); + assertEquals(inputAutomationCompositions.getAutomationCompositionList(), acList); + } + @Test void testDeleteAutomationComposition() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); -- cgit 1.2.3-korg