From 1df4475d60d9c6d46087f8284dd2e0697d59c071 Mon Sep 17 00:00:00 2001 From: Sirisha_Manchikanti Date: Mon, 6 Sep 2021 09:15:07 +0100 Subject: Fix parsing of type heirarchy for nodetypes Fixed an issue where a ControlLoopElement with type defined in node-types is not parsed. This commit also includes changes to save the state of a controlLoopElement coming from ControlLoopAck message into runtime database. Issue-ID: POLICY-3575 Signed-off-by: Sirisha_Manchikanti Change-Id: I1249cf2cabd4a499d80b401f94f7f42f08b350e3 --- .../runtime/supervision/SupervisionHandler.java | 54 ++++++++++++++++++++++ .../comm/ParticipantUpdatePublisher.java | 18 +++++++- 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'runtime-controlloop/src/main/java/org') diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java index 789e4fa92..a426cac4a 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java @@ -22,11 +22,15 @@ package org.onap.policy.clamp.controlloop.runtime.supervision; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import javax.ws.rs.core.Response; import lombok.AllArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementAck; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; @@ -166,6 +170,22 @@ public class SupervisionHandler { @MessageIntercept public void handleParticipantMessage(ParticipantUpdateAck participantUpdateAckMessage) { LOGGER.debug("Participant Update Ack received {}", participantUpdateAckMessage); + try { + var participantList = + participantProvider.getParticipants(participantUpdateAckMessage.getParticipantId().getName(), + participantUpdateAckMessage.getParticipantId().getVersion()); + + if (participantList != null) { + for (Participant participant : participantList) { + participant.setParticipantState(participantUpdateAckMessage.getState()); + } + participantProvider.updateParticipants(participantList); + } else { + LOGGER.warn("Participant not found in database {}", participantUpdateAckMessage.getParticipantId()); + } + } catch (PfModelException pfme) { + LOGGER.warn("Model exception occured {}", participantUpdateAckMessage.getParticipantId()); + } } /** @@ -200,6 +220,7 @@ public class SupervisionHandler { @MessageIntercept public void handleControlLoopUpdateAckMessage(ControlLoopAck controlLoopAckMessage) { LOGGER.debug("ControlLoop Update Ack message received {}", controlLoopAckMessage); + setClElementStateInDb(controlLoopAckMessage); } /** @@ -210,6 +231,39 @@ public class SupervisionHandler { @MessageIntercept public void handleControlLoopStateChangeAckMessage(ControlLoopAck controlLoopAckMessage) { LOGGER.debug("ControlLoop StateChange Ack message received {}", controlLoopAckMessage); + setClElementStateInDb(controlLoopAckMessage); + } + + private void setClElementStateInDb(ControlLoopAck controlLoopAckMessage) { + if (controlLoopAckMessage.getControlLoopResultMap() != null) { + try { + var controlLoop = controlLoopProvider.getControlLoop(controlLoopAckMessage.getControlLoopId()); + if (controlLoop != null) { + var updated = updateState(controlLoop, controlLoopAckMessage + .getControlLoopResultMap().entrySet()); + if (updated) { + controlLoopProvider.updateControlLoop(controlLoop); + } + } else { + LOGGER.warn("ControlLoop not found in database {}", controlLoopAckMessage.getControlLoopId()); + } + } catch (PfModelException pfme) { + LOGGER.warn("Model exception occured {}", controlLoopAckMessage.getControlLoopId()); + } + } + } + + private boolean updateState(ControlLoop controlLoop, Set> + controlLoopResultSet) { + var updated = false; + for (var clElementAck : controlLoopResultSet) { + var element = controlLoop.getElements().get(clElementAck.getKey()); + if (element != null) { + element.setState(clElementAck.getValue().getState()); + updated = true; + } + } + return updated; } /** diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java index c820bf3f1..d15a424b9 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java @@ -78,7 +78,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher participantDefinitionUpdates = new ArrayList<>(); for (Map.Entry toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate() .getNodeTemplates().entrySet()) { - if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) { + if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) { ToscaConceptIdentifier clParticipantType; try { clParticipantType = @@ -138,4 +138,20 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher