Search in sources :

Example 1 with ExecutionServiceOutput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput in project so by onap.

the class CDSProcessingHandler method process.

CountDownLatch process(ExecutionServiceInput request, ManagedChannel channel) {
    ActionIdentifiers header = request.getActionIdentifiers();
    log.info("Processing blueprint({}:{}) for action({})", header.getBlueprintVersion(), header.getBlueprintName(), header.getActionName());
    final CountDownLatch finishLatch = new CountDownLatch(1);
    final BluePrintProcessingServiceStub asyncStub = BluePrintProcessingServiceGrpc.newStub(channel);
    final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<ExecutionServiceOutput>() {

        @Override
        public void onNext(ExecutionServiceOutput output) {
            listener.onMessage(output);
        }

        @Override
        public void onError(Throwable t) {
            listener.onError(t);
            finishLatch.countDown();
        }

        @Override
        public void onCompleted() {
            log.info("Completed blueprint({}:{}) for action({})", header.getBlueprintVersion(), header.getBlueprintName(), header.getBlueprintVersion());
            finishLatch.countDown();
        }
    };
    final StreamObserver<ExecutionServiceInput> requestObserver = asyncStub.process(responseObserver);
    try {
        // Send our message to CDS backend for processing
        requestObserver.onNext(request);
        // Mark the end of requests
        requestObserver.onCompleted();
    } catch (RuntimeException e) {
        requestObserver.onError(e);
    }
    return finishLatch;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ExecutionServiceOutput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput) CountDownLatch(java.util.concurrent.CountDownLatch) ActionIdentifiers(org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers) BluePrintProcessingServiceStub(org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput)

Example 2 with ExecutionServiceOutput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput in project so by onap.

the class GrpcNettyServer method start.

@PostConstruct
public void start() throws IOException {
    final BluePrintProcessingServiceImplBase blueprintPrcessorImpl = new BluePrintProcessingServiceImplBase() {

        @Override
        public StreamObserver<ExecutionServiceInput> process(StreamObserver<ExecutionServiceOutput> responseObserver) {
            responseObserverRef.set(responseObserver);
            StreamObserver<ExecutionServiceInput> requestObserver = new StreamObserver<ExecutionServiceInput>() {

                @Override
                public void onNext(ExecutionServiceInput message) {
                    detailedMessages.add(message);
                    logger.info("Message received: {}", message);
                    ExecutionServiceOutput executionServiceOutput = ExecutionServiceOutput.newBuilder().setActionIdentifiers(message.getActionIdentifiers()).setStatus(Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_EXECUTED).build()).build();
                    responseObserverRef.get().onNext(executionServiceOutput);
                    logger.info("Message sent: {}", executionServiceOutput);
                }

                @Override
                public void onError(Throwable t) {
                    responseObserverRef.get().onError(t);
                }

                @Override
                public void onCompleted() {
                    allRequestsDelivered.countDown();
                    responseObserverRef.get().onCompleted();
                }
            };
            return requestObserver;
        }
    };
    grpcCleanup.register(ServerBuilder.forPort(Integer.valueOf(port)).directExecutor().addService(blueprintPrcessorImpl).build().start());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ExecutionServiceOutput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput) BluePrintProcessingServiceImplBase(org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput) PostConstruct(javax.annotation.PostConstruct)

Example 3 with ExecutionServiceOutput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput in project so by onap.

the class CDSProcessingClientTest method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ExecutionServiceInput fakeRequest1 = ExecutionServiceInput.newBuilder().setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("request1").build()).build();
    ExecutionServiceOutput fakeResponse1 = ExecutionServiceOutput.newBuilder().setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("response1").build()).build();
    ExecutionServiceOutput fakeResponse2 = ExecutionServiceOutput.newBuilder().setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("response2").build()).build();
    CountDownLatch finishLatch = client.sendRequest(fakeRequest1);
    // request message sent and delivered for one time
    assertTrue(allRequestsDelivered.await(1, TimeUnit.SECONDS));
    assertEquals(Collections.singletonList("request1"), messagesDelivered);
    // Let the server send out two simple response messages
    // and verify that the client receives them.
    responseObserverRef.get().onNext(fakeResponse1);
    verify(listener).onMessage(fakeResponse1);
    responseObserverRef.get().onNext(fakeResponse2);
    verify(listener).onMessage(fakeResponse2);
    // let server complete.
    responseObserverRef.get().onCompleted();
    assertTrue(finishLatch.await(1, TimeUnit.SECONDS));
}
Also used : ExecutionServiceOutput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput) Test(org.junit.Test)

Aggregations

ExecutionServiceInput (org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput)3 ExecutionServiceOutput (org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput)3 StreamObserver (io.grpc.stub.StreamObserver)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PostConstruct (javax.annotation.PostConstruct)1 Test (org.junit.Test)1 ActionIdentifiers (org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers)1 BluePrintProcessingServiceImplBase (org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase)1 BluePrintProcessingServiceStub (org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub)1