diff options
Diffstat (limited to 'runtime-acm')
6 files changed, 91 insertions, 36 deletions
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 02e5b1ac6..4665fec37 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 @@ -196,8 +196,8 @@ public class AutomationCompositionInstantiationProvider { "Automation composition state is still " + automationComposition.getDeployState()); } var response = new InstantiationResponse(); - automationComposition = - automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId()); + var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()); + supervisionAcHandler.delete(automationComposition, acDefinition); response.setInstanceId(automationComposition.getInstanceId()); response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier()); return response; diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java index 0eb4ecbd9..8032b4d5d 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java @@ -109,6 +109,19 @@ public class SupervisionAcHandler { } /** + * Handle Delete an AutomationComposition instance. + * + * @param automationComposition the AutomationComposition + * @param acDefinition the AutomationCompositionDefinition + */ + public void delete(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + AcmUtils.setCascadedState(automationComposition, DeployState.DELETING, LockState.NONE); + automationCompositionProvider.updateAutomationComposition(automationComposition); + var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); + } + + /** * Handle a AutomationComposition deploy acknowledge message from a participant. * * @param automationCompositionAckMessage the AutomationCompositionAck message received from a participant @@ -139,19 +152,33 @@ public class SupervisionAcHandler { } private void setAcElementStateInDb(AutomationCompositionDeployAck automationCompositionAckMessage) { - if (automationCompositionAckMessage.getAutomationCompositionResultMap() != null) { - var automationComposition = automationCompositionProvider - .findAutomationComposition(automationCompositionAckMessage.getAutomationCompositionId()); - if (automationComposition.isPresent()) { - var updated = updateState(automationComposition.get(), - automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet()); - if (updated) { - automationCompositionProvider.updateAutomationComposition(automationComposition.get()); - } + var automationComposition = automationCompositionProvider + .findAutomationComposition(automationCompositionAckMessage.getAutomationCompositionId()); + if (automationComposition.isEmpty()) { + LOGGER.warn("AutomationComposition not found in database {}", + automationCompositionAckMessage.getAutomationCompositionId()); + return; + } + + if (automationCompositionAckMessage.getAutomationCompositionResultMap() == null + || automationCompositionAckMessage.getAutomationCompositionResultMap().isEmpty()) { + if (DeployState.DELETING.equals(automationComposition.get().getDeployState())) { + // scenario when Automation Composition instance has never been deployed + automationComposition.get().getElements().values() + .forEach(element -> element.setDeployState(DeployState.DELETED)); + automationCompositionProvider.updateAutomationComposition(automationComposition.get()); } else { - LOGGER.warn("AutomationComposition not found in database {}", - automationCompositionAckMessage.getAutomationCompositionId()); + LOGGER.warn("Empty AutomationCompositionResultMap {} {}", + automationCompositionAckMessage.getAutomationCompositionId(), + automationCompositionAckMessage.getMessage()); } + return; + } + + var updated = updateState(automationComposition.get(), + automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet()); + if (updated) { + automationCompositionProvider.updateAutomationComposition(automationComposition.get()); } } @@ -163,15 +190,9 @@ public class SupervisionAcHandler { if (element != null) { element.setDeployState(acElementAck.getValue().getDeployState()); element.setLockState(acElementAck.getValue().getLockState()); - if (DeployState.DEPLOYED.equals(element.getDeployState())) { - element.setOperationalState(acElementAck.getValue().getOperationalState()); - element.setUseState(acElementAck.getValue().getUseState()); - element.setStatusProperties(acElementAck.getValue().getStatusProperties()); - } else { - element.setOperationalState(null); - element.setUseState(null); - element.setStatusProperties(Map.of()); - } + element.setOperationalState(acElementAck.getValue().getOperationalState()); + element.setUseState(acElementAck.getValue().getUseState()); + element.setStatusProperties(acElementAck.getValue().getStatusProperties()); updated = true; } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java index 7ee7267e2..e23d79d57 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java @@ -133,14 +133,7 @@ public class SupervisionScanner { LOGGER.debug("automation composition scan: transition state {} {} ", automationComposition.getDeployState(), automationComposition.getLockState()); - var deployState = automationComposition.getDeployState(); - automationComposition.setDeployState(AcmUtils.deployCompleted(deployState)); - automationComposition - .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState())); - automationCompositionProvider.updateAutomationComposition(automationComposition); - - // Clear missed report counter on automation composition - clearFaultAndCounter(automationComposition); + complete(automationComposition); } else { LOGGER.debug("automation composition scan: transition from state {} to {} not completed", automationComposition.getDeployState(), automationComposition.getLockState()); @@ -163,6 +156,21 @@ public class SupervisionScanner { } } + private void complete(final AutomationComposition automationComposition) { + var deployState = automationComposition.getDeployState(); + automationComposition.setDeployState(AcmUtils.deployCompleted(deployState)); + automationComposition + .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState())); + if (DeployState.DELETED.equals(automationComposition.getDeployState())) { + automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId()); + } else { + automationCompositionProvider.updateAutomationComposition(automationComposition); + } + + // Clear missed report counter on automation composition + clearFaultAndCounter(automationComposition); + } + private void clearFaultAndCounter(AutomationComposition automationComposition) { automationCompositionCounter.clear(automationComposition.getInstanceId()); phaseMap.remove(automationComposition.getInstanceId()); 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 9f39d8dc6..faf356c22 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 @@ -95,8 +95,9 @@ class AutomationCompositionInstantiationProviderTest { var compositionId = acDefinition.getCompositionId(); when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); var acProvider = mock(AutomationCompositionProvider.class); - var instantiationProvider = - new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null); + var supervisionAcHandler = mock(SupervisionAcHandler.class); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + null, supervisionAcHandler); var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); automationCompositionCreate.setCompositionId(compositionId); @@ -136,7 +137,7 @@ class AutomationCompositionInstantiationProviderTest { instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getCompositionId(), automationCompositionCreate.getInstanceId()); - verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getInstanceId()); + verify(supervisionAcHandler).delete(any(), any()); } @Test @@ -146,9 +147,10 @@ class AutomationCompositionInstantiationProviderTest { var acProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); + var supervisionAcHandler = mock(SupervisionAcHandler.class); var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null); + acDefinitionProvider, null, supervisionAcHandler); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -168,6 +170,7 @@ class AutomationCompositionInstantiationProviderTest { when(acProvider.deleteAutomationComposition(instanceId)).thenReturn(automationComposition); instantiationProvider.deleteAutomationComposition(compositionId, instanceId); + verify(supervisionAcHandler).delete(any(), any()); } private void assertThatDeleteThrownBy(AutomationComposition automationComposition, diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java index fe0a477f9..5380d67a6 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java @@ -42,6 +42,7 @@ import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; 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.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.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; @@ -268,7 +269,8 @@ class InstantiationControllerTest extends CommonRestController { var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(compositionId, automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion()); - assertThat(automationCompositionsFromDb.getAutomationCompositionList()).isEmpty(); + assertEquals(DeployState.DELETING, + automationCompositionsFromDb.getAutomationCompositionList().get(0).getDeployState()); } @Test 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 index 032468a56..8ead9a7c0 100644 --- 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 @@ -101,7 +101,28 @@ class SupervisionScannerTest { acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + } + + @Test + void testScannerDelete() { + var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); + automationComposition.setDeployState(DeployState.DELETING); + automationComposition.setLockState(LockState.NONE); + 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, acDefinitionProvider, + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); + supervisionScanner.run(false); + + verify(automationCompositionProvider).deleteAutomationComposition(automationComposition.getInstanceId()); } @Test |