use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project beam by apache.
the class BeamFnControlService method getProcessBundleDescriptor.
@Override
public void getProcessBundleDescriptor(BeamFnApi.GetProcessBundleDescriptorRequest request, StreamObserver<BeamFnApi.ProcessBundleDescriptor> responseObserver) {
String bundleDescriptorId = request.getProcessBundleDescriptorId();
LOG.info("getProcessBundleDescriptor request with id {}", bundleDescriptorId);
BeamFnApi.ProcessBundleDescriptor descriptor = processBundleDescriptors.get(bundleDescriptorId);
if (descriptor == null) {
String msg = String.format("ProcessBundleDescriptor with id %s not found", bundleDescriptorId);
responseObserver.onError(new StatusException(Status.NOT_FOUND.withDescription(msg)));
LOG.error(msg);
} else {
responseObserver.onNext(descriptor);
responseObserver.onCompleted();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project beam by apache.
the class InMemoryJobService method prepare.
@Override
public void prepare(PrepareJobRequest request, StreamObserver<PrepareJobResponse> responseObserver) {
try {
LOG.trace("{} {}", PrepareJobRequest.class.getSimpleName(), request);
// insert preparation
String preparationId = String.format("%s_%s", request.getJobName(), UUID.randomUUID().toString());
Struct pipelineOptions = request.getPipelineOptions();
if (pipelineOptions == null) {
throw new NullPointerException("Encountered null pipeline options.");
}
LOG.trace("PIPELINE OPTIONS {} {}", pipelineOptions.getClass(), pipelineOptions);
JobPreparation preparation = JobPreparation.builder().setId(preparationId).setPipeline(request.getPipeline()).setOptions(pipelineOptions).build();
JobPreparation previous = preparations.putIfAbsent(preparationId, preparation);
if (previous != null) {
// this should never happen with a UUID
String errMessage = String.format("A job with the preparation ID \"%s\" already exists.", preparationId);
StatusException exception = Status.NOT_FOUND.withDescription(errMessage).asException();
responseObserver.onError(exception);
return;
}
String stagingSessionToken = stagingServiceTokenProvider.apply(preparationId);
stagingSessionTokens.putIfAbsent(preparationId, stagingSessionToken);
stagingService.getService().registerJob(stagingSessionToken, Maps.transformValues(request.getPipeline().getComponents().getEnvironmentsMap(), RunnerApi.Environment::getDependenciesList));
// send response
PrepareJobResponse response = PrepareJobResponse.newBuilder().setPreparationId(preparationId).setArtifactStagingEndpoint(stagingServiceDescriptor).setStagingSessionToken(stagingSessionToken).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (Exception e) {
LOG.error("Could not prepare job with name {}", request.getJobName(), e);
responseObserver.onError(Status.INTERNAL.withCause(e).asException());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException 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.StatusException 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.StatusException in project grpc-java by grpc.
the class NettyClientHandler method createStream.
/**
* Attempts to create a new stream from the given command. If there are too many active streams,
* the creation request is queued.
*/
private void createStream(CreateStreamCommand command, ChannelPromise promise) throws Exception {
if (lifecycleManager.getShutdownThrowable() != null) {
command.stream().setNonExistent();
// The connection is going away (it is really the GOAWAY case),
// just terminate the stream now.
command.stream().transportReportStatus(lifecycleManager.getShutdownStatus(), RpcProgress.MISCARRIED, true, new Metadata());
promise.setFailure(lifecycleManager.getShutdownThrowable());
return;
}
// Get the stream ID for the new stream.
int streamId;
try {
streamId = incrementAndGetNextStreamId();
} catch (StatusException e) {
command.stream().setNonExistent();
// Stream IDs have been exhausted for this connection. Fail the promise immediately.
promise.setFailure(e);
// Initiate a graceful shutdown if we haven't already.
if (!connection().goAwaySent()) {
logger.fine("Stream IDs have been exhausted for this connection. " + "Initiating graceful shutdown of the connection.");
lifecycleManager.notifyShutdown(e.getStatus());
close(ctx(), ctx().newPromise());
}
return;
}
if (connection().goAwayReceived()) {
Status s = abruptGoAwayStatus;
int maxActiveStreams = connection().local().maxActiveStreams();
int lastStreamId = connection().local().lastStreamKnownByPeer();
if (s == null) {
// Should be impossible, but handle pseudo-gracefully
s = Status.INTERNAL.withDescription("Failed due to abrupt GOAWAY, but can't find GOAWAY details");
} else if (streamId > lastStreamId) {
s = s.augmentDescription("stream id: " + streamId + ", GOAWAY Last-Stream-ID:" + lastStreamId);
} else if (connection().local().numActiveStreams() == maxActiveStreams) {
s = s.augmentDescription("At MAX_CONCURRENT_STREAMS limit. limit: " + maxActiveStreams);
}
if (streamId > lastStreamId || connection().local().numActiveStreams() == maxActiveStreams) {
// This should only be reachable during onGoAwayReceived, as otherwise
// getShutdownThrowable() != null
command.stream().setNonExistent();
command.stream().transportReportStatus(s, RpcProgress.MISCARRIED, true, new Metadata());
promise.setFailure(s.asRuntimeException());
return;
}
}
NettyClientStream.TransportState stream = command.stream();
Http2Headers headers = command.headers();
stream.setId(streamId);
PerfMark.startTask("NettyClientHandler.createStream", stream.tag());
PerfMark.linkIn(command.getLink());
try {
createStreamTraced(streamId, stream, headers, command.isGet(), command.shouldBeCountedForInUse(), promise);
} finally {
PerfMark.stopTask("NettyClientHandler.createStream", stream.tag());
}
}
Aggregations