aboutsummaryrefslogtreecommitdiffstats
path: root/models-sim
diff options
context:
space:
mode:
authorAjith Sreekumar <ajith.sreekumar@bell.ca>2020-10-01 11:44:39 +0000
committerGerrit Code Review <gerrit@onap.org>2020-10-01 11:44:39 +0000
commite6c06754e2edd4a5ff108983828a2dbb15739a2e (patch)
tree5b76e2d5e78728dcf49c4cff2f1e118a4f47d01a /models-sim
parentb8c397eb62b91cbcadd10448410a3487ab0dfec8 (diff)
parent7fb6242e113efb3653c7846ffe7ac2959612daf3 (diff)
Merge "Enhance gRPC Simulator:"
Diffstat (limited to 'models-sim')
-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
14 files changed, 655 insertions, 2 deletions
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>