aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-controlloop')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java54
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java18
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java20
3 files changed, 90 insertions, 2 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;
+ }
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
index 260ccfb35..14de34d1c 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -193,7 +193,7 @@ class SupervisionMessagesTest extends CommonRestController {
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 = CODER.decode(
@@ -216,6 +216,22 @@ class SupervisionMessagesTest extends CommonRestController {
}
}
+ 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;
+ }
+
private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
@@ -259,6 +275,8 @@ class SupervisionMessagesTest extends CommonRestController {
participantUpdateAckMsg.setMessage("ParticipantUpdateAck message");
participantUpdateAckMsg.setResponseTo(UUID.randomUUID());
participantUpdateAckMsg.setResult(true);
+ participantUpdateAckMsg.setParticipantId(getParticipantId());
+ participantUpdateAckMsg.setParticipantType(getParticipantType());
synchronized (lockit) {
ParticipantUpdateAckListener participantUpdateAckListener =