summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/src/main/resources/tosca/PolicyControlLoopElementType.yaml6
-rw-r--r--common/src/test/resources/demo/Notes.txt9
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java9
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java48
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java50
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java7
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java83
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java (renamed from models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChange.java)15
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java (renamed from models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdate.java)32
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java13
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java56
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java27
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java64
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java30
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java (renamed from models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChange.java)19
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java (renamed from models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java)34
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java (renamed from models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java)16
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java (renamed from models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java)49
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java2
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java (renamed from models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java)27
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java66
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java11
-rw-r--r--packages/policy-clamp-docker/pom.xml6
-rw-r--r--packages/policy-clamp-docker/src/main/docker/ClRuntimeDockerfile8
-rw-r--r--packages/policy-clamp-docker/src/main/docker/DcaeParticipantDockerfile7
-rw-r--r--packages/policy-clamp-docker/src/main/docker/KubernetesParticipantDockerfile3
-rw-r--r--packages/policy-clamp-docker/src/main/docker/PolicyParticipantDockerfile7
-rw-r--r--packages/policy-clamp-docker/src/main/docker/controlloop-runtime.sh18
-rw-r--r--packages/policy-clamp-docker/src/main/docker/dcae-participant.sh6
-rw-r--r--packages/policy-clamp-docker/src/main/docker/kubernetes-participant.sh16
-rw-r--r--packages/policy-clamp-docker/src/main/docker/policy-participant.sh6
-rw-r--r--packages/policy-clamp-tarball/src/main/package/tarball/assembly.xml13
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.json53
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml54
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.json70
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.yaml55
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml54
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.json76
-rw-r--r--packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml33
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/main/resources/config/application.yaml26
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/ParticipantDcaeTest.java (renamed from participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java)70
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java2
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java90
-rw-r--r--participant/participant-impl/participant-impl-http/pom.xml50
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/Application.java (renamed from runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStateChangePublisher.java)24
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/config/ParticipantConfig.java43
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/exception/HttpWebClientException.java (renamed from runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/PropertiesConfig.java)19
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java148
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigRequest.java51
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigurationEntity.java40
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/RestParams.java54
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/webclient/ClHttpClient.java135
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml27
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java63
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java146
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java48
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/webclient/ClHttpClientTest.java85
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/resources/HttpParticipantConfig.yaml208
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml24
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/parameters/CommonTestData.java2
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml26
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantMessagesTest.java75
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java48
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java2
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java93
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml26
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java8
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java58
-rw-r--r--participant/participant-impl/pom.xml1
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java6
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java6
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java77
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java21
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusReqListener.java (renamed from participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java)10
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java84
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java14
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java151
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java5
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java2
-rw-r--r--pom.xml4
-rw-r--r--runtime-controlloop/pom.xml5
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java4
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java263
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterGroup.java45
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterHandler.java72
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantParameters.java27
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantStateChangeParameters.java53
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantUpdateParameters.java20
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java227
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java155
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/MonitoringQueryController.java104
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java73
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounter.java91
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/MessageIntercept.java32
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java78
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java97
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java168
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/AbstractParticipantAckPublisher.java62
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java (renamed from runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopStateChangePublisher.java)10
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java51
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopUpdatePublisher.java61
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterAckPublisher.java45
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterListener.java67
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterAckPublisher.java (renamed from participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java)25
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterListener.java67
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusListener.java2
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusReqPublisher.java48
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdateAckListener.java67
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java82
-rw-r--r--runtime-controlloop/src/main/resources/application.yaml31
-rw-r--r--runtime-controlloop/src/main/resources/parameters/ClRuntimeParameters.json56
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java31
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java5
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java19
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java17
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounterTest.java84
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java66
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java160
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java226
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java14
-rw-r--r--runtime-controlloop/src/test/resources/application_test.properties23
-rw-r--r--runtime-controlloop/src/test/resources/parameters/CommissioningConfig.json24
-rw-r--r--runtime-controlloop/src/test/resources/parameters/EmptyParameters.json0
-rw-r--r--runtime-controlloop/src/test/resources/parameters/InstantiationConfigParametersStd.json63
-rw-r--r--runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_InvalidName.json35
-rw-r--r--runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_sim.json55
-rw-r--r--runtime-controlloop/src/test/resources/parameters/InvalidParameters.json3
-rw-r--r--runtime-controlloop/src/test/resources/parameters/MinimumParametersH2.json53
-rw-r--r--runtime-controlloop/src/test/resources/parameters/NoParameters.json2
-rw-r--r--runtime-controlloop/src/test/resources/parameters/TestParameters.json13
-rw-r--r--runtime-controlloop/src/test/resources/parameters/Unreadable.json62
-rw-r--r--runtime/extra/sql/bulkload/create-db.sql6
-rw-r--r--runtime/pom.xml91
-rw-r--r--runtime/src/main/resources/asciidoc/swagger.adoc4
-rw-r--r--runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml153
-rw-r--r--runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml109
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java92
-rw-r--r--runtime/src/test/resources/http-cache/example/node_template.json44
-rw-r--r--runtime/src/test/resources/http-cache/third_party_proxy.py52
141 files changed, 4747 insertions, 2183 deletions
diff --git a/common/src/main/resources/tosca/PolicyControlLoopElementType.yaml b/common/src/main/resources/tosca/PolicyControlLoopElementType.yaml
index e584c2fce..bf66718ca 100644
--- a/common/src/main/resources/tosca/PolicyControlLoopElementType.yaml
+++ b/common/src/main/resources/tosca/PolicyControlLoopElementType.yaml
@@ -31,3 +31,9 @@ node_types:
description: The policy that this control loop element is managing, if the policy ID is specified, the policy
is either already in the Policy Framework database or is specified in the "policies" part of the
TOSCA service template of the Control Loop definition
+ pdpGroup:
+ type: string
+ required: false
+ default: defaultGroup
+ description: The PDP group to which the policy should be deployed. This parameter is used when the policy is
+ deployed to PAP. The value defaults to the "defaultGroup", which always exists.
diff --git a/common/src/test/resources/demo/Notes.txt b/common/src/test/resources/demo/Notes.txt
index 315d6407c..43b75e915 100644
--- a/common/src/test/resources/demo/Notes.txt
+++ b/common/src/test/resources/demo/Notes.txt
@@ -6,13 +6,12 @@ $ docker run -p 3904:3904 --volume //c/Users/${USER}/Github/simulator/distributi
Run DMaaP simulator using Maven
Check out policy models
-Go to policy/models/models-sim/models-sim-dmaap
-mvn exec:java -Dexec.mainClass=org.onap.policy.models.sim.dmaap.startstop.Main -Dexec.args="-c src/main/resources/etc/DefaultConfig.json"
-
+Go to policy/models/models-sim/policy-models-simulators
+mvn exec:java -Dexec.mainClass=org.onap.policy.models.simulators.Main -Dexec.args="src/test/resources/simParameters.json"
Run CL from command line
-Go to clamp/tosca-controlloop/runtime
-mvn exec:java -Dexec.mainClass=org.onap.policy.clamp.controlloop.runtime.main.startstop.Main -Dexec.args="-c src/test/resources/parameters/TestParametersMariaDB.json"
+Go to clamp/runtime-controlloop
+mvn spring-boot:run -Dspring-boot.run.arguments="--topicServer=localhost --mariadb.host=localhost"
Run Participant from command line using Maven
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8080 --topicServer=localhost"
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
index 83f062c74..b99759eb3 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
@@ -20,12 +20,16 @@
package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.UUID;
+import java.util.function.UnaryOperator;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.ToString;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
@@ -57,6 +61,10 @@ public class ControlLoopElement {
private ClElementStatistics clElementStatistics;
+ // A map indexed by the property name. Each map entry is the serialized value of the property,
+ // which can be deserialized into an instance of the type of the property.
+ private Map<String, String> commonPropertiesMap = new LinkedHashMap<>();
+
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
*
@@ -71,5 +79,6 @@ public class ControlLoopElement {
this.orderedState = otherElement.orderedState;
this.description = otherElement.description;
this.clElementStatistics = otherElement.clElementStatistics;
+ this.commonPropertiesMap = PfUtils.mapMap(otherElement.commonPropertiesMap, UnaryOperator.identity());
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java
new file mode 100644
index 000000000..bdf894125
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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 lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * Class to represent a control loop info instance.
+ */
+@NoArgsConstructor
+@Data
+@ToString
+public class ControlLoopInfo {
+
+ private ControlLoopState state = ControlLoopState.UNINITIALISED;
+
+ private ControlLoopStatistics controlLoopStatistics;
+
+ /**
+ * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
+ *
+ * @param otherElement the other element to copy from
+ */
+ public ControlLoopInfo(final ControlLoopInfo otherElement) {
+ this.state = otherElement.state;
+ this.controlLoopStatistics = otherElement.controlLoopStatistics;
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java
new file mode 100644
index 000000000..685947b13
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java
@@ -0,0 +1,50 @@
+/*-
+ * ============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.time.Instant;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import lombok.ToString;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+@NoArgsConstructor
+@Data
+@ToString
+public class ControlLoopStatistics {
+
+ @NonNull
+ private ToscaConceptIdentifier controlLoopId;
+
+ @NonNull
+ private Instant timeStamp;
+
+ @NonNull
+ private ClElementStatisticsList clElementStatisticsList;
+
+ private long eventCount;
+ private long lastExecutionTime;
+ private double averageExecutionTime;
+ private long upTime;
+ private long lastEnterTime;
+ private long lastStart;
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java
index 0cf41c9cd..e7c5fecda 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java
@@ -43,5 +43,10 @@ public enum ParticipantHealthStatus {
/**
* The health status of the Participant is unknown.
*/
- UNKNOWN
+ UNKNOWN,
+
+ /**
+ * The health status of the Participant is off line.
+ */
+ OFF_LINE
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java
new file mode 100644
index 000000000..3411a0369
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java
@@ -0,0 +1,83 @@
+/*-
+ * ============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.messages.dmaap.participant;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.UnaryOperator;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Class to represent the CONTROLLOOP_ACK message that a participant sends
+ * to control loop runtime as an acknowledgement to either ControlLoopUpdate
+ * or ControlLoopStateChange message.
+ */
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class ControlLoopAck extends ParticipantAckMessage {
+
+ /**
+ * Participant ID, or {@code null} for messages from participants.
+ */
+ private ToscaConceptIdentifier participantId;
+
+ /**
+ * Participant Type, or {@code null} for messages from participants.
+ */
+ private ToscaConceptIdentifier participantType;
+
+ /**
+ * Control loop ID, or {@code null} for messages to participants.
+ */
+ private ToscaConceptIdentifier controlLoopId;
+
+ // A map with ControlLoopElementID as its key, and a pair of result and message as value per
+ // ControlLoopElement.
+ private Map<UUID, Pair<Boolean, String>> controlLoopResultMap = new LinkedHashMap<>();
+
+ /**
+ * Constructor for instantiating ParticipantRegisterAck class with message name.
+ *
+ */
+ public ControlLoopAck(final ParticipantMessageType messageType) {
+ super(messageType);
+ }
+
+ /**
+ * Constructs the object, making a deep copy.
+ *
+ * @param source source from which to copy
+ */
+ public ControlLoopAck(final ControlLoopAck source) {
+ super(source);
+ this.participantId = source.participantId;
+ this.participantType = source.participantType;
+ this.controlLoopId = source.controlLoopId;
+ this.controlLoopResultMap = PfUtils.mapMap(source.controlLoopResultMap, UnaryOperator.identity());
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChange.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java
index 1a9a891f6..e6955b90b 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChange.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java
@@ -24,23 +24,25 @@ import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
/**
- * Class to represent the PARTICIPANT_CONTROL_LOOP_STATE_CHANGE message that the control loop runtime will send to
+ * Class to represent the CONTROL_LOOP_STATE_CHANGE message that the control loop runtime will send to
* participants to change the state of a control loop they are running.
*/
@Getter
@Setter
@ToString(callSuper = true)
-public class ParticipantControlLoopStateChange extends ParticipantMessage {
+public class ControlLoopStateChange extends ParticipantMessage {
private ControlLoopOrderedState orderedState;
+ private ControlLoopState currentState;
/**
- * Constructor for instantiating ParticipantControlLoopStateChange class with message name.
+ * Constructor for instantiating ControlLoopStateChange class with message name.
*
*/
- public ParticipantControlLoopStateChange() {
- super(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_STATE_CHANGE);
+ public ControlLoopStateChange() {
+ super(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
}
/**
@@ -48,9 +50,10 @@ public class ParticipantControlLoopStateChange extends ParticipantMessage {
*
* @param source source from which to copy
*/
- public ParticipantControlLoopStateChange(ParticipantControlLoopStateChange source) {
+ public ControlLoopStateChange(ControlLoopStateChange source) {
super(source);
this.orderedState = source.orderedState;
+ this.currentState = source.currentState;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdate.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java
index ed729a64b..865264f6d 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdate.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java
@@ -20,33 +20,40 @@
package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
- * Class to represent the PARTICIPANT_CONTROL_LOOP_UPDATE message that the control loop runtime sends to a participant.
+ * Class to represent the CONTROL_LOOP_UPDATE message that the control loop runtime sends to a participant.
* When a participant receives this message, it creates the control loop elements contained in the message and sets them
- * to state PASSIVE. subsequent PARTICIPANT_CONTROL_LOOP_STATE_CHANGE messages are used to activate the control loops.
+ * to state PASSIVE. subsequent CONTROL_LOOP_STATE_CHANGE messages are used to activate the control loops.
*/
@Getter
@Setter
@ToString(callSuper = true)
-public class ParticipantControlLoopUpdate extends ParticipantMessage {
+public class ControlLoopUpdate extends ParticipantMessage {
+
// The control loop
private ControlLoop controlLoop;
- // A service template containing a complete definition of the control loop
- private ToscaServiceTemplate controlLoopDefinition;
+ // A map with Participant ID as its key, and a map of ControlLoopElements as value.
+ private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>>
+ participantUpdateMap = new LinkedHashMap<>();
/**
- * Constructor for instantiating ParticipantControlLoopUpdate class with message name.
+ * Constructor for instantiating ControlLoopUpdate class with message name.
*
*/
- public ParticipantControlLoopUpdate() {
- super(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_UPDATE);
+ public ControlLoopUpdate() {
+ super(ParticipantMessageType.CONTROL_LOOP_UPDATE);
}
/**
@@ -54,10 +61,11 @@ public class ParticipantControlLoopUpdate extends ParticipantMessage {
*
* @param source source from which to copy
*/
- public ParticipantControlLoopUpdate(ParticipantControlLoopUpdate source) {
+ public ControlLoopUpdate(ControlLoopUpdate source) {
super(source);
- this.controlLoop = new ControlLoop(source.controlLoop);
- this.controlLoopDefinition = new ToscaServiceTemplate(source.controlLoopDefinition);
+ this.controlLoop = source.controlLoop;
+ this.participantUpdateMap = PfUtils.mapMap(source.participantUpdateMap,
+ clElementMap -> PfUtils.mapMap(clElementMap, ControlLoopElement::new));
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java
index 1e53921dd..8b59a1801 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java
@@ -24,6 +24,7 @@ import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent participant Ack message.
@@ -45,6 +46,16 @@ public class ParticipantAckMessage {
private ParticipantMessageType messageType;
/**
+ * Participant Type, or {@code null} for messages from participants.
+ */
+ private ToscaConceptIdentifier participantType;
+
+ /**
+ * Participant ID, or {@code null} for messages from participants.
+ */
+ private ToscaConceptIdentifier participantId;
+
+ /**
* Constructor for instantiating a participant ack message class.
*
* @param messageType the message type
@@ -63,5 +74,7 @@ public class ParticipantAckMessage {
this.result = source.result;
this.message = source.message;
this.messageType = source.messageType;
+ this.participantType = source.participantType;
+ this.participantId = source.participantId;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java
deleted file mode 100644
index e472e15fe..000000000
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============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.messages.dmaap.participant;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
-
-/**
- * Class to represent the PARTICIPANT_HEALTHCHECK message that the control loop runtime will send to
- * participants to change the state of a control loop they are running.
- */
-@Getter
-@Setter
-@ToString(callSuper = true)
-public class ParticipantHealthCheck extends ParticipantMessage {
- private ParticipantState state;
-
- /**
- * Constructor for instantiating ParticipantHealthCheck class with message name.
- *
- */
- public ParticipantHealthCheck() {
- super(ParticipantMessageType.PARTICIPANT_HEALTH_CHECK);
- }
-
- /**
- * Constructs the object, making a deep copy.
- *
- * @param source source from which to copy
- */
- public ParticipantHealthCheck(ParticipantHealthCheck source) {
- super(source);
-
- this.state = source.state;
- }
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java
index 94d484620..62b8d20b0 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java
@@ -38,15 +38,15 @@ public enum ParticipantMessageType {
/**
* Used by controlloop runtime to update the controlloops running on participants, triggers a
- * PARTICIPANT_STATUS message with the result of the PARTICIPANT_CONTROL_LOOP_UPDATE operation.
+ * PARTICIPANT_STATUS message with the result of the CONTROL_LOOP_UPDATE operation.
*/
- PARTICIPANT_CONTROL_LOOP_UPDATE,
+ CONTROL_LOOP_UPDATE,
/**
* Used by controlloop runtime to change the state of controlloops in participants, triggers a
- * PARTICIPANT_STATUS message with result of PARTICIPANT_CONTROL_LOOP_STATE_CHANGE operation.
+ * PARTICIPANT_STATUS message with result of CONTROL_LOOP_STATE_CHANGE operation.
*/
- PARTICIPANT_CONTROL_LOOP_STATE_CHANGE,
+ CONTROL_LOOP_STATE_CHANGE,
/**
* Used by the control loop runtime to order a health check on participants, triggers a
@@ -83,5 +83,22 @@ public enum ParticipantMessageType {
* Used by participant to acknowledge the receipt of Participant_Update message
* from control loop runtime.
*/
- PARTICIPANT_UPDATE_ACK
+ PARTICIPANT_UPDATE_ACK,
+
+ /**
+ * Used by participant to acknowledge the receipt of ControlLoop_Update message
+ * from control loop runtime.
+ */
+ CONTROLLOOP_UPDATE_ACK,
+
+ /**
+ * Used by participant to acknowledge the receipt of ControlLoop_StateChange message
+ * from control loop runtime.
+ */
+ CONTROLLOOP_STATECHANGE_ACK,
+
+ /**
+ * Used by control loop runtime to request for ParticipantStatus message immediately.
+ */
+ PARTICIPANT_STATUS_REQ
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java
index 7319d99db..af0149189 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java
@@ -23,10 +23,6 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
/**
* Class to represent the PARTICIPANT_REGISTER message that all the participants send to control loop runtime.
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java
deleted file mode 100644
index 4c771b405..000000000
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * ============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.messages.dmaap.participant;
-
-import java.util.UUID;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent participant response details.
- */
-@Getter
-@Setter
-@ToString
-@NoArgsConstructor
-public class ParticipantResponseDetails {
-
- // The responseTo field should match the original request id in the request.
- private UUID responseTo;
- private ParticipantResponseStatus responseStatus;
- private String responseMessage;
-
- /**
- * Constructs the object as a response to.
- *
- * @param triggerMessage the message to which this is a response
- */
- public ParticipantResponseDetails(ParticipantMessage triggerMessage) {
- this.responseMessage = null;
- this.responseStatus = ParticipantResponseStatus.FAIL;
- this.responseTo = triggerMessage.getMessageId();
- }
-
- /**
- * Constructs the object, making a deep copy.
- *
- * @param source source from which to copy
- */
- public ParticipantResponseDetails(ParticipantResponseDetails source) {
- this.responseMessage = source.responseMessage;
- this.responseStatus = source.responseStatus;
- this.responseTo = source.responseTo;
- }
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java
index 5b9284243..c3e630681 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java
@@ -20,13 +20,19 @@
package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent the PARTICIPANT_STATUS message that all the participants send to the control loop runtime.
@@ -35,21 +41,21 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
@Setter
@ToString(callSuper = true)
public class ParticipantStatus extends ParticipantMessage {
- // The response should be completed if this message is a response to a request from the Control Loop Runtime
- private ParticipantResponseDetails response;
// State and health status of the participant
private ParticipantState state;
private ParticipantHealthStatus healthStatus;
- // Control Loops on the participant
- private ControlLoops controlLoops;
-
// Participant statistics
private ParticipantStatistics participantStatistics;
- // Description. May be left {@code null}.
- private String message;
+ // A map with Participant ID as its key, and a map of ControlLoopElements as value.
+ // Returned in response to ParticipantStatusReq only
+ private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
+ participantDefinitionUpdateMap = new LinkedHashMap<>();
+
+ // Map of ControlLoopInfo types indexed by ControlLoopId, one entry for each control loop
+ private Map<ToscaConceptIdentifier, ControlLoopInfo> controlLoopInfoMap;
/**
* Constructor for instantiating ParticipantStatus class with message name.
@@ -69,8 +75,10 @@ public class ParticipantStatus extends ParticipantMessage {
this.state = source.state;
this.healthStatus = source.healthStatus;
- this.message = source.message;
- this.controlLoops = (source.controlLoops == null ? null : new ControlLoops(source.controlLoops));
- this.response = (source.response == null ? null : new ParticipantResponseDetails(source.response));
+ this.participantStatistics = (source.participantStatistics == null ? null : new ParticipantStatistics());
+ this.participantDefinitionUpdateMap = PfUtils.mapMap(source.participantDefinitionUpdateMap,
+ clElementDefinitionMap -> PfUtils.mapMap(clElementDefinitionMap,
+ ControlLoopElementDefinition::new));
+ this.controlLoopInfoMap = PfUtils.mapMap(source.controlLoopInfoMap, ControlLoopInfo::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChange.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java
index 5f5150077..9242cea02 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChange.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java
@@ -23,24 +23,21 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
/**
- * Class to represent the PARTICIPANT_STATE_CHANGE message that the control loop runtime will send to participants
- * to change their state.
+ * Class to represent the PARTICIPANT_STATUS_REQ message that controlloop runtime
+ * sends to participants for an immediate ParticipantStatus from participants.
*/
@Getter
@Setter
@ToString(callSuper = true)
-public class ParticipantStateChange extends ParticipantMessage {
- private ParticipantState state;
+public class ParticipantStatusReq extends ParticipantMessage {
/**
- * Constructor for instantiating ParticipantStateChange class with message name.
- *
+ * Constructor for instantiating a participant status request class.
*/
- public ParticipantStateChange() {
- super(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+ public ParticipantStatusReq() {
+ super(ParticipantMessageType.PARTICIPANT_STATUS_REQ);
}
/**
@@ -48,9 +45,7 @@ public class ParticipantStateChange extends ParticipantMessage {
*
* @param source source from which to copy
*/
- public ParticipantStateChange(ParticipantStateChange source) {
+ public ParticipantStatusReq(final ParticipantStatusReq source) {
super(source);
-
- this.state = source.state;
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java
index 7f595fbbb..d7d7e4327 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java
@@ -24,38 +24,40 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
-import java.time.Instant;
+import java.util.Map;
import java.util.UUID;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-/**
- * Test the copy constructor and other methods.
- */
-class ParticipantHealthCheckTest {
+class ControlLoopAckTest {
@Test
void testCopyConstructor() {
- assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ControlLoopAck((ControlLoopAck) null))
+ .isInstanceOf(NullPointerException.class);
- ParticipantHealthCheck orig = new ParticipantHealthCheck();
+ final ControlLoopAck orig = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_UPDATE);
// verify with null values
assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantHealthCheck(orig).toString()));
+ removeVariableFields(new ControlLoopAck(orig).toString()));
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier();
- id.setName("id");
- id.setVersion("1.2.3");
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setControlLoopId(id);
orig.setParticipantId(id);
- orig.setMessageId(UUID.randomUUID());
- orig.setState(ParticipantState.ACTIVE);
- orig.setTimestamp(Instant.ofEpochMilli(3000));
+ orig.setParticipantType(id);
+
+ Pair<Boolean, String> clElementResult = Pair.of(true, "ControlLoopElement result");
+ final Map<UUID, Pair<Boolean, String>> controlLoopResultMap = Map.of(UUID.randomUUID(), clElementResult);
+ orig.setControlLoopResultMap(controlLoopResultMap);
+
+ orig.setResponseTo(UUID.randomUUID());
+ orig.setResult(true);
+ orig.setMessage("Successfully processed ControlLoopUpdate message");
assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantHealthCheck(orig).toString()));
+ removeVariableFields(new ControlLoopAck(orig).toString()));
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java
index c37268ac0..dd6a814a7 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java
@@ -28,34 +28,34 @@ import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Test the copy constructor and other methods.
*/
-class ParticipantControlLoopStateChangeTest {
+class ControlLoopStateChangeTest {
@Test
void testCopyConstructor() {
- assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ControlLoopStateChange(null)).isInstanceOf(NullPointerException.class);
- ParticipantControlLoopStateChange orig = new ParticipantControlLoopStateChange();
+ ControlLoopStateChange orig = new ControlLoopStateChange();
// verify with null values
assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantControlLoopStateChange(orig).toString()));
+ removeVariableFields(new ControlLoopStateChange(orig).toString()));
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier();
- id.setName("id");
- id.setVersion("1.2.3");
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setControlLoopId(id);
orig.setParticipantId(id);
orig.setMessageId(UUID.randomUUID());
orig.setOrderedState(ControlLoopOrderedState.RUNNING);
+ orig.setCurrentState(ControlLoopState.PASSIVE);
orig.setTimestamp(Instant.ofEpochMilli(3000));
assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantControlLoopStateChange(orig).toString()));
+ removeVariableFields(new ControlLoopStateChange(orig).toString()));
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java
index 5d87095ba..0ac4f5331 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java
@@ -22,50 +22,59 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
import java.time.Instant;
+import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Test the copy constructor.
*/
-class ParticipantControlLoopUpdateTest {
+class ControlLoopUpdateTest {
@Test
void testCopyConstructor() {
- assertThatThrownBy(() -> new ParticipantControlLoopUpdate(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ControlLoopUpdate(null)).isInstanceOf(NullPointerException.class);
- ParticipantControlLoopUpdate orig = new ParticipantControlLoopUpdate();
+ ControlLoopUpdate orig = new ControlLoopUpdate();
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier();
- id.setName("id");
- id.setVersion("1.2.3");
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setControlLoopId(id);
- orig.setParticipantId(id);
+ orig.setParticipantId(null);
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
+ ControlLoopElement clElement = new ControlLoopElement();
+ clElement.setId(UUID.randomUUID());
+ clElement.setDefinition(id);
+ clElement.setDescription("Description");
+ clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ clElement.setState(ControlLoopState.PASSIVE);
+ clElement.setParticipantId(id);
+ clElement.setParticipantType(id);
+
ControlLoop controlLoop = new ControlLoop();
controlLoop.setName("controlLoop");
- ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
- toscaServiceTemplate.setName("serviceTemplate");
- toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
- toscaServiceTemplate.setDescription("Description of serviceTemplate");
- toscaServiceTemplate.setVersion("1.2.3");
- orig.setControlLoopDefinition(toscaServiceTemplate);
+ Map<UUID, ControlLoopElement> elements = Map.of(clElement.getId(), clElement);
+ controlLoop.setElements(elements);
orig.setControlLoop(controlLoop);
- ParticipantControlLoopUpdate other = new ParticipantControlLoopUpdate(orig);
+ Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+ clElement.setCommonPropertiesMap(commonPropertiesMap);
- assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
+ Map<UUID, ControlLoopElement> controlLoopElementMap = Map.of(UUID.randomUUID(), clElement);
+ Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>>
+ participantUpdateMap = Map.of(id, controlLoopElementMap);
+ orig.setParticipantUpdateMap(participantUpdateMap);
- // ensure list and items are not the same object
- assertNotSame(other.getControlLoop(), controlLoop);
- assertNotSame(other.getControlLoopDefinition(), toscaServiceTemplate);
+ ControlLoopUpdate other = new ControlLoopUpdate(orig);
+
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java
index 1a56a3979..e67fbc143 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java
@@ -46,6 +46,8 @@ class ParticipantPojosTest {
pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class));
pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class));
pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class));
+ pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAck.class));
+ pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAckTest.class));
// @formatter:off
final Validator validator = ValidatorBuilder
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java
index 6c73c6d3e..b391aa2cf 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java
@@ -27,35 +27,26 @@ import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participan
import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
- * Test the copy constructor and the other methods.
+ * Test the copy constructor.
*/
-class ParticipantStateChangeTest {
-
+class ParticipantStatusReqTest {
@Test
void testCopyConstructor() {
- assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class);
-
- ParticipantStateChange orig = new ParticipantStateChange();
-
- // verify with null values
- assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantStateChange(orig).toString()));
+ assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class);
+ ParticipantStatusReq orig = new ParticipantStatusReq();
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier();
- id.setName("id");
- id.setVersion("1.2.3");
- orig.setControlLoopId(id);
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setParticipantId(id);
+ orig.setControlLoopId(null);
+ orig.setParticipantType(null);
orig.setMessageId(UUID.randomUUID());
- orig.setState(ParticipantState.ACTIVE);
orig.setTimestamp(Instant.ofEpochMilli(3000));
- assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantStateChange(orig).toString()));
+ ParticipantStatusReq other = new ParticipantStatusReq(orig);
+ assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java
index 706e58b91..05cfdd78b 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java
@@ -25,10 +25,20 @@ import static org.junit.Assert.assertEquals;
import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
import java.time.Instant;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class ParticipantStatusTest {
@@ -43,20 +53,64 @@ class ParticipantStatusTest {
removeVariableFields(new ParticipantStatus(orig).toString()));
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier();
- id.setName("id");
- id.setVersion("1.2.3");
+ ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setControlLoopId(id);
orig.setParticipantId(id);
+ orig.setParticipantType(id);
orig.setMessageId(UUID.randomUUID());
orig.setState(ParticipantState.ACTIVE);
+ orig.setHealthStatus(ParticipantHealthStatus.HEALTHY);
orig.setTimestamp(Instant.ofEpochMilli(3000));
- final ParticipantResponseDetails resp = new ParticipantResponseDetails();
- resp.setResponseMessage("my-response");
- orig.setResponse(resp);
+ ControlLoopInfo clInfo = getControlLoopInfo(id);
+ orig.setControlLoopInfoMap(Map.of(id, clInfo));
+
+ ControlLoopElementDefinition clDefinition = getClElementDefinition();
+ Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
+ Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
+ participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap);
+ orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
assertEquals(removeVariableFields(orig.toString()),
removeVariableFields(new ParticipantStatus(orig).toString()));
}
+
+ private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) {
+ ControlLoopInfo clInfo = new ControlLoopInfo();
+ clInfo.setState(ControlLoopState.PASSIVE2RUNNING);
+
+ ControlLoopStatistics clStatistics = new ControlLoopStatistics();
+ clStatistics.setControlLoopId(id);
+ clStatistics.setAverageExecutionTime(12345);
+ clStatistics.setEventCount(12345);
+ clStatistics.setLastEnterTime(12345);
+ clStatistics.setLastExecutionTime(12345);
+ clStatistics.setLastStart(12345);
+ clStatistics.setTimeStamp(Instant.ofEpochMilli(3000));
+ clStatistics.setUpTime(12345);
+ ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList();
+ ClElementStatistics clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1"));
+ clElementStatistics.setTimeStamp(Instant.now());
+ clElementStatisticsList.setClElementStatistics(List.of(clElementStatistics));
+ clStatistics.setClElementStatisticsList(clElementStatisticsList);
+
+ clInfo.setControlLoopStatistics(clStatistics);
+ return clInfo;
+ }
+
+ private ControlLoopElementDefinition getClElementDefinition() {
+ ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
+ toscaServiceTemplate.setName("serviceTemplate");
+ toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
+ toscaServiceTemplate.setDescription("Description of serviceTemplate");
+ toscaServiceTemplate.setVersion("1.2.3");
+
+ ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setId(UUID.randomUUID());
+ clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate);
+ Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+ clDefinition.setCommonPropertiesMap(commonPropertiesMap);
+ return clDefinition;
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java
index 4f8b42b3a..094431233 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java
@@ -22,11 +22,9 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
import java.time.Instant;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -62,16 +60,13 @@ class ParticipantUpdateTest {
ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
clDefinition.setId(UUID.randomUUID());
clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate);
- Map<String, String> commonPropertiesMap = new LinkedHashMap<>();
- commonPropertiesMap.put("Prop1", "PropValue");
+ Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
clDefinition.setCommonPropertiesMap(commonPropertiesMap);
- Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>();
- controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition);
+ Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
- participantDefinitionUpdateMap = new LinkedHashMap<>();
- participantDefinitionUpdateMap.put(id, controlLoopElementDefinitionMap);
+ participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap);
orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
ParticipantUpdate other = new ParticipantUpdate(orig);
diff --git a/packages/policy-clamp-docker/pom.xml b/packages/policy-clamp-docker/pom.xml
index 576c95de6..16c416126 100644
--- a/packages/policy-clamp-docker/pom.xml
+++ b/packages/policy-clamp-docker/pom.xml
@@ -111,6 +111,12 @@
<outputDirectory>/lib</outputDirectory>
<outputFileNameMapping>policy-controlloop-runtime.tar.gz</outputFileNameMapping>
</dependencySet>
+ <dependencySet>
+ <includes>
+ <include>org.onap.policy.clamp:policy-clamp-runtime-controlloop</include>
+ </includes>
+ <outputFileNameMapping>app.jar</outputFileNameMapping>
+ </dependencySet>
</dependencySets>
</inline>
</assembly>
diff --git a/packages/policy-clamp-docker/src/main/docker/ClRuntimeDockerfile b/packages/policy-clamp-docker/src/main/docker/ClRuntimeDockerfile
index bd5000686..3d57418e5 100644
--- a/packages/policy-clamp-docker/src/main/docker/ClRuntimeDockerfile
+++ b/packages/policy-clamp-docker/src/main/docker/ClRuntimeDockerfile
@@ -33,14 +33,18 @@ ENV POLICY_HOME=$POLICY_HOME/clamp
RUN mkdir -p $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \
chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \
mkdir /packages
-COPY /maven/* /packages
+COPY /maven/lib/policy-controlloop-runtime.tar.gz /packages
+
RUN tar xvfz /packages/policy-controlloop-runtime.tar.gz --directory $POLICY_HOME && \
rm /packages/policy-controlloop-runtime.tar.gz
WORKDIR $POLICY_HOME
COPY controlloop-runtime.sh bin/.
+COPY /maven/app.jar /app
-RUN chown -R policy:policy * && chmod 755 bin/*.sh
+RUN chown -R policy:policy * && \
+ chmod 755 bin/*.sh && \
+ chown -R policy:policy /app
USER policy
WORKDIR $POLICY_HOME/bin
diff --git a/packages/policy-clamp-docker/src/main/docker/DcaeParticipantDockerfile b/packages/policy-clamp-docker/src/main/docker/DcaeParticipantDockerfile
index 368b9348a..ed09c50d3 100644
--- a/packages/policy-clamp-docker/src/main/docker/DcaeParticipantDockerfile
+++ b/packages/policy-clamp-docker/src/main/docker/DcaeParticipantDockerfile
@@ -34,15 +34,16 @@ RUN mkdir -p $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \
chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \
mkdir /packages
COPY /maven/lib/dcae-participant.tar.gz /packages
+
RUN tar xvfz /packages/dcae-participant.tar.gz --directory $POLICY_HOME && \
- rm /packages/dcae-participant.tar.gz && \
- rm -rf $POLICY_HOME/lib
+ rm /packages/dcae-participant.tar.gz
WORKDIR $POLICY_HOME
COPY dcae-participant.sh bin/.
COPY /maven/app.jar /app
-RUN chown -R policy:policy * && chmod 755 bin/*.sh && \
+RUN chown -R policy:policy * && \
+ chmod 755 bin/*.sh && \
chown -R policy:policy /app
USER policy
diff --git a/packages/policy-clamp-docker/src/main/docker/KubernetesParticipantDockerfile b/packages/policy-clamp-docker/src/main/docker/KubernetesParticipantDockerfile
index 63209d75f..d08e14fff 100644
--- a/packages/policy-clamp-docker/src/main/docker/KubernetesParticipantDockerfile
+++ b/packages/policy-clamp-docker/src/main/docker/KubernetesParticipantDockerfile
@@ -36,8 +36,7 @@ RUN mkdir -p $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \
COPY /maven/lib/kubernetes-participant.tar.gz /packages
RUN tar xvfz /packages/kubernetes-participant.tar.gz --directory $POLICY_HOME && \
- rm /packages/kubernetes-participant.tar.gz && \
- rm -rf $POLICY_HOME/lib
+ rm /packages/kubernetes-participant.tar.gz
WORKDIR $POLICY_HOME
COPY kubernetes-participant.sh bin/.
diff --git a/packages/policy-clamp-docker/src/main/docker/PolicyParticipantDockerfile b/packages/policy-clamp-docker/src/main/docker/PolicyParticipantDockerfile
index 3c2082202..8eca34d42 100644
--- a/packages/policy-clamp-docker/src/main/docker/PolicyParticipantDockerfile
+++ b/packages/policy-clamp-docker/src/main/docker/PolicyParticipantDockerfile
@@ -34,15 +34,16 @@ RUN mkdir -p $POLICY_LOGS $POLICY_HOME $POLICY_HOME/bin && \
chown -R policy:policy $POLICY_HOME $POLICY_LOGS && \
mkdir /packages
COPY /maven/lib/policy-participant.tar.gz /packages
+
RUN tar xvfz /packages/policy-participant.tar.gz --directory $POLICY_HOME && \
- rm /packages/policy-participant.tar.gz && \
- rm -rf $POLICY_HOME/lib
+ rm /packages/policy-participant.tar.gz
WORKDIR $POLICY_HOME
COPY policy-participant.sh bin/.
COPY /maven/app.jar /app
-RUN chown -R policy:policy * && chmod 755 bin/*.sh && \
+RUN chown -R policy:policy * && \
+ chmod 755 bin/*.sh && \
chown -R policy:policy /app
USER policy
diff --git a/packages/policy-clamp-docker/src/main/docker/controlloop-runtime.sh b/packages/policy-clamp-docker/src/main/docker/controlloop-runtime.sh
index 8d64fa5a4..6d12e590a 100644
--- a/packages/policy-clamp-docker/src/main/docker/controlloop-runtime.sh
+++ b/packages/policy-clamp-docker/src/main/docker/controlloop-runtime.sh
@@ -32,7 +32,7 @@ else
fi
if [ -z "$CONFIG_FILE" ]; then
- CONFIG_FILE="${POLICY_HOME}/etc/ClRuntimeParameters.json"
+ CONFIG_FILE="${POLICY_HOME}/etc/ClRuntimeParameters.yaml"
fi
echo "Policy clamp config file: $CONFIG_FILE"
@@ -48,15 +48,17 @@ if [ -f "${POLICY_HOME}/etc/mounted/policy-keystore" ]; then
fi
if [ -f "${POLICY_HOME}/etc/mounted/logback.xml" ]; then
- echo "overriding logback.xml"
- cp -f "${POLICY_HOME}"/etc/mounted/logback.xml "${POLICY_HOME}"/etc/
+ echo "overriding logback xml files"
+ cp -f "${POLICY_HOME}"/etc/mounted/logback*.xml "${POLICY_HOME}"/etc/
fi
-$JAVA_HOME/bin/java -cp "${POLICY_HOME}/etc:${POLICY_HOME}/lib/*" \
- -Dlogback.configurationFile="${POLICY_HOME}/etc/logback.xml" \
- -Djavax.net.ssl.keyStore="${KEYSTORE}" \
+touch /app/app.jar
+mkdir -p "${POLICY_HOME}"/config/
+cp -f "${CONFIG_FILE}" "${POLICY_HOME}"/config/ClRuntimeParameters.yaml
+
+$JAVA_HOME/bin/java -Djavax.net.ssl.keyStore="${KEYSTORE}" \
-Djavax.net.ssl.keyStorePassword="${KEYSTORE_PASSWD}" \
-Djavax.net.ssl.trustStore="${TRUSTSTORE}" \
-Djavax.net.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \
- org.onap.policy.clamp.controlloop.runtime.main.startstop.Main \
- -c "${CONFIG_FILE}"
+ -jar /app/app.jar \
+ --spring.config.location="${POLICY_HOME}/config/ClRuntimeParameters.yaml"
diff --git a/packages/policy-clamp-docker/src/main/docker/dcae-participant.sh b/packages/policy-clamp-docker/src/main/docker/dcae-participant.sh
index 4acb17b39..620fa42cd 100644
--- a/packages/policy-clamp-docker/src/main/docker/dcae-participant.sh
+++ b/packages/policy-clamp-docker/src/main/docker/dcae-participant.sh
@@ -32,7 +32,7 @@ else
fi
if [ -z "$CONFIG_FILE" ]; then
- CONFIG_FILE="${POLICY_HOME}/etc/DcaeParticipantParameters.json"
+ CONFIG_FILE="${POLICY_HOME}/etc/DcaeParticipantParameters.yaml"
fi
echo "Policy clamp config file: $CONFIG_FILE"
@@ -54,11 +54,11 @@ fi
touch /app/app.jar
mkdir -p "${POLICY_HOME}"/config/
-cp -f "${CONFIG_FILE}" "${POLICY_HOME}"/config/
+cp -f "${CONFIG_FILE}" "${POLICY_HOME}"/config/DcaeParticipantParameters.yaml
$JAVA_HOME/bin/java -Djavax.net.ssl.keyStore="${KEYSTORE}" \
-Djavax.net.ssl.keyStorePassword="${KEYSTORE_PASSWD}" \
-Djavax.net.ssl.trustStore="${TRUSTSTORE}" \
-Djavax.net.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \
-jar /app/app.jar \
- --participant.file="${POLICY_HOME}/config/DcaeParticipantParameters.json"
+ --spring.config.location="${POLICY_HOME}/config/DcaeParticipantParameters.yaml"
diff --git a/packages/policy-clamp-docker/src/main/docker/kubernetes-participant.sh b/packages/policy-clamp-docker/src/main/docker/kubernetes-participant.sh
index 50995de3b..cb5ae9251 100644
--- a/packages/policy-clamp-docker/src/main/docker/kubernetes-participant.sh
+++ b/packages/policy-clamp-docker/src/main/docker/kubernetes-participant.sh
@@ -25,7 +25,17 @@ TRUSTSTORE="${TRUSTSTORE:-$POLICY_HOME/etc/ssl/policy-truststore}"
KEYSTORE_PASSWD="${KEYSTORE_PASSWD:-Pol1cy_0nap}"
TRUSTSTORE_PASSWD="${TRUSTSTORE_PASSWD:-Pol1cy_0nap}"
+if [ "$#" -eq 1 ]; then
+ CONFIG_FILE=$1
+else
+ CONFIG_FILE=${CONFIG_FILE}
+fi
+
+if [ -z "$CONFIG_FILE" ]; then
+ CONFIG_FILE="${POLICY_HOME}/etc/KubernetesParticipantParameters.yaml"
+fi
+echo "Policy clamp config file: $CONFIG_FILE"
if [ -f "${POLICY_HOME}/etc/mounted/policy-truststore" ]; then
echo "overriding policy-truststore"
@@ -42,8 +52,12 @@ if [ -f "${POLICY_HOME}/etc/mounted/logback.xml" ]; then
cp -f "${POLICY_HOME}"/etc/mounted/logback*.xml "${POLICY_HOME}"/etc/
fi
+mkdir -p "${POLICY_HOME}"/config/
+cp -f "${CONFIG_FILE}" "${POLICY_HOME}"/config/KubernetesParticipantParameters.yaml
+
$JAVA_HOME/bin/java -Dserver.ssl.keyStore="${KEYSTORE}" \
-Dserver.ssl.keyStorePassword="${KEYSTORE_PASSWD}" \
-Dserver.ssl.trustStore="${TRUSTSTORE}" \
-Dserver.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \
- -jar /app/app.jar
+ -jar /app/app.jar \
+ --spring.config.location="${POLICY_HOME}/config/KubernetesParticipantParameters.yaml"
diff --git a/packages/policy-clamp-docker/src/main/docker/policy-participant.sh b/packages/policy-clamp-docker/src/main/docker/policy-participant.sh
index 2e7a7d54b..7949fab72 100644
--- a/packages/policy-clamp-docker/src/main/docker/policy-participant.sh
+++ b/packages/policy-clamp-docker/src/main/docker/policy-participant.sh
@@ -32,7 +32,7 @@ else
fi
if [ -z "$CONFIG_FILE" ]; then
- CONFIG_FILE="${POLICY_HOME}/etc/PolicyParticipantParameters.json"
+ CONFIG_FILE="${POLICY_HOME}/etc/PolicyParticipantParameters.yaml"
fi
echo "Policy clamp config file: $CONFIG_FILE"
@@ -54,11 +54,11 @@ fi
touch /app/app.jar
mkdir -p "${POLICY_HOME}"/config/
-cp -f "${CONFIG_FILE}" "${POLICY_HOME}"/config/
+cp -f "${CONFIG_FILE}" "${POLICY_HOME}"/config/PolicyParticipantParameters.yaml
$JAVA_HOME/bin/java -Djavax.net.ssl.keyStore="${KEYSTORE}" \
-Djavax.net.ssl.keyStorePassword="${KEYSTORE_PASSWD}" \
-Djavax.net.ssl.trustStore="${TRUSTSTORE}" \
-Djavax.net.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \
-jar /app/app.jar \
- --participant.file="${POLICY_HOME}/config/PolicyParticipantParameters.json"
+ --spring.config.location="${POLICY_HOME}/config/PolicyParticipantParameters.yaml"
diff --git a/packages/policy-clamp-tarball/src/main/package/tarball/assembly.xml b/packages/policy-clamp-tarball/src/main/package/tarball/assembly.xml
index 6e8cd454a..598c0cb3d 100644
--- a/packages/policy-clamp-tarball/src/main/package/tarball/assembly.xml
+++ b/packages/policy-clamp-tarball/src/main/package/tarball/assembly.xml
@@ -24,24 +24,13 @@
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
- <dependencySets>
- <dependencySet>
- <useProjectArtifact>true</useProjectArtifact>
- <outputDirectory>${file.separator}lib</outputDirectory>
- <unpack>false</unpack>
- <scope>runtime</scope>
- <includes>
- <include>*:jar</include>
- </includes>
- </dependencySet>
- </dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/etc
</directory>
<includes>
- <include>*.json</include>
<include>*.xml</include>
+ <include>*.yaml</include>
</includes>
<outputDirectory>${file.separator}etc</outputDirectory>
<lineEnding>unix</lineEnding>
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.json b/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.json
deleted file mode 100644
index a6a3ff0f8..000000000
--- a/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "name": "ControlLoopRuntimeGroup",
- "restServerParameters": {
- "host": "0.0.0.0",
- "port": 6969,
- "userName": "healthcheck",
- "password": "zb!XztG34",
- "https": false,
- "aaf": false
- },
- "participantParameters": {
- "heartBeatMs": 120000,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.mariadb.jdbc.Driver",
- "databaseUrl": "jdbc:mariadb://mariadb:3306/controlloop",
- "databaseUser": "policy",
- "databasePassword": "P01icY",
- "persistenceUnit": "CommissioningMariaDb"
- },
- "topicParameterGroup": {
- "topicSources": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [ "message-router" ],
- "topicCommInfrastructure": "dmaap",
- "fetchTimeout": 15000
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [ "message-router" ],
- "topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [ "message-router" ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
-}
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml
new file mode 100644
index 000000000..3970d15f1
--- /dev/null
+++ b/packages/policy-clamp-tarball/src/main/resources/etc/ClRuntimeParameters.yaml
@@ -0,0 +1,54 @@
+spring:
+ security:
+ user:
+ name: healthcheck
+ password: zb!XztG34
+ http:
+ converters:
+ preferred-json-mapper: gson
+
+security:
+ enable-csrf: false
+
+server:
+ port: 6969
+ servlet:
+ context-path: /onap/controlloop
+ error:
+ path: /error
+
+
+runtime:
+ supervisionScannerIntervalSec: 1000
+ participantClUpdateIntervalSec: 1000
+ participantClStateChangeIntervalSec: 1000
+ participantParameters:
+ heartBeatMs: 120000
+ updateParameters:
+ maxRetryCount: 1
+ maxWaitMs: 30000
+ stateChangeParameters:
+ maxRetryCount: 1
+ maxWaitMs: 30000
+ databaseProviderParameters:
+ name: PolicyProviderParameterGroup
+ implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
+ databaseDriver: org.mariadb.jdbc.Driver
+ databaseUrl: jdbc:mariadb://${mariadb.host:mariadb}:${mariadb.port:3306}/controlloop
+ databaseUser: policy
+ databasePassword: P01icY
+ persistenceUnit: CommissioningMariaDb
+ topicParameterGroup:
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.json b/packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.json
deleted file mode 100644
index f3ff62325..000000000
--- a/packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.json
+++ /dev/null
@@ -1,70 +0,0 @@
-{
- "name": "ControlLoopParticipantDcae",
- "clampClientParameters": {
- "clientName": "Clamp",
- "hostname": "0.0.0.0",
- "port": 8443,
- "userName": "admin",
- "password": "password",
- "useHttps": true,
- "allowSelfSignedCerts": false
- },
- "consulClientParameters": {
- "clientName": "Consul",
- "hostname": "consul",
- "port": 31321,
- "userName": "admin",
- "password": "password",
- "useHttps": false
- },
- "intermediaryParameters": {
- "name": "Participant parameters",
- "reportingTimeInterval": 120000,
- "description": "Participant Description",
- "participantId": {
- "name": "DCAEParticipant0",
- "version": "1.0.0"
- },
- "participantType": {
- "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
- "version": "2.3.4"
- },
- "clampControlLoopTopics": {
- "topicSources": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap",
- "fetchTimeout": 15000
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.mariadb.jdbc.Driver",
- "databaseUrl": "jdbc:mariadb://mariadb:3306/policyadmin",
- "databaseUser": "policy_user",
- "databasePassword": "policy_user",
- "persistenceUnit": "PolicyMariaDb"
- }
-}
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.yaml
new file mode 100644
index 000000000..5eedb9db4
--- /dev/null
+++ b/packages/policy-clamp-tarball/src/main/resources/etc/DcaeParticipantParameters.yaml
@@ -0,0 +1,55 @@
+
+participant:
+ name: ControlLoopParticipantDcae
+ clampClientEndPoints:
+ status: /restservices/clds/v2/loop/getstatus/
+ create: /restservices/clds/v2/loop/create/%s?templateName=%s
+ deploy: /restservices/clds/v2/loop/deploy/
+ stop: /restservices/clds/v2/loop/stop/
+ delete: /restservices/clds/v2/loop/delete/
+ undeploy: /restservices/clds/v2/loop/undeploy/
+ clampClientParameters:
+ clientName: Clamp
+ hostname: 0.0.0.0
+ port: 8443
+ userName: admin
+ password: password
+ https: true
+ aaf: false
+ consulClientEndPoints:
+ deploy: "/v1/kv/dcae-pmsh:"
+ consulClientParameters:
+ clientName: Consul
+ hostname: consul
+ port: 31321
+ userName: admin
+ password: password
+ https: false
+ aaf: false
+ intermediaryParameters:
+ name: Participant parameters
+ reportingTimeIntervalMs: 120000
+ description: Participant Description
+ participantId:
+ name: DCAEParticipant0
+ version: 1.0.0
+ participantType:
+ name: org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant
+ version: 2.3.4
+ clampControlLoopTopics:
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+ checkCount: 10
+ secCount: 10
+ jsonBodyConsulPath: src/main/resources/parameters/consul.json
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml
new file mode 100644
index 000000000..d91cc7394
--- /dev/null
+++ b/packages/policy-clamp-tarball/src/main/resources/etc/KubernetesParticipantParameters.yaml
@@ -0,0 +1,54 @@
+spring:
+ security:
+ user:
+ name: healthcheck
+ password: zb!XztG34
+security:
+ enable-csrf: false
+
+participant:
+ localChartDirectory: /var/helm-manager/local-charts
+ infoFileName: CHART_INFO.json
+ intermediaryParameters:
+ reportingTimeIntervalMs: 120000
+ description: Participant Description
+ participantId:
+ name: K8sParticipant0
+ version: 1.0.0
+ participantType:
+ name: org.onap.k8s.controlloop.K8SControlLoopParticipant
+ version: 2.3.4
+ clampControlLoopTopics:
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+
+management:
+ endpoints:
+ web:
+ exposure:
+ include: "loggers,logfile,health,info,metrics,threaddump,heapdump"
+server:
+ # Configuration of the HTTP/REST server. The parameters are defined and handled by the springboot framework.
+ # See springboot documentation.
+ port: 8083
+
+logging:
+ # Configuration of logging
+ level:
+ ROOT: INFO
+ org.springframework: ERROR
+ org.springframework.data: ERROR
+ org.springframework.web.reactive.function.client.ExchangeFunctions: ERROR
+ file:
+ name: /var/log/helm-manager/application.log
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.json b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.json
deleted file mode 100644
index e2eb067d9..000000000
--- a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.json
+++ /dev/null
@@ -1,76 +0,0 @@
-{
- "name":"ParticipantParameterGroup",
- "participantStatusParameters":{
- "timeIntervalMs":10000,
- "description":"Participant Status",
- "participantId":{
- "name": "PolicyParticipant0",
- "version":"1.0.0"
- },
- "participantType":{
- "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
- "version":"2.3.1"
- },
- "participantDefinition":{
- "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
- "version":"2.3.1"
- }
- },
- "intermediaryParameters": {
- "name": "Participant parameters",
- "reportingTimeInterval": 120000,
- "description": "Participant Description",
- "participantId": {
- "name": "PolicyParticipant0",
- "version": "1.0.0"
- },
- "participantType": {
- "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
- "version": "2.3.1"
- },
- "clampControlLoopTopics": {
- "topicSources": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap",
- "fetchTimeout": 15000
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.mariadb.jdbc.Driver",
- "databaseUrl": "jdbc:mariadb://mariadb:3306/policyadmin",
- "databaseUser": "policy_user",
- "databasePassword": "policy_user",
- "persistenceUnit": "PolicyMariaDb"
- }
-}
diff --git a/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml
new file mode 100644
index 000000000..1ea5d68c0
--- /dev/null
+++ b/packages/policy-clamp-tarball/src/main/resources/etc/PolicyParticipantParameters.yaml
@@ -0,0 +1,33 @@
+
+participant:
+ policyApiParameters:
+ clientName: api
+ hostname: policy-api
+ port: 6969
+ userName: healthcheck
+ password: zb!XztG34
+ https: true
+ allowSelfSignedCerts: true
+ intermediaryParameters:
+ reportingTimeIntervalMs: 120000
+ description: Participant Description
+ participantId:
+ name: org.onap.PM_Policy
+ version: 1.0.0
+ participantType:
+ name: org.onap.policy.controlloop.PolicyControlLoopParticipant
+ version: 2.3.1
+ clampControlLoopTopics:
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-dcae/src/main/resources/config/application.yaml
index 44ba5b3e8..a873f76b3 100644
--- a/participant/participant-impl/participant-impl-dcae/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-dcae/src/main/resources/config/application.yaml
@@ -1,3 +1,5 @@
+server:
+ port: 8081
participant:
name: ControlLoopParticipantDcae
@@ -28,7 +30,7 @@ participant:
aaf: false
intermediaryParameters:
name: Participant parameters
- reportingTimeInterval: 120000
+ reportingTimeIntervalMs: 120000
description: Participant Description
participantId:
name: DCAEParticipant0
@@ -37,15 +39,19 @@ participant:
name: org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant
version: 2.3.4
clampControlLoopTopics:
- topicSources[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
- fetchTimeout: 15000
- topicSinks[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
checkCount: 10
secCount: 10
jsonBodyConsulPath: src/main/resources/parameters/consul.json
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/ParticipantDcaeTest.java
index 3f5e42542..a3fcfdd9e 100644
--- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java
+++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/ParticipantDcaeTest.java
@@ -32,8 +32,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockserver.integration.ClientAndServer;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData;
import org.onap.policy.clamp.controlloop.participant.dcae.main.rest.TestListenerUtils;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
@@ -50,7 +50,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = {"classpath:application_test.properties"})
-class PartecipantDcaeTest {
+class ParticipantDcaeTest {
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
@@ -103,74 +103,74 @@ class PartecipantDcaeTest {
}
@Test
- void testParticipantControlLoopStateChangeMessageListener() {
- ParticipantControlLoopStateChange participantControlLoopStateChangeMsg =
+ void testControlLoopStateChangeMessageListener() {
+ ControlLoopStateChange controlLoopStateChangeMsg =
TestListenerUtils.createControlLoopStateChangeMsg(ControlLoopOrderedState.UNINITIALISED);
- participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ controlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.PASSIVE);
ControlLoopStateChangeListener clStateChangeListener = new ControlLoopStateChangeListener(participantHandler);
- clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg);
- assertEquals(ControlLoopOrderedState.PASSIVE, participantControlLoopStateChangeMsg.getOrderedState());
+ clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, controlLoopStateChangeMsg);
+ assertEquals(ControlLoopOrderedState.PASSIVE, controlLoopStateChangeMsg.getOrderedState());
- participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.RUNNING);
- clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg);
- assertEquals(ControlLoopOrderedState.RUNNING, participantControlLoopStateChangeMsg.getOrderedState());
+ controlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.RUNNING);
+ clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, controlLoopStateChangeMsg);
+ assertEquals(ControlLoopOrderedState.RUNNING, controlLoopStateChangeMsg.getOrderedState());
- participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.RUNNING);
- clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg);
- assertEquals(ControlLoopOrderedState.RUNNING, participantControlLoopStateChangeMsg.getOrderedState());
+ controlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.RUNNING);
+ clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, controlLoopStateChangeMsg);
+ assertEquals(ControlLoopOrderedState.RUNNING, controlLoopStateChangeMsg.getOrderedState());
}
@Test
void testControlLoopUpdateListener_ParticipantIdNoMatch() throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getParticipantId().setName("DummyName");
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getParticipantId().setName("DummyName");
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
// Verify the content in participantHandler
- assertNotEquals(participantControlLoopUpdateMsg.getParticipantId().getName(),
+ assertNotEquals(controlLoopUpdateMsg.getParticipantId().getName(),
participantHandler.getParticipantId().getName());
}
@Test
void testControlLoopUpdateListenerPassive() throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
// Verify the content in participantHandler
- assertEquals(participantHandler.getParticipantId(), participantControlLoopUpdateMsg.getParticipantId());
+ assertEquals(participantHandler.getParticipantId(), controlLoopUpdateMsg.getParticipantId());
assertEquals(1, participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList().size());
}
@Test
void testControlLoopUpdateListenerUninitialised() throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED);
ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
// Verify the content in participantHandler
- assertEquals(participantHandler.getParticipantId(), participantControlLoopUpdateMsg.getParticipantId());
+ assertEquals(participantHandler.getParticipantId(), controlLoopUpdateMsg.getParticipantId());
assertEquals(1, participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList().size());
}
@Test
void testControlLoopUpdateListenerString() throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED);
-
- assertThat(participantControlLoopUpdateMsg.toString()).contains("state=UNINITIALISED");
- ParticipantControlLoopUpdate copyParticipantControlLoopUpdateMsg =
- TestListenerUtils.createCopyControlLoopUpdateMsg(participantControlLoopUpdateMsg);
- assertThat(copyParticipantControlLoopUpdateMsg.toString()).contains("state=UNINITIALISED");
- assertNotEquals(participantControlLoopUpdateMsg, copyParticipantControlLoopUpdateMsg);
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ assertThat(controlLoopUpdateMsg.toString()).contains("state=UNINITIALISED");
+ ControlLoopUpdate copyControlLoopUpdateMsg =
+ TestListenerUtils.createCopyControlLoopUpdateMsg(controlLoopUpdateMsg);
+ assertThat(copyControlLoopUpdateMsg.toString()).contains("state=UNINITIALISED");
+ assertNotEquals(controlLoopUpdateMsg, copyControlLoopUpdateMsg);
}
}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java
index 4b6dcd619..a28a6ece1 100644
--- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java
@@ -172,7 +172,7 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
if (!isEmpty) {
map.put("name", "Participant parameters");
- map.put("reportingTimeInterval", TIME_INTERVAL);
+ map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("description", DESCRIPTION);
map.put("participantId", getParticipantId());
map.put("participantType", getParticipantId());
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
index 4579b52bf..136d0e500 100644
--- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
@@ -30,10 +30,8 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
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.ParticipantState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
+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.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -88,35 +86,15 @@ public class TestListenerUtils {
}
/**
- * Method to create ParticipantStateChange message from the arguments passed.
- *
- * @param participantState participant State
- *
- * @return ParticipantStateChange message
- */
- public static ParticipantStateChange createParticipantStateChangeMsg(final ParticipantState participantState) {
- final ParticipantStateChange participantStateChangeMsg = new ParticipantStateChange();
- ToscaConceptIdentifier participantId = new ToscaConceptIdentifier();
- participantId.setName("DCAEParticipant0");
- participantId.setVersion("1.0.0");
-
- participantStateChangeMsg.setParticipantId(participantId);
- participantStateChangeMsg.setTimestamp(Instant.now());
- participantStateChangeMsg.setState(participantState);
-
- return participantStateChangeMsg;
- }
-
- /**
* Method to create ControlLoopStateChange message from the arguments passed.
*
* @param controlLoopOrderedState controlLoopOrderedState
*
- * @return ParticipantControlLoopStateChange message
+ * @return ControlLoopStateChange message
*/
- public static ParticipantControlLoopStateChange createControlLoopStateChangeMsg(
+ public static ControlLoopStateChange createControlLoopStateChangeMsg(
final ControlLoopOrderedState controlLoopOrderedState) {
- final ParticipantControlLoopStateChange participantClStateChangeMsg = new ParticipantControlLoopStateChange();
+ final ControlLoopStateChange clStateChangeMsg = new ControlLoopStateChange();
ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
controlLoopId.setName("PMSHInstance0");
@@ -126,21 +104,21 @@ public class TestListenerUtils {
participantId.setName("DCAEParticipant0");
participantId.setVersion("1.0.0");
- participantClStateChangeMsg.setControlLoopId(controlLoopId);
- participantClStateChangeMsg.setParticipantId(participantId);
- participantClStateChangeMsg.setTimestamp(Instant.now());
- participantClStateChangeMsg.setOrderedState(controlLoopOrderedState);
+ clStateChangeMsg.setControlLoopId(controlLoopId);
+ clStateChangeMsg.setParticipantId(participantId);
+ clStateChangeMsg.setTimestamp(Instant.now());
+ clStateChangeMsg.setOrderedState(controlLoopOrderedState);
- return participantClStateChangeMsg;
+ return clStateChangeMsg;
}
/**
* Method to create ControlLoopUpdateMsg.
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
*/
- public static ParticipantControlLoopUpdate createControlLoopUpdateMsg() {
- final ParticipantControlLoopUpdate clUpdateMsg = new ParticipantControlLoopUpdate();
+ public static ControlLoopUpdate createControlLoopUpdateMsg() {
+ final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
controlLoopId.setName("PMSHInstance0");
controlLoopId.setVersion("1.0.0");
@@ -177,7 +155,6 @@ public class TestListenerUtils {
controlLoop.setVersion("1.0.0");
controlLoop.setDefinition(controlLoopId);
clUpdateMsg.setControlLoop(controlLoop);
- clUpdateMsg.setControlLoopDefinition(toscaServiceTemplate);
return clUpdateMsg;
}
@@ -185,48 +162,25 @@ public class TestListenerUtils {
/**
* Method to create a deep copy of ControlLoopUpdateMsg.
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
*/
- public static ParticipantControlLoopUpdate createCopyControlLoopUpdateMsg(ParticipantControlLoopUpdate cpy) {
- return new ParticipantControlLoopUpdate(cpy);
- }
-
- /**
- * Method to create ParticipantHealthCheck message.
- *
- * @return ParticipantHealthCheck message
- */
- public static ParticipantHealthCheck createParticipantHealthCheckMsg() {
- ToscaConceptIdentifier participantId = new ToscaConceptIdentifier();
- participantId.setName("DCAEParticipant0");
- participantId.setVersion("1.0.0");
-
- ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
- controlLoopId.setName("PMSHInstance0");
- controlLoopId.setVersion("1.0.0");
-
- final ParticipantHealthCheck participantHealthCheckMsg = new ParticipantHealthCheck();
- participantHealthCheckMsg.setParticipantId(participantId);
- participantHealthCheckMsg.setControlLoopId(controlLoopId);
- participantHealthCheckMsg.setTimestamp(Instant.now());
- participantHealthCheckMsg.setState(ParticipantState.PASSIVE);
-
- return participantHealthCheckMsg;
+ public static ControlLoopUpdate createCopyControlLoopUpdateMsg(ControlLoopUpdate cpy) {
+ return new ControlLoopUpdate(cpy);
}
/**
- * Method to create ParticipantControlLoopUpdate using the arguments passed.
+ * Method to create ControlLoopUpdate using the arguments passed.
*
* @param jsonFilePath the path of the controlloop content
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
* @throws CoderException exception while reading the file to object
*/
- public static ParticipantControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
+ public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
- CODER.decode(new File(jsonFilePath), ParticipantControlLoopUpdate.class);
- return participantControlLoopUpdateMsg;
+ ControlLoopUpdate controlLoopUpdateMsg =
+ CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
+ return controlLoopUpdateMsg;
}
private static ToscaServiceTemplate testControlLoopRead() {
diff --git a/participant/participant-impl/participant-impl-http/pom.xml b/participant/participant-impl/participant-impl-http/pom.xml
new file mode 100644
index 000000000..85d65e707
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/pom.xml
@@ -0,0 +1,50 @@
+<!--
+ ============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=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.policy.clamp.participant</groupId>
+ <artifactId>policy-clamp-participant-impl</artifactId>
+ <version>6.1.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>policy-clamp-participant-impl-http</artifactId>
+ <name>${project.artifactId}</name>
+ <description>HTTP participant, that performs CRUD operations on Microservices through REST</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStateChangePublisher.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/Application.java
index b63cbdf03..dc36392f7 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStateChangePublisher.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/Application.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * 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.
@@ -18,15 +18,23 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
+package org.onap.policy.clamp.controlloop.participant.http;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
-import org.springframework.stereotype.Component;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
- * This class is used to send ParticipantStateChange messages to participants on DMaaP.
+ * Starter.
+ *
*/
-@Component
-public class ParticipantStateChangePublisher extends AbstractParticipantPublisher<ParticipantStateChange> {
-
+@SpringBootApplication
+public class Application {
+ /**
+ * Main class.
+ *
+ * @param args args
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/config/ParticipantConfig.java
new file mode 100644
index 000000000..ce013a765
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/config/ParticipantConfig.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.http.config;
+
+import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ParticipantConfig {
+
+ /**
+ * 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/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/PropertiesConfig.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/exception/HttpWebClientException.java
index 04bd35da3..b10af884c 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/config/PropertiesConfig.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/exception/HttpWebClientException.java
@@ -18,21 +18,14 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.controlloop.runtime.config;
+package org.onap.policy.clamp.controlloop.participant.http.main.exception;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
-import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterHandler;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-@Configuration
-public class PropertiesConfig {
+import org.springframework.web.reactive.function.client.WebClientResponseException;
- @Bean
- public ClRuntimeParameterGroup clRuntimeParameterGroup(@Value("${runtime.file}") String file)
- throws ControlLoopException {
- return new ClRuntimeParameterHandler().getParameters(file);
+public class HttpWebClientException extends WebClientResponseException {
+
+ public HttpWebClientException(int statusCode, String statusText) {
+ super(statusCode, statusText, null, null, null);
}
}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
new file mode 100644
index 000000000..67948a95c
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
@@ -0,0 +1,148 @@
+/*-
+ * ============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.http.main.handler;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.lang3.tuple.Pair;
+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.participant.http.main.models.ConfigRequest;
+import org.onap.policy.clamp.controlloop.participant.http.main.webclient.ClHttpClient;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
+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.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+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, Closeable {
+
+ private static final Coder CODER = new StandardCoder();
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+
+ private Map<ToscaConceptIdentifier, Pair<Integer, String>> restResponseMap = new ConcurrentHashMap<>();
+
+ @Setter
+ private ParticipantIntermediaryApi intermediaryApi;
+
+ /**
+ * Handle controlLoopElement statistics.
+ *
+ * @param controlLoopElementId controlloop element id
+ */
+ @Override
+ public void handleStatistics(UUID controlLoopElementId) throws PfModelException {
+ // Implementation not needed for http participant
+
+ }
+
+ /**
+ * 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 a model exception
+ */
+ @Override
+ public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
+ ControlLoopOrderedState newState) throws PfModelException {
+ // Implementation not needed for http participant
+ }
+
+ /**
+ * Callback method to handle an update on a control loop element.
+ *
+ * @param element the information on the control loop element
+ * @param controlLoopDefinition toscaServiceTemplate
+ */
+ @Override
+ public void controlLoopElementUpdate(ControlLoopElement element, ToscaServiceTemplate controlLoopDefinition) {
+
+ for (Map.Entry<String, ToscaNodeTemplate> nodeTemplate : controlLoopDefinition.getToscaTopologyTemplate()
+ .getNodeTemplates().entrySet()) {
+ // Fetching the node template of corresponding CL element
+ if (element.getDefinition().getName().equals(nodeTemplate.getKey())) {
+ try {
+ var configRequest = CODER.convert(nodeTemplate.getValue().getProperties(), ConfigRequest.class);
+ Set<ConstraintViolation<ConfigRequest>> violations = Validation.buildDefaultValidatorFactory()
+ .getValidator().validate(configRequest);
+ if (violations.isEmpty()) {
+ invokeHttpClient(configRequest);
+ } else {
+ LOGGER.error("Violations found in the config request parameters: {}", violations);
+ throw new ValidationException("Constraint violations in the config request");
+ }
+ } catch (CoderException | ValidationException e) {
+ LOGGER.error("Error invoking the http request for the config ", e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Invoke a runnable thread to execute http requests.
+ * @param configRequest ConfigRequest
+ */
+ public void invokeHttpClient(ConfigRequest configRequest) {
+ // Invoke runnable thread to execute https requests of all config entities
+ executor.execute(new ClHttpClient(configRequest, restResponseMap));
+ }
+
+ /**
+ * Closes this stream and releases any system resources associated
+ * with it. If the stream is already closed then invoking this
+ * method has no effect.
+ *
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ public void close() throws IOException {
+ executor.shutdown();
+ }
+}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigRequest.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigRequest.java
new file mode 100644
index 000000000..87cab88a7
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigRequest.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.http.main.models;
+
+import java.util.List;
+import java.util.Map;
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.DefaultValue;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class ConfigRequest {
+
+ @NotBlank
+ private String baseUrl;
+
+ @NotNull
+ private Map<String, String> httpHeaders;
+
+ @NotNull
+ @Valid
+ private List<ConfigurationEntity> configurationEntities;
+
+ @Min(value = 1)
+ @DefaultValue("20")
+ private int uninitializedToPassiveTimeout;
+
+}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigurationEntity.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigurationEntity.java
new file mode 100644
index 000000000..8703a9d21
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/ConfigurationEntity.java
@@ -0,0 +1,40 @@
+/*-
+ * ============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.http.main.models;
+
+import java.util.List;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+@Data
+@AllArgsConstructor
+public class ConfigurationEntity {
+
+ @NotNull
+ private ToscaConceptIdentifier configurationEntityId;
+
+ @NotNull
+ @Valid
+ private List<RestParams> restSequence;
+}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/RestParams.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/RestParams.java
new file mode 100644
index 000000000..fc4e02897
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/models/RestParams.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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.http.main.models;
+
+import java.util.Map;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+@Data
+@AllArgsConstructor
+public class RestParams {
+
+ @NotNull
+ private ToscaConceptIdentifier restRequestId;
+
+ @NotNull
+ private String httpMethod;
+
+ @NotNull
+ private String path;
+
+ @Min(100)
+ @Max(599)
+ private int expectedResponse;
+
+ private Map<String, Object> pathParams;
+
+ private Map<String, String> queryParams;
+
+ private String body;
+
+}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/webclient/ClHttpClient.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/webclient/ClHttpClient.java
new file mode 100644
index 000000000..0e0ea557e
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/webclient/ClHttpClient.java
@@ -0,0 +1,135 @@
+/*-
+ * ============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.http.main.webclient;
+
+import java.lang.invoke.MethodHandles;
+import java.time.Duration;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.clamp.controlloop.participant.http.main.exception.HttpWebClientException;
+import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigRequest;
+import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigurationEntity;
+import org.onap.policy.clamp.controlloop.participant.http.main.models.RestParams;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.web.reactive.function.BodyInserters;
+import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.util.UriComponentsBuilder;
+import reactor.core.publisher.Mono;
+
+public class ClHttpClient implements Runnable {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private final ConfigRequest configRequest;
+
+ private Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap;
+
+ /**
+ * Constructor.
+ */
+ public ClHttpClient(ConfigRequest configRequest, Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap) {
+ this.configRequest = configRequest;
+ this.responseMap = responseMap;
+ }
+
+ /**
+ * Runnable to execute http requests.
+ */
+ @Override
+ public void run() {
+
+ var webClient = WebClient.builder()
+ .baseUrl(configRequest.getBaseUrl())
+ .defaultHeaders(httpHeaders -> httpHeaders.addAll(createHeaders(configRequest)))
+ .build();
+
+ for (ConfigurationEntity configurationEntity : configRequest.getConfigurationEntities()) {
+ LOGGER.info("Executing http requests for the config entity {}",
+ configurationEntity.getConfigurationEntityId());
+
+ executeRequest(webClient, configurationEntity);
+ }
+ }
+
+ private void executeRequest(WebClient client, ConfigurationEntity configurationEntity) {
+
+ // Iterate the sequence of http requests
+ for (RestParams request: configurationEntity.getRestSequence()) {
+ String response = null;
+ try {
+ var httpMethod = Objects.requireNonNull(HttpMethod.resolve(request.getHttpMethod()));
+ var uri = createUriString(request);
+ LOGGER.info("Executing HTTP request: {} for the Rest request id: {}", httpMethod,
+ request.getRestRequestId());
+
+ response = client.method(httpMethod)
+ .uri(uri)
+ .body(request.getBody() == null ? BodyInserters.empty()
+ : BodyInserters.fromValue(request.getBody()))
+ .exchangeToMono(clientResponse ->
+ clientResponse.statusCode().value() == request.getExpectedResponse()
+ ? clientResponse.bodyToMono(String.class)
+ : Mono.error(new HttpWebClientException(clientResponse.statusCode().value(),
+ clientResponse.bodyToMono(String.class).toString())))
+ .block(Duration.ofMillis(configRequest.getUninitializedToPassiveTimeout() * 1000L));
+
+ LOGGER.info("HTTP response for the {} request : {}", httpMethod, response);
+ responseMap.put(request.getRestRequestId(), new ImmutablePair<>(request.getExpectedResponse(),
+ response));
+
+ } catch (HttpWebClientException ex) {
+ LOGGER.error("Error occurred on the HTTP request ", ex);
+ responseMap.put(request.getRestRequestId(), new ImmutablePair<>(ex.getStatusCode().value(),
+ ex.getResponseBodyAsString()));
+ }
+ }
+ }
+
+ private HttpHeaders createHeaders(ConfigRequest request) {
+ var headers = new HttpHeaders();
+ for (Map.Entry<String, String> entry: request.getHttpHeaders().entrySet()) {
+ headers.add(entry.getKey(), entry.getValue());
+ }
+ return headers;
+ }
+
+ private String createUriString(RestParams restParams) {
+ var uriComponentsBuilder = UriComponentsBuilder.fromUriString(restParams.getPath());
+ // Add path params if present
+ if (restParams.getPathParams() != null) {
+ uriComponentsBuilder.uriVariables(restParams.getPathParams());
+ }
+ // Add query params if present
+ if (restParams.getQueryParams() != null) {
+ for (Map.Entry<String, String> entry : restParams.getQueryParams().entrySet()) {
+ uriComponentsBuilder.queryParam(entry.getKey(), entry.getValue());
+ }
+ }
+ return uriComponentsBuilder.build().toUriString();
+ }
+
+}
diff --git a/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml
new file mode 100644
index 000000000..1fd528458
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/main/resources/config/application.yaml
@@ -0,0 +1,27 @@
+participant:
+ intermediaryParameters:
+ reportingTimeInterval: 120000
+ description: Participant Description
+ participantId:
+ name: HttpParticipant0
+ version: 1.0.0
+ participantType:
+ name: org.onap.k8s.controlloop.HttpControlLoopParticipant
+ version: 2.3.4
+ clampControlLoopTopics:
+ topicSources:
+ - topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ - topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
+
+ - topic: POLICY-NOTIFICATION
+ servers:
+ - ${topicServer:message-router}
+ topicCommInfrastructure: dmaap
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java
new file mode 100644
index 000000000..10b8103cb
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java
@@ -0,0 +1,63 @@
+/*-
+ * ============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 handler;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import utils.CommonTestData;
+import utils.ToscaUtils;
+
+@ExtendWith(SpringExtension.class)
+class ClElementHandlerTest {
+
+ @InjectMocks
+ @Spy
+ private ControlLoopElementHandler controlLoopElementHandler = new ControlLoopElementHandler();
+
+ private CommonTestData commonTestData = new CommonTestData();
+
+ private static ToscaServiceTemplate serviceTemplate;
+
+ @BeforeAll
+ static void init() throws CoderException {
+ serviceTemplate = ToscaUtils.readControlLoopFromTosca();
+ }
+
+ @Test
+ void test_ControlLoopElementUpdate() {
+ doNothing().when(controlLoopElementHandler).invokeHttpClient(any());
+ ControlLoopElement element = commonTestData.getControlLoopElement();
+ assertDoesNotThrow(() -> controlLoopElementHandler
+ .controlLoopElementUpdate(element, serviceTemplate));
+ }
+}
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java b/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java
new file mode 100644
index 000000000..84957edfa
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/java/utils/CommonTestData.java
@@ -0,0 +1,146 @@
+/*-
+ * ============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 utils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+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.participant.http.main.models.ConfigurationEntity;
+import org.onap.policy.clamp.controlloop.participant.http.main.models.RestParams;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+public class CommonTestData {
+
+ private static final Coder CODER = new StandardCoder();
+ private static final String TEST_KEY_NAME = "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement";
+
+
+ /**
+ * Get a controlLoop Element.
+ * @return controlLoopElement object
+ */
+ public ControlLoopElement getControlLoopElement() {
+ ControlLoopElement element = new ControlLoopElement();
+ element.setId(UUID.randomUUID());
+ element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1"));
+ element.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ return element;
+ }
+
+ /**
+ * Get query params.
+ * @return Map of query params
+ */
+ public Map<String, String> getQueryParams() {
+ return Map.of("name", "dummy", "version", "1.0");
+ }
+
+ /**
+ * Get path params.
+ * @return Map of path params
+ */
+ public Map<String, Object> getPathParams() {
+ return Map.of("id", "123", "name", "dummy");
+ }
+
+ /**
+ * Rest params with GET request.
+ * @return RestParams obj
+ */
+ public RestParams restParamsWithGet() {
+ return new RestParams(
+ new ToscaConceptIdentifier("getRequest", "1.0"),
+ "GET",
+ "get",
+ 200,
+ null,
+ getQueryParams(),
+ null
+ );
+ }
+
+ /**
+ * Rest params with POST request.
+ * @return RestParams obj
+ */
+ public RestParams restParamsWithPost() {
+ return new RestParams(
+ new ToscaConceptIdentifier("postRequest", "1.0"),
+ "POST",
+ "post",
+ 200,
+ null,
+ getQueryParams(),
+ "Test body"
+ );
+ }
+
+ /**
+ * Rest params with POST request.
+ * @return RestParams obj
+ */
+ public RestParams restParamsWithInvalidPost() {
+ return new RestParams(
+ new ToscaConceptIdentifier("postRequest", "1.0"),
+ "POST",
+ "post/{id}/{name}",
+ 200,
+ getPathParams(),
+ getQueryParams(),
+ "Test body"
+ );
+ }
+
+ /**
+ * Get invalid configuration entity.
+ * @return ConfigurationEntity obj
+ */
+ public ConfigurationEntity getInvalidConfigurationEntity() {
+ return new ConfigurationEntity(
+ new ToscaConceptIdentifier("config1", "1.0.1"),
+ List.of(restParamsWithGet(), restParamsWithInvalidPost())
+ );
+ }
+
+ /**
+ * Get configuration entity.
+ * @return ConfigurationEntity obj
+ */
+ public ConfigurationEntity getConfigurationEntity() {
+ return new ConfigurationEntity(
+ new ToscaConceptIdentifier("config1", "1.0.1"),
+ List.of(restParamsWithGet(), restParamsWithPost())
+ );
+ }
+
+ /**
+ * Get headers for config request.
+ * @return Map of headers
+ */
+ public Map<String, String> getHeaders() {
+ return Map.of("Content-Type", "application/json", "Accept", "application/json");
+ }
+
+}
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
new file mode 100644
index 000000000..cf71248c3
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/java/utils/ToscaUtils.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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 utils;
+
+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;
+
+/**
+ * Util class for Test scope.
+ */
+public class ToscaUtils {
+
+ private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
+ private static final String TOSCA_TEMPLATE_YAML = "src/test/resources/HttpParticipantConfig.yaml";
+
+
+ /**
+ * Read a service template yaml.
+ * @return ToscaServiceTemplate
+ */
+ public static ToscaServiceTemplate readControlLoopFromTosca() {
+ return serializeControlLoopYaml(TOSCA_TEMPLATE_YAML);
+ }
+
+ private static ToscaServiceTemplate serializeControlLoopYaml(String controlLoopFilePath) {
+ String controlLoopString = ResourceUtils.getResourceAsString(controlLoopFilePath);
+ return yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class);
+ }
+}
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/webclient/ClHttpClientTest.java b/participant/participant-impl/participant-impl-http/src/test/java/webclient/ClHttpClientTest.java
new file mode 100644
index 000000000..411974a04
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/java/webclient/ClHttpClientTest.java
@@ -0,0 +1,85 @@
+/*-
+ * ============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 webclient;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigRequest;
+import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigurationEntity;
+import org.onap.policy.clamp.controlloop.participant.http.main.webclient.ClHttpClient;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import utils.CommonTestData;
+
+@ExtendWith(SpringExtension.class)
+class ClHttpClientTest {
+
+ private CommonTestData commonTestData = new CommonTestData();
+
+ private String testBaseUrl = "https://httpbin.org";
+
+ private Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap = new HashMap<>();
+
+
+ @Test
+ void test_validRequest() {
+ //Add valid rest requests POST, GET
+ ConfigurationEntity configurationEntity = commonTestData.getConfigurationEntity();
+
+ Map<String, String> headers = commonTestData.getHeaders();
+ ConfigRequest configRequest = new ConfigRequest(testBaseUrl, headers,
+ List.of(configurationEntity), 10);
+
+ ClHttpClient client = new ClHttpClient(configRequest, responseMap);
+ assertDoesNotThrow(client::run);
+ assertThat(responseMap).hasSize(2).containsKey(commonTestData
+ .restParamsWithGet().getRestRequestId());
+
+ Pair<Integer, String> restResponseMap = responseMap.get(commonTestData
+ .restParamsWithGet().getRestRequestId());
+ assertThat(restResponseMap.getKey()).isEqualTo(200);
+ }
+
+ @Test
+ void test_invalidRequest() {
+ //Add rest requests Invalid POST, Valid GET
+ ConfigurationEntity configurationEntity = commonTestData.getInvalidConfigurationEntity();
+
+ Map<String, String> headers = commonTestData.getHeaders();
+ ConfigRequest configRequest = new ConfigRequest(testBaseUrl, headers,
+ List.of(configurationEntity), 10);
+
+ ClHttpClient client = new ClHttpClient(configRequest, responseMap);
+ assertDoesNotThrow(client::run);
+ assertThat(responseMap).hasSize(2).containsKey(commonTestData
+ .restParamsWithGet().getRestRequestId());
+ Pair<Integer, String> response = responseMap
+ .get(commonTestData.restParamsWithInvalidPost().getRestRequestId());
+ assertThat(response.getKey()).isEqualTo(404);
+ }
+}
diff --git a/participant/participant-impl/participant-impl-http/src/test/resources/HttpParticipantConfig.yaml b/participant/participant-impl/participant-impl-http/src/test/resources/HttpParticipantConfig.yaml
new file mode 100644
index 000000000..43d0c269c
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/resources/HttpParticipantConfig.yaml
@@ -0,0 +1,208 @@
+# ============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=========================================================
+tosca_definitions_version: tosca_simple_yaml_1_3
+data_types:
+ onap.datatypes.ToscaConceptIdentifier:
+ derived_from: tosca.datatypes.Root
+ properties:
+ name:
+ type: string
+ required: true
+ version:
+ type: string
+ required: true
+
+ org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.RestRequest:
+ version: 1.0.0
+ derived_from: tosca.datatypes.Root
+ properties:
+ restRequestId:
+ type: onap.datatypes.ToscaConceptIdentifier
+ typeVersion: 1.0.0
+ required: true
+ description: The name and version of a REST request to be sent to a REST endpoint
+ httpMethod:
+ type: string
+ required: true
+ constraints:
+ - valid_values: [POST, PUT, GET, DELETE]
+ description: The REST method to use
+ path:
+ type: string
+ required: true
+ description: The path of the REST request relative to the base URL
+ body:
+ type: string
+ required: false
+ description: The body of the REST request for PUT and POST requests
+ expectedResponse:
+ type: integer
+ required: true
+ constraints:
+ - in_range: [100, 599]
+ description: THe expected HTTP status code for the REST request
+ org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.ConfigurationEntity:
+ version: 1.0.0
+ derived_from: tosca.datatypes.Root
+ properties:
+ configurationEntityId:
+ type: onap.datatypes.ToscaConceptIdentifier
+ typeVersion: 1.0.0
+ required: true
+ description: The name and version of a Configuration Entity to be handled by the HTTP Control Loop Element
+ restSequence:
+ type: list
+ entry_schema:
+ type: org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.RestRequest
+ typeVersion: 1.0.0
+ description: A sequence of REST commands to send to the REST endpoint
+
+
+node_types:
+ org.onap.policy.clamp.controlloop.Participant:
+ version: 1.0.1
+ derived_from: tosca.nodetypes.Root
+ properties:
+ provider:
+ type: string
+ requred: false
+ org.onap.policy.clamp.controlloop.ControlLoopElement:
+ version: 1.0.1
+ derived_from: tosca.nodetypes.Root
+ properties:
+ provider:
+ type: string
+ requred: false
+ participant_id:
+ type: onap.datatypes.ToscaConceptIdentifier
+ requred: true
+ org.onap.policy.clamp.controlloop.ControlLoop:
+ version: 1.0.1
+ derived_from: tosca.nodetypes.Root
+ properties:
+ provider:
+ type: string
+ requred: false
+ elements:
+ type: list
+ required: true
+ entry_schema:
+ type: onap.datatypes.ToscaConceptIdentifier
+ org.onap.policy.clamp.controlloop.HttpControlLoopElement:
+ version: 1.0.1
+ derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement
+ properties:
+ baseUrl:
+ type: string
+ required: true
+ description: The base URL to be prepended to each path, identifies the host for the REST endpoints.
+ httpHeaders:
+ type: map
+ required: false
+ entry_schema:
+ type: string
+ description: HTTP headers to send on REST requests
+ configurationEntities:
+ type: map
+ required: true
+ entry_schema:
+ type: org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.ConfigurationEntity
+ typeVersion: 1.0.0
+ description: The connfiguration entities the Control Loop Element is managing and their associated REST requests
+topology_template:
+ node_templates:
+ org.onap.k8s.controlloop.HttpControlLoopParticipant:
+ version: 2.3.4
+ type: org.onap.policy.clamp.controlloop.Participant
+ type_version: 1.0.1
+ description: Participant for Http requests
+ properties:
+ provider: ONAP
+
+ org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement:
+ # Http config for PMSH.
+ version: 1.2.3
+ type: org.onap.policy.clamp.controlloop.HttpControlLoopElement
+ type_version: 1.0.1
+ description: Control loop element for the http requests of PMSH microservice
+ properties:
+ provider: ONAP
+ participant_id:
+ name: org.onap.controlloop.HttpControlLoopParticipant
+ version: 2.3.4
+ uninitializedToPassiveTimeout: 180
+ baseUrl: https://httpbin.org
+ httpHeaders:
+ Content-Type: application/json
+ configurationEntities:
+ - configurationEntityId:
+ name: entity1
+ version: 1.0.1
+ restSequence:
+ - restRequestId:
+ name: request1
+ version: 1.0.1
+ httpMethod: POST
+ path: post
+ body: '{"name":"ob1","port_type"}'
+ expectedResponse: 200
+
+ - restRequestId:
+ name: request1
+ version: 1.0.1
+ httpMethod: GET
+ path: get
+ expectedResponse: 200
+
+ # Rest path with path params and query params
+ - configurationEntityId:
+ name: entity2
+ version: 1.0.1
+ restSequence:
+ - restRequestId:
+ name: request1
+ version: 1.0.1
+ httpMethod: POST
+ path: post/{id}/{name}
+ pathParams:
+ id: 123
+ name: dummyName
+ body: this is a test body
+ expectedResponse: 200
+
+ - restRequestId:
+ name: request1
+ version: 1.0.1
+ httpMethod: GET
+ path: get
+ queryParams:
+ id: 123
+ name: dummyName
+ expectedResponse: 200
+
+
+ org.onap.domain.sample.GenericK8s_ControlLoopDefinition:
+ version: 1.2.3
+ type: org.onap.policy.clamp.controlloop.ControlLoop
+ type_version: 1.0.0
+ description: Control loop for HTTP request
+ properties:
+ provider: ONAP
+ elements:
+ - name: org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement
+ version: 1.2.3
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
index 9d3523737..a27c33d44 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
@@ -10,7 +10,7 @@ participant:
localChartDirectory: /var/helm-manager/local-charts
infoFileName: CHART_INFO.json
intermediaryParameters:
- reportingTimeInterval: 120000
+ reportingTimeIntervalMs: 120000
description: Participant Description
participantId:
name: K8sParticipant0
@@ -19,15 +19,19 @@ participant:
name: org.onap.k8s.controlloop.K8SControlLoopParticipant
version: 2.3.4
clampControlLoopTopics:
- topicSources[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
- fetchTimeout: 15000
- topicSinks[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
management:
endpoints:
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/parameters/CommonTestData.java
index d8d477d1b..9255ee6dc 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org.onap.policy.clamp.controlloop.participant.kubernetes/parameters/CommonTestData.java
@@ -99,7 +99,7 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
if (!isEmpty) {
map.put("name", "Participant parameters");
- map.put("reportingTimeInterval", TIME_INTERVAL);
+ map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("description", DESCRIPTION);
map.put("participantId", getParticipantId());
map.put("participantType", getParticipantId());
diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
index d4c7d7561..32cd28cd3 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
@@ -1,3 +1,5 @@
+server:
+ port: 8082
participant:
policyApiParameters:
@@ -9,7 +11,7 @@ participant:
https: true
allowSelfSignedCerts: true
intermediaryParameters:
- reportingTimeInterval: 120000
+ reportingTimeIntervalMs: 120000
description: Participant Description
participantId:
name: org.onap.PM_Policy
@@ -18,12 +20,16 @@ participant:
name: org.onap.policy.controlloop.PolicyControlLoopParticipant
version: 2.3.1
clampControlLoopTopics:
- topicSources[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
- fetchTimeout: 15000
- topicSinks[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantMessagesTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantMessagesTest.java
index 4b4558b89..aed03556a 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantMessagesTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantMessagesTest.java
@@ -20,16 +20,27 @@
package org.onap.policy.clamp.controlloop.participant.policy.endtoend;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
import java.time.Instant;
import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantDeregisterAckListener;
@@ -41,6 +52,7 @@ import org.onap.policy.clamp.controlloop.participant.policy.main.utils.TestListe
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -139,6 +151,26 @@ class ParticipantMessagesTest {
}
}
+ @Test
+ void testParticipantStatusHeartbeat() throws Exception {
+ final ParticipantStatus heartbeat = new ParticipantStatus();
+ heartbeat.setParticipantId(getParticipantId());
+ ControlLoopInfo clInfo = getControlLoopInfo(getControlLoopId());
+ heartbeat.setControlLoopInfoMap(Map.of(getControlLoopId(), clInfo));
+
+ ControlLoopElementDefinition clDefinition = getClElementDefinition();
+ Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
+ Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
+ participantDefinitionUpdateMap = Map.of(getParticipantId(), clElementDefinitionMap);
+ heartbeat.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
+
+ synchronized (lockit) {
+ ParticipantMessagePublisher publisher =
+ new ParticipantMessagePublisher(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ assertThatCode(() -> publisher.sendHeartbeat(heartbeat)).doesNotThrowAnyException();
+ }
+ }
+
private ToscaConceptIdentifier getParticipantId() {
return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
}
@@ -146,4 +178,47 @@ class ParticipantMessagesTest {
private ToscaConceptIdentifier getParticipantType() {
return new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
}
+
+ private ToscaConceptIdentifier getControlLoopId() {
+ return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ }
+
+ private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) {
+ ControlLoopInfo clInfo = new ControlLoopInfo();
+ clInfo.setState(ControlLoopState.PASSIVE2RUNNING);
+
+ ControlLoopStatistics clStatistics = new ControlLoopStatistics();
+ clStatistics.setControlLoopId(id);
+ clStatistics.setAverageExecutionTime(12345);
+ clStatistics.setEventCount(12345);
+ clStatistics.setLastEnterTime(12345);
+ clStatistics.setLastExecutionTime(12345);
+ clStatistics.setLastStart(12345);
+ clStatistics.setTimeStamp(Instant.ofEpochMilli(3000));
+ clStatistics.setUpTime(12345);
+ ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList();
+ ClElementStatistics clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1"));
+ clElementStatistics.setTimeStamp(Instant.now());
+ clElementStatisticsList.setClElementStatistics(List.of(clElementStatistics));
+ clStatistics.setClElementStatisticsList(clElementStatisticsList);
+
+ clInfo.setControlLoopStatistics(clStatistics);
+ return clInfo;
+ }
+
+ private ControlLoopElementDefinition getClElementDefinition() {
+ ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
+ toscaServiceTemplate.setName("serviceTemplate");
+ toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
+ toscaServiceTemplate.setDescription("Description of serviceTemplate");
+ toscaServiceTemplate.setVersion("1.2.3");
+
+ ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setId(UUID.randomUUID());
+ clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate);
+ Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+ clDefinition.setCommonPropertiesMap(commonPropertiesMap);
+ return clDefinition;
+ }
}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
index 45674f4c8..10563cde2 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
@@ -21,17 +21,14 @@
package org.onap.policy.clamp.controlloop.participant.policy.endtoend;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantUpdateListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.policy.main.utils.TestListenerUtils;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -55,16 +52,13 @@ class ParticipantPolicyTest {
@Test
void testUpdatePolicyTypes() {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
-
- // Verify that the ToscaServicetemplate has policy_types
- assertNotNull(participantControlLoopUpdateMsg.getControlLoopDefinition().getPolicyTypes());
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
synchronized (lockit) {
ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
}
// Verify the result of GET participants with what is stored
assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
@@ -72,20 +66,13 @@ class ParticipantPolicyTest {
@Test
void testUpdatePolicies() throws Exception {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
-
- // Add policies to the toscaServiceTemplate
- TestListenerUtils.addPoliciesToToscaServiceTemplate(participantControlLoopUpdateMsg.getControlLoopDefinition());
-
- // Verify that the ToscaServicetemplate has policies
- assertNotNull(
- participantControlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies());
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
synchronized (lockit) {
ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
}
// Verify the result of GET participants with what is stored
assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
@@ -93,29 +80,22 @@ class ParticipantPolicyTest {
@Test
void testDeletePoliciesAndPolicyTypes() throws Exception {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
-
- // Add policies to the toscaServiceTemplate
- TestListenerUtils.addPoliciesToToscaServiceTemplate(participantControlLoopUpdateMsg.getControlLoopDefinition());
-
- // Verify that the ToscaServicetemplate has policies
- assertNotNull(
- participantControlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies());
+ ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
synchronized (lockit) {
ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
}
// Verify the result of GET participants with what is stored
assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
ControlLoopStateChangeListener clStateChangeListener = new ControlLoopStateChangeListener(participantHandler);
- ParticipantControlLoopStateChange participantControlLoopStateChangeMsg =
+ ControlLoopStateChange controlLoopStateChangeMsg =
TestListenerUtils.createControlLoopStateChangeMsg(ControlLoopOrderedState.UNINITIALISED);
- participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
- clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg);
+ controlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, controlLoopStateChangeMsg);
// Verify the result of GET participants with what is stored
assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java
index 38861472c..a34c9cda5 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java
@@ -99,7 +99,7 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
if (!isEmpty) {
map.put("name", "Participant parameters");
- map.put("reportingTimeInterval", TIME_INTERVAL);
+ map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("description", DESCRIPTION);
map.put("participantId", getParticipantId());
map.put("participantType", getParticipantId());
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 d439c9daf..b91cff22c 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
@@ -35,10 +35,8 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
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.ParticipantState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
+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;
import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
@@ -100,35 +98,15 @@ public class TestListenerUtils {
}
/**
- * Method to create ParticipantStateChange message from the arguments passed.
- *
- * @param participantState participant State
- *
- * @return ParticipantStateChange message
- */
- public static ParticipantStateChange createParticipantStateChangeMsg(final ParticipantState participantState) {
- final ParticipantStateChange participantStateChangeMsg = new ParticipantStateChange();
- ToscaConceptIdentifier participantId = new ToscaConceptIdentifier();
- participantId.setName("org.onap.PM_Policy");
- participantId.setVersion("0.0.0");
-
- participantStateChangeMsg.setParticipantId(participantId);
- participantStateChangeMsg.setTimestamp(Instant.now());
- participantStateChangeMsg.setState(participantState);
-
- return participantStateChangeMsg;
- }
-
- /**
* Method to create ControlLoopStateChange message from the arguments passed.
*
* @param controlLoopOrderedState controlLoopOrderedState
*
- * @return ParticipantControlLoopStateChange message
+ * @return ControlLoopStateChange message
*/
- public static ParticipantControlLoopStateChange createControlLoopStateChangeMsg(
+ public static ControlLoopStateChange createControlLoopStateChangeMsg(
final ControlLoopOrderedState controlLoopOrderedState) {
- final ParticipantControlLoopStateChange participantClStateChangeMsg = new ParticipantControlLoopStateChange();
+ final ControlLoopStateChange clStateChangeMsg = new ControlLoopStateChange();
ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
controlLoopId.setName("PMSHInstance0");
@@ -138,21 +116,21 @@ public class TestListenerUtils {
participantId.setName("org.onap.PM_Policy");
participantId.setVersion("0.0.0");
- participantClStateChangeMsg.setControlLoopId(controlLoopId);
- participantClStateChangeMsg.setParticipantId(participantId);
- participantClStateChangeMsg.setTimestamp(Instant.now());
- participantClStateChangeMsg.setOrderedState(controlLoopOrderedState);
+ clStateChangeMsg.setControlLoopId(controlLoopId);
+ clStateChangeMsg.setParticipantId(participantId);
+ clStateChangeMsg.setTimestamp(Instant.now());
+ clStateChangeMsg.setOrderedState(controlLoopOrderedState);
- return participantClStateChangeMsg;
+ return clStateChangeMsg;
}
/**
* Method to create ControlLoopUpdateMsg.
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
*/
- public static ParticipantControlLoopUpdate createControlLoopUpdateMsg() {
- final ParticipantControlLoopUpdate clUpdateMsg = new ParticipantControlLoopUpdate();
+ public static ControlLoopUpdate createControlLoopUpdateMsg() {
+ final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
controlLoopId.setName("PMSHInstance0");
controlLoopId.setVersion("1.0.0");
@@ -177,6 +155,7 @@ public class TestListenerUtils {
clElementParticipantId.setName(toscaInputEntry.getKey());
clElementParticipantId.setVersion(toscaInputEntry.getValue().getVersion());
clElement.setParticipantId(clElementParticipantId);
+ clElement.setParticipantType(clElementParticipantId);
clElement.setDefinition(clElementParticipantId);
clElement.setState(ControlLoopState.UNINITIALISED);
@@ -189,7 +168,6 @@ public class TestListenerUtils {
controlLoop.setVersion("1.0.0");
controlLoop.setDefinition(controlLoopId);
clUpdateMsg.setControlLoop(controlLoop);
- clUpdateMsg.setControlLoopDefinition(toscaServiceTemplate);
return clUpdateMsg;
}
@@ -211,11 +189,9 @@ public class TestListenerUtils {
participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
participantUpdateMsg.setMessageId(UUID.randomUUID());
- ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
- toscaServiceTemplate.setName("serviceTemplate");
- toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
- toscaServiceTemplate.setDescription("Description of serviceTemplate");
- toscaServiceTemplate.setVersion("1.2.3");
+ ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead();
+ // Add policies to the toscaServiceTemplate
+ TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate);
ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
clDefinition.setId(UUID.randomUUID());
@@ -234,41 +210,18 @@ public class TestListenerUtils {
}
/**
- * Method to create ParticipantHealthCheck message.
- *
- * @return ParticipantHealthCheck message
- */
- public static ParticipantHealthCheck createParticipantHealthCheckMsg() {
- ToscaConceptIdentifier participantId = new ToscaConceptIdentifier();
- participantId.setName("org.onap.PM_Policy");
- participantId.setVersion("0.0.0");
-
- ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier();
- controlLoopId.setName("PMSHInstance0");
- controlLoopId.setVersion("1.0.0");
-
- final ParticipantHealthCheck participantHealthCheckMsg = new ParticipantHealthCheck();
- participantHealthCheckMsg.setParticipantId(participantId);
- participantHealthCheckMsg.setControlLoopId(controlLoopId);
- participantHealthCheckMsg.setTimestamp(Instant.now());
- participantHealthCheckMsg.setState(ParticipantState.PASSIVE);
-
- return participantHealthCheckMsg;
- }
-
- /**
- * Method to create ParticipantControlLoopUpdate using the arguments passed.
+ * Method to create ControlLoopUpdate using the arguments passed.
*
* @param jsonFilePath the path of the controlloop content
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
* @throws CoderException exception while reading the file to object
*/
- public static ParticipantControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
+ public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
- CODER.decode(new File(jsonFilePath), ParticipantControlLoopUpdate.class);
- return participantControlLoopUpdateMsg;
+ ControlLoopUpdate controlLoopUpdateMsg =
+ CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
+ return controlLoopUpdateMsg;
}
private static ToscaServiceTemplate testControlLoopRead() {
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 5a9cf1497..c26749b4d 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
@@ -5,7 +5,7 @@ spring:
password: zb!XztG34
server:
- port: 6969
+ port: 8084
servlet:
context-path: /onap/participantsim
error:
@@ -13,7 +13,7 @@ server:
participant:
intermediaryParameters:
- reportingTimeInterval: 120000
+ reportingTimeIntervalMs: 120000
description: Participant Description
participantId:
name: org.onap.PM_CDS_Blueprint
@@ -22,12 +22,16 @@ participant:
name: org.onap.PM_CDS_Blueprint
version: 1.0.0
clampControlLoopTopics:
- topicSources[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
- fetchTimeout: 15000
- topicSinks[0]:
- topic: POLICY-CLRUNTIME-PARTICIPANT
- servers[0]: ${topicServer:message-router}
- topicCommInfrastructure: dmaap
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
index 0b63c395a..beb50da37 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
@@ -36,7 +36,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
@@ -103,10 +103,10 @@ class ParticipantSimulatorTest {
ControlLoopUpdateListener clUpdateListener =
new ControlLoopUpdateListener(participantHandler);
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
+ ControlLoopUpdate controlLoopUpdateMsg =
TestListenerUtils.createControlLoopUpdateMsg();
- participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
- clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
+ controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
+ clUpdateListener.onTopicEvent(INFRA, TOPIC, null, controlLoopUpdateMsg);
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
index e85b3ebbe..9c41c8bcb 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
@@ -79,7 +79,7 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
if (!isEmpty) {
map.put("name", "Participant parameters");
- map.put("reportingTimeInterval", TIME_INTERVAL);
+ map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("description", DESCRIPTION);
map.put("participantId", getParticipantId());
map.put("participantType", getParticipantId());
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 8aa40cbd5..999feb1e1 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
@@ -34,9 +34,8 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
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.ParticipantState;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -98,52 +97,34 @@ public class TestListenerUtils {
}
/**
- * Method to create ParticipantStateChange message from the arguments passed.
- *
- * @param participantState participant State
- *
- * @return ParticipantStateChange message
- */
- public static ParticipantStateChange createParticipantStateChangeMsg(final ParticipantState participantState) {
- final ParticipantStateChange participantStateChangeMsg = new ParticipantStateChange();
- ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0");
-
- participantStateChangeMsg.setParticipantId(participantId);
- participantStateChangeMsg.setTimestamp(Instant.now());
- participantStateChangeMsg.setState(participantState);
-
- return participantStateChangeMsg;
- }
-
- /**
* Method to create ControlLoopStateChange message from the arguments passed.
*
* @param controlLoopOrderedState controlLoopOrderedState
*
- * @return ParticipantControlLoopStateChange message
+ * @return ControlLoopStateChange message
*/
- public static ParticipantControlLoopStateChange createControlLoopStateChangeMsg(
+ public static ControlLoopStateChange createControlLoopStateChangeMsg(
final ControlLoopOrderedState controlLoopOrderedState) {
- final ParticipantControlLoopStateChange participantClStateChangeMsg = new ParticipantControlLoopStateChange();
+ final ControlLoopStateChange clStateChangeMsg = new ControlLoopStateChange();
ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0");
- participantClStateChangeMsg.setControlLoopId(controlLoopId);
- participantClStateChangeMsg.setParticipantId(participantId);
- participantClStateChangeMsg.setTimestamp(Instant.now());
- participantClStateChangeMsg.setOrderedState(controlLoopOrderedState);
+ clStateChangeMsg.setControlLoopId(controlLoopId);
+ clStateChangeMsg.setParticipantId(participantId);
+ clStateChangeMsg.setTimestamp(Instant.now());
+ clStateChangeMsg.setOrderedState(controlLoopOrderedState);
- return participantClStateChangeMsg;
+ return clStateChangeMsg;
}
/**
* Method to create ControlLoopUpdateMsg.
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
*/
- public static ParticipantControlLoopUpdate createControlLoopUpdateMsg() {
- final ParticipantControlLoopUpdate clUpdateMsg = new ParticipantControlLoopUpdate();
+ public static ControlLoopUpdate createControlLoopUpdateMsg() {
+ final ControlLoopUpdate clUpdateMsg = new ControlLoopUpdate();
ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0");
@@ -177,24 +158,23 @@ public class TestListenerUtils {
controlLoop.setVersion("1.0.0");
controlLoop.setDefinition(controlLoopId);
clUpdateMsg.setControlLoop(controlLoop);
- clUpdateMsg.setControlLoopDefinition(toscaServiceTemplate);
return clUpdateMsg;
}
/**
- * Method to create ParticipantControlLoopUpdate using the arguments passed.
+ * Method to create ControlLoopUpdate using the arguments passed.
*
* @param jsonFilePath the path of the controlloop content
*
- * @return ParticipantControlLoopUpdate message
+ * @return ControlLoopUpdate message
* @throws CoderException exception while reading the file to object
*/
- public static ParticipantControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
+ public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
throws CoderException {
- ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
- CODER.decode(new File(jsonFilePath), ParticipantControlLoopUpdate.class);
- return participantControlLoopUpdateMsg;
+ ControlLoopUpdate controlLoopUpdateMsg =
+ CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
+ return controlLoopUpdateMsg;
}
private static ToscaServiceTemplate testControlLoopRead() {
diff --git a/participant/participant-impl/pom.xml b/participant/participant-impl/pom.xml
index f1f4f0eb9..439bdea90 100644
--- a/participant/participant-impl/pom.xml
+++ b/participant/participant-impl/pom.xml
@@ -40,6 +40,7 @@
<module>participant-impl-policy</module>
<module>participant-impl-cds</module>
<module>participant-impl-kubernetes</module>
+ <module>participant-impl-http</module>
</modules>
<dependencies>
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java
index e46c6db1b..0b9110bd0 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.springframework.stereotype.Component;
@@ -28,7 +28,7 @@ import org.springframework.stereotype.Component;
* Listener for Participant State Change messages sent by CLAMP.
*/
@Component
-public class ControlLoopStateChangeListener extends ParticipantListener<ParticipantControlLoopStateChange> {
+public class ControlLoopStateChangeListener extends ParticipantListener<ControlLoopStateChange> {
/**
* Constructs the object.
@@ -36,7 +36,7 @@ public class ControlLoopStateChangeListener extends ParticipantListener<Particip
* @param participantHandler the handler for managing the state of the participant
*/
public ControlLoopStateChangeListener(final ParticipantHandler participantHandler) {
- super(ParticipantControlLoopStateChange.class, participantHandler,
+ super(ControlLoopStateChange.class, participantHandler,
participantHandler::handleControlLoopStateChange);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java
index d15643e0f..56bc1fd9a 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java
@@ -20,7 +20,7 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.springframework.stereotype.Component;
@@ -28,7 +28,7 @@ import org.springframework.stereotype.Component;
* Listener for Control Loop Update messages sent by CLAMP.
*/
@Component
-public class ControlLoopUpdateListener extends ParticipantListener<ParticipantControlLoopUpdate> {
+public class ControlLoopUpdateListener extends ParticipantListener<ControlLoopUpdate> {
/**
* Constructs the object.
@@ -36,6 +36,6 @@ public class ControlLoopUpdateListener extends ParticipantListener<ParticipantCo
* @param participantHandler the handler for managing the state of the participant
*/
public ControlLoopUpdateListener(final ParticipantHandler participantHandler) {
- super(ParticipantControlLoopUpdate.class, participantHandler, participantHandler::handleControlLoopUpdate);
+ super(ControlLoopUpdate.class, participantHandler, participantHandler::handleControlLoopUpdate);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java
index 1bfce1374..3ff420ffa 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java
@@ -22,7 +22,10 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
import java.io.Closeable;
import java.time.Instant;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.TimerTask;
+import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -30,9 +33,9 @@ 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.ControlLoops;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
@@ -67,18 +70,13 @@ public class MessageSender extends TimerTask implements Closeable {
// Kick off the timer
timerPool = makeTimerPool();
- timerPool.scheduleAtFixedRate(this, 0, interval, TimeUnit.SECONDS);
+ timerPool.scheduleAtFixedRate(this, 0, interval, TimeUnit.MILLISECONDS);
}
@Override
public void run() {
LOGGER.debug("Sent heartbeat to CLAMP");
-
- var response = new ParticipantResponseDetails();
-
- response.setResponseTo(null);
- response.setResponseStatus(ParticipantResponseStatus.PERIODIC);
- response.setResponseMessage("Periodic response from participant");
+ this.sendHeartbeat();
}
@Override
@@ -89,48 +87,23 @@ public class MessageSender extends TimerTask implements Closeable {
/**
* Send a response message for this participant.
*
- * @param response the details to include in the response message
+ * @param ackMessage the details to include in the response message
*/
- public void sendResponse(ParticipantResponseDetails response) {
- sendResponse(null, response);
+ public void sendAckResponse(ControlLoopAck ackMessage) {
+ sendAckResponse(null, ackMessage);
}
/**
* Dispatch a response message for this participant.
*
* @param controlLoopId the control loop to which this message is a response
- * @param response the details to include in the response message
+ * @param ackMessage the details to include in the response message
*/
- public void sendResponse(ToscaConceptIdentifier controlLoopId, ParticipantResponseDetails response) {
- var status = new ParticipantStatus();
-
+ public void sendAckResponse(ToscaConceptIdentifier controlLoopId, ControlLoopAck ackMessage) {
// Participant related fields
- status.setParticipantType(participantHandler.getParticipantType());
- status.setParticipantId(participantHandler.getParticipantId());
- status.setState(participantHandler.getState());
- status.setHealthStatus(participantHandler.getHealthStatus());
-
- // Control loop related fields
- var controlLoops = participantHandler.getControlLoopHandler().getControlLoops();
- status.setControlLoopId(controlLoopId);
- status.setControlLoops(controlLoops);
- status.setResponse(response);
-
- var participantStatistics = new ParticipantStatistics();
- participantStatistics.setTimeStamp(Instant.now());
- participantStatistics.setParticipantId(participantHandler.getParticipantId());
- participantStatistics.setHealthStatus(participantHandler.getHealthStatus());
- participantStatistics.setState(participantHandler.getState());
- status.setParticipantStatistics(participantStatistics);
-
- for (ControlLoopElementListener clElementListener :
- participantHandler.getControlLoopHandler().getListeners()) {
- updateClElementStatistics(controlLoops, clElementListener);
- }
-
- status.setControlLoops(controlLoops);
-
- publisher.sendParticipantStatus(status);
+ ackMessage.setParticipantType(participantHandler.getParticipantType());
+ ackMessage.setParticipantId(participantHandler.getParticipantId());
+ publisher.sendControlLoopAck(ackMessage);
}
/**
@@ -161,6 +134,28 @@ public class MessageSender extends TimerTask implements Closeable {
}
/**
+ * Send a ParticipantStatus message for this participant.
+ *
+ * @param participantStatus the ParticipantStatus message
+ */
+ public void sendParticipantStatus(ParticipantStatus participantStatus) {
+ var controlLoops = participantHandler.getControlLoopHandler().getControlLoops();
+ for (ControlLoopElementListener clElementListener :
+ participantHandler.getControlLoopHandler().getListeners()) {
+ updateClElementStatistics(controlLoops, clElementListener);
+ }
+
+ publisher.sendParticipantStatus(participantStatus);
+ }
+
+ /**
+ * Dispatch a heartbeat for this participant.
+ */
+ public void sendHeartbeat() {
+ publisher.sendHeartbeat(participantHandler.makeHeartbeat());
+ }
+
+ /**
* Update ControlLoopElement statistics. The control loop elements listening will be
* notified to retrieve statistics from respective controlloop elements, and controlloopelements
* data on the handler will be updated.
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java
index 9e1b84620..d8cc9eb6b 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantMessagePublisher.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
import java.util.List;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
@@ -90,4 +91,24 @@ public class ParticipantMessagePublisher {
topicSinkClient.send(participantUpdateAck);
LOGGER.debug("Sent Participant Update Ack message to CLAMP - {}", participantUpdateAck);
}
+
+ /**
+ * Method to send ControlLoop Update/StateChange Ack message to runtime.
+ *
+ * @param controlLoopAck ControlLoop Update/StateChange Ack
+ */
+ public void sendControlLoopAck(final ControlLoopAck controlLoopAck) {
+ topicSinkClient.send(controlLoopAck);
+ LOGGER.debug("Sent ControlLoop Update/StateChange Ack to runtime - {}", controlLoopAck);
+ }
+
+ /**
+ * Method to send Participant heartbeat to clamp on demand.
+ *
+ * @param participantStatus the Participant Status
+ */
+ public void sendHeartbeat(final ParticipantStatus participantStatus) {
+ topicSinkClient.send(participantStatus);
+ LOGGER.debug("Sent Participant heartbeat to CLAMP - {}", participantStatus);
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusReqListener.java
index 15f5140eb..0881edb19 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusReqListener.java
@@ -20,22 +20,22 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatusReq;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.springframework.stereotype.Component;
/**
- * Listener for Participant health status messages sent by CLAMP.
+ * Listener for Participant status request messages sent by runtime to all/one participant.
*/
@Component
-public class ParticipantHealthCheckListener extends ParticipantListener<ParticipantHealthCheck> {
+public class ParticipantStatusReqListener extends ParticipantListener<ParticipantStatusReq> {
/**
* Constructs the object.
*
* @param participantHandler the handler for managing the state and health of the participant
*/
- public ParticipantHealthCheckListener(final ParticipantHandler participantHandler) {
- super(ParticipantHealthCheck.class, participantHandler, participantHandler::handleParticipantHealthCheck);
+ public ParticipantStatusReqListener(final ParticipantHandler participantHandler) {
+ super(ParticipantStatusReq.class, participantHandler, participantHandler::handleParticipantStatusReq);
}
}
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 50048ffc2..876a4cc52 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,16 +28,18 @@ import java.util.UUID;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
+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.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSender;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
@@ -59,6 +61,7 @@ public class ControlLoopHandler {
private final Map<ToscaConceptIdentifier, ControlLoop> controlLoopMap = new LinkedHashMap<>();
+ @Getter
private final Map<UUID, ControlLoopElement> elementsOnThisParticipant = new LinkedHashMap<>();
@Getter
@@ -92,21 +95,23 @@ public class ControlLoopHandler {
ControlLoopState newState) {
if (id == null) {
- return null;
+ LOGGER.warn("Cannot update Control loop element state, id is null");
}
+ ControlLoopAck controlLoopStateChangeAck =
+ new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
ControlLoopElement clElement = elementsOnThisParticipant.get(id);
if (clElement != null) {
clElement.setOrderedState(orderedState);
clElement.setState(newState);
+ controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(),
+ Pair.of(true, "Control loop element {} state changed to {}\", id, newState)"));
LOGGER.debug("Control loop element {} state changed to {}", id, newState);
- var response = new ParticipantResponseDetails();
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage("ControlLoopElement state changed to {} " + newState);
- messageSender.sendResponse(response);
+ controlLoopStateChangeAck.setMessage("ControlLoopElement state changed to {} " + newState);
+ controlLoopStateChangeAck.setResult(true);
+ messageSender.sendAckResponse(controlLoopStateChangeAck);
return clElement;
}
-
return null;
}
@@ -130,7 +135,7 @@ public class ControlLoopHandler {
*
* @param stateChangeMsg the state change message
*/
- public void handleControlLoopStateChange(ParticipantControlLoopStateChange stateChangeMsg) {
+ public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg) {
if (stateChangeMsg.getControlLoopId() == null) {
return;
}
@@ -142,9 +147,11 @@ public class ControlLoopHandler {
return;
}
- var response = new ParticipantResponseDetails(stateChangeMsg);
- handleState(controlLoop, response, stateChangeMsg.getOrderedState());
- messageSender.sendResponse(response);
+ var controlLoopStateChangeAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
+ controlLoopStateChangeAck.setResponseTo(stateChangeMsg.getMessageId());
+ controlLoopStateChangeAck.setControlLoopId(stateChangeMsg.getControlLoopId());
+ handleState(controlLoop, controlLoopStateChangeAck, stateChangeMsg.getOrderedState());
+ messageSender.sendAckResponse(controlLoopStateChangeAck);
}
/**
@@ -154,7 +161,7 @@ public class ControlLoopHandler {
* @param response participant response
* @param orderedState controlloop ordered state
*/
- private void handleState(final ControlLoop controlLoop, final ParticipantResponseDetails response,
+ private void handleState(final ControlLoop controlLoop, final ControlLoopAck response,
ControlLoopOrderedState orderedState) {
switch (orderedState) {
case UNINITIALISED:
@@ -177,7 +184,8 @@ public class ControlLoopHandler {
*
* @param updateMsg the update message
*/
- public void handleControlLoopUpdate(ParticipantControlLoopUpdate updateMsg) {
+ public void handleControlLoopUpdate(ControlLoopUpdate updateMsg,
+ Map<UUID, ControlLoopElementDefinition> clElementDefinitions) {
if (!updateMsg.appliesTo(participantType, participantId)) {
return;
@@ -185,16 +193,17 @@ public class ControlLoopHandler {
var controlLoop = controlLoopMap.get(updateMsg.getControlLoopId());
- var response = new ParticipantResponseDetails(updateMsg);
+ var controlLoopUpdateAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_UPDATE_ACK);
// TODO: Updates to existing ControlLoops are not supported yet (Addition/Removal of ControlLoop
// elements to existing ControlLoop has to be supported).
if (controlLoop != null) {
- response.setResponseStatus(ParticipantResponseStatus.FAIL);
- response.setResponseMessage("Control loop " + updateMsg.getControlLoopId()
- + " already defined on participant " + participantId);
-
- messageSender.sendResponse(response);
+ controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
+ controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
+ controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId()
+ + " already defined on participant " + participantId);
+ controlLoopUpdateAck.setResult(false);
+ messageSender.sendAckResponse(controlLoopUpdateAck);
return;
}
@@ -211,18 +220,20 @@ public class ControlLoopHandler {
for (ControlLoopElementListener clElementListener : listeners) {
try {
for (ControlLoopElement element : updateMsg.getControlLoop().getElements().values()) {
- clElementListener.controlLoopElementUpdate(element, updateMsg.getControlLoopDefinition());
+ clElementListener.controlLoopElementUpdate(element,
+ clElementDefinitions.get(element.getId()).getControlLoopElementToscaServiceTemplate());
}
} catch (PfModelException e) {
LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId());
}
}
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage(
- "Control loop " + updateMsg.getControlLoopId() + " defined on participant " + participantId);
-
- messageSender.sendResponse(response);
+ controlLoopUpdateAck.setResponseTo(updateMsg.getMessageId());
+ controlLoopUpdateAck.setControlLoopId(updateMsg.getControlLoopId());
+ controlLoopUpdateAck.setMessage("Control loop " + updateMsg.getControlLoopId()
+ + " defined on participant " + participantId);
+ controlLoopUpdateAck.setResult(true);
+ messageSender.sendAckResponse(controlLoopUpdateAck);
}
/**
@@ -233,7 +244,7 @@ public class ControlLoopHandler {
* @param response participant response
*/
private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- final ParticipantResponseDetails response) {
+ final ControlLoopAck response) {
handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED, response);
controlLoopMap.remove(controlLoop.getKey().asIdentifier());
@@ -256,7 +267,7 @@ public class ControlLoopHandler {
* @param response participant response
*/
private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- final ParticipantResponseDetails response) {
+ final ControlLoopAck response) {
handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE, response);
}
@@ -268,7 +279,7 @@ public class ControlLoopHandler {
* @param response participant response
*/
private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- final ParticipantResponseDetails response) {
+ final ControlLoopAck response) {
handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING, response);
}
@@ -281,11 +292,11 @@ public class ControlLoopHandler {
* @param response the response to the state change request
*/
private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
- ControlLoopState newState, ParticipantResponseDetails response) {
+ ControlLoopState newState, ControlLoopAck response) {
if (orderedState.equals(controlLoop.getOrderedState())) {
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage("Control loop is already in state " + orderedState);
+ response.setMessage("Control loop is already in state " + orderedState);
+ response.setResult(false);
return;
}
@@ -296,9 +307,8 @@ public class ControlLoopHandler {
});
}
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage(
- "ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState);
+ response.setMessage("ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState);
+ response.setResult(true);
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 0aa536746..4fc0ae1b1 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
@@ -28,9 +28,8 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.api.Participan
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantDeregisterAckListener;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantHealthCheckListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantRegisterAckListener;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStateChangeListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStatusReqListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantUpdateListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
@@ -120,16 +119,13 @@ public class IntermediaryActivator extends ServiceManagerContainer implements Cl
private void registerMsgDispatcher() {
MessageTypeDispatcher msgDispatcher = applicationContext.getBean(MessageTypeDispatcher.class);
- msgDispatcher.register(ParticipantMessageType.PARTICIPANT_STATE_CHANGE.name(),
- applicationContext.getBean(ParticipantStateChangeListener.class));
+ msgDispatcher.register(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(),
+ applicationContext.getBean(ParticipantStatusReqListener.class));
- msgDispatcher.register(ParticipantMessageType.PARTICIPANT_HEALTH_CHECK.name(),
- applicationContext.getBean(ParticipantHealthCheckListener.class));
-
- msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_STATE_CHANGE.name(),
+ msgDispatcher.register(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE.name(),
applicationContext.getBean(ControlLoopStateChangeListener.class));
- msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_UPDATE.name(),
+ msgDispatcher.register(ParticipantMessageType.CONTROL_LOOP_UPDATE.name(),
applicationContext.getBean(ControlLoopUpdateListener.class));
msgDispatcher.register(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(),
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 a8913c1f0..6a0e758dd 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
@@ -32,17 +32,18 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
+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.ParticipantDeregister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatusReq;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSender;
@@ -85,7 +86,8 @@ public class ParticipantHandler implements Closeable {
this.participantType = parameters.getIntermediaryParameters().getParticipantType();
this.participantId = parameters.getIntermediaryParameters().getParticipantId();
this.sender =
- new MessageSender(this, publisher, parameters.getIntermediaryParameters().getReportingTimeInterval());
+ new MessageSender(this, publisher,
+ parameters.getIntermediaryParameters().getReportingTimeIntervalMs());
this.controlLoopHandler = new ControlLoopHandler(parameters.getIntermediaryParameters(), sender);
this.participantStatistics = new ParticipantStatistics();
}
@@ -96,56 +98,17 @@ public class ParticipantHandler implements Closeable {
}
/**
- * Method which handles a participant state change event from clamp.
- *
- * @param stateChangeMsg participant state change message
- */
- public void handleParticipantStateChange(final ParticipantStateChange stateChangeMsg) {
-
- if (!stateChangeMsg.appliesTo(participantType, participantId)) {
- return;
- }
-
- var response = new ParticipantResponseDetails(stateChangeMsg);
-
- switch (stateChangeMsg.getState()) {
- case PASSIVE:
- handlePassiveState(response);
- break;
- case ACTIVE:
- handleActiveState(response);
- break;
- case SAFE:
- handleSafeState(response);
- break;
- case TEST:
- handleTestState(response);
- break;
- case TERMINATED:
- handleTerminatedState(response);
- break;
- default:
- LOGGER.debug("StateChange message has no state, state is null {}", stateChangeMsg.getParticipantId());
- response.setResponseStatus(ParticipantResponseStatus.FAIL);
- response.setResponseMessage(
- "StateChange message has invalid state for participantId " + stateChangeMsg.getParticipantId());
- break;
- }
-
- sender.sendResponse(response);
- }
-
- /**
* Method which handles a participant health check event from clamp.
*
- * @param healthCheckMsg participant health check message
+ * @param participantStatusReqMsg participant participantStatusReq message
*/
- public void handleParticipantHealthCheck(final ParticipantHealthCheck healthCheckMsg) {
- var response = new ParticipantResponseDetails(healthCheckMsg);
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage(healthStatus.toString());
-
- sender.sendResponse(response);
+ public void handleParticipantStatusReq(final ParticipantStatusReq participantStatusReqMsg) {
+ ParticipantStatus participantStatus = new ParticipantStatus();
+ participantStatus.setParticipantId(participantId);
+ participantStatus.setParticipantStatistics(participantStatistics);
+ participantStatus.setParticipantType(participantType);
+ participantStatus.setHealthStatus(healthStatus);
+ sender.sendParticipantStatus(participantStatus);
}
/**
@@ -153,8 +116,8 @@ public class ParticipantHandler implements Closeable {
*
* @param updateMsg the update message
*/
- public void handleControlLoopUpdate(ParticipantControlLoopUpdate updateMsg) {
- controlLoopHandler.handleControlLoopUpdate(updateMsg);
+ public void handleControlLoopUpdate(ControlLoopUpdate updateMsg) {
+ controlLoopHandler.handleControlLoopUpdate(updateMsg, clElementDefsOnThisParticipant);
}
/**
@@ -162,62 +125,17 @@ public class ParticipantHandler implements Closeable {
*
* @param stateChangeMsg the state change message
*/
- public void handleControlLoopStateChange(ParticipantControlLoopStateChange stateChangeMsg) {
+ public void handleControlLoopStateChange(ControlLoopStateChange stateChangeMsg) {
controlLoopHandler.handleControlLoopStateChange(stateChangeMsg);
}
- /**
- * Method to handle when the new state from participant is active.
- *
- * @param response participant response
- */
- private void handleActiveState(final ParticipantResponseDetails response) {
- handleStateChange(ParticipantState.ACTIVE, response);
- }
-
- /**
- * Method to handle when the new state from participant is passive.
- *
- * @param response participant response
- */
- private void handlePassiveState(final ParticipantResponseDetails response) {
- handleStateChange(ParticipantState.PASSIVE, response);
- }
-
- /**
- * Method to handle when the new state from participant is safe.
- *
- * @param response participant response
- */
- private void handleSafeState(final ParticipantResponseDetails response) {
- handleStateChange(ParticipantState.SAFE, response);
- }
-
- /**
- * Method to handle when the new state from participant is TEST.
- *
- * @param response participant response
- */
- private void handleTestState(final ParticipantResponseDetails response) {
- handleStateChange(ParticipantState.TEST, response);
- }
-
- /**
- * Method to handle when the new state from participant is Terminated.
- *
- * @param response participant response
- */
- private void handleTerminatedState(final ParticipantResponseDetails response) {
- handleStateChange(ParticipantState.TERMINATED, response);
- }
-
- private void handleStateChange(ParticipantState newParticipantState, ParticipantResponseDetails response) {
+ private void handleStateChange(ParticipantState newParticipantState, ParticipantUpdateAck response) {
if (state.equals(newParticipantState)) {
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage("Participant already in state " + newParticipantState);
+ response.setResult(false);
+ response.setMessage("Participant already in state " + newParticipantState);
} else {
- response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
- response.setResponseMessage("Participant state changed from " + state + " to " + newParticipantState);
+ response.setResult(true);
+ response.setMessage("Participant state changed from " + state + " to " + newParticipantState);
state = newParticipantState;
}
}
@@ -234,9 +152,10 @@ public class ParticipantHandler implements Closeable {
LOGGER.debug("No participant with this ID {}", definition.getName());
return null;
}
- var response = new ParticipantResponseDetails();
- handleStateChange(participantState, response);
- sender.sendResponse(response);
+
+ var participantUpdateAck = new ParticipantUpdateAck();
+ handleStateChange(participantState, participantUpdateAck);
+ sender.sendParticipantUpdateAck(participantUpdateAck);
return getParticipant(definition.getName(), definition.getVersion());
}
@@ -341,7 +260,21 @@ public class ParticipantHandler implements Closeable {
participantUpdateAck.setResponseTo(messageId);
participantUpdateAck.setMessage("Participant Update Ack message");
participantUpdateAck.setResult(true);
+ participantUpdateAck.setParticipantId(participantId);
+ participantUpdateAck.setParticipantType(participantType);
sender.sendParticipantUpdateAck(participantUpdateAck);
}
+
+ /**
+ * Method to send heartbeat to controlloop runtime.
+ */
+ public ParticipantStatus makeHeartbeat() {
+ ParticipantStatus heartbeat = new ParticipantStatus();
+ heartbeat.setParticipantId(participantId);
+ heartbeat.setParticipantStatistics(participantStatistics);
+ heartbeat.setParticipantType(participantType);
+ heartbeat.setHealthStatus(healthStatus);
+ return heartbeat;
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java
index 5627abfe6..fdc451e6b 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.parameters;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Positive;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
@@ -50,7 +51,9 @@ public class ParticipantIntermediaryParameters {
private ToscaConceptIdentifier participantType;
// The time interval for periodic reporting of status to the CLAMP control loop server
- private long reportingTimeInterval;
+ @Valid
+ @Positive
+ private long reportingTimeIntervalMs;
@NotNull
@ParameterGroupConstraint
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
index 93ba15846..9353cde81 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
@@ -68,7 +68,7 @@ public class CommonTestData {
map.put("participantId", getParticipantId());
map.put("description", DESCRIPTION);
map.put("participantType", getParticipantId());
- map.put("reportingTimeInterval", TIME_INTERVAL);
+ map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("clampControlLoopTopics", getTopicParametersMap(false));
return map;
diff --git a/pom.xml b/pom.xml
index fdaeb13d9..61af7c48e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -201,5 +201,9 @@
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webflux</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/runtime-controlloop/pom.xml b/runtime-controlloop/pom.xml
index e436451ff..508f44a80 100644
--- a/runtime-controlloop/pom.xml
+++ b/runtime-controlloop/pom.xml
@@ -67,6 +67,11 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-aop</artifactId>
+ <version>${version.springboot}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java
index 6b772513c..5fbd36c06 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/Application.java
@@ -22,11 +22,15 @@ package org.onap.policy.clamp.controlloop.runtime;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
+@EnableScheduling
@SpringBootApplication
@ComponentScan({"org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider",
"org.onap.policy.clamp.controlloop.runtime"})
+@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.runtime.main.parameters")
public class Application {
public static void main(String[] args) {
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 bf6e39914..e676cbe0e 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
@@ -23,13 +23,14 @@ package org.onap.policy.clamp.controlloop.runtime.commissioning;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
-import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.models.controlloop.persistence.provider.ControlLoopProvider;
@@ -42,6 +43,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
@@ -59,6 +61,7 @@ public class CommissioningProvider {
private final PolicyModelsProvider modelsProvider;
private final ControlLoopProvider clProvider;
+ private final ObjectMapper mapper = new ObjectMapper();
private static final Object lockit = new Object();
@@ -71,6 +74,7 @@ public class CommissioningProvider {
public CommissioningProvider(PolicyModelsProvider modelsProvider, ControlLoopProvider clProvider) {
this.modelsProvider = modelsProvider;
this.clProvider = clProvider;
+ mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
}
/**
@@ -181,6 +185,165 @@ public class CommissioningProvider {
}
/**
+ * Get the initial node types with common or instance properties.
+ *
+ * @param fullNodeTypes map of all the node types in the specified template
+ * @param common boolean to indicate whether common or instance properties are required
+ * @return node types map that only has common properties
+ * @throws PfModelException on errors getting node type with common properties
+ */
+ private Map<String, ToscaNodeType> getInitialNodeTypesMap(Map<String, ToscaNodeType> fullNodeTypes,
+ boolean common) {
+
+ var tempNodeTypesMap = new HashMap<String, ToscaNodeType>();
+
+ fullNodeTypes.forEach((key, nodeType) -> {
+ var tempToscaNodeType = new ToscaNodeType();
+ tempToscaNodeType.setName(key);
+
+ var resultantPropertyMap = findCommonOrInstancePropsInNodeTypes(nodeType, common);
+
+ if (!resultantPropertyMap.isEmpty()) {
+ tempToscaNodeType.setProperties(resultantPropertyMap);
+ tempNodeTypesMap.put(key, tempToscaNodeType);
+ }
+ });
+ return tempNodeTypesMap;
+ }
+
+ private Map<String, ToscaProperty> findCommonOrInstancePropsInNodeTypes(ToscaNodeType nodeType, boolean common) {
+
+ var tempCommonPropertyMap = new HashMap<String, ToscaProperty>();
+ var tempInstancePropertyMap = new HashMap<String, ToscaProperty>();
+
+ nodeType.getProperties().forEach((propKey, prop) -> {
+
+ if (prop.getMetadata() != null) {
+ prop.getMetadata().forEach((k, v) -> {
+ if (k.equals("common") && v.equals("true") && common) {
+ tempCommonPropertyMap.put(propKey, prop);
+ } else if (k.equals("common") && v.equals("false") && !common) {
+ tempInstancePropertyMap.put(propKey, prop);
+ }
+
+ });
+ } else {
+ tempInstancePropertyMap.put(propKey, prop);
+ }
+ });
+
+ if (tempCommonPropertyMap.isEmpty() && !common) {
+ return tempInstancePropertyMap;
+ } else {
+ return tempCommonPropertyMap;
+ }
+ }
+
+ /**
+ * Get the node types derived from those that have common properties.
+ *
+ * @param initialNodeTypes map of all the node types in the specified template
+ * @param filteredNodeTypes map of all the node types that have common or instance properties
+ * @return all node types that have common properties including their children
+ * @throws PfModelException on errors getting node type with common properties
+ */
+ private Map<String, ToscaNodeType> getFinalNodeTypesMap(Map<String, ToscaNodeType> initialNodeTypes,
+ Map<String, ToscaNodeType> filteredNodeTypes) {
+ for (var i = 0; i < initialNodeTypes.size(); i++) {
+ initialNodeTypes.forEach((key, nodeType) -> {
+ var tempToscaNodeType = new ToscaNodeType();
+ tempToscaNodeType.setName(key);
+
+ if (filteredNodeTypes.get(nodeType.getDerivedFrom()) != null) {
+ tempToscaNodeType.setName(key);
+
+ var finalProps = new HashMap<String, ToscaProperty>(
+ filteredNodeTypes.get(nodeType.getDerivedFrom()).getProperties());
+
+ tempToscaNodeType.setProperties(finalProps);
+ } else {
+ return;
+ }
+ filteredNodeTypes.putIfAbsent(key, tempToscaNodeType);
+
+ });
+ }
+ return filteredNodeTypes;
+ }
+
+ /**
+ * Get the requested node types with common or instance properties.
+ *
+ * @param common boolean indicating common or instance properties
+ * @param name the name of the definition to get, null for all definitions
+ * @param version the version of the definition to get, null for all definitions
+ * @return the node types with common or instance properties
+ * @throws PfModelException on errors getting node type properties
+ */
+ private Map<String, ToscaNodeType> getCommonOrInstancePropertiesFromNodeTypes(boolean common, String name,
+ String version) throws PfModelException {
+ var serviceTemplates = new ToscaServiceTemplates();
+ serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
+ var tempNodeTypesMap =
+ this.getInitialNodeTypesMap(serviceTemplates.getServiceTemplates().get(0).getNodeTypes(), common);
+
+ return this.getFinalNodeTypesMap(serviceTemplates.getServiceTemplates().get(0).getNodeTypes(),
+ tempNodeTypesMap);
+
+ }
+
+ /**
+ * Get node templates with appropriate common or instance properties added.
+ *
+ * @param initialNodeTemplates map of all the node templates in the specified template
+ * @param nodeTypeProps map of all the node types that have common or instance properties including children
+ * @return all node templates with appropriate common or instance properties added
+ * @throws PfModelException on errors getting map of node templates with common or instance properties added
+ */
+ private Map<String, ToscaNodeTemplate> getDerivedCommonOrInstanceNodeTemplates(
+ Map<String, ToscaNodeTemplate> initialNodeTemplates, Map<String, ToscaNodeType> nodeTypeProps) {
+
+ var finalNodeTemplatesMap = new HashMap<String, ToscaNodeTemplate>();
+
+ initialNodeTemplates.forEach((templateKey, template) -> {
+ if (nodeTypeProps.containsKey(template.getType())) {
+ var finalMergedProps = new HashMap<String, Object>();
+
+ nodeTypeProps.get(template.getType()).getProperties().forEach(finalMergedProps::putIfAbsent);
+
+ template.setProperties(finalMergedProps);
+
+ finalNodeTemplatesMap.put(templateKey, template);
+ } else {
+ return;
+ }
+ });
+ return finalNodeTemplatesMap;
+ }
+
+ /**
+ * Get node templates with common properties added.
+ *
+ * @param common boolean indicating common or instance properties to be used
+ * @param name the name of the definition to use, null for all definitions
+ * @param version the version of the definition to use, null for all definitions
+ * @return the nodes templates with common or instance properties
+ * @throws PfModelException on errors getting common or instance properties from node_templates
+ */
+ public Map<String, ToscaNodeTemplate> getNodeTemplatesWithCommonOrInstanceProperties(boolean common, String name,
+ String version) throws PfModelException {
+
+ var commonOrInstanceNodeTypeProps = this.getCommonOrInstancePropertiesFromNodeTypes(common, name, version);
+
+ var serviceTemplates = new ToscaServiceTemplates();
+ serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
+
+ return this.getDerivedCommonOrInstanceNodeTemplates(
+ serviceTemplates.getServiceTemplates().get(0).getToscaTopologyTemplate().getNodeTemplates(),
+ commonOrInstanceNodeTypeProps);
+ }
+
+ /**
* Get the requested control loop definitions.
*
* @param name the name of the definition to get, null for all definitions
@@ -195,47 +358,77 @@ public class CommissioningProvider {
}
/**
+ * Get the tosca service template with only required sections.
+ *
+ * @param name the name of the template to get, null for all definitions
+ * @param version the version of the template to get, null for all definitions
+ * @return the tosca service template
+ * @throws PfModelException on errors getting tosca service template
+ */
+ public String getToscaServiceTemplateReduced(String name, String version) throws PfModelException {
+ var serviceTemplates = new ToscaServiceTemplates();
+ serviceTemplates.setServiceTemplates(modelsProvider.getServiceTemplateList(name, version));
+
+ ToscaServiceTemplate fullTemplate = serviceTemplates.getServiceTemplates().get(0);
+
+ var template = new HashMap<String, Object>();
+ template.put("tosca_definitions_version", fullTemplate.getToscaDefinitionsVersion());
+ template.put("data_types", fullTemplate.getDataTypes());
+ template.put("policy_types", fullTemplate.getPolicyTypes());
+ template.put("node_types", fullTemplate.getNodeTypes());
+ template.put("topology_template", fullTemplate.getToscaTopologyTemplate());
+
+ try {
+ return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(template);
+
+ } catch (JsonProcessingException e) {
+ throw new PfModelException(Status.BAD_REQUEST, "Converion to Json Schema failed", e);
+ }
+ }
+
+ /**
* Get the requested json schema.
*
* @param section section of the tosca service template to get schema for
* @return the specified tosca service template or section Json Schema
* @throws PfModelException on errors with retrieving the classes
- * @throws JsonProcessingException on errors generating the schema
*/
- public String getToscaServiceTemplateSchema(String section) throws PfModelException, JsonProcessingException {
- ObjectMapper mapper = new ObjectMapper();
- mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
- SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
-
- switch (section) {
- case "data_types":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaDataType.class), visitor);
- break;
- case "capability_types":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaCapabilityType.class), visitor);
- break;
- case "node_types":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaNodeType.class), visitor);
- break;
- case "relationship_types":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaRelationshipType.class), visitor);
- break;
- case "policy_types":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaPolicyType.class), visitor);
- break;
- case "topology_template":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaTopologyTemplate.class), visitor);
- break;
- case "node_templates":
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaNodeTemplate.class), visitor);
- break;
- default:
- mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaServiceTemplate.class), visitor);
- }
+ public String getToscaServiceTemplateSchema(String section) throws PfModelException {
+ var visitor = new SchemaFactoryWrapper();
- JsonSchema jsonSchema = visitor.finalSchema();
- String response = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
+ try {
+ switch (section) {
+ case "data_types":
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaDataType.class), visitor);
+ break;
+ case "capability_types":
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaCapabilityType.class), visitor);
+ break;
+ case "node_types":
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaNodeType.class), visitor);
+ break;
+ case "relationship_types":
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaRelationshipType.class), visitor);
+ break;
+ case "policy_types":
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaPolicyType.class), visitor);
+ break;
+ case "topology_template":
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaTopologyTemplate.class), visitor);
+ break;
+ case "node_templates":
+ mapper.acceptJsonFormatVisitor(
+ mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class),
+ visitor);
+ break;
+ default:
+ mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaServiceTemplate.class), visitor);
+ }
- return response;
+ var jsonSchema = visitor.finalSchema();
+ return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
+ } catch (JsonProcessingException e) {
+ throw new PfModelException(Status.BAD_REQUEST, "Converion to Json Schema failed", e);
+ }
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterGroup.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterGroup.java
index d1fa31261..86473caa8 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterGroup.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterGroup.java
@@ -20,38 +20,49 @@
package org.onap.policy.clamp.controlloop.runtime.main.parameters;
-import javax.validation.constraints.NotBlank;
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
import lombok.Getter;
-import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import lombok.Setter;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
/**
* Class to hold all parameters needed for the Control Loop runtime component.
*
*/
-@NotNull
-@NotBlank
+@Validated
@Getter
-public class ClRuntimeParameterGroup extends ParameterGroupImpl {
- private RestServerParameters restServerParameters;
+@Setter
+@ConfigurationProperties(prefix = "runtime")
+public class ClRuntimeParameterGroup {
+
+ @NotNull
+ @ParameterGroupConstraint
private PolicyModelsProviderParameters databaseProviderParameters;
+
+ @Valid
+ @NotNull
private ParticipantParameters participantParameters;
+
+ @NotNull
+ @ParameterGroupConstraint
private TopicParameterGroup topicParameterGroup;
+ @Min(value = 0)
private long supervisionScannerIntervalSec;
- private long participantStateChangeIntervalSec;
+
+ @Min(value = 0)
private long participantClUpdateIntervalSec;
+
+ @Min(value = 0)
private long participantClStateChangeIntervalSec;
+ private long participantRegisterAckIntervalSec;
+ private long participantDeregisterAckIntervalSec;
+ private long participantUpdateIntervalSec;
- /**
- * Create the Control Loop parameter group.
- *
- * @param name the parameter group name
- */
- public ClRuntimeParameterGroup(final String name) {
- super(name);
- }
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterHandler.java
deleted file mode 100644
index bcf1124d2..000000000
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ClRuntimeParameterHandler.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * ============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.runtime.main.parameters;
-
-import java.io.File;
-import javax.ws.rs.core.Response;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.common.parameters.ValidationResult;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-
-/**
- * This class handles reading, parsing and validating of control loop runtime parameters from JSON files.
- */
-public class ClRuntimeParameterHandler {
-
- private static final Coder CODER = new StandardCoder();
-
- /**
- * Read the parameters from the parameter file.
- *
- * @param path the path passed to control loop runtime
- * @return the parameters read from the configuration file
- * @throws ControlLoopException on parameter exceptions
- */
- public ClRuntimeParameterGroup getParameters(final String path) throws ControlLoopException {
- ClRuntimeParameterGroup clRuntimeParameterGroup = null;
-
- // Read the parameters
- try {
- // Read the parameters from JSON
- File file = new File(path);
- clRuntimeParameterGroup = CODER.decode(file, ClRuntimeParameterGroup.class);
- } catch (final CoderException e) {
- throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE,
- "error reading parameters from \"" + path + "\"\n" + "(" + e.getClass().getSimpleName() + ")", e);
- }
-
- // The JSON processing returns null if there is an empty file
- if (clRuntimeParameterGroup == null) {
- throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, "no parameters found in \"" + path + "\"");
- }
-
- // validate the parameters
- final ValidationResult validationResult = clRuntimeParameterGroup.validate();
- if (!validationResult.isValid()) {
- throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE,
- "validation error(s) on parameters from \"" + path + "\"\n" + validationResult.getResult());
- }
-
- return clRuntimeParameterGroup;
- }
-}
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 dfc1b2806..47a99ca29 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
@@ -19,19 +19,20 @@
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;
import lombok.Getter;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.Min;
-import org.onap.policy.common.parameters.annotations.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
+import lombok.Setter;
+import org.springframework.validation.annotation.Validated;
/**
* Parameters for communicating with participants.
*/
-@NotNull
-@NotBlank
@Getter
-public class ParticipantParameters extends ParameterGroupImpl {
+@Setter
+@Validated
+public class ParticipantParameters {
/**
* Default maximum message age, in milliseconds, that should be examined. Any message
@@ -39,21 +40,13 @@ public class ParticipantParameters extends ParameterGroupImpl {
*/
public static final long DEFAULT_MAX_AGE_MS = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
-
@Min(1)
private long heartBeatMs;
@Min(1)
private long maxMessageAgeMs = DEFAULT_MAX_AGE_MS;
+ @Valid
+ @NotNull
private ParticipantUpdateParameters updateParameters;
- private ParticipantStateChangeParameters stateChangeParameters;
-
-
- /**
- * Constructs the object.
- */
- public ParticipantParameters() {
- super(ParticipantParameters.class.getSimpleName());
- }
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantStateChangeParameters.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantStateChangeParameters.java
deleted file mode 100644
index 2eea4ab51..000000000
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/parameters/ParticipantStateChangeParameters.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.controlloop.runtime.main.parameters;
-
-import lombok.Getter;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.Min;
-import org.onap.policy.common.parameters.annotations.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
-
-/**
- * Parameters for Participant STATE-CHANGE requests.
- */
-@NotNull
-@NotBlank
-@Getter
-public class ParticipantStateChangeParameters extends ParameterGroupImpl {
-
- /**
- * Maximum number of times to re-send a request to a PDP.
- */
- @Min(value = 0)
- private int maxRetryCount;
-
- /**
- * Maximum time to wait, in milliseconds, for a PDP response.
- */
- @Min(value = 0)
- private long maxWaitMs;
-
- /**
- * Constructs the object.
- */
- public ParticipantStateChangeParameters() {
- super(ParticipantStateChangeParameters.class.getSimpleName());
- }
-}
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 2af5be534..8102fe90e 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
@@ -18,19 +18,18 @@
package org.onap.policy.clamp.controlloop.runtime.main.parameters;
+import javax.validation.constraints.Min;
import lombok.Getter;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.Min;
-import org.onap.policy.common.parameters.annotations.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
+import lombok.Setter;
+import org.springframework.validation.annotation.Validated;
/**
* Parameters for Participant UPDATE requests.
*/
-@NotNull
-@NotBlank
@Getter
-public class ParticipantUpdateParameters extends ParameterGroupImpl {
+@Setter
+@Validated
+public class ParticipantUpdateParameters {
/**
* Maximum number of times to re-send a request to a PDP.
@@ -44,11 +43,4 @@ public class ParticipantUpdateParameters extends ParameterGroupImpl {
@Min(value = 0)
private long maxWaitMs;
- /**
- * Constructs the object.
- */
- public ParticipantUpdateParameters() {
- super(ParticipantUpdateParameters.class.getSimpleName());
- }
}
-
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 b50e7a0ed..ec7f14d8b 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
@@ -20,11 +20,6 @@
package org.onap.policy.clamp.controlloop.runtime.main.rest;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategies;
-import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
-import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
@@ -34,18 +29,16 @@ import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import javax.ws.rs.core.Response.Status;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.controlloop.runtime.main.web.AbstractRestController;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -60,27 +53,20 @@ import org.springframework.web.bind.annotation.RestController;
* Class to provide REST end points for creating, deleting, querying commissioned control loops.
*/
@RestController
+@RequiredArgsConstructor
public class CommissioningController extends AbstractRestController {
- private static final Logger LOGGER = LoggerFactory.getLogger(CommissioningController.class);
+ private static final String TAGS = "Clamp Control Loop Commissioning API";
private final CommissioningProvider provider;
/**
- * Create Commissioning Controller.
- *
- * @param provider the CommissioningProvider
- */
- public CommissioningController(CommissioningProvider provider) {
- this.provider = provider;
- }
-
- /**
* Creates a control loop definition.
*
* @param requestId request ID used in ONAP logging
* @param body the body of control loop following TOSCA definition
* @return a response
+ * @throws PfModelException on errors creating a control loop definition
*/
// @formatter:off
@PostMapping(value = "/commission",
@@ -90,7 +76,7 @@ public class CommissioningController extends AbstractRestController {
value = "Commissions control loop definitions",
notes = "Commissions control loop definitions, returning the commissioned control loop definition IDs",
response = CommissioningResponse.class,
- tags = {"Control Loop Commissioning API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -133,17 +119,10 @@ public class CommissioningController extends AbstractRestController {
@RequestHeader(
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) {
- try {
- return ResponseEntity.ok().body(provider.createControlLoopDefinitions(body));
-
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Commissioning of the control loops failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
- }
+ @ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ToscaServiceTemplate body)
+ throws PfModelException {
+ return ResponseEntity.ok().body(provider.createControlLoopDefinitions(body));
}
/**
@@ -153,6 +132,7 @@ public class CommissioningController extends AbstractRestController {
* @param name the name of the control loop definition to delete
* @param version the version of the control loop definition to delete
* @return a response
+ * @throws PfModelException on errors deleting a control loop definition
*/
// @formatter:off
@DeleteMapping(value = "/commission",
@@ -160,7 +140,7 @@ public class CommissioningController extends AbstractRestController {
@ApiOperation(value = "Delete a commissioned control loop",
notes = "Deletes a Commissioned Control Loop, returning optional error details",
response = CommissioningResponse.class,
- tags = {"Clamp Control Loop Commissioning API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -206,18 +186,10 @@ public class CommissioningController extends AbstractRestController {
value = "name") String name,
@ApiParam(
value = "Control Loop definition version",
- required = true) @RequestParam("version") String version) {
-
- try {
- return ResponseEntity.ok().body(provider.deleteControlLoopDefinition(name, version));
-
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Decommisssioning of control loop failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
- }
+ required = true) @RequestParam("version") String version)
+ throws PfModelException {
+ return ResponseEntity.ok().body(provider.deleteControlLoopDefinition(name, version));
}
/**
@@ -227,6 +199,7 @@ public class CommissioningController extends AbstractRestController {
* @param name the name of the control loop definition to get, null for all definitions
* @param version the version of the control loop definition to get, null for all definitions
* @return the control loop definitions
+ * @throws PfModelException on errors getting details of all or specific control loop definitions
*/
// @formatter:off
@GetMapping(value = "/commission",
@@ -235,7 +208,7 @@ public class CommissioningController extends AbstractRestController {
notes = "Queries details of the requested commissioned control loop definitions, "
+ "returning all control loop details",
response = ToscaNodeTemplate.class,
- tags = {"Clamp Control Loop Commissioning API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -266,7 +239,7 @@ public class CommissioningController extends AbstractRestController {
}
)
// @formatter:on
- public ResponseEntity<?> query(
+ public ResponseEntity<List<ToscaNodeTemplate>> query(
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@@ -275,18 +248,10 @@ public class CommissioningController extends AbstractRestController {
required = false) String name,
@ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
value = "version",
- required = false) String version) {
-
- try {
- return ResponseEntity.ok().body(provider.getControlLoopDefinitions(name, version));
-
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Get of control loop definitions failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
- }
+ required = false) String version)
+ throws PfModelException {
+ return ResponseEntity.ok().body(provider.getControlLoopDefinitions(name, version));
}
/**
@@ -296,6 +261,7 @@ public class CommissioningController extends AbstractRestController {
* @param name the name of the tosca service template to retrieve
* @param version the version of the tosca service template to get
* @return the specified tosca service template
+ * @throws PfModelException on errors getting the Tosca Service Template
*/
// @formatter:off
@GetMapping(value = "/commission/toscaservicetemplate",
@@ -304,7 +270,7 @@ public class CommissioningController extends AbstractRestController {
notes = "Queries details of the requested commissioned tosca service template, "
+ "returning all tosca service template details",
response = ToscaServiceTemplate.class,
- tags = {"Clamp Control Loop Commissioning API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -335,27 +301,19 @@ public class CommissioningController extends AbstractRestController {
}
)
// @formatter:on
- public ResponseEntity<?> queryToscaServiceTemplate(
+ public ResponseEntity<String> queryToscaServiceTemplate(
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "Tosca service template name", required = false) @RequestParam(
value = "name",
required = false) String name,
- @ApiParam(value = "Tosca service template version", required = true) @RequestParam(
+ @ApiParam(value = "Tosca service template version", required = false) @RequestParam(
value = "version",
- required = false) String version) {
-
- try {
- return ResponseEntity.ok().body(provider.getToscaServiceTemplate(name, version));
-
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Get of tosca service template failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
- }
+ required = false) String version)
+ throws PfModelException {
+ return ResponseEntity.ok().body(provider.getToscaServiceTemplateReduced(name, version));
}
/**
@@ -364,6 +322,7 @@ public class CommissioningController extends AbstractRestController {
* @param requestId request ID used in ONAP logging
* @param section section of the tosca service template to get schema for
* @return the specified tosca service template or section Json Schema
+ * @throws PfModelException on errros getting the Json Schema for the specified Tosca Service Template
*/
// @formatter:off
@GetMapping(value = "/commission/toscaServiceTemplateSchema",
@@ -372,7 +331,7 @@ public class CommissioningController extends AbstractRestController {
notes = "Queries details of the requested commissioned tosca service template json schema, "
+ "returning all tosca service template json schema details",
response = ToscaServiceTemplate.class,
- tags = {"Clamp Control Loop Commissioning API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -403,27 +362,84 @@ public class CommissioningController extends AbstractRestController {
}
)
// @formatter:on
- public ResponseEntity<?> queryToscaServiceTemplateJsonSchema(
- @RequestHeader(
- name = REQUEST_ID_NAME,
- required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Section of Template schema is desired for", required = false) @RequestParam(
- value = "section",
- required = false, defaultValue = "all") String section) {
- try {
- return ResponseEntity.ok().body(provider.getToscaServiceTemplateSchema(section));
+ public ResponseEntity<String> queryToscaServiceTemplateJsonSchema(
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Section of Template schema is desired for", required = false) @RequestParam(
+ value = "section",
+ required = false,
+ defaultValue = "all") String section)
+ throws PfModelException {
+
+ return ResponseEntity.ok().body(provider.getToscaServiceTemplateSchema(section));
+ }
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Get of tosca service template json schema failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
- } catch (JsonProcessingException e) {
- LOGGER.warn("Get of tosca service template json schema failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getMessage());
- return ResponseEntity.status(Status.BAD_REQUEST.getStatusCode()).body(resp);
+ /**
+ * Retrieves the Common or Instance Properties for the specified Tosca Service Template.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param common a flag, true to get common properties, false to get instance properties
+ * @param name the name of the tosca service template to retrieve
+ * @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
+ */
+ // @formatter:off
+ @GetMapping(value = "/commission/getCommonOrInstanceProperties",
+ produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
+ @ApiOperation(value = "Query details of the requested tosca service template common or instance properties",
+ notes = "Queries details of the requested commissioned tosca service template json common"
+ + "or instance properties, returning all tosca service template common or instance property details",
+ response = ToscaServiceTemplate.class,
+ tags = {"Clamp Control Loop Commissioning API"},
+ 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<Map<String, ToscaNodeTemplate>> queryToscaServiceCommonOrInstanceProperties(
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Flag, true for common properties, false for instance", required = false) @RequestParam(
+ value = "common",
+ defaultValue = "false",
+ required = false) boolean common,
+ @ApiParam(value = "Tosca service template name", required = false) @RequestParam(
+ value = "name",
+ required = false) String name,
+ @ApiParam(value = "Tosca service template version", required = false) @RequestParam(
+ value = "version",
+ required = false) String version)
+ throws PfModelException {
+
+ return ResponseEntity.ok().body(provider.getNodeTemplatesWithCommonOrInstanceProperties(common, name, version));
}
/**
@@ -433,6 +449,7 @@ public class CommissioningController extends AbstractRestController {
* @param name the name of the control loop definition to get
* @param version the version of the control loop definition to get
* @return the control loop element definitions
+ * @throws PfModelException on errors getting the elements of a specific control loop
*/
// @formatter:off
@GetMapping(value = "/commission/elements",
@@ -441,7 +458,7 @@ public class CommissioningController extends AbstractRestController {
notes = "Queries details of the requested commissioned control loop element definitions, "
+ "returning all control loop elements' details",
response = ToscaNodeTemplate.class,
- tags = {"Clamp Control Loop Commissioning API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -472,35 +489,25 @@ public class CommissioningController extends AbstractRestController {
}
)
// @formatter:on
- public ResponseEntity<?> queryElements(
+ public ResponseEntity<List<ToscaNodeTemplate>> queryElements(
@RequestHeader(
name = REQUEST_ID_NAME,
required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
value = "name",
required = false) String name,
- @ApiParam(value = "Control Loop definition version", required = true) @RequestParam(
+ @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
value = "version",
- required = false) String version) {
-
- try {
- List<ToscaNodeTemplate> nodeTemplate = provider.getControlLoopDefinitions(name, version);
- // Prevent ambiguous queries with multiple returns
- if (nodeTemplate.size() > 1) {
- var resp = new CommissioningResponse();
- resp.setErrorDetails("Multiple ControlLoops are not supported");
- return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(resp);
- }
-
- List<ToscaNodeTemplate> response = provider.getControlLoopElementDefinitions(nodeTemplate.get(0));
- return ResponseEntity.ok().body(response);
+ required = false) String version)
+ throws PfModelException {
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Get of control loop element definitions failed", e);
- var resp = new CommissioningResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
+ List<ToscaNodeTemplate> nodeTemplate = provider.getControlLoopDefinitions(name, version);
+ // Prevent ambiguous queries with multiple returns
+ if (nodeTemplate.size() > 1) {
+ throw new PfModelException(Status.NOT_ACCEPTABLE, "Multiple ControlLoops are not supported");
}
+ List<ToscaNodeTemplate> response = provider.getControlLoopElementDefinitions(nodeTemplate.get(0));
+ return ResponseEntity.ok().body(response);
}
}
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 aba585e29..29919f528 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
@@ -29,6 +29,7 @@ import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
import java.util.UUID;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
@@ -36,10 +37,6 @@ import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.Inst
import org.onap.policy.clamp.controlloop.runtime.instantiation.ControlLoopInstantiationProvider;
import org.onap.policy.clamp.controlloop.runtime.main.web.AbstractRestController;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -55,28 +52,21 @@ import org.springframework.web.bind.annotation.RestController;
* Class to provide REST end points for creating, deleting, query and commanding a control loop definition.
*/
@RestController
+@RequiredArgsConstructor
public class InstantiationController extends AbstractRestController {
- private static final Logger LOGGER = LoggerFactory.getLogger(InstantiationController.class);
+ private static final String TAGS = "Clamp Control Loop Instantiation API";
// The CL provider for instantiation requests
private final ControlLoopInstantiationProvider provider;
/**
- * Create Instantiation Controller.
- *
- * @param provider the ControlLoopInstantiationProvider
- */
- public InstantiationController(ControlLoopInstantiationProvider provider) {
- this.provider = provider;
- }
-
- /**
* Creates a control loop.
*
* @param requestId request ID used in ONAP logging
* @param controlLoops the control loops
* @return a response
+ * @throws PfModelException on errors creating a control loop
*/
// @formatter:off
@PostMapping(value = "/instantiation",
@@ -86,7 +76,7 @@ public class InstantiationController extends AbstractRestController {
value = "Commissions control loop definitions",
notes = "Commissions control loop definitions, returning the control loop IDs",
response = InstantiationResponse.class,
- tags = {"Control Loop Instantiation API"},
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -126,18 +116,13 @@ public class InstantiationController extends AbstractRestController {
)
// @formatter:on
public ResponseEntity<InstantiationResponse> create(
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Entity Body of Control Loop", required = true)
- @RequestBody ControlLoops controlLoops) {
-
- try {
- return ResponseEntity.ok().body(provider.createControlLoops(controlLoops));
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ControlLoops controlLoops)
+ throws PfModelException {
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("creation of control loop failed", e);
- return createInstantiationErrorResponse(e);
- }
+ return ResponseEntity.ok().body(provider.createControlLoops(controlLoops));
}
/**
@@ -147,6 +132,7 @@ public class InstantiationController extends AbstractRestController {
* @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 control loops
+ * @throws PfModelException on errors getting commissioning of control loop
*/
// @formatter:off
@GetMapping(value = "/instantiation",
@@ -154,9 +140,7 @@ public class InstantiationController extends AbstractRestController {
@ApiOperation(value = "Query details of the requested control loops",
notes = "Queries details of the requested control loops, returning all control loop details",
response = ControlLoops.class,
- tags = {
- "Clamp control loop Instantiation API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -187,22 +171,19 @@ public class InstantiationController extends AbstractRestController {
}
)
// @formatter:on
- public ResponseEntity<?> query(
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Control Loop definition name", required = false)
- @RequestParam(value = "name", required = false) String name,
- @ApiParam(value = "Control Loop definition version", required = false)
- @RequestParam(value = "version", required = false) String version) {
-
- try {
- return ResponseEntity.ok().body(provider.getControlLoops(name, version));
-
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("commisssioning of control loop failed", e);
- return createInstantiationErrorResponse(e);
- }
+ public ResponseEntity<ControlLoops> query(
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
+ value = "name",
+ required = false) String name,
+ @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
+ value = "version",
+ required = false) String version)
+ throws PfModelException {
+ return ResponseEntity.ok().body(provider.getControlLoops(name, version));
}
/**
@@ -211,6 +192,7 @@ public class InstantiationController extends AbstractRestController {
* @param requestId request ID used in ONAP logging
* @param controlLoops the control loops
* @return a response
+ * @throws PfModelException on errors updating of control loops
*/
// @formatter:off
@PutMapping(value = "/instantiation",
@@ -220,9 +202,7 @@ public class InstantiationController extends AbstractRestController {
value = "Updates control loop definitions",
notes = "Updates control loop definitions, returning the updated control loop definition IDs",
response = InstantiationResponse.class,
- tags = {
- "Control Loop Instantiation API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -262,18 +242,13 @@ public class InstantiationController extends AbstractRestController {
)
// @formatter:on
public ResponseEntity<InstantiationResponse> update(
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Entity Body of Control Loop", required = true)
- @RequestBody ControlLoops controlLoops) {
-
- try {
- return ResponseEntity.ok().body(provider.updateControlLoops(controlLoops));
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "Entity Body of Control Loop", required = true) @RequestBody ControlLoops controlLoops)
+ throws PfModelException {
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("update of control loops failed", e);
- return createInstantiationErrorResponse(e);
- }
+ return ResponseEntity.ok().body(provider.updateControlLoops(controlLoops));
}
/**
@@ -283,6 +258,7 @@ public class InstantiationController extends AbstractRestController {
* @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
*/
// @formatter:off
@DeleteMapping(value = "/instantiation",
@@ -290,9 +266,7 @@ public class InstantiationController extends AbstractRestController {
@ApiOperation(value = "Delete a control loop",
notes = "Deletes a control loop, returning optional error details",
response = InstantiationResponse.class,
- tags = {
- "Clamp Control Loop Instantiation API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -332,20 +306,16 @@ public class InstantiationController extends AbstractRestController {
// @formatter:on
public ResponseEntity<InstantiationResponse> delete(
- @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 = false) String version) {
-
- try {
- return ResponseEntity.ok().body(provider.deleteControlLoop(name, version));
+ @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 = false) String version)
+ throws PfModelException {
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("delete of control loop failed", e);
- return createInstantiationErrorResponse(e);
- }
+ return ResponseEntity.ok().body(provider.deleteControlLoop(name, version));
}
/**
@@ -354,6 +324,8 @@ public class InstantiationController extends AbstractRestController {
* @param requestId request ID used in ONAP logging
* @param command the command to issue to control loops
* @return the control loop definitions
+ * @throws PfModelException on errors issuing a command
+ * @throws ControlLoopException on errors issuing a command
*/
// @formatter:off
@PutMapping(value = "/instantiation/command",
@@ -362,9 +334,7 @@ public class InstantiationController extends AbstractRestController {
@ApiOperation(value = "Issue a command to the requested control loops",
notes = "Issues a command to a control loop, ordering a state change on the control loop",
response = InstantiationResponse.class,
- tags = {
- "Clamp Control Loop Instantiation API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -396,29 +366,14 @@ public class InstantiationController extends AbstractRestController {
)
// @formatter:on
public ResponseEntity<InstantiationResponse> issueControlLoopCommand(
- @RequestHeader(name = REQUEST_ID_NAME, required = false)
- @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
- @ApiParam(value = "Entity Body of control loop command", required = true)
- @RequestBody InstantiationCommand command) {
-
- try {
- return ResponseEntity.accepted().body(provider.issueControlLoopCommand(command));
-
- } catch (PfModelRuntimeException | PfModelException | ControlLoopException e) {
- LOGGER.warn("creation of control loop failed", e);
- return createInstantiationErrorResponse(e);
- }
- }
+ @RequestHeader(
+ name = REQUEST_ID_NAME,
+ required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(
+ value = "Entity Body of control loop command",
+ required = true) @RequestBody InstantiationCommand command)
+ throws ControlLoopException, PfModelException {
- /**
- * create a Instantiation Response from an exception.
- *
- * @param e the error
- * @return the Instantiation Response
- */
- private ResponseEntity<InstantiationResponse> createInstantiationErrorResponse(ErrorResponseInfo e) {
- var resp = new InstantiationResponse();
- resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
+ return ResponseEntity.accepted().body(provider.issueControlLoopCommand(command));
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/MonitoringQueryController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/MonitoringQueryController.java
index 86531597a..c4ce5bb05 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/MonitoringQueryController.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/MonitoringQueryController.java
@@ -30,14 +30,12 @@ import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
import java.time.Instant;
import java.util.UUID;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
import org.onap.policy.clamp.controlloop.runtime.main.web.AbstractRestController;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@@ -49,21 +47,13 @@ import org.springframework.web.bind.annotation.RestController;
* This class handles REST endpoints for CL Statistics monitoring.
*/
@RestController
+@RequiredArgsConstructor
public class MonitoringQueryController extends AbstractRestController {
- private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringQueryController.class);
+ private static final String TAGS = "Clamp Control Loop Monitoring API";
private final MonitoringProvider provider;
/**
- * Create Monitoring Controller.
- *
- * @param provider the MonitoringProvider
- */
- public MonitoringQueryController(MonitoringProvider provider) {
- this.provider = provider;
- }
-
- /**
* Queries details of control loop participants statistics.
*
* @param requestId request ID used in ONAP logging
@@ -80,9 +70,7 @@ public class MonitoringQueryController extends AbstractRestController {
@ApiOperation(value = "Query details of the requested participant stats",
notes = "Queries details of the requested participant stats, returning all participant stats",
response = ParticipantStatisticsList.class,
- tags = {
- "Clamp control loop Monitoring API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -134,24 +122,17 @@ public class MonitoringQueryController extends AbstractRestController {
value = "endTime",
required = false) final String endTime) {
- try {
- Instant startTimestamp = null;
- Instant endTimestamp = null;
+ Instant startTimestamp = null;
+ Instant endTimestamp = null;
- if (startTime != null) {
- startTimestamp = Instant.parse(startTime);
- }
- if (endTime != null) {
- endTimestamp = Instant.parse(endTime);
- }
- return ResponseEntity.ok().body(provider.fetchFilteredParticipantStatistics(name, version, recordCount,
- startTimestamp, endTimestamp));
-
- } catch (PfModelRuntimeException e) {
- LOGGER.warn("Monitoring of participants statistics failed", e);
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).build();
+ if (startTime != null) {
+ startTimestamp = Instant.parse(startTime);
}
-
+ if (endTime != null) {
+ endTimestamp = Instant.parse(endTime);
+ }
+ return ResponseEntity.ok().body(
+ provider.fetchFilteredParticipantStatistics(name, version, recordCount, startTimestamp, endTimestamp));
}
/**
@@ -168,9 +149,7 @@ public class MonitoringQueryController extends AbstractRestController {
@ApiOperation(value = "Query details of all the participant stats in a control loop",
notes = "Queries details of the participant stats, returning all participant stats",
response = ClElementStatisticsList.class,
- tags = {
- "Clamp control loop Monitoring API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -211,14 +190,7 @@ public class MonitoringQueryController extends AbstractRestController {
value = "version",
required = false) final String version) {
- try {
- return ResponseEntity.ok().body(provider.fetchParticipantStatsPerControlLoop(name, version));
-
- } catch (PfModelRuntimeException e) {
- LOGGER.warn("Monitoring of Cl participant statistics failed", e);
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).build();
- }
-
+ return ResponseEntity.ok().body(provider.fetchParticipantStatsPerControlLoop(name, version));
}
/**
@@ -235,9 +207,7 @@ public class MonitoringQueryController extends AbstractRestController {
@ApiOperation(value = "Query details of the requested cl element stats in a control loop",
notes = "Queries details of the requested cl element stats, returning all clElement stats",
response = ClElementStatisticsList.class,
- tags = {
- "Clamp control loop Monitoring API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -278,14 +248,7 @@ public class MonitoringQueryController extends AbstractRestController {
value = "version",
required = false) final String version) {
- try {
- return ResponseEntity.ok().body(provider.fetchClElementStatsPerControlLoop(name, version));
-
- } catch (PfModelRuntimeException e) {
- LOGGER.warn("Monitoring of Cl Element statistics failed", e);
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).build();
- }
-
+ return ResponseEntity.ok().body(provider.fetchClElementStatsPerControlLoop(name, version));
}
/**
@@ -299,6 +262,7 @@ public class MonitoringQueryController extends AbstractRestController {
* @param startTime the time from which to get statistics
* @param endTime the time to which to get statistics
* @return the control loop element statistics
+ * @throws PfModelException on errors getting details of all control loop element statistics per control loop
*/
// @formatter:off
@GetMapping(value = "/monitoring/clelement",
@@ -306,9 +270,7 @@ public class MonitoringQueryController extends AbstractRestController {
@ApiOperation(value = "Query details of the requested cl element stats",
notes = "Queries details of the requested cl element stats, returning all clElement stats",
response = ClElementStatisticsList.class,
- tags = {
- "Clamp control loop Monitoring API"
- },
+ tags = {TAGS},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@ResponseHeader(
@@ -360,26 +322,20 @@ public class MonitoringQueryController extends AbstractRestController {
required = false) final String startTime,
@ApiParam(value = "end time", required = false) @RequestParam(
value = "endTime",
- required = false) final String endTime) {
-
- try {
- Instant startTimestamp = null;
- Instant endTimestamp = null;
+ required = false) final String endTime)
+ throws PfModelException {
- if (startTime != null) {
- startTimestamp = Instant.parse(startTime);
- }
- if (endTime != null) {
- endTimestamp = Instant.parse(endTime);
- }
- return ResponseEntity.ok().body(provider.fetchFilteredClElementStatistics(name, version, id, startTimestamp,
- endTimestamp, recordCount));
+ Instant startTimestamp = null;
+ Instant endTimestamp = null;
- } catch (PfModelRuntimeException | PfModelException e) {
- LOGGER.warn("Monitoring of Cl Element statistics failed", e);
- return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).build();
+ if (startTime != null) {
+ startTimestamp = Instant.parse(startTime);
}
-
+ if (endTime != null) {
+ endTimestamp = Instant.parse(endTime);
+ }
+ return ResponseEntity.ok().body(provider.fetchFilteredClElementStatistics(name, version, id, startTimestamp,
+ endTimestamp, recordCount));
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java
new file mode 100644
index 000000000..d093c677f
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java
@@ -0,0 +1,73 @@
+/*-
+ * ============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.runtime.main.web;
+
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
+import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@RestControllerAdvice
+public class GlobalControllerExceptionHandler {
+
+ /**
+ * Handle ControlLoopException.
+ *
+ * @param ex ControlLoopException
+ * @return ResponseEntity
+ */
+ @ExceptionHandler(ControlLoopException.class)
+ public ResponseEntity<SimpleResponse> handleBadRequest(ControlLoopException ex) {
+ var resp = new SimpleResponse();
+ resp.setErrorDetails(ex.getErrorResponse().getErrorMessage());
+ return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
+ }
+
+ /**
+ * Handle PfModelRuntimeException.
+ *
+ * @param ex PfModelRuntimeException
+ * @return ResponseEntity
+ */
+ @ExceptionHandler(PfModelRuntimeException.class)
+ public ResponseEntity<SimpleResponse> handleBadRequest(PfModelRuntimeException ex) {
+ var resp = new SimpleResponse();
+ resp.setErrorDetails(ex.getErrorResponse().getErrorMessage());
+ return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
+ }
+
+ /**
+ * Handle PfModelException.
+ *
+ * @param ex PfModelException
+ * @return ResponseEntity
+ */
+ @ExceptionHandler(PfModelException.class)
+ public ResponseEntity<SimpleResponse> handleBadRequest(PfModelException ex) {
+ var resp = new SimpleResponse();
+ resp.setErrorDetails(ex.getErrorResponse().getErrorMessage());
+ return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
+ }
+
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounter.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounter.java
new file mode 100644
index 000000000..2151dc143
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounter.java
@@ -0,0 +1,91 @@
+/*-
+ * ============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.runtime.supervision;
+
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
+
+public class HandleCounter<K> {
+ @Getter
+ @Setter
+ private long maxWaitMs;
+
+ @Getter
+ @Setter
+ private int maxRetryCount;
+
+ private Map<K, Integer> mapCounter = new HashMap<>();
+ private Set<K> mapFault = new HashSet<>();
+ private Map<K, Long> mapTimer = new HashMap<>();
+
+ public long getDuration(K id) {
+ mapTimer.putIfAbsent(id, getEpochMilli());
+ return getEpochMilli() - mapTimer.get(id);
+ }
+
+ /**
+ * Reset timer and clear counter and fault by id.
+ *
+ * @param id the id
+ */
+ public void clear(K id) {
+ mapFault.remove(id);
+ mapCounter.put(id, 0);
+ mapTimer.put(id, getEpochMilli());
+ }
+
+ public void setFault(K id) {
+ mapCounter.put(id, 0);
+ mapFault.add(id);
+ }
+
+ /**
+ * Increment RetryCount by id e return true if minor or equal of maxRetryCount.
+ *
+ * @param id the identifier
+ * @return false if count is major of maxRetryCount
+ */
+ public boolean count(K id) {
+ int counter = mapCounter.getOrDefault(id, 0) + 1;
+ if (counter <= maxRetryCount) {
+ mapCounter.put(id, counter);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isFault(K id) {
+ return mapFault.contains(id);
+ }
+
+ public int getCounter(K id) {
+ return mapCounter.getOrDefault(id, 0);
+ }
+
+ protected long getEpochMilli() {
+ return Instant.now().toEpochMilli();
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/MessageIntercept.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/MessageIntercept.java
new file mode 100644
index 000000000..c23ed833d
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/MessageIntercept.java
@@ -0,0 +1,32 @@
+/*-
+ * ============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.runtime.supervision;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface MessageIntercept {
+
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java
new file mode 100644
index 000000000..d0d18ab1a
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspect.java
@@ -0,0 +1,78 @@
+/*-
+ * ============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.runtime.supervision;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import lombok.RequiredArgsConstructor;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+@RequiredArgsConstructor
+public class SupervisionAspect implements Closeable {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAspect.class);
+
+ private final SupervisionScanner supervisionScanner;
+
+ private ThreadPoolExecutor executor =
+ new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
+
+ @Scheduled(
+ fixedRateString = "${runtime.participantParameters.heartBeatMs}",
+ initialDelayString = "${runtime.participantParameters.heartBeatMs}")
+ public void schedule() {
+ LOGGER.info("Add scheduled scanning");
+ executor.execute(() -> supervisionScanner.run(true));
+ }
+
+ /**
+ * Intercept Messages from participant and run Supervision Scan.
+ */
+ @After("@annotation(MessageIntercept)")
+ public void doCheck() {
+ if (executor.getQueue().size() < 2) {
+ LOGGER.debug("Add scanning Message");
+ executor.execute(() -> supervisionScanner.run(false));
+ }
+ }
+
+ @Before("@annotation(MessageIntercept) && args(participantStatusMessage,..)")
+ public void handleParticipantStatus(ParticipantStatus participantStatusMessage) {
+ executor.execute(() -> supervisionScanner.handleParticipantStatus(participantStatusMessage.getParticipantId()));
+ }
+
+ @Override
+ public void close() throws IOException {
+ executor.shutdown();
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
index aba545750..16dba0f07 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
@@ -21,20 +21,28 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
import java.util.List;
+import java.util.Map;
import javax.ws.rs.core.Response;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
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.ControlLoopInfo;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
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;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
-import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantControlLoopStateChangePublisher;
-import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantControlLoopUpdatePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.slf4j.Logger;
@@ -62,8 +70,11 @@ public class SupervisionHandler {
private final MonitoringProvider monitoringProvider;
// Publishers for participant communication
- private final ParticipantControlLoopUpdatePublisher controlLoopUpdatePublisher;
- private final ParticipantControlLoopStateChangePublisher controlLoopStateChangePublisher;
+ private final ControlLoopUpdatePublisher controlLoopUpdatePublisher;
+ private final ControlLoopStateChangePublisher controlLoopStateChangePublisher;
+ private final ParticipantRegisterAckPublisher participantRegisterAckPublisher;
+ private final ParticipantDeregisterAckPublisher participantDeregisterAckPublisher;
+ private final ParticipantUpdatePublisher participantUpdatePublisher;
/**
* Supervision trigger called when a command is issued on control loops.
@@ -102,9 +113,9 @@ public class SupervisionHandler {
*
* @param participantStatusMessage the ParticipantStatus message received from a participant
*/
- public void handleParticipantStatusMessage(ParticipantStatus participantStatusMessage) {
+ @MessageIntercept
+ public void handleParticipantMessage(ParticipantStatus participantStatusMessage) {
LOGGER.debug("Participant Status received {}", participantStatusMessage);
-
try {
superviseParticipant(participantStatusMessage);
} catch (PfModelException | ControlLoopException svExc) {
@@ -120,6 +131,42 @@ public class SupervisionHandler {
}
/**
+ * Handle a ParticipantRegister message from a participant.
+ *
+ * @param participantRegisterMessage the ParticipantRegister message received from a participant
+ */
+ @MessageIntercept
+ public void handleParticipantMessage(ParticipantRegister participantRegisterMessage) {
+ LOGGER.debug("Participant Register received {}", participantRegisterMessage);
+
+ participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId());
+
+ participantUpdatePublisher.send(participantRegisterMessage.getParticipantId(),
+ participantRegisterMessage.getParticipantType());
+ }
+
+ /**
+ * Handle a ParticipantDeregister message from a participant.
+ *
+ * @param participantDeregisterMessage the ParticipantDeregister message received from a participant
+ */
+ @MessageIntercept
+ public void handleParticipantMessage(ParticipantDeregister participantDeregisterMessage) {
+ LOGGER.debug("Participant Deregister received {}", participantDeregisterMessage);
+ participantDeregisterAckPublisher.send(participantDeregisterMessage.getMessageId());
+ }
+
+ /**
+ * Handle a ParticipantUpdateAck message from a participant.
+ *
+ * @param participantUpdateAckMessage the ParticipantUpdateAck message received from a participant
+ */
+ @MessageIntercept
+ public void handleParticipantMessage(ParticipantUpdateAck participantUpdateAckMessage) {
+ LOGGER.debug("Participant Update Ack received {}", participantUpdateAckMessage);
+ }
+
+ /**
* Supervise a control loop, performing whatever actions need to be performed on the control loop.
*
* @param controlLoop the control loop to supervises
@@ -265,39 +312,17 @@ public class SupervisionHandler {
private void superviseControlLoops(ParticipantStatus participantStatusMessage)
throws PfModelException, ControlLoopException {
- if (CollectionUtils.isEmpty(participantStatusMessage.getControlLoops().getControlLoopList())) {
- return;
- }
-
- for (ControlLoop controlLoop : participantStatusMessage.getControlLoops().getControlLoopList()) {
- if (controlLoop == null) {
- exceptionOccured(Response.Status.NOT_FOUND,
- "PARTICIPANT_STATUS message references unknown control loop: " + controlLoop);
- }
-
- var dbControlLoop = controlLoopProvider
- .getControlLoop(new ToscaConceptIdentifier(controlLoop.getName(), controlLoop.getVersion()));
+ for (Map.Entry<ToscaConceptIdentifier, ControlLoopInfo> clEntry :
+ participantStatusMessage.getControlLoopInfoMap().entrySet()) {
+ var dbControlLoop = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier(
+ clEntry.getKey().getName(), clEntry.getKey().getVersion()));
if (dbControlLoop == null) {
exceptionOccured(Response.Status.NOT_FOUND,
- "PARTICIPANT_STATUS control loop not found in database: " + controlLoop);
+ "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getKey());
}
-
- for (ControlLoopElement element : controlLoop.getElements().values()) {
- ControlLoopElement dbElement = dbControlLoop.getElements().get(element.getId());
-
- if (dbElement == null) {
- exceptionOccured(Response.Status.NOT_FOUND,
- "PARTICIPANT_STATUS message references unknown control loop element: " + element);
- }
-
- // Replace element entry in the database
- dbControlLoop.getElements().put(element.getId(), element);
- }
- controlLoopProvider.updateControlLoop(dbControlLoop);
- }
-
- for (ControlLoop controlLoop : participantStatusMessage.getControlLoops().getControlLoopList()) {
- monitoringProvider.createClElementStatistics(controlLoop.getControlLoopElementStatisticsList(controlLoop));
+ dbControlLoop.setState(clEntry.getValue().getState());
+ monitoringProvider.createClElementStatistics(clEntry.getValue()
+ .getControlLoopStatistics().getClElementStatisticsList().getClElementStatistics());
}
}
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 68f5830c0..7be407c3f 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
@@ -20,15 +20,20 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
-import java.io.Closeable;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import java.util.List;
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.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusReqPublisher;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -37,35 +42,76 @@ import org.springframework.stereotype.Component;
* This class is used to scan the control loops in the database and check if they are in the correct state.
*/
@Component
-public class SupervisionScanner implements Runnable, Closeable {
+public class SupervisionScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class);
- private ControlLoopProvider controlLoopProvider;
- private ScheduledExecutorService timerPool;
+ private HandleCounter<ToscaConceptIdentifier> controlLoopCounter = new HandleCounter<>();
+ private HandleCounter<ToscaConceptIdentifier> participantCounter = new HandleCounter<>();
+
+ private final ControlLoopProvider controlLoopProvider;
+ private final ControlLoopStateChangePublisher controlLoopStateChangePublisher;
+ private final ControlLoopUpdatePublisher controlLoopUpdatePublisher;
+ private final ParticipantProvider participantProvider;
+ private final ParticipantStatusReqPublisher participantStatusReqPublisher;
+
+ private final long maxMessageAgeMs;
/**
* Constructor for instantiating SupervisionScanner.
*
- * @param clRuntimeParameterGroup the parameters for the control loop runtime
* @param controlLoopProvider the provider to use to read control loops from the database
+ * @param controlLoopStateChangePublisher the ControlLoop StateChange Publisher
+ * @param controlLoopUpdatePublisher the ControlLoopUpdate Publisher
+ * @param participantProvider the Participant Provider
+ * @param participantStatusReqPublisher the Participant StatusReq Publisher
+ * @param clRuntimeParameterGroup the parameters for the control loop runtime
*/
public SupervisionScanner(final ControlLoopProvider controlLoopProvider,
- ClRuntimeParameterGroup clRuntimeParameterGroup) {
+ final ControlLoopStateChangePublisher controlLoopStateChangePublisher,
+ ControlLoopUpdatePublisher controlLoopUpdatePublisher, ParticipantProvider participantProvider,
+ ParticipantStatusReqPublisher participantStatusReqPublisher,
+ final ClRuntimeParameterGroup clRuntimeParameterGroup) {
this.controlLoopProvider = controlLoopProvider;
-
- // Kick off the timer
- timerPool = makeTimerPool();
- timerPool.scheduleAtFixedRate(this, 0, clRuntimeParameterGroup.getSupervisionScannerIntervalSec(),
- TimeUnit.SECONDS);
+ this.controlLoopStateChangePublisher = controlLoopStateChangePublisher;
+ this.controlLoopUpdatePublisher = controlLoopUpdatePublisher;
+ this.participantProvider = participantProvider;
+ this.participantStatusReqPublisher = participantStatusReqPublisher;
+
+ controlLoopCounter.setMaxRetryCount(
+ clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
+ controlLoopCounter
+ .setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs());
+
+ participantCounter.setMaxRetryCount(
+ clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
+ participantCounter
+ .setMaxWaitMs(clRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxWaitMs());
+
+ maxMessageAgeMs = clRuntimeParameterGroup.getParticipantParameters().getMaxMessageAgeMs();
}
- @Override
- public void run() {
+ /**
+ * Run Scanning.
+ *
+ * @param counterCheck if true activate counter and retry
+ */
+ public void run(boolean counterCheck) {
LOGGER.debug("Scanning control loops in the database . . .");
+ if (counterCheck) {
+ try {
+ for (Participant participant : participantProvider.getParticipants(null, null)) {
+ scanParticipant(participant);
+ }
+ } catch (PfModelException pfme) {
+ LOGGER.warn("error reading participant from database", pfme);
+ return;
+ }
+ }
+
try {
for (ControlLoop controlLoop : controlLoopProvider.getControlLoops(null, null)) {
- scanControlLoop(controlLoop);
+ scanControlLoop(controlLoop, counterCheck);
}
} catch (PfModelException pfme) {
LOGGER.warn("error reading control loops from database", pfme);
@@ -74,40 +120,92 @@ public class SupervisionScanner implements Runnable, Closeable {
LOGGER.debug("Control loop scan complete . . .");
}
- @Override
- public void close() {
- timerPool.shutdown();
+ private void scanParticipant(Participant participant) throws PfModelException {
+ ToscaConceptIdentifier id = participant.getKey().asIdentifier();
+ if (participantCounter.isFault(id)) {
+ LOGGER.debug("report Participant fault");
+ return;
+ }
+ if (participantCounter.getDuration(id) > maxMessageAgeMs) {
+ if (participantCounter.count(id)) {
+ LOGGER.debug("retry message ParticipantStatusReq");
+ participantStatusReqPublisher.send(id);
+ participant.setHealthStatus(ParticipantHealthStatus.NOT_HEALTHY);
+ } else {
+ LOGGER.debug("report Participant fault");
+ participantCounter.setFault(id);
+ participant.setHealthStatus(ParticipantHealthStatus.OFF_LINE);
+ }
+ participantProvider.updateParticipants(List.of(participant));
+ }
}
- private void scanControlLoop(final ControlLoop controlLoop) throws PfModelException {
+ /**
+ * handle participant Status message.
+ */
+ public void handleParticipantStatus(ToscaConceptIdentifier id) {
+ participantCounter.clear(id);
+ }
+
+ private void scanControlLoop(final ControlLoop controlLoop, boolean counterCheck) throws PfModelException {
LOGGER.debug("scanning control loop {} . . .", controlLoop.getKey().asIdentifier());
if (controlLoop.getState().equals(controlLoop.getOrderedState().asState())) {
LOGGER.debug("control loop {} scanned, OK", controlLoop.getKey().asIdentifier());
+
+ // Clear missed report counter on Control Loop
+ clearFaultAndCounter(controlLoop);
return;
}
+ boolean completed = true;
for (ControlLoopElement element : controlLoop.getElements().values()) {
if (!element.getState().equals(element.getOrderedState().asState())) {
- LOGGER.debug("control loop scan: transitioning from state {} to {}", controlLoop.getState(),
- controlLoop.getOrderedState());
- return;
+ completed = false;
+ break;
}
}
- LOGGER.debug("control loop scan: transition from state {} to {} completed", controlLoop.getState(),
- controlLoop.getOrderedState());
+ if (completed) {
+ LOGGER.debug("control loop scan: transition from state {} to {} completed", controlLoop.getState(),
+ controlLoop.getOrderedState());
+
+ controlLoop.setState(controlLoop.getOrderedState().asState());
+ controlLoopProvider.updateControlLoop(controlLoop);
- controlLoop.setState(controlLoop.getOrderedState().asState());
- controlLoopProvider.updateControlLoop(controlLoop);
+ // Clear missed report counter on Control Loop
+ clearFaultAndCounter(controlLoop);
+ } else {
+ LOGGER.debug("control loop scan: transition from state {} to {} not completed", controlLoop.getState(),
+ controlLoop.getOrderedState());
+ if (counterCheck) {
+ handleCounter(controlLoop);
+ }
+ }
}
- /**
- * Makes a new timer pool.
- *
- * @return a new timer pool
- */
- protected ScheduledExecutorService makeTimerPool() {
- return Executors.newScheduledThreadPool(1);
+ private void clearFaultAndCounter(ControlLoop controlLoop) {
+ controlLoopCounter.clear(controlLoop.getKey().asIdentifier());
+ }
+
+ private void handleCounter(ControlLoop controlLoop) {
+ ToscaConceptIdentifier id = controlLoop.getKey().asIdentifier();
+ if (controlLoopCounter.isFault(id)) {
+ LOGGER.debug("report ControlLoop fault");
+ return;
+ }
+
+ 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("report ControlLoop fault");
+ controlLoopCounter.setFault(id);
+ }
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/AbstractParticipantAckPublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/AbstractParticipantAckPublisher.java
new file mode 100644
index 000000000..4b4ca9915
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/AbstractParticipantAckPublisher.java
@@ -0,0 +1,62 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import java.util.List;
+import javax.ws.rs.core.Response.Status;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantAckMessage;
+import org.onap.policy.clamp.controlloop.runtime.config.messaging.Publisher;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
+
+public abstract class AbstractParticipantAckPublisher<E extends ParticipantAckMessage> implements Publisher {
+
+ private TopicSinkClient topicSinkClient;
+ private boolean active = false;
+
+ /**
+ * Method to send Participant message to participants on demand.
+ *
+ * @param participantMessage the Participant message
+ */
+ public void send(final E participantMessage) {
+ if (!active) {
+ throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, "Not Active!");
+ }
+ topicSinkClient.send(participantMessage);
+ }
+
+
+ @Override
+ public void active(List<TopicSink> topicSinks) {
+ if (topicSinks.size() != 1) {
+ throw new IllegalArgumentException("Topic Sink must be one");
+ }
+ this.topicSinkClient = new TopicSinkClient(topicSinks.get(0));
+ active = true;
+ }
+
+ @Override
+ public void stop() {
+ active = false;
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopStateChangePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
index 734ccb842..79d113c14 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopStateChangePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopStateChangePublisher.java
@@ -22,15 +22,15 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
import java.util.UUID;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
import org.springframework.stereotype.Component;
/**
- * This class is used to send ParticipantControlLoopStateChangePublisher messages to participants on DMaaP.
+ * This class is used to send ControlLoopStateChangePublisher messages to participants on DMaaP.
*/
@Component
-public class ParticipantControlLoopStateChangePublisher
- extends AbstractParticipantPublisher<ParticipantControlLoopStateChange> {
+public class ControlLoopStateChangePublisher
+ extends AbstractParticipantPublisher<ControlLoopStateChange> {
/**
* Send ControlLoopStateChange to Participant.
@@ -38,7 +38,7 @@ public class ParticipantControlLoopStateChangePublisher
* @param controlLoop the ControlLoop
*/
public void send(ControlLoop controlLoop) {
- var clsc = new ParticipantControlLoopStateChange();
+ var clsc = new ControlLoopStateChange();
clsc.setControlLoopId(controlLoop.getKey().asIdentifier());
clsc.setMessageId(UUID.randomUUID());
clsc.setOrderedState(controlLoop.getOrderedState());
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
new file mode 100644
index 000000000..448662cfe
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class is used to send ControlLoopUpdate messages to participants on DMaaP.
+ */
+@Component
+@AllArgsConstructor
+public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<ControlLoopUpdate> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdatePublisher.class);
+
+ /**
+ * Send ControlLoopUpdate to Participant.
+ *
+ * @param controlLoop the ControlLoop
+ */
+ public void send(ControlLoop controlLoop) {
+ var controlLoopUpdateMsg = new ControlLoopUpdate();
+ controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
+ controlLoopUpdateMsg.setControlLoop(controlLoop);
+ LOGGER.debug("ControlLoopUpdate message sent", controlLoopUpdateMsg);
+ super.send(controlLoopUpdateMsg);
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopUpdatePublisher.java
deleted file mode 100644
index 8d40c5e69..000000000
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantControlLoopUpdatePublisher.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * ============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.runtime.supervision.comm;
-
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
-import org.onap.policy.models.base.PfModelException;
-import org.springframework.stereotype.Component;
-
-/**
- * This class is used to send ParticipantControlLoopUpdate messages to participants on DMaaP.
- */
-@Component
-public class ParticipantControlLoopUpdatePublisher extends AbstractParticipantPublisher<ParticipantControlLoopUpdate> {
-
- private final CommissioningProvider commissioningProvider;
-
- /**
- * Constructor.
- *
- * @param commissioningProvider the CommissioningProvider
- */
- public ParticipantControlLoopUpdatePublisher(CommissioningProvider commissioningProvider) {
- this.commissioningProvider = commissioningProvider;
- }
-
- /**
- * Send ControlLoopUpdate to Participant.
- *
- * @param controlLoop the ControlLoop
- * @throws PfModelException on errors getting the Control Loop Definition
- */
- public void send(ControlLoop controlLoop) throws PfModelException {
- var pclu = new ParticipantControlLoopUpdate();
- pclu.setControlLoopId(controlLoop.getKey().asIdentifier());
- pclu.setControlLoop(controlLoop);
- // TODO: We should look up the correct TOSCA node template here for the control loop
- // Tiny hack implemented to return the tosca service template entry from the database and be passed onto dmaap
- pclu.setControlLoopDefinition(commissioningProvider.getToscaServiceTemplate(null, null));
- super.send(pclu);
- }
-}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterAckPublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterAckPublisher.java
new file mode 100644
index 000000000..e92b6ee1b
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterAckPublisher.java
@@ -0,0 +1,45 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import java.util.UUID;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class is used to send ParticipantDeregisterAck messages to participants on DMaaP.
+ */
+@Component
+public class ParticipantDeregisterAckPublisher extends AbstractParticipantAckPublisher<ParticipantDeregisterAck> {
+
+ /**
+ * Sent ParticipantDeregisterAck to Participant.
+ *
+ * @param responseTo the original request id in the request.
+ */
+ public void send(UUID responseTo) {
+ var message = new ParticipantDeregisterAck();
+ message.setResponseTo(responseTo);
+ message.setMessage("Participant Deregister Ack");
+ message.setResult(true);
+ super.send(message);
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterListener.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterListener.java
new file mode 100644
index 000000000..a03ff0a63
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantDeregisterListener.java
@@ -0,0 +1,67 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.controlloop.runtime.config.messaging.Listener;
+import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.listeners.ScoListener;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Listener for ParticipantDeregister messages sent by participants.
+ */
+@Component
+public class ParticipantDeregisterListener extends ScoListener<ParticipantDeregister> implements Listener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantDeregisterListener.class);
+
+ private final SupervisionHandler supervisionHandler;
+
+ /**
+ * Constructs the object.
+ */
+ public ParticipantDeregisterListener(SupervisionHandler supervisionHandler) {
+ super(ParticipantDeregister.class);
+ this.supervisionHandler = supervisionHandler;
+ }
+
+ @Override
+ public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
+ final ParticipantDeregister participantDeregisterMessage) {
+ LOGGER.debug("ParticipantDeregister message received from participant - {}", participantDeregisterMessage);
+ supervisionHandler.handleParticipantMessage(participantDeregisterMessage);
+ }
+
+ @Override
+ public String getType() {
+ return ParticipantMessageType.PARTICIPANT_DEREGISTER.name();
+ }
+
+ @Override
+ public ScoListener<ParticipantDeregister> getScoListener() {
+ return this;
+ }
+}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterAckPublisher.java
index ec6548a7c..73860b5c2 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterAckPublisher.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * 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.
@@ -18,25 +18,28 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
+package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
-import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
+import java.util.UUID;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
import org.springframework.stereotype.Component;
/**
- * Listener for Participant State Change messages sent by CLAMP.
- *
+ * This class is used to send ParticipantRegisterAck messages to participants on DMaaP.
*/
@Component
-public class ParticipantStateChangeListener extends ParticipantListener<ParticipantStateChange> {
+public class ParticipantRegisterAckPublisher extends AbstractParticipantAckPublisher<ParticipantRegisterAck> {
/**
- * Constructs the object.
+ * Send ParticipantRegisterAck to Participant.
*
- * @param participantHandler the handler for managing the state of the participant
+ * @param responseTo the original request id in the request.
*/
- public ParticipantStateChangeListener(final ParticipantHandler participantHandler) {
- super(ParticipantStateChange.class, participantHandler, participantHandler::handleParticipantStateChange);
+ public void send(UUID responseTo) {
+ var message = new ParticipantRegisterAck();
+ message.setResponseTo(responseTo);
+ message.setMessage("Participant Register Ack");
+ message.setResult(true);
+ super.send(message);
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterListener.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterListener.java
new file mode 100644
index 000000000..a4d8c7697
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantRegisterListener.java
@@ -0,0 +1,67 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
+import org.onap.policy.clamp.controlloop.runtime.config.messaging.Listener;
+import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.listeners.ScoListener;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Listener for ParticipantRegister messages sent by participants.
+ */
+@Component
+public class ParticipantRegisterListener extends ScoListener<ParticipantRegister> implements Listener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantRegisterListener.class);
+
+ private final SupervisionHandler supervisionHandler;
+
+ /**
+ * Constructs the object.
+ */
+ public ParticipantRegisterListener(SupervisionHandler supervisionHandler) {
+ super(ParticipantRegister.class);
+ this.supervisionHandler = supervisionHandler;
+ }
+
+ @Override
+ public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
+ final ParticipantRegister participantRegisterMessage) {
+ LOGGER.debug("ParticipantRegister message received from participant - {}", participantRegisterMessage);
+ supervisionHandler.handleParticipantMessage(participantRegisterMessage);
+ }
+
+ @Override
+ public String getType() {
+ return ParticipantMessageType.PARTICIPANT_REGISTER.name();
+ }
+
+ @Override
+ public ScoListener<ParticipantRegister> getScoListener() {
+ return this;
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusListener.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusListener.java
index 8fa076240..9da886026 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusListener.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusListener.java
@@ -52,7 +52,7 @@ public class ParticipantStatusListener extends ScoListener<ParticipantStatus> im
public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
final ParticipantStatus participantStatusMessage) {
LOGGER.debug("ParticipantStatus message received from participant - {}", participantStatusMessage);
- supervisionHandler.handleParticipantStatusMessage(participantStatusMessage);
+ supervisionHandler.handleParticipantMessage(participantStatusMessage);
}
@Override
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusReqPublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusReqPublisher.java
new file mode 100644
index 000000000..69d598285
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantStatusReqPublisher.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import java.time.Instant;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatusReq;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ParticipantStatusReqPublisher extends AbstractParticipantPublisher<ParticipantStatusReq> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantStatusReqPublisher.class);
+
+ /**
+ * Send ParticipantStatusReq to Participant.
+ *
+ * @param participantId the participant Id
+ */
+ public void send(ToscaConceptIdentifier participantId) {
+ ParticipantStatusReq message = new ParticipantStatusReq();
+ message.setParticipantId(participantId);
+ message.setTimestamp(Instant.now());
+
+ LOGGER.debug("Participant StatusReq sent {}", message);
+ super.send(message);
+ }
+}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdateAckListener.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdateAckListener.java
new file mode 100644
index 000000000..4eeb0a8ce
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdateAckListener.java
@@ -0,0 +1,67 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.controlloop.runtime.config.messaging.Listener;
+import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.listeners.ScoListener;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Listener for ParticipantUpdateAck messages sent by participants.
+ */
+@Component
+public class ParticipantUpdateAckListener extends ScoListener<ParticipantUpdateAck> implements Listener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdateAckListener.class);
+
+ private final SupervisionHandler supervisionHandler;
+
+ /**
+ * Constructs the object.
+ */
+ public ParticipantUpdateAckListener(SupervisionHandler supervisionHandler) {
+ super(ParticipantUpdateAck.class);
+ this.supervisionHandler = supervisionHandler;
+ }
+
+ @Override
+ public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
+ final ParticipantUpdateAck participantUpdateAckMessage) {
+ LOGGER.debug("ParticipantUpdateAck message received from participant - {}", participantUpdateAckMessage);
+ supervisionHandler.handleParticipantMessage(participantUpdateAckMessage);
+ }
+
+ @Override
+ public String getType() {
+ return ParticipantMessageType.PARTICIPANT_UPDATE_ACK.name();
+ }
+
+ @Override
+ public ScoListener<ParticipantUpdateAck> getScoListener() {
+ return this;
+ }
+}
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
new file mode 100644
index 000000000..88cf90d02
--- /dev/null
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
@@ -0,0 +1,82 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import java.time.Instant;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
+import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class is used to send ParticipantUpdate messages to participants on DMaaP.
+ */
+@Component
+@AllArgsConstructor
+public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
+
+ private final CommissioningProvider commissioningProvider;
+
+ /**
+ * Send ParticipantUpdate to Participant.
+ *
+ * @param participantId the participant Id
+ * @param participantType the participant Type
+ */
+ public void send(ToscaConceptIdentifier participantId, ToscaConceptIdentifier participantType) {
+ var message = new ParticipantUpdate();
+ message.setParticipantId(participantId);
+ message.setParticipantType(participantType);
+ message.setTimestamp(Instant.now());
+
+ var clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setId(UUID.randomUUID());
+
+ try {
+ clDefinition.setControlLoopElementToscaServiceTemplate(
+ commissioningProvider.getToscaServiceTemplate(null, null));
+ } catch (PfModelException pfme) {
+ LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
+ return;
+ }
+
+ Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>();
+ controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition);
+
+ Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap =
+ new LinkedHashMap<>();
+ participantDefinitionUpdateMap.put(participantId, controlLoopElementDefinitionMap);
+ message.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
+
+ LOGGER.debug("Participant Update sent {}", message);
+ super.send(message);
+ }
+}
diff --git a/runtime-controlloop/src/main/resources/application.yaml b/runtime-controlloop/src/main/resources/application.yaml
index af9966d40..d0e5500d6 100644
--- a/runtime-controlloop/src/main/resources/application.yaml
+++ b/runtime-controlloop/src/main/resources/application.yaml
@@ -19,4 +19,33 @@ server:
runtime:
- file: src/main/resources/parameters/ClRuntimeParameters.json
+ supervisionScannerIntervalSec: 1000
+ participantClUpdateIntervalSec: 1000
+ participantClStateChangeIntervalSec: 1000
+ participantParameters:
+ heartBeatMs: 120000
+ updateParameters:
+ maxRetryCount: 1
+ maxWaitMs: 30000
+ databaseProviderParameters:
+ name: PolicyProviderParameterGroup
+ implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
+ databaseDriver: org.mariadb.jdbc.Driver
+ databaseUrl: jdbc:mariadb://${mariadb.host:localhost}:${mariadb.port:3306}/controlloop
+ databaseUser: policy
+ databasePassword: P01icY
+ persistenceUnit: CommissioningMariaDb
+ topicParameterGroup:
+ topicSources:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
+ fetchTimeout: 15000
+ topicSinks:
+ -
+ topic: POLICY-CLRUNTIME-PARTICIPANT
+ servers:
+ - ${topicServer:localhost}
+ topicCommInfrastructure: dmaap
diff --git a/runtime-controlloop/src/main/resources/parameters/ClRuntimeParameters.json b/runtime-controlloop/src/main/resources/parameters/ClRuntimeParameters.json
deleted file mode 100644
index 00ca7f9a6..000000000
--- a/runtime-controlloop/src/main/resources/parameters/ClRuntimeParameters.json
+++ /dev/null
@@ -1,56 +0,0 @@
-{
- "name": "ControlLoopRuntimeGroup",
- "supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
- "participantClUpdateIntervalSec": 1000,
- "participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "0.0.0.0",
- "port": 6969,
- "userName": "healthcheck",
- "password": "zb!XztG34",
- "https": false,
- "aaf": false
- },
- "participantParameters": {
- "heartBeatMs": 120000,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.mariadb.jdbc.Driver",
- "databaseUrl": "jdbc:mariadb://mariadb:3306/controlloop",
- "databaseUser": "policy",
- "databasePassword": "P01icY",
- "persistenceUnit": "CommissioningMariaDb"
- },
- "topicParameterGroup": {
- "topicSources": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap",
- "fetchTimeout": 15000
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
-}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
index 440380781..448df4199 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
@@ -31,9 +31,6 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
-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.provider.PolicyModelsProvider;
@@ -46,31 +43,11 @@ class CommissioningProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML =
"src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml";
private static final String TEMPLATE_IS_NULL = ".*serviceTemplate is marked non-null but is null";
- private static final Coder CODER = new StandardCoder();
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
- private static int dbNum = 0;
- private static final Object lockit = new Object();
private PolicyModelsProvider modelsProvider = null;
private ControlLoopProvider clProvider = null;
- private static String getParameterGroupAsString() {
- dbNum++;
- return ResourceUtils.getResourceAsString("src/test/resources/parameters/TestParameters.json")
- .replace("jdbc:h2:mem:testdb", "jdbc:h2:mem:commissioningdb" + dbNum);
- }
-
- /**
- * return a Cl Runtime Parameters.
- *
- * @throws CoderException .
- */
- public ClRuntimeParameterGroup getClRuntimeParameterGroup() throws CoderException {
- synchronized (lockit) {
- return CODER.decode(getParameterGroupAsString(), ClRuntimeParameterGroup.class);
- }
- }
-
@AfterEach
void close() throws Exception {
if (modelsProvider != null) {
@@ -88,7 +65,7 @@ class CommissioningProviderTest {
*/
@Test
void testGetControlLoopDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
@@ -125,7 +102,7 @@ class CommissioningProviderTest {
*/
@Test
void testCreateControlLoopDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("createCLDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
@@ -154,7 +131,7 @@ class CommissioningProviderTest {
*/
@Test
void testDeleteControlLoopDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("deleteCLDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
@@ -182,7 +159,7 @@ class CommissioningProviderTest {
*/
@Test
void testGetControlLoopElementDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLElDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
index 2b4abaa3b..461c8b558 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
@@ -33,8 +33,8 @@ import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
-import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterHandler;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusListener;
+import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
@@ -52,8 +52,7 @@ class MessageDispatcherActivatorTest {
@Test
void testStartAndStop() throws Exception {
- final String path = "src/test/resources/parameters/TestParameters.json";
- ClRuntimeParameterGroup parameterGroup = new ClRuntimeParameterHandler().getParameters(path);
+ ClRuntimeParameterGroup parameterGroup = CommonTestData.geParameterGroup("dbtest");
var publisherFirst = spy(mock(Publisher.class));
var publisherSecond = spy(mock(Publisher.class));
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
index 1d7a00b18..c414ffa02 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
@@ -43,8 +43,11 @@ import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProv
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
-import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantControlLoopStateChangePublisher;
-import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantControlLoopUpdatePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
@@ -97,7 +100,7 @@ class ControlLoopInstantiationProviderTest {
*/
@BeforeAll
public static void setupDbProviderParameters() throws PfModelException {
- ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup(0, "instantproviderdb");
+ ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb");
modelsProvider =
CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
@@ -110,10 +113,14 @@ class ControlLoopInstantiationProviderTest {
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
- var controlLoopUpdatePublisher = Mockito.mock(ParticipantControlLoopUpdatePublisher.class);
- var controlLoopStateChangePublisher = Mockito.mock(ParticipantControlLoopStateChangePublisher.class);
+ var controlLoopUpdatePublisher = Mockito.mock(ControlLoopUpdatePublisher.class);
+ var controlLoopStateChangePublisher = Mockito.mock(ControlLoopStateChangePublisher.class);
+ var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
+ var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
+ var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider,
- controlLoopUpdatePublisher, controlLoopStateChangePublisher);
+ controlLoopUpdatePublisher, controlLoopStateChangePublisher,
+ participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
}
@AfterAll
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
index c47211a2d..5f885ec97 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
@@ -97,7 +97,7 @@ class TestMonitoringProvider {
@Test
void testCreateParticipantStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "createparStat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("createparStat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
@@ -123,7 +123,7 @@ class TestMonitoringProvider {
@Test
void testGetParticipantStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getparStat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getparStat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
@@ -156,7 +156,7 @@ class TestMonitoringProvider {
@Test
void testCreateClElementStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "createelemstat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("createelemstat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
@@ -183,14 +183,13 @@ class TestMonitoringProvider {
@Test
void testGetClElementStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getelemstat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
MonitoringProvider provider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
-
assertThatThrownBy(() -> {
provider.fetchFilteredClElementStatistics(null, null, null, null, null, 0);
}).hasMessageMatching("name is marked .*null but is null");
@@ -217,7 +216,7 @@ class TestMonitoringProvider {
@Test
void testGetParticipantStatsPerCL() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getparStatCL");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getparStatCL");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
var mockClProvider = Mockito.mock(ControlLoopProvider.class);
@@ -253,7 +252,7 @@ class TestMonitoringProvider {
mockCL.setElements(new LinkedHashMap<>());
mockCL.getElements().put(mockClElement.getId(), mockClElement);
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstatPerCL");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getelemstatPerCL");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
ControlLoopProvider mockClProvider = Mockito.mock(ControlLoopProvider.class);
@@ -265,8 +264,8 @@ class TestMonitoringProvider {
monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- ClElementStatisticsList getResponse;
- getResponse = monitoringProvider.fetchClElementStatsPerControlLoop("testCLName", "1.001");
+ ClElementStatisticsList getResponse =
+ monitoringProvider.fetchClElementStatsPerControlLoop("testCLName", "1.001");
assertThat(getResponse.getClElementStatistics()).hasSize(2);
assertEquals(getResponse.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""),
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounterTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounterTest.java
new file mode 100644
index 000000000..51f3b4a32
--- /dev/null
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/HandleCounterTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.runtime.supervision;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class HandleCounterTest {
+
+ private static final int ID = 1;
+
+ @Test
+ void testCount() {
+ var handleCounter = new HandleCounter<Integer>();
+ handleCounter.setMaxRetryCount(2);
+ assertThat(handleCounter.count(ID)).isTrue();
+ assertThat(handleCounter.getCounter(ID)).isEqualTo(1);
+ assertThat(handleCounter.count(ID)).isTrue();
+ assertThat(handleCounter.getCounter(ID)).isEqualTo(2);
+ assertThat(handleCounter.count(ID)).isFalse();
+ assertThat(handleCounter.getCounter(ID)).isEqualTo(2);
+
+ handleCounter.clear(ID);
+ assertThat(handleCounter.count(ID)).isTrue();
+ assertThat(handleCounter.getCounter(ID)).isEqualTo(1);
+ }
+
+ @Test
+ void testFault() {
+ var handleCounter = new HandleCounter<Integer>();
+ handleCounter.setFault(ID);
+ assertThat(handleCounter.isFault(ID)).isTrue();
+ handleCounter.clear(ID);
+ assertThat(handleCounter.isFault(ID)).isFalse();
+ }
+
+ @Test
+ void testDuration() throws InterruptedException {
+
+ var handleCounter = new HandleCounter<Integer>() {
+ long epochMilli = 0;
+
+ @Override
+ protected long getEpochMilli() {
+ return epochMilli;
+ }
+ };
+ handleCounter.epochMilli = 100;
+ var result = handleCounter.getDuration(ID);
+ assertThat(result).isZero();
+
+ handleCounter.epochMilli += 100;
+ result = handleCounter.getDuration(ID);
+ assertThat(result).isEqualTo(100);
+
+ handleCounter.epochMilli += 100;
+ result = handleCounter.getDuration(ID);
+ assertThat(result).isEqualTo(200);
+
+ handleCounter.epochMilli += 100;
+ handleCounter.clear(ID);
+ result = handleCounter.getDuration(ID);
+ assertThat(result).isZero();
+ }
+}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java
new file mode 100644
index 000000000..30ee9b1b9
--- /dev/null
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java
@@ -0,0 +1,66 @@
+/*-
+ * ============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.runtime.supervision;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class SupervisionAspectTest {
+
+ @Test
+ void testSchedule() throws Exception {
+ var supervisionScanner = spy(mock(SupervisionScanner.class));
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ supervisionAspect.schedule();
+ verify(supervisionScanner, timeout(500)).run(eq(true));
+ }
+ }
+
+ @Test
+ void testDoCheck() throws Exception {
+ var supervisionScanner = spy(mock(SupervisionScanner.class));
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ supervisionAspect.doCheck();
+ supervisionAspect.doCheck();
+ verify(supervisionScanner, timeout(500).times(2)).run(eq(false));
+ }
+ }
+
+ @Test
+ void testHandleParticipantStatus() throws Exception {
+ var supervisionScanner = spy(mock(SupervisionScanner.class));
+ var participantStatusMessage = new ParticipantStatus();
+ var identifier = new ToscaConceptIdentifier("abc", "1.0.0");
+ participantStatusMessage.setParticipantId(identifier);
+
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ supervisionAspect.handleParticipantStatus(participantStatusMessage);
+ verify(supervisionScanner, timeout(500)).handleParticipantStatus(eq(identifier));
+ }
+ }
+}
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
new file mode 100644
index 000000000..485f58dba
--- /dev/null
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
@@ -0,0 +1,160 @@
+/*-
+ * ============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.runtime.supervision;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusReqPublisher;
+import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class SupervisionScannerTest {
+
+ @Test
+ void testScannerOrderedStateEqualsToState() throws PfModelException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
+ var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+
+ var controlLoop = new ControlLoop();
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+
+ var supervisionScanner =
+ new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher, controlLoopUpdatePublisher,
+ participantProvider, participantStatusReqPublisher, clRuntimeParameterGroup);
+ supervisionScanner.run(false);
+
+ verify(controlLoopProvider, times(0)).updateControlLoop(any(ControlLoop.class));
+ }
+
+ @Test
+ void testScannerOrderedStateDifferentToState() throws PfModelException {
+ var controlLoop = new ControlLoop();
+ controlLoop.setState(ControlLoopState.UNINITIALISED2PASSIVE);
+ controlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+ controlLoop.setElements(Map.of(UUID.randomUUID(), new ControlLoopElement()));
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
+ var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+
+ var supervisionScanner =
+ new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher, controlLoopUpdatePublisher,
+ participantProvider, participantStatusReqPublisher, clRuntimeParameterGroup);
+ supervisionScanner.run(false);
+
+ verify(controlLoopProvider, times(1)).updateControlLoop(any(ControlLoop.class));
+ }
+
+ @Test
+ void testScanner() throws PfModelException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoop = new ControlLoop();
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+
+ var participantProvider = mock(ParticipantProvider.class);
+ var participant = new Participant();
+ participant.setName("Participant0");
+ participant.setVersion("1.0.0");
+ when(participantProvider.getParticipants(null, null)).thenReturn(List.of(participant));
+
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
+ var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
+ var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+
+ var supervisionScanner =
+ new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher, controlLoopUpdatePublisher,
+ participantProvider, participantStatusReqPublisher, clRuntimeParameterGroup);
+
+ supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
+ supervisionScanner.run(true);
+ verify(controlLoopProvider, times(0)).updateControlLoop(any(ControlLoop.class));
+ verify(participantStatusReqPublisher, times(0)).send(any(ToscaConceptIdentifier.class));
+ }
+
+ @Test
+ void testScanParticipant() throws PfModelException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoop = new ControlLoop();
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+
+ var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
+ clRuntimeParameterGroup.getParticipantParameters().setMaxMessageAgeMs(0);
+
+ var participant = new Participant();
+ participant.setName("Participant0");
+ participant.setVersion("1.0.0");
+ participant.setHealthStatus(ParticipantHealthStatus.HEALTHY);
+ participant.setParticipantState(ParticipantState.ACTIVE);
+ participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0"));
+ var participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider.updateParticipants(List.of(participant));
+
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
+ var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
+
+ var supervisionScanner =
+ new SupervisionScanner(controlLoopProvider, controlLoopStateChangePublisher, controlLoopUpdatePublisher,
+ participantProvider, participantStatusReqPublisher, clRuntimeParameterGroup);
+
+ supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
+ supervisionScanner.run(true);
+ verify(participantStatusReqPublisher, times(1)).send(any(ToscaConceptIdentifier.class));
+
+ List<Participant> participants = participantProvider.getParticipants(null, null);
+ 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
new file mode 100644
index 000000000..5f00706e1
--- /dev/null
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -0,0 +1,226 @@
+/*-
+ * ============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.runtime.supervision.comm;
+
+import java.time.Instant;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+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;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantStatisticsProvider;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
+import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
+import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
+import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
+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.YamlJsonTranslator;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+class SupervisionMessagesTest extends CommonRestController {
+
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML =
+ "src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml";
+ private static final Object lockit = new Object();
+ private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
+ private static final String TOPIC = "my-topic";
+ private static final long interval = 1000;
+ private static SupervisionHandler supervisionHandler;
+ private static CommissioningProvider commissioningProvider;
+ private static ControlLoopProvider clProvider;
+ private static PolicyModelsProvider modelsProvider;
+ private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
+
+ /**
+ * setup Db Provider Parameters.
+ *
+ * @throws PfModelException if an error occurs
+ */
+ @BeforeAll
+ public static void setupDbProviderParameters() throws PfModelException {
+ ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb");
+
+ modelsProvider =
+ CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var participantStatisticsProvider =
+ new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var clElementStatisticsProvider =
+ new ClElementStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
+ commissioningProvider = new CommissioningProvider(modelsProvider, clProvider);
+ var monitoringProvider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
+ var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var controlLoopUpdatePublisher = Mockito.mock(ControlLoopUpdatePublisher.class);
+ var controlLoopStateChangePublisher = Mockito.mock(ControlLoopStateChangePublisher.class);
+ var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
+ var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
+ var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
+ supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider,
+ controlLoopUpdatePublisher, controlLoopStateChangePublisher,
+ participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
+ }
+
+ @AfterAll
+ public static void closeDbProvider() throws PfModelException {
+ clProvider.close();
+ modelsProvider.close();
+ }
+
+ @Test
+ void testReceiveParticipantRegister() throws Exception {
+ final ParticipantRegister participantRegisterMsg = new ParticipantRegister();
+ participantRegisterMsg.setParticipantId(getParticipantId());
+ participantRegisterMsg.setTimestamp(Instant.now());
+ participantRegisterMsg.setParticipantType(getParticipantType());
+
+ synchronized (lockit) {
+ ParticipantRegisterListener participantRegisterListener =
+ new ParticipantRegisterListener(supervisionHandler);
+ ToscaServiceTemplate serviceTemplate = yamlTranslator
+ .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+
+ List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null);
+ commissioningProvider.createControlLoopDefinitions(serviceTemplate);
+ participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg);
+ }
+ }
+
+ @Test
+ void testSendParticipantRegisterAck() throws Exception {
+ final ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck();
+ participantRegisterAckMsg.setMessage("ParticipantRegisterAck message");
+ participantRegisterAckMsg.setResponseTo(UUID.randomUUID());
+ participantRegisterAckMsg.setResult(true);
+
+ synchronized (lockit) {
+ ParticipantRegisterAckPublisher clRegisterAckPublisher = new ParticipantRegisterAckPublisher();
+ clRegisterAckPublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ clRegisterAckPublisher.send(participantRegisterAckMsg);
+ }
+ }
+
+ @Test
+ void testReceiveParticipantDeregister() throws Exception {
+ final ParticipantDeregister participantDeregisterMsg = new ParticipantDeregister();
+ participantDeregisterMsg.setParticipantId(getParticipantId());
+ participantDeregisterMsg.setTimestamp(Instant.now());
+ participantDeregisterMsg.setParticipantType(getParticipantType());
+
+ synchronized (lockit) {
+ ParticipantDeregisterListener participantDeregisterListener =
+ new ParticipantDeregisterListener(supervisionHandler);
+ participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg);
+ }
+ }
+
+ @Test
+ void testSendParticipantDeregisterAck() throws Exception {
+ final ParticipantDeregisterAck participantDeregisterAckMsg = new ParticipantDeregisterAck();
+ participantDeregisterAckMsg.setMessage("ParticipantDeregisterAck message");
+ participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
+ participantDeregisterAckMsg.setResult(true);
+
+ synchronized (lockit) {
+ ParticipantDeregisterAckPublisher clDeregisterAckPublisher = new ParticipantDeregisterAckPublisher();
+ clDeregisterAckPublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ clDeregisterAckPublisher.send(participantDeregisterAckMsg);
+ }
+ }
+
+ @Test
+ void testSendParticipantUpdate() throws Exception {
+ final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
+ participantUpdateMsg.setParticipantId(getParticipantId());
+ participantUpdateMsg.setTimestamp(Instant.now());
+ participantUpdateMsg.setParticipantType(getParticipantType());
+ participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
+ participantUpdateMsg.setMessageId(UUID.randomUUID());
+
+ ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
+ toscaServiceTemplate.setName("serviceTemplate");
+ toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
+ toscaServiceTemplate.setDescription("Description of serviceTemplate");
+ toscaServiceTemplate.setVersion("1.2.3");
+
+ ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
+ clDefinition.setId(UUID.randomUUID());
+ clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate);
+ Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+ clDefinition.setCommonPropertiesMap(commonPropertiesMap);
+
+ Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap =
+ Map.of(UUID.randomUUID(), clDefinition);
+
+ Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
+ participantDefinitionUpdateMap = Map.of(getParticipantId(), controlLoopElementDefinitionMap);
+ participantUpdateMsg.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
+
+ synchronized (lockit) {
+ ParticipantUpdatePublisher clUpdatePublisher = new ParticipantUpdatePublisher(commissioningProvider);
+ clUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ clUpdatePublisher.send(participantUpdateMsg);
+ }
+ }
+
+ @Test
+ void testReceiveParticipantUpdateAckMessage() throws Exception {
+ final ParticipantUpdateAck participantUpdateAckMsg = new ParticipantUpdateAck();
+ participantUpdateAckMsg.setMessage("ParticipantUpdateAck message");
+ participantUpdateAckMsg.setResponseTo(UUID.randomUUID());
+ participantUpdateAckMsg.setResult(true);
+
+ synchronized (lockit) {
+ ParticipantUpdateAckListener participantUpdateAckListener =
+ new ParticipantUpdateAckListener(supervisionHandler);
+ participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg);
+ }
+ }
+
+ private ToscaConceptIdentifier getParticipantId() {
+ return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
+ }
+
+ private ToscaConceptIdentifier getParticipantType() {
+ return new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+ }
+}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
index 464c14354..300c662ce 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
@@ -38,19 +38,18 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
*
*/
public class CommonTestData {
- private static final Coder coder = new StandardCoder();
+ private static final Coder CODER = new StandardCoder();
/**
* Gets the standard Control Loop parameters.
*
- * @param port port to be inserted into the parameters
* @param dbName the database name
* @return the standard Control Loop parameters
* @throws ControlLoopRuntimeException on errors reading the control loop parameters
*/
- public static ClRuntimeParameterGroup geParameterGroup(final int port, final String dbName) {
+ public static ClRuntimeParameterGroup geParameterGroup(final String dbName) {
try {
- return coder.decode(getParameterGroupAsString(port, dbName), ClRuntimeParameterGroup.class);
+ return CODER.convert(getParameterGroupAsString(dbName), ClRuntimeParameterGroup.class);
} catch (CoderException e) {
throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, "cannot read Control Loop parameters", e);
@@ -60,13 +59,12 @@ public class CommonTestData {
/**
* Gets the standard Control Loop parameters, as a String.
*
- * @param port port to be inserted into the parameters
* @param dbName the database name
* @return the standard Control Loop parameters as string
*/
- public static String getParameterGroupAsString(final int port, final String dbName) {
- return ResourceUtils.getResourceAsString("src/test/resources/parameters/InstantiationConfigParametersStd.json")
- .replace("${port}", String.valueOf(port)).replace("${dbName}", "jdbc:h2:mem:" + dbName);
+ public static String getParameterGroupAsString(final String dbName) {
+ return ResourceUtils.getResourceAsString("src/test/resources/parameters/TestParameters.json")
+ .replace("${dbName}", "jdbc:h2:mem:" + dbName);
}
/**
diff --git a/runtime-controlloop/src/test/resources/application_test.properties b/runtime-controlloop/src/test/resources/application_test.properties
index fc24ea290..ad2a4b12c 100644
--- a/runtime-controlloop/src/test/resources/application_test.properties
+++ b/runtime-controlloop/src/test/resources/application_test.properties
@@ -6,4 +6,25 @@ server.port=6969
server.servlet.context-path=/onap/controlloop
server.error.path=/error
-runtime.file=src/test/resources/parameters/TestParameters.json
+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.databaseProviderParameters.name=PolicyProviderParameterGroup
+runtime.databaseProviderParameters.implementation=org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
+runtime.databaseProviderParameters.databaseDriver=org.h2.Driver
+runtime.databaseProviderParameters.databaseUrl=jdbc:h2:mem:testdb
+runtime.databaseProviderParameters.databaseUser=policy
+runtime.databaseProviderParameters.databasePassword=P01icY
+runtime.databaseProviderParameters.persistenceUnit=ToscaConceptTest
+runtime.topicParameterGroup.topicSources[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+runtime.topicParameterGroup.topicSources[0].servers[0]=localhost
+runtime.topicParameterGroup.topicSources[0].topicCommInfrastructure=dmaap
+runtime.topicParameterGroup.topicSources[0].fetchTimeout=15000
+runtime.topicParameterGroup.topicSinks[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+runtime.topicParameterGroup.topicSinks[0].servers[0]=localhost
+runtime.topicParameterGroup.topicSinks[0].topicCommInfrastructure=dmaap
diff --git a/runtime-controlloop/src/test/resources/parameters/CommissioningConfig.json b/runtime-controlloop/src/test/resources/parameters/CommissioningConfig.json
deleted file mode 100644
index 762e3f793..000000000
--- a/runtime-controlloop/src/test/resources/parameters/CommissioningConfig.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "name": "CommissioningGroup",
- "supervisionScannerIntervalSec" : 1000,
- "participantStateChangeIntervalSec" : 1000,
- "participantClUpdateIntervalSec" : 1000,
- "participantClStateChangeIntervalSec" : 1000,
- "restServerParameters": {
- "host": "127.0.0.1",
- "port": 6969,
- "userName": "admin",
- "password": "password",
- "https": false,
- "aaf": false
- },
- "databaseProviderParameters": {
- "name": "CommissioningProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.h2.Driver",
- "databaseUrl": "jdbc:h2:mem:testdb",
- "databaseUser": "controlloop",
- "databasePassword": "C0ntr0lL00p",
- "persistenceUnit": "ToscaConceptTest"
- }
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/EmptyParameters.json b/runtime-controlloop/src/test/resources/parameters/EmptyParameters.json
deleted file mode 100644
index e69de29bb..000000000
--- a/runtime-controlloop/src/test/resources/parameters/EmptyParameters.json
+++ /dev/null
diff --git a/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParametersStd.json b/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParametersStd.json
deleted file mode 100644
index 06f4370e8..000000000
--- a/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParametersStd.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
- "name": "ControlLoopRuntimeGroup",
- "supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
- "participantClUpdateIntervalSec": 1000,
- "participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "0.0.0.0",
- "port": ${port},
- "userName": "healthcheck",
- "password": "zb!XztG34",
- "https": false,
- "aaf": false
- },
- "participantParameters": {
- "heartBeatMs": 120000,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.h2.Driver",
- "databaseUrl": "${dbName}",
- "databaseUser": "policy",
- "databasePassword": "P01icY",
- "persistenceUnit": "InstantiationTests"
- },
- "topicParameterGroup": {
- "topicSources": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap",
- "fetchTimeout": 15000
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_InvalidName.json b/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_InvalidName.json
deleted file mode 100644
index 944bc770d..000000000
--- a/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_InvalidName.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "name": " ",
- "supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
- "participantClUpdateIntervalSec": 1000,
- "participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "127.0.0.1",
- "port": 6969,
- "userName": "admin",
- "password": "password",
- "https": false,
- "aaf": false
- },
- "pdpParameters": {
- "heartBeatMs": 1,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 1
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 1
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.h2.Driver",
- "databaseUrl": "jdbc:h2:mem:testdb",
- "databaseUser": "policy",
- "databasePassword": "P01icY",
- "persistenceUnit": "PdpGroupTest"
- }
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_sim.json b/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_sim.json
deleted file mode 100644
index 47cb74838..000000000
--- a/runtime-controlloop/src/test/resources/parameters/InstantiationConfigParameters_sim.json
+++ /dev/null
@@ -1,55 +0,0 @@
-{
- "name": "Instantiation",
- "supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
- "participantClUpdateIntervalSec": 1000,
- "participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "127.0.0.1",
- "port": 6969,
- "userName": "admin",
- "password": "password",
- "https": false,
- "aaf": false
- },
- "pdpParameters": {
- "heartBeatMs": 10,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.mariadb.jdbc.Driver",
- "databaseUrl": "jdbc:mariadb://localhost:3306/policyadmin",
- "databaseUser": "policy",
- "databasePassword": "UDAxaWNZ",
- "persistenceUnit": "PolicyMariaDb"
- },
- "topicParameterGroup": {
- "topicSources": [
- {
- "topic": "INSTANTIATION",
- "servers": [
- "localhost:6845"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ],
- "topicSinks": [
- {
- "topic": "INSTANTIATION",
- "servers": [
- "localhost:6845"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/InvalidParameters.json b/runtime-controlloop/src/test/resources/parameters/InvalidParameters.json
deleted file mode 100644
index 976ec2937..000000000
--- a/runtime-controlloop/src/test/resources/parameters/InvalidParameters.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "name": ""
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/MinimumParametersH2.json b/runtime-controlloop/src/test/resources/parameters/MinimumParametersH2.json
deleted file mode 100644
index 2be642943..000000000
--- a/runtime-controlloop/src/test/resources/parameters/MinimumParametersH2.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "name": "PapGroup",
- "supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
- "participantClUpdateIntervalSec": 1000,
- "participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "0.0.0.0",
- "port": 6969,
- "userName": "healthcheck",
- "password": "zb!XztG34"
- },
- "pdpParameters": {
- "heartBeatMs": 1,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 1
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 1
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.h2.Driver",
- "databaseUrl": "jdbc:h2:mem:testdb",
- "databaseUser": "policy",
- "databasePassword": "P01icY",
- "persistenceUnit": "PdpGroupTest"
- },
- "topicParameterGroup": {
- "topicSources": [
- {
- "topic": "POLICY-PDP-PAP",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-PDP-PAP",
- "servers": [
- "message-router"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/NoParameters.json b/runtime-controlloop/src/test/resources/parameters/NoParameters.json
deleted file mode 100644
index 2c63c0851..000000000
--- a/runtime-controlloop/src/test/resources/parameters/NoParameters.json
+++ /dev/null
@@ -1,2 +0,0 @@
-{
-}
diff --git a/runtime-controlloop/src/test/resources/parameters/TestParameters.json b/runtime-controlloop/src/test/resources/parameters/TestParameters.json
index 680e070f2..99fc43d21 100644
--- a/runtime-controlloop/src/test/resources/parameters/TestParameters.json
+++ b/runtime-controlloop/src/test/resources/parameters/TestParameters.json
@@ -1,17 +1,8 @@
{
"name": "ControlLoopRuntimeGroup",
"supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
"participantClUpdateIntervalSec": 1000,
"participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "0.0.0.0",
- "port": 6969,
- "userName": "healthcheck",
- "password": "zb!XztG34",
- "https": false,
- "aaf": false
- },
"participantParameters": {
"heartBeatMs": 120000,
"updateParameters": {
@@ -27,10 +18,10 @@
"name": "PolicyProviderParameterGroup",
"implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
"databaseDriver": "org.h2.Driver",
- "databaseUrl": "jdbc:h2:mem:testdb",
+ "databaseUrl": "${dbName}",
"databaseUser": "policy",
"databasePassword": "P01icY",
- "persistenceUnit": "ToscaConceptTest"
+ "persistenceUnit": "InstantiationTests"
},
"topicParameterGroup": {
"topicSources": [
diff --git a/runtime-controlloop/src/test/resources/parameters/Unreadable.json b/runtime-controlloop/src/test/resources/parameters/Unreadable.json
deleted file mode 100644
index 0ea56eb5d..000000000
--- a/runtime-controlloop/src/test/resources/parameters/Unreadable.json
+++ /dev/null
@@ -1,62 +0,0 @@
-{
- "name": "ControlLoopRuntimeGroup",
- "supervisionScannerIntervalSec": 1000,
- "participantStateChangeIntervalSec": 1000,
- "participantClUpdateIntervalSec": 1000,
- "participantClStateChangeIntervalSec": 1000,
- "restServerParameters": {
- "host": "0.0.0.0",
- "port": 6969,
- "userName": "healthcheck",
- "password": "zb!XztG34",
- "https": false,
- "aaf": false
- },
- "participantParameters": {
- "heartBeatMs": 120000,
- "updateParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- },
- "stateChangeParameters": {
- "maxRetryCount": 1,
- "maxWaitMs": 30000
- }
- },
- "databaseProviderParameters": {
- "name": "PolicyProviderParameterGroup",
- "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
- "databaseDriver": "org.h2.Driver",
- "databaseUrl": "jdbc:h2:mem:testdb",
- "databaseUser": "policy",
- "databasePassword": "P01icY",
- "persistenceUnit": "ToscaConceptTest"
- },
- "topicParameterGroup": {
- "topicSources": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap",
- "fetchTimeout": 15000
- }
- ],
- "topicSinks": [
- {
- "topic": "POLICY-CLRUNTIME-PARTICIPANT",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap"
- }
- ]
- }
diff --git a/runtime/extra/sql/bulkload/create-db.sql b/runtime/extra/sql/bulkload/create-db.sql
index ea4d97c1b..5fa34ca04 100644
--- a/runtime/extra/sql/bulkload/create-db.sql
+++ b/runtime/extra/sql/bulkload/create-db.sql
@@ -7,5 +7,9 @@ USE `cldsdb4`;
DROP USER 'clds';
CREATE USER 'clds';
GRANT ALL on cldsdb4.* to 'clds' identified by 'sidnnd83K' with GRANT OPTION;
+CREATE DATABASE `controlloop`;
+USE `controlloop`;
+DROP USER 'policy';
+CREATE USER 'policy';
+GRANT ALL on controlloop.* to 'policy' identified by 'P01icY' with GRANT OPTION;
FLUSH PRIVILEGES;
-
diff --git a/runtime/pom.xml b/runtime/pom.xml
index 444bc325e..3a8ece35b 100644
--- a/runtime/pom.xml
+++ b/runtime/pom.xml
@@ -97,6 +97,9 @@
<ui.react.src>ui-react</ui.react.src>
<ui.react.lib.src>ui-react-lib</ui.react.lib.src>
<npm.publish.url>https://nexus3.onap.org/repository/npm.snapshot/</npm.publish.url>
+
+ <!-- This property triggers generation of the Swagger documents -->
+ <swagger.generation.phase>post-integration-test</swagger.generation.phase>
</properties>
<profiles>
@@ -152,6 +155,7 @@
</properties>
</profile>
</profiles>
+
<dependencyManagement>
<dependencies>
<dependency>
@@ -555,94 +559,7 @@
</executions>
</plugin>
- <!-- Read the swagger.json file and the definition from SwaggerConfig.java; generate
- a list of .adoc files containing the APIs info in more structured way -->
- <plugin>
- <groupId>io.github.swagger2markup</groupId>
- <artifactId>swagger2markup-maven-plugin</artifactId>
- <version>1.3.3</version>
- <dependencies>
- <dependency>
- <groupId>io.github.swagger2markup</groupId>
- <artifactId>swagger2markup-import-files-ext</artifactId>
- <version>1.3.3</version>
- </dependency>
- <dependency>
- <groupId>io.github.swagger2markup</groupId>
- <artifactId>swagger2markup-spring-restdocs-ext</artifactId>
- <version>1.3.3</version>
- </dependency>
- </dependencies>
- <configuration>
- <swaggerInput>${project.build.directory}/swagger/swagger.json</swaggerInput>
- <outputDir>${project.build.directory}/asciidoc/generated</outputDir>
- <config>
- <swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
- </config>
- </configuration>
- <executions>
- <execution>
- <phase>post-integration-test</phase>
- <goals>
- <goal>convertSwagger2markup</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <!-- Run the generated asciidoc through Asciidoctor to generate other documentation
- types, such as PDFs or HTML5 -->
- <plugin>
- <groupId>org.asciidoctor</groupId>
- <artifactId>asciidoctor-maven-plugin</artifactId>
- <version>1.5.7.1</version>
- <dependencies>
- <dependency>
- <groupId>org.asciidoctor</groupId>
- <artifactId>asciidoctorj-pdf</artifactId>
- <version>1.5.0-alpha.10.1</version>
- </dependency>
- </dependencies>
- <configuration>
- <sourceDirectory>${project.basedir}/src/main/resources/asciidoc</sourceDirectory>
- <sourceDocumentName>swagger.adoc</sourceDocumentName>
- <attributes>
- <doctype>book</doctype>
- <toc>left</toc>
- <toclevels>3</toclevels>
- <numbered/>
- <hardbreaks/>
- <sectlinks/>
- <sectanchors/>
- <generated>${project.build.directory}/asciidoc/generated</generated>
- </attributes>
- </configuration>
- <executions>
- <execution>
- <id>output-html</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>process-asciidoc</goal>
- </goals>
- <configuration>
- <backend>html5</backend>
- <outputDirectory>${project.build.directory}/swagger</outputDirectory>
- </configuration>
- </execution>
- <execution>
- <id>output-pdf</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>process-asciidoc</goal>
- </goals>
- <configuration>
- <backend>pdf</backend>
- <outputDirectory>${project.build.directory}/swagger</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
diff --git a/runtime/src/main/resources/asciidoc/swagger.adoc b/runtime/src/main/resources/asciidoc/swagger.adoc
deleted file mode 100644
index 6896747fd..000000000
--- a/runtime/src/main/resources/asciidoc/swagger.adoc
+++ /dev/null
@@ -1,4 +0,0 @@
-include::{generated}/overview.adoc[]
-include::{generated}/paths.adoc[]
-include::{generated}/security.adoc[]
-include::{generated}/definitions.adoc[] \ No newline at end of file
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 4b07f6458..677ec64c9 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
@@ -1475,7 +1475,7 @@
<constant>application/json</constant>
</setHeader>
<setProperty name="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">true</simple>
+ <simple resultType="java.lang.Boolean">false</simple>
</setProperty>
<to uri="direct:get-service-template"/>
<to
@@ -1509,7 +1509,7 @@
<route>
<removeHeaders pattern="*"/>
<setProperty name="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">true</simple>
+ <simple resultType="java.lang.Boolean">false</simple>
</setProperty>
<setHeader name="Content-Type">
<constant>application/json</constant>
@@ -1543,6 +1543,50 @@
</route>
</post>
+ <delete uri="/v2/toscaControlLoop/decommissionToscaTemplate"
+ 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">true</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:decommission-service-template"/>
+ <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="Decommissioning of Tosca Service Template FAILED"/>
+
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>Decommissioning Tosca Service Template FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </delete>
+
<get uri="/v2/toscaControlLoop/getToscaInstantiation" outType="java.lang.String" bindingMode="off" produces="application/json">
<route>
<doTry>
@@ -1610,6 +1654,111 @@
</route>
</get>
+ <get uri="/v2/toscaControlLoop/getElementDefinitions" outType="java.lang.String" bindingMode="off" produces="application/json">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="name|version|requestId"/>
+ <doTry>
+ <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Json Schema ')"/>
+ <to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')"/>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">true</simple>
+ </setProperty>
+ <to uri="direct:get-element-definitions"/>
+ <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="GET Element Definitions request failed: ${exception.stacktrace}"/>
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>GET JSON Schema FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </get>
+
+ <get uri="/v2/toscaControlLoop/getControlLoopDefinitions" outType="java.lang.String" bindingMode="off" produces="application/json">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="name|version|requestId"/>
+ <doTry>
+ <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Json Schema ')"/>
+ <to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')"/>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">true</simple>
+ </setProperty>
+ <to uri="direct:get-control-loop-definitions"/>
+ <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="GET Control Loop Definitions request failed: ${exception.stacktrace}"/>
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>GET Control Loop Definitions FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </get>
+
+ <get uri="/v2/toscaControlLoop/getCommonOrInstanceProperties" outType="java.lang.String" bindingMode="off" produces="application/json">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="name|version|requestId|common"/>
+ <doTry>
+ <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Common Properties ')"/>
+ <to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')"/>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-common-or-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="GET Common Or Instance Properties request failed: ${exception.stacktrace}"/>
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>GET Common Properties FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </get>
+
<post uri="/v2/toscaControlLoop/postToscaInstantiation"
type="java.lang.String"
consumes="plain/text"
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 6ee2572b3..ff39200b7 100644
--- a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
+++ b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
@@ -54,6 +54,37 @@
</doFinally>
</doTry>
</route>
+ <route id="decommission-service-template">
+ <from uri="direct:decommission-service-template"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Decommissioning the tosca service template"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Controlloop', 'Decommissioning the tosca service template')"/>
+ <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 send Tosca Service Template: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission?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="get-tosca-instantiation">
<from uri="direct:get-tosca-instantiation"/>
<doTry>
@@ -157,4 +188,82 @@
</doFinally>
</doTry>
</route>
+ <route id="get-element-definitions">
+ <from uri="direct:get-element-definitions"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Getting the Control Loop Element Definitions"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('ControlLoop', 'Getting the Controlloop Element Definitions')"/>
+ <setHeader name="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <log loggingLevel="INFO"
+ message="Endpoint to get Json Schema: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/elements"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/elements?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="get-control-loop-definitions">
+ <from uri="direct:get-control-loop-definitions"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Getting the Control Loop Definitions"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('ControlLoop', 'Getting the Controlloop Element Definitions')"/>
+ <setHeader name="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <log loggingLevel="INFO"
+ message="Endpoint to get Json Schema: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/elements"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission? 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="get-common-or-instance-properties">
+ <from uri="direct:get-common-or-instance-properties"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Getting Common Or Instance Properties"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('ControlLoop', 'Getting Common Or Instance Properties')"/>
+ <setHeader name="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="common">
+ <simple>${header.common}</simple>
+ </setProperty>
+ <log loggingLevel="INFO"
+ message="Endpoint to get Common Or Instance Properties: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/getCommonOrInstanceProperties"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/getCommonOrInstanceProperties?common=${exchangeProperty[common]}&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>
</routes>
diff --git a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
index 7616d7a49..f4e171174 100644
--- a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
+++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
@@ -102,4 +102,96 @@ public class RuntimeCommissioningResponseTestItCase {
assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
.is2xxSuccessful()).isTrue();
}
+
+ @Test
+ public void testDecommissioningOfToscaServiceTemplateStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:decommission-service-template", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetControlLoopDefinitions() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-control-loop-definitions", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetControlLoopElementDefinitions() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-element-definitions", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetCommonOrInstancePropertiesCommonTrue() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-common-or-instance-properties", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("common", true)
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetCommonOrInstancePropertiesCommonFalse() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-common-or-instance-properties", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("common", false)
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetCommonOrInstancePropertiesCommonMissing() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-common-or-instance-properties", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
}
diff --git a/runtime/src/test/resources/http-cache/example/node_template.json b/runtime/src/test/resources/http-cache/example/node_template.json
new file mode 100644
index 000000000..fdbfe8563
--- /dev/null
+++ b/runtime/src/test/resources/http-cache/example/node_template.json
@@ -0,0 +1,44 @@
+{
+ "org.onap.domain.pmsh.PMSHControlLoopDefinition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3",
+ "derived_from": null,
+ "metadata": {},
+ "description": "Control loop for Performance Management Subscription Handling",
+ "type": "org.onap.policy.clamp.controlloop.ControlLoop",
+ "type_version": "1.0.0",
+ "properties": {
+ "elements": [
+ {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ }
+ ],
+ "provider": "Ericsson"
+ },
+ "requirements": null,
+ "capabilities": null,
+ "identifier": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3"
+ },
+ "type_identifier": {
+ "name": "org.onap.policy.clamp.controlloop.ControlLoop",
+ "version": "1.0.0"
+ },
+ "key": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3"
+ },
+ "defined_name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "defined_version": "1.2.3"
+ }
+}
diff --git a/runtime/src/test/resources/http-cache/third_party_proxy.py b/runtime/src/test/resources/http-cache/third_party_proxy.py
index 1aaf4024d..013388197 100644
--- a/runtime/src/test/resources/http-cache/third_party_proxy.py
+++ b/runtime/src/test/resources/http-cache/third_party_proxy.py
@@ -107,6 +107,15 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def _get_cached_header_file_name(self,cached_file_folder):
return "%s/.header" % (cached_file_folder,)
+ def _create_cache(self, generated_json, cached_file_folder, cached_file_header, cached_file_content):
+ print "jsonGenerated: " + generated_json
+ if not os.path.exists(cached_file_folder):
+ os.makedirs(cached_file_folder, 0775)
+ with open(cached_file_header, 'w+') as f:
+ f.write("{\"Content-Length\": \"" + str(len(generated_json)) + "\", \"Content-Type\": \"application/json\"}")
+ with open(cached_file_content, 'w+') as f:
+ f.write(generated_json)
+
def _execute_content_generated_cases(self,http_type):
print("Testing special cases, cache files will be sent to :" +TMP_ROOT)
cached_file_folder = self._get_cached_file_folder_name(TMP_ROOT)
@@ -274,14 +283,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print ("cached file folder for onap is %s: ", cached_file_folder)
print "self.path start with /onap/controlloop/v2/commission/, generating response json..."
jsonGenerated = "{\"tosca_definitions_version\": \"tosca_simple_yaml_1_1_0\",\"data_types\": {},\"node_types\": {}, \"policy_types\": {}, \"topology_template\": {}, \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}"
- print "jsonGenerated: " + jsonGenerated
- if not os.path.exists(cached_file_folder):
- os.makedirs(cached_file_folder, 0777)
-
- with open(cached_file_header, 'w+') as f:
- f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}")
- with open(cached_file_content, 'w+') as f:
- f.write(jsonGenerated)
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
return True
elif (self.path.startswith("/onap/controlloop/v2/commission/toscaServiceTemplateSchema")) and http_type == "GET":
if not _file_available:
@@ -289,14 +291,27 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print ("cached file folder for onap is %s: ", cached_file_folder)
print "self.path start with /onap/controlloop/v2/commission/, generating response json..."
jsonGenerated = "{\"tosca_definitions_version\": \"tosca_simple_yaml_1_1_0\",\"data_types\": {},\"node_types\": {}, \"policy_types\": {}, \"topology_template\": {}, \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}"
- print "jsonGenerated: " + jsonGenerated
- if not os.path.exists(cached_file_folder):
- os.makedirs(cached_file_folder, 0777)
-
- with open(cached_file_header, 'w+') as f:
- f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}")
- with open(cached_file_content, 'w+') as f:
- f.write(jsonGenerated)
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
+ elif (self.path.startswith("/onap/controlloop/v2/commission/elements")) and http_type == "GET":
+ if not _file_available:
+ print "self.path start with /commission/elements Control Loop Elements, generating response json..."
+ jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSH_DCAEMicroservice\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
+ elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "GET":
+ if not _file_available:
+ print "self.path start with /commission control loop definition, generating response json..."
+ #jsondata = json.loads(self.data_string)
+ jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSHControlLoopDefinition\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
+ elif (self.path.startswith("/onap/controlloop/v2/commission/getCommonOrInstanceProperties")) and http_type == "GET":
+ if not _file_available:
+ print "self.path start with /commission getting common properties, generating response json..."
+ with open("example/node_template.json", "r") as f:
+ jsonGenerated = f.read()
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
return True
elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "POST":
print "self.path start with POST /onap/controlloop/v2/commission, copying body to response ..."
@@ -307,6 +322,11 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
with open(cached_file_content, 'w+') as f:
f.write(self.data_string)
return True
+ elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "DELETE":
+ print "self.path start with /commission Decommissioning, generating response json..."
+ jsonGenerated = "{\"errorDetails\": null,\"affectedControlLoopDefinitions\": [{ \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\" }]}"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
else:
return False