aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-simulator/src/main/java
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-simulator/src/main/java
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-simulator/src/main/java')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParametersConfig.java40
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java76
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java33
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java4
5 files changed, 18 insertions, 137 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
index 3aa1c36db..9f6e4aa4b 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
@@ -22,12 +22,14 @@ package org.onap.policy.clamp.controlloop.participant.simulator;
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.simulator.main.parameters")
public class ParticipantSimulatorApplication {
public static void main(String[] args) {
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
index 936df2c57..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/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.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
index 178d08794..000000000
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameterHandler.java
+++ /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;
- }
-
-}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
index a4e62b446..5110ac6a6 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
@@ -20,32 +20,31 @@
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/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java
index 82c1ac602..d4429b879 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/ParticipantErrorController.java
@@ -94,8 +94,4 @@ public class ParticipantErrorController implements ErrorController {
return ResponseEntity.status(getStatus(request)).body(resp);
}
-
- public String getErrorPath() {
- return path;
- }
}