From a769d1215cff61aa8ec1cb026cd91c3318c5eee5 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Wed, 27 Sep 2023 11:03:48 +0100 Subject: Add migration publisher message in ACM runtime Issue-ID: POLICY-4823 Change-Id: Id4480a0800e41ec8e2f0f9931a9a93752b2ef952 Signed-off-by: FrancescoFioraEst --- ...mationCompositionInstantiationProviderTest.java | 73 ++++++++++++++++++++-- .../supervision/SupervisionAcHandlerTest.java | 38 +++++++---- .../supervision/SupervisionScannerTest.java | 40 +++++++++++- .../supervision/comm/SupervisionMessagesTest.java | 12 +++- 4 files changed, 144 insertions(+), 19 deletions(-) mode change 100644 => 100755 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java mode change 100644 => 100755 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java mode change 100644 => 100755 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java (limited to 'runtime-acm/src/test/java') 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 308eed5da..8f7a4fe8f 100755 --- 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 @@ -79,7 +79,7 @@ class AutomationCompositionInstantiationProviderTest { + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\"" + " INVALID, Not found\n"; private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n" - + " item \"ServiceTemplate\" value \"\" INVALID," + + " item \"ServiceTemplate\" value \"%s\" INVALID," + " Commissioned automation composition definition not found\n"; private static final String DO_NOT_MATCH = " do not match with "; @@ -94,11 +94,12 @@ class AutomationCompositionInstantiationProviderTest { } @Test - void testInstantiationCrud() throws AutomationCompositionException { + void testInstantiationCrud() { var acDefinitionProvider = mock(AcDefinitionProvider.class); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var compositionId = acDefinition.getCompositionId(); when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); + when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition); var acProvider = mock(AutomationCompositionProvider.class); var supervisionAcHandler = mock(SupervisionAcHandler.class); var acmParticipantProvider = mock(AcmParticipantProvider.class); @@ -199,6 +200,14 @@ class AutomationCompositionInstantiationProviderTest { () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) .hasMessageMatching( "Not allowed to update in the state " + automationCompositionUpdate.getDeployState()); + + automationCompositionUpdate.setDeployState(DeployState.UPDATING); + automationCompositionUpdate.setLockState(LockState.LOCKED); + automationCompositionUpdate.setCompositionTargetId(UUID.randomUUID()); + assertThatThrownBy( + () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) + .hasMessageMatching( + "Not allowed to migrate in the state " + automationCompositionUpdate.getDeployState()); } @Test @@ -261,6 +270,48 @@ class AutomationCompositionInstantiationProviderTest { + " There is a restarting process in composition\n"); } + @Test + void testInstantiationMigration() { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var compositionId = acDefinition.getCompositionId(); + when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); + + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + automationComposition.setCompositionId(compositionId); + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.LOCKED); + automationComposition.setCompositionTargetId(UUID.randomUUID()); + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) + .thenReturn(automationComposition); + when(acProvider.updateAutomationComposition(automationComposition)).thenReturn(automationComposition); + + var supervisionAcHandler = mock(SupervisionAcHandler.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + null, supervisionAcHandler, acmParticipantProvider, new AcRuntimeParameterGroup()); + + assertThatThrownBy(() -> instantiationProvider + .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition)) + .hasMessageMatching( + String.format(AC_DEFINITION_NOT_FOUND, automationComposition.getCompositionTargetId())); + + var acDefinitionTarget = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var compositionTargetId = acDefinitionTarget.getCompositionId(); + when(acDefinitionProvider.findAcDefinition(compositionTargetId)).thenReturn(Optional.of(acDefinitionTarget)); + + automationComposition.setCompositionTargetId(compositionTargetId); + + var instantiationResponse = instantiationProvider + .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition); + + verify(supervisionAcHandler).migrate(any(), any()); + verify(acProvider).updateAutomationComposition(automationComposition); + InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationComposition); + } + @Test void testInstantiationDelete() { var automationComposition = @@ -268,6 +319,10 @@ class AutomationCompositionInstantiationProviderTest { automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); var acProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var compositionId = acDefinition.getCompositionId(); + when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition); + automationComposition.setCompositionId(compositionId); var supervisionAcHandler = mock(SupervisionAcHandler.class); var acmParticipantProvider = mock(AcmParticipantProvider.class); var acRuntimeParameterGroup = mock(AcRuntimeParameterGroup.class); @@ -280,7 +335,6 @@ class AutomationCompositionInstantiationProviderTest { var wrongCompositionId = UUID.randomUUID(); var instanceId = automationComposition.getInstanceId(); - var compositionId = automationComposition.getCompositionId(); assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(wrongCompositionId, instanceId)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); @@ -390,10 +444,10 @@ class AutomationCompositionInstantiationProviderTest { var compositionId = automationComposition.getCompositionId(); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) - .hasMessageMatching(AC_DEFINITION_NOT_FOUND); + .hasMessageMatching(String.format(AC_DEFINITION_NOT_FOUND, compositionId)); assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition)) - .hasMessageMatching(AC_DEFINITION_NOT_FOUND); + .hasMessageMatching(String.format(AC_DEFINITION_NOT_FOUND, compositionId)); } @Test @@ -422,6 +476,15 @@ class AutomationCompositionInstantiationProviderTest { assertThatThrownBy(() -> provider.compositionInstanceState(wrongCompositionId, automationComposition.getInstanceId(), new AcInstanceStateUpdate())) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); + + var compositionTargetId = UUID.randomUUID(); + automationComposition.setCompositionTargetId(compositionTargetId); + assertThatThrownBy( + () -> provider.getAutomationComposition(wrongCompositionId, automationComposition.getInstanceId())) + .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); + + var result = provider.getAutomationComposition(compositionTargetId, automationComposition.getInstanceId()); + assertThat(result).isNotNull(); } @Test diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java old mode 100644 new mode 100755 index 1f63c3da8..d3f859843 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java @@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; +import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionMigrationPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; @@ -62,7 +63,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var automationCompositionAckMessage = getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK, @@ -101,7 +102,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); @@ -136,7 +137,8 @@ class SupervisionAcHandlerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionAcHandler(automationCompositionProvider, - mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher, null); + mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher, null, + null); handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); @@ -148,7 +150,7 @@ class SupervisionAcHandlerTest { var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionProvider = mock(AutomationCompositionProvider.class); var handler = new SupervisionAcHandler(automationCompositionProvider, automationCompositionDeployPublisher, - mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class)); + mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); @@ -167,7 +169,7 @@ class SupervisionAcHandlerTest { var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -184,7 +186,7 @@ class SupervisionAcHandlerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); @@ -204,7 +206,7 @@ class SupervisionAcHandlerTest { var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -221,7 +223,7 @@ class SupervisionAcHandlerTest { var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -240,7 +242,7 @@ class SupervisionAcHandlerTest { var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -257,7 +259,7 @@ class SupervisionAcHandlerTest { var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -287,7 +289,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), - mock(AcElementPropertiesPublisher.class)); + mock(AcElementPropertiesPublisher.class), null); handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); @@ -299,10 +301,22 @@ class SupervisionAcHandlerTest { var acElementPropertiesPublisher = mock(AcElementPropertiesPublisher.class); var handler = new SupervisionAcHandler(mock(AutomationCompositionProvider.class), mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), - acElementPropertiesPublisher); + acElementPropertiesPublisher, null); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock"); handler.update(automationComposition); verify(acElementPropertiesPublisher).send(any(AutomationComposition.class)); } + + @Test + void testMigrate() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acCompositionMigrationPublisher = mock(AutomationCompositionMigrationPublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, null, null, null, + acCompositionMigrationPublisher); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate"); + handler.migrate(automationComposition, UUID.randomUUID()); + verify(acCompositionMigrationPublisher).send(any(AutomationComposition.class), any()); + } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java old mode 100644 new mode 100755 index 5fe4f4c25..a1fad46b1 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -20,6 +20,7 @@ package org.onap.policy.clamp.acm.runtime.supervision; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -207,13 +208,20 @@ class SupervisionScannerTest { automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); + automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); scannerObj2.run(); verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); + assertEquals(StateChangeResult.TIMEOUT, automationComposition.getStateChangeResult()); + for (Map.Entry entry : automationComposition.getElements().entrySet()) { + entry.getValue().setDeployState(DeployState.DEPLOYED); + } + scannerObj2.run(); + assertEquals(StateChangeResult.NO_ERROR, automationComposition.getStateChangeResult()); } @Test - void testSendAutomationCompositionMsgUpdate() { + void testSendAutomationCompositionMsgStartPhase() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); automationComposition.setDeployState(DeployState.DEPLOYING); automationComposition.setLockState(LockState.NONE); @@ -246,6 +254,36 @@ class SupervisionScannerTest { any(ToscaServiceTemplate.class), anyInt(), anyBoolean()); } + @Test + void testSendAutomationCompositionMigrate() { + var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); + automationComposition.setDeployState(DeployState.MIGRATING); + var compositionTargetId = UUID.randomUUID(); + automationComposition.setCompositionTargetId(compositionTargetId); + automationComposition.setLockState(LockState.LOCKED); + for (var element : automationComposition.getElements().values()) { + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.LOCKED); + } + + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) + .thenReturn(List.of(automationComposition)); + + var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); + var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); + + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); + + supervisionScanner.run(); + verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); + assertEquals(DeployState.DEPLOYED, automationComposition.getDeployState()); + assertEquals(compositionTargetId, automationComposition.getCompositionId()); + } + @Test void testSendAutomationCompositionMsgUnlocking() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java old mode 100644 new mode 100755 index 85444ed2f..87e00da93 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -226,6 +226,17 @@ class SupervisionMessagesTest { verify(topicSink).send(anyString()); } + @Test + void testAutomationCompositionMigrationPublisher() { + var publisher = new AutomationCompositionMigrationPublisher(); + var topicSink = mock(TopicSink.class); + publisher.active(List.of(topicSink)); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + publisher.send(automationComposition, UUID.randomUUID()); + verify(topicSink).send(anyString()); + } + @Test void testParticipantRestartPublisher() { var publisher = new ParticipantRestartPublisher(CommonTestData.getTestParamaterGroup()); @@ -289,5 +300,4 @@ class SupervisionMessagesTest { acStateChangeAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck); verify(supervisionHandler).handleAutomationCompositionStateChangeAckMessage(automationCompositionAck); } - } -- cgit 1.2.3-korg