diff options
author | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-09-06 09:15:07 +0100 |
---|---|---|
committer | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-09-07 17:47:12 +0100 |
commit | 1df4475d60d9c6d46087f8284dd2e0697d59c071 (patch) | |
tree | 00763b704dd8d4818a08223afef40728d8565909 /runtime-controlloop/src/main | |
parent | 29fc6f31180fbbc48d75a3bb1ac97d4b00883e5c (diff) |
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 <sirisha.manchikanti@est.tech>
Change-Id: I1249cf2cabd4a499d80b401f94f7f42f08b350e3
Diffstat (limited to 'runtime-controlloop/src/main')
2 files changed, 71 insertions, 1 deletions
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<Map.Entry<UUID, ControlLoopElementAck>> + 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<Par List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>(); for (Map.Entry<String, ToscaNodeTemplate> 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<Par participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); return participantDefinition; } + + private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate, + ToscaServiceTemplate toscaServiceTemplate) { + if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) { + return true; + } else { + var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType()); + if (nodeType != null) { + var derivedFrom = nodeType.getDerivedFrom(); + if (derivedFrom != null) { + return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false; + } + } + } + return false; + } } |