summaryrefslogtreecommitdiffstats
path: root/models-sim/policy-models-simulators/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-10-05 11:31:40 -0400
committerJim Hahn <jrh3@att.com>2020-10-05 11:37:56 -0400
commit66cce3f7afce095871b339440f7816389ddc614a (patch)
treebe135336b8e87f63d2f14cb3a669e5bf97630afa /models-sim/policy-models-simulators/src/main
parentc48e63f81e072c3cdf3f3fe84983285c0b8f1439 (diff)
Make simulator parameters optional
Modified the simulator to make the DMaaP and GRPC parameters optional so that a simulator can be started without them. Also added parameter validation, as that was not being performed on the DMaaP or GRPC parameters. Also modified the validation so-as not to require the rest server parameter field contained within the DMaaP parameter class. Issue-ID: POLICY-2858 Change-Id: I85dde93c7baf863eca2cb10eab37806f3e08a087 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-sim/policy-models-simulators/src/main')
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java18
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java10
2 files changed, 19 insertions, 9 deletions
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
index a0fafbc9b..f82423c11 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
@@ -83,18 +83,22 @@ public class Main extends ServiceManagerContainer {
}
DmaapSimParameterGroup dmaapProv = params.getDmaapProvider();
- String dmaapName = dmaapProv.getName();
- String provName = dmaapName.replace("simulator", "provider");
+ String dmaapName = (dmaapProv != null ? dmaapProv.getName() : null);
// dmaap provider
- AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
- addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
+ if (dmaapProv != null) {
+ String provName = dmaapName.replace("simulator", "provider");
+ AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
+ addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
+ }
CdsServerParameters cdsServer = params.getGrpcServer();
// Cds Simulator
- AtomicReference<CdsSimulator> cdsSim = new AtomicReference<>();
- addAction(cdsServer.getName(), () -> cdsSim.set(buildCdsSimulator(cdsServer)), () -> cdsSim.get().stop());
+ if (cdsServer != null) {
+ AtomicReference<CdsSimulator> cdsSim = new AtomicReference<>();
+ addAction(cdsServer.getName(), () -> cdsSim.set(buildCdsSimulator(cdsServer)), () -> cdsSim.get().stop());
+ }
// REST server simulators
// @formatter:off
@@ -276,7 +280,7 @@ public class Main extends ServiceManagerContainer {
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "false");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
- if (dmaapName.equals(params.getName())) {
+ if (dmaapName != null && dmaapName.equals(params.getName())) {
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
String.join(",", CambriaMessageBodyHandler.class.getName(),
GsonMessageBodyHandler.class.getName(),
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
index 788829f36..c22527165 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
@@ -27,14 +27,12 @@ import lombok.Getter;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.BeanValidator;
-import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
/**
* Simulator parameters.
*/
@Getter
-@NotNull
public class SimulatorParameters {
/**
@@ -77,6 +75,14 @@ public class SimulatorParameters {
public BeanValidationResult validate(String containerName) {
BeanValidationResult result = new BeanValidator().validateTop(containerName, this);
+ if (dmaapProvider != null) {
+ result.addResult(dmaapProvider.validate());
+ }
+
+ if (grpcServer != null) {
+ result.addResult(grpcServer.validate());
+ }
+
result.validateList("restServers", restServers, params -> params.validate("restServers"));
result.validateList("topicServers", topicServers, params -> params.validate("topicServers"));