diff options
author | saul.gill <saul.gill@est.tech> | 2023-02-15 12:39:43 +0000 |
---|---|---|
committer | saul.gill <saul.gill@est.tech> | 2023-02-15 12:55:23 +0000 |
commit | a85118152983dbc53ce1d0e14712bc66c4177f65 (patch) | |
tree | 5202356c6fb39b4bbb2f78e22c1f26de92eac04a /models/src | |
parent | 06339bee0cf891144ca781983ba99d170b10b2b7 (diff) |
Add undeploy on deregister (acm-side)
State of Ac Elements associated with participant changed on deregister
Issue-ID: POLICY-4499
Change-Id: I54265c13deebd77d654fb843a33f7267d4276b76
Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'models/src')
3 files changed, 115 insertions, 2 deletions
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/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/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" + } + ] +} |