From c71863696d729286502f951a64c3d2193c6641e7 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Mon, 19 Dec 2022 14:43:11 +0000 Subject: Add compositionId into Messages between ACM and Participants Issue-ID: POLICY-4489 Change-Id: I1fb8c04eacee040d5c944c522ca59a2a9a50376b Signed-off-by: FrancescoFioraEst --- .../api/ParticipantIntermediaryApi.java | 59 ---------- .../api/impl/ParticipantIntermediaryApiImpl.java | 71 +----------- .../handler/AutomationCompositionHandler.java | 113 ++++++++----------- .../intermediary/handler/ParticipantHandler.java | 123 +++++---------------- 4 files changed, 83 insertions(+), 283 deletions(-) (limited to 'participant/participant-intermediary/src/main/java/org') diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java index 367215a29..d74c41f35 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java @@ -21,18 +21,11 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; -import java.util.List; -import java.util.Map; import java.util.UUID; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; /** * This interface is used by participant implementations to use the participant intermediary. @@ -47,58 +40,6 @@ public interface ParticipantIntermediaryApi { void registerAutomationCompositionElementListener( AutomationCompositionElementListener automationCompositionElementListener); - /** - * Get participants loops from the intermediary API. - * - * @param name the participant name, null for all - * @param version the participant version, null for all - * @return the participants - */ - List getParticipants(String name, String version); - - /** - * Get common properties of a automation composition element. - * - * @param acElementDef the automation composition element definition - * @return the common properties - */ - Map getAcElementDefinitionCommonProperties(ToscaConceptIdentifier acElementDef); - - /** - * Update the state of a participant. - * - * @param definition the definition of the participant to update the state on - * @param state the state of the participant - * @return the participant - */ - Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state); - - /** - * Get automation compositions from the intermediary API. - * - * @param name the automation composition element name, null for all - * @param version the automation composition element version, null for all - * @return the automation composition elements - */ - AutomationCompositions getAutomationCompositions(String name, String version); - - /** - * Get automation composition elements from the intermediary API. - * - * @param name the automation composition element name, null for all - * @param version the automation composition element version, null for all - * @return the automation composition elements - */ - Map getAutomationCompositionElements(String name, String version); - - /** - * Get automation composition element from the intermediary API. - * - * @param id automation composition element ID - * @return the automation composition element - */ - AutomationCompositionElement getAutomationCompositionElement(UUID id); - /** * Update the state of a automation composition element. * 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 6dfc82791..acbcc37a6 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 @@ -21,24 +21,14 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; import java.util.UUID; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler; -import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; -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.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.springframework.stereotype.Component; /** @@ -47,21 +37,15 @@ import org.springframework.stereotype.Component; @Component public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi { - // The handler for the participant intermediary - private final ParticipantHandler participantHandler; - // The handler for the automationComposition intermediary private final AutomationCompositionHandler automationCompositionHandler; /** * Constructor. * - * @param participantHandler ParticipantHandler * @param automationCompositionHandler AutomationCompositionHandler */ - public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler, - AutomationCompositionHandler automationCompositionHandler) { - this.participantHandler = participantHandler; + public ParticipantIntermediaryApiImpl(AutomationCompositionHandler automationCompositionHandler) { this.automationCompositionHandler = automationCompositionHandler; } @@ -72,56 +56,9 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp } @Override - public List getParticipants(String name, String version) { - return List.of(participantHandler.getParticipant(name, version)); - } - - @Override - public Map getAcElementDefinitionCommonProperties(ToscaConceptIdentifier acElementDef) { - return participantHandler.getAcElementDefinitionCommonProperties(acElementDef); - } - - @Override - public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) { - return participantHandler.updateParticipantState(definition, state); - } - - @Override - public AutomationCompositions getAutomationCompositions(String name, String version) { - return automationCompositionHandler.getAutomationCompositions(); - } - - @Override - public Map getAutomationCompositionElements(String name, String version) { - var automationCompositions = - automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList(); - - for (var automationComposition : automationCompositions) { - if (name.equals(automationComposition.getName())) { - return automationComposition.getElements(); - } - } - return new LinkedHashMap<>(); - } - - @Override - public AutomationCompositionElement getAutomationCompositionElement(UUID id) { - List automationCompositions = - automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList(); - - for (AutomationComposition automationComposition : automationCompositions) { - AutomationCompositionElement acElement = automationComposition.getElements().get(id); - if (acElement != null) { - return acElement; - } - } - return null; - } - - @Override - public AutomationCompositionElement updateAutomationCompositionElementState( - UUID automationCompositionId, UUID id, AutomationCompositionOrderedState currentState, - AutomationCompositionState newState, ParticipantMessageType messageType) { + public AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, + AutomationCompositionOrderedState currentState, AutomationCompositionState newState, + ParticipantMessageType messageType) { return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, currentState, newState); } 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 66ac0c1dc..568ab8a36 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 @@ -38,7 +38,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementAck import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionAck; @@ -97,9 +96,8 @@ public class AutomationCompositionHandler { * @param newState the ordered state * @return automationCompositionElement the updated automation composition element */ - public AutomationCompositionElement updateAutomationCompositionElementState( - UUID automationCompositionId, UUID id, AutomationCompositionOrderedState orderedState, - AutomationCompositionState newState) { + public AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, + AutomationCompositionOrderedState orderedState, AutomationCompositionState newState) { if (id == null) { LOGGER.warn("Cannot update Automation composition element state, id is null"); @@ -114,7 +112,7 @@ public class AutomationCompositionHandler { element.setState(newState); } var checkOpt = automationComposition.getElements().values().stream() - .filter(acElement -> !newState.equals(acElement.getState())).findAny(); + .filter(acElement -> !newState.equals(acElement.getState())).findAny(); if (checkOpt.isEmpty()) { automationComposition.setState(newState); automationComposition.setOrderedState(orderedState); @@ -125,18 +123,18 @@ public class AutomationCompositionHandler { var acElement = elementsOnThisParticipant.get(id); if (acElement != null) { var automationCompositionStateChangeAck = - new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); + new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); automationCompositionStateChangeAck.setParticipantId(participantId); automationCompositionStateChangeAck.setParticipantType(participantType); automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId); acElement.setOrderedState(orderedState); acElement.setState(newState); automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(), - new AutomationCompositionElementAck(newState, true, - "Automation composition element {} state changed to {}\", id, newState)")); + new AutomationCompositionElementAck(newState, true, + "Automation composition element {} state changed to {}\", id, newState)")); LOGGER.debug("Automation composition element {} state changed to {}", id, newState); automationCompositionStateChangeAck - .setMessage("AutomationCompositionElement state changed to {} " + newState); + .setMessage("AutomationCompositionElement state changed to {} " + newState); automationCompositionStateChangeAck.setResult(true); publisher.sendAutomationCompositionAck(automationCompositionStateChangeAck); return acElement; @@ -151,7 +149,7 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ public void handleAutomationCompositionStateChange(AutomationCompositionStateChange stateChangeMsg, - List acElementDefinitions) { + List acElementDefinitions) { if (stateChangeMsg.getAutomationCompositionId() == null) { return; } @@ -160,22 +158,22 @@ public class AutomationCompositionHandler { if (automationComposition == null) { var automationCompositionAck = - new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); + new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); automationCompositionAck.setParticipantId(participantId); automationCompositionAck.setParticipantType(participantType); automationCompositionAck.setMessage("Automation composition " + stateChangeMsg.getAutomationCompositionId() - + " does not use this participant " + participantId); + + " does not use this participant " + participantId); automationCompositionAck.setResult(false); automationCompositionAck.setResponseTo(stateChangeMsg.getMessageId()); automationCompositionAck.setAutomationCompositionId(stateChangeMsg.getAutomationCompositionId()); publisher.sendAutomationCompositionAck(automationCompositionAck); LOGGER.debug("Automation composition {} does not use this participant", - stateChangeMsg.getAutomationCompositionId()); + stateChangeMsg.getAutomationCompositionId()); return; } handleState(automationComposition, stateChangeMsg.getOrderedState(), stateChangeMsg.getStartPhase(), - acElementDefinitions); + acElementDefinitions); } /** @@ -187,8 +185,8 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ private void handleState(final AutomationComposition automationComposition, - AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List acElementDefinitions) { + AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + List acElementDefinitions) { switch (orderedState) { case UNINITIALISED: handleUninitialisedState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); @@ -200,8 +198,7 @@ public class AutomationCompositionHandler { handleRunningState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); break; default: - LOGGER.debug("StateChange message has no state, state is null {}", - automationComposition.getKey()); + LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey()); break; } } @@ -213,7 +210,7 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ public void handleAutomationCompositionUpdate(AutomationCompositionUpdate updateMsg, - List acElementDefinitions) { + List acElementDefinitions) { if (!updateMsg.appliesTo(participantType, participantId)) { return; @@ -227,7 +224,7 @@ public class AutomationCompositionHandler { } private void handleAcUpdatePhase0(AutomationCompositionUpdate updateMsg, - List acElementDefinitions) { + List acElementDefinitions) { var automationComposition = automationCompositionMap.get(updateMsg.getAutomationCompositionId()); // TODO: Updates to existing AutomationCompositions are not supported yet (Addition/Removal of @@ -235,12 +232,12 @@ public class AutomationCompositionHandler { // elements to existing AutomationComposition has to be supported). if (automationComposition != null) { var automationCompositionUpdateAck = - new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE_ACK); + new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE_ACK); automationCompositionUpdateAck.setParticipantId(participantId); automationCompositionUpdateAck.setParticipantType(participantType); automationCompositionUpdateAck.setMessage("Automation composition " + updateMsg.getAutomationCompositionId() - + " already defined on participant " + participantId); + + " already defined on participant " + participantId); automationCompositionUpdateAck.setResult(false); automationCompositionUpdateAck.setResponseTo(updateMsg.getMessageId()); automationCompositionUpdateAck.setAutomationCompositionId(updateMsg.getAutomationCompositionId()); @@ -250,7 +247,7 @@ public class AutomationCompositionHandler { if (updateMsg.getParticipantUpdatesList().isEmpty()) { LOGGER.warn("No AutomationCompositionElement updates in message {}", - updateMsg.getAutomationCompositionId()); + updateMsg.getAutomationCompositionId()); return; } @@ -262,23 +259,23 @@ public class AutomationCompositionHandler { automationCompositionMap.put(updateMsg.getAutomationCompositionId(), automationComposition); handleAutomationCompositionElementUpdate(acElements, acElementDefinitions, updateMsg.getStartPhase(), - updateMsg.getAutomationCompositionId()); + updateMsg.getAutomationCompositionId()); } private void handleAcUpdatePhaseN(AutomationCompositionUpdate updateMsg, - List acElementDefinitions) { + List acElementDefinitions) { var acElementList = updateMsg.getParticipantUpdatesList().stream() - .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream()) - .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList()); + .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream()) + .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList()); handleAutomationCompositionElementUpdate(acElementList, acElementDefinitions, updateMsg.getStartPhase(), - updateMsg.getAutomationCompositionId()); + updateMsg.getAutomationCompositionId()); } private void handleAutomationCompositionElementUpdate(List acElements, - List acElementDefinitions, Integer startPhaseMsg, - UUID automationCompositionId) { + List acElementDefinitions, Integer startPhaseMsg, + UUID automationCompositionId) { try { for (var element : acElements) { var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, element.getDefinition()); @@ -300,7 +297,7 @@ public class AutomationCompositionHandler { } private ToscaNodeTemplate getAcElementNodeTemplate( - List acElementDefinitions, ToscaConceptIdentifier acElementDefId) { + List acElementDefinitions, ToscaConceptIdentifier acElementDefId) { for (var acElementDefinition : acElementDefinitions) { if (acElementDefId.getName().contains(acElementDefinition.getAcElementDefinitionId().getName())) { @@ -311,10 +308,10 @@ public class AutomationCompositionHandler { } private List storeElementsOnThisParticipant( - List participantUpdates) { + List participantUpdates) { var acElementList = participantUpdates.stream() - .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream()) - .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList()); + .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream()) + .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList()); for (var element : acElementList) { elementsOnThisParticipant.put(element.getId(), element); @@ -339,16 +336,16 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ private void handleUninitialisedState(final AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List acElementDefinitions) { + final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + List acElementDefinitions) { handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); boolean isAllUninitialised = automationComposition.getElements().values().stream() - .filter(element -> !AutomationCompositionState.UNINITIALISED.equals(element.getState())).findAny() - .isEmpty(); + .filter(element -> !AutomationCompositionState.UNINITIALISED.equals(element.getState())).findAny() + .isEmpty(); if (isAllUninitialised) { automationCompositionMap.remove(automationComposition.getInstanceId()); automationComposition.getElements().values() - .forEach(element -> elementsOnThisParticipant.remove(element.getId())); + .forEach(element -> elementsOnThisParticipant.remove(element.getId())); } } @@ -361,8 +358,8 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ private void handlePassiveState(final AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List acElementDefinitions) { + final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + List acElementDefinitions) { handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); } @@ -375,8 +372,8 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ private void handleRunningState(final AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List acElementDefinitions) { + final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + List acElementDefinitions) { handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); } @@ -389,12 +386,12 @@ public class AutomationCompositionHandler { * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ private void handleStateChange(AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List acElementDefinitions) { + final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + List acElementDefinitions) { if (orderedState.equals(automationComposition.getOrderedState())) { var automationCompositionAck = - new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); + new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); automationCompositionAck.setParticipantId(participantId); automationCompositionAck.setParticipantType(participantType); automationCompositionAck.setMessage("Automation composition is already in state " + orderedState); @@ -405,22 +402,21 @@ public class AutomationCompositionHandler { } automationComposition.getElements().values().stream() - .forEach(acElement -> automationCompositionElementStateChange(automationComposition, orderedState, - acElement, startPhaseMsg, acElementDefinitions)); + .forEach(acElement -> automationCompositionElementStateChange(automationComposition, orderedState, + acElement, startPhaseMsg, acElementDefinitions)); } private void automationCompositionElementStateChange(AutomationComposition automationComposition, - AutomationCompositionOrderedState orderedState, AutomationCompositionElement acElement, Integer startPhaseMsg, - List acElementDefinitions) { + AutomationCompositionOrderedState orderedState, AutomationCompositionElement acElement, + Integer startPhaseMsg, List acElementDefinitions) { var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition()); if (acElementNodeTemplate != null) { int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties()); if (startPhaseMsg.equals(startPhase)) { for (var acElementListener : listeners) { try { - acElementListener.automationCompositionElementStateChange( - automationComposition.getInstanceId(), acElement.getId(), acElement.getState(), - orderedState); + acElementListener.automationCompositionElementStateChange(automationComposition.getInstanceId(), + acElement.getId(), acElement.getState(), orderedState); } catch (PfModelException e) { LOGGER.debug("Automation composition element update failed {}", automationComposition.getInstanceId()); @@ -429,15 +425,4 @@ public class AutomationCompositionHandler { } } } - - /** - * Get automation compositions as a {@link ConrolLoops} class. - * - * @return the automation compositions - */ - public AutomationCompositions getAutomationCompositions() { - var automationCompositions = new AutomationCompositions(); - automationCompositions.setAutomationCompositionList(new ArrayList<>(automationCompositionMap.values())); - return automationCompositions; - } } 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 d29186844..b442b9967 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 @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.UUID; import lombok.Getter; import lombok.Setter; @@ -35,7 +34,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessag import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; -import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; @@ -52,7 +50,6 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantSt import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -79,7 +76,7 @@ public class ParticipantHandler { @Setter private ParticipantHealthStatus healthStatus = ParticipantHealthStatus.UNKNOWN; - private final List acElementDefsOnThisParticipant = new ArrayList<>(); + private final Map> acElementDefsMap = new HashMap<>(); /** * Constructor, set the participant ID and sender. @@ -88,7 +85,7 @@ public class ParticipantHandler { * @param publisher the publisher for sending responses to messages */ public ParticipantHandler(ParticipantParameters parameters, ParticipantMessagePublisher publisher, - AutomationCompositionHandler automationCompositionHandler) { + AutomationCompositionHandler automationCompositionHandler) { this.participantType = parameters.getIntermediaryParameters().getParticipantType(); this.participantId = parameters.getIntermediaryParameters().getParticipantId(); this.publisher = publisher; @@ -100,8 +97,7 @@ public class ParticipantHandler { * * @param participantStatusReqMsg participant participantStatusReq message */ - @Timed(value = "listener.participant_status_req", - description = "PARTICIPANT_STATUS_REQ messages received") + @Timed(value = "listener.participant_status_req", description = "PARTICIPANT_STATUS_REQ messages received") public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) { var participantStatus = makeHeartbeat(true); publisher.sendParticipantStatus(participantStatus); @@ -112,10 +108,12 @@ public class ParticipantHandler { * * @param updateMsg the update message */ - @Timed(value = "listener.automation_composition_update", + @Timed( + value = "listener.automation_composition_update", description = "AUTOMATION_COMPOSITION_UPDATE messages received") public void handleAutomationCompositionUpdate(AutomationCompositionUpdate updateMsg) { - automationCompositionHandler.handleAutomationCompositionUpdate(updateMsg, acElementDefsOnThisParticipant); + automationCompositionHandler.handleAutomationCompositionUpdate(updateMsg, + acElementDefsMap.get(updateMsg.getCompositionId())); } /** @@ -123,75 +121,12 @@ public class ParticipantHandler { * * @param stateChangeMsg the state change message */ - @Timed(value = "listener.automation_composition_state_change", + @Timed( + value = "listener.automation_composition_state_change", description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages received") public void handleAutomationCompositionStateChange(AutomationCompositionStateChange stateChangeMsg) { automationCompositionHandler.handleAutomationCompositionStateChange(stateChangeMsg, - acElementDefsOnThisParticipant); - } - - private void handleStateChange(ParticipantState newParticipantState, ParticipantUpdateAck response) { - if (state.equals(newParticipantState)) { - response.setResult(false); - response.setMessage("Participant already in state " + newParticipantState); - } else { - response.setResult(true); - response.setMessage("Participant state changed from " + state + " to " + newParticipantState); - state = newParticipantState; - } - } - - /** - * Method to update participant state. - * - * @param definition participant definition - * @param participantState participant state - * @return the participant - */ - public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState participantState) { - if (!Objects.equals(definition, participantId)) { - LOGGER.debug("No participant with this ID {}", definition.getName()); - return null; - } - - var participantUpdateAck = new ParticipantUpdateAck(); - handleStateChange(participantState, participantUpdateAck); - publisher.sendParticipantUpdateAck(participantUpdateAck); - return getParticipant(definition.getName(), definition.getVersion()); - } - - /** - * Get participants as a {@link Participant} class. - * - * @param name the participant name to get - * @param version the version of the participant to get - * @return the participant - */ - public Participant getParticipant(String name, String version) { - if (participantId.getName().equals(name)) { - var participant = new Participant(); - participant.setDefinition(participantId); - participant.setParticipantState(state); - participant.setHealthStatus(healthStatus); - return participant; - } - return null; - } - - /** - * Get common properties of a automation composition element. - * - * @param acElementDef the automation composition element definition - * @return the common properties - */ - public Map getAcElementDefinitionCommonProperties(ToscaConceptIdentifier acElementDef) { - Map commonPropertiesMap = new HashMap<>(); - acElementDefsOnThisParticipant.stream().forEach(definition -> { - if (definition.getAcElementDefinitionId().equals(acElementDef)) { - commonPropertiesMap.putAll(definition.getCommonPropertiesMap()); - } - }); - return commonPropertiesMap; + acElementDefsMap.get(stateChangeMsg.getCompositionId())); } /** @@ -230,11 +165,10 @@ public class ParticipantHandler { * * @param participantRegisterAckMsg the participantRegisterAck message */ - @Timed(value = "listener.participant_register_ack", - description = "PARTICIPANT_REGISTER_ACK messages received") + @Timed(value = "listener.participant_register_ack", description = "PARTICIPANT_REGISTER_ACK messages received") public void handleParticipantRegisterAck(ParticipantRegisterAck participantRegisterAckMsg) { LOGGER.debug("ParticipantRegisterAck message received as responseTo {}", - participantRegisterAckMsg.getResponseTo()); + participantRegisterAckMsg.getResponseTo()); statusToPassive(); publisher.sendParticipantStatus(makeHeartbeat(false)); } @@ -266,11 +200,10 @@ public class ParticipantHandler { * * @param participantDeregisterAckMsg the participantDeregisterAck message */ - @Timed(value = "listener.participant_deregister_ack", - description = "PARTICIPANT_DEREGISTER_ACK messages received") + @Timed(value = "listener.participant_deregister_ack", description = "PARTICIPANT_DEREGISTER_ACK messages received") public void handleParticipantDeregisterAck(ParticipantDeregisterAck participantDeregisterAckMsg) { LOGGER.debug("ParticipantDeregisterAck message received as responseTo {}", - participantDeregisterAckMsg.getResponseTo()); + participantDeregisterAckMsg.getResponseTo()); } /** @@ -278,25 +211,25 @@ public class ParticipantHandler { * * @param participantUpdateMsg the ParticipantUpdate message */ - @Timed(value = "listener.participant_update", - description = "PARTICIPANT_UPDATE messages received") + @Timed(value = "listener.participant_update", description = "PARTICIPANT_UPDATE messages received") public void handleParticipantUpdate(ParticipantUpdate participantUpdateMsg) { LOGGER.debug("ParticipantUpdate message received for participantId {}", - participantUpdateMsg.getParticipantId()); + participantUpdateMsg.getParticipantId()); + acElementDefsMap.putIfAbsent(participantUpdateMsg.getCompositionId(), new ArrayList<>()); if (!participantUpdateMsg.getParticipantDefinitionUpdates().isEmpty()) { statusToPassive(); // This message is to commission the automation composition - for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) { + for (var participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) { if (participantDefinition.getParticipantType().equals(participantType)) { - acElementDefsOnThisParticipant - .addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); + acElementDefsMap.get(participantUpdateMsg.getCompositionId()) + .addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); break; } } } else { // This message is to decommission the automation composition - acElementDefsOnThisParticipant.clear(); + acElementDefsMap.get(participantUpdateMsg.getCompositionId()).clear(); this.state = ParticipantState.TERMINATED; } sendParticipantUpdateAck(participantUpdateMsg.getMessageId()); @@ -335,11 +268,15 @@ public class ParticipantHandler { heartbeat.setAutomationCompositionInfoList(getAutomationCompositionInfoList()); if (responseToParticipantStatusReq) { - ParticipantDefinition participantDefinition = new ParticipantDefinition(); - participantDefinition.setParticipantId(participantId); - participantDefinition.setParticipantType(participantType); - participantDefinition.setAutomationCompositionElementDefinitionList(acElementDefsOnThisParticipant); - heartbeat.setParticipantDefinitionUpdates(List.of(participantDefinition)); + List participantDefinitionList = new ArrayList<>(acElementDefsMap.size()); + for (var acElementDefsOnThisParticipant : acElementDefsMap.values()) { + var participantDefinition = new ParticipantDefinition(); + participantDefinition.setParticipantId(participantId); + participantDefinition.setParticipantType(participantType); + participantDefinition.setAutomationCompositionElementDefinitionList(acElementDefsOnThisParticipant); + participantDefinitionList.add(participantDefinition); + } + heartbeat.setParticipantDefinitionUpdates(participantDefinitionList); } return heartbeat; -- cgit 1.2.3-korg