aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-09-23 12:39:46 +0100
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-09-30 13:43:42 +0100
commit7fb6242e113efb3653c7846ffe7ac2959612daf3 (patch)
treec01b16fd7735978224c049a8eebb97809b264594
parent5a4ba9fa46bdebdcfe1796ffeaa3c9be29b89b45 (diff)
Enhance gRPC Simulator:
1.Make gRPC Simulator respond to different actions by generating the response on the basis of received request. 2.Include CDS Simulator in policy-models-simulator 3.Introduce a packages module in models-sim to package the docker image of policy-models-simulator which includes all the simulators(pdp-simulator to be added in future) in models. 4.The Jenkins job changes to push this newly created Docker image may be taken in the next release. Issue-ID: POLICY-2828 Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca> Change-Id: Ic1663bbe8205c64a8133ea0b0c28152f21d0732a
-rw-r--r--models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/CdsSimulator.java62
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json22
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json29
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json22
-rw-r--r--models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json29
-rw-r--r--models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java17
-rw-r--r--models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json22
-rw-r--r--models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json29
-rw-r--r--models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/create-subscription.json29
-rw-r--r--models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json22
-rw-r--r--models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json29
-rw-r--r--models-sim/packages/models-simulator-docker/pom.xml174
-rw-r--r--models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile60
-rw-r--r--models-sim/packages/models-simulator-docker/src/main/docker/simulators.sh43
-rw-r--r--models-sim/packages/models-simulator-tarball/pom.xml88
-rw-r--r--models-sim/packages/models-simulator-tarball/src/main/assembly.xml50
-rw-r--r--models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-keystorebin0 -> 4431 bytes
-rw-r--r--models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-truststorebin0 -> 124180 bytes
-rw-r--r--models-sim/packages/pom.xml62
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java97
-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.java3
-rw-r--r--models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/CdsServerParametersTest.java46
-rw-r--r--models-sim/policy-models-simulators/src/test/resources/simParameters.json14
-rw-r--r--models-sim/pom.xml2
25 files changed, 959 insertions, 10 deletions
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/CdsSimulator.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/CdsSimulator.java
index dbbaa1681..f1785c8ee 100644
--- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/CdsSimulator.java
+++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/CdsSimulator.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,13 +29,16 @@ import io.grpc.netty.NettyServerBuilder;
import io.grpc.stub.StreamObserver;
import java.io.IOException;
import java.net.InetSocketAddress;
-import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import lombok.Getter;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput.Builder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
public class CdsSimulator {
@Getter
@@ -42,6 +46,10 @@ public class CdsSimulator {
private final Server server;
+ private final String resourceLocation;
+
+ private AtomicInteger countOfEvents = new AtomicInteger(1);
+
/**
* Constructs the object, but does not start it.
*
@@ -49,7 +57,21 @@ public class CdsSimulator {
* @param port port of the server
*/
public CdsSimulator(String host, int port) {
+ this(host, port, "org/onap/policy/simulators/cds/", 0, 0);
+ }
+
+ /**
+ * Constructs the object, but does not start it.
+ *
+ * @param host host name of the server
+ * @param port port of the server
+ * @param countOfSuccesfulEvents number of successive successful events
+ * @param requestedResponseDelayMs time for the request to be processed
+ */
+ public CdsSimulator(String host, int port, String resourceLocation, int countOfSuccesfulEvents,
+ long requestedResponseDelayMs) {
this.port = port;
+ this.resourceLocation = resourceLocation;
BluePrintProcessingServiceImplBase testCdsBlueprintServerImpl = new BluePrintProcessingServiceImplBase() {
@@ -62,18 +84,17 @@ public class CdsSimulator {
@Override
public void onNext(final ExecutionServiceInput executionServiceInput) {
try {
- String responseString = IOUtils.toString(
- getClass().getResource("cds/CreateSubscriptionResponseEvent.json"),
- StandardCharsets.UTF_8);
+ String responseString = getResponseString(executionServiceInput, countOfSuccesfulEvents);
Builder builder = ExecutionServiceOutput.newBuilder();
JsonFormat.parser().ignoringUnknownFields().merge(responseString, builder);
+ TimeUnit.MILLISECONDS.sleep(requestedResponseDelayMs);
responseObserver.onNext(builder.build());
-
} catch (InvalidProtocolBufferException e) {
throw new SimulatorRuntimeException("Cannot convert ExecutionServiceOutput output", e);
-
} catch (IOException e) {
throw new SimulatorRuntimeException("Cannot read ExecutionServiceOutput from file", e);
+ } catch (InterruptedException e) {
+ throw new SimulatorRuntimeException("Execution Interrupted", e);
}
}
@@ -101,4 +122,31 @@ public class CdsSimulator {
public void stop() {
server.shutdown();
}
+
+ /**
+ * Constructs the ResponseString on the basis of request.
+ *
+ * @param executionServiceInput service input
+ * @param countOfSuccesfulEvents number of successive successful events
+ * @return responseString
+ */
+ public String getResponseString(ExecutionServiceInput executionServiceInput, int countOfSuccesfulEvents) {
+ String resourceName = "DefaultResponseEvent";
+ if (!StringUtils.isBlank(executionServiceInput.getActionIdentifiers().getActionName())) {
+ ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
+ resourceName = actionIdentifiers.getBlueprintName() + "-" + actionIdentifiers.getActionName();
+ }
+ if (countOfSuccesfulEvents > 0 && countOfEvents.getAndIncrement() % countOfSuccesfulEvents == 0) {
+ // generating the failure response
+ resourceName = resourceName + "-error.json";
+ } else {
+ resourceName = resourceName + ".json";
+ }
+ String responseString = ResourceUtils.getResourceAsString(resourceLocation + resourceName);
+ if (responseString == null) {
+ responseString = ResourceUtils.getResourceAsString(resourceLocation
+ + "DefaultResponseEvent.json");
+ }
+ return responseString;
+ }
}
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json
new file mode 100644
index 000000000..a66b1114f
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json
@@ -0,0 +1,22 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 500,
+ "message": "failure",
+ "eventType": "EVENT_COMPONENT_FAILURE",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json
new file mode 100644
index 000000000..adb51adcb
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json
@@ -0,0 +1,29 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 200,
+ "message": "success",
+ "eventType": "EVENT_COMPONENT_EXECUTED",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ },
+ "payload": {
+ "create-subscription-response": {
+ "odl-response": {
+ "status": "success"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json
new file mode 100644
index 000000000..a66b1114f
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json
@@ -0,0 +1,22 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 500,
+ "message": "failure",
+ "eventType": "EVENT_COMPONENT_FAILURE",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json
new file mode 100644
index 000000000..adb51adcb
--- /dev/null
+++ b/models-interactions/model-simulators/src/main/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json
@@ -0,0 +1,29 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 200,
+ "message": "success",
+ "eventType": "EVENT_COMPONENT_EXECUTED",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ },
+ "payload": {
+ "create-subscription-response": {
+ "odl-response": {
+ "status": "success"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java
index 5f82b7e94..fea03e3e4 100644
--- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java
+++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,11 +29,13 @@ import io.grpc.internal.DnsNameResolverProvider;
import io.grpc.internal.PickFirstLoadBalancerProvider;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.StreamObserver;
+import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
+import org.json.simple.parser.ParseException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -40,7 +43,9 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessin
import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
public class CdsSimulatorTest {
private static final StandardCoder coder = new StandardCoder();
@@ -61,7 +66,6 @@ public class CdsSimulatorTest {
public void test() throws Exception {
String reqstr = IOUtils.toString(getClass().getResource("cds/cds.request.json"), StandardCharsets.UTF_8);
ExecutionServiceInput request = coder.decode(reqstr, ExecutionServiceInput.class);
-
ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", sim.getPort())
.nameResolverFactory(new DnsNameResolverProvider())
.loadBalancerFactory(new PickFirstLoadBalancerProvider()).usePlaintext().build();
@@ -111,4 +115,15 @@ public class CdsSimulatorTest {
channel.shutdown();
}
}
+
+ @Test
+ public void testGetResponseString() throws IOException, CoderException, ParseException {
+ CdsSimulator cdsSimulator = new CdsSimulator("localhost", sim.getPort());
+ String reqstr = ResourceUtils.getResourceAsString(
+ "org/onap/policy/simulators/cds/cds.request.json");
+ String responseqstr = ResourceUtils.getResourceAsString(
+ "org/onap/policy/simulators/cds/pm_control-create-subscription.json");
+ ExecutionServiceInput request = coder.decode(reqstr, ExecutionServiceInput.class);
+ assertEquals(responseqstr, cdsSimulator.getResponseString(request, 0));
+ }
}
diff --git a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json
new file mode 100644
index 000000000..a66b1114f
--- /dev/null
+++ b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent-error.json
@@ -0,0 +1,22 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 500,
+ "message": "failure",
+ "eventType": "EVENT_COMPONENT_FAILURE",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json
new file mode 100644
index 000000000..adb51adcb
--- /dev/null
+++ b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/DefaultResponseEvent.json
@@ -0,0 +1,29 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 200,
+ "message": "success",
+ "eventType": "EVENT_COMPONENT_EXECUTED",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ },
+ "payload": {
+ "create-subscription-response": {
+ "odl-response": {
+ "status": "success"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/create-subscription.json b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/create-subscription.json
new file mode 100644
index 000000000..adb51adcb
--- /dev/null
+++ b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/create-subscription.json
@@ -0,0 +1,29 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 200,
+ "message": "success",
+ "eventType": "EVENT_COMPONENT_EXECUTED",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ },
+ "payload": {
+ "create-subscription-response": {
+ "odl-response": {
+ "status": "success"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json
new file mode 100644
index 000000000..a66b1114f
--- /dev/null
+++ b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription-error.json
@@ -0,0 +1,22 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 500,
+ "message": "failure",
+ "eventType": "EVENT_COMPONENT_FAILURE",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ }
+} \ No newline at end of file
diff --git a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json
new file mode 100644
index 000000000..adb51adcb
--- /dev/null
+++ b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/cds/pm_control-create-subscription.json
@@ -0,0 +1,29 @@
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "pm_control",
+ "blueprintVersion": "1.0.0",
+ "actionName": "create-subscription",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 200,
+ "message": "success",
+ "eventType": "EVENT_COMPONENT_EXECUTED",
+ "timestamp": "Fri Mar 20 14:00:26 GMT 2020"
+ },
+ "payload": {
+ "create-subscription-response": {
+ "odl-response": {
+ "status": "success"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/models-sim/packages/models-simulator-docker/pom.xml b/models-sim/packages/models-simulator-docker/pom.xml
new file mode 100644
index 000000000..c6f4717c0
--- /dev/null
+++ b/models-sim/packages/models-simulator-docker/pom.xml
@@ -0,0 +1,174 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 Bell Canada.
+ ================================================================================
+ 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=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.models.sim</groupId>
+ <artifactId>policy-models-sim</artifactId>
+ <version>2.3.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>models-simulator-docker</artifactId>
+ <packaging>pom</packaging>
+
+ <name>${project.artifactId}</name>
+ <description>The module for creating docker images of Simulators component.</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <dist.project.version>${project.version}</dist.project.version>
+ <docker.skip>false</docker.skip>
+ <docker.skip.build>false</docker.skip.build>
+ <docker.skip.push>false</docker.skip.push>
+ <docker.pull.registry>nexus3.onap.org:10001</docker.pull.registry>
+ <docker.push.registry>nexus3.onap.org:10003</docker.push.registry>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmm</maven.build.timestamp.format>
+ </properties>
+
+ <build>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.groovy.maven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <source>
+ println 'Project version: ' + project.properties['dist.project.version']
+ if (project.properties['dist.project.version'] != null) {
+ def versionArray = project.properties['dist.project.version'].split('-')
+ def minMaxVersionArray = versionArray[0].tokenize('.')
+ if (project.properties['dist.project.version'].endsWith("-SNAPSHOT")) {
+ project.properties['project.docker.latest.minmax.tag.version'] =
+ minMaxVersionArray[0] + "." + minMaxVersionArray[1] + "-SNAPSHOT-latest"
+ } else {
+ project.properties['project.docker.latest.minmax.tag.version'] =
+ minMaxVersionArray[0] + "." + minMaxVersionArray[1] + "-STAGING-latest"
+ }
+ println 'New tag for docker: ' + project.properties['project.docker.latest.minmax.tag.version']
+ }
+ </source>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+
+ <configuration>
+ <verbose>true</verbose>
+ <apiVersion>1.23</apiVersion>
+ <pullRegistry>${docker.pull.registry}</pullRegistry>
+ <pushRegistry>${docker.push.registry}</pushRegistry>
+
+ <images>
+ <image>
+ <name>onap/policy-models-simulator</name>
+ <build>
+ <cleanup>try</cleanup>
+ <dockerFile>Dockerfile</dockerFile>
+ <tags>
+ <tag>${project.version}</tag>
+ <tag>${project.version}-${maven.build.timestamp}</tag>
+ <tag>${project.docker.latest.minmax.tag.version}</tag>
+ </tags>
+ <assembly>
+ <inline>
+ <dependencySets>
+ <dependencySet>
+ <includes>
+ <include>org.onap.policy.models.sim:models-simulator-tarball</include>
+ </includes>
+ <outputDirectory>/lib</outputDirectory>
+ <outputFileNameMapping>models-simulator.tar.gz</outputFileNameMapping>
+ </dependencySet>
+ </dependencySets>
+ </inline>
+ </assembly>
+ </build>
+ </image>
+ </images>
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>clean-images</id>
+ <phase>pre-clean</phase>
+ <goals>
+ <goal>remove</goal>
+ </goals>
+ <configuration>
+ <removeAll>true</removeAll>
+ </configuration>
+ </execution>
+
+ <execution>
+ <id>generate-images</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>push-images</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>build</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <image>onap/policy-models-simulator</image>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.models.sim</groupId>
+ <artifactId>models-simulator-tarball</artifactId>
+ <version>2.3.2-SNAPSHOT</version>
+ <classifier>tarball</classifier>
+ <type>tar.gz</type>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile b/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile
new file mode 100644
index 000000000..a4420b343
--- /dev/null
+++ b/models-sim/packages/models-simulator-docker/src/main/docker/Dockerfile
@@ -0,0 +1,60 @@
+#
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+# Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+# ================================================================================
+# 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=========================================================
+#
+
+#
+# Docker file to build an image that runs the simulators
+#
+
+FROM onap/policy-jre-alpine:2.1.1
+
+LABEL maintainer="Policy Team"
+
+ARG POLICY_LOGS=/var/log/onap/policy/simulators
+
+ENV POLICY_HOME /opt/app/policy
+ENV POLICY_LOGS ${POLICY_LOGS}
+
+# Create DMaaP simulator user and group
+# Add simulator-specific directories and set ownership as the simulator user
+RUN mkdir -p ${POLICY_HOME}/simulators \
+ && mkdir -p ${POLICY_HOME}/simulators/bin \
+ && mkdir -p ${POLICY_LOGS} \
+ && mkdir /packages
+
+# Unpack the tarball
+COPY /maven/* /packages
+RUN tar xvfz /packages/models-simulator.tar.gz --directory ${POLICY_HOME}/simulators \
+ && rm /packages/models-simulator.tar.gz
+
+# Ensure everything has the correct permissions
+# Copy scripts simulator user area
+COPY simulators.sh ${POLICY_HOME}/simulators/bin
+RUN find /opt/app -type d -perm 755 \
+ && find /opt/app -type f -perm 644 \
+ && chmod 755 ${POLICY_HOME}/simulators/bin/* \
+ && chown -R policy:policy $POLICY_HOME $POLICY_LOGS
+
+USER policy:policy
+
+ENV PATH ${POLICY_HOME}/simulators/bin:$PATH
+ENTRYPOINT [ "bash", "simulators.sh" ]
diff --git a/models-sim/packages/models-simulator-docker/src/main/docker/simulators.sh b/models-sim/packages/models-simulator-docker/src/main/docker/simulators.sh
new file mode 100644
index 000000000..1cec646de
--- /dev/null
+++ b/models-sim/packages/models-simulator-docker/src/main/docker/simulators.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+# Modifications copyright (C) 2020 Bell Canada. All rights reserved.
+# ================================================================================
+# 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=========================================================
+#
+
+if [ -z "$SIMULATOR_HOME" ]
+then
+ SIMULATOR_HOME=${POLICY_HOME}/simulators
+fi
+
+JAVA_HOME=/usr/lib/jvm/java-11-openjdk
+KEYSTORE="${SIMULATOR_HOME}/etc/ssl/policy-keystore"
+KEYSTORE_PASSWD="Pol1cy_0nap"
+TRUSTSTORE="${SIMULATOR_HOME}/etc/ssl/policy-truststore"
+TRUSTSTORE_PASSWD="Pol1cy_0nap"
+
+${JAVA_HOME}/bin/java \
+ -cp "${SIMULATOR_HOME}/etc:${SIMULATOR_HOME}/lib/*" \
+ -Djavax.net.ssl.keyStore="${KEYSTORE}" \
+ -Djavax.net.ssl.keyStorePassword="${KEYSTORE_PASSWD}" \
+ -Djavax.net.ssl.trustStore="${TRUSTSTORE}" \
+ -Djavax.net.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \
+ org.onap.policy.models.simulators.Main \
+ ${SIMULATOR_HOME}/etc/mounted/simParameters.json
diff --git a/models-sim/packages/models-simulator-tarball/pom.xml b/models-sim/packages/models-simulator-tarball/pom.xml
new file mode 100644
index 000000000..9fb1fb5fd
--- /dev/null
+++ b/models-sim/packages/models-simulator-tarball/pom.xml
@@ -0,0 +1,88 @@
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 2020 Bell Canada.
+ ================================================================================
+ 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=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.models.sim</groupId>
+ <artifactId>policy-models-sim</artifactId>
+ <version>2.3.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>models-simulator-tarball</artifactId>
+
+ <name>${project.artifactId}</name>
+ <description>A module that runs all "simulators", including DMaaP.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.models.sim</groupId>
+ <artifactId>policy-models-simulators</artifactId>
+ <version>2.3.2-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <!-- Output the version of the service -->
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/version.txt</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ <excludes>
+ <exclude>**/version.txt</exclude>
+ </excludes>
+ </resource>
+ </resources>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-complete-tar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly.xml</descriptor>
+ </descriptors>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ </build>
+</project>
diff --git a/models-sim/packages/models-simulator-tarball/src/main/assembly.xml b/models-sim/packages/models-simulator-tarball/src/main/assembly.xml
new file mode 100644
index 000000000..9a2fd65df
--- /dev/null
+++ b/models-sim/packages/models-simulator-tarball/src/main/assembly.xml
@@ -0,0 +1,50 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ Modifications copyright (C) 2020 Bell Canada. All rights reserved.
+ ================================================================================
+ 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=========================================================
+-->
+
+<assembly>
+ <id>tarball</id>
+ <formats>
+ <format>tar.gz</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>true</useProjectArtifact>
+ <outputDirectory>/lib</outputDirectory>
+ <unpack>false</unpack>
+ <scope>runtime</scope>
+ <includes>
+ <include>*:jar</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+ <fileSets>
+ <fileSet>
+ <directory>${project.basedir}/src/main/resources/ssl
+ </directory>
+ <includes>
+ <include>policy*</include>
+ </includes>
+ <outputDirectory>etc${file.separator}ssl</outputDirectory>
+ <lineEnding>keep</lineEnding>
+ </fileSet>
+ </fileSets>
+</assembly>
diff --git a/models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-keystore b/models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-keystore
new file mode 100644
index 000000000..389df5fe5
--- /dev/null
+++ b/models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-keystore
Binary files differ
diff --git a/models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-truststore b/models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-truststore
new file mode 100644
index 000000000..8834ac257
--- /dev/null
+++ b/models-sim/packages/models-simulator-tarball/src/main/resources/ssl/policy-truststore
Binary files differ
diff --git a/models-sim/packages/pom.xml b/models-sim/packages/pom.xml
new file mode 100644
index 000000000..14922559d
--- /dev/null
+++ b/models-sim/packages/pom.xml
@@ -0,0 +1,62 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 Bell Canada.
+ ================================================================================
+ 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=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.models.sim</groupId>
+ <artifactId>policy-models-sim</artifactId>
+ <version>2.3.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>models-sim-packages</artifactId>
+ <packaging>pom</packaging>
+
+ <name>${project.artifactId}</name>
+ <description>The module for packaging the policy-models-simulator component.</description>
+
+ <properties>
+ <!-- There is no code in this sub-module, only holds interfaces. So skip sonar. -->
+ <sonar.skip>true</sonar.skip>
+ </properties>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>models-simulator-tarball</module>
+ </modules>
+ </profile>
+ <profile>
+ <id>docker</id>
+ <modules>
+ <module>models-simulator-tarball</module>
+ <module>models-simulator-docker</module>
+ </modules>
+ <properties>
+ <docker.skip.push>false</docker.skip.push>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java
new file mode 100644
index 000000000..97dc35449
--- /dev/null
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Bell Canada.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.simulators;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterRuntimeException;
+import org.onap.policy.common.parameters.annotations.Max;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotNull;
+
+@Getter
+@Setter
+@ToString
+public class CdsServerParameters implements ParameterGroup {
+
+ // Port range constants
+ private static final int MIN_USER_PORT = 1024;
+ private static final int MAX_USER_PORT = 65535;
+
+ private static final String SERVER_PROPERTIES_TYPE = "CDS gRPC Server Properties";
+
+ // CDS carrier properties
+
+ // Request timeout in seconds
+ @Min(value = 1)
+ private int timeout;
+
+ @Min(value = MIN_USER_PORT)
+ @Max(value = MAX_USER_PORT)
+ private int port;
+
+ @Min(value = 0)
+ private int successRepeatCount;
+
+ private int requestedResponseDelayMs;
+
+ @NotNull
+ private String host;
+
+ @NotNull
+ private String username;
+
+ @NotNull
+ private String password;
+
+ @NotNull
+ private String resourceLocation;
+
+ @Override
+ public String getName() {
+ return SERVER_PROPERTIES_TYPE;
+ }
+
+ @Override
+ public void setName(final String name) {
+ throw new ParameterRuntimeException("The name of this ParameterGroup implementation is always " + getName());
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ return new GroupValidationResult(this);
+ }
+
+ /**
+ * Generate base64-encoded Authorization header from username and password.
+ *
+ * @return Base64 encoded string
+ */
+ public String getBasicAuth() {
+ String encodedAuth = Base64.getEncoder().encodeToString(
+ String.format("%s:%s", getUsername(), getPassword()).getBytes(StandardCharsets.UTF_8));
+ // Return encoded basic auth header
+ return "Basic " + encodedAuth;
+ }
+}
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 ed9ade562..a0fafbc9b 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
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
package org.onap.policy.models.simulators;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
@@ -48,6 +50,7 @@ import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
import org.onap.policy.models.sim.dmaap.rest.CambriaMessageBodyHandler;
import org.onap.policy.models.sim.dmaap.rest.TextMessageBodyHandler;
+import org.onap.policy.simulators.CdsSimulator;
import org.onap.policy.simulators.TopicServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -87,6 +90,12 @@ public class Main extends ServiceManagerContainer {
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());
+
// REST server simulators
// @formatter:off
for (ClassRestServerParameters restsim : params.getRestServers()) {
@@ -173,10 +182,17 @@ public class Main extends ServiceManagerContainer {
DmaapSimProvider prov = new DmaapSimProvider(params);
DmaapSimProvider.setInstance(prov);
prov.start();
-
return prov;
}
+ private CdsSimulator buildCdsSimulator(CdsServerParameters params) throws IOException {
+ CdsSimulator cdsSimulator = new CdsSimulator(params.getHost(), params.getPort(), params.getResourceLocation(),
+ params.getSuccessRepeatCount(), params.getRequestedResponseDelayMs());
+ cdsSimulator.start();
+ return cdsSimulator;
+ }
+
+
private TopicSink startSink(TopicParameters params) {
TopicSink sink = TopicEndpointManager.getManager().addTopicSinks(List.of(params)).get(0);
sink.start();
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 c47ff8876..788829f36 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +45,8 @@ public class SimulatorParameters {
*/
private DmaapSimParameterGroup dmaapProvider;
+ private CdsServerParameters grpcServer;
+
/**
* Parameters for the REST server simulators that are to be started.
*/
diff --git a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/CdsServerParametersTest.java b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/CdsServerParametersTest.java
new file mode 100644
index 000000000..03aae8e61
--- /dev/null
+++ b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/CdsServerParametersTest.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Bell Canada.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.simulators;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+public class CdsServerParametersTest {
+ @Test
+ public void testValidateString() throws CoderException {
+ // some fields missing
+ ValidationResult result = new CdsServerParameters().validate();
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+
+ // everything populated
+ SimulatorParameters simParams = new StandardCoder()
+ .decode(new File("src/test/resources/simParameters.json"), SimulatorParameters.class);
+ CdsServerParameters params = simParams.getGrpcServer();
+ assertTrue(params.validate().isValid());
+ }
+}
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 33821a538..1d1c0aad7 100644
--- a/models-sim/policy-models-simulators/src/test/resources/simParameters.json
+++ b/models-sim/policy-models-simulators/src/test/resources/simParameters.json
@@ -109,5 +109,17 @@
"sink": "SDNR-CL",
"source": "SDNR-CL-RSP"
}
- ]
+ ],
+ "grpcServer": {
+ "name": "CDS simulator",
+ "providerClass": "org.onap.policy.simulators.CdsSimulator",
+ "host": "0.0.0.0",
+ "port": 6680,
+ "timeout": 30,
+ "username": "ccsdkapps",
+ "password": "ccsdkapps",
+ "resourceLocation": "org/onap/policy/simulators/cds/",
+ "successRepeatCount": 0,
+ "requestedResponseDelayMs": 0
+ }
}
diff --git a/models-sim/pom.xml b/models-sim/pom.xml
index 654928e09..ce9cfae06 100644
--- a/models-sim/pom.xml
+++ b/models-sim/pom.xml
@@ -2,6 +2,7 @@
============LICENSE_START=======================================================
Copyright (C) 2019 Nordix Foundation.
Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -40,5 +41,6 @@
<module>models-sim-dmaap</module>
<module>policy-models-sim-pdp</module>
<module>policy-models-simulators</module>
+ <module>packages</module>
</modules>
</project>