summaryrefslogtreecommitdiffstats
path: root/models-sim/policy-models-simulators
diff options
context:
space:
mode:
Diffstat (limited to 'models-sim/policy-models-simulators')
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java65
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/appc.lcm.request.json17
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/simParameters.json8
3 files changed, 57 insertions, 33 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 8333800f3..a0b165564 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
@@ -22,7 +22,9 @@ package org.onap.policy.models.simulators;
import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import lombok.AccessLevel;
@@ -85,9 +87,8 @@ public class Main extends ServiceManagerContainer {
AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
- // @formatter:off
-
// REST server simulators
+ // @formatter:off
for (ClassRestServerParameters restsim : params.getRestServers()) {
AtomicReference<HttpServletServer> ref = new AtomicReference<>();
addAction(restsim.getName(),
@@ -98,23 +99,30 @@ public class Main extends ServiceManagerContainer {
// NOTE: topics must be started AFTER the (dmaap) rest servers
// topic sinks
- AtomicReference<List<TopicSink>> sinkRef = new AtomicReference<>();
- addAction("topic sinks", () -> sinkRef.set(buildSinks(params.getTopicSinks())),
- () -> shutdownSinks(sinkRef.get()));
+ Map<String, TopicSink> sinks = new HashMap<>();
+ for (TopicParameters topicParams : params.getTopicSinks()) {
+ String topic = topicParams.getTopic();
+ addAction("Sink " + topic,
+ () -> sinks.put(topic, startSink(topicParams)),
+ () -> sinks.get(topic).shutdown());
+ }
// topic sources
- AtomicReference<List<TopicSource>> sourceRef = new AtomicReference<>();
- addAction("topic sources", () -> sourceRef.set(buildSources(params.getTopicSources())),
- () -> shutdownSources(sourceRef.get()));
+ Map<String, TopicSource> sources = new HashMap<>();
+ for (TopicParameters topicParams : params.getTopicSources()) {
+ String topic = topicParams.getTopic();
+ addAction("Source " + topic,
+ () -> sources.put(topic, startSource(topicParams)),
+ () -> sources.get(topic).shutdown());
+ }
// topic server simulators
for (TopicServerParameters topicsim : params.getTopicServers()) {
AtomicReference<TopicServer<?>> ref = new AtomicReference<>();
addAction(topicsim.getName(),
- () -> ref.set(buildTopicServer(topicsim, sinkRef.get(), sourceRef.get())),
+ () -> ref.set(buildTopicServer(topicsim, sinks, sources)),
() -> ref.get().shutdown());
}
-
// @formatter:on
}
@@ -164,20 +172,16 @@ public class Main extends ServiceManagerContainer {
return prov;
}
- protected List<TopicSink> buildSinks(List<TopicParameters> params) {
- return TopicEndpointManager.getManager().addTopicSinks(params);
+ private TopicSink startSink(TopicParameters params) {
+ TopicSink sink = TopicEndpointManager.getManager().addTopicSinks(List.of(params)).get(0);
+ sink.start();
+ return sink;
}
- private void shutdownSinks(List<TopicSink> sinks) {
- sinks.forEach(TopicSink::shutdown);
- }
-
- protected List<TopicSource> buildSources(List<TopicParameters> params) {
- return TopicEndpointManager.getManager().addTopicSources(params);
- }
-
- private void shutdownSources(List<TopicSource> sources) {
- sources.forEach(TopicSource::shutdown);
+ private TopicSource startSource(TopicParameters params) {
+ TopicSource source = TopicEndpointManager.getManager().addTopicSources(List.of(params)).get(0);
+ source.start();
+ return source;
}
private HttpServletServer buildRestServer(String dmaapName, ClassRestServerParameters params) {
@@ -201,17 +205,20 @@ public class Main extends ServiceManagerContainer {
}
}
- private TopicServer<?> buildTopicServer(TopicServerParameters params, List<TopicSink> sinks,
- List<TopicSource> sources) {
+ private TopicServer<?> buildTopicServer(TopicServerParameters params, Map<String, TopicSink> sinks,
+ Map<String, TopicSource> sources) {
try {
// find the desired sink
- TopicSink sink = sinks.stream().filter(sink2 -> sink2.getTopic().equals(params.getSink())).findAny()
- .orElseThrow(() -> new IllegalArgumentException("invalid sink topic " + params.getSink()));
+ TopicSink sink = sinks.get(params.getSink());
+ if (sink == null) {
+ throw new IllegalArgumentException("invalid sink topic " + params.getSink());
+ }
// find the desired source
- TopicSource source = sources.stream().filter(source2 -> source2.getTopic().equals(params.getSource()))
- .findAny().orElseThrow(() -> new IllegalArgumentException(
- "invalid source topic " + params.getSource()));
+ TopicSource source = sources.get(params.getSource());
+ if (source == null) {
+ throw new IllegalArgumentException("invalid source topic " + params.getSource());
+ }
// create the topic server
return (TopicServer<?>) Class.forName(params.getProviderClass())
diff --git a/models-sim/policy-models-simulators/src/test/resources/appc.lcm.request.json b/models-sim/policy-models-simulators/src/test/resources/appc.lcm.request.json
new file mode 100644
index 000000000..cf2ebd521
--- /dev/null
+++ b/models-sim/policy-models-simulators/src/test/resources/appc.lcm.request.json
@@ -0,0 +1,17 @@
+{
+ "body": {
+ "input": {
+ "common-header": {
+ "timestamp": "2017-08-25T21:06:23.037Z",
+ "api-ver": "5.00",
+ "originator-id": "664be3d2-6c12-4f4b-a3e7-c349acced200",
+ "request-id": "664be3d2-6c12-4f4b-a3e7-c349acced200",
+ "sub-request-id": "111be3d2-6c12-4f4b-a3e7-c349acced200",
+ "flags": {}
+ }
+ }
+ },
+ "version": "2.0",
+ "rpc-name": "restart",
+ "type": "request"
+}
diff --git a/models-sim/policy-models-simulators/src/test/resources/simParameters.json b/models-sim/policy-models-simulators/src/test/resources/simParameters.json
index c7abb2973..5f946f105 100644
--- a/models-sim/policy-models-simulators/src/test/resources/simParameters.json
+++ b/models-sim/policy-models-simulators/src/test/resources/simParameters.json
@@ -58,7 +58,7 @@
"useHttps": true
},
{
- "topic": "APPC-LCM-READ",
+ "topic": "APPC-LCM-WRITE",
"servers": ["localhost"],
"topicCommInfrastructure": "DMAAP",
"useHttps": true
@@ -72,7 +72,7 @@
"useHttps": true
},
{
- "topic": "APPC-LCM-WRITE",
+ "topic": "APPC-LCM-READ",
"servers": ["localhost"],
"topicCommInfrastructure": "DMAAP",
"useHttps": true
@@ -88,8 +88,8 @@
{
"name": "APPC-LCM simulator",
"providerClass": "org.onap.policy.simulators.AppcLcmTopicServer",
- "sink": "APPC-LCM-READ",
- "source": "APPC-LCM-WRITE"
+ "sink": "APPC-LCM-WRITE",
+ "source": "APPC-LCM-READ"
}
]
}