aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/main
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-10 21:51:48 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-18 14:58:42 +0100
commitd0a1bcee60c43a736a0526d49c07c564632c4f02 (patch)
tree32d46f33307a9bb65215a1f52eb626ae7db3d1ee /runtime-controlloop/src/main
parenta37bd982693785af5fc791df0baaa49dda039846 (diff)
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 <sirisha.manchikanti@est.tech> Change-Id: I80d96a7553a89ca47de2aa35e09df5a5c792acfa
Diffstat (limited to 'runtime-controlloop/src/main')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java14
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java47
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java81
3 files changed, 120 insertions, 22 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 9180cedb3..0e2ff5ca9 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
@@ -311,18 +311,16 @@ public class SupervisionHandler {
private void superviseControlLoops(ParticipantStatus participantStatusMessage)
throws PfModelException, ControlLoopException {
- if (participantStatusMessage.getControlLoopInfoMap() != null) {
- for (Map.Entry<String, ControlLoopInfo> clEntry : participantStatusMessage.getControlLoopInfoMap()
- .entrySet()) {
- String[] key = clEntry.getKey().split(" ");
+ if (participantStatusMessage.getControlLoopInfoList() != null) {
+ for (ControlLoopInfo clEntry : participantStatusMessage.getControlLoopInfoList()) {
var dbControlLoop = controlLoopProvider.getControlLoop(
- new ToscaConceptIdentifier(key[0], key[1]));
+ new ToscaConceptIdentifier(clEntry.getControlLoopId()));
if (dbControlLoop == null) {
exceptionOccured(Response.Status.NOT_FOUND,
- "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getKey());
+ "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getControlLoopId());
}
- dbControlLoop.setState(clEntry.getValue().getState());
- monitoringProvider.createClElementStatistics(clEntry.getValue().getControlLoopStatistics()
+ dbControlLoop.setState(clEntry.getState());
+ monitoringProvider.createClElementStatistics(clEntry.getControlLoopStatistics()
.getClElementStatisticsList().getClElementStatistics());
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
index 448662cfe..be9a2a27d 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
@@ -20,9 +20,19 @@
package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -44,8 +54,43 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
public void send(ControlLoop controlLoop) {
var controlLoopUpdateMsg = new ControlLoopUpdate();
controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
- controlLoopUpdateMsg.setControlLoop(controlLoop);
+ controlLoopUpdateMsg.setMessageId(UUID.randomUUID());
+ controlLoopUpdateMsg.setTimestamp(Instant.now());
+
+ List<ParticipantUpdates> participantUpdates = new ArrayList<>();
+ for (ControlLoopElement element : controlLoop.getElements().values()) {
+ prepareParticipantUpdate(element, participantUpdates);
+ }
+ controlLoopUpdateMsg.setParticipantUpdatesList(participantUpdates);
+
LOGGER.debug("ControlLoopUpdate message sent", controlLoopUpdateMsg);
super.send(controlLoopUpdateMsg);
}
+
+ private void prepareParticipantUpdate(ControlLoopElement clElement,
+ List<ParticipantUpdates> participantUpdates) {
+ if (participantUpdates.isEmpty()) {
+ participantUpdates.add(getControlLoopElementList(clElement));
+ } else {
+ boolean participantExists = false;
+ for (ParticipantUpdates participantUpdate : participantUpdates) {
+ if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) {
+ participantUpdate.getControlLoopElementList().add(clElement);
+ participantExists = true;
+ }
+ }
+ if (!participantExists) {
+ participantUpdates.add(getControlLoopElementList(clElement));
+ }
+ }
+ }
+
+ private ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) {
+ ParticipantUpdates participantUpdate = new ParticipantUpdates();
+ List<ControlLoopElement> controlLoopElementList = new ArrayList<>();
+ participantUpdate.setParticipantId(clElement.getParticipantId());
+ controlLoopElementList.add(clElement);
+ participantUpdate.setControlLoopElementList(controlLoopElementList);
+ return participantUpdate;
+ }
}
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 cfc0e3932..5edf528b8 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
@@ -21,15 +21,23 @@
package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
import java.time.Instant;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
-import java.util.UUID;
import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
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.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -42,8 +50,9 @@ import org.springframework.stereotype.Component;
public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
-
+ private static final String CONTROL_LOOP_ELEMENT = "ControlLoopElement";
private final CommissioningProvider commissioningProvider;
+ private static final Coder CODER = new StandardCoder();
/**
* Send ParticipantUpdate to Participant.
@@ -57,25 +66,71 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
message.setParticipantType(participantType);
message.setTimestamp(Instant.now());
- var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setId(UUID.randomUUID());
-
+ ToscaServiceTemplate toscaServiceTemplate;
try {
- clDefinition.setControlLoopElementToscaServiceTemplate(
- commissioningProvider.getToscaServiceTemplate(null, null));
+ toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null);
} catch (PfModelException pfme) {
LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
return;
}
- Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>();
- controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition);
-
- Map<String, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap = new LinkedHashMap<>();
- participantDefinitionUpdateMap.put(participantId.toString(), controlLoopElementDefinitionMap);
- message.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
+ List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
+ toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
+ if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ ToscaConceptIdentifier clParticipantId;
+ try {
+ clParticipantId = CODER.decode(
+ toscaInputEntry.getValue().getProperties().get("participant_id").toString(),
+ ToscaConceptIdentifier.class);
+ } catch (CoderException e) {
+ throw new RuntimeException("cannot get ParticipantId from toscaNodeTemplate", e);
+ }
+ prepareParticipantDefinitionUpdate(clParticipantId, toscaInputEntry.getKey(),
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
+ }
+ }
+ message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ message.setToscaServiceTemplate(toscaServiceTemplate);
LOGGER.debug("Participant Update sent {}", message);
super.send(message);
}
+
+ private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantId, String entryKey,
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+
+ var clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
+ entryKey, entryValue.getVersion()));
+ clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
+
+ if (participantDefinitionUpdates.isEmpty()) {
+ participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantId,
+ controlLoopElementDefinitionList));
+ } else {
+ boolean participantExists = false;
+ for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
+ if (participantDefinitionUpdate.getParticipantId().equals(clParticipantId)) {
+ participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
+ participantExists = true;
+ }
+ }
+ if (!participantExists) {
+ participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantId,
+ controlLoopElementDefinitionList));
+ }
+ }
+ }
+
+ private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
+ ToscaConceptIdentifier clParticipantId,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ParticipantDefinition participantDefinition = new ParticipantDefinition();
+ participantDefinition.setParticipantId(clParticipantId);
+ controlLoopElementDefinitionList.add(clDefinition);
+ participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
+ return participantDefinition;
+ }
}