From d0a1bcee60c43a736a0526d49c07c564632c4f02 Mon Sep 17 00:00:00 2001 From: Sirisha_Manchikanti Date: Tue, 10 Aug 2021 21:51:48 +0100 Subject: 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 Change-Id: I80d96a7553a89ca47de2aa35e09df5a5c792acfa --- .../api/ControlLoopElementListener.java | 6 +- .../api/ParticipantIntermediaryApi.java | 8 +++ .../api/impl/ParticipantIntermediaryApiImpl.java | 6 ++ .../intermediary/handler/ControlLoopHandler.java | 66 ++++++++++++++++------ .../intermediary/handler/ParticipantHandler.java | 22 +++++--- 5 files changed, 79 insertions(+), 29 deletions(-) (limited to 'participant/participant-intermediary/src/main') 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. @@ -98,6 +99,13 @@ public interface ParticipantIntermediaryApi { */ Map 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. * 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; /** @@ -119,6 +120,11 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp return null; } + @Override + public ToscaServiceTemplate getToscaServiceTemplate() { + return participantHandler.getToscaServiceTemplate(); + } + @Override public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState, ControlLoopState 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 clElementDefinitions) { + List 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 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 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 clElementDefinitions, + ToscaConceptIdentifier clElementDefId) { + for (ControlLoopElementDefinition clElementDefinition : clElementDefinitions) { + if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) { + return clElementDefinition.getControlLoopElementToscaNodeTemplate(); + } + } + return null; + } + + private List storeElementsOnThisParticipant(List participantUpdates) { + List 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 prepareClElementMap(List clElements) { + Map 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 clElementDefsOnThisParticipant = new LinkedHashMap<>(); + private List 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 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()); } -- cgit 1.2.3-korg