aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-09-22 09:31:25 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2021-09-22 15:29:39 +0000
commit3b9768ebb116a49aed649927d162dbdcdfa7fffe (patch)
treef5f4026adfa7832cc0bb466c620040ac69b5365e /participant/participant-intermediary/src/main
parentb428105b44d0504b05a0b93894bef97e5ab7e8b4 (diff)
Fix startPhase in runtime and participants
Issue-ID: POLICY-3677 Change-Id: I78635928086cc39fc3539925052e06b657b249c2 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/main')
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java65
1 files changed, 49 insertions, 16 deletions
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<ControlLoopElementDefinition> 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<ControlLoopElementDefinition> 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<ControlLoopElement> clElements,
+ List<ControlLoopElementDefinition> 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<ControlLoopElementDefinition> clElementDefinitions,
ToscaConceptIdentifier clElementDefId) {
+
for (var clElementDefinition : clElementDefinitions) {
if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) {
return clElementDefinition.getControlLoopElementToscaNodeTemplate();
@@ -273,14 +306,14 @@ public class ControlLoopHandler {
}
private List<ControlLoopElement> storeElementsOnThisParticipant(List<ParticipantUpdates> 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<UUID, ControlLoopElement> prepareClElementMap(List<ControlLoopElement> 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());
}