diff options
author | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-08-10 21:51:48 +0100 |
---|---|---|
committer | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-08-18 14:58:42 +0100 |
commit | d0a1bcee60c43a736a0526d49c07c564632c4f02 (patch) | |
tree | 32d46f33307a9bb65215a1f52eb626ae7db3d1ee /participant/participant-intermediary/src/main | |
parent | a37bd982693785af5fc791df0baaa49dda039846 (diff) |
Updated ControlLoop component messages
Updated controlloop messages (ParticipantUpdate, ControlLoopUpdate,
ParticipantStatus) according to the following Wiki and added
implementation for the corresponding updates in runtime-controlloop and
participant components
https://wiki.onap.org/display/DW/The+CLAMP+Control+Loop+Participant+Protocol
Issue-ID: POLICY-3417
Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech>
Change-Id: I80d96a7553a89ca47de2aa35e09df5a5c792acfa
Diffstat (limited to 'participant/participant-intermediary/src/main')
5 files changed, 79 insertions, 29 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ControlLoopElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ControlLoopElementListener.java index 9e5d2c663..4dd978f0f 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ControlLoopElementListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ControlLoopElementListener.java @@ -25,7 +25,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; /** * This interface is implemented by participant implementations to receive updates on control loop elements. @@ -46,11 +46,11 @@ public interface ControlLoopElementListener { * Handle an update on a control loop element. * * @param element the information on the control loop element - * @param controlLoopDefinition toscaServiceTemplate + * @param controlLoopElementDefinition toscaNodeTemplate * @throws PfModelException from Policy framework */ public void controlLoopElementUpdate(ControlLoopElement element, - ToscaServiceTemplate controlLoopDefinition) throws PfModelException; + ToscaNodeTemplate controlLoopElementDefinition) throws PfModelException; /** * Handle controlLoopElement statistics. diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java index 7e448dc15..aa2027ab8 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java @@ -32,6 +32,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * This interface is used by participant implementations to use the participant intermediary. @@ -99,6 +100,13 @@ public interface ParticipantIntermediaryApi { Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version); /** + * Get ToscaServiceTemplate from the intermediary API. + * + * @return the control loop element + */ + ToscaServiceTemplate getToscaServiceTemplate(); + + /** * Get control loop element from the intermediary API. * * @param id control loop element ID diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java index 9652f1a8d..a2a4c3436 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java @@ -37,6 +37,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoo import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.stereotype.Component; /** @@ -120,6 +121,11 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp } @Override + public ToscaServiceTemplate getToscaServiceTemplate() { + return participantHandler.getToscaServiceTemplate(); + } + + @Override public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState, ControlLoopState newState) { return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState); diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java index 876a4cc52..f2421141a 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java @@ -36,6 +36,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate; @@ -45,6 +46,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSe import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,7 +187,7 @@ public class ControlLoopHandler { * @param updateMsg the update message */ public void handleControlLoopUpdate(ControlLoopUpdate updateMsg, - Map<UUID, ControlLoopElementDefinition> clElementDefinitions) { + List<ControlLoopElementDefinition> clElementDefinitions) { if (!updateMsg.appliesTo(participantType, participantId)) { return; @@ -207,27 +209,26 @@ public class ControlLoopHandler { return; } - controlLoop = updateMsg.getControlLoop(); - controlLoop.getElements().values().removeIf(element -> !participantType.equals(element.getParticipantType())); + List<ControlLoopElement> clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList()); - controlLoopMap.put(updateMsg.getControlLoopId(), controlLoop); - for (ControlLoopElement element : updateMsg.getControlLoop().getElements().values()) { - element.setState(element.getOrderedState().asState()); - element.setParticipantId(participantId); - elementsOnThisParticipant.put(element.getId(), element); - } - - for (ControlLoopElementListener clElementListener : listeners) { - try { - for (ControlLoopElement element : updateMsg.getControlLoop().getElements().values()) { - clElementListener.controlLoopElementUpdate(element, - clElementDefinitions.get(element.getId()).getControlLoopElementToscaServiceTemplate()); + try { + for (ControlLoopElement element : clElements) { + ToscaNodeTemplate clElementNodeTemplate = getClElementNodeTemplate( + clElementDefinitions, element.getDefinition()); + for (ControlLoopElementListener clElementListener : listeners) { + clElementListener.controlLoopElementUpdate(element, clElementNodeTemplate); } - } catch (PfModelException e) { - LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId()); } + } catch (PfModelException e) { + LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId()); } + Map<UUID, ControlLoopElement> clElementMap = prepareClElementMap(clElements); + controlLoop = new ControlLoop(); + controlLoop.setDefinition(updateMsg.getControlLoopId()); + controlLoop.setElements(clElementMap); + controlLoopMap.put(updateMsg.getControlLoopId(), controlLoop); + controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId()); controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId()); controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId() @@ -236,6 +237,37 @@ public class ControlLoopHandler { messageSender.sendAckResponse(controlLoopUpdateAck); } + private ToscaNodeTemplate getClElementNodeTemplate(List<ControlLoopElementDefinition> clElementDefinitions, + ToscaConceptIdentifier clElementDefId) { + for (ControlLoopElementDefinition clElementDefinition : clElementDefinitions) { + if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) { + return clElementDefinition.getControlLoopElementToscaNodeTemplate(); + } + } + return null; + } + + private List<ControlLoopElement> storeElementsOnThisParticipant(List<ParticipantUpdates> participantUpdates) { + List<ControlLoopElement> clElementMap = new ArrayList<>(); + for (ParticipantUpdates participantUpdate : participantUpdates) { + if (participantUpdate.getParticipantId().equals(participantType)) { + clElementMap = participantUpdate.getControlLoopElementList(); + } + } + for (ControlLoopElement element : clElementMap) { + elementsOnThisParticipant.put(element.getId(), element); + } + return clElementMap; + } + + private Map<UUID, ControlLoopElement> prepareClElementMap(List<ControlLoopElement> clElements) { + Map<UUID, ControlLoopElement> clElementMap = new LinkedHashMap<>(); + for (ControlLoopElement element : clElements) { + clElementMap.put(element.getId(), element); + } + return clElementMap; + } + /** * Method to handle when the new state from participant is UNINITIALISED state. * diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java index e1c0f7c46..6dcf93357 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java @@ -22,14 +22,15 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler; import java.io.Closeable; import java.time.Instant; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import java.util.UUID; import lombok.Getter; import lombok.Setter; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; @@ -48,6 +49,7 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSe import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -72,7 +74,10 @@ public class ParticipantHandler implements Closeable { @Setter private ParticipantHealthStatus healthStatus = ParticipantHealthStatus.UNKNOWN; - private final Map<UUID, ControlLoopElementDefinition> clElementDefsOnThisParticipant = new LinkedHashMap<>(); + private List<ControlLoopElementDefinition> clElementDefsOnThisParticipant = + new ArrayList<>(); + + public ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); /** * Constructor, set the participant ID and sender. @@ -239,13 +244,12 @@ public class ParticipantHandler implements Closeable { return; } - Map<UUID, ControlLoopElementDefinition> clDefinitionMap = participantUpdateMsg - .getParticipantDefinitionUpdateMap().get(participantUpdateMsg.getParticipantId().toString()); - - for (ControlLoopElementDefinition element : clDefinitionMap.values()) { - clElementDefsOnThisParticipant.put(element.getId(), element); + toscaServiceTemplate = participantUpdateMsg.getToscaServiceTemplate(); + for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) { + if (participantDefinition.getParticipantId().equals(participantType)) { + clElementDefsOnThisParticipant = participantDefinition.getControlLoopElementDefinitionList(); + } } - sendParticipantUpdateAck(participantUpdateMsg.getMessageId()); } |