<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-base</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-dao</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-decisions</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-errors</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-examples</artifactId>
onap.datatypes.drools.controller.relation:
derived_from: tosca.datatypes.Root
properties:
- controllerName:
+ name:
type: string
required: true
description: the name of drools controller policy
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.aai</artifactId>
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
import org.onap.policy.aai.AaiConstants;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
Map<String, Object> headers = makeHeaders();
- headers.put("Accept", MediaType.APPLICATION_JSON);
-
StringBuilder str = new StringBuilder(getClient().getBaseUrl());
String path = getPath() + URI_SEP + URLEncoder.encode(getTargetEntity(), StandardCharsets.UTF_8);
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
import org.onap.policy.aai.AaiConstants;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
@Override
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
- Map<String, Object> headers = makeHeaders();
-
- headers.put("Accept", MediaType.APPLICATION_JSON);
+ final Map<String, Object> headers = makeHeaders();
StringBuilder str = new StringBuilder(getClient().getBaseUrl());
import java.util.HashMap;
import java.util.Map;
+import javax.ws.rs.core.MediaType;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
/**
headers.put("X-FromAppId", "POLICY");
headers.put("X-TransactionId", params.getRequestId().toString());
+ headers.put("Accept", MediaType.APPLICATION_JSON);
return headers;
}
protected void verifyHeaders(Map<String, Object> headers) {
assertEquals("POLICY", headers.get("X-FromAppId").toString());
assertEquals(params.getRequestId().toString(), headers.get("X-TransactionId"));
+ assertEquals("application/json", headers.get("Accept").toString());
}
}
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.appc</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.appclcm</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.cds</artifactId>
<dependencies>
--- /dev/null
+{
+ "commonHeader": {
+ "timestamp": "2020-03-20T14:00:25.217Z",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "flag": {
+ },
+ "originatorId": "sdnc"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "my_artifact",
+ "blueprintVersion": "1.0.0",
+ "actionName": "subscribe",
+ "mode": "sync"
+ },
+ "status": {
+ "code": 200,
+ "message": "success",
+ "eventType": "EVENT_COMPONENT_EXECUTED",
+ "timestamp": "2020-07-02T14:56:25.608Z"
+ },
+ "payload": {
+ "subscription-response": {
+ "status": "success"
+ }
+ }
+}
\ No newline at end of file
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.guard</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.sdnc</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.sdnr</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.so</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.test</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actor.vfc</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<artifactId>model-actors</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>actorServiceProvider</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models-interactions</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>aai</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>appc</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>appclcm</artifactId>
<parent>
<artifactId>model-impl</artifactId>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>cds</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>events</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>guard</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models-interactions</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>rest</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>sdnc</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>sdnr</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>so</artifactId>
<parent>
<groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
<artifactId>model-impl</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>vfc</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models-interactions</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.models.policy-models-interactions</groupId>
import io.grpc.stub.StreamObserver;
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.time.Instant;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CdsSimulator implements Runnable {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CdsSimulator.class);
-public class CdsSimulator {
@Getter
private final int port;
@Override
public StreamObserver<ExecutionServiceInput> process(
- final StreamObserver<ExecutionServiceOutput> responseObserver) {
+ final StreamObserver<ExecutionServiceOutput> responseObserver) {
return new StreamObserver<ExecutionServiceInput>() {
@Override
public void onNext(final ExecutionServiceInput executionServiceInput) {
+ LOGGER.info("Received request input to CDS: {}", executionServiceInput);
try {
- String responseString = getResponseString(executionServiceInput, countOfSuccesfulEvents);
- Builder builder = ExecutionServiceOutput.newBuilder();
- JsonFormat.parser().ignoringUnknownFields().merge(responseString, builder);
+ Builder builder = getResponse(executionServiceInput, countOfSuccesfulEvents);
TimeUnit.MILLISECONDS.sleep(requestedResponseDelayMs);
responseObserver.onNext(builder.build());
} catch (InvalidProtocolBufferException e) {
};
server = NettyServerBuilder.forAddress(new InetSocketAddress(host, port)).addService(testCdsBlueprintServerImpl)
- .build();
+ .build();
}
+ /**
+ * Start the server.
+ *
+ * @throws IOException IO exception.
+ */
public void start() throws IOException {
server.start();
+ // The grpc server uses daemon threads by default. Hence the application will exit as soon the main thread
+ // completes. So, wrap the server in a non-daemon thread and call awaitTermination to keep the thread alive
+ // until the server is terminated.
+ new Thread(this).start();
}
+ /**
+ * Stop the server.
+ */
public void stop() {
server.shutdown();
}
*
* @param executionServiceInput service input
* @param countOfSuccesfulEvents number of successive successful events
- * @return responseString
+ * @return builder for ExecutionServiceOutput response
+ * @throws InvalidProtocolBufferException when response string cannot be converted
*/
- public String getResponseString(ExecutionServiceInput executionServiceInput, int countOfSuccesfulEvents) {
+ public Builder getResponse(ExecutionServiceInput executionServiceInput, int countOfSuccesfulEvents)
+ throws InvalidProtocolBufferException {
String resourceName = "DefaultResponseEvent";
if (!StringUtils.isBlank(executionServiceInput.getActionIdentifiers().getActionName())) {
ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
} else {
resourceName = resourceName + ".json";
}
+ LOGGER.info("Fetching response from {}", resourceName);
String responseString = ResourceUtils.getResourceAsString(resourceLocation + resourceName);
- if (responseString == null) {
- responseString = ResourceUtils.getResourceAsString(resourceLocation
- + "DefaultResponseEvent.json");
+ Builder builder = ExecutionServiceOutput.newBuilder();
+ if (null == responseString) {
+ LOGGER.info("Expected response file {} not found in {}", resourceName, resourceLocation);
+ ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers();
+ builder.setCommonHeader(executionServiceInput.getCommonHeader());
+ builder.setActionIdentifiers(actionIdentifiers);
+ builder.setPayload(executionServiceInput.getPayload());
+ builder.setStatus(Status.newBuilder().setCode(500).setMessage("failure")
+ .setErrorMessage("failed to get get cba file name(" + actionIdentifiers.getBlueprintName()
+ + "), version(" + actionIdentifiers.getBlueprintVersion() + ") from db : file check failed.")
+ .setEventType(EventType.EVENT_COMPONENT_FAILURE).setTimestamp(Instant.now().toString()));
+ } else {
+ LOGGER.debug("Returning response from CDS Simulator: {}", responseString);
+ JsonFormat.parser().ignoringUnknownFields().merge(responseString, builder);
+ }
+ return builder;
+ }
+
+ @Override
+ public void run() {
+ try {
+ server.awaitTermination();
+ } catch (InterruptedException e) {
+ LOGGER.info("gRPC server is terminated");
+ Thread.currentThread().interrupt();
}
- return responseString;
}
}
private static final String CANNOT_PROCESS_PARAMETERS = "cannot parse parameters ";
private static final String CANNOT_CONNECT = "cannot connect to port ";
- private static final String LOCALHOST = "localhost";
+ public static final String LOCALHOST = "localhost";
private Util() {
// Prevent instantiation of this class
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import com.google.protobuf.util.JsonFormat;
import io.grpc.ManagedChannel;
import io.grpc.internal.DnsNameResolverProvider;
import io.grpc.internal.PickFirstLoadBalancerProvider;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc;
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.ExecutionServiceInput.Builder;
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.network.NetworkUtil;
import org.onap.policy.common.utils.resources.ResourceUtils;
public class CdsSimulatorTest {
private CdsSimulator sim;
+ /**
+ * Starts the simulator, allocating a unique port for each test so we don't have to
+ * wait for the prior server to shut down.
+ */
@Before
public void setUp() throws Exception {
- sim = Util.buildCdsSim();
+ int port = NetworkUtil.allocPort();
+ sim = new CdsSimulator(Util.LOCALHOST, port);
+ sim.start();
}
@After
@Test
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())
+ Builder builder = ExecutionServiceInput.newBuilder();
+ JsonFormat.parser().ignoringUnknownFields().merge(reqstr, builder);
+ ExecutionServiceInput request = builder.build();
+ ManagedChannel channel = NettyChannelBuilder.forAddress(Util.LOCALHOST, sim.getPort())
.nameResolverFactory(new DnsNameResolverProvider())
.loadBalancerFactory(new PickFirstLoadBalancerProvider()).usePlaintext().build();
}
@Test
- public void testGetResponseString() throws IOException, CoderException, ParseException {
- CdsSimulator cdsSimulator = new CdsSimulator("localhost", sim.getPort());
+ public void testGetResponse() throws IOException, CoderException, ParseException {
+ CdsSimulator cdsSimulator = new CdsSimulator(Util.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));
+ org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput.Builder esoBuilder =
+ ExecutionServiceOutput.newBuilder();
+ JsonFormat.parser().ignoringUnknownFields().merge(responseqstr, esoBuilder);
+ assertEquals(esoBuilder.toString(), cdsSimulator.getResponse(request, 0).toString());
}
}
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-interactions</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-pap</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-pdp</artifactId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-provider</artifactId>
<parent>
<groupId>org.onap.policy.models.sim</groupId>
<artifactId>policy-models-sim</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-sim-dmaap</artifactId>
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. 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.
<!--
============LICENSE_START=======================================================
Copyright (C) 2020 Bell Canada.
+ Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.models.sim</groupId>
- <artifactId>policy-models-sim</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <artifactId>models-sim-packages</artifactId>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>models-simulator-docker</artifactId>
<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>
+ <!-- There is no code in this sub-module, only holds interfaces. So skip sonar. -->
+ <sonar.skip>true</sonar.skip>
</properties>
<build>
<dependency>
<groupId>org.onap.policy.models.sim</groupId>
<artifactId>models-simulator-tarball</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>${project.version}</version>
<classifier>tarball</classifier>
<type>tar.gz</type>
</dependency>
ONAP
================================================================================
Copyright (C) 2020 Bell Canada.
+ Modifications Copyright (C) 2020 AT&T Intellectual Property. 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.
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.models.sim</groupId>
- <artifactId>policy-models-sim</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <artifactId>models-sim-packages</artifactId>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>models-simulator-tarball</artifactId>
<name>${project.artifactId}</name>
<description>A module that runs all "simulators", including DMaaP.</description>
+ <properties>
+ <!-- There is no code in this sub-module, only holds interfaces. So skip sonar. -->
+ <sonar.skip>true</sonar.skip>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.onap.policy.models.sim</groupId>
<artifactId>policy-models-simulators</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
</dependencies>
<outputDirectory>etc${file.separator}ssl</outputDirectory>
<lineEnding>keep</lineEnding>
</fileSet>
+ <fileSet>
+ <directory>${project.basedir}/src/main/resources/etc
+ </directory>
+ <includes>
+ <include>*.xml</include>
+ </includes>
+ <outputDirectory>etc</outputDirectory>
+ <lineEnding>unix</lineEnding>
+ </fileSet>
</fileSets>
</assembly>
--- /dev/null
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 AT&T Intellectual Property.
+ ================================================================================
+ 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=========================================================
+-->
+
+<configuration scan="true" scanPeriod="30 seconds" debug="false">
+
+ <!--
+ This is only used for testing and only a snapshot docker image is generated,
+ thus it is not necessary for the messages to following the ONAP standard.
+ Therefore, keeping it short so it's easier to wade through the output.
+
+ Also sending all output to stdout instead of to a log file; it can be viewed
+ via "docker logs" or captured by kubernetes.
+ -->
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %level %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration>
<parent>
<groupId>org.onap.policy.models.sim</groupId>
<artifactId>policy-models-sim</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>models-sim-packages</artifactId>
<parent>
<groupId>org.onap.policy.models.sim</groupId>
<artifactId>policy-models-sim</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-sim-pdp</artifactId>
<name>policy-models-sim-pdp</name>
<parent>
<groupId>org.onap.policy.models.sim</groupId>
<artifactId>policy-models-sim</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-simulators</artifactId>
}
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
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(),
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.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
/**
* Simulator parameters.
*/
@Getter
-@NotNull
public class SimulatorParameters {
/**
public BeanValidationResult validate(String containerName) {
BeanValidationResult result = new BeanValidator().validateTop(containerName, this);
+ if (dmaapProvider != null) {
+ // do not want full validation of the provider, so validate the relevant
+ // fields ourselves
+ BeanValidationResult subResult = new BeanValidationResult("dmaapProvider", dmaapProvider);
+ subResult.validateNotNull("name", dmaapProvider.getName());
+ if (dmaapProvider.getTopicSweepSec() < 1) {
+ ObjectValidationResult fieldResult =
+ new ObjectValidationResult("topicSweepSec", dmaapProvider.getTopicSweepSec(),
+ ValidationStatus.INVALID, "is below the minimum value: 1");
+ subResult.addResult(fieldResult);
+ }
+ result.addResult(subResult);
+ }
+
+ if (grpcServer != null) {
+ result.addResult(grpcServer.validate());
+ }
+
result.validateList("restServers", restServers, params -> params.validate("restServers"));
result.validateList("topicServers", topicServers, params -> params.validate("topicServers"));
@Test
public void testConstructor() throws Exception {
- assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidSimParameters.json"))
+ assertThatIllegalArgumentException().isThrownBy(() -> new Main("invalidDmaapProvider.json"))
.withMessage("invalid simulator parameters");
}
Main.main(new String[] {PARAMETER_FILE});
// don't need to wait long, because buildXxx() does the wait for us
- for (int port = 6666; port <= 6670; ++port) {
+ for (int port : new int[] {6666, 6667, 6668, 6669, 6670, 6680}) {
assertTrue("simulator on port " + port, NetworkUtil.isTcpPortOpen(HOST, port, 1, 100));
}
checkAai();
}
+ @Test
+ public void testMainMinimalParameters() {
+ Main.main(new String[] {"minParameters.json"});
+ assertNotNull(Main.getInstance());
+ assertTrue(Main.getInstance().isAlive());
+ }
+
private void checkAai() throws HttpClientConfigException {
BusTopicParams params = BusTopicParams.builder().clientName("client").hostname(HOST).port(6666).useHttps(true)
.allowSelfSignedCerts(true).basePath("aai").build();
package org.onap.policy.models.simulators;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@Test
public void testValidate() throws CoderException {
- // some fields missing
- BeanValidationResult result = new SimulatorParameters().validate("InvalidParams");
- assertFalse(result.isValid());
- assertNotNull(result.getResult());
-
- // everything populated
SimulatorParameters params = new StandardCoder().decode(new File("src/test/resources/simParameters.json"),
SimulatorParameters.class);
assertNull(params.validate("ValidParams").getResult());
}
+
+ @Test
+ public void testValidateEmptyRestServer() throws CoderException {
+ SimulatorParameters params = new StandardCoder()
+ .decode(new File("src/test/resources/emptyRestServer.json"), SimulatorParameters.class);
+ assertNull(params.validate("ValidParams").getResult());
+ }
+
+ @Test
+ public void testValidateInvalidDmaapProvider() throws CoderException {
+ SimulatorParameters params = new StandardCoder()
+ .decode(new File("src/test/resources/invalidDmaapProvider.json"), SimulatorParameters.class);
+ BeanValidationResult result = params.validate("InvalidDmaapParams");
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+ }
+
+ @Test
+ public void testValidateInvalidDmaapName() throws CoderException {
+ SimulatorParameters params = new StandardCoder().decode(
+ new File("src/test/resources/invalidDmaapName.json"), SimulatorParameters.class);
+ BeanValidationResult result = params.validate("InvalidDmaapParams");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("item \"name\" value \"null\"");
+ }
+
+ @Test
+ public void testValidateInvalidTopicSweep() throws CoderException {
+ SimulatorParameters params = new StandardCoder().decode(
+ new File("src/test/resources/invalidTopicSweep.json"), SimulatorParameters.class);
+ BeanValidationResult result = params.validate("InvalidDmaapParams");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("topicSweepSec");
+ }
+
+ @Test
+ public void testValidateInvalidGrpcServer() throws CoderException {
+ SimulatorParameters params = new StandardCoder()
+ .decode(new File("src/test/resources/invalidGrpcServer.json"), SimulatorParameters.class);
+ BeanValidationResult result = params.validate("InvalidGrpcParams");
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+ }
}
--- /dev/null
+{
+ "dmaapProvider": {
+ "name": "DMaaP simulator",
+ "topicSweepSec": 300,
+ "restServerParameters": {}
+ },
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "dmaapProvider": {
+ "name": null,
+ "topicSweepSec":300
+ },
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "dmaapProvider": {},
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "grpcServer": {},
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "dmaapProvider": {
+ "name": "DMaaP simulator",
+ "topicSweepSec":0
+ },
+ "restServers": [],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
--- /dev/null
+{
+ "restServers": [
+ {
+ "name": "A&AI simulator",
+ "providerClass": "org.onap.policy.simulators.AaiSimulatorJaxRs",
+ "host": "localhost",
+ "port": 6766,
+ "https": true
+ }
+ ],
+ "topicSinks": [],
+ "topicSources": [],
+ "topicServers": []
+}
{
"dmaapProvider": {
"name": "DMaaP simulator",
- "topicSweepSec": 300,
- "restServerParameters": {
-
- }
+ "topicSweepSec": 300
},
"restServers": [
{
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.models.sim</groupId>
<parent>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
</parent>
<artifactId>policy-models-tosca</artifactId>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.5-SNAPSHOT</version>
<packaging>pom</packaging>
<name>policy-models</name>
--- /dev/null
+distribution_type: 'maven'
+version: '2.3.2'
+project: 'policy-models'
+log_dir: 'policy-models-maven-stage-master/493/'
--- /dev/null
+distribution_type: 'maven'
+version: '2.3.3'
+project: 'policy-models'
+log_dir: 'policy-models-maven-stage-master/495/'
--- /dev/null
+distribution_type: 'maven'
+version: '2.3.4'
+project: 'policy-models'
+log_dir: 'policy-models-maven-stage-master/496/'
major=2
minor=3
-patch=2
+patch=5
base_version=${major}.${minor}.${patch}