diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-06-14 13:57:07 +0100 |
---|---|---|
committer | Adheli Tavares <adheli.tavares@est.tech> | 2023-06-15 15:01:34 +0000 |
commit | a2320d29b9373041db88395d9fdda7ea84d38807 (patch) | |
tree | 4088c3e0941bcf4d2988a503471c55db4085986d /participant | |
parent | dd44112fcda0951dc76861cacfdabbffc9fe8579 (diff) |
Add support for Prime Deprime Failure Handling in Intermediary
Issue-ID: POLICY-4715
Change-Id: Iab48e6c32c7aedcef9773614a61436398b059a49
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
7 files changed, 100 insertions, 30 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java index 592513258..96d96cac9 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java @@ -46,7 +46,6 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp private final AutomationCompositionOutHandler automationCompositionHandler; private final CacheProvider cacheProvider; - @Override public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState, LockState lockState, StateChangeResult stateChangeResult, String message) { @@ -69,6 +68,6 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp @Override public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult, String message) { - // TODO Auto-generated method stub + automationCompositionHandler.updateCompositionState(compositionId, state, stateChangeResult, message); } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java index 0fcd5ecc4..7e713654d 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java @@ -28,6 +28,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; @@ -201,8 +202,7 @@ public class AutomationCompositionHandler { public void handleAutomationCompositionDeploy(AutomationCompositionDeploy deployMsg) { if (deployMsg.getParticipantUpdatesList().isEmpty()) { - LOGGER.warn("No AutomationCompositionElement deploy in message {}", - deployMsg.getAutomationCompositionId()); + LOGGER.warn("No AutomationCompositionElement deploy in message {}", deployMsg.getAutomationCompositionId()); return; } @@ -325,4 +325,31 @@ public class AutomationCompositionHandler { LOGGER.debug("Automation composition element Unlock failed {}", automationComposition.getInstanceId()); } } + + /** + * Handles prime a Composition Definition. + * + * @param compositionId the compositionId + * @param list the list of AutomationCompositionElementDefinition + */ + public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> list) { + try { + listener.prime(compositionId, list); + } catch (PfModelException e) { + LOGGER.debug("Composition prime failed {}", compositionId); + } + } + + /** + * Handles deprime a Composition Definition. + * + * @param compositionId the compositionId + */ + public void deprime(UUID compositionId) { + try { + listener.deprime(compositionId); + } catch (PfModelException e) { + LOGGER.debug("Composition deprime failed {}", compositionId); + } + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java index 665baee42..2c34652c8 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java @@ -26,6 +26,7 @@ import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; 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.AutomationCompositionElementInfo; @@ -36,6 +37,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -196,4 +198,25 @@ public class AutomationCompositionOutHandler { elementInfo.setOutProperties(element.getOutProperties()); return elementInfo; } + + /** + * Update Composition State for prime and deprime. + * + * @param compositionId the composition id + * @param state the Composition State + * @param stateChangeResult the indicator if error occurs + * @param message the message + */ + public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult, + String message) { + var participantPrimeAck = new ParticipantPrimeAck(); + participantPrimeAck.setCompositionId(compositionId); + participantPrimeAck.setMessage(message); + participantPrimeAck.setResult(true); + participantPrimeAck.setCompositionState(state); + participantPrimeAck.setStateChangeResult(stateChangeResult); + participantPrimeAck.setParticipantId(cacheProvider.getParticipantId()); + participantPrimeAck.setState(ParticipantState.ON_LINE); + publisher.sendParticipantPrimeAck(participantPrimeAck); + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java index 1e5caad15..0e7e193f6 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java @@ -25,7 +25,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; import io.micrometer.core.annotation.Timed; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; @@ -39,7 +38,6 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; @@ -188,25 +186,12 @@ public class ParticipantHandler { } } cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list); + automationCompositionHandler.prime(participantPrimeMsg.getCompositionId(), list); } else { // deprime cacheProvider.removeElementDefinition(participantPrimeMsg.getCompositionId()); + automationCompositionHandler.deprime(participantPrimeMsg.getCompositionId()); } - sendParticipantPrimeAck(participantPrimeMsg.getMessageId(), participantPrimeMsg.getCompositionId()); - } - - /** - * Method to send ParticipantPrimeAck message to automation composition runtime. - */ - private void sendParticipantPrimeAck(UUID messageId, UUID compositionId) { - var participantPrimeAck = new ParticipantPrimeAck(); - participantPrimeAck.setResponseTo(messageId); - participantPrimeAck.setCompositionId(compositionId); - participantPrimeAck.setMessage("Participant Prime Ack message"); - participantPrimeAck.setResult(true); - participantPrimeAck.setParticipantId(cacheProvider.getParticipantId()); - participantPrimeAck.setState(ParticipantState.ON_LINE); - publisher.sendParticipantPrimeAck(participantPrimeAck); } /** diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java index 7e0c3da7f..b4397b49f 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -35,6 +36,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; @@ -196,4 +198,25 @@ class AutomationCompositionHandlerTest { ach.handleAutomationCompositionDeploy(deployMsg); verify(listener, times(automationComposition.getElements().size())).deploy(any(), any(), any()); } + + @Test + void handleComposiotPrimeTest() throws PfModelException { + var listener = mock(AutomationCompositionElementListener.class); + var ach = new AutomationCompositionHandler(mock(CacheProvider.class), mock(ParticipantMessagePublisher.class), + listener); + var compositionId = UUID.randomUUID(); + var list = List.of(new AutomationCompositionElementDefinition()); + ach.prime(compositionId, list); + verify(listener).prime(compositionId, list); + } + + @Test + void handleComposiotDeprimeTest() throws PfModelException { + var listener = mock(AutomationCompositionElementListener.class); + var ach = new AutomationCompositionHandler(mock(CacheProvider.class), mock(ParticipantMessagePublisher.class), + listener); + var compositionId = UUID.randomUUID(); + ach.deprime(compositionId); + verify(listener).deprime(compositionId); + } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java index 3f022dcf2..d7bc2e687 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandlerTest.java @@ -32,10 +32,12 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; 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; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; class AutomationCompositionOutHandlerTest { @@ -135,8 +137,18 @@ class AutomationCompositionOutHandlerTest { when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); var elementId = automationComposition.getElements().values().iterator().next().getId(); - acOutHandler.sendAcElementInfo(automationComposition.getInstanceId(), - elementId, "", "", Map.of()); + acOutHandler.sendAcElementInfo(automationComposition.getInstanceId(), elementId, "", "", Map.of()); verify(publisher).sendParticipantStatus(any(ParticipantStatus.class)); } + + @Test + void updateCompositionStateTest() { + var cacheProvider = mock(CacheProvider.class); + when(cacheProvider.getParticipantId()).thenReturn(UUID.randomUUID()); + var publisher = mock(ParticipantMessagePublisher.class); + var acOutHandler = new AutomationCompositionOutHandler(publisher, cacheProvider); + acOutHandler.updateCompositionState(UUID.randomUUID(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, + "Primed"); + verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class)); + } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java index 6cad99fa1..895d4ed59 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java @@ -43,7 +43,6 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; @@ -160,15 +159,16 @@ class ParticipantHandlerTest { var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); var publisher = mock(ParticipantMessagePublisher.class); - var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class), - mock(AutomationCompositionOutHandler.class), publisher, cacheProvider); + var acHandler = mock(AutomationCompositionHandler.class); + var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class), + publisher, cacheProvider); var participantPrime = new ParticipantPrime(); participantPrime.setCompositionId(UUID.randomUUID()); participantPrime.setParticipantDefinitionUpdates(List.of(createParticipantDefinition())); participantHandler.handleParticipantPrime(participantPrime); verify(cacheProvider).addElementDefinition(any(), any()); - verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class)); + verify(acHandler).prime(any(), any()); } @Test @@ -176,14 +176,15 @@ class ParticipantHandlerTest { var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); var publisher = mock(ParticipantMessagePublisher.class); - var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class), - mock(AutomationCompositionOutHandler.class), publisher, cacheProvider); + var acHandler = mock(AutomationCompositionHandler.class); + var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class), + publisher, cacheProvider); var participantPrime = new ParticipantPrime(); var compositionId = UUID.randomUUID(); participantPrime.setCompositionId(compositionId); participantHandler.handleParticipantPrime(participantPrime); verify(cacheProvider).removeElementDefinition(compositionId); - verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class)); + verify(acHandler).deprime(compositionId); } @Test |