Removed CDS simulator from apex-pdp 57/109657/1
authorJim Hahn <jrh3@att.com>
Mon, 29 Jun 2020 16:34:58 +0000 (12:34 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 29 Jun 2020 16:37:58 +0000 (12:37 -0400)
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>
examples/examples-grpc/pom.xml
examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java [deleted file]
examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java

index c3d25d3..de58120 100644 (file)
@@ -2,6 +2,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.
          <artifactId>events</artifactId>
          <version>${version.policy.models}</version>
       </dependency>
+      <dependency>
+        <groupId>org.onap.policy.models.policy-models-interactions</groupId>
+        <artifactId>simulators</artifactId>
+         <version>${version.policy.models}</version>
+      </dependency>
       <dependency>
          <groupId>org.onap.policy.common</groupId>
          <artifactId>policy-endpoints</artifactId>
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 (file)
index da9b8e3..0000000
+++ /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();
-    }
-}
index fcdf553..cd9f11c 100644 (file)
@@ -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");