Search in sources :

Example 11 with StatusException

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();
    }
}
Also used : StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi)

Example 12 with StatusException

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());
    }
}
Also used : StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException) RunnerApi(org.apache.beam.model.pipeline.v1.RunnerApi) PrepareJobResponse(org.apache.beam.model.jobmanagement.v1.JobApi.PrepareJobResponse) PrepareJobRequest(org.apache.beam.model.jobmanagement.v1.JobApi.PrepareJobRequest) StatusRuntimeException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException) StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException) Struct(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.Struct)

Example 13 with StatusException

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());
    }
}
Also used : GetJobPipelineRequest(org.apache.beam.model.jobmanagement.v1.JobApi.GetJobPipelineRequest) RunnerApi(org.apache.beam.model.pipeline.v1.RunnerApi) StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException) GetJobPipelineResponse(org.apache.beam.model.jobmanagement.v1.JobApi.GetJobPipelineResponse) StatusRuntimeException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException) StatusRuntimeException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException) StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)

Example 14 with StatusException

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());
    }
}
Also used : JobStateEvent(org.apache.beam.model.jobmanagement.v1.JobApi.JobStateEvent) StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException) GetJobStateRequest(org.apache.beam.model.jobmanagement.v1.JobApi.GetJobStateRequest) StatusRuntimeException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException) StatusRuntimeException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException) StatusException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)

Example 15 with StatusException

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());
    }
}
Also used : Status(io.grpc.Status) StatusException(io.grpc.StatusException) Http2Headers(io.netty.handler.codec.http2.Http2Headers) Metadata(io.grpc.Metadata)

Aggregations

StatusException (io.grpc.StatusException)45 Test (org.junit.Test)20 Status (io.grpc.Status)9 IOException (java.io.IOException)9 StatusException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)9 ExecutionException (java.util.concurrent.ExecutionException)8 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)6 Metadata (io.grpc.Metadata)6 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)5 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)4 TrackingObjectPoolForTest (io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest)4 TimeoutException (java.util.concurrent.TimeoutException)4 StatusRuntimeException (io.grpc.StatusRuntimeException)3 InetSocketAddress (java.net.InetSocketAddress)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)2 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)2 PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)2