aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/pom.xml8
-rw-r--r--common/src/main/java/org/onap/policy/clamp/controlloop/common/utils/CommonUtils.java150
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java105
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java71
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java56
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java53
6 files changed, 177 insertions, 266 deletions
diff --git a/common/pom.xml b/common/pom.xml
index 75239ecf8..c60ed6c8f 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -34,6 +34,14 @@
<name>${project.artifactId}</name>
<description>Common utilities and code for the TOSCA Control Loop system</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.clamp</groupId>
+ <artifactId>policy-clamp-models</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
<build>
<plugins>
<!-- Builds examples jar -->
diff --git a/common/src/main/java/org/onap/policy/clamp/controlloop/common/utils/CommonUtils.java b/common/src/main/java/org/onap/policy/clamp/controlloop/common/utils/CommonUtils.java
new file mode 100644
index 000000000..4b0e41f23
--- /dev/null
+++ b/common/src/main/java/org/onap/policy/clamp/controlloop/common/utils/CommonUtils.java
@@ -0,0 +1,150 @@
+/*-
+ * ============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.common.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+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.controlloop.concepts.ParticipantUpdates;
+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.ToscaNodeType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
+
+/**
+ * Utility functions used in controlloop-runtime and participants.
+ *
+ */
+public class CommonUtils {
+ private static final String POLICY_TYPE_ID = "policy_type_id";
+ private static final String POLICY_ID = "policy_id";
+
+ /**
+ * Prepare participant updates map.
+ *
+ * @param clElement controlloop element
+ * @param participantUpdates list of participantUpdates
+ */
+ public static void prepareParticipantUpdate(ControlLoopElement clElement,
+ List<ParticipantUpdates> participantUpdates) {
+ if (participantUpdates.isEmpty()) {
+ participantUpdates.add(getControlLoopElementList(clElement));
+ return;
+ }
+
+ var participantExists = false;
+ for (ParticipantUpdates participantUpdate : participantUpdates) {
+ if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) {
+ participantUpdate.setControlLoopElementList(List.of(clElement));
+ participantExists = true;
+ }
+ }
+ if (!participantExists) {
+ participantUpdates.add(getControlLoopElementList(clElement));
+ }
+ }
+
+ private static ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) {
+ var participantUpdate = new ParticipantUpdates();
+ participantUpdate.setParticipantId(clElement.getParticipantId());
+ participantUpdate.setControlLoopElementList(List.of(clElement));
+ return participantUpdate;
+ }
+
+ /**
+ * Set the Policy information in the service template for the controlloopelement.
+ *
+ * @param clElement controlloop element
+ * @param toscaServiceTemplate ToscaServiceTemplate
+ */
+ public static void setServiceTemplatePolicyInfo(ControlLoopElement clElement,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ // Pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment
+ if (toscaServiceTemplate.getPolicyTypes() == null
+ && toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() == null) {
+ return;
+ }
+ ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
+ toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes());
+ ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
+ toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies());
+ toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate);
+ toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes());
+ clElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
+ }
+
+ /**
+ * Prepare ParticipantDefinitionUpdate to set in the message.
+ *
+ * @param clParticipantType controlloop element
+ * @param entryKey key for the entry
+ * @param entryValue value relates to toscaNodeTemplate
+ * @param participantDefinitionUpdates list of participantDefinitionUpdates
+ * @param commonPropertiesMap common properties map
+ */
+ public static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates,
+ Map<String, ToscaNodeType> commonPropertiesMap) {
+
+ var clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
+ clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
+ if (commonPropertiesMap != null) {
+ ToscaNodeType nodeType = commonPropertiesMap.get(entryValue.getType());
+ if (nodeType != null) {
+ clDefinition.setCommonPropertiesMap(nodeType.getProperties());
+ }
+ }
+
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
+
+ if (participantDefinitionUpdates.isEmpty()) {
+ participantDefinitionUpdates
+ .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
+ } else {
+ var participantExists = false;
+ for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
+ if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) {
+ participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
+ participantExists = true;
+ }
+ }
+ if (!participantExists) {
+ participantDefinitionUpdates.add(
+ getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
+ }
+ }
+ }
+
+ private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
+ ToscaConceptIdentifier clParticipantType,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ var participantDefinition = new ParticipantDefinition();
+ participantDefinition.setParticipantType(clParticipantType);
+ controlLoopElementDefinitionList.add(clDefinition);
+ participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
+ return participantDefinition;
+ }
+}
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 25da5a3e9..d517ef61e 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
@@ -33,9 +33,9 @@ import java.util.Set;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.onap.policy.clamp.controlloop.common.utils.CommonUtils;
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;
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.controlloop.concepts.ParticipantDefinition;
@@ -53,7 +53,6 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
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.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,8 +63,6 @@ public final class TestListenerUtils {
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 POLICY_TYPE_ID = "policy_type_id";
- private static final String POLICY_ID = "policy_id";
/**
* Method to create a controlLoop from a yaml file.
@@ -174,65 +171,13 @@ public final class TestListenerUtils {
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (ControlLoopElement element : elements.values()) {
- populateToscaNodeTemplateFragment(element, toscaServiceTemplate);
- prepareParticipantUpdateForControlLoop(element, participantUpdates);
+ CommonUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate);
+ CommonUtils.prepareParticipantUpdate(element, participantUpdates);
}
clUpdateMsg.setParticipantUpdatesList(participantUpdates);
return clUpdateMsg;
}
- private static void populateToscaNodeTemplateFragment(ControlLoopElement clElement,
- ToscaServiceTemplate toscaServiceTemplate) {
- 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)
- || (toscaNodeTemplate.getProperties().get(POLICY_ID) != null)) {
- // ControlLoopElement for policy framework, send policies and policyTypes to participants
- if ((toscaServiceTemplate.getPolicyTypes() != null)
- || (toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() != null)) {
- ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
- toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes());
-
- ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
- toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies());
- toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate);
-
- toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes());
-
- clElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
- }
- }
- }
-
- private static void prepareParticipantUpdateForControlLoop(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 static 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;
- }
-
/**
* Method to create participantUpdateMsg.
*
@@ -259,10 +204,10 @@ public final class TestListenerUtils {
.getNodeTemplates().entrySet()) {
if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
toscaServiceTemplate)) {
- var clParticipantType =
- ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
- prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ CommonUtils.prepareParticipantDefinitionUpdate(
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()),
+ toscaInputEntry.getKey(), toscaInputEntry.getValue(),
+ participantDefinitionUpdates, null);
}
}
@@ -270,42 +215,6 @@ public final class TestListenerUtils {
return participantUpdateMsg;
}
- private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, 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, clParticipantType, controlLoopElementDefinitionList));
- } else {
- boolean participantExists = false;
- for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
- if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) {
- participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
- participantExists = true;
- }
- }
- if (!participantExists) {
- participantDefinitionUpdates.add(
- getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
- }
- }
- }
-
- private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
- ParticipantDefinition participantDefinition = new ParticipantDefinition();
- participantDefinition.setParticipantType(clParticipantType);
- controlLoopElementDefinitionList.add(clDefinition);
- participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
- return participantDefinition;
- }
-
/**
* Method to create ControlLoopUpdate using the arguments passed.
*
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 bd3316abb..c9848248e 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
@@ -33,9 +33,9 @@ import java.util.Set;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.onap.policy.clamp.controlloop.common.utils.CommonUtils;
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;
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.controlloop.concepts.ParticipantDefinition;
@@ -166,39 +166,12 @@ public final class TestListenerUtils {
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (ControlLoopElement element : elements.values()) {
- prepareParticipantUpdateForControlLoop(element, participantUpdates);
+ CommonUtils.prepareParticipantUpdate(element, participantUpdates);
}
clUpdateMsg.setParticipantUpdatesList(participantUpdates);
return clUpdateMsg;
}
- private static void prepareParticipantUpdateForControlLoop(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 static 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;
- }
-
/**
* Method to create participantUpdateMsg.
*
@@ -226,8 +199,8 @@ public final class TestListenerUtils {
toscaServiceTemplate)) {
var clParticipantType =
ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
- prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ CommonUtils.prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
+ toscaInputEntry.getValue(), participantDefinitionUpdates, null);
}
}
@@ -235,42 +208,6 @@ public final class TestListenerUtils {
return participantUpdateMsg;
}
- private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, 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, clParticipantType, controlLoopElementDefinitionList));
- } else {
- boolean participantExists = false;
- for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
- if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) {
- participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
- participantExists = true;
- }
- }
- if (!participantExists) {
- participantDefinitionUpdates.add(
- getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
- }
- }
- }
-
- private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
- ParticipantDefinition participantDefinition = new ParticipantDefinition();
- participantDefinition.setParticipantType(clParticipantType);
- controlLoopElementDefinitionList.add(clDefinition);
- participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
- return participantDefinition;
- }
-
/**
* Method to create ControlLoopUpdate using the arguments passed.
*
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 74d987240..06fbcd649 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
@@ -27,15 +27,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.controlloop.common.utils.CommonUtils;
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.ParticipantUpdates;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -48,8 +47,6 @@ import org.springframework.stereotype.Component;
public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<ControlLoopUpdate> {
private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdatePublisher.class);
- private static final String POLICY_TYPE_ID = "policy_type_id";
- private static final String POLICY_ID = "policy_id";
private final PolicyModelsProvider modelsProvider;
/**
@@ -83,59 +80,12 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (ControlLoopElement element : controlLoop.getElements().values()) {
- ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate
- .getToscaTopologyTemplate().getNodeTemplates().get(element.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)
- || (toscaNodeTemplate.getProperties().get(POLICY_ID) != null)) {
- // ControlLoopElement for policy framework, send policies and policyTypes to participants
- if ((toscaServiceTemplate.getPolicyTypes() != null)
- || (toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() != null)) {
- ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
- toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes());
-
- ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
- toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies());
- toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate);
-
- toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes());
-
- element.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
- }
- }
- prepareParticipantUpdate(element, participantUpdates);
+ CommonUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate);
+ CommonUtils.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 {
- var 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) {
- var 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 5d879dc56..c6788f12c 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
@@ -27,14 +27,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.common.utils.CommonUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
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.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
@@ -99,10 +98,10 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
for (var 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, commonPropertiesMap);
+ CommonUtils.prepareParticipantDefinitionUpdate(
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()),
+ toscaInputEntry.getKey(), toscaInputEntry.getValue(),
+ participantDefinitionUpdates, commonPropertiesMap);
}
}
@@ -113,48 +112,6 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
return true;
}
- private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates,
- Map<String, ToscaNodeType> commonPropertiesMap) {
-
- var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
- clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
- ToscaNodeType nodeType = commonPropertiesMap.get(entryValue.getType());
- if (nodeType != null) {
- clDefinition.setCommonPropertiesMap(nodeType.getProperties());
- }
-
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
-
- if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates
- .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
- } else {
- var participantExists = false;
- for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
- if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) {
- participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
- participantExists = true;
- }
- }
- if (!participantExists) {
- participantDefinitionUpdates.add(
- getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
- }
- }
- }
-
- private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
- var participantDefinition = new ParticipantDefinition();
- participantDefinition.setParticipantType(clParticipantType);
- controlLoopElementDefinitionList.add(clDefinition);
- participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
- return participantDefinition;
- }
-
/**
* Send ParticipantUpdate to Participant after that commissioning has been removed.
*/