aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-policy/src/main
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-06-15 16:01:31 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2021-06-23 17:07:17 +0100
commitdbc13c78875a3d5493054a7252a7804daae8cf1f (patch)
tree635e3600320c38a44a9f0f54db471fcf5e3995ed /participant/participant-impl/participant-impl-policy/src/main
parentdf2d3298e9881410dff5547e0ba9850135d63d5c (diff)
Move parameters from config Json file to application.yaml
Issue-ID: POLICY-3343 Change-Id: Id78c00a5a241337f684a70feeee543f3a88fc01c Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-policy/src/main')
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java40
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java75
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java34
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json53
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml32
5 files changed, 49 insertions, 185 deletions
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
index 9c65d029c..000000000
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParametersConfig.java
+++ /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
index 0d8e70013..000000000
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameterHandler.java
+++ /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;
- }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
index 490722a45..91f7ae47f 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
@@ -20,30 +20,32 @@
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
index bf458fae9..000000000
--- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/PolicyParticipantConfig.json
+++ /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
- }
-}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
index 79eca8f92..7bf4f623a 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml
@@ -1,3 +1,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