summaryrefslogtreecommitdiffstats
path: root/examples/examples-grpc/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-29 12:34:58 -0400
committerJim Hahn <jrh3@att.com>2020-06-29 12:37:58 -0400
commit833597be4ca0d570e0573205203fa745ef464713 (patch)
tree7a5c7a10b7f938ba3aa03c9458302e0cd3b852ab /examples/examples-grpc/src
parentbea0762a2c28ee0330036843e17f5af38e06c807 (diff)
Removed CDS simulator from apex-pdp
As the simulator now resides in policy-models, the code for it is no longer needed in apex-pdp. Deleted it. Issue-ID: POLICY-2676 Change-Id: I8ae6c8d860a47e5e7ba0509c99e4e2676109de25 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'examples/examples-grpc/src')
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java102
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java6
2 files changed, 4 insertions, 104 deletions
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java
deleted file mode 100644
index da9b8e3d1..000000000
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * 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=========================================================
- */
-
-package org.onap.policy.apex.examples.grpc;
-
-import com.google.protobuf.InvalidProtocolBufferException;
-import com.google.protobuf.util.JsonFormat;
-import io.grpc.Server;
-import io.grpc.netty.NettyServerBuilder;
-import io.grpc.stub.StreamObserver;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-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.apex.service.engine.event.ApexEventRuntimeException;
-
-/**
- * The Class GrpcTestDummyGrpcServer creates a dummy gRPC server to mimic a CDS implementation.
- */
-public class GrpcTestDummyGrpcServer {
- private Server server;
-
- /**
- * Dummy server for gRPC.
- *
- * @param host hostname of the server
- * @param port port of the server
- */
- public GrpcTestDummyGrpcServer(String host, int port) {
- // Implement the dummy gRPC server
- BluePrintProcessingServiceImplBase testCdsBlueprintServerImpl = new BluePrintProcessingServiceImplBase() {
- @Override
- public StreamObserver<ExecutionServiceInput>
- process(final StreamObserver<ExecutionServiceOutput> responseObserver) {
- return new StreamObserver<ExecutionServiceInput>() {
- @Override
- public void onNext(final ExecutionServiceInput executionServiceInput) {
- String responseString = "";
- try {
- responseString = Files.readString(Paths.get(
- "src/main/resources/examples/events/APEXgRPC/CreateSubscriptionResponseEvent.json"));
- } catch (IOException e) {
- throw new ApexEventRuntimeException("Cannot read executionServiceOutput from file", e);
- }
- ExecutionServiceOutput executionServiceOutput;
- Builder builder = ExecutionServiceOutput.newBuilder();
- try {
- JsonFormat.parser().ignoringUnknownFields().merge(responseString, builder);
- executionServiceOutput = builder.build();
- responseObserver.onNext(executionServiceOutput);
- } catch (InvalidProtocolBufferException e) {
- throw new ApexEventRuntimeException(
- "Output string cannot be converted to ExecutionServiceOutput type for gRPC request."
- + e);
- }
- }
-
- @Override
- public void onError(final Throwable throwable) {
- responseObserver.onError(throwable);
- }
-
- @Override
- public void onCompleted() {
- responseObserver.onCompleted();
- }
- };
- }
- };
- server = NettyServerBuilder.forAddress(new InetSocketAddress(host, port)).addService(testCdsBlueprintServerImpl)
- .build();
- }
-
- public void start() throws IOException {
- server.start();
- }
-
- public void stop() {
- server.shutdown();
- }
-}
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
index fcdf55322..cd9f11c41 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
+ * 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.
@@ -25,6 +26,7 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.simulators.CdsSimulator;
/**
* The Class GrpcTestServerSim that manages test servers for REST and gRPC requests for the test.
@@ -32,7 +34,7 @@ import org.onap.policy.common.utils.network.NetworkUtil;
public class GrpcTestServerSim {
private static final String HOST = "localhost";
private HttpServletServer restServer;
- private GrpcTestDummyGrpcServer grpcServer;
+ private CdsSimulator grpcServer;
/**
* Instantiates a new REST simulator for DMaaP requests.
@@ -52,7 +54,7 @@ public class GrpcTestServerSim {
}
int grpcServerPort = 54322;
- grpcServer = new GrpcTestDummyGrpcServer(HOST, grpcServerPort);
+ grpcServer = new CdsSimulator(HOST, grpcServerPort);
grpcServer.start();
if (!NetworkUtil.isTcpPortOpen(HOST, grpcServerPort, 50, 200L)) {
throw new IllegalStateException("port " + grpcServerPort + " is still not in use");