summaryrefslogtreecommitdiffstats
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--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java24
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java84
-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/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java86
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java2
-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--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/SupervisionHandler.java22
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java32
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java4
-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
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java4
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java10
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java79
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java34
-rw-r--r--runtime-controlloop/src/test/resources/rest/controlloops/ControlLoopsSmoke.json174
32 files changed, 1058 insertions, 540 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/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
index 4c3dd4b06..c05311892 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
@@ -57,6 +57,30 @@ public final class ParticipantUtils {
}
/**
+ * Get the First StartPhase
+ * it depend of the state of the Control Loop
+ * and also from the all startPhase defined into the ToscaServiceTemplate.
+ * @param controlLoop the ControlLoop
+ * @param toscaServiceTemplate the ToscaServiceTemplate
+ * @return the First StartPhase
+ */
+ public static int getFirstStartPhase(ControlLoop controlLoop, ToscaServiceTemplate toscaServiceTemplate) {
+ var minStartPhase = 1000;
+ var maxStartPhase = 0;
+ for (var element : controlLoop.getElements().values()) {
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ minStartPhase = Math.min(minStartPhase, startPhase);
+ maxStartPhase = Math.max(maxStartPhase, startPhase);
+ }
+
+ return ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())
+ || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? minStartPhase
+ : maxStartPhase;
+ }
+
+ /**
* Finds startPhase from a map of properties.
*
* @param properties Map of properties
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java
new file mode 100644
index 000000000..3fb8b6d7f
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============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.models.controlloop.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+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.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;
+
+class ParticipantUtilsTest {
+
+ private static final Coder CODER = new StandardCoder();
+ private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml";
+ private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json";
+ private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
+ private static final String POLICY_CONTROL_LOOP_ELEMENT =
+ "org.onap.policy.clamp.controlloop.PolicyControlLoopElement";
+ private static final String PARTICIPANT_CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.Participant";
+ private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
+
+ @Test
+ void testFindParticipantType() throws CoderException {
+ var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1");
+ var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier)));
+ assertThat(result).isEqualTo(identifier);
+ }
+
+ @Test
+ void testFindStartPhase() {
+ var identifier = 13;
+ var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier));
+ assertThat(result).isEqualTo(identifier);
+ }
+
+ @Test
+ void testGetFirstStartPhase() throws CoderException {
+ var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML),
+ ToscaServiceTemplate.class);
+ var controlLoops = CODER.decode(ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON), ControlLoops.class);
+ var result = ParticipantUtils.getFirstStartPhase(controlLoops.getControlLoopList().get(0), serviceTemplate);
+ assertThat(result).isZero();
+ }
+
+ @Test
+ void testCheckIfNodeTemplateIsControlLoopElement() throws CoderException {
+ var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML),
+ ToscaServiceTemplate.class);
+ var nodeTemplate = new ToscaNodeTemplate();
+ nodeTemplate.setType(CONTROL_LOOP_ELEMENT);
+ assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue();
+
+ nodeTemplate.setType(POLICY_CONTROL_LOOP_ELEMENT);
+ assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue();
+
+ nodeTemplate.setType(PARTICIPANT_CONTROL_LOOP_ELEMENT);
+ assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isFalse();
+ }
+}
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/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
index ac135b0d3..5a0f4989f 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
@@ -93,7 +93,8 @@ public class ControlLoopHandler {
/**
* Handle a control loop element state change message.
*
- * @param id controlloop element id
+ * @param controlLoopId the controlLoop Id
+ * @param id the controlLoop UUID
* @param orderedState the current state
* @param newState the ordered state
* @return controlLoopElement the updated controlloop element
@@ -160,8 +161,10 @@ public class ControlLoopHandler {
* Handle a control loop state change message.
*
* @param stateChangeMsg the state change message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
- public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg) {
+ public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg,
+ List<ControlLoopElementDefinition> clElementDefinitions) {
if (stateChangeMsg.getControlLoopId() == null) {
return;
}
@@ -182,7 +185,8 @@ public class ControlLoopHandler {
return;
}
- handleState(controlLoop, stateChangeMsg.getOrderedState());
+ handleState(controlLoop, stateChangeMsg.getOrderedState(), stateChangeMsg.getStartPhase(),
+ clElementDefinitions);
}
/**
@@ -190,17 +194,20 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState controlloop ordered state
+ * @param startPhaseMsg startPhase from message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
- private void handleState(final ControlLoop controlLoop, ControlLoopOrderedState orderedState) {
+ private void handleState(final ControlLoop controlLoop, ControlLoopOrderedState orderedState, Integer startPhaseMsg,
+ List<ControlLoopElementDefinition> clElementDefinitions) {
switch (orderedState) {
case UNINITIALISED:
- handleUninitialisedState(controlLoop, orderedState);
+ handleUninitialisedState(controlLoop, orderedState, startPhaseMsg, clElementDefinitions);
break;
case PASSIVE:
- handlePassiveState(controlLoop, orderedState);
+ handlePassiveState(controlLoop, orderedState, startPhaseMsg, clElementDefinitions);
break;
case RUNNING:
- handleRunningState(controlLoop, orderedState);
+ handleRunningState(controlLoop, orderedState, startPhaseMsg, clElementDefinitions);
break;
default:
LOGGER.debug("StateChange message has no state, state is null {}", controlLoop.getDefinition());
@@ -212,6 +219,7 @@ public class ControlLoopHandler {
* Handle a control loop update message.
*
* @param updateMsg the update message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
public void handleControlLoopUpdate(ControlLoopUpdate updateMsg,
List<ControlLoopElementDefinition> clElementDefinitions) {
@@ -300,8 +308,7 @@ public class ControlLoopHandler {
ToscaConceptIdentifier clElementDefId) {
for (var clElementDefinition : clElementDefinitions) {
- if (clElementDefId.getName().contains(
- clElementDefinition.getClElementDefinitionId().getName())) {
+ if (clElementDefId.getName().contains(clElementDefinition.getClElementDefinitionId().getName())) {
return clElementDefinition.getControlLoopElementToscaNodeTemplate();
}
}
@@ -332,11 +339,18 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState orderedState
+ * @param startPhaseMsg startPhase from message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
- private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState);
- controlLoopMap.remove(controlLoop.getDefinition());
- controlLoop.getElements().values().forEach(element -> elementsOnThisParticipant.remove(element.getId()));
+ private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
+ Integer startPhaseMsg, List<ControlLoopElementDefinition> clElementDefinitions) {
+ handleStateChange(controlLoop, orderedState, startPhaseMsg, clElementDefinitions);
+ boolean isAllUninitialised = controlLoop.getElements().values().stream()
+ .filter(element -> !ControlLoopState.UNINITIALISED.equals(element.getState())).findAny().isEmpty();
+ if (isAllUninitialised) {
+ controlLoopMap.remove(controlLoop.getDefinition());
+ controlLoop.getElements().values().forEach(element -> elementsOnThisParticipant.remove(element.getId()));
+ }
}
/**
@@ -344,9 +358,12 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState orderedState
+ * @param startPhaseMsg startPhase from message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
- private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState);
+ private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
+ Integer startPhaseMsg, List<ControlLoopElementDefinition> clElementDefinitions) {
+ handleStateChange(controlLoop, orderedState, startPhaseMsg, clElementDefinitions);
}
/**
@@ -354,9 +371,12 @@ public class ControlLoopHandler {
*
* @param controlLoop participant response
* @param orderedState orderedState
+ * @param startPhaseMsg startPhase from message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
- private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState);
+ private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
+ Integer startPhaseMsg, List<ControlLoopElementDefinition> clElementDefinitions) {
+ handleStateChange(controlLoop, orderedState, startPhaseMsg, clElementDefinitions);
}
/**
@@ -364,8 +384,11 @@ public class ControlLoopHandler {
*
* @param controlLoop participant status in memory
* @param orderedState orderedState the new ordered state the participant should have
+ * @param startPhaseMsg startPhase from message
+ * @param clElementDefinitions the list of ControlLoopElementDefinition
*/
- private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
+ private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
+ Integer startPhaseMsg, List<ControlLoopElementDefinition> clElementDefinitions) {
if (orderedState.equals(controlLoop.getOrderedState())) {
var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
@@ -378,16 +401,27 @@ public class ControlLoopHandler {
return;
}
- controlLoop.getElements().values().stream().forEach(clElement -> {
- for (var clElementListener : listeners) {
- try {
- clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), clElement.getId(),
- clElement.getState(), orderedState);
- } catch (PfModelException e) {
- LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
+ controlLoop.getElements().values().stream().forEach(clElement -> controlLoopElementStateChange(controlLoop,
+ orderedState, clElement, startPhaseMsg, clElementDefinitions));
+ }
+
+ private void controlLoopElementStateChange(ControlLoop controlLoop, ControlLoopOrderedState orderedState,
+ ControlLoopElement clElement, Integer startPhaseMsg,
+ List<ControlLoopElementDefinition> clElementDefinitions) {
+ var clElementNodeTemplate = getClElementNodeTemplate(clElementDefinitions, clElement.getDefinition());
+ if (clElementNodeTemplate != null) {
+ int startPhase = ParticipantUtils.findStartPhase(clElementNodeTemplate.getProperties());
+ if (startPhaseMsg.equals(startPhase)) {
+ for (var clElementListener : listeners) {
+ try {
+ clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), clElement.getId(),
+ clElement.getState(), orderedState);
+ } catch (PfModelException e) {
+ LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
+ }
}
}
- });
+ }
}
/**
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index 0734cb9c7..d7537e3d8 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
@@ -156,7 +156,7 @@ public class ParticipantHandler {
* @param stateChangeMsg the state change message
*/
public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg) {
- controlLoopHandler.handleControlLoopStateChange(stateChangeMsg);
+ controlLoopHandler.handleControlLoopStateChange(stateChangeMsg, clElementDefsOnThisParticipant);
}
private void handleStateChange(ParticipantState newParticipantState, ParticipantUpdateAck response) {
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/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/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
index 960cb4304..2a1f9082f 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
@@ -36,6 +37,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
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.controlloop.concepts.ParticipantUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
@@ -51,7 +53,10 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDer
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -75,6 +80,7 @@ public class SupervisionHandler {
private final ControlLoopProvider controlLoopProvider;
private final ParticipantProvider participantProvider;
private final MonitoringProvider monitoringProvider;
+ private final PolicyModelsProvider modelsProvider;
// Publishers for participant communication
private final ControlLoopUpdatePublisher controlLoopUpdatePublisher;
@@ -350,7 +356,7 @@ public class SupervisionHandler {
case UNINITIALISED2PASSIVE:
case PASSIVE:
controlLoop.setState(ControlLoopState.PASSIVE2UNINITIALISED);
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, getFirstStartPhase(controlLoop));
break;
case PASSIVE2UNINITIALISED:
@@ -384,7 +390,7 @@ public class SupervisionHandler {
case RUNNING:
controlLoop.setState(ControlLoopState.RUNNING2PASSIVE);
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, getFirstStartPhase(controlLoop));
break;
default:
@@ -408,7 +414,7 @@ public class SupervisionHandler {
case PASSIVE:
controlLoop.setState(ControlLoopState.PASSIVE2RUNNING);
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, getFirstStartPhase(controlLoop));
break;
default:
@@ -418,6 +424,16 @@ public class SupervisionHandler {
}
}
+ private int getFirstStartPhase(ControlLoop controlLoop) {
+ ToscaServiceTemplate toscaServiceTemplate = null;
+ try {
+ toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
+ } catch (PfModelException e) {
+ throw new PfModelRuntimeException(Status.BAD_REQUEST, "Canont load ToscaServiceTemplate from DB", e);
+ }
+ return ParticipantUtils.getFirstStartPhase(controlLoop, toscaServiceTemplate);
+ }
+
private void checkParticipant(ParticipantMessage participantMessage, ParticipantState participantState,
ParticipantHealthStatus healthStatus) throws ControlLoopException, PfModelException {
if (participantMessage.getParticipantId() == null) {
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
index 5147aa241..48e06010d 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
@@ -220,13 +220,19 @@ public class SupervisionScanner {
var completed = true;
var minSpNotCompleted = 1000; // min startPhase not completed
+ var maxSpNotCompleted = 0; // max startPhase not completed
+ var defaultMin = 1000; // min startPhase
+ var defaultMax = 0; // max startPhase
for (ControlLoopElement element : controlLoop.getElements().values()) {
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ defaultMin = Math.min(defaultMin, startPhase);
+ defaultMax = Math.max(defaultMax, startPhase);
if (!element.getState().equals(element.getOrderedState().asState())) {
completed = false;
- ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
- .get(element.getDefinition().getName());
- int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
+ maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase);
}
}
@@ -243,12 +249,20 @@ public class SupervisionScanner {
LOGGER.debug("control loop scan: transition from state {} to {} not completed", controlLoop.getState(),
controlLoop.getOrderedState());
- if (minSpNotCompleted != phaseMap.getOrDefault(controlLoop.getKey().asIdentifier(), 0)
- && ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
- phaseMap.put(controlLoop.getKey().asIdentifier(), minSpNotCompleted);
- sendControlLoopMsg(controlLoop, minSpNotCompleted);
+ var nextSpNotCompleted = ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())
+ || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? minSpNotCompleted
+ : maxSpNotCompleted;
+
+ var firstStartPhase = ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())
+ || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? defaultMin
+ : defaultMax;
+
+ if (nextSpNotCompleted != phaseMap.getOrDefault(controlLoop.getKey().asIdentifier(), firstStartPhase)) {
+ phaseMap.put(controlLoop.getKey().asIdentifier(), nextSpNotCompleted);
+ sendControlLoopMsg(controlLoop, nextSpNotCompleted);
} else if (counterCheck) {
- handleCounter(controlLoop, minSpNotCompleted);
+ phaseMap.put(controlLoop.getKey().asIdentifier(), nextSpNotCompleted);
+ handleCounter(controlLoop, nextSpNotCompleted);
}
}
}
@@ -282,7 +296,7 @@ public class SupervisionScanner {
controlLoopUpdatePublisher.send(controlLoop, startPhase);
} else {
LOGGER.debug("retry message ControlLoopStateChange");
- controlLoopStateChangePublisher.send(controlLoop);
+ controlLoopStateChangePublisher.send(controlLoop, startPhase);
}
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
index 79d113c14..69d7b73d0 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
@@ -36,12 +36,14 @@ public class ControlLoopStateChangePublisher
* Send ControlLoopStateChange to Participant.
*
* @param controlLoop the ControlLoop
+ * @param startPhase the startPhase
*/
- public void send(ControlLoop controlLoop) {
+ public void send(ControlLoop controlLoop, int startPhase) {
var clsc = new ControlLoopStateChange();
clsc.setControlLoopId(controlLoop.getKey().asIdentifier());
clsc.setMessageId(UUID.randomUUID());
clsc.setOrderedState(controlLoop.getOrderedState());
+ clsc.setStartPhase(startPhase);
super.send(clsc);
}
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.
*/
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
index 82f7e66d5..d8892c8b9 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
@@ -133,7 +133,9 @@ class ControlLoopInstantiationProviderTest {
var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
- supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider,
+ var modelsProvider = Mockito.mock(PolicyModelsProvider.class);
+
+ supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider, modelsProvider,
controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher,
participantDeregisterAckPublisher, participantUpdatePublisher);
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
index 0ad8aad43..0fcf52ab9 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
@@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
@@ -56,9 +57,12 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantReg
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionHandlerTest {
+ private static final String TOSCA_TEMPLATE_YAML =
+ "src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml";
private static final String CL_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/controlloops/ControlLoops.json";
private static final ToscaConceptIdentifier identifier = new ToscaConceptIdentifier("PMSHInstance0Crud", "1.0.1");
private static final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
@@ -262,7 +266,11 @@ class SupervisionHandlerTest {
when(controlLoopProvider.getControlLoop(eq(identifier))).thenReturn(controlLoop);
- return new SupervisionHandler(controlLoopProvider, participantProvider, monitoringProvider,
+ var modelsProvider = Mockito.mock(PolicyModelsProvider.class);
+ when(modelsProvider.getServiceTemplateList(any(), any()))
+ .thenReturn(List.of(InstantiationUtils.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML)));
+
+ return new SupervisionHandler(controlLoopProvider, participantProvider, monitoringProvider, modelsProvider,
controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher,
participantDeregisterAckPublisher, participantUpdatePublisher);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
index 47cc6f1dc..f884e0129 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
@@ -29,11 +29,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
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.Participant;
@@ -47,6 +45,7 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpd
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusReqPublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -56,11 +55,19 @@ class SupervisionScannerTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML =
"src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml";
+ private static final String CONTROLLOOP_JSON = "src/test/resources/rest/controlloops/ControlLoopsSmoke.json";
+
+ private static PolicyModelsProvider modelsProvider = mock(PolicyModelsProvider.class);
+
+ @BeforeAll
+ public static void setUpBeforeAll() throws Exception {
+ ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ when(modelsProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
+ }
@Test
- void testScannerOrderedStateEqualsToState() throws PfModelException {
+ void testScannerOrderedStateEqualsToState() throws PfModelException, CoderException {
var controlLoopProvider = mock(ControlLoopProvider.class);
- var modelsProvider = mock(PolicyModelsProvider.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantProvider = mock(ParticipantProvider.class);
@@ -68,8 +75,9 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var controlLoop = new ControlLoop();
- when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+ var controlLoops =
+ InstantiationUtils.getControlLoopsFromResource(CONTROLLOOP_JSON, "Crud").getControlLoopList();
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(controlLoops);
var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
@@ -80,13 +88,13 @@ class SupervisionScannerTest {
}
@Test
- void testScannerOrderedStateDifferentToState() throws PfModelException {
- var controlLoop = new ControlLoop();
- controlLoop.setState(ControlLoopState.UNINITIALISED2PASSIVE);
- controlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
- controlLoop.setElements(Map.of(UUID.randomUUID(), new ControlLoopElement()));
+ void testScannerOrderedStateDifferentToState() throws PfModelException, CoderException {
+ var controlLoops =
+ InstantiationUtils.getControlLoopsFromResource(CONTROLLOOP_JSON, "Crud").getControlLoopList();
+ controlLoops.get(0).setState(ControlLoopState.UNINITIALISED2PASSIVE);
+ controlLoops.get(0).setOrderedState(ControlLoopOrderedState.UNINITIALISED);
var controlLoopProvider = mock(ControlLoopProvider.class);
- when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(controlLoops);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
@@ -95,9 +103,6 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var modelsProvider = mock(PolicyModelsProvider.class);
- when(modelsProvider.getServiceTemplateList(null, null)).thenReturn(List.of(new ToscaServiceTemplate()));
-
var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup);
@@ -118,7 +123,6 @@ class SupervisionScannerTest {
participant.setVersion("1.0.0");
when(participantProvider.getParticipants(null, null)).thenReturn(List.of(participant));
- var modelsProvider = mock(PolicyModelsProvider.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
@@ -136,19 +140,24 @@ class SupervisionScannerTest {
}
@Test
- void testSendControlLoopMsgUpdate() throws PfModelException {
- var controlLoop = new ControlLoop();
- controlLoop.setState(ControlLoopState.UNINITIALISED2PASSIVE);
- controlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE);
- controlLoop.setElements(Map.of(UUID.randomUUID(),
- createHttpElement(ControlLoopState.UNINITIALISED, ControlLoopOrderedState.PASSIVE)));
+ void testSendControlLoopMsgUpdate() throws PfModelException, CoderException {
+ var controlLoops =
+ InstantiationUtils.getControlLoopsFromResource(CONTROLLOOP_JSON, "Crud").getControlLoopList();
+ controlLoops.get(0).setState(ControlLoopState.UNINITIALISED2PASSIVE);
+ controlLoops.get(0).setOrderedState(ControlLoopOrderedState.PASSIVE);
+ for (var element : controlLoops.get(0).getElements().values()) {
+ if ("org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement"
+ .equals(element.getDefinition().getName())) {
+ element.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ element.setState(ControlLoopState.UNINITIALISED);
+ } else {
+ element.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ element.setState(ControlLoopState.PASSIVE);
+ }
+ }
var controlLoopProvider = mock(ControlLoopProvider.class);
- when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
-
- ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- var modelsProvider = mock(PolicyModelsProvider.class);
- when(modelsProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(controlLoops);
var participantProvider = mock(ParticipantProvider.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
@@ -166,19 +175,6 @@ class SupervisionScannerTest {
verify(controlLoopUpdatePublisher).send(any(ControlLoop.class), anyInt());
}
- private ControlLoopElement createHttpElement(ControlLoopState state, ControlLoopOrderedState orderedState) {
- var element = new ControlLoopElement();
- element.setDefinition(new ToscaConceptIdentifier(
- "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement", "1.2.3"));
- element.setState(state);
- element.setOrderedState(orderedState);
- element.setParticipantId(new ToscaConceptIdentifier("HttpParticipant0", "1.0.0"));
- element.setParticipantType(
- new ToscaConceptIdentifier("org.onap.k8s.controlloop.HttpControlLoopParticipant", "2.3.4"));
-
- return element;
- }
-
@Test
void testScanParticipant() throws PfModelException {
var controlLoopProvider = mock(ControlLoopProvider.class);
@@ -199,7 +195,6 @@ class SupervisionScannerTest {
var participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider.updateParticipants(List.of(participant));
- var modelsProvider = mock(PolicyModelsProvider.class);
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
index 70d115e47..4dfb8a9fd 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -22,14 +22,21 @@
package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import java.time.Instant;
import java.util.Collections;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ClElementStatisticsProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
@@ -51,6 +58,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionMessagesTest extends CommonRestController {
+ private static final String NOT_ACTIVE = "Not Active!";
private static final Object lockit = new Object();
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
@@ -77,12 +85,13 @@ class SupervisionMessagesTest extends CommonRestController {
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var modelsProvider = Mockito.mock(PolicyModelsProvider.class);
var controlLoopUpdatePublisher = Mockito.mock(ControlLoopUpdatePublisher.class);
var controlLoopStateChangePublisher = Mockito.mock(ControlLoopStateChangePublisher.class);
var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
- supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider,
+ supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider, modelsProvider,
controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher,
participantDeregisterAckPublisher, participantUpdatePublisher);
}
@@ -154,6 +163,29 @@ class SupervisionMessagesTest extends CommonRestController {
}
}
+ @Test
+ void testSendControlLoopStateChangePublisherNotActive() {
+ var publisher = new ControlLoopStateChangePublisher();
+ assertThatThrownBy(() -> publisher.send(getControlLoop(), 0)).hasMessage(NOT_ACTIVE);
+ }
+
+ @Test
+ void testSendControlLoopStateChangePublisher() {
+ var publisher = new ControlLoopStateChangePublisher();
+ var topicSink = mock(TopicSink.class);
+ publisher.active(List.of(topicSink));
+ publisher.send(getControlLoop(), 0);
+ verify(topicSink).send(anyString());
+ }
+
+ private ControlLoop getControlLoop() {
+ var controlLoop = new ControlLoop();
+ controlLoop.setName("NAME");
+ controlLoop.setVersion("0.0.1");
+ controlLoop.setState(ControlLoopState.UNINITIALISED);
+ return controlLoop;
+ }
+
private ToscaConceptIdentifier getParticipantId() {
return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
}
diff --git a/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoopsSmoke.json b/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoopsSmoke.json
new file mode 100644
index 000000000..47f379b84
--- /dev/null
+++ b/runtime-controlloop/src/test/resources/rest/controlloops/ControlLoopsSmoke.json
@@ -0,0 +1,174 @@
+{
+ "controlLoopList": [
+ {
+ "name": "PMSHInstance0",
+ "version": "1.0.1",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "PMSH control loop instance 0",
+ "elements": {
+ "709c62b3-8918-41b9-a747-d21eb79c6c20": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c20",
+ "definition": {
+ "name": "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "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-d21eb79c6c21": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "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-d21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "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-d21eb79c6c23": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c23",
+ "definition": {
+ "name": "org.onap.domain.database.PMSH_K8SMicroserviceControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "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": "PMSHInstance1",
+ "version": "1.0.1",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "PMSH control loop instance 1",
+ "elements": {
+ "709c62b3-8918-41b9-a747-d21eb79c6c24": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c24",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "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-d21eb79c6c25": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c25",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "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-d21eb79c6c26": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c26",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "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-d21eb79c6c27": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c27",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantId": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "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"
+ }
+ }
+ }
+ ]
+}