From 3b9768ebb116a49aed649927d162dbdcdfa7fffe Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Wed, 22 Sep 2021 09:31:25 +0100 Subject: Fix startPhase in runtime and participants Issue-ID: POLICY-3677 Change-Id: I78635928086cc39fc3539925052e06b657b249c2 Signed-off-by: FrancescoFioraEst --- .../intermediary/handler/ControlLoopHandler.java | 65 ++++++++++++++++------ 1 file changed, 49 insertions(+), 16 deletions(-) (limited to 'participant/participant-intermediary/src/main/java/org/onap') 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 30a06ba22..ab6d5bd83 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 @@ -37,6 +37,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop 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.controlloop.concepts.ParticipantUtils; 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; @@ -217,6 +218,15 @@ public class ControlLoopHandler { return; } + if (0 == updateMsg.getStartPhase()) { + handleClUpdatePhase0(updateMsg, clElementDefinitions); + } else { + handleClUpdatePhaseN(updateMsg, clElementDefinitions); + } + } + + private void handleClUpdatePhase0(ControlLoopUpdate updateMsg, + List clElementDefinitions) { var controlLoop = controlLoopMap.get(updateMsg.getControlLoopId()); // TODO: Updates to existing ControlLoops are not supported yet (Addition/Removal of ControlLoop @@ -242,28 +252,51 @@ public class ControlLoopHandler { var clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList()); + var clElementMap = prepareClElementMap(clElements); + controlLoop = new ControlLoop(); + controlLoop.setDefinition(updateMsg.getControlLoopId()); + controlLoop.setElements(clElementMap); + controlLoopMap.put(updateMsg.getControlLoopId(), controlLoop); + + handleControlLoopElementUpdate(clElements, clElementDefinitions, updateMsg.getStartPhase(), + updateMsg.getControlLoopId()); + } + + private void handleClUpdatePhaseN(ControlLoopUpdate updateMsg, + List clElementDefinitions) { + + var clElementList = updateMsg.getParticipantUpdatesList().stream() + .flatMap(participantUpdate -> participantUpdate.getControlLoopElementList().stream()) + .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList()); + + handleControlLoopElementUpdate(clElementList, clElementDefinitions, updateMsg.getStartPhase(), + updateMsg.getControlLoopId()); + } + + private void handleControlLoopElementUpdate(List clElements, + List clElementDefinitions, Integer startPhaseMsg, + ToscaConceptIdentifier controlLoopId) { try { for (var element : clElements) { - var clElementNodeTemplate = - getClElementNodeTemplate(clElementDefinitions, element.getDefinition()); - for (var clElementListener : listeners) { - clElementListener.controlLoopElementUpdate(updateMsg.getControlLoopId(), element, - clElementNodeTemplate); + var clElementNodeTemplate = getClElementNodeTemplate(clElementDefinitions, element.getDefinition()); + if (clElementNodeTemplate != null) { + int startPhase = ParticipantUtils.findStartPhase(clElementNodeTemplate.getProperties()); + if (startPhaseMsg.equals(startPhase)) { + for (var clElementListener : listeners) { + clElementListener.controlLoopElementUpdate(controlLoopId, element, clElementNodeTemplate); + } + } } } } catch (PfModelException e) { - LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId()); + LOGGER.debug("Control loop element update failed {}", controlLoopId); } - var clElementMap = prepareClElementMap(clElements); - controlLoop = new ControlLoop(); - controlLoop.setDefinition(updateMsg.getControlLoopId()); - controlLoop.setElements(clElementMap); - controlLoopMap.put(updateMsg.getControlLoopId(), controlLoop); } private ToscaNodeTemplate getClElementNodeTemplate(List clElementDefinitions, ToscaConceptIdentifier clElementDefId) { + for (var clElementDefinition : clElementDefinitions) { if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) { return clElementDefinition.getControlLoopElementToscaNodeTemplate(); @@ -273,14 +306,14 @@ public class ControlLoopHandler { } private List storeElementsOnThisParticipant(List participantUpdates) { - var clElementMap = participantUpdates.stream() + var clElementList = participantUpdates.stream() .flatMap(participantUpdate -> participantUpdate.getControlLoopElementList().stream()) .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList()); - for (var element : clElementMap) { + for (var element : clElementList) { elementsOnThisParticipant.put(element.getId(), element); } - return clElementMap; + return clElementList; } private Map prepareClElementMap(List clElements) { @@ -345,8 +378,8 @@ public class ControlLoopHandler { controlLoop.getElements().values().stream().forEach(clElement -> { for (var clElementListener : listeners) { try { - clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), - clElement.getId(), clElement.getState(), orderedState); + clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), clElement.getId(), + clElement.getState(), orderedState); } catch (PfModelException e) { LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition()); } -- cgit 1.2.3-korg