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;
}
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());
}
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));
}
Aggregations