summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java81
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java34
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java3
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml6
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java5
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java5
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java108
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java16
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java111
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java100
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java10
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java35
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java102
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java12
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java24
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java49
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java253
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java13
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java4
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java7
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java75
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java35
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java51
-rw-r--r--runtime-controlloop/src/main/resources/application.yaml6
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java19
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java4
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java74
-rw-r--r--runtime-controlloop/src/test/resources/application_test.properties9
-rw-r--r--runtime-controlloop/src/test/resources/parameters/TestParameters.json5
-rw-r--r--runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml91
-rw-r--r--runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml70
34 files changed, 981 insertions, 447 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java
index 691ce95db..4ab406f3b 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java
@@ -18,6 +18,7 @@
package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
@@ -34,7 +35,7 @@ import org.onap.policy.models.base.PfUtils;
@AllArgsConstructor
@EqualsAndHashCode
public class ControlLoops {
- private List<ControlLoop> controlLoopList;
+ private List<ControlLoop> controlLoopList = new ArrayList<>();
/**
* Copy constructor, does a deep copy.
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
new file mode 100644
index 000000000..05f5a4bb8
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
@@ -0,0 +1,81 @@
+/*-
+ * ============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 java.util.Map;
+import javax.ws.rs.core.Response;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+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.models.base.PfModelRuntimeException;
+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;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ParticipantUtils {
+
+ private static final Coder CODER = new StandardCoder();
+ private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
+
+ /**
+ * Finds participantType from a map of properties.
+ *
+ * @param properties Map of properties
+ * @return participantType
+ */
+ public static ToscaConceptIdentifier findParticipantType(Map<String, Object> properties) {
+ var objParticipantType = properties.get("participantType");
+ if (objParticipantType != null) {
+ try {
+ return CODER.decode(objParticipantType.toString(), ToscaConceptIdentifier.class);
+ } catch (CoderException e) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks If NodeTemplate Is ControlLoopElement.
+ *
+ * @param nodeTemplate the ToscaNodeTemplate
+ * @param toscaServiceTemplate the ToscaServiceTemplate
+ * @return true if NodeTemplate Is ControlLoopElement
+ */
+ public static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
+ return true;
+ } else {
+ var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
+ if (nodeType != null) {
+ var derivedFrom = nodeType.getDerivedFrom();
+ if (derivedFrom != null) {
+ return derivedFrom.contains(CONTROL_LOOP_ELEMENT);
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java
index 762b927ab..b4f99a51e 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java
@@ -45,6 +45,7 @@ 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.ToscaTypedEntityFilter;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates;
import org.springframework.stereotype.Component;
/**
@@ -197,18 +198,39 @@ public class ControlLoopProvider extends AbstractModelsProvider {
Map<String, ToscaNodeTemplate> savedNodeTemplates = new HashMap<>();
- serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, template) -> {
- var jpaToscaNodeTemplate = new JpaToscaNodeTemplate(template);
-
- getPfDao().create(jpaToscaNodeTemplate);
+ var jpaToscaNodeTemplates = new JpaToscaNodeTemplates();
+ jpaToscaNodeTemplates.fromAuthorative(Collections.singletonList(serviceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates()));
- savedNodeTemplates.put(key, template);
- });
+ getPfDao().create(jpaToscaNodeTemplates);
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach(savedNodeTemplates::put);
return savedNodeTemplates;
}
/**
+ * Deletes Instance Properties on the database.
+ *
+ * @param filteredToscaNodeTemplateMap filtered node templates map to delete
+ * @param filteredToscaNodeTemplateList filtered node template list to delete
+ */
+ public void deleteInstanceProperties(
+ Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap,
+ List<ToscaNodeTemplate> filteredToscaNodeTemplateList) {
+
+ var jpaToscaNodeTemplates = new JpaToscaNodeTemplates();
+ jpaToscaNodeTemplates.fromAuthorative(Collections.singletonList(filteredToscaNodeTemplateMap));
+
+ getPfDao().create(jpaToscaNodeTemplates);
+
+ filteredToscaNodeTemplateList.forEach(template -> {
+ var jpaToscaNodeTemplate = new JpaToscaNodeTemplate(template);
+
+ getPfDao().delete(jpaToscaNodeTemplate);
+ });
+ }
+
+ /**
* Get Node Templates.
*
* @param name the name of the node template to get, null to get all node templates
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java
index ff5b132ab..3cce9c55c 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java
@@ -24,15 +24,15 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import javax.ws.rs.core.Response;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfModelRuntimeException;
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ProviderUtils {
- private ProviderUtils() {
- // Utility class has no instances
- }
protected static <A, J extends PfConcept & PfAuthorative<A>> List<J> getJpaAndValidate(
List<A> authorativeConceptList, Supplier<J> jpaSupplier, String conceptDescription) {
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java
index eed339447..d8974d6e3 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java
@@ -19,6 +19,7 @@
package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation;
+import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
@@ -33,5 +34,5 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@Setter
@ToString(callSuper = true)
public class InstancePropertiesResponse extends SimpleResponse {
- private List<ToscaConceptIdentifier> affectedInstanceProperties;
+ private List<ToscaConceptIdentifier> affectedInstanceProperties = new ArrayList<>();
}
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml
index 635b98cb8..ade249e99 100644
--- a/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml
+++ b/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml
@@ -23,11 +23,11 @@ runtime:
participantClUpdateIntervalSec: 1000
participantClStateChangeIntervalSec: 1000
participantParameters:
- heartBeatMs: 120000
- maxMessageAgeMs: 600000
+ heartBeatMs: 20000
+ maxStatusWaitMs: 100000
updateParameters:
maxRetryCount: 3
- maxWaitMs: 100000
+ maxWaitMs: 20000
databaseProviderParameters:
name: PolicyProviderParameterGroup
implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java b/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
index cf71248c3..0bad5ed96 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
@@ -20,6 +20,8 @@
package utils;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -27,7 +29,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Util class for Test scope.
*/
-public class ToscaUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ToscaUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final String TOSCA_TEMPLATE_YAML = "src/test/resources/HttpParticipantConfig.yaml";
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java
index b01dfa28e..af514f8aa 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/controlloop/participant/kubernetes/utils/TestUtils.java
@@ -21,11 +21,14 @@
package org.onap.policy.clamp.controlloop.participant.kubernetes.utils;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-public class TestUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final String TOSCA_TEMPLATE_YAML = "src/test/resources/servicetemplates/KubernetesHelm.yaml";
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
index fe7cb3c96..25da5a3e9 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
@@ -31,6 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
@@ -38,6 +40,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
@@ -54,18 +57,16 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TestListenerUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestListenerUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final Coder CODER = new StandardCoder();
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
private static final String POLICY_TYPE_ID = "policy_type_id";
private static final String POLICY_ID = "policy_id";
- private TestListenerUtils() {}
-
/**
* Method to create a controlLoop from a yaml file.
*
@@ -138,10 +139,8 @@ public class TestListenerUtils {
*/
public static ControlLoopUpdate createControlLoopUpdateMsg() {
final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
- ToscaConceptIdentifier controlLoopId =
- new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
- ToscaConceptIdentifier participantId =
- new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
+ ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
clUpdateMsg.setControlLoopId(controlLoopId);
clUpdateMsg.setParticipantId(participantId);
@@ -154,23 +153,18 @@ public class TestListenerUtils {
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
clElement.setParticipantId(clParticipantType);
clElement.setParticipantType(clParticipantType);
- clElement.setDefinition(new ToscaConceptIdentifier(toscaInputEntry.getKey(),
- toscaInputEntry.getValue().getVersion()));
+ clElement.setDefinition(
+ new ToscaConceptIdentifier(toscaInputEntry.getKey(), toscaInputEntry.getValue().getVersion()));
clElement.setState(ControlLoopState.UNINITIALISED);
clElement.setDescription(toscaInputEntry.getValue().getDescription());
clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
@@ -187,26 +181,10 @@ public class TestListenerUtils {
return clUpdateMsg;
}
- private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
- ToscaServiceTemplate toscaServiceTemplate) {
- if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
- return true;
- } else {
- var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
- if (nodeType != null) {
- var derivedFrom = nodeType.getDerivedFrom();
- if (derivedFrom != null) {
- return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
- }
- }
- }
- return false;
- }
-
private static void populateToscaNodeTemplateFragment(ControlLoopElement clElement,
ToscaServiceTemplate toscaServiceTemplate) {
- ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate
- .getToscaTopologyTemplate().getNodeTemplates().get(clElement.getDefinition().getName());
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(clElement.getDefinition().getName());
// If the ControlLoopElement has policy_type_id or policy_id, identify it as a PolicyControlLoopElement
// and pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment
if ((toscaNodeTemplate.getProperties().get(POLICY_TYPE_ID) != null)
@@ -229,7 +207,7 @@ public class TestListenerUtils {
}
private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
- List<ParticipantUpdates> participantUpdates) {
+ List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
participantUpdates.add(getControlLoopElementList(clElement));
} else {
@@ -263,8 +241,8 @@ public class TestListenerUtils {
public static ParticipantUpdate createParticipantUpdateMsg() {
final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
- ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(
- "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+ ToscaConceptIdentifier participantType =
+ new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
participantUpdateMsg.setParticipantId(participantId);
participantUpdateMsg.setTimestamp(Instant.now());
@@ -277,19 +255,14 @@ public class TestListenerUtils {
TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate);
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().entrySet()) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
@@ -298,17 +271,16 @@ public class TestListenerUtils {
}
private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
- entryKey, entryValue.getVersion()));
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates
+ .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
} else {
boolean participantExists = false;
for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
@@ -318,15 +290,15 @@ public class TestListenerUtils {
}
}
if (!participantExists) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates.add(
+ getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
}
}
}
private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ToscaConceptIdentifier clParticipantType,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
ParticipantDefinition participantDefinition = new ParticipantDefinition();
participantDefinition.setParticipantType(clParticipantType);
controlLoopElementDefinitionList.add(clDefinition);
@@ -369,8 +341,7 @@ public class TestListenerUtils {
return toscaServiceTemplate;
}
- private static void addPolicyTypesToToscaServiceTemplate(
- ToscaServiceTemplate toscaServiceTemplate) {
+ private static void addPolicyTypesToToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate) {
Set<String> policyTypeDirectoryContents = ResourceUtils.getDirectoryContents("policytypes");
for (String policyTypeFilePath : policyTypeDirectoryContents) {
@@ -413,10 +384,9 @@ public class TestListenerUtils {
for (String policiesFilePath : policiesDirectoryContents) {
String policiesString = ResourceUtils.getResourceAsString(policiesFilePath);
- ToscaServiceTemplate foundPoliciesSt =
- yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class);
- toscaServiceTemplate.getToscaTopologyTemplate().setPolicies(
- foundPoliciesSt.getToscaTopologyTemplate().getPolicies());
+ ToscaServiceTemplate foundPoliciesSt = yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class);
+ toscaServiceTemplate.getToscaTopologyTemplate()
+ .setPolicies(foundPoliciesSt.getToscaTopologyTemplate().getPolicies());
}
}
@@ -427,8 +397,8 @@ public class TestListenerUtils {
throw new FileNotFoundException(controlLoopFilePath);
}
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- controlLoopString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate =
+ yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class);
return serviceTemplate;
} catch (FileNotFoundException e) {
LOGGER.error("cannot find YAML file", controlLoopFilePath);
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
index c890ec247..d28ddf9dc 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
@@ -20,7 +20,10 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.controlloop.participant.simulator.main.handler.ControlLoopElementHandler;
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.RequestResponseLoggingFilter;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -42,4 +45,17 @@ public class ParticipantConfig {
return registrationBean;
}
+
+ /**
+ * Register ControlLoopElementListener.
+ *
+ * @param intermediaryApi the ParticipantIntermediaryApi
+ * @param clElementHandler the ControlLoop Element Handler
+ */
+ @Autowired
+ public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi,
+ ControlLoopElementHandler clElementHandler) {
+ intermediaryApi.registerControlLoopElementListener(clElementHandler);
+ clElementHandler.setIntermediaryApi(intermediaryApi);
+ }
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java
new file mode 100644
index 000000000..fd46faf97
--- /dev/null
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/handler/ControlLoopElementHandler.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.participant.simulator.main.handler;
+
+import java.time.Instant;
+import java.util.UUID;
+import lombok.Setter;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class handles implementation of controlLoopElement updates.
+ */
+@Component
+public class ControlLoopElementHandler implements ControlLoopElementListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopElementHandler.class);
+
+ @Setter
+ private ParticipantIntermediaryApi intermediaryApi;
+
+ /**
+ * Callback method to handle a control loop element state change.
+ *
+ * @param controlLoopElementId the ID of the control loop element
+ * @param currentState the current state of the control loop element
+ * @param newState the state to which the control loop element is changing to
+ * @throws PfModelException in case of an exception
+ */
+ @Override
+ public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
+ UUID controlLoopElementId, ControlLoopState currentState,
+ ControlLoopOrderedState newState) throws PfModelException {
+ switch (newState) {
+ case UNINITIALISED:
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ break;
+ case PASSIVE:
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.PASSIVE,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ break;
+ case RUNNING:
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.RUNNING,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ break;
+ default:
+ LOGGER.debug("Unknown orderedstate {}", newState);
+ break;
+ }
+ }
+
+ /**
+ * Callback method to handle an update on a control loop element.
+ *
+ * @param element the information on the control loop element
+ * @param clElementDefinition toscaNodeTemplate
+ * @throws PfModelException in case of an exception
+ */
+ @Override
+ public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
+ ToscaNodeTemplate clElementDefinition)
+ throws PfModelException {
+ intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(),
+ ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ }
+
+ @Override
+ public void handleStatistics(UUID controlLoopElementId) throws PfModelException {
+ var clElement = intermediaryApi.getControlLoopElement(controlLoopElementId);
+ if (clElement != null) {
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setControlLoopState(clElement.getState());
+ clElementStatistics.setTimeStamp(Instant.now());
+ intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics);
+ }
+ }
+
+}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
index c26749b4d..320b53805 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
@@ -13,7 +13,7 @@ server:
participant:
intermediaryParameters:
- reportingTimeIntervalMs: 120000
+ reportingTimeIntervalMs: 60000
description: Participant Description
participantId:
name: org.onap.PM_CDS_Blueprint
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
index 7439ccd5b..bd3316abb 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
@@ -31,6 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
@@ -38,6 +40,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
@@ -53,15 +56,13 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TestListenerUtils {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class TestListenerUtils {
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final Coder CODER = new StandardCoder();
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
-
- private TestListenerUtils() {}
/**
* Method to create a controlLoop from a yaml file.
@@ -131,10 +132,8 @@ public class TestListenerUtils {
*/
public static ControlLoopUpdate createControlLoopUpdateMsg() {
final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
- ToscaConceptIdentifier controlLoopId =
- new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
- ToscaConceptIdentifier participantId =
- new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
+ ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
clUpdateMsg.setControlLoopId(controlLoopId);
clUpdateMsg.setParticipantId(participantId);
@@ -146,23 +145,18 @@ public class TestListenerUtils {
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
clElement.setParticipantId(clParticipantType);
clElement.setParticipantType(clParticipantType);
- clElement.setDefinition(new ToscaConceptIdentifier(toscaInputEntry.getKey(),
- toscaInputEntry.getValue().getVersion()));
+ clElement.setDefinition(
+ new ToscaConceptIdentifier(toscaInputEntry.getKey(), toscaInputEntry.getValue().getVersion()));
clElement.setState(ControlLoopState.UNINITIALISED);
clElement.setDescription(toscaInputEntry.getValue().getDescription());
clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
@@ -178,24 +172,8 @@ public class TestListenerUtils {
return clUpdateMsg;
}
- private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
- ToscaServiceTemplate toscaServiceTemplate) {
- if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
- return true;
- } else {
- var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
- if (nodeType != null) {
- var derivedFrom = nodeType.getDerivedFrom();
- if (derivedFrom != null) {
- return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
- }
- }
- }
- return false;
- }
-
private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
- List<ParticipantUpdates> participantUpdates) {
+ List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
participantUpdates.add(getControlLoopElementList(clElement));
} else {
@@ -229,8 +207,8 @@ public class TestListenerUtils {
public static ParticipantUpdate createParticipantUpdateMsg() {
final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
- ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(
- "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+ ToscaConceptIdentifier participantType =
+ new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
participantUpdateMsg.setParticipantId(participantId);
participantUpdateMsg.setTimestamp(Instant.now());
@@ -242,19 +220,14 @@ public class TestListenerUtils {
// Add policies to the toscaServiceTemplate
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().entrySet()) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
@@ -263,17 +236,16 @@ public class TestListenerUtils {
}
private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
- entryKey, entryValue.getVersion()));
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates
+ .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
} else {
boolean participantExists = false;
for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
@@ -283,15 +255,15 @@ public class TestListenerUtils {
}
}
if (!participantExists) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates.add(
+ getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
}
}
}
private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ToscaConceptIdentifier clParticipantType,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
ParticipantDefinition participantDefinition = new ParticipantDefinition();
participantDefinition.setParticipantType(clParticipantType);
controlLoopElementDefinitionList.add(clDefinition);
@@ -307,10 +279,8 @@ public class TestListenerUtils {
* @return ControlLoopUpdate message
* @throws CoderException exception while reading the file to object
*/
- public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
- throws CoderException {
- ControlLoopUpdate controlLoopUpdateMsg =
- CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
+ public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath) throws CoderException {
+ ControlLoopUpdate controlLoopUpdateMsg = CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
return controlLoopUpdateMsg;
}
@@ -340,8 +310,8 @@ public class TestListenerUtils {
throw new FileNotFoundException(controlLoopFilePath);
}
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- controlLoopString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate =
+ yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class);
return serviceTemplate;
} catch (FileNotFoundException e) {
LOGGER.error("cannot find YAML file", controlLoopFilePath);
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
index 3859e0c39..891d67e2d 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -48,16 +48,6 @@ public interface ParticipantIntermediaryApi {
void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener);
/**
- * Send participant register message to controlloop runtime.
- */
- void sendParticipantRegister();
-
- /**
- * Send participant deregister message to controlloop runtime.
- */
- void sendParticipantDeregister();
-
- /**
* Get participants loops from the intermediary API.
*
* @param name the participant name, null for all
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index 1f79d7179..aa1febadd 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -37,6 +37,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.stereotype.Component;
@@ -48,30 +49,26 @@ import org.springframework.stereotype.Component;
public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
// The handler for the participant intermediary
- private ParticipantHandler participantHandler;
+ private final ParticipantHandler participantHandler;
+
+ // The handler for the controlLoop intermediary
+ private final ControlLoopHandler controlLoopHandler;
/**
* Constructor.
*
* @param participantHandler ParticipantHandler
+ * @param controlLoopHandler ControlLoopHandler
*/
- public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler) {
+ public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
+ ControlLoopHandler controlLoopHandler) {
this.participantHandler = participantHandler;
+ this.controlLoopHandler = controlLoopHandler;
}
@Override
public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
- participantHandler.getControlLoopHandler().registerControlLoopElementListener(controlLoopElementListener);
- }
-
- @Override
- public void sendParticipantRegister() {
- participantHandler.sendParticipantRegister();
- }
-
- @Override
- public void sendParticipantDeregister() {
- participantHandler.sendParticipantDeregister();
+ controlLoopHandler.registerControlLoopElementListener(controlLoopElementListener);
}
@Override
@@ -91,13 +88,12 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoops getControlLoops(String name, String version) {
- return participantHandler.getControlLoopHandler().getControlLoops();
+ return controlLoopHandler.getControlLoops();
}
@Override
public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
- List<ControlLoop> controlLoops =
- participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
+ List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
for (ControlLoop controlLoop : controlLoops) {
if (name.equals(controlLoop.getDefinition().getName())) {
@@ -109,8 +105,7 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoopElement getControlLoopElement(UUID id) {
- List<ControlLoop> controlLoops =
- participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
+ List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
for (ControlLoop controlLoop : controlLoops) {
ControlLoopElement clElement = controlLoop.getElements().get(id);
@@ -125,12 +120,12 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
UUID id, ControlLoopOrderedState currentState,
ControlLoopState newState, ParticipantMessageType messageType) {
- return participantHandler.getControlLoopHandler().updateControlLoopElementState(controlLoopId,
+ return controlLoopHandler.updateControlLoopElementState(controlLoopId,
id, currentState, newState);
}
@Override
public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
- participantHandler.getControlLoopHandler().updateControlLoopElementStatistics(id, elementStatistics);
+ controlLoopHandler.updateControlLoopElementStatistics(id, elementStatistics);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
index 6e1b31cfe..8bdf91824 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Getter;
-import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
@@ -45,7 +44,6 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -97,33 +95,37 @@ public class ControlLoopHandler {
* @param newState the ordered state
* @return controlLoopElement the updated controlloop element
*/
- public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
- UUID id, ControlLoopOrderedState orderedState,
- ControlLoopState newState) {
+ public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId, UUID id,
+ ControlLoopOrderedState orderedState, ControlLoopState newState) {
if (id == null) {
LOGGER.warn("Cannot update Control loop element state, id is null");
+ return null;
}
- ControlLoopElement clElement = elementsOnThisParticipant.get(id);
for (var controlLoop : controlLoopMap.values()) {
var element = controlLoop.getElements().get(id);
if (element != null) {
element.setState(newState);
}
+ var checkOpt = controlLoop.getElements().values().stream()
+ .filter(clElement -> !newState.equals(clElement.getState())).findAny();
+ if (checkOpt.isEmpty()) {
+ controlLoop.setState(newState);
+ controlLoop.setOrderedState(orderedState);
+ }
}
+ var clElement = elementsOnThisParticipant.get(id);
if (clElement != null) {
- var controlLoopStateChangeAck =
- new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
+ var controlLoopStateChangeAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
controlLoopStateChangeAck.setParticipantId(participantId);
controlLoopStateChangeAck.setParticipantType(participantType);
controlLoopStateChangeAck.setControlLoopId(controlLoopId);
clElement.setOrderedState(orderedState);
clElement.setState(newState);
- controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(),
- new ControlLoopElementAck(newState, true,
- "Control loop element {} state changed to {}\", id, newState)"));
+ controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(), new ControlLoopElementAck(
+ newState, true, "Control loop element {} state changed to {}\", id, newState)"));
LOGGER.debug("Control loop element {} state changed to {}", id, newState);
controlLoopStateChangeAck.setMessage("ControlLoopElement state changed to {} " + newState);
controlLoopStateChangeAck.setResult(true);
@@ -140,7 +142,7 @@ public class ControlLoopHandler {
* @param elementStatistics control loop element Statistics
*/
public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
- ControlLoopElement clElement = elementsOnThisParticipant.get(id);
+ var clElement = elementsOnThisParticipant.get(id);
if (clElement != null) {
elementStatistics.setParticipantId(participantId);
elementStatistics.setId(id);
@@ -165,7 +167,7 @@ public class ControlLoopHandler {
controlLoopAck.setParticipantId(participantId);
controlLoopAck.setParticipantType(participantType);
controlLoopAck.setMessage("Control loop " + stateChangeMsg.getControlLoopId()
- + " does not use this participant " + participantId);
+ + " does not use this participant " + participantId);
controlLoopAck.setResult(false);
controlLoopAck.setResponseTo(stateChangeMsg.getMessageId());
controlLoopAck.setControlLoopId(stateChangeMsg.getControlLoopId());
@@ -206,7 +208,7 @@ public class ControlLoopHandler {
* @param updateMsg the update message
*/
public void handleControlLoopUpdate(ControlLoopUpdate updateMsg,
- List<ControlLoopElementDefinition> clElementDefinitions) {
+ List<ControlLoopElementDefinition> clElementDefinitions) {
if (!updateMsg.appliesTo(participantType, participantId)) {
return;
@@ -222,7 +224,7 @@ public class ControlLoopHandler {
controlLoopUpdateAck.setParticipantType(participantType);
controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId()
- + " already defined on participant " + participantId);
+ + " already defined on participant " + participantId);
controlLoopUpdateAck.setResult(false);
controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
@@ -235,22 +237,22 @@ public class ControlLoopHandler {
return;
}
- List<ControlLoopElement> clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
+ var clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
try {
- for (ControlLoopElement element : clElements) {
- ToscaNodeTemplate clElementNodeTemplate = getClElementNodeTemplate(
- clElementDefinitions, element.getDefinition());
- for (ControlLoopElementListener clElementListener : listeners) {
- clElementListener.controlLoopElementUpdate(updateMsg.getControlLoopId(),
- element, clElementNodeTemplate);
+ for (var element : clElements) {
+ var clElementNodeTemplate =
+ getClElementNodeTemplate(clElementDefinitions, element.getDefinition());
+ for (var clElementListener : listeners) {
+ clElementListener.controlLoopElementUpdate(updateMsg.getControlLoopId(), element,
+ clElementNodeTemplate);
}
}
} catch (PfModelException e) {
LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId());
}
- Map<UUID, ControlLoopElement> clElementMap = prepareClElementMap(clElements);
+ var clElementMap = prepareClElementMap(clElements);
controlLoop = new ControlLoop();
controlLoop.setDefinition(updateMsg.getControlLoopId());
controlLoop.setElements(clElementMap);
@@ -258,8 +260,8 @@ public class ControlLoopHandler {
}
private ToscaNodeTemplate getClElementNodeTemplate(List<ControlLoopElementDefinition> clElementDefinitions,
- ToscaConceptIdentifier clElementDefId) {
- for (ControlLoopElementDefinition clElementDefinition : clElementDefinitions) {
+ ToscaConceptIdentifier clElementDefId) {
+ for (var clElementDefinition : clElementDefinitions) {
if (clElementDefinition.getClElementDefinitionId().equals(clElementDefId)) {
return clElementDefinition.getControlLoopElementToscaNodeTemplate();
}
@@ -268,11 +270,9 @@ public class ControlLoopHandler {
}
private List<ControlLoopElement> storeElementsOnThisParticipant(List<ParticipantUpdates> participantUpdates) {
- var clElementMap =
- participantUpdates.stream()
+ var clElementMap = participantUpdates.stream()
.flatMap(participantUpdate -> participantUpdate.getControlLoopElementList().stream())
- .filter(element -> participantType.equals(element.getParticipantType()))
- .collect(Collectors.toList());
+ .filter(element -> participantType.equals(element.getParticipantType())).collect(Collectors.toList());
for (var element : clElementMap) {
elementsOnThisParticipant.put(element.getId(), element);
@@ -282,7 +282,7 @@ public class ControlLoopHandler {
private Map<UUID, ControlLoopElement> prepareClElementMap(List<ControlLoopElement> clElements) {
Map<UUID, ControlLoopElement> clElementMap = new LinkedHashMap<>();
- for (ControlLoopElement element : clElements) {
+ for (var element : clElements) {
clElementMap.put(element.getId(), element);
}
return clElementMap;
@@ -295,19 +295,9 @@ public class ControlLoopHandler {
* @param orderedState orderedState
*/
private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED);
- controlLoopMap.remove(controlLoop.getKey().asIdentifier());
-
- for (ControlLoopElementListener clElementListener : listeners) {
- try {
- for (ControlLoopElement element : controlLoop.getElements().values()) {
- clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(),
- element.getId(), element.getState(), orderedState);
- }
- } catch (PfModelException e) {
- LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
- }
- }
+ handleStateChange(controlLoop, orderedState);
+ controlLoopMap.remove(controlLoop.getDefinition());
+ controlLoop.getElements().values().forEach(element -> elementsOnThisParticipant.remove(element.getId()));
}
/**
@@ -317,7 +307,7 @@ public class ControlLoopHandler {
* @param orderedState orderedState
*/
private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE);
+ handleStateChange(controlLoop, orderedState);
}
/**
@@ -327,7 +317,7 @@ public class ControlLoopHandler {
* @param orderedState orderedState
*/
private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
- handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING);
+ handleStateChange(controlLoop, orderedState);
}
/**
@@ -335,30 +325,30 @@ public class ControlLoopHandler {
*
* @param controlLoop participant status in memory
* @param orderedState orderedState the new ordered state the participant should have
- * @param newState new state of the control loop elements
*/
- private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- ControlLoopState newState) {
+ private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState) {
if (orderedState.equals(controlLoop.getOrderedState())) {
var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
controlLoopAck.setParticipantId(participantId);
controlLoopAck.setParticipantType(participantType);
- controlLoopAck.setMessage("Control loop is already in state" + orderedState);
+ controlLoopAck.setMessage("Control loop is already in state " + orderedState);
controlLoopAck.setResult(false);
controlLoopAck.setControlLoopId(controlLoop.getDefinition());
publisher.sendControlLoopAck(controlLoopAck);
return;
}
- if (!CollectionUtils.isEmpty(controlLoop.getElements().values())) {
- controlLoop.getElements().values().forEach(element -> {
- element.setState(newState);
- element.setOrderedState(orderedState);
- });
+ for (var clElementListener : listeners) {
+ try {
+ for (var element : controlLoop.getElements().values()) {
+ clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(), element.getId(),
+ element.getState(), orderedState);
+ }
+ } catch (PfModelException e) {
+ LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
+ }
}
-
- controlLoop.setOrderedState(orderedState);
}
/**
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
index 5458f7c34..1d445324b 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
@@ -24,7 +24,6 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
@@ -48,7 +47,7 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
private List<TopicSink> topicSinks;
private List<TopicSource> topicSources;
- ParticipantIntermediaryApi participantIntermediaryApi;
+ private ParticipantHandler participantHandler;
private final MessageTypeDispatcher msgDispatcher;
@@ -56,13 +55,14 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
* Instantiate the activator for participant.
*
* @param parameters the ParticipantParameters
+ * @param participantHandler the ParticipantHandler
* @param publishers list of Publishers
* @param listeners list of Listeners
*/
public <T> IntermediaryActivator(final ParticipantParameters parameters,
- ParticipantIntermediaryApi participantIntermediaryApi, List<Publisher> publishers,
+ ParticipantHandler participantHandler, List<Publisher> publishers,
List<Listener<T>> listeners) {
- this.participantIntermediaryApi = participantIntermediaryApi;
+ this.participantHandler = participantHandler;
topicSinks = TopicEndpointManager.getManager()
.addTopicSinks(parameters.getIntermediaryParameters().getClampControlLoopTopics().getTopicSinks());
@@ -118,11 +118,11 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
}
private void sendParticipantRegister() {
- participantIntermediaryApi.sendParticipantRegister();
+ participantHandler.sendParticipantRegister();
}
private void sendParticipantDeregister() {
- participantIntermediaryApi.sendParticipantDeregister();
+ participantHandler.sendParticipantDeregister();
}
/**
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index 19641b0d5..69f8febb8 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
+import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
@@ -66,13 +67,16 @@ import org.springframework.stereotype.Component;
/**
* This class is responsible for managing the state of a participant.
*/
-@Getter
@Component
public class ParticipantHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantHandler.class);
+ @Getter
private final ToscaConceptIdentifier participantType;
+
+ @Getter
private final ToscaConceptIdentifier participantId;
+
private final ControlLoopHandler controlLoopHandler;
private final ParticipantStatistics participantStatistics;
private final ParticipantMessagePublisher publisher;
@@ -110,11 +114,6 @@ public class ParticipantHandler {
* @param participantStatusReqMsg participant participantStatusReq message
*/
public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) {
- var controlLoops = controlLoopHandler.getControlLoops();
- for (ControlLoopElementListener clElementListener : controlLoopHandler.getListeners()) {
- updateClElementStatistics(controlLoops, clElementListener);
- }
-
var participantStatus = makeHeartbeat(true);
publisher.sendParticipantStatus(participantStatus);
}
@@ -331,6 +330,12 @@ public class ParticipantHandler {
* Method to send heartbeat to controlloop runtime.
*/
public ParticipantStatus makeHeartbeat(boolean responseToParticipantStatusReq) {
+ if (!responseToParticipantStatusReq) {
+ var controlLoops = controlLoopHandler.getControlLoops();
+ for (var clElementListener : controlLoopHandler.getListeners()) {
+ updateClElementStatistics(controlLoops, clElementListener);
+ }
+ }
this.participantStatistics.setState(state);
this.participantStatistics.setHealthStatus(healthStatus);
this.participantStatistics.setTimeStamp(Instant.now());
@@ -363,10 +368,15 @@ public class ParticipantHandler {
clStatitistics.setControlLoopId(entry.getKey());
ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList();
clElementStatisticsList
- .setClElementStatistics(entry.getValue().getControlLoopElementStatisticsList(entry.getValue()));
+ .setClElementStatistics(entry.getValue().getElements().values()
+ .stream()
+ .map(ControlLoopElement::getClElementStatistics)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList()));
clStatitistics.setClElementStatisticsList(clElementStatisticsList);
clInfo.setControlLoopStatistics(clStatitistics);
clInfo.setState(entry.getValue().getState());
+ controlLoopInfoList.add(clInfo);
}
return controlLoopInfoList;
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
index fbfc1de69..0b7bc9a26 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
@@ -34,7 +34,6 @@ import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
@@ -64,6 +63,7 @@ import org.springframework.stereotype.Component;
@Component
public class CommissioningProvider {
public static final String CONTROL_LOOP_NODE_TYPE = "org.onap.policy.clamp.controlloop.ControlLoop";
+ private static final String INSTANCE_TEXT = "_Instance";
private final PolicyModelsProvider modelsProvider;
private final ControlLoopProvider clProvider;
@@ -98,10 +98,10 @@ public class CommissioningProvider {
* @throws PfModelException on creation errors
*/
public CommissioningResponse createControlLoopDefinitions(ToscaServiceTemplate serviceTemplate)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
if (verifyIfInstancePropertiesExists()) {
- throw new ControlLoopException(Status.BAD_REQUEST,
+ throw new PfModelException(Status.BAD_REQUEST,
"Delete instances, to commission control loop definitions");
}
@@ -148,10 +148,10 @@ public class CommissioningProvider {
* @throws PfModelException on deletion errors
*/
public CommissioningResponse deleteControlLoopDefinition(String name, String version)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
if (verifyIfInstancePropertiesExists()) {
- throw new ControlLoopException(Status.BAD_REQUEST,
+ throw new PfModelException(Status.BAD_REQUEST,
"Delete instances, to commission control loop definitions");
}
@@ -395,10 +395,17 @@ public class CommissioningProvider {
public Map<String, ToscaNodeTemplate> getNodeTemplatesWithCommonOrInstanceProperties(boolean common, String name,
String version) throws PfModelException {
- var commonOrInstanceNodeTypeProps = this.getCommonOrInstancePropertiesFromNodeTypes(common, name, version);
+ if (common && verifyIfInstancePropertiesExists()) {
+ throw new PfModelException(Status.BAD_REQUEST,
+ "Cannot create or edit common properties, delete all the instantiations first");
+ }
+
+ var commonOrInstanceNodeTypeProps =
+ this.getCommonOrInstancePropertiesFromNodeTypes(common, name, version);
var serviceTemplates = new ToscaServiceTemplates();
- serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
+ serviceTemplates.setServiceTemplates(filterToscaNodeTemplateInstance(
+ modelsProvider.getServiceTemplateList(name, version)));
return this.getDerivedCommonOrInstanceNodeTemplates(
serviceTemplates.getServiceTemplates().get(0).getToscaTopologyTemplate().getNodeTemplates(),
@@ -433,7 +440,8 @@ public class CommissioningProvider {
var serviceTemplates = new ToscaServiceTemplates();
serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
- ToscaServiceTemplate fullTemplate = serviceTemplates.getServiceTemplates().get(0);
+ ToscaServiceTemplate fullTemplate = filterToscaNodeTemplateInstance(
+ serviceTemplates.getServiceTemplates()).get(0);
var template = new HashMap<String, Object>();
template.put("tosca_definitions_version", fullTemplate.getToscaDefinitionsVersion());
@@ -496,6 +504,29 @@ public class CommissioningProvider {
}
}
+ private List<ToscaServiceTemplate> filterToscaNodeTemplateInstance(List<ToscaServiceTemplate> serviceTemplates) {
+
+ List<ToscaServiceTemplate> toscaServiceTemplates = new ArrayList<>();
+
+ serviceTemplates.stream().forEach(serviceTemplate -> {
+
+ Map<String, ToscaNodeTemplate> toscaNodeTemplates = new HashMap<>();
+
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> {
+ if (!nodeTemplate.getName().contains(INSTANCE_TEXT)) {
+ toscaNodeTemplates.put(key, nodeTemplate);
+ }
+ });
+
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().clear();
+ serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(toscaNodeTemplates);
+
+ toscaServiceTemplates.add(serviceTemplate);
+ });
+
+ return toscaServiceTemplates;
+ }
+
/**
* Validates to see if there is any instance properties saved.
*
@@ -503,7 +534,7 @@ public class CommissioningProvider {
*/
private boolean verifyIfInstancePropertiesExists() {
return clProvider.getNodeTemplates(null, null).stream()
- .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains("_Instance"));
+ .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains(INSTANCE_TEXT));
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
index a71772624..dc40cc274 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
@@ -21,18 +21,27 @@
package org.onap.policy.clamp.controlloop.runtime.instantiation;
+import com.google.gson.Gson;
+import com.google.gson.internal.LinkedTreeMap;
+import com.google.gson.reflect.TypeToken;
+import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
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.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.controlloop.persistence.provider.ControlLoopProvider;
@@ -49,6 +58,7 @@ import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNameVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.stereotype.Component;
@@ -59,48 +69,102 @@ import org.springframework.stereotype.Component;
@Component
@AllArgsConstructor
public class ControlLoopInstantiationProvider {
+ private static final String CONTROL_LOOP_NODE_TYPE = "org.onap.policy.clamp.controlloop.ControlLoop";
+ private static final String CONTROL_LOOP_NODE_ELEMENT_TYPE = "ControlLoopElement";
+ private static final String PARTICIPANT_ID_PROPERTY_KEY = "participant_id";
+ private static final String CL_ELEMENT_NAME = "name";
+ private static final String CL_ELEMENT_VERSION = "version";
private static final String INSTANCE_TEXT = "_Instance";
+ private static final Gson GSON = new Gson();
+
private final ControlLoopProvider controlLoopProvider;
private final CommissioningProvider commissioningProvider;
private final SupervisionHandler supervisionHandler;
private static final Object lockit = new Object();
- private static final String CL_ELEMENT_NAME = "name";
-
/**
- * Create Instance Properties.
+ * Creates Instance Properties and Control Loop.
*
* @param serviceTemplate the service template
* @return the result of the instantiation operation
* @throws PfModelException on creation errors
*/
- public InstancePropertiesResponse saveInstanceProperties(ToscaServiceTemplate serviceTemplate) {
+ public InstancePropertiesResponse createInstanceProperties(ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
String instanceName = generateSequentialInstanceName();
+ ControlLoop controlLoop = new ControlLoop();
+ Map<UUID, ControlLoopElement> controlLoopElements = new HashMap<>();
+
+ ToscaServiceTemplate toscaServiceTemplate = commissioningProvider
+ .getToscaServiceTemplate(null, null);
- Map<String, ToscaNodeTemplate> nodeTemplates = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ Map<String, ToscaNodeTemplate> persistedNodeTemplateMap = toscaServiceTemplate
+ .getToscaTopologyTemplate().getNodeTemplates();
+
+ Map<String, ToscaNodeTemplate> nodeTemplates =
+ deepCloneNodeTemplate(serviceTemplate);
nodeTemplates.forEach((key, template) -> {
+ ToscaNodeTemplate newNodeTemplate = new ToscaNodeTemplate();
String name = key + instanceName;
+ String version = template.getVersion();
String description = template.getDescription() + instanceName;
- template.setName(name);
- template.setDescription(description);
+ newNodeTemplate.setName(name);
+ newNodeTemplate.setVersion(version);
+ newNodeTemplate.setDescription(description);
+ newNodeTemplate.setProperties(new HashMap<>(template.getProperties()));
+ newNodeTemplate.setType(template.getType());
+ newNodeTemplate.setTypeVersion(template.getTypeVersion());
+ newNodeTemplate.setMetadata(template.getMetadata());
- changeInstanceElementsName(template, instanceName);
+ crateNewControlLoopInstance(instanceName, controlLoop, controlLoopElements, template, newNodeTemplate);
+ persistedNodeTemplateMap.put(name, newNodeTemplate);
});
- Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate = controlLoopProvider
- .saveInstanceProperties(serviceTemplate);
+ ControlLoops controlLoops = new ControlLoops();
- var response = new InstancePropertiesResponse();
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(persistedNodeTemplateMap);
+
+ controlLoop.setElements(controlLoopElements);
+ controlLoops.getControlLoopList().add(controlLoop);
+
+ return saveInstancePropertiesAndControlLoop(serviceTemplate, controlLoops);
+ }
+
+ /**
+ * Deletes Instance Properties.
+ *
+ * @param name the name of the control loop to delete
+ * @param version the version of the control loop to delete
+ * @return the result of the deletion
+ * @throws PfModelException on deletion errors
+ */
+ public InstantiationResponse deleteInstanceProperties(String name, String version) throws PfModelException {
+
+ String instanceName = getInstancePropertyName(name, version);
+
+ Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap = new HashMap<>();
- // @formatter:off
- response.setAffectedInstanceProperties(toscaSavedNodeTemplate.values().stream().map(template ->
- template.getKey().asIdentifier()).collect(Collectors.toList()));
- // @formatter:on
+ ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(name, version);
+
+ toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().forEach((key, nodeTemplate) -> {
+ if (!nodeTemplate.getName().contains(instanceName)) {
+ filteredToscaNodeTemplateMap.put(key, nodeTemplate);
+ }
+ });
+
+ List<ToscaNodeTemplate> filteredToscaNodeTemplateList =
+ toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().values().stream()
+ .filter(nodeTemplate -> nodeTemplate.getName().contains(instanceName)).collect(Collectors.toList());
+
+ InstantiationResponse response = this.deleteControlLoop(name, version);
+
+ controlLoopProvider.deleteInstanceProperties(filteredToscaNodeTemplateMap, filteredToscaNodeTemplateList);
return response;
}
@@ -116,7 +180,8 @@ public class ControlLoopInstantiationProvider {
synchronized (lockit) {
for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
- var checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
+ var checkControlLoop = controlLoopProvider
+ .getControlLoop(controlLoop.getKey().asIdentifier());
if (checkControlLoop != null) {
throw new PfModelException(Response.Status.BAD_REQUEST,
controlLoop.getKey().asIdentifier() + " already defined");
@@ -323,27 +388,102 @@ public class ControlLoopInstantiationProvider {
}
/**
- * Creates instance element name.
+ * Saves Instance Properties and Control Loop.
*
- * @param serviceTemplate the service serviceTemplate
- * @param instanceName to amend to the element name
+ * @param serviceTemplate the service template
+ * @param controlLoops a list of control loops
+ * @return the result of the instance properties and instantiation operation
+ * @throws PfModelException on creation errors
*/
- private void changeInstanceElementsName(ToscaNodeTemplate serviceTemplate, String instanceName) {
+ private InstancePropertiesResponse saveInstancePropertiesAndControlLoop(
+ ToscaServiceTemplate serviceTemplate, ControlLoops controlLoops) throws PfModelException {
- @SuppressWarnings("unchecked")
- List<Map<String, String>> controlLoopElements = (List<Map<String, String>>) serviceTemplate.getProperties()
- .get("elements");
+ var response = new InstancePropertiesResponse();
- if (controlLoopElements != null) {
- controlLoopElements.forEach(clElement -> {
- String name = clElement.get(CL_ELEMENT_NAME) + instanceName;
- clElement.replace(CL_ELEMENT_NAME, name);
- });
+ Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate;
+
+ synchronized (lockit) {
+ for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
+ var checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
+ if (checkControlLoop != null) {
+ throw new PfModelException(Response.Status.BAD_REQUEST,
+ controlLoop.getKey().asIdentifier() + " already defined");
+ }
+ }
+
+ toscaSavedNodeTemplate = controlLoopProvider.saveInstanceProperties(serviceTemplate);
+
+ controlLoopProvider.createControlLoops(controlLoops.getControlLoopList());
+
+ }
+
+ List<ToscaConceptIdentifier> affectedControlLoops = controlLoops.getControlLoopList().stream()
+ .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList());
+
+ List<ToscaConceptIdentifier> toscaAffectedProperties = toscaSavedNodeTemplate.values().stream()
+ .map(template -> template.getKey().asIdentifier()).collect(Collectors.toList());
+
+ response.setAffectedInstanceProperties(Stream.of(affectedControlLoops, toscaAffectedProperties)
+ .flatMap(Collection::stream).collect(Collectors.toList()));
+
+ return response;
+ }
+
+ /**
+ * Crates a new Control Loop instance.
+ * @param instanceName Control Loop Instance name
+ * @param controlLoop empty Control Loop
+ * @param controlLoopElements new Control Loop Element map
+ * @param template original Cloned Tosca Node Template
+ * @param newNodeTemplate new Tosca Node Template
+ */
+ private void crateNewControlLoopInstance(String instanceName, ControlLoop controlLoop,
+ Map<UUID, ControlLoopElement> controlLoopElements,
+ ToscaNodeTemplate template,
+ ToscaNodeTemplate newNodeTemplate) {
+ if (template.getType().equals(CONTROL_LOOP_NODE_TYPE)) {
+ controlLoop.setDefinition(getControlLoopDefinition(newNodeTemplate));
+ }
+
+ if (template.getType().contains(CONTROL_LOOP_NODE_ELEMENT_TYPE)) {
+ ControlLoopElement controlLoopElement = getControlLoopElement(instanceName, newNodeTemplate);
+ controlLoopElements.put(controlLoopElement.getId(), controlLoopElement);
}
+
+ controlLoop.setName("PMSH" + instanceName);
+ controlLoop.setVersion(template.getVersion());
+ controlLoop.setDescription("PMSH control loop " + instanceName);
+ controlLoop.setState(ControlLoopState.UNINITIALISED);
+ controlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
}
/**
+ * Get's the instance property name of the control loop.
+ *
+ * @param name the name of the control loop to get, null for all control loops
+ * @param version the version of the control loop to get, null for all control loops
+ * @return the instance name of the control loop instance properties
+ * @throws PfModelException on errors getting control loops
+ */
+ private String getInstancePropertyName(String name, String version) throws PfModelException {
+ List<String> toscaDefinitionsNames =
+ controlLoopProvider.getControlLoops(name, version).stream().map(ControlLoop::getDefinition)
+ .map(ToscaNameVersion::getName).collect(Collectors.toList());
+
+ return toscaDefinitionsNames.stream().reduce("", (s1, s2) -> {
+
+ if (s2.contains(INSTANCE_TEXT)) {
+ String[] instances = s2.split(INSTANCE_TEXT);
+
+ return INSTANCE_TEXT + instances[1];
+ }
+
+ return s1;
+ });
+ }
+
+ /**
* Generates Instance Name in sequential order and return it to append to the Node Template Name.
*
* @return instanceName
@@ -361,4 +501,61 @@ public class ControlLoopInstantiationProvider {
return INSTANCE_TEXT + (instanceNumber + 1);
}
+
+ /**
+ * Retrieves Control Loop Definition.
+ *
+ * @param template tosca node template
+ * @return control loop definition
+ */
+ private ToscaConceptIdentifier getControlLoopDefinition(ToscaNodeTemplate template) {
+ ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
+ definition.setName(template.getName());
+ definition.setVersion(template.getVersion());
+
+ return definition;
+ }
+
+ /**
+ * Retrieves Control Loop Element.
+ *
+ * @param instanceName instance name to be appended to participant name
+ * @param template tosca node template
+ * @return a control loop element
+ */
+ @SuppressWarnings("unchecked")
+ private ControlLoopElement getControlLoopElement(String instanceName, ToscaNodeTemplate template) {
+ ControlLoopElement controlLoopElement = new ControlLoopElement();
+ ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
+ definition.setName(template.getName());
+ definition.setVersion(template.getVersion());
+ controlLoopElement.setDefinition(definition);
+
+ LinkedTreeMap<String, Object> participantId = (LinkedTreeMap<String, Object>) template.getProperties()
+ .get(PARTICIPANT_ID_PROPERTY_KEY);
+
+ ToscaConceptIdentifier participantIdAndType = new ToscaConceptIdentifier();
+ participantIdAndType.setName(participantId.get(CL_ELEMENT_NAME) + instanceName);
+ participantIdAndType.setVersion(String.valueOf(participantId.get(CL_ELEMENT_VERSION)));
+
+ controlLoopElement.setParticipantType(participantIdAndType);
+ controlLoopElement.setParticipantId(participantIdAndType);
+
+ return controlLoopElement;
+ }
+
+ /**
+ * Deep clones ToscaNodeTemplate.
+ *
+ * @param serviceTemplate ToscaServiceTemplate
+ * @return a cloned Hash Map of ToscaNodeTemplate
+ */
+ private Map<String, ToscaNodeTemplate> deepCloneNodeTemplate(ToscaServiceTemplate serviceTemplate) {
+ String jsonString = GSON.toJson(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates());
+
+ Type type = new TypeToken<HashMap<String, ToscaNodeTemplate>>() {}.getType();
+
+ return GSON.fromJson(jsonString, type);
+ }
+
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java
index 47a99ca29..e3e34878f 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java
@@ -18,7 +18,6 @@
package org.onap.policy.clamp.controlloop.runtime.main.parameters;
-import java.util.concurrent.TimeUnit;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@@ -34,17 +33,11 @@ import org.springframework.validation.annotation.Validated;
@Validated
public class ParticipantParameters {
- /**
- * Default maximum message age, in milliseconds, that should be examined. Any message
- * older than this is discarded.
- */
- public static final long DEFAULT_MAX_AGE_MS = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
-
- @Min(1)
+ @Min(100)
private long heartBeatMs;
- @Min(1)
- private long maxMessageAgeMs = DEFAULT_MAX_AGE_MS;
+ @Min(100)
+ private long maxStatusWaitMs;
@Valid
@NotNull
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java
index 8102fe90e..c0b0480de 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java
@@ -34,13 +34,13 @@ public class ParticipantUpdateParameters {
/**
* Maximum number of times to re-send a request to a PDP.
*/
- @Min(value = 0)
+ @Min(value = 1)
private int maxRetryCount;
/**
* Maximum time to wait, in milliseconds, for a PDP response.
*/
- @Min(value = 0)
+ @Min(value = 100)
private long maxWaitMs;
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java
index 2c3a41e26..fcb5aed97 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java
@@ -121,7 +121,7 @@ public class CommissioningController extends AbstractRestController {
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ToscaServiceTemplate body)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
return ResponseEntity.ok().body(provider.createControlLoopDefinitions(body));
}
@@ -188,7 +188,7 @@ public class CommissioningController extends AbstractRestController {
@ApiParam(
value = "Control Loop definition version",
required = true) @RequestParam("version") String version)
- throws PfModelException, ControlLoopException {
+ throws PfModelException {
return ResponseEntity.ok().body(provider.deleteControlLoopDefinition(name, version));
}
@@ -385,6 +385,7 @@ public class CommissioningController extends AbstractRestController {
* @param version the version of the tosca service template to get
* @return the specified tosca service template or section Json Schema
* @throws PfModelException on errors getting the Common or Instance Properties
+ * @throws ControlLoopException on error getting the Common or Instance Properties
*/
// @formatter:off
@GetMapping(value = "/commission/getCommonOrInstanceProperties",
@@ -438,7 +439,7 @@ public class CommissioningController extends AbstractRestController {
@ApiParam(value = "Tosca service template version", required = false) @RequestParam(
value = "version",
required = false) String version)
- throws PfModelException {
+ throws PfModelException {
return ResponseEntity.ok().body(provider.getNodeTemplatesWithCommonOrInstanceProperties(common, name, version));
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
index 5a8275f8a..91958f97a 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
@@ -187,9 +187,76 @@ public class InstantiationController extends AbstractRestController {
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body) {
+ @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body)
+ throws PfModelException {
+
+ return ResponseEntity.ok().body(provider.createInstanceProperties(body));
+ }
+
+ /**
+ * Deletes a control loop definition and instance properties.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param name the name of the control loop to delete
+ * @param version the version of the control loop to delete
+ * @return a response
+ * @throws PfModelException on errors deleting of control loop and instance properties
+ */
+ // @formatter:off
+ @DeleteMapping(value = "/instanceProperties",
+ produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
+ @ApiOperation(value = "Delete a control loop and instance properties",
+ notes = "Deletes a control loop and instance properties, returning optional error details",
+ response = InstantiationResponse.class,
+ tags = {TAGS},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(
+ name = VERSION_MINOR_NAME,
+ description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(
+ name = VERSION_PATCH_NAME,
+ description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(
+ name = VERSION_LATEST_NAME,
+ description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(
+ name = REQUEST_ID_NAME,
+ description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {
+ @Extension
+ (
+ name = EXTENSION_NAME,
+ properties = {
+ @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
+ }
+ )
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
+ }
+ )
+ // @formatter:on
+
+ public ResponseEntity<InstantiationResponse> deleteInstanceProperties(
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Control Loop definition name", required = true) @RequestParam("name") String name,
+ @ApiParam(value = "Control Loop definition version") @RequestParam(
+ value = "version",
+ required = true) String version) throws PfModelException {
- return ResponseEntity.ok().body(provider.saveInstanceProperties(body));
+ return ResponseEntity.ok().body(provider.deleteInstanceProperties(name, version));
}
/**
@@ -494,10 +561,10 @@ public class InstantiationController extends AbstractRestController {
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
+ @ApiParam(value = "Control Loop name", required = false) @RequestParam(
value = "name",
required = false) String name,
- @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
+ @ApiParam(value = "Control Loop version", required = false) @RequestParam(
value = "version",
required = false) String version)
throws PfModelException {
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 65149a733..d13d66c5d 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
@@ -61,8 +61,6 @@ public class SupervisionScanner {
private final ParticipantStatusReqPublisher participantStatusReqPublisher;
private final ParticipantUpdatePublisher participantUpdatePublisher;
- private final long maxWaitMs;
-
/**
* Constructor for instantiating SupervisionScanner.
*
@@ -89,8 +87,7 @@ public class SupervisionScanner {
controlLoopCounter.setMaxRetryCount(
clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- controlLoopCounter
- .setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs());
+ controlLoopCounter.setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
participantUpdateCounter.setMaxRetryCount(
clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
@@ -99,10 +96,7 @@ public class SupervisionScanner {
participantStatusCounter.setMaxRetryCount(
clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- participantStatusCounter
- .setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs());
-
- maxWaitMs = clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs();
+ participantStatusCounter.setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
@@ -131,6 +125,7 @@ public class SupervisionScanner {
} catch (PfModelException pfme) {
LOGGER.warn("error reading control loops from database", pfme);
}
+
if (counterCheck) {
scanParticipantUpdate();
}
@@ -145,7 +140,7 @@ public class SupervisionScanner {
if (participantUpdateCounter.isFault(id)) {
LOGGER.debug("report Participant Update fault");
- } else if (participantUpdateCounter.getDuration(id) > maxWaitMs) {
+ } else if (participantUpdateCounter.getDuration(id) > participantUpdateCounter.getMaxWaitMs()) {
if (participantUpdateCounter.count(id)) {
LOGGER.debug("retry message ParticipantUpdate");
@@ -166,7 +161,7 @@ public class SupervisionScanner {
LOGGER.debug("report Participant fault");
return;
}
- if (participantStatusCounter.getDuration(id) > maxWaitMs) {
+ if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()) {
if (participantStatusCounter.count(id)) {
LOGGER.debug("retry message ParticipantStatusReq");
participantStatusReqPublisher.send(id);
@@ -243,17 +238,19 @@ public class SupervisionScanner {
return;
}
- if (controlLoopCounter.count(id)) {
- if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
- LOGGER.debug("retry message ControlLoopUpdate");
- controlLoopUpdatePublisher.send(controlLoop);
+ if (controlLoopCounter.getDuration(id) > controlLoopCounter.getMaxWaitMs()) {
+ if (controlLoopCounter.count(id)) {
+ if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
+ LOGGER.debug("retry message ControlLoopUpdate");
+ controlLoopUpdatePublisher.send(controlLoop);
+ } else {
+ LOGGER.debug("retry message ControlLoopStateChange");
+ controlLoopStateChangePublisher.send(controlLoop);
+ }
} else {
- LOGGER.debug("retry message ControlLoopStateChange");
- controlLoopStateChangePublisher.send(controlLoop);
+ LOGGER.debug("report ControlLoop fault");
+ controlLoopCounter.setFault(id);
}
- } else {
- LOGGER.debug("report ControlLoop fault");
- controlLoopCounter.setFault(id);
}
}
}
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 d15a424b9..fe46297f1 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
@@ -25,14 +25,11 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
import java.time.Instant;
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.models.controlloop.concepts.ParticipantDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
-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.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -50,8 +47,7 @@ import org.springframework.stereotype.Component;
public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
- private static final Coder CODER = new StandardCoder();
+
private final PolicyModelsProvider modelsProvider;
/**
@@ -67,28 +63,27 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
message.setParticipantType(participantType);
message.setTimestamp(Instant.now());
- ToscaServiceTemplate toscaServiceTemplate;
+ ToscaServiceTemplate toscaServiceTemplate = null;
try {
- toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
+ var list = modelsProvider.getServiceTemplateList(null, null);
+ if (!list.isEmpty()) {
+ toscaServiceTemplate = list.get(0);
+ }
} catch (PfModelException pfme) {
LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
return;
}
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
- .getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType =
- CODER.decode(toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
+ if (toscaServiceTemplate != null) {
+ 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);
}
- prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
@@ -138,20 +133,4 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
return participantDefinition;
}
-
- private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
- ToscaServiceTemplate toscaServiceTemplate) {
- if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
- return true;
- } else {
- var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
- if (nodeType != null) {
- var derivedFrom = nodeType.getDerivedFrom();
- if (derivedFrom != null) {
- return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
- }
- }
- }
- return false;
- }
}
diff --git a/runtime-controlloop/src/main/resources/application.yaml b/runtime-controlloop/src/main/resources/application.yaml
index cddb3d0fb..96c340491 100644
--- a/runtime-controlloop/src/main/resources/application.yaml
+++ b/runtime-controlloop/src/main/resources/application.yaml
@@ -23,11 +23,11 @@ runtime:
participantClUpdateIntervalSec: 1000
participantClStateChangeIntervalSec: 1000
participantParameters:
- heartBeatMs: 120000
- maxMessageAgeMs: 600000
+ heartBeatMs: 20000
+ maxStatusWaitMs: 100000
updateParameters:
maxRetryCount: 3
- maxWaitMs: 100000
+ maxWaitMs: 20000
databaseProviderParameters:
name: PolicyProviderParameterGroup
implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
index 8529c0c9b..c107986a5 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
@@ -144,23 +144,4 @@ public class InstantiationUtils {
commissioningProvider.createControlLoopDefinitions(template);
}
-
- /**
- * Assert that instance properties has been properly saved.
- *
- * @param response InstancePropertiesResponse
- * @throws PfModelException if an error occurs
- */
- public static void assertInstancePropertiesResponse(InstancePropertiesResponse response) throws PfModelException {
-
- assertThat(response).isNotNull();
- assertThat(response.getErrorDetails()).isNull();
- assertThat(response.getAffectedInstanceProperties()).hasSize(8);
-
- boolean containsInstance = response.getAffectedInstanceProperties().stream()
- .anyMatch(identifier -> identifier.getName().contains("_Instance"));
-
- assertThat(containsInstance).isTrue();
-
- }
}
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 717858ebe..2ba321d36 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
@@ -130,7 +130,8 @@ class SupervisionScannerTest {
when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
- clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(0);
+ clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
+ clRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
var participant = new Participant();
participant.setName("Participant0");
@@ -158,7 +159,6 @@ class SupervisionScannerTest {
assertThat(participants.get(0).getHealthStatus()).isEqualTo(ParticipantHealthStatus.NOT_HEALTHY);
supervisionScanner.run(true);
- supervisionScanner.run(true);
participants = participantProvider.getParticipants(null, null);
assertThat(participants.get(0).getHealthStatus()).isEqualTo(ParticipantHealthStatus.OFF_LINE);
}
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 14de34d1c..bcc3a701c 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
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
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.ParticipantUtils;
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;
@@ -53,9 +54,6 @@ import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
@@ -77,8 +75,6 @@ class SupervisionMessagesTest extends CommonRestController {
private static PolicyModelsProvider modelsProvider;
private static ParticipantProvider participantProvider;
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
- private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
- private static final Coder CODER = new StandardCoder();
/**
* setup Db Provider Parameters.
@@ -133,7 +129,7 @@ class SupervisionMessagesTest extends CommonRestController {
// List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null);
commissioningProvider.createControlLoopDefinitions(serviceTemplate);
assertThatCode(() -> participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg))
- .doesNotThrowAnyException();
+ .doesNotThrowAnyException();
}
}
@@ -160,9 +156,10 @@ class SupervisionMessagesTest extends CommonRestController {
synchronized (lockit) {
ParticipantDeregisterListener participantDeregisterListener =
- new ParticipantDeregisterListener(supervisionHandler);
- assertThatCode(() -> participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null,
- participantDeregisterMsg)).doesNotThrowAnyException();
+ new ParticipantDeregisterListener(supervisionHandler);
+ assertThatCode(
+ () -> participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg))
+ .doesNotThrowAnyException();
}
}
@@ -191,59 +188,36 @@ class SupervisionMessagesTest extends CommonRestController {
ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null);
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
- for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
- toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
- ToscaConceptIdentifier clParticipantType;
- try {
- clParticipantType = CODER.decode(
- toscaInputEntry.getValue().getProperties().get("participantType").toString(),
- ToscaConceptIdentifier.class);
- } catch (CoderException e) {
- throw new RuntimeException("cannot get ParticipantType from toscaNodeTemplate", e);
- }
+ for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
+ .getNodeTemplates().entrySet()) {
+ if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
+ toscaServiceTemplate)) {
+ var clParticipantType =
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ toscaInputEntry.getValue(), participantDefinitionUpdates);
}
}
participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
synchronized (lockit) {
- ParticipantUpdatePublisher participantUpdatePublisher =
- new ParticipantUpdatePublisher(modelsProvider);
+ ParticipantUpdatePublisher participantUpdatePublisher = new ParticipantUpdatePublisher(modelsProvider);
participantUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
assertThatCode(() -> participantUpdatePublisher.send(participantUpdateMsg)).doesNotThrowAnyException();
}
}
- private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
- ToscaServiceTemplate toscaServiceTemplate) {
- if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
- return true;
- } else {
- var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
- if (nodeType != null) {
- var derivedFrom = nodeType.getDerivedFrom();
- if (derivedFrom != null) {
- return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
- }
- }
- }
- return false;
- }
-
private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
+ ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(
- entryKey, entryValue.getVersion()));
+ clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates
+ .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
} else {
boolean participantExists = false;
for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
@@ -253,15 +227,15 @@ class SupervisionMessagesTest extends CommonRestController {
}
}
if (!participantExists) {
- participantDefinitionUpdates.add(getParticipantDefinition(clDefinition, clParticipantType,
- controlLoopElementDefinitionList));
+ participantDefinitionUpdates.add(
+ getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
}
}
}
private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
+ ToscaConceptIdentifier clParticipantType,
+ List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
ParticipantDefinition participantDefinition = new ParticipantDefinition();
participantDefinition.setParticipantType(clParticipantType);
controlLoopElementDefinitionList.add(clDefinition);
@@ -280,9 +254,9 @@ class SupervisionMessagesTest extends CommonRestController {
synchronized (lockit) {
ParticipantUpdateAckListener participantUpdateAckListener =
- new ParticipantUpdateAckListener(supervisionHandler);
+ new ParticipantUpdateAckListener(supervisionHandler);
assertThatCode(() -> participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg))
- .doesNotThrowAnyException();
+ .doesNotThrowAnyException();
}
}
diff --git a/runtime-controlloop/src/test/resources/application_test.properties b/runtime-controlloop/src/test/resources/application_test.properties
index 0074d9f95..61557879d 100644
--- a/runtime-controlloop/src/test/resources/application_test.properties
+++ b/runtime-controlloop/src/test/resources/application_test.properties
@@ -9,11 +9,10 @@ server.error.path=/error
runtime.supervisionScannerIntervalSec=1000
runtime.participantClUpdateIntervalSec=1000
runtime.participantClStateChangeIntervalSec=1000
-runtime.participantParameters.heartBeatMs=120000
-runtime.participantParameters.updateParameters.maxRetryCount=1
-runtime.participantParameters.updateParameters.maxWaitMs=30000
-runtime.participantParameters.stateChangeParameters.maxRetryCount=1
-runtime.participantParameters.stateChangeParameters.maxWaitMs=30000
+runtime.participantParameters.heartBeatMs=20000
+runtime.participantParameters.maxStatusWaitMs=100000
+runtime.participantParameters.updateParameters.maxRetryCount=3
+runtime.participantParameters.updateParameters.maxWaitMs=20000
runtime.databaseProviderParameters.name=PolicyProviderParameterGroup
runtime.databaseProviderParameters.implementation=org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
runtime.databaseProviderParameters.databaseDriver=org.h2.Driver
diff --git a/runtime-controlloop/src/test/resources/parameters/TestParameters.json b/runtime-controlloop/src/test/resources/parameters/TestParameters.json
index 99fc43d21..6d16f4853 100644
--- a/runtime-controlloop/src/test/resources/parameters/TestParameters.json
+++ b/runtime-controlloop/src/test/resources/parameters/TestParameters.json
@@ -5,13 +5,10 @@
"participantClStateChangeIntervalSec": 1000,
"participantParameters": {
"heartBeatMs": 120000,
+ "maxStatusWaitMs": 100000,
"updateParameters": {
"maxRetryCount": 1,
"maxWaitMs": 30000
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
}
},
"databaseProviderParameters": {
diff --git a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index f800efe8d..55e1f8ad1 100644
--- a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1587,6 +1587,50 @@
</route>
</delete>
+ <delete uri="/v2/toscaControlLoop/deleteToscaInstantiation"
+ type="java.lang.String"
+ consumes="plain/text"
+ outType="java.lang.String"
+ produces="application/json"
+ bindingMode="off">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="name|version|requestId"/>
+ <setProperty name="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <doTry>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Delete Tosca Service Template')"/>
+ <to
+ uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')"/>
+ <to uri="direct:delete-tosca-instantiation"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/>
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
+ <log loggingLevel="ERROR"
+ message="Deleting Tosca Instantiation FAILED"/>
+
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>Deleting Tosca Instantiation FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </delete>
+
<get uri="/v2/toscaControlLoop/getToscaInstantiation" outType="java.lang.String" bindingMode="off" produces="application/json">
<route>
<removeHeaders pattern="*"
@@ -1644,12 +1688,12 @@
<to
uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
<log loggingLevel="ERROR"
- message="GET Tosca Instantiation JSON request failed: ${exception.stacktrace}"/>
+ message="GET Tosca Instantiation Order State JSON request failed: ${exception.stacktrace}"/>
<setHeader name="CamelHttpResponseCode">
<constant>500</constant>
</setHeader>
<setBody>
- <simple>GET Tosca Instantiation JSON FAILED</simple>
+ <simple>GET Tosca Instantiation Order State JSON FAILED</simple>
</setBody>
</doCatch>
</doTry>
@@ -1802,6 +1846,49 @@
</doTry>
</route>
</post>
+ <delete uri="/v2/toscaControlLoop/deleteToscaInstanceProperties"
+ type="java.lang.String"
+ consumes="plain/text"
+ outType="java.lang.String"
+ produces="application/json"
+ bindingMode="off">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="name|version|requestId"/>
+ <setProperty name="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <doTry>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Delete Tosca Service Template')"/>
+ <to
+ uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')"/>
+ <to uri="direct:delete-tosca-instance-properties"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/>
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
+ <log loggingLevel="ERROR"
+ message="Deleting Tosca Instance Properties FAILED"/>
+
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>Deleting Tosca Instance Properties FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </delete>
<get uri="/v2/toscaControlLoop/getCommonOrInstanceProperties" outType="java.lang.String" bindingMode="off" produces="application/json">
<route>
diff --git a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
index 12b43dd9f..ac83ffd7a 100644
--- a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
+++ b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
@@ -110,6 +110,37 @@
</doFinally>
</doTry>
</route>
+ <route id="delete-tosca-instantiation">
+ <from uri="direct:delete-tosca-instantiation"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Deleting Tosca Instantiation"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Controlloop', 'Deleting Tosca Instantiation')"/>
+ <setHeader name="CamelHttpMethod">
+ <constant>DELETE</constant>
+ </setHeader>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="name">
+ <simple>${header.name}</simple>
+ </setProperty>
+ <setProperty name="version">
+ <simple>${header.version}</simple>
+ </setProperty>
+ <log loggingLevel="INFO"
+ message="Endpoint to delete Tosca Instantiation: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation?name=${exchangeProperty[name]}&amp;version=${exchangeProperty[version]}&amp;bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <convertBodyTo type="java.lang.String"/>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
<route id="post-tosca-instance-properties">
<from uri="direct:post-tosca-instance-properties"/>
<doTry>
@@ -135,6 +166,37 @@
</doFinally>
</doTry>
</route>
+ <route id="delete-tosca-instance-properties">
+ <from uri="direct:delete-tosca-instance-properties"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Deleting Tosca Instance Properties"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Controlloop', 'Deleting Tosca Instance Properties')"/>
+ <setHeader name="CamelHttpMethod">
+ <constant>DELETE</constant>
+ </setHeader>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="name">
+ <simple>${header.name}</simple>
+ </setProperty>
+ <setProperty name="version">
+ <simple>${header.version}</simple>
+ </setProperty>
+ <log loggingLevel="INFO"
+ message="Endpoint to delete Tosca Instance Properties: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instanceProperties"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instanceProperties?name=${exchangeProperty[name]}&amp;version=${exchangeProperty[version]}&amp;bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <convertBodyTo type="java.lang.String"/>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
<route id="post-tosca-instantiation">
<from uri="direct:post-tosca-instantiation"/>
<doTry>
@@ -198,10 +260,16 @@
<setHeader name="Content-Type">
<constant>application/json</constant>
</setHeader>
+ <setProperty name="name">
+ <simple>${header.name}</simple>
+ </setProperty>
+ <setProperty name="version">
+ <simple>${header.version}</simple>
+ </setProperty>
<log loggingLevel="INFO"
message="Endpoint to get Tosca Instantiation Order State: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiationState"></log>
<toD
- uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiationState?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiationState?name=${exchangeProperty[name]}&amp;version=${exchangeProperty[version]}&amp;bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<convertBodyTo type="java.lang.String"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>