Search in sources :

Example 1 with StatusRuntimeException

use of org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException in project incubator-ratis by apache.

the class GrpcUtil method getCallId.

static long getCallId(Throwable t) {
    if (t instanceof StatusRuntimeException) {
        final Metadata trailers = ((StatusRuntimeException) t).getTrailers();
        String callId = trailers.get(CALL_ID);
        return callId != null ? Integer.parseInt(callId) : -1;
    }
    return -1;
}
Also used : StatusRuntimeException(org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException) Metadata(org.apache.ratis.thirdparty.io.grpc.Metadata)

Example 2 with StatusRuntimeException

use of org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException in project incubator-ratis by apache.

the class GrpcUtil method tryUnwrapException.

static IOException tryUnwrapException(StatusRuntimeException se) {
    final Status status = se.getStatus();
    if (status != null && status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
        return new TimeoutIOException(status.getDescription(), se);
    }
    final Metadata trailers = se.getTrailers();
    if (trailers == null) {
        return null;
    }
    final byte[] bytes = trailers.get(EXCEPTION_OBJECT_KEY);
    if (bytes != null) {
        try {
            return IOUtils.bytes2Object(bytes, IOException.class);
        } catch (Exception e) {
            se.addSuppressed(e);
        }
    }
    if (status != null) {
        final String className = trailers.get(EXCEPTION_TYPE_KEY);
        if (className != null) {
            try {
                final Class<? extends Throwable> clazz = Class.forName(className).asSubclass(Throwable.class);
                final Throwable unwrapped = ReflectionUtils.instantiateException(clazz, status.getDescription());
                return IOUtils.asIOException(unwrapped.initCause(se));
            } catch (Throwable e) {
                se.addSuppressed(e);
                return new IOException(se);
            }
        }
    }
    return null;
}
Also used : Status(org.apache.ratis.thirdparty.io.grpc.Status) Metadata(org.apache.ratis.thirdparty.io.grpc.Metadata) IOException(java.io.IOException) TimeoutIOException(org.apache.ratis.protocol.exceptions.TimeoutIOException) TimeoutIOException(org.apache.ratis.protocol.exceptions.TimeoutIOException) ServerNotReadyException(org.apache.ratis.protocol.exceptions.ServerNotReadyException) IOException(java.io.IOException) TimeoutIOException(org.apache.ratis.protocol.exceptions.TimeoutIOException) StatusRuntimeException(org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException)

Example 3 with StatusRuntimeException

use of org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException in project incubator-ratis by apache.

the class GrpcUtil method isHeartbeat.

static boolean isHeartbeat(Throwable t) {
    if (t instanceof StatusRuntimeException) {
        final Metadata trailers = ((StatusRuntimeException) t).getTrailers();
        String isHeartbeat = trailers != null ? trailers.get(HEARTBEAT) : null;
        return isHeartbeat != null && Boolean.valueOf(isHeartbeat);
    }
    return false;
}
Also used : StatusRuntimeException(org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException) Metadata(org.apache.ratis.thirdparty.io.grpc.Metadata)

Aggregations

Metadata (org.apache.ratis.thirdparty.io.grpc.Metadata)3 StatusRuntimeException (org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException)3 IOException (java.io.IOException)1 ServerNotReadyException (org.apache.ratis.protocol.exceptions.ServerNotReadyException)1 TimeoutIOException (org.apache.ratis.protocol.exceptions.TimeoutIOException)1 Status (org.apache.ratis.thirdparty.io.grpc.Status)1