Move parameters from config Json file to application.yaml 84/121984/8
authorFrancescoFioraEst <francesco.fiora@est.tech>
Tue, 15 Jun 2021 15:01:31 +0000 (16:01 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 23 Jun 2021 16:07:17 +0000 (17:07 +0100)
Issue-ID: POLICY-3343
Change-Id: Id78c00a5a241337f684a70feeee543f3a88fc01c
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
75 files changed:
common/src/test/resources/demo/Notes.txt
models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java
participant/participant-impl/participant-impl-dcae/pom.xml
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClient.java
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClient.java
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandler.java
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ClampEndPoints.java [moved from participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/config/ParametersConfig.java with 52% similarity]
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ConsulEndPoints.java [moved from participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParametersConfig.java with 51% similarity]
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameters.java
participant/participant-impl/participant-impl-dcae/src/main/resources/config/DCAEParticipantConfig.json [deleted file]
participant/participant-impl/participant-impl-dcae/src/main/resources/config/application.yaml
participant/participant-impl/participant-impl-dcae/src/main/resources/parameters/consul.json [new file with mode: 0644]
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ClampHttpClientTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/httpclient/ConsulDcaeHttpClientTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java [new file with mode: 0644]
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/CommonTestData.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParametersTest.java [new file with mode: 0644]
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
participant/participant-impl/participant-impl-dcae/src/test/resources/application_test.properties [new file with mode: 0644]
participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/InvalidParameters.json [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/MinimumParametersH2.json [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/NoParameters.json [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParametersStd.json [deleted file]
participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/Unreadable.json [deleted file]
participant/participant-impl/participant-impl-kubernetes/pom.xml
participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/Application.java
participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/service/ChartStore.java
participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/KubernetesParticipantConfig.json [deleted file]
participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/application.yaml
participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java [deleted file]
participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json [deleted file]
participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/CommonTestData.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParametersTest.java [new file with mode: 0644]
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameters.java [deleted file]
participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties [new file with mode: 0644]
participant/participant-impl/participant-impl-policy/src/test/resources/parameters/InvalidParameters.json [deleted file]
participant/participant-impl/participant-impl-policy/src/test/resources/parameters/MinimumParametersH2.json [deleted file]
participant/participant-impl/participant-impl-policy/src/test/resources/parameters/NoParameters.json [deleted file]
participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParameters.json [deleted file]
participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParametersStd.json [deleted file]
participant/participant-impl/participant-impl-policy/src/test/resources/parameters/Unreadable.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java [deleted file]
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java
participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties
participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/EmptyParameters.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/NoParameters.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParameters.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParametersStd.json [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/Unreadable.json [deleted file]
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantIntermediaryParameters.java

index 21be914..315d640 100644 (file)
@@ -14,10 +14,16 @@ 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"
 
-Run Participant from command line
-mvn exec:java  -Dexec.mainClass=org.onap.policy.clamp.controlloop.participants.ParticipantMain -Dexec.args=" -c src/main/resources/config/CDSParticipantConfig.json"
-mvn exec:java  -Dexec.mainClass=org.onap.policy.clamp.controlloop.participant.dcae.main.startstop.Main -Dexec.args=" -c src/main/resources/config/DCAEParticipantConfig.json"
-mvn exec:java  -Dexec.mainClass=org.onap.policy.clamp.controlloop.participants.ParticipantMain -Dexec.args=" -c src/main/resources/config/PolicyParticipantConfig.json"
+Run Participant from command line using Maven
+mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8080 --topicServer=localhost"
+mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8081 --topicServer=localhost"
+mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8082 --topicServer=localhost"
+
+Run Participant from command line using Jar
+java -jar -Dserver.port=8080 -DtopicServer=localhost target/policy-clamp-participant-impl-simulator-6.1.2-SNAPSHOT.jar
+java -jar -Dserver.port=8081 -DtopicServer=localhost target/policy-clamp-participant-impl-dcae-6.1.2-SNAPSHOT.jar
+java -jar -Dserver.port=8082 -DtopicServer=localhost target/policy-clamp-participant-impl-policy-6.1.2-SNAPSHOT.jar
+java -jar -DtopicServer=localhost target/policy-clamp-participant-impl-kubernetes-6.1.2-SNAPSHOT.jar
 
 Config of DB
 
index a7216ed..272333b 100644 (file)
@@ -74,7 +74,6 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider {
         }
     }
 
-
     /**
      * Get filtered participant statistics.
      *
@@ -108,7 +107,6 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider {
         return asParticipantStatisticsList(getPfDao().getFiltered(JpaParticipantStatistics.class, filterParams));
     }
 
-
     /**
      * Creates Participant statistics.
      *
@@ -138,8 +136,6 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider {
         return participantStatistics;
     }
 
-
-
     /**
      * Convert JPA participant statistics list to participant statistics list.
      *
index d59bca3..9478626 100644 (file)
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
-            <version>${version.springboot}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-validation</artifactId>
-            <version>${version.springboot}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
-            <version>${version.springboot}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
index fd19d9d..74c1ee5 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.policy.clamp.controlloop.participant.dcae.httpclient;
 
 import org.apache.http.HttpStatus;
+import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ClampEndPoints;
 import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
 import org.onap.policy.clamp.controlloop.participant.dcae.model.ExternalComponent;
 import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop;
@@ -29,12 +30,7 @@ import org.springframework.stereotype.Component;
 @Component
 public class ClampHttpClient extends AbstractHttpClient {
 
-    private static final String STATUS = "/restservices/clds/v2/loop/getstatus/";
-    private static final String CREATE = "/restservices/clds/v2/loop/create/%s?templateName=%s";
-    private static final String DEPLOY = "/restservices/clds/v2/loop/deploy/";
-    private static final String STOP = "/restservices/clds/v2/loop/stop/";
-    private static final String DELETE = "/restservices/clds/v2/loop/delete/";
-    private static final String UNDEPLOY = "/restservices/clds/v2/loop/undeploy/";
+    private final ClampEndPoints endPoints;
     public static final String STATUS_NOT_FOUND = "STATUS_NOT_FOUND";
     public static final String POLICY_NOT_FOUND = "POLICY_NOT_FOUND";
 
@@ -45,6 +41,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      */
     public ClampHttpClient(ParticipantDcaeParameters parameters) {
         super(parameters.getClampClientParameters());
+        this.endPoints = parameters.getClampClientEndPoints();
     }
 
     /**
@@ -55,7 +52,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      * @return the Loop object or null if error occurred
      */
     public Loop create(String loopName, String templateName) {
-        return executePost(String.format(CREATE, loopName, templateName), HttpStatus.SC_OK);
+        return executePost(String.format(endPoints.getCreate(), loopName, templateName), HttpStatus.SC_OK);
     }
 
     /**
@@ -65,7 +62,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      * @return true
      */
     public boolean deploy(String loopName) {
-        return executePut(DEPLOY + loopName, HttpStatus.SC_ACCEPTED);
+        return executePut(endPoints.getDeploy() + loopName, HttpStatus.SC_ACCEPTED);
     }
 
     /**
@@ -75,7 +72,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      * @return the Loop object or null if error occurred
      */
     public Loop getstatus(String loopName) {
-        return executeGet(STATUS + loopName, HttpStatus.SC_OK);
+        return executeGet(endPoints.getStatus() + loopName, HttpStatus.SC_OK);
     }
 
     /**
@@ -85,7 +82,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      * @return true
      */
     public boolean undeploy(String loopName) {
-        return executePut(UNDEPLOY + loopName, HttpStatus.SC_ACCEPTED);
+        return executePut(endPoints.getUndeploy() + loopName, HttpStatus.SC_ACCEPTED);
     }
 
     /**
@@ -95,7 +92,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      * @return true
      */
     public boolean stop(String loopName) {
-        return executePut(STOP + loopName, HttpStatus.SC_OK);
+        return executePut(endPoints.getStop() + loopName, HttpStatus.SC_OK);
     }
 
     /**
@@ -105,7 +102,7 @@ public class ClampHttpClient extends AbstractHttpClient {
      * @return true
      */
     public boolean delete(String loopName) {
-        return executePut(DELETE + loopName, HttpStatus.SC_OK);
+        return executePut(endPoints.getDelete() + loopName, HttpStatus.SC_OK);
     }
 
     /**
index 154dd09..4cdcf7c 100644 (file)
 package org.onap.policy.clamp.controlloop.participant.dcae.httpclient;
 
 import org.apache.http.HttpStatus;
+import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ConsulEndPoints;
 import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
 import org.springframework.stereotype.Component;
 
 @Component
 public class ConsulDcaeHttpClient extends AbstractHttpClient {
 
-    private static final String DEPLOY = "/v1/kv/dcae-pmsh:";
+    private final ConsulEndPoints endPoints;
 
     /**
      * Constructor.
@@ -36,16 +37,17 @@ public class ConsulDcaeHttpClient extends AbstractHttpClient {
      */
     public ConsulDcaeHttpClient(ParticipantDcaeParameters parameters) {
         super(parameters.getConsulClientParameters());
+        this.endPoints = parameters.getConsulClientEndPoints();
     }
 
     /**
-     * Call consult.
+     * Call deploy consult.
      *
      * @param name the name to deploy
      * @param jsonEntity the Entity
      * @return true
      */
     public boolean deploy(String name, String jsonEntity) {
-        return executePut(DEPLOY + name, jsonEntity, HttpStatus.SC_OK);
+        return executePut(endPoints.getDeploy() + name, jsonEntity, HttpStatus.SC_OK);
     }
 }
index 6c5ff1d..5a0ddab 100644 (file)
@@ -30,9 +30,11 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 import org.onap.policy.clamp.controlloop.participant.dcae.httpclient.ClampHttpClient;
 import org.onap.policy.clamp.controlloop.participant.dcae.httpclient.ConsulDcaeHttpClient;
+import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
 import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop;
 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.resources.ResourceUtils;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.slf4j.Logger;
@@ -58,19 +60,11 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
 
     private static final String BLUEPRINT_DEPLOYED = "BLUEPRINT_DEPLOYED";
     private static final String MICROSERVICE_INSTALLED_SUCCESSFULLY = "MICROSERVICE_INSTALLED_SUCCESSFULLY";
-    private static final int CHECK_COUNT = 10;
-
-    private static final String BODY_CONSUL =
-            "{ \"subscription\": { \"subscriptionName\": \"subscriptiona\", \"administrativeState\": \"UNLOCKED\", "
-                    + "\"fileBasedGP\": 15, \"fileLocation\": \"/pm/pm.xml\", \"nfFilter\": "
-                    + "{ \"nfNames\": [ \"^pnf1.*\" ], \"modelInvariantIDs\": "
-                    + "[ \"5845y423-g654-6fju-po78-8n53154532k6\", \"7129e420-d396-4efb-af02-6b83499b12f8\" ], "
-                    + "\"modelVersionIDs\": [ \"e80a6ae3-cafd-4d24-850d-e14c084a5ca9\" ] }, \"measurementGroups\": "
-                    + "[ { \"measurementGroup\": { \"measurementTypes\": [ { \"measurementType\": \"countera\" }, "
-                    + "{ \"measurementType\": \"counterb\" } ], \"managedObjectDNsBasic\": [ { \"DN\": \"dna\" }, "
-                    + "{ \"DN\": \"dnb\" } ] } }, { \"measurementGroup\": { \"measurementTypes\": "
-                    + "[ { \"measurementType\": \"counterc\" }, { \"measurementType\": \"counterd\" } ], "
-                    + "\"managedObjectDNsBasic\": " + "[ { \"DN\": \"dnc\" }, { \"DN\": \"dnd\" } ] } } ] } }";
+
+    private int checkCount;
+    private int secCount;
+
+    private String bodyConsul;
 
     /**
      * Constructor.
@@ -78,9 +72,13 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
      * @param clampClient the CLAMP client
      * @param consulClient the Consul client
      */
-    public ControlLoopElementHandler(ClampHttpClient clampClient, ConsulDcaeHttpClient consulClient) {
+    public ControlLoopElementHandler(ClampHttpClient clampClient, ConsulDcaeHttpClient consulClient,
+            ParticipantDcaeParameters parameters) {
         this.clampClient = clampClient;
         this.consulClient = consulClient;
+        this.checkCount = parameters.getCheckCount();
+        this.secCount = parameters.getSecCount();
+        bodyConsul = ResourceUtils.getResourceAsString(parameters.getJsonBodyConsulPath());
     }
 
     /**
@@ -126,7 +124,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
     }
 
     private void deploy() throws PfModelException {
-        if (!consulClient.deploy(POLICY, BODY_CONSUL)) {
+        if (!consulClient.deploy(POLICY, bodyConsul)) {
             throw new PfModelException(null, "deploy to consul failed");
         }
         if (!clampClient.deploy(LOOP)) {
@@ -150,9 +148,9 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
             if (BLUEPRINT_DEPLOYED.equals(ClampHttpClient.getStatusCode(loop))) {
                 deploy();
                 boolean deployedFlag = false;
-                for (int i = 0; i < CHECK_COUNT; i++) {
+                for (int i = 0; i < checkCount; i++) {
                     // sleep 10 seconds
-                    TimeUnit.SECONDS.sleep(CHECK_COUNT);
+                    TimeUnit.SECONDS.sleep(secCount);
                     loop = getStatus();
                     String status = ClampHttpClient.getStatusCode(loop);
                     if (MICROSERVICE_INSTALLED_SUCCESSFULLY.equals(status)) {
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.clamp.controlloop.participant.dcae.config;
+package org.onap.policy.clamp.controlloop.participant.dcae.main.parameters;
 
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameterHandler;
-import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import javax.validation.constraints.NotBlank;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.validation.annotation.Validated;
 
-@Configuration
-public class ParametersConfig {
+/**
+ * Class to hold all end points needed for clamp client.
+ *
+ */
+@Validated
+@Getter
+@Setter
+public class ClampEndPoints {
+
+    @NotBlank
+    private String status;
+
+    @NotBlank
+    private String create;
+
+    @NotBlank
+    private String deploy;
+
+    @NotBlank
+    private String stop;
+
+    @NotBlank
+    private String delete;
 
-    @Value("${participant.file}")
-    private String file;
+    @NotBlank
+    private String undeploy;
 
-    @Bean
-    public ParticipantDcaeParameters participantDcaeParameters() throws ControlLoopException {
-        return new ParticipantDcaeParameterHandler().toParticipantDcaeParameters(file);
-    }
 }
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.clamp.controlloop.participant.kubernetes.configurations;
+package org.onap.policy.clamp.controlloop.participant.dcae.main.parameters;
 
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.participant.kubernetes.parameters.ParticipantK8sParameterHandler;
-import org.onap.policy.clamp.controlloop.participant.kubernetes.parameters.ParticipantK8sParameters;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import javax.validation.constraints.NotBlank;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.validation.annotation.Validated;
 
-@Configuration
-public class ParametersConfig {
-
-    @Value("${participant.file}")
-    private String file;
+/**
+ * Class to hold all end points needed for consul client.
+ *
+ */
+@Validated
+@Getter
+@Setter
+public class ConsulEndPoints {
 
-    @Bean
-    public ParticipantK8sParameters participantK8sParameters() throws ControlLoopException {
-        return new ParticipantK8sParameterHandler().toParticipantK8sParameters(file);
-    }
+    @NotBlank
+    private String deploy;
 }
-
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameterHandler.java b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameterHandler.java
deleted file mode 100644 (file)
index 689bb40..0000000
+++ /dev/null
@@ -1,82 +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.participant.dcae.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.BeanValidationResult;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class handles reading, parsing and validating of control loop runtime parameters from JSON files.
- */
-public class ParticipantDcaeParameterHandler {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantDcaeParameterHandler.class);
-
-    private static final Coder CODER = new StandardCoder();
-
-    /**
-     * Read the parameters from the path of the file.
-     *
-     * @param path path of the config file.
-     * @return the parameters read from the configuration file
-     * @throws ControlLoopException on parameter exceptions
-     */
-    public ParticipantDcaeParameters toParticipantDcaeParameters(String path) throws ControlLoopException {
-        ParticipantDcaeParameters parameters = null;
-        // Read the parameters
-        try {
-            // Read the parameters from JSON
-            File file = new File(path);
-            parameters = CODER.decode(file, ParticipantDcaeParameters.class);
-        } catch (final CoderException e) {
-            final String errorMessage =
-                    "error reading parameters from \"" + path + "\"\n" + "(" + e.getClass().getSimpleName() + ")";
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage, e);
-        }
-
-        // The JSON processing returns null if there is an empty file
-        if (parameters == null) {
-            final String errorMessage = "no parameters found in \"" + path + "\"";
-            LOGGER.error(errorMessage);
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage);
-        }
-
-        // validate the parameters
-        final BeanValidationResult validationResult = parameters.validate();
-        if (!validationResult.isValid()) {
-            final String returnMessage =
-                    "validation error(s) on parameters from \"" + path + "\"\n" + validationResult.getResult();
-
-            LOGGER.error(returnMessage);
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, returnMessage);
-        }
-
-        return parameters;
-    }
-
-}
index 469a6fe..7987811 100644 (file)
 
 package org.onap.policy.clamp.controlloop.participant.dcae.main.parameters;
 
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
+import lombok.Setter;
 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.parameters.annotations.NotNull;
-import org.onap.policy.common.parameters.annotations.Valid;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.common.endpoints.parameters.RestClientParameters;
+import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
 
 /**
  * Class to hold all parameters needed for the participant dcae.
  *
  */
-@NotNull
-@NotBlank
+@Validated
 @Getter
-public class ParticipantDcaeParameters extends ParameterGroupImpl {
+@Setter
+@ConfigurationProperties(prefix = "participant")
+public class ParticipantDcaeParameters {
 
-    private static final String MSG_IS_BLANK = "is blank";
+    @NotNull
+    @Min(10)
+    private int checkCount = 10;
 
-    @Valid
-    private BusTopicParams clampClientParameters;
+    @NotNull
+    @Min(1)
+    private int secCount = 10;
+
+    @NotBlank
+    private String jsonBodyConsulPath;
 
+    @NotNull
     @Valid
-    private BusTopicParams consulClientParameters;
+    private ClampEndPoints clampClientEndPoints;
 
-    private ParticipantIntermediaryParameters intermediaryParameters;
-    private PolicyModelsProviderParameters databaseProviderParameters;
+    @NotNull
+    @Valid
+    private ConsulEndPoints consulClientEndPoints;
 
-    /**
-     * Create the participant dcae parameter group.
-     *
-     * @param name the parameter group name
-     */
-    public ParticipantDcaeParameters(final String name) {
-        super(name);
-    }
+    @NotNull
+    @ParameterGroupConstraint
+    private RestClientParameters clampClientParameters;
 
-    /**
-     * {@inheritDoc}.
-     */
-    @Override
-    public BeanValidationResult validate() {
-        BeanValidationResult result = super.validate();
-        if (result.isValid()) {
-            result.addResult(checkMissingMandatoryParams(clampClientParameters));
-            result.addResult(checkMissingMandatoryParams(consulClientParameters));
-        }
-        return result;
-    }
+    @NotNull
+    @ParameterGroupConstraint
+    private RestClientParameters consulClientParameters;
 
-    private BeanValidationResult checkMissingMandatoryParams(BusTopicParams clientParameters) {
-        BeanValidationResult result = new BeanValidationResult(clientParameters.getClientName(), clientParameters);
-        if (clientParameters.isHostnameInvalid()) {
-            result.addResult("Host", clientParameters.getHostname(), ValidationStatus.INVALID, MSG_IS_BLANK);
-        }
-        if (clientParameters.isClientNameInvalid()) {
-            result.addResult("Name", clientParameters.getClientName(), ValidationStatus.INVALID, MSG_IS_BLANK);
-        }
-        if (StringUtils.isBlank(clientParameters.getPassword())) {
-            result.addResult("Password", clientParameters.getPassword(), ValidationStatus.INVALID, MSG_IS_BLANK);
-        }
-        if (StringUtils.isBlank(clientParameters.getUserName())) {
-            result.addResult("UserName", clientParameters.getUserName(), ValidationStatus.INVALID, MSG_IS_BLANK);
-        }
-        if (clientParameters.isPortInvalid()) {
-            result.addResult("Port", clientParameters.getPort(), ValidationStatus.INVALID, "is not valid");
-        }
-        return result;
-    }
+    @NotNull
+    @Valid
+    private ParticipantIntermediaryParameters intermediaryParameters;
 }
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/resources/config/DCAEParticipantConfig.json b/participant/participant-impl/participant-impl-dcae/src/main/resources/config/DCAEParticipantConfig.json
deleted file mode 100644 (file)
index a7ea089..0000000
+++ /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": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap",
-                    "fetchTimeout": 15000
-                }
-            ],
-            "topicSinks": [
-                {
-                    "topic": "POLICY-CLRUNTIME-PARTICIPANT",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                },
-                {
-                    "topic": "POLICY-NOTIFICATION",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
index 58908cf..36b9f84 100644 (file)
@@ -1,3 +1,55 @@
 
 participant:
-  file: src/main/resources/config/DCAEParticipantConfig.json
+  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
+    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[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
+      topicSinks[1]:
+        topic: POLICY-NOTIFICATION
+        servers[0]: ${topicServer:message-router}
+        topicCommInfrastructure: dmaap
+  checkCount: 10
+  secCount: 10
+  jsonBodyConsulPath: src/main/resources/parameters/consul.json
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/resources/parameters/consul.json b/participant/participant-impl/participant-impl-dcae/src/main/resources/parameters/consul.json
new file mode 100644 (file)
index 0000000..3aad78e
--- /dev/null
@@ -0,0 +1,62 @@
+{
+  "subscription": {
+    "subscriptionName": "subscriptiona",
+    "administrativeState": "UNLOCKED",
+    "fileBasedGP": 15,
+    "fileLocation": "/pm/pm.xml",
+    "nfFilter": {
+      "nfNames": [
+        "^pnf1.*"
+      ],
+      "modelInvariantIDs": [
+        "5845y423-g654-6fju-po78-8n53154532k6",
+        "7129e420-d396-4efb-af02-6b83499b12f8"
+      ],
+      "modelVersionIDs": [
+        "e80a6ae3-cafd-4d24-850d-e14c084a5ca9"
+      ]
+    },
+    "measurementGroups": [
+      {
+        "measurementGroup": {
+          "measurementTypes": [
+            {
+              "measurementType": "countera"
+            },
+            {
+              "measurementType": "counterb"
+            }
+          ],
+          "managedObjectDNsBasic": [
+            {
+              "DN": "dna"
+            },
+            {
+              "DN": "dnb"
+            }
+          ]
+        }
+      },
+      {
+        "measurementGroup": {
+          "measurementTypes": [
+            {
+              "measurementType": "counterc"
+            },
+            {
+              "measurementType": "counterd"
+            }
+          ],
+          "managedObjectDNsBasic": [
+            {
+              "DN": "dnc"
+            },
+            {
+              "DN": "dnd"
+            }
+          ]
+        }
+      }
+    ]
+  }
+}
index 6d7592d..4631772 100644 (file)
@@ -48,7 +48,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@TestPropertySource(properties = "participant.file=src/test/resources/parameters/TestParameters.json")
+@TestPropertySource(locations = {"classpath:application_test.properties"})
 class PartecipantDcaeTest {
 
     private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
index 6e37522..f730f36 100644 (file)
@@ -60,9 +60,7 @@ class ClampHttpClientTest {
     public static void setUp() {
         CommonTestData commonTestData = new CommonTestData();
 
-        parameters = commonTestData.toObject(
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantDcaeParameters.class);
+        parameters = commonTestData.getParticipantDcaeParameters();
 
         mockServer = ClientAndServer.startClientAndServer(parameters.getClampClientParameters().getPort());
 
index 734919e..5155fed 100644 (file)
@@ -48,9 +48,7 @@ class ConsulDcaeHttpClientTest {
     public static void startServer() {
         CommonTestData commonTestData = new CommonTestData();
 
-        parameters = commonTestData.toObject(
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantDcaeParameters.class);
+        parameters = commonTestData.getParticipantDcaeParameters();
 
         mockServer = ClientAndServer.startClientAndServer(parameters.getConsulClientParameters().getPort());
 
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/handler/ControlLoopElementHandlerTest.java
new file mode 100644 (file)
index 0000000..ab181d4
--- /dev/null
@@ -0,0 +1,144 @@
+/*-
+ * ============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.dcae.main.handler;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+import org.json.JSONException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+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.dcae.httpclient.ClampHttpClient;
+import org.onap.policy.clamp.controlloop.participant.dcae.httpclient.ConsulDcaeHttpClient;
+import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData;
+import org.onap.policy.clamp.controlloop.participant.dcae.model.Loop;
+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.ToscaServiceTemplate;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+/**
+ * Class to perform unit test of {@link ControlLoopElementHandler}.
+ *
+ */
+@ExtendWith(SpringExtension.class)
+class ControlLoopElementHandlerTest {
+
+    private static final String LOOP = "pmsh_loop";
+    private static final String TEMPLATE = "LOOP_TEMPLATE_k8s_pmsh";
+    private static final String BLUEPRINT_DEPLOYED = "BLUEPRINT_DEPLOYED";
+    private static final String MICROSERVICE_INSTALLED_SUCCESSFULLY = "MICROSERVICE_INSTALLED_SUCCESSFULLY";
+
+    public static final Coder CODER = new StandardCoder();
+    private CommonTestData commonTestData = new CommonTestData();
+
+    @Test
+    void test_ControlLoopElementStateChange() {
+        ClampHttpClient clampClient = spy(mock(ClampHttpClient.class));
+        ConsulDcaeHttpClient consulClient = mock(ConsulDcaeHttpClient.class);
+        ControlLoopElementHandler controlLoopElementHandler =
+                new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters());
+
+        when(clampClient.getstatus(eq(LOOP))).thenReturn(new Loop());
+
+        ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
+
+        controlLoopElementHandler.controlLoopElementStateChange(UUID.randomUUID(), ControlLoopState.PASSIVE,
+                ControlLoopOrderedState.UNINITIALISED);
+
+        verify(clampClient).undeploy(eq(LOOP));
+    }
+
+    @Test
+    void testCreate_ControlLoopElementUpdate() throws PfModelException, JSONException, CoderException {
+        ClampHttpClient clampClient = spy(mock(ClampHttpClient.class));
+        Loop loopDeployed = CODER.convert(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED), Loop.class);
+        when(clampClient.create(eq(LOOP), eq(TEMPLATE))).thenReturn(loopDeployed);
+        when(clampClient.deploy(eq(LOOP))).thenReturn(true);
+
+        Loop loopInstalled =
+                CODER.convert(CommonTestData.createJsonStatus(MICROSERVICE_INSTALLED_SUCCESSFULLY), Loop.class);
+        when(clampClient.getstatus(eq(LOOP))).thenReturn(null, loopInstalled);
+
+        ConsulDcaeHttpClient consulClient = spy(mock(ConsulDcaeHttpClient.class));
+        when(consulClient.deploy(any(String.class), any(String.class))).thenReturn(true);
+
+        ControlLoopElementHandler controlLoopElementHandler =
+                new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters());
+
+        ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
+
+        ControlLoopElement element = new ControlLoopElement();
+        element.setId(UUID.randomUUID());
+        element.setOrderedState(ControlLoopOrderedState.PASSIVE);
+
+        final ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate();
+        controlLoopElementHandler.controlLoopElementUpdate(element, controlLoopDefinition);
+
+        verify(clampClient).create(eq(LOOP), eq(TEMPLATE));
+        verify(consulClient).deploy(any(String.class), any(String.class));
+        verify(clampClient).deploy(eq(LOOP));
+    }
+
+    @Test
+    void test_ControlLoopElementUpdate() throws PfModelException, JSONException, CoderException {
+        ClampHttpClient clampClient = spy(mock(ClampHttpClient.class));
+        Loop loopDeployed = CODER.convert(CommonTestData.createJsonStatus(BLUEPRINT_DEPLOYED), Loop.class);
+        Loop loopInstalled =
+                CODER.convert(CommonTestData.createJsonStatus(MICROSERVICE_INSTALLED_SUCCESSFULLY), Loop.class);
+        when(clampClient.getstatus(eq(LOOP))).thenReturn(loopDeployed, loopInstalled);
+        when(clampClient.deploy(eq(LOOP))).thenReturn(true);
+
+        ConsulDcaeHttpClient consulClient = spy(mock(ConsulDcaeHttpClient.class));
+        when(consulClient.deploy(any(String.class), any(String.class))).thenReturn(true);
+
+        ControlLoopElementHandler controlLoopElementHandler =
+                new ControlLoopElementHandler(clampClient, consulClient, commonTestData.getParticipantDcaeParameters());
+
+        ParticipantIntermediaryApi intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
+
+        ControlLoopElement element = new ControlLoopElement();
+        element.setId(UUID.randomUUID());
+        element.setOrderedState(ControlLoopOrderedState.PASSIVE);
+
+        ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate();
+        controlLoopElementHandler.controlLoopElementUpdate(element, controlLoopDefinition);
+
+        verify(clampClient, times(0)).create(eq(LOOP), eq(TEMPLATE));
+        verify(consulClient).deploy(any(String.class), any(String.class));
+        verify(clampClient).deploy(eq(LOOP));
+    }
+}
index 5d8881e..4b6dcd6 100644 (file)
@@ -31,7 +31,6 @@ import java.util.TreeMap;
 import javax.ws.rs.core.Response;
 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
 import org.onap.policy.common.endpoints.parameters.TopicParameters;
-import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -54,24 +53,19 @@ public class CommonTestData {
     private static final boolean REST_CONSUL_HTTPS = false;
     private static final boolean REST_CLIENT_AAF = false;
 
-    public static final Coder coder = new StandardCoder();
+    public static final Coder CODER = new StandardCoder();
 
     /**
-     * Converts the contents of a map to a parameter class.
+     * Get ParticipantDcaeParameters.
      *
-     * @param <T> specific type of ParameterGroup class
-     * @param source property map
-     * @param clazz class of object to be created from the map
-     * @return a new object represented by the map
-     * @throws ControlLoopRuntimeException on errors
+     * @return ParticipantDcaeParameters
      */
-    public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+    public ParticipantDcaeParameters getParticipantDcaeParameters() {
         try {
-            return coder.convert(source, clazz);
-
+            return CODER.convert(getParticipantParameterGroupMap(PARTICIPANT_GROUP_NAME),
+                    ParticipantDcaeParameters.class);
         } catch (final CoderException e) {
-            throw new ControlLoopRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
-                    "cannot create " + clazz.getName() + " from map", e);
+            throw new RuntimeException("cannot create ParticipantDcaeParameters from map", e);
         }
     }
 
@@ -86,10 +80,31 @@ public class CommonTestData {
         final Map<String, Object> map = new TreeMap<>();
 
         map.put("name", name);
+        map.put("checkCount", 10);
+        map.put("secCount", 10);
+        map.put("jsonBodyConsulPath", "src/main/resources/parameters/consul.json");
         map.put("clampClientParameters", getClampClientParametersMap(false));
         map.put("consulClientParameters", getConsulClientParametersMap(false));
         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
-        map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false));
+        map.put("clampClientEndPoints", getClampClientEndPoints());
+        map.put("consulClientEndPoints", getConsulClientEndPoints());
+        return map;
+    }
+
+    private Map<String, Object> getConsulClientEndPoints() {
+        final Map<String, Object> map = new TreeMap<>();
+        map.put("deploy", "/v1/kv/dcae-pmsh:");
+        return map;
+    }
+
+    private Map<String, Object> getClampClientEndPoints() {
+        final Map<String, Object> map = new TreeMap<>();
+        map.put("status", "/restservices/clds/v2/loop/getstatus/");
+        map.put("create", "/restservices/clds/v2/loop/create/%s?templateName=%s");
+        map.put("deploy", "/restservices/clds/v2/loop/deploy/");
+        map.put("stop", "/restservices/clds/v2/loop/stop/");
+        map.put("delete", "/restservices/clds/v2/loop/delete/");
+        map.put("undeploy", "/restservices/clds/v2/loop/undeploy/");
         return map;
     }
 
@@ -147,27 +162,6 @@ public class CommonTestData {
         return map;
     }
 
-    /**
-     * Returns a property map for a databaseProviderParameters map for test cases.
-     *
-     * @param isEmpty boolean value to represent that object created should be empty or not
-     * @return a property map suitable for constructing an object
-     */
-    public Map<String, Object> getDatabaseProviderParametersMap(final boolean isEmpty) {
-        final Map<String, Object> map = new TreeMap<>();
-        if (!isEmpty) {
-            map.put("name", "PolicyProviderParameterGroup");
-            map.put("implementation", "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
-            map.put("databaseDriver", "org.h2.Driver");
-            map.put("databaseUrl", "jdbc:h2:mem:testdb");
-            map.put("databaseUser", "policy");
-            map.put("databasePassword", "P01icY");
-            map.put("persistenceUnit", "ToscaConceptTest");
-        }
-
-        return map;
-    }
-
     /**
      * Returns a property map for a intermediaryParameters map for test cases.
      *
@@ -228,58 +222,6 @@ public class CommonTestData {
         return participantId;
     }
 
-    /**
-     * Gets the standard participant parameters.
-     *
-     * @param port port to be inserted into the parameters
-     * @return the standard participant parameters
-     * @throws ControlLoopRuntimeException on errors
-     */
-    public ParticipantDcaeParameters getParticipantParameterGroup(int port) {
-        try {
-            return coder.decode(getParticipantParameterGroupAsString(port), ParticipantDcaeParameters.class);
-
-        } catch (CoderException e) {
-            throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
-                    e);
-        }
-    }
-
-    /**
-     * Gets the standard participant parameters, as a String.
-     *
-     * @param port port to be inserted into the parameters
-     * @return the standard participant parameters
-     * @throws ControlLoopRuntimeException on errors
-     */
-    public static String getParticipantParameterGroupAsString(int port) {
-
-        try {
-            File file = new File(getParamFile());
-            String json = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
-
-            json = json.replace("${port}", String.valueOf(port));
-            json = json.replace("${dbName}", "jdbc:h2:mem:testdb");
-
-            return json;
-
-        } catch (IOException e) {
-            throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
-                    e);
-
-        }
-    }
-
-    /**
-     * Gets the full path to the parameter file, which may vary depending on whether or
-     * not this is an end-to-end test.
-     *
-     * @return the parameter file name
-     */
-    private static String getParamFile() {
-        return "src/test/resources/parameters/TestParametersStd.json";
-    }
-
     /**
      * Nulls out a field within a JSON string.
      *
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParametersTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParametersTest.java
new file mode 100644 (file)
index 0000000..b59cee7
--- /dev/null
@@ -0,0 +1,163 @@
+/*-
+ * ============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.dcae.main.parameters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+
+/**
+ * Class to perform unit test of {@link ParticipantDcaeParameters}.
+ * It will be tested the "javax.validation.constraints"
+ *
+ */
+class ParticipantDcaeParametersTest {
+    private CommonTestData commonTestData = new CommonTestData();
+    private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
+
+    @Test
+    void testParticipantDcaeParameters() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty();
+    }
+
+    @Test
+    void testZeroCheckCount() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.setCheckCount(0);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPoints() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.setClampClientEndPoints(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPointCreate() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientEndPoints().setCreate(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPointDelete() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientEndPoints().setDelete(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPointDeploy() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientEndPoints().setDeploy(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPointStatus() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientEndPoints().setStatus(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPointStop() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientEndPoints().setStop(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientEndPointUndeploy() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientEndPoints().setUndeploy(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoClampClientParameters() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.setClampClientParameters(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoHostname() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getClampClientParameters().setHostname(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoTopicSinks() throws ControlLoopException {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+
+        ParticipantIntermediaryParameters intermediaryParameters = participantParameters.getIntermediaryParameters();
+        intermediaryParameters.getClampControlLoopTopics().setTopicSinks(null);
+
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoTopicSources() throws ControlLoopException {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+
+        ParticipantIntermediaryParameters intermediaryParameters = participantParameters.getIntermediaryParameters();
+        intermediaryParameters.getClampControlLoopTopics().setTopicSources(null);
+
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoConsulClientParameters() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.setConsulClientParameters(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoConsulHostname() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getConsulClientParameters().setHostname(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoIntermediaryParameters() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.setIntermediaryParameters(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testNoParticipantId() {
+        final ParticipantDcaeParameters participantParameters = commonTestData.getParticipantDcaeParameters();
+        participantParameters.getIntermediaryParameters().setParticipantId(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameterHandler.java
deleted file mode 100644 (file)
index 2eb8332..0000000
+++ /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.participant.dcae.main.parameters;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileNotFoundException;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.common.utils.coder.CoderException;
-
-
-/**
- * Class to perform unit test of {@link ParticipantParameterHandler}.
- *
- */
-class TestParticipantDcaeParameterHandler {
-
-    @Test
-    void testParameterHandlerNoParameterFile() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/NoParametersFile.json";
-
-        assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().toParticipantDcaeParameters(path))
-            .hasCauseInstanceOf(CoderException.class)
-            .hasRootCauseInstanceOf(FileNotFoundException.class);
-    }
-
-    @Test
-    void testParameterHandlerInvalidParameters() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/InvalidParameters.json";
-
-        assertThatThrownBy(() -> new ParticipantDcaeParameterHandler().toParticipantDcaeParameters(path))
-            .hasMessageStartingWith("error reading parameters from")
-            .hasCauseInstanceOf(CoderException.class);
-    }
-
-    @Test
-    void testParticipantParameterGroup() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/TestParameters.json";
-
-        final ParticipantDcaeParameters parGroup = new ParticipantDcaeParameterHandler()
-                .toParticipantDcaeParameters(path);
-        assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName());
-    }
-}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/TestParticipantDcaeParameters.java
deleted file mode 100644 (file)
index 2320ae0..0000000
+++ /dev/null
@@ -1,88 +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.participant.dcae.main.parameters;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.parameters.ValidationResult;
-
-/**
- * Class to perform unit test of {@link ParticipantParameterGroup}.
- *
- */
-class TestParticipantDcaeParameters {
-    CommonTestData commonTestData = new CommonTestData();
-
-    @Test
-    void testParticipantParameterGroup_Named() {
-        final ParticipantDcaeParameters participantParameters = new ParticipantDcaeParameters("my-name");
-        assertEquals("my-name", participantParameters.getName());
-    }
-
-    @Test
-    void testParticipantParameterGroup() {
-        final ParticipantDcaeParameters participantParameters = commonTestData.toObject(
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantDcaeParameters.class);
-        final ParticipantIntermediaryParameters participantIntermediaryParameters = participantParameters
-                .getIntermediaryParameters();
-        final TopicParameterGroup topicParameterGroup  = participantParameters.getIntermediaryParameters()
-                .getClampControlLoopTopics();
-        final ValidationResult validationResult = participantParameters.validate();
-        assertTrue(validationResult.isValid());
-        assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, participantParameters.getName());
-        assertEquals(CommonTestData.TIME_INTERVAL, participantIntermediaryParameters.getReportingTimeInterval());
-        assertEquals(CommonTestData.DESCRIPTION, participantIntermediaryParameters.getDescription());
-        assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
-        assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
-    }
-
-    @Test
-    void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() {
-        final Map<String, Object> map =
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME);
-        map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true));
-        final ParticipantDcaeParameters participantParameters =
-                commonTestData.toObject(map, ParticipantDcaeParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertNull(validationResult.getResult());
-    }
-
-    @Test
-    void testParticipantParameterGroup_EmptyTopicParameters() {
-        final Map<String, Object> map =
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME);
-        final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false);
-        intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true));
-        map.replace("intermediaryParameters", intermediaryParametersMap);
-
-        final ParticipantDcaeParameters participantParameters =
-                commonTestData.toObject(map, ParticipantDcaeParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertNull(validationResult.getResult());
-    }
-}
index f414b7a..0b2712b 100644 (file)
@@ -34,7 +34,6 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
 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.participant.dcae.main.parameters.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;
@@ -49,7 +48,6 @@ public class TestListenerUtils {
     private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
     private static final Coder CODER = new StandardCoder();
     private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml";
-    static CommonTestData commonTestData = new CommonTestData();
 
     /**
      * Method to create a controlLoop from a yaml file.
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-dcae/src/test/resources/application_test.properties
new file mode 100644 (file)
index 0000000..d585dd3
--- /dev/null
@@ -0,0 +1,41 @@
+spring.security.user.name=healthcheck
+spring.security.user.password=zb!XztG34
+
+server.servlet.context-path=/onap/participantsim
+server.error.path=/error
+
+participant.name=ControlLoopParticipant Dcae Test
+participant.clampClientParameters.clientName=Clamp
+participant.clampClientParameters.hostname=0.0.0.0
+participant.clampClientParameters.port=8443
+participant.clampClientParameters.userName=admin
+participant.clampClientParameters.password=password
+participant.clampClientParameters.https=true
+participant.clampClientParameters.aaf=false
+participant.consulClientParameters.clientName=Consul
+participant.consulClientParameters.hostname=consul
+participant.consulClientParameters.port=31321
+participant.consulClientParameters.userName=admin
+participant.consulClientParameters.password=password
+participant.consulClientParameters.https=false
+participant.consulClientParameters.aaf=false
+participant.intermediaryParameters.name=Participant parameters
+participant.intermediaryParameters.reportingTimeInterval=120000
+participant.intermediaryParameters.description=Participant Description
+participant.intermediaryParameters.participantId.name=DCAEParticipant0
+participant.intermediaryParameters.participantId.version=1.0.0
+participant.intermediaryParameters.participantType.name=org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant
+participant.intermediaryParameters.participantType.version=2.3.4
+participant.intermediaryParameters.clampControlLoopTopics.name=ControlLoop Topics
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topicCommInfrastructure=dmaap
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].fetchTimeout=15000
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topicCommInfrastructure=dmaap
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topic=POLICY-NOTIFICATION
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topicCommInfrastructure=dmaap
+
+participant.checkCount=10
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/InvalidParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/InvalidParameters.json
deleted file mode 100644 (file)
index 1035ccb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "name": "
-}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/MinimumParametersH2.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/MinimumParametersH2.json
deleted file mode 100644 (file)
index 1ee2955..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "restServerParameters": {
-        "host": "0.0.0.0",
-        "port": 6969,
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": false,
-        "aaf": 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": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap",
-                    "fetchTimeout": 15000
-                }
-            ],
-            "topicSinks": [
-                {
-                    "topic": "POLICY-CLRUNTIME-PARTICIPANT",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                },
-                {
-                    "topic": "POLICY-NOTIFICATION",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/NoParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/NoParameters.json
deleted file mode 100644 (file)
index 7a73a41..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-{
-}
\ No newline at end of file
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParameters.json
deleted file mode 100644 (file)
index 580eea7..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "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": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap",
-                    "fetchTimeout": 15000
-                }
-            ],
-            "topicSinks": [
-                {
-                    "topic": "POLICY-CLRUNTIME-PARTICIPANT",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                },
-                {
-                    "topic": "POLICY-NOTIFICATION",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParametersStd.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/TestParametersStd.json
deleted file mode 100644 (file)
index 789fc7b..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "clampClientParameters": {
-        "name": "Clamp",
-        "host": "0.0.0.0",
-        "port": 8443,
-        "userName": "admin",
-        "password": "password",
-        "https": true,
-        "aaf": false
-    },
-    "consulClientParameters": {
-        "name": "Clamp",
-        "host": "consul",
-        "port": 31321,
-        "userName": "admin",
-        "password": "password",
-        "https": false,
-        "aaf": 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": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap",
-                    "fetchTimeout": 15000
-                }
-            ],
-            "topicSinks": [
-                {
-                    "topic": "POLICY-CLRUNTIME-PARTICIPANT",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                },
-                {
-                    "topic": "POLICY-NOTIFICATION",
-                    "servers": [
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure": "dmaap"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/Unreadable.json b/participant/participant-impl/participant-impl-dcae/src/test/resources/parameters/Unreadable.json
deleted file mode 100644 (file)
index b918def..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{
-    "name": "ControlLoopRuntimeGroup",
-    "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": "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"
-            }
-        ]
-    }
-}
-
-
index 48b56a0..f51e365 100644 (file)
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-webflux</artifactId>
index ffa0bce..37ecf4e 100644 (file)
@@ -22,19 +22,21 @@ package org.onap.policy.clamp.controlloop.participant.kubernetes;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
 
 /**
  * Starter.
  *
  */
 @SpringBootApplication
+@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.kubernetes.parameters")
 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-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameterHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameterHandler.java
deleted file mode 100644 (file)
index 1a7dc35..0000000
+++ /dev/null
@@ -1,73 +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.participant.kubernetes.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.BeanValidationResult;
-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 participant parameters from JSON files.
- */
-public class ParticipantK8sParameterHandler {
-    private static final Coder CODER = new StandardCoder();
-
-    /**
-     * Read the parameters from the path of the file.
-     *
-     * @param path path of the config file.
-     * @return the parameters read from the configuration file
-     * @throws ControlLoopException on parameter exceptions
-     */
-    public ParticipantK8sParameters toParticipantK8sParameters(String path) throws ControlLoopException {
-        ParticipantK8sParameters parameters = null;
-        // Read the parameters
-        try {
-            // Read the parameters from JSON
-            var file = new File(path);
-            parameters = CODER.decode(file, ParticipantK8sParameters.class);
-        } catch (final CoderException e) {
-            final String errorMessage =
-                    "error reading parameters from \"" + path + "\"\n" + "(" + e.getClass().getSimpleName() + ")";
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage, e);
-        }
-
-        // The JSON processing returns null if there is an empty file
-        if (parameters == null) {
-            final String errorMessage = "no parameters found in \"" + path + "\"";
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage);
-        }
-
-        // validate the parameters
-        final BeanValidationResult validationResult = parameters.validate();
-        if (!validationResult.isValid()) {
-            String returnMessage =
-                    "validation error(s) on parameters from \"" + path + "\"\n" + validationResult.getResult();
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, returnMessage);
-        }
-
-        return parameters;
-    }
-}
index 65b3243..54eb3b2 100644 (file)
 package org.onap.policy.clamp.controlloop.participant.kubernetes.parameters;
 
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 import lombok.Getter;
+import lombok.Setter;
 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.NotNull;
 import org.onap.policy.common.parameters.annotations.Valid;
-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 kubernetes participant.
  *
  */
-@NotNull
-@NotBlank
+@Validated
 @Getter
-public class ParticipantK8sParameters extends ParameterGroupImpl {
-    public static final String DEFAULT_LOCAL_CHART_DIR = "/var/helm-manager/local-charts";
-    public static final String DEFAULT_INFO_FILE_NAME = "CHART_INFO.json";
+@Setter
+@ConfigurationProperties(prefix = "participant")
+public class ParticipantK8sParameters {
 
+    @NotNull
     @Valid
     private ParticipantIntermediaryParameters intermediaryParameters;
-    @Valid
-    private PolicyModelsProviderParameters databaseProviderParameters;
-
 
-    private String localChartDirectory = DEFAULT_LOCAL_CHART_DIR;
-    private String infoFileName = DEFAULT_INFO_FILE_NAME;
+    @NotBlank
+    private String localChartDirectory;
 
-    /**
-     * Create the kubernetes participant parameter group.
-     *
-     * @param name the parameter group name
-     */
-    public ParticipantK8sParameters(final String name) {
-        super(name);
-    }
+    @NotBlank
+    private String infoFileName;
 }
index e7458a4..dcdff62 100644 (file)
@@ -40,7 +40,6 @@ import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.FileSystemUtils;
 import org.springframework.web.multipart.MultipartFile;
@@ -61,7 +60,7 @@ public class ChartStore {
     /**
      * Constructor method.
      */
-    public ChartStore(@Autowired ParticipantK8sParameters participantK8sParameters) {
+    public ChartStore(ParticipantK8sParameters participantK8sParameters) {
         this.participantK8sParameters = participantK8sParameters;
         this.restoreFromLocalFileSystem();
     }
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/KubernetesParticipantConfig.json b/participant/participant-impl/participant-impl-kubernetes/src/main/resources/config/KubernetesParticipantConfig.json
deleted file mode 100644 (file)
index e854a93..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-{
-    "name": "ControlLoopParticipantK8s",
-    "localChartDirectory": "/var/helm-manager/local-charts",
-    "infoFileName": "CHART_INFO.json",
-
-    "intermediaryParameters":{
-        "name":"Participant parameters",
-        "reportingTimeInterval":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":[
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure":"dmaap",
-                    "fetchTimeout":15000
-                }
-            ],
-            "topicSinks":[
-                {
-                    "topic":"POLICY-CLRUNTIME-PARTICIPANT",
-                    "servers":[
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure":"dmaap"
-                },
-                {
-                    "topic":"POLICY-NOTIFICATION",
-                    "servers":[
-                        "localhost"
-                    ],
-                    "topicCommInfrastructure":"dmaap"
-                }
-            ]
-        }
-    },
-    "databaseProviderParameters":{
-        "name":"PolicyProviderParameterGroup",
-        "implementation":"org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
-        "databaseDriver":"org.mariadb.jdbc.Driver",
-        "databaseUrl":"jdbc:mariadb://localhost:3306/controlloop",
-        "databaseUser":"policy",
-        "databasePassword":"P01icY",
-        "persistenceUnit":"ToscaConceptTest"
-    }
-}
index b424003..63ec8a2 100644 (file)
@@ -3,7 +3,32 @@ spring:
     active: prod
 
 participant:
-  file: src/main/resources/config/KubernetesParticipantConfig.json
+  localChartDirectory: /var/helm-manager/local-charts
+  infoFileName: CHART_INFO.json
+  intermediaryParameters:
+    reportingTimeInterval: 120000
+    description: Participant Description
+    participantId:
+      name: K8sParticipant0
+      version: 1.0.0
+    participantType:
+      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
+      topicSinks[1]:
+        topic: POLICY-NOTIFICATION
+        servers[0]: ${topicServer:message-router}
+        topicCommInfrastructure: dmaap
+
 management:
   endpoints:
     web:
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java
deleted file mode 100644 (file)
index 9c65d02..0000000
+++ /dev/null
@@ -1,40 +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.participant.policy.config;
-
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameterHandler;
-import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParametersConfig {
-
-    @Value("${participant.file}")
-    private String file;
-
-    @Bean
-    public ParticipantPolicyParameters participantPolicyParameters() throws ControlLoopException {
-        return new ParticipantPolicyParameterHandler().toParticipantDcaeParameters(file);
-    }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java
deleted file mode 100644 (file)
index 0d8e700..0000000
+++ /dev/null
@@ -1,75 +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.participant.policy.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.BeanValidationResult;
-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 policy participant parameters from JSON files.
- */
-public class ParticipantPolicyParameterHandler {
-
-    private static final Coder CODER = new StandardCoder();
-
-    /**
-     * Read the parameters from the parameter file.
-     *
-     * @param path the path passed to policy
-     * @return the parameters read from the configuration file
-     * @throws ControlLoopException on parameter exceptions
-     */
-    public ParticipantPolicyParameters toParticipantDcaeParameters(final String path) throws ControlLoopException {
-        ParticipantPolicyParameters parameters = null;
-
-        // Read the parameters
-        try {
-            // Read the parameters from JSON
-            File file = new File(path);
-            parameters = CODER.decode(file, ParticipantPolicyParameters.class);
-        } catch (final CoderException e) {
-            final String errorMessage =
-                    "error reading parameters from \"" + path + "\"\n" + "(" + e.getClass().getSimpleName() + ")";
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage, e);
-        }
-
-        // The JSON processing returns null if there is an empty file
-        if (parameters == null) {
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, "no parameters found in \"" + path + "\"");
-        }
-
-        // validate the parameters
-        final BeanValidationResult validationResult = parameters.validate();
-        if (!validationResult.isValid()) {
-            final String returnMessage =
-                    "validation error(s) on parameters from \"" + path + "\"\n" + validationResult.getResult();
-
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, returnMessage);
-        }
-
-        return parameters;
-    }
-}
index 490722a..91f7ae4 100644 (file)
 
 package org.onap.policy.clamp.controlloop.participant.policy.main.parameters;
 
-import javax.validation.constraints.NotBlank;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
 import lombok.Getter;
+import lombok.Setter;
 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.endpoints.parameters.RestClientParameters;
+import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
+
 
 /**
  * Class to hold all parameters needed for the policy participant.
  *
  */
-@NotNull
-@NotBlank
+@Validated
 @Getter
-public class ParticipantPolicyParameters extends ParameterGroupImpl {
+@Setter
+@ConfigurationProperties(prefix = "participant")
+public class ParticipantPolicyParameters {
+
+    @NotNull
+    @Valid
     private ParticipantIntermediaryParameters intermediaryParameters;
-    private BusTopicParams policyApiParameters;
 
-    /**
-     * Create the policy participant parameter group.
-     *
-     * @param name the parameter group name
-     */
-    public ParticipantPolicyParameters(final String name) {
-        super(name);
-    }
+    @NotNull
+    @ParameterGroupConstraint
+    private RestClientParameters policyApiParameters;
 }
diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json b/participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json
deleted file mode 100644 (file)
index bf458fa..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantType":{
-            "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
-            "version":"2.3.1"
-        },
-        "participantId": {
-            "name": "org.onap.PM_Policy",
-            "version": "1.0.0"
-        },
-        "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"
-                }
-            ]
-        }
-    },
-    "policyApiParameters": {
-        "clientName": "api",
-        "hostname": "policy-api",
-        "port": "6969",
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": true,
-        "allowSelfSignedCerts": true
-    }
-}
index 79eca8f..7bf4f62 100644 (file)
@@ -1,3 +1,33 @@
 
 participant:
-  file: src/main/resources/config/PolicyParticipantConfig.json
+  policyApiParameters:
+    clientName: api
+    hostname: policy-api
+    port: 6969
+    userName: healthcheck
+    password: zb!XztG34
+    https: true
+    allowSelfSignedCerts: true
+  intermediaryParameters:
+    reportingTimeInterval: 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[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
+      topicSinks[1]:
+        topic: POLICY-NOTIFICATION
+        servers[0]: ${topicServer:message-router}
+        topicCommInfrastructure: dmaap
index 2a6f4b0..d34a381 100644 (file)
@@ -41,7 +41,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@TestPropertySource(properties = "participant.file=src/test/resources/parameters/TestParameters.json")
+@TestPropertySource(locations = {"classpath:application_test.properties"})
 class ParticipantPolicyTest {
 
     private static final Object lockit = new Object();
index 1acc2c8..3886147 100644 (file)
 
 package org.onap.policy.clamp.controlloop.participant.policy.main.parameters;
 
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
 import org.onap.policy.common.endpoints.parameters.TopicParameters;
-import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -47,23 +39,19 @@ public class CommonTestData {
     public static final long TIME_INTERVAL = 2000;
     public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
 
-    public static final Coder coder = new StandardCoder();
+    public static final Coder CODER = new StandardCoder();
 
     /**
-     * Converts the contents of a map to a parameter class.
+     * Get ParticipantPolicyParameters.
      *
-     * @param <T> the type of ParameterGroup to process
-     * @param source property map
-     * @param clazz class of object to be created from the map
-     * @return a new object represented by the map
-     * @throws ControlLoopRuntimeException on decoding errors
+     * @return ParticipantPolicyParameters
      */
-    public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+    public ParticipantPolicyParameters getParticipantPolicyParameters() {
         try {
-            return coder.convert(source, clazz);
+            return CODER.convert(getParticipantPolicyParametersMap(PARTICIPANT_GROUP_NAME),
+                    ParticipantPolicyParameters.class);
         } catch (final CoderException e) {
-            throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE,
-                "cannot create " + clazz.getName() + " from map", e);
+            throw new RuntimeException("cannot create ParticipantPolicyParameters from map", e);
         }
     }
 
@@ -79,27 +67,24 @@ public class CommonTestData {
 
         map.put("name", name);
         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
-        map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false));
+        map.put("policyApiParameters", getPolicyApiParametersMap());
         return map;
     }
 
     /**
-     * Returns a property map for a databaseProviderParameters map for test cases.
+     * Returns a property map for a policyApiParameters map for test cases.
      *
-     * @param isEmpty boolean value to represent that object created should be empty or not
      * @return a property map suitable for constructing an object
      */
-    public Map<String, Object> getDatabaseProviderParametersMap(final boolean isEmpty) {
+    public Map<String, Object> getPolicyApiParametersMap() {
         final Map<String, Object> map = new TreeMap<>();
-        if (!isEmpty) {
-            map.put("name", "PolicyProviderParameterGroup");
-            map.put("implementation", "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
-            map.put("databaseDriver", "org.h2.Driver");
-            map.put("databaseUrl", "jdbc:h2:mem:testdb");
-            map.put("databaseUser", "policy");
-            map.put("databasePassword", "P01icY");
-            map.put("persistenceUnit", "ToscaConceptTest");
-        }
+        map.put("clientName", "api");
+        map.put("hostname", "localhost");
+        map.put("port", 6969);
+        map.put("userName", "healthcheck");
+        map.put("password", "zb!XztG34");
+        map.put("https", false);
+        map.put("allowSelfSignedCerts", true);
 
         return map;
     }
@@ -162,59 +147,6 @@ public class CommonTestData {
         return participantId;
     }
 
-    /**
-     * Gets the standard participant parameters.
-     *
-     * @param port port to be inserted into the parameters
-     * @return the standard participant parameters
-     * @throws ControlLoopRuntimeException on parameter read errors
-     */
-    public ParticipantPolicyParameters getParticipantPolicyParameters(int port) {
-        try {
-            return coder.decode(getParticipantPolicyParametersAsString(port), ParticipantPolicyParameters.class);
-
-        } catch (CoderException e) {
-            throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
-                e);
-        }
-    }
-
-    /**
-     * Gets the standard participant parameters, as a String.
-     *
-     * @param port port to be inserted into the parameters
-     * @return the standard participant parameters
-     * @throws ControlLoopRuntimeException on parameter read errors
-     */
-    public static String getParticipantPolicyParametersAsString(int port) {
-
-        try {
-            File file = new File(getParamFile());
-            String json = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
-
-            json = json.replace("${port}", String.valueOf(port));
-            json = json.replace("${dbName}", "jdbc:h2:mem:testdb");
-
-            return json;
-
-        } catch (IOException e) {
-            throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
-                e);
-
-        }
-    }
-
-    /**
-     * Gets the full path to the parameter file, which may vary depending on whether or
-     * not this is an end-to-end test.
-     *
-     * @return the parameter file name
-     */
-    private static String getParamFile() {
-        String paramFile = "src/test/resources/parameters/TestParametersStd.json";
-        return paramFile;
-    }
-
     /**
      * Nulls out a field within a JSON string.
      *
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParametersTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParametersTest.java
new file mode 100644 (file)
index 0000000..74e7cb1
--- /dev/null
@@ -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.participant.policy.main.parameters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import org.junit.jupiter.api.Test;
+
+class ParticipantPolicyParametersTest {
+    private CommonTestData commonTestData = new CommonTestData();
+    private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
+
+    @Test
+    void testParticipantPolicyParameters() {
+        final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters();
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty();
+    }
+
+    @Test
+    void testParticipantPolicyParameters_NullTopicSinks() {
+        final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters();
+        participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testParticipantPolicyParameters_NullTopicSources() {
+        final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters();
+        participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSources(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testParticipantPolicyParameters_NullPolicyApiParameters() {
+        final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters();
+        participantParameters.setPolicyApiParameters(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+
+    @Test
+    void testParticipantPolicyParameters_NullHostname() {
+        final ParticipantPolicyParameters participantParameters = commonTestData.getParticipantPolicyParameters();
+        participantParameters.getPolicyApiParameters().setHostname(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
+    }
+}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameterHandler.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameterHandler.java
deleted file mode 100644 (file)
index 8c12a40..0000000
+++ /dev/null
@@ -1,58 +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.participant.policy.main.parameters;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileNotFoundException;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.common.utils.coder.CoderException;
-
-class TestParticipantPolicyParameterHandler {
-
-    @Test
-    void testParameterHandlerNoParameterFile() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/NoParametersFile.json";
-
-        assertThatThrownBy(() -> new ParticipantPolicyParameterHandler().toParticipantDcaeParameters(path))
-            .hasCauseInstanceOf(CoderException.class)
-            .hasRootCauseInstanceOf(FileNotFoundException.class);
-    }
-
-    @Test
-    void testParameterHandlerInvalidParameters() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/InvalidParameters.json";
-
-        assertThatThrownBy(() -> new ParticipantPolicyParameterHandler().toParticipantDcaeParameters(path))
-            .hasMessageStartingWith("error reading parameters from")
-            .hasCauseInstanceOf(CoderException.class);
-    }
-
-    @Test
-    void testParticipantParameterGroup() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/TestParameters.json";
-        final ParticipantPolicyParameters parGroup = new ParticipantPolicyParameterHandler()
-                .toParticipantDcaeParameters(path);
-        assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName());
-    }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/TestParticipantPolicyParameters.java
deleted file mode 100644 (file)
index 5ffe510..0000000
+++ /dev/null
@@ -1,106 +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.participant.policy.main.parameters;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-
-import java.util.Map;
-import org.junit.Test;
-import org.onap.policy.common.parameters.ValidationResult;
-
-public class TestParticipantPolicyParameters {
-    CommonTestData commonTestData = new CommonTestData();
-
-    @Test
-    public void testParticipantPolicyParameters_Named() {
-        final ParticipantPolicyParameters participantParameters = new ParticipantPolicyParameters("my-name");
-        assertEquals("my-name", participantParameters.getName());
-    }
-
-    @Test
-    public void testParticipantPolicyParameters() {
-        final ParticipantPolicyParameters participantParameters = commonTestData.toObject(
-                commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantPolicyParameters.class);
-        assertThat(participantParameters.validate().isValid()).isTrue();
-    }
-
-    @Test
-    public void testParticipantPolicyParameters_NullName() {
-        final ParticipantPolicyParameters participantParameters = commonTestData
-                .toObject(commonTestData.getParticipantPolicyParametersMap(null),
-                        ParticipantPolicyParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertFalse(validationResult.isValid());
-        assertEquals(null, participantParameters.getName());
-        assertThat(validationResult.getResult()).contains("is null");
-    }
-
-    @Test
-    public void testParticipantPolicyParameters_EmptyName() {
-        final ParticipantPolicyParameters participantParameters = commonTestData
-                .toObject(commonTestData.getParticipantPolicyParametersMap(""),
-                                ParticipantPolicyParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertFalse(validationResult.isValid());
-        assertEquals("", participantParameters.getName());
-        assertThat(validationResult.getResult()).contains(
-                "item \"name\" value \"\" INVALID, " + "is blank");
-    }
-
-    @Test
-    public void testParticipantPolicyParameters_SetName() {
-        final ParticipantPolicyParameters participantParameters = commonTestData.toObject(
-                commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantPolicyParameters.class);
-        participantParameters.setName("ParticipantNewGroup");
-        assertThat(participantParameters.validate().isValid()).isTrue();
-        assertEquals("ParticipantNewGroup", participantParameters.getName());
-    }
-
-    @Test
-    public void testParticipantPolicyParameters_EmptyParticipantIntermediaryParameters() {
-        final Map<String, Object> map =
-                commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME);
-        map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true));
-        final ParticipantPolicyParameters participantParameters =
-                commonTestData.toObject(map, ParticipantPolicyParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertNull(validationResult.getResult());
-    }
-
-    @Test
-    public void testParticipantPolicyParametersp_EmptyTopicParameters() {
-        final Map<String, Object> map =
-                commonTestData.getParticipantPolicyParametersMap(CommonTestData.PARTICIPANT_GROUP_NAME);
-        final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false);
-        intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true));
-        map.replace("intermediaryParameters", intermediaryParametersMap);
-
-        final ParticipantPolicyParameters participantParameters =
-                commonTestData.toObject(map, ParticipantPolicyParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertNull(validationResult.getResult());
-    }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties
new file mode 100644 (file)
index 0000000..2f26082
--- /dev/null
@@ -0,0 +1,27 @@
+server.servlet.context-path=/onap/participantsim
+server.error.path=/error
+
+participant.policyApiParameters.clientName=api
+participant.policyApiParameters.hostname=localhost
+participant.policyApiParameters.port=6969
+participant.policyApiParameters.userName=healthcheck
+participant.policyApiParameters.password=zb!XztG34
+participant.policyApiParameters.https=false
+participant.policyApiParameters.allowSelfSignedCerts=true
+participant.intermediaryParameters.reportingTimeInterval: 120000
+participant.intermediaryParameters.description: Participant Description
+participant.intermediaryParameters.participantId.name: org.onap.PM_Policy
+participant.intermediaryParameters.participantId.version: 1.0.0
+participant.intermediaryParameters.participantType.name: org.onap.policy.controlloop.PolicyControlLoopParticipant
+participant.intermediaryParameters.participantType.version: 2.3.1
+participant.intermediaryParameters.clampControlLoopTopics.name=ControlLoop Topics
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topicCommInfrastructure=dmaap
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].fetchTimeout=15000
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topicCommInfrastructure=dmaap
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topic=POLICY-NOTIFICATION
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topicCommInfrastructure=dmaap
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/InvalidParameters.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/InvalidParameters.json
deleted file mode 100644 (file)
index 1035ccb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "name": "
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/MinimumParametersH2.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/MinimumParametersH2.json
deleted file mode 100644 (file)
index 30250be..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantType":{
-            "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
-            "version":"2.3.1"
-        },
-        "participantId": {
-            "name": "org.onap.PM_Policy",
-            "version": "1.0.0"
-        },
-        "clampControlLoopTopics": {
-            "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"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/NoParameters.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/NoParameters.json
deleted file mode 100644 (file)
index 7a73a41..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-{
-}
\ No newline at end of file
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParameters.json
deleted file mode 100644 (file)
index 024f72d..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantType":{
-            "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
-            "version":"2.3.1"
-        },
-        "participantId": {
-            "name": "org.onap.PM_Policy",
-            "version": "1.0.0"
-        },
-        "clampControlLoopTopics": {
-            "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"
-                }
-            ]
-        }
-    },
-    "policyApiParameters": {
-        "clientName": "api",
-        "hostname": "localhost",
-        "port": "6969",
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": false,
-        "allowSelfSignedCerts": true
-    }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParametersStd.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/TestParametersStd.json
deleted file mode 100644 (file)
index 7954063..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantType": {
-            "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
-            "version": "2.3.1"
-        },
-        "participantId": {
-            "name": "org.onap.PM_Policy",
-            "version": "1.0.0"
-        },
-        "clampControlLoopTopics": {
-            "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"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/Unreadable.json b/participant/participant-impl/participant-impl-policy/src/test/resources/parameters/Unreadable.json
deleted file mode 100644 (file)
index e33409f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-{
-    "name": "ControlLoopRuntimeGroup",
-    "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"
-            }
-        ]
-    }
-}
-
-
index 3aa1c36..9f6e4aa 100644 (file)
@@ -22,12 +22,14 @@ package org.onap.policy.clamp.controlloop.participant.simulator;
 \r
 import org.springframework.boot.SpringApplication;\r
 import org.springframework.boot.autoconfigure.SpringBootApplication;\r
+import org.springframework.boot.context.properties.ConfigurationPropertiesScan;\r
 \r
 /**\r
  * Starter.\r
  *\r
  */\r
 @SpringBootApplication\r
+@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.simulator.main.parameters")\r
 public class ParticipantSimulatorApplication {\r
 \r
     public static void main(String[] args) {\r
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java
deleted file mode 100644 (file)
index 936df2c..0000000
+++ /dev/null
@@ -1,40 +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.participant.simulator.config;
-
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameterHandler;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ParametersConfig {
-
-    @Value("${participant.file}")
-    private String file;
-
-    @Bean
-    public ParticipantSimulatorParameters participantSimulatorParameters() throws ControlLoopException {
-        return new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(file);
-    }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java
deleted file mode 100644 (file)
index 178d087..0000000
+++ /dev/null
@@ -1,76 +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.participant.simulator.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.BeanValidationResult;
-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 participant simulator parameters from JSON files.
- */
-public class ParticipantSimulatorParameterHandler {
-
-    private static final Coder CODER = new StandardCoder();
-
-    /**
-     * Read the parameters from the path of the file.
-     *
-     * @param path path of the config file.
-     * @return the parameters read from the configuration file
-     * @throws ControlLoopException on parameter exceptions
-     */
-    public ParticipantSimulatorParameters toParticipantSimulatorParameters(String path) throws ControlLoopException {
-        ParticipantSimulatorParameters parameters = null;
-        // Read the parameters
-        try {
-            // Read the parameters from JSON
-            File file = new File(path);
-            parameters = CODER.decode(file, ParticipantSimulatorParameters.class);
-        } catch (final CoderException e) {
-            final String errorMessage = "error reading parameters from \"" + path + "\"" + System.lineSeparator() + "("
-                    + e.getClass().getSimpleName() + ")";
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage, e);
-        }
-
-        // The JSON processing returns null if there is an empty file
-        if (parameters == null) {
-            final String errorMessage = "no parameters found in \"" + path + "\"";
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, errorMessage);
-        }
-
-        // validate the parameters
-        final BeanValidationResult validationResult = parameters.validate();
-        if (!validationResult.isValid()) {
-            final String returnMessage = "validation error(s) on parameters from \"" + path + "\""
-                    + System.lineSeparator() + validationResult.getResult();
-
-            throw new ControlLoopException(Response.Status.NOT_ACCEPTABLE, returnMessage);
-        }
-
-        return parameters;
-    }
-
-}
index a4e62b4..5110ac6 100644 (file)
 
 package org.onap.policy.clamp.controlloop.participant.simulator.main.parameters;
 
-import javax.validation.constraints.NotBlank;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
 import lombok.Getter;
+import lombok.Setter;
 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.common.endpoints.parameters.RestServerParameters;
-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 participant simulator.
  *
  */
-@NotNull
-@NotBlank
+@Validated
 @Getter
-public class ParticipantSimulatorParameters extends ParameterGroupImpl {
-    private RestServerParameters restServerParameters;
+@Setter
+@ConfigurationProperties(prefix = "participant")
+public class ParticipantSimulatorParameters {
+
+    @NotNull
+    @Valid
     private ParticipantIntermediaryParameters intermediaryParameters;
-    private PolicyModelsProviderParameters databaseProviderParameters;
 
-    /**
-     * Create the participant simulator parameter group.
-     *
-     * @param name the parameter group name
-     */
-    public ParticipantSimulatorParameters(final String name) {
-        super(name);
-    }
+    @NotNull
+    @ParameterGroupConstraint
+    private PolicyModelsProviderParameters databaseProviderParameters;
 }
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/CDSParticipantConfig.json
deleted file mode 100644 (file)
index 544edb1..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "restServerParameters": {
-        "host": "0.0.0.0",
-        "port": 6969,
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": false,
-        "aaf": false
-    },
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantId": {
-            "name": "org.onap.PM_CDS_Blueprint",
-            "version": "1.0.0"
-        },
-        "participantType": {
-            "name": "org.onap.PM_CDS_Blueprint",
-            "version": "1.0.0"
-        },
-        "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/cdsparticipantsim",
-        "databaseUser": "policy",
-        "databasePassword": "P01icY",
-        "persistenceUnit": "ToscaConceptTest"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/DCAEParticipantConfig.json
deleted file mode 100644 (file)
index e80570f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-{
-    "name":"ParticipantParameterGroup",
-    "participantStatusParameters":{
-        "timeIntervalMs": 10000,
-        "description":"Participant Status",
-        "participantType":{
-            "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
-            "version":"2.3.4"
-        },
-        "participantId":{
-            "name": "DCAEParticipant0",
-            "version":"1.0.0"
-        },
-        "participantDefinition":{
-            "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
-            "version":"2.3.4"
-        }
-    },
-    "topicParameterGroup": {
-        "topicSources" : [{
-            "topic" : "POLICY-CLRUNTIME-PARTICIPANT",
-            "servers" : [ "127.0.0.1:3904" ],
-            "topicCommInfrastructure" : "dmaap"
-        }],
-        "topicSinks" : [{
-            "topic" : "POLICY-CLRUNTIME-PARTICIPANT",
-            "servers" : [ "127.0.0.1:3904" ],
-            "topicCommInfrastructure" : "dmaap"
-        }]
-    }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/PolicyParticipantConfig.json
deleted file mode 100644 (file)
index 8c8fa33..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-{
-    "name":"ParticipantParameterGroup",
-    "participantStatusParameters":{
-        "timeIntervalMs":10000,
-        "description":"Participant Status",
-        "participantType":{
-            "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
-            "version":"2.3.1"
-        },
-        "participantId":{
-            "name": "PolicyParticipant0",
-            "version":"1.0.0"
-        },
-        "participantDefinition":{
-            "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
-            "version":"2.3.1"
-        }
-    },
-    "topicParameterGroup": {
-        "topicSources" : [{
-            "topic" : "POLICY-CLRUNTIME-PARTICIPANT",
-            "servers" : [ "127.0.0.1:3904" ],
-            "topicCommInfrastructure" : "dmaap"
-        }],
-        "topicSinks" : [{
-            "topic" : "POLICY-CLRUNTIME-PARTICIPANT",
-            "servers" : [ "127.0.0.1:3904" ],
-            "topicCommInfrastructure" : "dmaap"
-        }]
-    }
-}
index b1fc135..a45636b 100644 (file)
@@ -12,4 +12,34 @@ server:
     path: /error
 
 participant:
-  file: src/main/resources/config/CDSParticipantConfig.json
+  intermediaryParameters:
+    reportingTimeInterval: 120000
+    description: Participant Description
+    participantId:
+      name: org.onap.PM_CDS_Blueprint
+      version: 1.0.0
+    participantType:
+      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
+      topicSinks[1]:
+        topic: POLICY-NOTIFICATION
+        servers[0]: ${topicServer: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/cdsparticipantsim
+    databaseUser: policy
+    databasePassword: P01icY
+    persistenceUnit: ToscaConceptTest
index 2c9b1cc..c53410b 100644 (file)
 
 package org.onap.policy.clamp.controlloop.participant.simulator.main.parameters;
 
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
 import org.onap.policy.common.endpoints.parameters.TopicParameters;
-import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -46,30 +38,20 @@ public class CommonTestData {
     public static final String DESCRIPTION = "Participant description";
     public static final long TIME_INTERVAL = 2000;
     public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
-    private static final String REST_SERVER_PASSWORD = "zb!XztG34";
-    private static final String REST_SERVER_USER = "healthcheck";
-    private static final int REST_SERVER_PORT = 6969;
-    public static final String REST_SERVER_HOST = "0.0.0.0";
-    private static final boolean REST_SERVER_HTTPS = true;
-    private static final boolean REST_SERVER_AAF = false;
 
-    public static final Coder coder = new StandardCoder();
+    public static final Coder CODER = new StandardCoder();
 
     /**
-     * Converts the contents of a map to a parameter class.
+     * Get ParticipantSimulatorParameters.
      *
-     * @param <T> the specific parameter group type to convert
-     * @param source property map
-     * @param clazz class of object to be created from the map
-     * @return a new object represented by the map
-     * @throws ControlLoopRuntimeException on parameter parsing errors
+     * @return ParticipantSimulatorParameters
      */
-    public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+    public ParticipantSimulatorParameters getParticipantSimulatorParameters() {
         try {
-            return coder.convert(source, clazz);
+            return CODER.convert(getParticipantParameterGroupMap(PARTICIPANT_GROUP_NAME),
+                    ParticipantSimulatorParameters.class);
         } catch (final CoderException e) {
-            throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE,
-                "cannot create " + clazz.getName() + " from map", e);
+            throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
         }
     }
 
@@ -84,33 +66,11 @@ public class CommonTestData {
         final Map<String, Object> map = new TreeMap<>();
 
         map.put("name", name);
-        map.put("restServerParameters", getRestServerParametersMap(false));
         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
         map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false));
         return map;
     }
 
-    /**
-     * Returns a property map for a RestServerParameters map for test cases.
-     *
-     * @param isEmpty boolean value to represent that object created should be empty or not
-     * @return a property map suitable for constructing an object
-     */
-    public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
-        final Map<String, Object> map = new TreeMap<>();
-        map.put("https", REST_SERVER_HTTPS);
-        map.put("aaf", REST_SERVER_AAF);
-
-        if (!isEmpty) {
-            map.put("host", REST_SERVER_HOST);
-            map.put("port", REST_SERVER_PORT);
-            map.put("userName", REST_SERVER_USER);
-            map.put("password", REST_SERVER_PASSWORD);
-        }
-
-        return map;
-    }
-
     /**
      * Returns a property map for a databaseProviderParameters map for test cases.
      *
@@ -190,58 +150,6 @@ public class CommonTestData {
         return participantId;
     }
 
-    /**
-     * Gets the standard participant parameters.
-     *
-     * @param port port to be inserted into the parameters
-     * @return the standard participant parameters
-     * @throws ControlLoopRuntimeException on parameter read errors
-     */
-    public ParticipantSimulatorParameters getParticipantParameterGroup(int port) {
-        try {
-            return coder.decode(getParticipantParameterGroupAsString(port), ParticipantSimulatorParameters.class);
-
-        } catch (CoderException e) {
-            throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, "cannot read participant parameters", e);
-        }
-    }
-
-    /**
-     * Gets the standard participant parameters, as a String.
-     *
-     * @param port port to be inserted into the parameters
-     * @return the standard participant parameters
-     * @throws ControlLoopRuntimeException on parameter read errors
-     */
-    public static String getParticipantParameterGroupAsString(int port) {
-
-        try {
-            File file = new File(getParamFile());
-            String json = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
-
-            json = json.replace("${port}", String.valueOf(port));
-            json = json.replace("${dbName}", "jdbc:h2:mem:testdb");
-
-            return json;
-
-        } catch (IOException e) {
-            throw new ControlLoopRuntimeException(Response.Status.NOT_ACCEPTABLE, "cannot read participant parameters",
-                e);
-
-        }
-    }
-
-    /**
-     * Gets the full path to the parameter file, which may vary depending on whether or
-     * not this is an end-to-end test.
-     *
-     * @return the parameter file name
-     */
-    private static String getParamFile() {
-        String paramFile = "src/test/resources/parameters/TestParametersStd.json";
-        return paramFile;
-    }
-
     /**
      * Nulls out a field within a JSON string.
      *
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameterHandler.java
deleted file mode 100644 (file)
index 44b49f3..0000000
+++ /dev/null
@@ -1,71 +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.participant.simulator.main.parameters;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileNotFoundException;
-import org.apache.commons.io.DirectoryWalker.CancelException;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
-import org.onap.policy.common.utils.coder.CoderException;
-
-/**
- * Class to perform unit test of {@link ParticipantParameterHandler}.
- */
-class TestParticipantSimulatorParameterHandler {
-
-    @Test
-    void testParameterHandlerNoParameterFile() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/NoParametersFile.json";
-
-        assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path))
-            .hasCauseInstanceOf(CoderException.class)
-            .hasRootCauseInstanceOf(FileNotFoundException.class);
-    }
-
-    @Test
-    void testParameterHandlerInvalidParameters() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/InvalidParameters.json";
-
-        assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path))
-            .hasMessageStartingWith("error reading parameters from")
-            .hasCauseInstanceOf(CoderException.class);
-    }
-
-    @Test
-    void testParameterHandlerNoParameters() throws CancelException, ControlLoopException {
-        final String path = "src/test/resources/parameters/EmptyParameters.json";
-
-        assertThatThrownBy(() -> new ParticipantSimulatorParameterHandler().toParticipantSimulatorParameters(path))
-            .hasMessageContaining("no parameters found");
-    }
-
-    @Test
-    void testParticipantParameterGroup() throws ControlLoopException {
-        final String path = "src/test/resources/parameters/TestParameters.json";
-
-        final ParticipantSimulatorParameters parGroup = new ParticipantSimulatorParameterHandler()
-                .toParticipantSimulatorParameters(path);
-        assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, parGroup.getName());
-    }
-}
index 41c5b09..e5c7b5e 100644 (file)
 package org.onap.policy.clamp.controlloop.participant.simulator.main.parameters;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 
-import java.util.Map;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
 import org.junit.jupiter.api.Test;
-import org.onap.policy.common.parameters.ValidationResult;
 
 /**
  * Class to perform unit test of {@link ParticipantParameterGroup}.
  */
 class TestParticipantSimulatorParameters {
-    CommonTestData commonTestData = new CommonTestData();
-
-    @Test
-    void testParticipantParameterGroup_Named() {
-        final ParticipantSimulatorParameters participantParameters = new ParticipantSimulatorParameters("my-name");
-        assertEquals("my-name", participantParameters.getName());
-    }
+    private CommonTestData commonTestData = new CommonTestData();
+    private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
 
     @Test
     void testParticipantParameterGroup() {
-        final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantSimulatorParameters.class);
-        assertThat(participantParameters.validate().isValid()).isTrue();
-        assertEquals(CommonTestData.PARTICIPANT_GROUP_NAME, participantParameters.getName());
+        final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty();
     }
 
     @Test
-    void testParticipantParameterGroup_NullName() {
-        final ParticipantSimulatorParameters participantParameters = commonTestData
-                .toObject(commonTestData.getParticipantParameterGroupMap(null),
-                        ParticipantSimulatorParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertFalse(validationResult.isValid());
-        assertEquals(null, participantParameters.getName());
-        assertThat(validationResult.getResult()).contains("is null");
-    }
-
-    @Test
-    void testParticipantParameterGroup_EmptyName() {
-        final ParticipantSimulatorParameters participantParameters = commonTestData
-                .toObject(commonTestData.getParticipantParameterGroupMap(""),
-                                ParticipantSimulatorParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertFalse(validationResult.isValid());
-        assertEquals("", participantParameters.getName());
-        assertThat(validationResult.getResult()).contains(
-                "item \"name\" value \"\" INVALID, " + "is blank");
+    void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() {
+        final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
+        participantParameters.setIntermediaryParameters(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
     }
 
     @Test
-    void testParticipantParameterGroup_SetName() {
-        final ParticipantSimulatorParameters participantParameters = commonTestData.toObject(
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME),
-                ParticipantSimulatorParameters.class);
-        participantParameters.setName("ParticipantNewGroup");
-        assertThat(participantParameters.validate().isValid()).isTrue();
-        assertEquals("ParticipantNewGroup", participantParameters.getName());
+    void testParticipantParameterGroup_EmptyDatabaseProviderParameters() {
+        final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
+        participantParameters.setDatabaseProviderParameters(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
     }
 
     @Test
-    void testParticipantParameterGroup_EmptyParticipantIntermediaryParameters() {
-        final Map<String, Object> map =
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME);
-        map.replace("intermediaryParameters", commonTestData.getIntermediaryParametersMap(true));
-        final ParticipantSimulatorParameters participantParameters =
-                commonTestData.toObject(map, ParticipantSimulatorParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertNull(validationResult.getResult());
+    void testParticipantPolicyParameters_NullTopicSinks() {
+        final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
+        participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
     }
 
     @Test
-    void testParticipantParameterGroupp_EmptyTopicParameters() {
-        final Map<String, Object> map =
-                commonTestData.getParticipantParameterGroupMap(CommonTestData.PARTICIPANT_GROUP_NAME);
-        final Map<String, Object> intermediaryParametersMap = commonTestData.getIntermediaryParametersMap(false);
-        intermediaryParametersMap.put("clampControlLoopTopics", commonTestData.getTopicParametersMap(true));
-        map.replace("intermediaryParameters", intermediaryParametersMap);
-
-        final ParticipantSimulatorParameters participantParameters =
-                commonTestData.toObject(map, ParticipantSimulatorParameters.class);
-        final ValidationResult validationResult = participantParameters.validate();
-        assertNull(validationResult.getResult());
+    void testParticipantPolicyParameters_NullTopicSources() {
+        final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
+        participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSources(null);
+        assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
     }
 }
index c31bb9d..89c57bb 100644 (file)
@@ -4,4 +4,32 @@ spring.security.user.password=zb!XztG34
 server.servlet.context-path=/onap/participantsim
 server.error.path=/error
 
-participant.file=src/test/resources/parameters/TestParameters.json
+participant.restServerParameters.host=0.0.0.0
+participant.restServerParameters.port=6969
+participant.restServerParameters.userName=healthcheck
+participant.restServerParameters.password=zb!XztG34
+participant.restServerParameters.https=false
+participant.restServerParameters.aaf=false
+participant.intermediaryParameters.reportingTimeInterval=120000
+participant.intermediaryParameters.description=Participant Description
+participant.intermediaryParameters.participantId.name=org.onap.PM_CDS_Blueprint
+participant.intermediaryParameters.participantId.version=1.0.0
+participant.intermediaryParameters.participantType.name=org.onap.PM_CDS_Blueprint
+participant.intermediaryParameters.participantType.version=1.0.0
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].topicCommInfrastructure=dmaap
+participant.intermediaryParameters.clampControlLoopTopics.topicSources[0].fetchTimeout=15000
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topic=POLICY-CLRUNTIME-PARTICIPANT
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topicCommInfrastructure=dmaap
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topic=POLICY-NOTIFICATION
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].servers[0]=localhost
+participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topicCommInfrastructure=dmaap
+participant.databaseProviderParameters.name=PolicyProviderParameterGroup
+participant.databaseProviderParameters.implementation=org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
+participant.databaseProviderParameters.databaseDriver=org.h2.Driver
+participant.databaseProviderParameters.databaseUrl=jdbc:h2:mem:testdb
+participant.databaseProviderParameters.databaseUser=policy
+participant.databaseProviderParameters.databasePassword=P01icY
+participant.databaseProviderParameters.persistenceUnit=ToscaConceptTest
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/EmptyParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/EmptyParameters.json
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/InvalidParameters.json
deleted file mode 100644 (file)
index 1035ccb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "name": "
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/NoParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/NoParameters.json
deleted file mode 100644 (file)
index 7a73a41..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-{
-}
\ No newline at end of file
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParameters.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParameters.json
deleted file mode 100644 (file)
index 8c59404..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-    "restServerParameters": {
-        "host": "0.0.0.0",
-        "port": 6969,
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": false,
-        "aaf": false
-    },
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantId": {
-            "name": "org.onap.PM_CDS_Blueprint",
-            "version": "1.0.0"
-        },
-        "participantType": {
-            "name": "org.onap.PM_CDS_Blueprint",
-            "version": "1.0.0"
-        },
-        "clampControlLoopTopics": {
-            "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"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParametersStd.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/TestParametersStd.json
deleted file mode 100644 (file)
index 0295a8f..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-{
-    "name": "ControlLoopParticipantGroup",
-     "restServerParameters": {
-        "host": "0.0.0.0",
-        "port": ${port},
-        "userName": "healthcheck",
-        "password": "zb!XztG34",
-        "https": false,
-        "aaf": false
-    },
-    "intermediaryParameters": {
-        "name": "Participant parameters",
-        "reportingTimeInterval": 120000,
-        "description": "Participant Description",
-        "participantId": {
-            "name": "org.onap.PM_CDS_Blueprint",
-            "version": "1.0.0"
-        },
-        "participantType": {
-            "name": "org.onap.PM_CDS_Blueprint",
-            "version": "1.0.0"
-        },
-        "clampControlLoopTopics": {
-            "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"
-                }
-            ]
-        }
-    },
-    "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"
-    }
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/Unreadable.json b/participant/participant-impl/participant-impl-simulator/src/test/resources/parameters/Unreadable.json
deleted file mode 100644 (file)
index fc36b49..0000000
+++ /dev/null
@@ -1,61 +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.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"
-            }
-        ]
-    }
-}
-
-
index 18ee29f..3eebd17 100644 (file)
@@ -95,7 +95,7 @@ public class ControlLoopHandler implements Closeable {
      * @return controlLoopElement the updated controlloop element
      */
     public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState orderedState,
-        ControlLoopState newState) {
+            ControlLoopState newState) {
 
         if (id == null) {
             return null;
@@ -161,7 +161,7 @@ public class ControlLoopHandler implements Closeable {
      * @param orderedState controlloop ordered state
      */
     private void handleState(final ControlLoop controlLoop, final ParticipantResponseDetails response,
-        ControlLoopOrderedState orderedState) {
+            ControlLoopOrderedState orderedState) {
         switch (orderedState) {
             case UNINITIALISED:
                 handleUninitialisedState(controlLoop, orderedState, response);
@@ -197,8 +197,8 @@ public class ControlLoopHandler implements Closeable {
         // 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);
+            response.setResponseMessage("Control loop " + updateMsg.getControlLoopId()
+                    + " already defined on participant " + participantId);
 
             messageSender.sendResponse(response);
             return;
@@ -226,7 +226,7 @@ public class ControlLoopHandler implements Closeable {
 
         response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
         response.setResponseMessage(
-            "Control loop " + updateMsg.getControlLoopId() + " defined on participant " + participantId);
+                "Control loop " + updateMsg.getControlLoopId() + " defined on participant " + participantId);
 
         messageSender.sendResponse(response);
     }
@@ -239,7 +239,7 @@ public class ControlLoopHandler implements Closeable {
      * @param response participant response
      */
     private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
-        final ParticipantResponseDetails response) {
+            final ParticipantResponseDetails response) {
         handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED, response);
         controlLoopMap.remove(controlLoop.getKey().asIdentifier());
 
@@ -262,7 +262,7 @@ public class ControlLoopHandler implements Closeable {
      * @param response participant response
      */
     private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
-        final ParticipantResponseDetails response) {
+            final ParticipantResponseDetails response) {
         handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE, response);
     }
 
@@ -274,7 +274,7 @@ public class ControlLoopHandler implements Closeable {
      * @param response participant response
      */
     private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
-        final ParticipantResponseDetails response) {
+            final ParticipantResponseDetails response) {
         handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING, response);
     }
 
@@ -287,7 +287,7 @@ public class ControlLoopHandler implements Closeable {
      * @param response the response to the state change request
      */
     private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState,
-        ControlLoopState newState, ParticipantResponseDetails response) {
+            ControlLoopState newState, ParticipantResponseDetails response) {
 
         if (orderedState.equals(controlLoop.getOrderedState())) {
             response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
@@ -304,7 +304,7 @@ public class ControlLoopHandler implements Closeable {
 
         response.setResponseStatus(ParticipantResponseStatus.SUCCESS);
         response.setResponseMessage(
-            "ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState);
+                "ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState);
         controlLoop.setOrderedState(orderedState);
     }
 
index 913c050..5e414b1 100644 (file)
@@ -111,15 +111,14 @@ public class ParticipantHandler implements Closeable {
             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());
+                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.
      *
@@ -196,8 +195,7 @@ public class ParticipantHandler implements Closeable {
      * @param participantState participant state
      * @return the participant
      */
-    public Participant updateParticipantState(ToscaConceptIdentifier definition,
-            ParticipantState participantState) {
+    public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState participantState) {
         if (!Objects.equals(definition, participantId)) {
             LOGGER.debug("No participant with this ID {}", definition.getName());
             return null;
index 8e3440e..5627abf 100644 (file)
 
 package org.onap.policy.clamp.controlloop.participant.intermediary.parameters;
 
+import javax.validation.Valid;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 import lombok.Getter;
+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.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
  * Class to hold all parameters needed for participant component.
  */
-@NotNull
-@NotBlank
 @Getter
-public class ParticipantIntermediaryParameters extends ParameterGroupImpl {
+@Setter
+public class ParticipantIntermediaryParameters {
+
     // The ID and description of this participant
+    @NotNull
+    @Valid
     private ToscaConceptIdentifier participantId;
+
+    @NotBlank
     private String description;
 
     // The participant type of this participant
+    @NotNull
+    @Valid
     private ToscaConceptIdentifier participantType;
 
     // The time interval for periodic reporting of status to the CLAMP control loop server
     private long reportingTimeInterval;
 
-    // DMaaP topics for communicating with the CLAMP control loop server
+    @NotNull
+    @ParameterGroupConstraint
     private TopicParameterGroup clampControlLoopTopics;
-
-    /**
-     * Create the participant parameter group.
-     *
-     * @param instanceId instance id of the event.
-     */
-    public ParticipantIntermediaryParameters(final String instanceId) {
-        super(instanceId);
-    }
 }