diff options
Diffstat (limited to 'runtime-acm')
3 files changed, 30 insertions, 12 deletions
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 c4cebb430..db67e5eea 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 @@ -198,7 +198,7 @@ public class SupervisionScanner { if (nextSpNotCompleted != automationComposition.getPhase()) { sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted); } else { - handleTimeout(automationComposition); + handleTimeout(automationComposition, serviceTemplate); } } } @@ -217,7 +217,7 @@ public class SupervisionScanner { if (completed) { complete(automationComposition, serviceTemplate); } else { - handleTimeout(automationComposition); + handleTimeout(automationComposition, serviceTemplate); } } @@ -250,11 +250,11 @@ public class SupervisionScanner { automationComposition.getDeployState(), automationComposition.getLockState()); if (minStageNotCompleted != automationComposition.getPhase()) { - savePahese(automationComposition, minStageNotCompleted); + savePhase(automationComposition, minStageNotCompleted); LOGGER.debug("retry message AutomationCompositionMigration"); automationCompositionMigrationPublisher.send(automationComposition, minStageNotCompleted); } else { - handleTimeout(automationComposition); + handleTimeout(automationComposition, serviceTemplate); } } } @@ -300,10 +300,12 @@ public class SupervisionScanner { acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT); acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), acDefinition.getStateChangeResult()); + participantSyncPublisher.sendSync(acDefinition, null); } } - private void handleTimeout(AutomationComposition automationComposition) { + private void handleTimeout(AutomationComposition automationComposition, + ToscaServiceTemplate serviceTemplate) { LOGGER.debug("automation composition scan: transition from state {} to {} {} not completed", automationComposition.getDeployState(), automationComposition.getLockState(), automationComposition.getSubState()); @@ -318,10 +320,11 @@ public class SupervisionScanner { LOGGER.debug("Report timeout for the ac instance {}", automationComposition.getInstanceId()); automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT); automationCompositionProvider.updateAcState(automationComposition); + participantSyncPublisher.sendSync(serviceTemplate, automationComposition); } } - private void savePahese(AutomationComposition automationComposition, int startPhase) { + private void savePhase(AutomationComposition automationComposition, int startPhase) { automationComposition.setLastMsg(TimestampHelper.now()); automationComposition.setPhase(startPhase); automationCompositionProvider.updateAcState(automationComposition); @@ -329,7 +332,7 @@ public class SupervisionScanner { private void sendAutomationCompositionMsg(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate, int startPhase) { - savePahese(automationComposition, startPhase); + savePhase(automationComposition, startPhase); if (DeployState.DEPLOYING.equals(automationComposition.getDeployState())) { LOGGER.debug("retry message AutomationCompositionDeploy"); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java index eb1db6f0e..d90b6f667 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java @@ -101,6 +101,7 @@ public class ParticipantSyncPublisher extends AbstractParticipantPublisher<Parti message.getExcludeReplicas().add(excludeReplicaId); } message.setState(acDefinition.getState()); + message.setStateChangeResult(acDefinition.getStateChangeResult()); message.setMessageId(UUID.randomUUID()); message.setTimestamp(Instant.now()); if (AcTypeState.COMMISSIONED.equals(acDefinition.getState())) { @@ -131,6 +132,7 @@ public class ParticipantSyncPublisher extends AbstractParticipantPublisher<Parti syncAc.setAutomationCompositionId(automationComposition.getInstanceId()); syncAc.setDeployState(automationComposition.getDeployState()); syncAc.setLockState(automationComposition.getLockState()); + syncAc.setStateChangeResult(automationComposition.getStateChangeResult()); if (DeployState.DELETED.equals(automationComposition.getDeployState())) { message.setDelete(true); } else { 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 5cefd5f09..17cc8ad3b 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 @@ -115,10 +115,11 @@ class SupervisionScannerTest { void testAcDefinitionPrimeTimeout() { var acDefinition = createAutomationCompositionDefinition(AcTypeState.PRIMING, StateChangeResult.NO_ERROR); var acDefinitionProvider = createAcDefinitionProvider(acDefinition); + var participantSyncPublisher = mock(ParticipantSyncPublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider, mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class), - mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup); + participantSyncPublisher, null, acRuntimeParameterGroup); supervisionScanner.run(); // Ac Definition in Priming state verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any()); @@ -126,25 +127,30 @@ class SupervisionScannerTest { acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider, mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class), - mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup); + participantSyncPublisher, null, acRuntimeParameterGroup); supervisionScanner.run(); // set Timeout verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), StateChangeResult.TIMEOUT); + verify(participantSyncPublisher).sendSync(any(AutomationCompositionDefinition.class), any()); clearInvocations(acDefinitionProvider); + clearInvocations(participantSyncPublisher); acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT); supervisionScanner.run(); // already in Timeout verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any()); + verify(participantSyncPublisher, times(0)).sendSync(acDefinition, null); clearInvocations(acDefinitionProvider); + clearInvocations(participantSyncPublisher); // retry by the user acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR); supervisionScanner.run(); // set Timeout verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), StateChangeResult.TIMEOUT); + verify(participantSyncPublisher).sendSync(any(AutomationCompositionDefinition.class), any()); clearInvocations(acDefinitionProvider); for (var element : acDefinition.getElementStateMap().values()) { @@ -263,31 +269,38 @@ class SupervisionScannerTest { when(automationCompositionProvider.updateAcState(any())).thenReturn(automationComposition); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var participantSyncPublisher = mock(ParticipantSyncPublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); // verify timeout scenario var scannerObj2 = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, - mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup); + participantSyncPublisher, null, acRuntimeParameterGroup); automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationComposition.setLastMsg(TimestampHelper.now()); scannerObj2.run(); - verify(automationCompositionProvider, times(1)).updateAcState(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAcState(any(AutomationComposition.class)); + verify(participantSyncPublisher).sendSync(any(ToscaServiceTemplate.class), any(AutomationComposition.class)); assertEquals(StateChangeResult.TIMEOUT, automationComposition.getStateChangeResult()); //already in TIMEOUT clearInvocations(automationCompositionProvider); + clearInvocations(participantSyncPublisher); scannerObj2.run(); verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); + verify(participantSyncPublisher, times(0)) + .sendSync(any(ToscaServiceTemplate.class), any(AutomationComposition.class)); clearInvocations(automationCompositionProvider); + clearInvocations(participantSyncPublisher); for (Map.Entry<UUID, AutomationCompositionElement> entry : automationComposition.getElements().entrySet()) { entry.getValue().setDeployState(DeployState.DEPLOYED); } scannerObj2.run(); - verify(automationCompositionProvider, times(1)).updateAcState(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAcState(any(AutomationComposition.class)); + verify(participantSyncPublisher).sendSync(any(ToscaServiceTemplate.class), any(AutomationComposition.class)); assertEquals(StateChangeResult.NO_ERROR, automationComposition.getStateChangeResult()); } |