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/rest/CoderHttpMesageConverter.java (renamed from runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/CoderHttpMesageConverter.java)2
-rw-r--r--common/src/main/java/org/onap/policy/clamp/controlloop/common/rest/RequestResponseLoggingFilter.java (renamed from runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/RequestResponseLoggingFilter.java)2
-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/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java3
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java5
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java75
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java69
-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--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java92
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java100
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java102
-rw-r--r--participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json142
-rw-r--r--pom.xml6
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java3
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/ConverterConfiguration.java1
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/FilterConfig.java2
-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
21 files changed, 591 insertions, 458 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/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/CoderHttpMesageConverter.java b/common/src/main/java/org/onap/policy/clamp/controlloop/common/rest/CoderHttpMesageConverter.java
index cdd6ea73b..9eb43fd6f 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/CoderHttpMesageConverter.java
+++ b/common/src/main/java/org/onap/policy/clamp/controlloop/common/rest/CoderHttpMesageConverter.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.controlloop.runtime.config;
+package org.onap.policy.clamp.controlloop.common.rest;
import java.io.IOException;
import java.io.InputStreamReader;
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/RequestResponseLoggingFilter.java b/common/src/main/java/org/onap/policy/clamp/controlloop/common/rest/RequestResponseLoggingFilter.java
index 0dd00e766..915cdf0b2 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/RequestResponseLoggingFilter.java
+++ b/common/src/main/java/org/onap/policy/clamp/controlloop/common/rest/RequestResponseLoggingFilter.java
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.controlloop.runtime.main.web;
+package org.onap.policy.clamp.controlloop.common.rest;
import java.io.IOException;
import java.util.UUID;
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/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
index 580bffa80..5e72d9479 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
@@ -34,7 +34,8 @@ import org.springframework.context.annotation.ComponentScan;
@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.simulator.main.parameters")
@ComponentScan({
"org.onap.policy.clamp.controlloop.participant.simulator",
- "org.onap.policy.clamp.controlloop.participant.intermediary"
+ "org.onap.policy.clamp.controlloop.participant.intermediary",
+ "org.onap.policy.clamp.controlloop.common.rest"
})
//@formatter:on
public class ParticipantSimulatorApplication {
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 d28ddf9dc..f2079edf5 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,9 +20,9 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
+import org.onap.policy.clamp.controlloop.common.rest.RequestResponseLoggingFilter;
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;
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
index 16da5cf7f..28dd2f9bc 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
import java.util.List;
+import org.onap.policy.clamp.controlloop.common.rest.CoderHttpMesageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
@@ -32,8 +33,8 @@ public class YamlConfiguration implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
- converters.add(new YamlHttpMessageConverter<>("yaml"));
- converters.add(new YamlHttpMessageConverter<>("json"));
+ converters.add(new CoderHttpMesageConverter<>("yaml"));
+ converters.add(new CoderHttpMesageConverter<>("json"));
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN));
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
deleted file mode 100644
index d9a72ce10..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.config;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.nio.charset.StandardCharsets;
-import javax.ws.rs.core.Response;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.coder.StandardYamlCoder;
-import org.springframework.http.HttpInputMessage;
-import org.springframework.http.HttpOutputMessage;
-import org.springframework.http.MediaType;
-import org.springframework.http.converter.AbstractHttpMessageConverter;
-import org.springframework.http.converter.HttpMessageNotReadableException;
-import org.springframework.http.converter.HttpMessageNotWritableException;
-
-public class YamlHttpMessageConverter<T> extends AbstractHttpMessageConverter<T> {
-
- private Coder coder;
-
- public YamlHttpMessageConverter(String type) {
- super(new MediaType("application", type, StandardCharsets.UTF_8));
- this.coder = "json".equals(type) ? new StandardCoder() : new StandardYamlCoder();
- }
-
- @Override
- protected boolean supports(Class<?> clazz) {
- return true;
- }
-
- @Override
- protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
- throws IOException, HttpMessageNotReadableException {
- try (var is = new InputStreamReader(inputMessage.getBody(), StandardCharsets.UTF_8)) {
- return coder.decode(is, clazz);
- } catch (CoderException e) {
- throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
- }
- }
-
- @Override
- protected void writeInternal(T t, HttpOutputMessage outputMessage)
- throws IOException, HttpMessageNotWritableException {
- try (var writer = new OutputStreamWriter(outputMessage.getBody(), StandardCharsets.UTF_8)) {
- coder.encode(writer, t);
- } catch (CoderException e) {
- throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
- }
- }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java
deleted file mode 100644
index 9626421e8..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/RequestResponseLoggingFilter.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.rest;
-
-import java.io.IOException;
-import java.util.UUID;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-
-@Component
-@Order(2)
-public class RequestResponseLoggingFilter implements Filter {
-
- private static final String VERSION_MINOR_NAME = "X-MinorVersion";
- private static final String VERSION_PATCH_NAME = "X-PatchVersion";
- private static final String VERSION_LATEST_NAME = "X-LatestVersion";
- public static final String API_VERSION = "1.0.0";
- public static final String REQUEST_ID_NAME = "X-ONAP-RequestID";
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws IOException, ServletException {
-
-
- HttpServletResponse res = (HttpServletResponse) response;
- HttpServletRequest req = (HttpServletRequest) request;
-
- /*
- * Disabling sonar because of ONAP requires the request ID to be copied from the request
- * to the response, and just a simulator used during testing.
- */
- String requestId = req.getHeader(REQUEST_ID_NAME);
- res.addHeader(REQUEST_ID_NAME, requestId != null ? requestId : UUID.randomUUID().toString()); // NOSONAR
-
- res.addHeader(VERSION_MINOR_NAME, "0");
- res.addHeader(VERSION_PATCH_NAME, "0");
- res.addHeader(VERSION_LATEST_NAME, API_VERSION);
-
- chain.doFilter(request, response);
- }
-
-}
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/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
index 29387959b..e77dd69ee 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
@@ -21,20 +21,29 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.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.messages.dmaap.participant.ControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -45,14 +54,14 @@ class ControlLoopHandlerTest {
@Test
void controlLoopHandlerTest() {
- ControlLoopHandler clh = commonTestData.getMockControlLoopHandler();
+ var clh = commonTestData.getMockControlLoopHandler();
assertNotNull(clh.getControlLoops());
assertNotNull(clh.getControlLoopMap());
assertNotNull(clh.getElementsOnThisParticipant());
- UUID elementId1 = UUID.randomUUID();
- ControlLoopElement element = new ControlLoopElement();
+ var elementId1 = UUID.randomUUID();
+ var element = new ControlLoopElement();
element.setId(elementId1);
element.setDefinition(new ToscaConceptIdentifier(
"org.onap.policy.controlloop.PolicyControlLoopParticipant", "1.0.1"));
@@ -62,22 +71,21 @@ class ControlLoopHandlerTest {
ControlLoopElementListener listener = mock(ControlLoopElementListener.class);
clh.registerControlLoopElementListener(listener);
assertThat(clh.getListeners()).contains(listener);
-
}
@Test
void updateNullControlLoopHandlerTest() {
- UUID id = UUID.randomUUID();
+ var id = UUID.randomUUID();
- ControlLoopHandler clh = commonTestData.getMockControlLoopHandler();
+ var clh = commonTestData.getMockControlLoopHandler();
assertNull(clh.updateControlLoopElementState(null, null, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
assertNull(clh.updateControlLoopElementState(null, id, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
- ClElementStatistics clElementStatistics = new ClElementStatistics();
- ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
+ var clElementStatistics = new ClElementStatistics();
+ var controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
clElementStatistics.setParticipantId(controlLoopId);
clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
clElementStatistics.setTimeStamp(Instant.now());
@@ -85,9 +93,77 @@ class ControlLoopHandlerTest {
clh.updateControlLoopElementStatistics(id, clElementStatistics);
assertNull(clh.updateControlLoopElementState(controlLoopId, id, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
+ }
+
+ @Test
+ void updateControlLoopHandlerTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var clh = setTestControlLoopHandler(id, uuid);
+ var key = clh.getElementsOnThisParticipant().keySet().iterator().next();
+ var value = clh.getElementsOnThisParticipant().get(key);
+ assertEquals(ControlLoopState.UNINITIALISED, value.getState());
+ clh.updateControlLoopElementState(id, uuid, ControlLoopOrderedState.UNINITIALISED,
+ ControlLoopState.PASSIVE);
+ assertEquals(ControlLoopState.PASSIVE, value.getState());
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ assertNotEquals(uuid, value.getClElementStatistics().getId());
+ clh.updateControlLoopElementStatistics(uuid, clElementStatistics);
+ assertEquals(uuid, value.getClElementStatistics().getId());
+ }
+
+ @Test
+ void handleControlLoopUpdateExceptionTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var stateChange = new ControlLoopStateChange();
+ stateChange.setControlLoopId(id);
+ stateChange.setParticipantId(id);
+ stateChange.setMessageId(uuid);
+ stateChange.setOrderedState(ControlLoopOrderedState.RUNNING);
+ stateChange.setCurrentState(ControlLoopState.UNINITIALISED);
+ stateChange.setTimestamp(Instant.ofEpochMilli(3000));
+
+ var clh = setTestControlLoopHandler(id, uuid);
+ clh.handleControlLoopStateChange(stateChange);
+ var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ stateChange.setControlLoopId(newid);
+ stateChange.setParticipantId(newid);
+ assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChange));
+
+ List<ControlLoopElementDefinition> clElementDefinitions = new ArrayList<>();
+ var cld = new ControlLoopElementDefinition();
+ cld.setClElementDefinitionId(id);
+ clElementDefinitions.add(cld);
+ var updateMsg = new ControlLoopUpdate();
+ updateMsg.setControlLoopId(id);
+ updateMsg.setMessageId(uuid);
+ updateMsg.setParticipantId(id);
+ updateMsg.setStartPhase(0);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ updateMsg.setStartPhase(1);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ }
+
+ private ControlLoopHandler setTestControlLoopHandler(ToscaConceptIdentifier id, UUID uuid) throws CoderException {
+ var clh = commonTestData.getMockControlLoopHandler();
+ var key = commonTestData.getTestControlLoopMap().keySet().iterator().next();
+ var value = commonTestData.getTestControlLoopMap().get(key);
+ clh.getControlLoopMap().put(key, value);
+ var keyElem = commonTestData.setControlLoopElementTest(uuid, id).keySet().iterator().next();
+ var valueElem = commonTestData.setControlLoopElementTest(uuid, id).get(keyElem);
+ clh.getElementsOnThisParticipant().put(keyElem, valueElem);
+ return clh;
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
index 63db364ca..d00697521 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -23,23 +23,28 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantAckMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
class ParticipantHandlerTest {
private CommonTestData commonTestData = new CommonTestData();
@@ -48,11 +53,11 @@ class ParticipantHandlerTest {
@Test
void mockParticipantHandlerTest() {
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
+ var participantHandler = commonTestData.getMockParticipantHandler();
assertNull(participantHandler.getParticipant(null, null));
assertEquals("org.onap.PM_CDS_Blueprint 1.0.1", participantHandler.getParticipantId().toString());
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
assertEquals(id, participantHandler.getParticipantId());
assertEquals(id, participantHandler.getParticipantType());
assertThat(participantHandler.getClElementDefinitionCommonProperties(id)).isEmpty();
@@ -61,27 +66,27 @@ class ParticipantHandlerTest {
@Test
void handleUpdateTest() {
- ParticipantParameters parameters = CommonTestData.getParticipantParameters();
- ControlLoopHandler controlLoopHander = commonTestData.getMockControlLoopHandler();
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
- ParticipantHandler emptyParticipantHandler =
+ var parameters = CommonTestData.getParticipantParameters();
+ var controlLoopHander = commonTestData.getMockControlLoopHandler();
+ var publisher = new ParticipantMessagePublisher();
+ var emptyParticipantHandler =
new ParticipantHandler(parameters, publisher, controlLoopHander);
- ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
+ var participantUpdateMsg = new ParticipantUpdate();
assertThatThrownBy(() ->
emptyParticipantHandler.handleParticipantUpdate(participantUpdateMsg))
.isInstanceOf(RuntimeException.class);
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantHandler = commonTestData.getMockParticipantHandler();
+
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
participantUpdateMsg.setControlLoopId(id);
participantUpdateMsg.setParticipantId(id);
participantUpdateMsg.setParticipantType(id);
participantUpdateMsg.setMessageId(UUID.randomUUID());
participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
-
- ParticipantStatus heartbeatF = participantHandler.makeHeartbeat(false);
+ var heartbeatF = participantHandler.makeHeartbeat(false);
assertEquals(id, heartbeatF.getParticipantId());
assertEquals(ParticipantState.UNKNOWN, heartbeatF.getParticipantStatistics().getState());
assertThat(heartbeatF.getControlLoopInfoList()).isEmpty();
@@ -89,30 +94,83 @@ class ParticipantHandlerTest {
participantHandler.handleParticipantUpdate(participantUpdateMsg);
assertThat(participantHandler.getClElementDefinitionCommonProperties(id)).isEmpty();
- ParticipantStatus heartbeatT = participantHandler.makeHeartbeat(true);
+ var heartbeatT = participantHandler.makeHeartbeat(true);
assertEquals(id, heartbeatT.getParticipantId());
assertEquals(ParticipantState.TERMINATED, heartbeatT.getParticipantStatistics().getState());
assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
assertEquals(id, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
+ var pum = setListParticipantDefinition(participantUpdateMsg);
+ participantHandler.handleParticipantUpdate(pum);
+ var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
+ assertEquals(id, heartbeatTAfterUpdate.getParticipantId());
+ assertEquals(ParticipantState.PASSIVE, heartbeatTAfterUpdate.getParticipantStatistics().getState());
+
+ }
+
+ private ParticipantUpdate setListParticipantDefinition(ParticipantUpdate participantUpdateMsg) {
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+ var def = new ParticipantDefinition();
+ def.setParticipantId(id);
+ def.setParticipantType(id);
+ participantDefinitionUpdates.add(def);
+ participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ return participantUpdateMsg;
}
@Test
void handleParticipantTest() {
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- Participant p = participantHandler.getParticipant(id.getName(), id.getVersion());
+ var participantHandler = commonTestData.getMockParticipantHandler();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var p = participantHandler.getParticipant(id.getName(), id.getVersion());
assertEquals(ParticipantState.UNKNOWN, p.getParticipantState());
participantHandler.updateParticipantState(id, ParticipantState.PASSIVE);
- Participant p2 = participantHandler.getParticipant(id.getName(), id.getVersion());
+ var p2 = participantHandler.getParticipant(id.getName(), id.getVersion());
assertEquals(ParticipantState.PASSIVE, p2.getParticipantState());
- ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck();
+ var participantRegisterAckMsg = new ParticipantRegisterAck();
participantRegisterAckMsg.setState(ParticipantState.TERMINATED);
participantHandler.handleParticipantRegisterAck(participantRegisterAckMsg);
assertEquals(ParticipantHealthStatus.HEALTHY, participantHandler.makeHeartbeat(false).getHealthStatus());
+ var emptyid = new ToscaConceptIdentifier("", ID_VERSION);
+ assertNull(participantHandler.updateParticipantState(emptyid, ParticipantState.PASSIVE));
+
+ var sameid = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participant = participantHandler.updateParticipantState(sameid, ParticipantState.PASSIVE);
+ assertEquals(participant.getDefinition(), sameid);
+
+ }
+
+ @Test
+ void checkAppliesTo() {
+ var participantHandler = commonTestData.getMockParticipantHandler();
+ var participantAckMsg =
+ new ParticipantAckMessage(ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ assertTrue(participantHandler.appliesTo(participantAckMsg));
+
+ var participantMsg =
+ new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
+ assertTrue(participantHandler.appliesTo(participantMsg));
+
+ var emptyid = new ToscaConceptIdentifier("", ID_VERSION);
+ participantMsg.setParticipantType(emptyid);
+ assertFalse(participantHandler.appliesTo(participantMsg));
+
+ }
+
+ @Test
+ void getControlLoopInfoListTest() throws CoderException {
+ var participantHandler = commonTestData.getParticipantHandlerControlLoops();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ participantHandler.sendHeartbeat();
+ assertEquals(id, participantHandler.makeHeartbeat(false)
+ .getControlLoopInfoList()
+ .get(0)
+ .getControlLoopId());
+
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
index af88b5a8a..43f3c8e2b 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
@@ -20,18 +20,28 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters;
+import java.io.File;
+import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.UUID;
import org.mockito.Mockito;
+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;
+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.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.DummyParticipantParameters;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
@@ -129,7 +139,7 @@ public class CommonTestData {
* @return topic parameters
*/
public static TopicParameters getTopicParams() {
- final TopicParameters topicParams = new TopicParameters();
+ final var topicParams = new TopicParameters();
topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
topicParams.setTopicCommInfrastructure("dmaap");
topicParams.setServers(Arrays.asList("localhost"));
@@ -152,8 +162,7 @@ public class CommonTestData {
*/
private ParticipantMessagePublisher getParticipantMessagePublisher() {
synchronized (lockit) {
- ParticipantMessagePublisher participantMessagePublisher =
- new ParticipantMessagePublisher();
+ var participantMessagePublisher = new ParticipantMessagePublisher();
participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
return participantMessagePublisher;
}
@@ -176,12 +185,89 @@ public class CommonTestData {
* @return participant Handler
*/
public ParticipantHandler getMockParticipantHandler() {
- ParticipantParameters parameters = getParticipantParameters();
- ControlLoopHandler controlLoopHander = getMockControlLoopHandler();
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
+ var parameters = getParticipantParameters();
+ var controlLoopHandler = getMockControlLoopHandler();
+ var publisher = new ParticipantMessagePublisher();
publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- ParticipantHandler participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHander);
+ var participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHandler);
return participantHandler;
}
+ /**
+ * Returns a mocked ParticipantHandler for test cases.
+ *
+ * @return participant Handler
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public ParticipantHandler getParticipantHandlerControlLoops() throws CoderException {
+ var controlLoopHandler = Mockito.mock(ControlLoopHandler.class);
+ Mockito.doReturn(getTestControlLoops()).when(controlLoopHandler).getControlLoops();
+ Mockito.doReturn(getTestControlLoopMap()).when(controlLoopHandler).getControlLoopMap();
+ var publisher = new ParticipantMessagePublisher();
+ publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ var parameters = getParticipantParameters();
+ var participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHandler);
+ participantHandler.sendParticipantRegister();
+ participantHandler.handleParticipantStatusReq(null);
+ participantHandler.sendParticipantDeregister();
+ var participantDeregisterAckMsg = new ParticipantDeregisterAck();
+ participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
+ participantHandler.handleParticipantDeregisterAck(participantDeregisterAckMsg);
+ return participantHandler;
+ }
+
+ /**
+ * Returns a Map of ToscaConceptIdentifier and ControlLoop for test cases.
+ *
+ * @return controlLoopMap
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public Map<ToscaConceptIdentifier, ControlLoop> getTestControlLoopMap() throws CoderException {
+ var controlLoops = getTestControlLoops();
+ var controlLoop = controlLoops.getControlLoopList().get(1);
+ var id = getParticipantId();
+ Map<ToscaConceptIdentifier, ControlLoop> controlLoopMap = new LinkedHashMap<>();
+ controlLoopMap.put(id, controlLoop);
+ return controlLoopMap;
+ }
+
+ /**
+ * Returns List of ControlLoop for test cases.
+ *
+ * @return ControlLoops
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public ControlLoops getTestControlLoops() throws CoderException {
+ return new StandardCoder()
+ .decode(new File("src/test/resources/providers/TestControlLoops.json"), ControlLoops.class);
+ }
+
+ /**
+ * Returns a map for a elementsOnThisParticipant for test cases.
+ *
+ * @param uuid UUID and id ToscaConceptIdentifier
+ * @return a map suitable for elementsOnThisParticipant
+ */
+ public Map<UUID, ControlLoopElement> setControlLoopElementTest(UUID uuid, ToscaConceptIdentifier id) {
+ var clElement = new ControlLoopElement();
+ clElement.setId(uuid);
+ clElement.setParticipantId(id);
+ clElement.setDefinition(id);
+ clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ clElement.setClElementStatistics(clElementStatistics);
+
+ Map<UUID, ControlLoopElement> elementsOnThisParticipant = new LinkedHashMap<>();
+ elementsOnThisParticipant.put(uuid, clElement);
+ return elementsOnThisParticipant;
+ }
+
}
diff --git a/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json b/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json
new file mode 100644
index 000000000..fedda9600
--- /dev/null
+++ b/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json
@@ -0,0 +1,142 @@
+{
+ "controlLoopList": [
+ {
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.0.0"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c20": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c20",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "DCAE Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c21": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c23": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c23",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "CDS Control Loop Element for the PMSH instance 0 control loop"
+ }
+ },
+ "name": "PMSHInstance0",
+ "version": "1.0.1",
+ "description": "PMSH control loop instance 0"
+ },
+ {
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.0.0"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c24": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c24",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "DCAE Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c25": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c25",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Monitoring Policy Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c26": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c26",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Operational Policy Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c27": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c27",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "CDS Control Loop Element for the PMSH instance 1 control loop"
+ }
+ },
+ "name": "PMSHInstance1",
+ "version": "1.0.1",
+ "description": "PMSH control loop instance 1"
+ }
+ ]
+}
diff --git a/pom.xml b/pom.xml
index d09de75ca..3203e8ac0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.onap.policy.parent</groupId>
<artifactId>integration</artifactId>
- <version>3.4.3</version>
+ <version>3.5.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.clamp</groupId>
@@ -50,8 +50,8 @@
</description>
<properties>
- <policy.common.version>1.9.1</policy.common.version>
- <policy.models.version>2.5.1</policy.models.version>
+ <policy.common.version>1.10.0-SNAPSHOT</policy.common.version>
+ <policy.models.version>2.6.0-SNAPSHOT</policy.models.version>
</properties>
<modules>
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java
index 5fbd36c06..a9b45c589 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java
@@ -29,7 +29,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication
@ComponentScan({"org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider",
- "org.onap.policy.clamp.controlloop.runtime"})
+ "org.onap.policy.clamp.controlloop.runtime",
+ "org.onap.policy.clamp.controlloop.common.rest"})
@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.runtime.main.parameters")
public class Application {
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/ConverterConfiguration.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/ConverterConfiguration.java
index b14c675df..d67d2e75d 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/ConverterConfiguration.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/ConverterConfiguration.java
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.controlloop.runtime.config;
import java.util.Arrays;
import java.util.List;
+import org.onap.policy.clamp.controlloop.common.rest.CoderHttpMesageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/FilterConfig.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/FilterConfig.java
index d58553ae4..57bfc2e7c 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/FilterConfig.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/FilterConfig.java
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.controlloop.runtime.config;
-import org.onap.policy.clamp.controlloop.runtime.main.web.RequestResponseLoggingFilter;
+import org.onap.policy.clamp.controlloop.common.rest.RequestResponseLoggingFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.
*/