aboutsummaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java5
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java5
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java108
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java16
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java111
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java100
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java10
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java35
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java102
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java12
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java24
12 files changed, 294 insertions, 236 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java b/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
index cf71248c3..0bad5ed96 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
@@ -20,6 +20,8 @@
package utils;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -27,7 +29,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Util class for Test scope.
*/
-public class ToscaUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ToscaUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final String TOSCA_TEMPLATE_YAML = "src/test/resources/HttpParticipantConfig.yaml";
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java
index b01dfa28e..af514f8aa 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java
@@ -21,11 +21,14 @@
package org.onap.policy.clamp.controlloop.participant.kubernetes.utils;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-public class TestUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final String TOSCA_TEMPLATE_YAML = "src/test/resources/servicetemplates/KubernetesHelm.yaml";
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
index fe7cb3c96..25da5a3e9 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
@@ -31,6 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
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.ControlLoopElementDefinition;
@@ -38,6 +40,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.ParticipantDefinition;
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.ControlLoopStateChange;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
@@ -54,18 +57,16 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TestListenerUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestListenerUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final Coder CODER = new StandardCoder();
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
private static final String POLICY_TYPE_ID = "policy_type_id";
private static final String POLICY_ID = "policy_id";
- private TestListenerUtils() {}
-
/**
* Method to create a controlLoop from a yaml file.
*
@@ -138,10 +139,8 @@ public class TestListenerUtils {
*/
public static ControlLoopUpdate createControlLoopUpdateMsg() {
final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
- ToscaConceptIdentifier controlLoopId =
- new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
- ToscaConceptIdentifier participantId =
- new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
+ ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
clUpdateMsg.setControlLoopId(controlLoopId);
clUpdateMsg.setParticipantId(participantId);
@@ -154,23 +153,18 @@ public class TestListenerUtils {
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
clElement.setParticipantId(clParticipantType);
clElement.setParticipantType(clParticipantType);
- clElement.setDefinition(new ToscaConceptIdentifier(toscaInputEntry.getKey(),
- toscaInputEntry.getValue().getVersion()));
+ clElement.setDefinition(
+ new ToscaConceptIdentifier(toscaInputEntry.getKey(), toscaInputEntry.getValue().getVersion()));
clElement.setState(ControlLoopState.UNINITIALISED);
clElement.setDescription(toscaInputEntry.getValue().getDescription());
clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
@@ -187,26 +181,10 @@ public class TestListenerUtils {
return clUpdateMsg;
}
- 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 static void populateToscaNodeTemplateFragment(ControlLoopElement clElement,
ToscaServiceTemplate toscaServiceTemplate) {
- ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate
- .getToscaTopologyTemplate().getNodeTemplates().get(clElement.getDefinition().getName());
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(clElement.getDefinition().getName());
// If the ControlLoopElement has policy_type_id or policy_id, identify it as a PolicyControlLoopElement
// and pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment
if ((toscaNodeTemplate.getProperties().get(POLICY_TYPE_ID) != null)
@@ -229,7 +207,7 @@ public class TestListenerUtils {
}
private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
- List<ParticipantUpdates> participantUpdates) {
+ List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
participantUpdates.add(getControlLoopElementList(clElement));
} else {
@@ -263,8 +241,8 @@ public class TestListenerUtils {
public static ParticipantUpdate createParticipantUpdateMsg() {
final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
- ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(
- "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+ ToscaConceptIdentifier participantType =
+ new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
participantUpdateMsg.setParticipantId(participantId);
participantUpdateMsg.setTimestamp(Instant.now());
@@ -277,19 +255,14 @@ public class TestListenerUtils {
TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate);
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().entrySet()) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
@@ -298,17 +271,16 @@ public class TestListenerUtils {
}
private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
- entryKey, entryValue.getVersion()));
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates
+ .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
} else {
boolean participantExists = false;
for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
@@ -318,15 +290,15 @@ public class TestListenerUtils {
}
}
if (!participantExists) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates.add(
+ getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
}
}
}
private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ToscaConceptIdentifier clParticipantType,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
ParticipantDefinition participantDefinition = new ParticipantDefinition();
participantDefinition.setParticipantType(clParticipantType);
controlLoopElementDefinitionList.add(clDefinition);
@@ -369,8 +341,7 @@ public class TestListenerUtils {
return toscaServiceTemplate;
}
- private static void addPolicyTypesToToscaServiceTemplate(
- ToscaServiceTemplate toscaServiceTemplate) {
+ private static void addPolicyTypesToToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate) {
Set<String> policyTypeDirectoryContents = ResourceUtils.getDirectoryContents("policytypes");
for (String policyTypeFilePath : policyTypeDirectoryContents) {
@@ -413,10 +384,9 @@ public class TestListenerUtils {
for (String policiesFilePath : policiesDirectoryContents) {
String policiesString = ResourceUtils.getResourceAsString(policiesFilePath);
- ToscaServiceTemplate foundPoliciesSt =
- yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class);
- toscaServiceTemplate.getToscaTopologyTemplate().setPolicies(
- foundPoliciesSt.getToscaTopologyTemplate().getPolicies());
+ ToscaServiceTemplate foundPoliciesSt = yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class);
+ toscaServiceTemplate.getToscaTopologyTemplate()
+ .setPolicies(foundPoliciesSt.getToscaTopologyTemplate().getPolicies());
}
}
@@ -427,8 +397,8 @@ public class TestListenerUtils {
throw new FileNotFoundException(controlLoopFilePath);
}
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- controlLoopString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate =
+ yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class);
return serviceTemplate;
} catch (FileNotFoundException e) {
LOGGER.error("cannot find YAML file", controlLoopFilePath);
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
index c890ec247..d28ddf9dc 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
@@ -20,7 +20,10 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.controlloop.participant.simulator.main.handler.ControlLoopElementHandler;
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.RequestResponseLoggingFilter;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -42,4 +45,17 @@ public class ParticipantConfig {
return registrationBean;
}
+
+ /**
+ * Register ControlLoopElementListener.
+ *
+ * @param intermediaryApi the ParticipantIntermediaryApi
+ * @param clElementHandler the ControlLoop Element Handler
+ */
+ @Autowired
+ public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi,
+ ControlLoopElementHandler clElementHandler) {
+ intermediaryApi.registerControlLoopElementListener(clElementHandler);
+ clElementHandler.setIntermediaryApi(intermediaryApi);
+ }
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java
new file mode 100644
index 000000000..fd46faf97
--- /dev/null
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.participant.simulator.main.handler;
+
+import java.time.Instant;
+import java.util.UUID;
+import lombok.Setter;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class handles implementation of controlLoopElement updates.
+ */
+@Component
+public class ControlLoopElementHandler implements ControlLoopElementListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopElementHandler.class);
+
+ @Setter
+ private ParticipantIntermediaryApi intermediaryApi;
+
+ /**
+ * Callback method to handle a control loop element state change.
+ *
+ * @param controlLoopElementId the ID of the control loop element
+ * @param currentState the current state of the control loop element
+ * @param newState the state to which the control loop element is changing to
+ * @throws PfModelException in case of an exception
+ */
+ @Override
+ public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
+ UUID controlLoopElementId, ControlLoopState currentState,
+ ControlLoopOrderedState newState) throws PfModelException {
+ switch (newState) {
+ case UNINITIALISED:
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ break;
+ case PASSIVE:
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.PASSIVE,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ break;
+ case RUNNING:
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.RUNNING,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ break;
+ default:
+ LOGGER.debug("Unknown orderedstate {}", newState);
+ break;
+ }
+ }
+
+ /**
+ * Callback method to handle an update on a control loop element.
+ *
+ * @param element the information on the control loop element
+ * @param clElementDefinition toscaNodeTemplate
+ * @throws PfModelException in case of an exception
+ */
+ @Override
+ public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
+ ToscaNodeTemplate clElementDefinition)
+ throws PfModelException {
+ intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(),
+ ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ }
+
+ @Override
+ public void handleStatistics(UUID controlLoopElementId) throws PfModelException {
+ var clElement = intermediaryApi.getControlLoopElement(controlLoopElementId);
+ if (clElement != null) {
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setControlLoopState(clElement.getState());
+ clElementStatistics.setTimeStamp(Instant.now());
+ intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics);
+ }
+ }
+
+}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
index c26749b4d..320b53805 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
@@ -13,7 +13,7 @@ server:
participant:
intermediaryParameters:
- reportingTimeIntervalMs: 120000
+ reportingTimeIntervalMs: 60000
description: Participant Description
participantId:
name: org.onap.PM_CDS_Blueprint
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
index 7439ccd5b..bd3316abb 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
@@ -31,6 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
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.ControlLoopElementDefinition;
@@ -38,6 +40,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.ParticipantDefinition;
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.ControlLoopStateChange;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
@@ -53,15 +56,13 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TestListenerUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestListenerUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final Coder CODER = new StandardCoder();
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
-
- private TestListenerUtils() {}
/**
* Method to create a controlLoop from a yaml file.
@@ -131,10 +132,8 @@ public class TestListenerUtils {
*/
public static ControlLoopUpdate createControlLoopUpdateMsg() {
final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
- ToscaConceptIdentifier controlLoopId =
- new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
- ToscaConceptIdentifier participantId =
- new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
+ ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
clUpdateMsg.setControlLoopId(controlLoopId);
clUpdateMsg.setParticipantId(participantId);
@@ -146,23 +145,18 @@ public class TestListenerUtils {
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
clElement.setParticipantId(clParticipantType);
clElement.setParticipantType(clParticipantType);
- clElement.setDefinition(new ToscaConceptIdentifier(toscaInputEntry.getKey(),
- toscaInputEntry.getValue().getVersion()));
+ clElement.setDefinition(
+ new ToscaConceptIdentifier(toscaInputEntry.getKey(), toscaInputEntry.getValue().getVersion()));
clElement.setState(ControlLoopState.UNINITIALISED);
clElement.setDescription(toscaInputEntry.getValue().getDescription());
clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
@@ -178,24 +172,8 @@ public class TestListenerUtils {
return clUpdateMsg;
}
- 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 static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
- List<ParticipantUpdates> participantUpdates) {
+ List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
participantUpdates.add(getControlLoopElementList(clElement));
} else {
@@ -229,8 +207,8 @@ public class TestListenerUtils {
public static ParticipantUpdate createParticipantUpdateMsg() {
final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
- ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(
- "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+ ToscaConceptIdentifier participantType =
+ new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
participantUpdateMsg.setParticipantId(participantId);
participantUpdateMsg.setTimestamp(Instant.now());
@@ -242,19 +220,14 @@ public class TestListenerUtils {
// Add policies to the toscaServiceTemplate
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().entrySet()) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
@@ -263,17 +236,16 @@ public class TestListenerUtils {
}
private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
- entryKey, entryValue.getVersion()));
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates
+ .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
} else {
boolean participantExists = false;
for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
@@ -283,15 +255,15 @@ public class TestListenerUtils {
}
}
if (!participantExists) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates.add(
+ getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
}
}
}
private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ToscaConceptIdentifier clParticipantType,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
ParticipantDefinition participantDefinition = new ParticipantDefinition();
participantDefinition.setParticipantType(clParticipantType);
controlLoopElementDefinitionList.add(clDefinition);
@@ -307,10 +279,8 @@ public class TestListenerUtils {
* @return ControlLoopUpdate message
* @throws CoderException exception while reading the file to object
*/
- public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
- throws CoderException {
- ControlLoopUpdate controlLoopUpdateMsg =
- CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
+ public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath) throws CoderException {
+ ControlLoopUpdate controlLoopUpdateMsg = CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
return controlLoopUpdateMsg;
}
@@ -340,8 +310,8 @@ public class TestListenerUtils {
throw new FileNotFoundException(controlLoopFilePath);
}
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- controlLoopString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate =
+ yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class);
return serviceTemplate;
} catch (FileNotFoundException e) {
LOGGER.error("cannot find YAML file", controlLoopFilePath);
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
index 3859e0c39..891d67e2d 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -48,16 +48,6 @@ public interface ParticipantIntermediaryApi {
void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener);
/**
- * Send participant register message to controlloop runtime.
- */
- void sendParticipantRegister();
-
- /**
- * Send participant deregister message to controlloop runtime.
- */
- void sendParticipantDeregister();
-
- /**
* Get participants loops from the intermediary API.
*
* @param name the participant name, null for all
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index 1f79d7179..aa1febadd 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -37,6 +37,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.stereotype.Component;
@@ -48,30 +49,26 @@ import org.springframework.stereotype.Component;
public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
// The handler for the participant intermediary
- private ParticipantHandler participantHandler;
+ private final ParticipantHandler participantHandler;
+
+ // The handler for the controlLoop intermediary
+ private final ControlLoopHandler controlLoopHandler;
/**
* Constructor.
*
* @param participantHandler ParticipantHandler
+ * @param controlLoopHandler ControlLoopHandler
*/
- public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler) {
+ public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
+ ControlLoopHandler controlLoopHandler) {
this.participantHandler = participantHandler;
+ this.controlLoopHandler = controlLoopHandler;
}
@Override
public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
- participantHandler.getControlLoopHandler().registerControlLoopElementListener(controlLoopElementListener);
- }
-
- @Override
- public void sendParticipantRegister() {
- participantHandler.sendParticipantRegister();
- }
-
- @Override
- public void sendParticipantDeregister() {
- participantHandler.sendParticipantDeregister();
+ controlLoopHandler.registerControlLoopElementListener(controlLoopElementListener);
}
@Override
@@ -91,13 +88,12 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoops getControlLoops(String name, String version) {
- return participantHandler.getControlLoopHandler().getControlLoops();
+ return controlLoopHandler.getControlLoops();
}
@Override
public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
- List<ControlLoop> controlLoops =
- participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
+ List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
for (ControlLoop controlLoop : controlLoops) {
if (name.equals(controlLoop.getDefinition().getName())) {
@@ -109,8 +105,7 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoopElement getControlLoopElement(UUID id) {
- List<ControlLoop> controlLoops =
- participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
+ List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
for (ControlLoop controlLoop : controlLoops) {
ControlLoopElement clElement = controlLoop.getElements().get(id);
@@ -125,12 +120,12 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
UUID id, ControlLoopOrderedState currentState,
ControlLoopState newState, ParticipantMessageType messageType) {
- return participantHandler.getControlLoopHandler().updateControlLoopElementState(controlLoopId,
+ return controlLoopHandler.updateControlLoopElementState(controlLoopId,
id, currentState, newState);
}
@Override
public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
- participantHandler.getControlLoopHandler().updateControlLoopElementStatistics(id, elementStatistics);
+ controlLoopHandler.updateControlLoopElementStatistics(id, elementStatistics);
}
}
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 6e1b31cfe..8bdf91824 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
@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Getter;
-import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
@@ -45,7 +44,6 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
-import org.onap.policy.common.utils.coder.CoderException;
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;
@@ -97,33 +95,37 @@ public class ControlLoopHandler {
* @param newState the ordered state
* @return controlLoopElement the updated controlloop element
*/
- public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
- UUID id, ControlLoopOrderedState orderedState,
- ControlLoopState newState) {
+ public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId, UUID id,
+ ControlLoopOrderedState orderedState, ControlLoopState newState) {
if (id == null) {
LOGGER.warn("Cannot update Control loop element state, id is null");
+ return null;
}
- ControlLoopElement clElement = elementsOnThisParticipant.get(id);
for (var controlLoop : controlLoopMap.values()) {
var element = controlLoop.getElements().get(id);
if (element != null) {
element.setState(newState);
}
+ var checkOpt = controlLoop.getElements().values().stream()
+ .filter(clElement -> !newState.equals(clElement.getState())).findAny();
+ if (checkOpt.isEmpty()) {
+ controlLoop.setState(newState);
+ controlLoop.setOrderedState(orderedState);
+ }
}
+ var clElement = elementsOnThisParticipant.get(id);
if (clElement != null) {
- var controlLoopStateChangeAck =
- new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
+ var controlLoopStateChangeAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
controlLoopStateChangeAck.setParticipantId(participantId);
controlLoopStateChangeAck.setParticipantType(participantType);
controlLoopStateChangeAck.setControlLoopId(controlLoopId);
clElement.setOrderedState(orderedState);
clElement.setState(newState);
- controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(),
- new ControlLoopElementAck(newState, true,
- "Control loop element {} state changed to {}\", id, newState)"));
+ controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(), new ControlLoopElementAck(
+ newState, true, "Control loop element {} state changed to {}\", id, newState)"));
LOGGER.debug("Control loop element {} state changed to {}", id, newState);
controlLoopStateChangeAck.setMessage("ControlLoopElement state changed to {} " + newState);
controlLoopStateChangeAck.setResult(true);
@@ -140,7 +142,7 @@ public class ControlLoopHandler {
* @param elementStatistics control loop element Statistics
*/
public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
- ControlLoopElement clElement = elementsOnThisParticipant.get(id);
+ var clElement = elementsOnThisParticipant.get(id);
if (clElement != null) {
elementStatistics.setParticipantId(participantId);
elementStatistics.setId(id);
@@ -165,7 +167,7 @@ public class ControlLoopHandler {
controlLoopAck.setParticipantId(participantId);
controlLoopAck.setParticipantType(participantType);
controlLoopAck.setMessage("Control loop " + stateChangeMsg.getControlLoopId()
- + " does not use this participant " + participantId);
+ + " does not use this participant " + participantId);
controlLoopAck.setResult(false);
controlLoopAck.setResponseTo(stateChangeMsg.getMessageId());
controlLoopAck.setControlLoopId(stateChangeMsg.getControlLoopId());
@@ -206,7 +208,7 @@ public class ControlLoopHandler {
* @param updateMsg the update message
*/
public void handleControlLoopUpdate(ControlLoopUpdate updateMsg,
- List<ControlLoopElementDefinition> clElementDefinitions) {
+ List<ControlLoopElementDefinition> clElementDefinitions) {
if (!updateMsg.appliesTo(participantType, participantId)) {
return;
@@ -222,7 +224,7 @@ public class ControlLoopHandler {
controlLoopUpdateAck.setParticipantType(participantType);
controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId()
- + " already defined on participant " + participantId);
+ + " already defined on participant " + participantId);
controlLoopUpdateAck.setResult(false);
controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
@@ -235,22 +237,22 @@ public class ControlLoopHandler {
return;
}
- List<ControlLoopElement> clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
+ var clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
try {
- for (ControlLoopElement element : clElements) {
- ToscaNodeTemplate clElementNodeTemplate = getClElementNodeTemplate(
- clElementDefinitions, element.getDefinition());
- for (ControlLoopElementListener clElementListener : listeners) {
- clElementListener.controlLoopElementUpdate(updateMsg.getControlLoopId(),
- element, clElementNodeTemplate);
+ for (var element : clElements) {
+ var clElementNodeTemplate =
+ getClElementNodeTemplate(clElementDefinitions, element.getDefinition());
+ for (var clElementListener : listeners) {
+ clElementListener.controlLoopElementUpdate(updateMsg.getControlLoopId(), element,
+ clElementNodeTemplate);
}
}
} catch (PfModelException e) {
LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId());
}
- Map<UUID, ControlLoopElement> clElementMap = prepareClElementMap(clElements);
+ var clElementMap = prepareClElementMap(clElements);
controlLoop = new ControlLoop();
controlLoop.setDefinition(updateMsg.getControlLoopId());
controlLoop.setElements(clElementMap);
@@ -258,8 +260,8 @@ public class ControlLoopHandler {
}
private ToscaNodeTemplate getClElementNodeTemplate(List<ControlLoopElementDefinition> clElementDefinitions,
- ToscaConceptIdentifier clElementDefId) {
- for (ControlLoopElementDefinition clElementDefinition : clElementDefinitions) {
+ ToscaConceptIdentifier clElementDefId) {
+ for (var clElementDefinition : clElementDefinitions) {
if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) {
return clElementDefinition.getControlLoopElementToscaNodeTemplate();
}
@@ -268,11 +270,9 @@ public class ControlLoopHandler {
}
private List<ControlLoopElement> storeElementsOnThisParticipant(List<ParticipantUpdates> participantUpdates) {
- var clElementMap =
- participantUpdates.stream()
+ var clElementMap = participantUpdates.stream()
.flatMap(participantUpdate -> participantUpdate.getControlLoopElementList().stream())
- .filter(element -> participantType.equals(element.getParticipantType()))
- .collect(Collectors.toList());
+ .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList());
for (var element : clElementMap) {
elementsOnThisParticipant.put(element.getId(), element);
@@ -282,7 +282,7 @@ public class ControlLoopHandler {
private Map<UUID, ControlLoopElement> prepareClElementMap(List<ControlLoopElement> clElements) {
Map<UUID, ControlLoopElement> clElementMap = new LinkedHashMap<>();
- for (ControlLoopElement element : clElements) {
+ for (var element : clElements) {
clElementMap.put(element.getId(), element);
}
return clElementMap;
@@ -295,19 +295,9 @@ public class ControlLoopHandler {
* @param orderedState orderedState
*/
private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED);
- controlLoopMap.remove(controlLoop.getKey().asIdentifier());
-
- for (ControlLoopElementListener clElementListener : listeners) {
- try {
- for (ControlLoopElement element : controlLoop.getElements().values()) {
- clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(),
- element.getId(), element.getState(), orderedState);
- }
- } catch (PfModelException e) {
- LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
- }
- }
+ handleStateChange(controlLoop, orderedState);
+ controlLoopMap.remove(controlLoop.getDefinition());
+ controlLoop.getElements().values().forEach(element -> elementsOnThisParticipant.remove(element.getId()));
}
/**
@@ -317,7 +307,7 @@ public class ControlLoopHandler {
* @param orderedState orderedState
*/
private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE);
+ handleStateChange(controlLoop, orderedState);
}
/**
@@ -327,7 +317,7 @@ public class ControlLoopHandler {
* @param orderedState orderedState
*/
private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING);
+ handleStateChange(controlLoop, orderedState);
}
/**
@@ -335,30 +325,30 @@ public class ControlLoopHandler {
*
* @param controlLoop participant status in memory
* @param orderedState orderedState the new ordered state the participant should have
- * @param newState new state of the control loop elements
*/
- private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- ControlLoopState newState) {
+ private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
if (orderedState.equals(controlLoop.getOrderedState())) {
var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
controlLoopAck.setParticipantId(participantId);
controlLoopAck.setParticipantType(participantType);
- controlLoopAck.setMessage("Control loop is already in state" + orderedState);
+ controlLoopAck.setMessage("Control loop is already in state " + orderedState);
controlLoopAck.setResult(false);
controlLoopAck.setControlLoopId(controlLoop.getDefinition());
publisher.sendControlLoopAck(controlLoopAck);
return;
}
- if (!CollectionUtils.isEmpty(controlLoop.getElements().values())) {
- controlLoop.getElements().values().forEach(element -> {
- element.setState(newState);
- element.setOrderedState(orderedState);
- });
+ for (var clElementListener : listeners) {
+ try {
+ for (var element : controlLoop.getElements().values()) {
+ clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), element.getId(),
+ element.getState(), orderedState);
+ }
+ } catch (PfModelException e) {
+ LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
+ }
}
-
- controlLoop.setOrderedState(orderedState);
}
/**
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
index 5458f7c34..1d445324b 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
@@ -24,7 +24,6 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
@@ -48,7 +47,7 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
private List<TopicSink> topicSinks;
private List<TopicSource> topicSources;
- ParticipantIntermediaryApi participantIntermediaryApi;
+ private ParticipantHandler participantHandler;
private final MessageTypeDispatcher msgDispatcher;
@@ -56,13 +55,14 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
* Instantiate the activator for participant.
*
* @param parameters the ParticipantParameters
+ * @param participantHandler the ParticipantHandler
* @param publishers list of Publishers
* @param listeners list of Listeners
*/
public <T> IntermediaryActivator(final ParticipantParameters parameters,
- ParticipantIntermediaryApi participantIntermediaryApi, List<Publisher> publishers,
+ ParticipantHandler participantHandler, List<Publisher> publishers,
List<Listener<T>> listeners) {
- this.participantIntermediaryApi = participantIntermediaryApi;
+ this.participantHandler = participantHandler;
topicSinks = TopicEndpointManager.getManager()
.addTopicSinks(parameters.getIntermediaryParameters().getClampControlLoopTopics().getTopicSinks());
@@ -118,11 +118,11 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
}
private void sendParticipantRegister() {
- participantIntermediaryApi.sendParticipantRegister();
+ participantHandler.sendParticipantRegister();
}
private void sendParticipantDeregister() {
- participantIntermediaryApi.sendParticipantDeregister();
+ participantHandler.sendParticipantDeregister();
}
/**
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index 19641b0d5..69f8febb8 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
+import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
@@ -66,13 +67,16 @@ import org.springframework.stereotype.Component;
/**
* This class is responsible for managing the state of a participant.
*/
-@Getter
@Component
public class ParticipantHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantHandler.class);
+ @Getter
private final ToscaConceptIdentifier participantType;
+
+ @Getter
private final ToscaConceptIdentifier participantId;
+
private final ControlLoopHandler controlLoopHandler;
private final ParticipantStatistics participantStatistics;
private final ParticipantMessagePublisher publisher;
@@ -110,11 +114,6 @@ public class ParticipantHandler {
* @param participantStatusReqMsg participant participantStatusReq message
*/
public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) {
- var controlLoops = controlLoopHandler.getControlLoops();
- for (ControlLoopElementListener clElementListener : controlLoopHandler.getListeners()) {
- updateClElementStatistics(controlLoops, clElementListener);
- }
-
var participantStatus = makeHeartbeat(true);
publisher.sendParticipantStatus(participantStatus);
}
@@ -331,6 +330,12 @@ public class ParticipantHandler {
* Method to send heartbeat to controlloop runtime.
*/
public ParticipantStatus makeHeartbeat(boolean responseToParticipantStatusReq) {
+ if (!responseToParticipantStatusReq) {
+ var controlLoops = controlLoopHandler.getControlLoops();
+ for (var clElementListener : controlLoopHandler.getListeners()) {
+ updateClElementStatistics(controlLoops, clElementListener);
+ }
+ }
this.participantStatistics.setState(state);
this.participantStatistics.setHealthStatus(healthStatus);
this.participantStatistics.setTimeStamp(Instant.now());
@@ -363,10 +368,15 @@ public class ParticipantHandler {
clStatitistics.setControlLoopId(entry.getKey());
ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList();
clElementStatisticsList
- .setClElementStatistics(entry.getValue().getControlLoopElementStatisticsList(entry.getValue()));
+ .setClElementStatistics(entry.getValue().getElements().values()
+ .stream()
+ .map(ControlLoopElement::getClElementStatistics)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList()));
clStatitistics.setClElementStatisticsList(clElementStatisticsList);
clInfo.setControlLoopStatistics(clStatitistics);
clInfo.setState(entry.getValue().getState());
+ controlLoopInfoList.add(clInfo);
}
return controlLoopInfoList;
}