Search in sources :

Example 76 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project instrumentation-java by census-instrumentation.

the class OcAgentMetricsServiceExportRpcHandler method onComplete.

// Marks this export stream as completed with an optional error.
// Once onComplete is called, this OcAgentMetricsServiceExportRpcHandler instance can be discarded
// and GC'ed in the worker thread.
synchronized void onComplete(@javax.annotation.Nullable Throwable error) {
    if (isCompleted()) {
        return;
    }
    // TODO(songya): add Runnable
    Status status;
    if (error == null) {
        status = Status.OK;
    } else if (error instanceof StatusRuntimeException) {
        status = ((StatusRuntimeException) error).getStatus();
    } else {
        status = Status.UNKNOWN;
    }
    terminateStatus = status;
}
Also used : Status(io.grpc.Status) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 77 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project alluxio by Alluxio.

the class AbstractClient method retryRPCInternal.

private synchronized <V> V retryRPCInternal(RetryPolicy retryPolicy, RpcCallable<V> rpc, Supplier<Void> onRetry) throws AlluxioStatusException {
    Exception ex = null;
    while (retryPolicy.attempt()) {
        if (mClosed) {
            throw new FailedPreconditionException("Client is closed");
        }
        connect();
        try {
            return rpc.call();
        } catch (StatusRuntimeException e) {
            AlluxioStatusException se = AlluxioStatusException.fromStatusRuntimeException(e);
            if (se.getStatusCode() == Status.Code.UNAVAILABLE || se.getStatusCode() == Status.Code.CANCELLED || se.getStatusCode() == Status.Code.UNAUTHENTICATED || e.getCause() instanceof UnresolvedAddressException) {
                ex = se;
            } else {
                throw se;
            }
        }
        LOG.debug("Rpc failed ({}): ", retryPolicy.getAttemptCount(), ex);
        onRetry.get();
        disconnect();
    }
    throw new UnavailableException("Failed after " + retryPolicy.getAttemptCount() + " attempts: " + ex.toString(), ex);
}
Also used : FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) StatusRuntimeException(io.grpc.StatusRuntimeException) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) StatusRuntimeException(io.grpc.StatusRuntimeException) ServiceNotFoundException(alluxio.exception.ServiceNotFoundException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 78 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project instrumentation-java by census-instrumentation.

the class OcAgentTraceServiceExportRpcHandler method onComplete.

// Marks this export stream as completed with an optional error.
// Once onComplete is called, this OcAgentTraceServiceExportRpcHandler instance can be discarded
// and GC'ed in the worker thread.
synchronized void onComplete(@javax.annotation.Nullable Throwable error) {
    if (isCompleted()) {
        return;
    }
    // TODO(songya): add Runnable
    Status status;
    if (error == null) {
        status = Status.OK;
    } else if (error instanceof StatusRuntimeException) {
        status = ((StatusRuntimeException) error).getStatus();
    } else {
        status = Status.UNKNOWN;
    }
    terminateStatus = status;
}
Also used : Status(io.grpc.Status) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 79 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project alluxio by Alluxio.

the class SnapshotReplicationManagerTest method uploadFailure.

/**
 * Simulates a {@link SnapshotUploader} error.
 */
@Test
public void uploadFailure() throws Exception {
    before(2);
    List<Follower> followers = new ArrayList<>(mFollowers.values());
    Follower firstFollower = followers.get(0);
    Follower secondFollower = followers.get(1);
    // create default 0, 1 snapshot
    createSnapshotFile(firstFollower.mStore);
    // preferable to the default 0, 1 snapshot
    createSnapshotFile(secondFollower.mStore, 0, 2);
    // make sure to error out when requesting the better snapshot from secondFollower
    Mockito.doAnswer(mock -> {
        SingleFileSnapshotInfo snapshot = secondFollower.mStore.getLatestSnapshot();
        StreamObserver<UploadSnapshotPResponse> responseObserver = SnapshotUploader.forFollower(secondFollower.mStore, snapshot);
        StreamObserver<UploadSnapshotPRequest> requestObserver = mClient.uploadSnapshot(responseObserver);
        responseObserver.onError(new StatusRuntimeException(Status.UNAVAILABLE));
        requestObserver.onNext(UploadSnapshotPRequest.newBuilder().setData(SnapshotData.newBuilder().setSnapshotTerm(snapshot.getTerm()).setSnapshotIndex(snapshot.getIndex()).setOffset(0)).build());
        return null;
    }).when(secondFollower.mSnapshotManager).sendSnapshotToLeader();
    mLeaderSnapshotManager.maybeCopySnapshotFromFollower();
    CommonUtils.waitFor("leader snapshot to complete", () -> mLeaderSnapshotManager.maybeCopySnapshotFromFollower() != -1, mWaitOptions);
    // verify that the leader still requests and gets second best snapshot
    validateSnapshotFile(mLeaderStore);
}
Also used : SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) ArrayList(java.util.ArrayList) StatusRuntimeException(io.grpc.StatusRuntimeException) UploadSnapshotPRequest(alluxio.grpc.UploadSnapshotPRequest) UploadSnapshotPResponse(alluxio.grpc.UploadSnapshotPResponse) Test(org.junit.Test)

Example 80 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project beam by apache.

the class GrpcWindmillServer method callWithBackoff.

private <ResponseT> ResponseT callWithBackoff(Supplier<ResponseT> function) {
    BackOff backoff = grpcBackoff();
    int rpcErrors = 0;
    while (true) {
        try {
            return function.get();
        } catch (StatusRuntimeException e) {
            try {
                if (++rpcErrors % 20 == 0) {
                    LOG.warn("Many exceptions calling gRPC. Last exception: {} with status {}", e, e.getStatus());
                }
                if (!BackOffUtils.next(Sleeper.DEFAULT, backoff)) {
                    throw new WindmillServerStub.RpcException(e);
                }
            } catch (IOException | InterruptedException i) {
                if (i instanceof InterruptedException) {
                    Thread.currentThread().interrupt();
                }
                WindmillServerStub.RpcException rpcException = new WindmillServerStub.RpcException(e);
                rpcException.addSuppressed(i);
                throw rpcException;
            }
        }
    }
}
Also used : StatusRuntimeException(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException) BackOff(org.apache.beam.sdk.util.BackOff)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6