use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project beam by apache.
the class FnApiControlClient method closeAndTerminateOutstandingRequests.
/**
* Closes this client and terminates any outstanding requests exceptionally.
*/
private void closeAndTerminateOutstandingRequests(Throwable cause) {
if (isClosed.getAndSet(true)) {
return;
}
try {
// Make a copy of the map to make the view of the outstanding requests consistent.
Map<String, CompletableFuture<BeamFnApi.InstructionResponse>> outstandingRequestsCopy = new ConcurrentHashMap<>(outstandingRequests);
outstandingRequests.clear();
if (outstandingRequestsCopy.isEmpty()) {
requestReceiver.onCompleted();
return;
}
requestReceiver.onError(new StatusRuntimeException(Status.CANCELLED.withDescription(cause.getMessage())));
LOG.error("{} closed, clearing outstanding requests {}", FnApiControlClient.class.getSimpleName(), outstandingRequestsCopy);
for (CompletableFuture<BeamFnApi.InstructionResponse> outstandingRequest : outstandingRequestsCopy.values()) {
outstandingRequest.completeExceptionally(cause);
}
} finally {
for (Consumer<FnApiControlClient> onCloseListener : onCloseListeners) {
onCloseListener.accept(this);
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project beam by apache.
the class BigtableServiceImpl method tableExists.
@Override
public boolean tableExists(String tableId) throws IOException {
try (BigtableSession session = new BigtableSession(options)) {
GetTableRequest getTable = GetTableRequest.newBuilder().setName(options.getInstanceName().toTableNameStr(tableId)).build();
session.getTableAdminClient().getTable(getTable);
return true;
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode() == Code.NOT_FOUND) {
return false;
}
String message = String.format("Error checking whether table %s (BigtableOptions %s) exists", tableId, options);
LOG.error(message, e);
throw new IOException(message, e);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project beam by apache.
the class InMemoryJobService method getPipeline.
@Override
public void getPipeline(GetJobPipelineRequest request, StreamObserver<GetJobPipelineResponse> responseObserver) {
LOG.trace("{} {}", GetJobPipelineRequest.class.getSimpleName(), request);
String invocationId = request.getJobId();
try {
JobInvocation invocation = getInvocation(invocationId);
RunnerApi.Pipeline pipeline = invocation.getPipeline();
GetJobPipelineResponse response = GetJobPipelineResponse.newBuilder().setPipeline(pipeline).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (StatusRuntimeException | StatusException e) {
responseObserver.onError(e);
} catch (Exception e) {
String errMessage = String.format("Encountered Unexpected Exception for Invocation %s", invocationId);
LOG.error(errMessage, e);
responseObserver.onError(Status.INTERNAL.withCause(e).asException());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project beam by apache.
the class InMemoryJobService method getState.
@Override
public void getState(GetJobStateRequest request, StreamObserver<JobStateEvent> responseObserver) {
LOG.trace("{} {}", GetJobStateRequest.class.getSimpleName(), request);
String invocationId = request.getJobId();
try {
JobInvocation invocation = getInvocation(invocationId);
JobStateEvent response = invocation.getStateEvent();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (StatusRuntimeException | StatusException e) {
responseObserver.onError(e);
} catch (Exception e) {
String errMessage = String.format("Encountered Unexpected Exception for Invocation %s", invocationId);
LOG.error(errMessage, e);
responseObserver.onError(Status.INTERNAL.withCause(e).asException());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.
the class MoreInProcessTest method asyncClientStreaming_serverErrorPriorToRequest.
@Test
public void asyncClientStreaming_serverErrorPriorToRequest() throws Exception {
// implement a service
final Status fakeError = Status.INVALID_ARGUMENT;
TestServiceImplBase clientStreamingImpl = new TestServiceImplBase() {
@Override
public StreamObserver<StreamingInputCallRequest> streamingInputCall(StreamObserver<StreamingInputCallResponse> responseObserver) {
// send error directly
responseObserver.onError(new StatusRuntimeException(fakeError));
responseObserver.onCompleted();
return new StreamObserver<StreamingInputCallRequest>() {
@Override
public void onNext(StreamingInputCallRequest value) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
}
};
serviceRegistry.addService(clientStreamingImpl);
// implement a client
final CountDownLatch finishLatch = new CountDownLatch(1);
final AtomicReference<StreamingInputCallResponse> responseRef = new AtomicReference<>();
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
StreamObserver<StreamingInputCallResponse> responseObserver = new StreamObserver<StreamingInputCallResponse>() {
@Override
public void onNext(StreamingInputCallResponse response) {
responseRef.set(response);
}
@Override
public void onError(Throwable t) {
throwableRef.set(t);
finishLatch.countDown();
}
@Override
public void onCompleted() {
finishLatch.countDown();
}
};
// make a gRPC call
TestServiceGrpc.newStub(inProcessChannel).streamingInputCall(responseObserver);
assertTrue(finishLatch.await(900, TimeUnit.MILLISECONDS));
assertEquals(fakeError.getCode(), Status.fromThrowable(throwableRef.get()).getCode());
assertNull(responseRef.get());
}
Aggregations