diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-10-16 12:57:37 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-10-16 15:08:36 +0000 |
commit | 7f7d2bfe1673f3334e43029bb81408d3305fa2e2 (patch) | |
tree | 70aa8b88ac15517ff34a481dca04a7dacbafd123 /runtime-acm | |
parent | 9bd7cd21ab1b8afa935f0c1d7f8ef422bf86b19f (diff) |
Fix messages in ACM
Fix TIMEOUT support in MIGRATING.
Avoid conflicts updating AC instance Element instead
of a full AC instance.
Using ExecutorService to send messages to the participant,
the transaction will completed before the message is sent.
Issue-ID: POLICY-4811
Change-Id: I2730ae694c8a5c9edfe500b1fa93cfb3787f32c5
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
2 files changed, 49 insertions, 24 deletions
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 dbed7f790..d7a00f237 100755 --- 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 @@ -25,6 +25,8 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import lombok.AllArgsConstructor; import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; @@ -62,6 +64,8 @@ public class SupervisionAcHandler { private final AcElementPropertiesPublisher acElementPropertiesPublisher; private final AutomationCompositionMigrationPublisher acCompositionMigrationPublisher; + private final ExecutorService executor = Executors.newFixedThreadPool(1); + /** * Handle Deploy an AutomationComposition instance. * @@ -74,6 +78,7 @@ public class SupervisionAcHandler { for (var element : automationComposition.getElements().values()) { if (!DeployState.DEPLOYED.equals(element.getDeployState())) { element.setDeployState(DeployState.DEPLOYING); + element.setMessage(null); } } } else { @@ -82,8 +87,9 @@ public class SupervisionAcHandler { automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionDeployPublisher.send(automationComposition, acDefinition.getServiceTemplate(), startPhase, - true); + executor.execute( + () -> automationCompositionDeployPublisher.send(automationComposition, acDefinition.getServiceTemplate(), + startPhase, true)); } /** @@ -104,9 +110,11 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYING, LockState.NONE); } automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); + automationComposition.setCompositionTargetId(null); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); + executor.execute( + () -> automationCompositionStateChangePublisher.send(automationComposition, startPhase, true)); } /** @@ -129,7 +137,8 @@ public class SupervisionAcHandler { automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); + executor.execute( + () -> automationCompositionStateChangePublisher.send(automationComposition, startPhase, true)); } /** @@ -152,7 +161,8 @@ public class SupervisionAcHandler { automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); + executor.execute( + () -> automationCompositionStateChangePublisher.send(automationComposition, startPhase, true)); } /** @@ -163,7 +173,8 @@ public class SupervisionAcHandler { public void update(AutomationComposition automationComposition) { AcmUtils.setCascadedState(automationComposition, DeployState.UPDATING, automationComposition.getLockState()); automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); - acElementPropertiesPublisher.send(automationComposition); + executor.execute( + () -> acElementPropertiesPublisher.send(automationComposition)); } /** @@ -177,7 +188,8 @@ public class SupervisionAcHandler { automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); + executor.execute( + () -> automationCompositionStateChangePublisher.send(automationComposition, startPhase, true)); } /** @@ -227,9 +239,10 @@ public class SupervisionAcHandler { for (var element : automationComposition.getElements().values()) { if (element.getParticipantId().equals(automationCompositionAckMessage.getParticipantId())) { element.setDeployState(DeployState.DELETED); + automationCompositionProvider.updateAutomationCompositionElement(element, + automationComposition.getInstanceId()); } } - automationCompositionProvider.updateAutomationComposition(automationComposition); } else { LOGGER.warn("Empty AutomationCompositionResultMap {} {}", automationCompositionAckMessage.getAutomationCompositionId(), @@ -251,8 +264,9 @@ public class SupervisionAcHandler { StateChangeResult stateChangeResult) { var updated = false; boolean inProgress = !StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult()); - if (inProgress) { + if (inProgress && !stateChangeResult.equals(automationComposition.getStateChangeResult())) { automationComposition.setStateChangeResult(stateChangeResult); + updated = true; } for (var acElementAck : automationCompositionResultSet) { @@ -265,7 +279,8 @@ public class SupervisionAcHandler { element.setDeployState(acElementAck.getValue().getDeployState()); element.setLockState(acElementAck.getValue().getLockState()); element.setRestarting(null); - updated = true; + automationCompositionProvider.updateAutomationCompositionElement(element, + automationComposition.getInstanceId()); } } @@ -274,6 +289,7 @@ public class SupervisionAcHandler { .map(AutomationCompositionElement::getRestarting).filter(Objects::nonNull).findAny(); if (restarting.isEmpty()) { automationComposition.setRestarting(null); + updated = true; } } @@ -289,6 +305,7 @@ public class SupervisionAcHandler { public void migrate(AutomationComposition automationComposition, UUID compositionTargetId) { AcmUtils.setCascadedState(automationComposition, DeployState.MIGRATING, LockState.LOCKED); automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); - acCompositionMigrationPublisher.send(automationComposition, compositionTargetId); + executor.execute( + () -> acCompositionMigrationPublisher.send(automationComposition, compositionTargetId)); } } 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 index d3f859843..f39970f32 100755 --- 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 @@ -24,6 +24,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; @@ -41,6 +43,7 @@ import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; 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.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.StateChangeResult; @@ -70,7 +73,8 @@ class SupervisionAcHandlerTest { automationComposition, DeployState.DEPLOYED, LockState.UNLOCKED); handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage); - verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(3)) + .updateAutomationCompositionElement(any(AutomationCompositionElement.class), any()); } private AutomationCompositionDeployAck getAutomationCompositionDeployAck(ParticipantMessageType messageType, @@ -83,6 +87,7 @@ class SupervisionAcHandlerTest { } automationCompositionAckMessage.setAutomationCompositionId(automationComposition.getInstanceId()); automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId()); + automationCompositionAckMessage.setStateChangeResult(StateChangeResult.NO_ERROR); return automationCompositionAckMessage; } @@ -121,6 +126,7 @@ class SupervisionAcHandlerTest { var automationCompositionAckMessage = new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK); + automationCompositionAckMessage.setStateChangeResult(StateChangeResult.NO_ERROR); for (var element : automationComposition.getElements().values()) { element.setDeployState(DeployState.DEPLOYED); } @@ -142,7 +148,8 @@ class SupervisionAcHandlerTest { handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); - verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider) + .updateAutomationCompositionElement(any(AutomationCompositionElement.class), any()); } @Test @@ -159,8 +166,8 @@ class SupervisionAcHandlerTest { automationComposition.setStateChangeResult(StateChangeResult.FAILED); handler.deploy(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(automationComposition); - verify(automationCompositionDeployPublisher).send(automationComposition, acDefinition.getServiceTemplate(), 0, - true); + verify(automationCompositionDeployPublisher, timeout(1000)) + .send(automationComposition, acDefinition.getServiceTemplate(), 0, true); } @Test @@ -177,7 +184,7 @@ class SupervisionAcHandlerTest { handler.undeploy(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); - verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean()); } @Test @@ -197,7 +204,7 @@ class SupervisionAcHandlerTest { .forEach(element -> element.setDeployState(DeployState.UNDEPLOYING)); handler.undeploy(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(automationComposition); - verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean()); } @Test @@ -214,7 +221,7 @@ class SupervisionAcHandlerTest { handler.unlock(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); - verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean()); } @Test @@ -233,7 +240,7 @@ class SupervisionAcHandlerTest { handler.unlock(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); - verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean()); } @Test @@ -250,7 +257,7 @@ class SupervisionAcHandlerTest { handler.lock(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); - verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean()); } @Test @@ -269,7 +276,7 @@ class SupervisionAcHandlerTest { handler.lock(automationComposition, acDefinition); verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); - verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + verify(acStateChangePublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt(), anyBoolean()); } @Test @@ -293,7 +300,8 @@ class SupervisionAcHandlerTest { handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); - verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider) + .updateAutomationCompositionElement(any(AutomationCompositionElement.class), any()); } @Test @@ -305,7 +313,7 @@ class SupervisionAcHandlerTest { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock"); handler.update(automationComposition); - verify(acElementPropertiesPublisher).send(any(AutomationComposition.class)); + verify(acElementPropertiesPublisher, timeout(1000)).send(any(AutomationComposition.class)); } @Test @@ -317,6 +325,6 @@ class SupervisionAcHandlerTest { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate"); handler.migrate(automationComposition, UUID.randomUUID()); - verify(acCompositionMigrationPublisher).send(any(AutomationComposition.class), any()); + verify(acCompositionMigrationPublisher, timeout(1000)).send(any(AutomationComposition.class), any()); } } |