@Test public void abortWithoutRetryInfo() { Status status = Status.fromCodeValue(Status.Code.ABORTED.value()); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status)); assertThat(e).isInstanceOf(AbortedException.class); assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(-1L); }
/** Extracts the GRPC status code if available. Returns UNKNOWN for non-GRPC exceptions. */ private static Status getStatus(Throwable throwable) { Status status = Status.UNKNOWN; if (throwable instanceof StatusRuntimeException) { status = ((StatusRuntimeException) throwable).getStatus(); } else if (throwable instanceof StatusException) { status = ((StatusException) throwable).getStatus(); } return status; }
public static RuntimeException parse(Throwable ex) { String code = "AXONIQ-0001"; if( ex instanceof StatusRuntimeException) { if(ex.getCause() instanceof EventStoreClientException) { return (EventStoreClientException)ex.getCause(); } StatusRuntimeException statusRuntimeException = (StatusRuntimeException)ex; if(Status.Code.UNIMPLEMENTED.equals(statusRuntimeException.getStatus().getCode()) ) { return new UnsupportedOperationException(ex.getMessage(), ex); } Metadata trailer = statusRuntimeException.getTrailers(); String errorCode = trailer.get(ERROR_CODE_KEY); if (errorCode != null) { code = errorCode; } } return ErrorCode.getFromCode(code).convert(ex); }
Throwable cause = (e.getCause() != null) ? e.getCause() : e; if (e.getTrailers() != null && e.getTrailers().containsKey(sInnerCauseKey)) { try { cause = (Throwable) SerializationUtils.deserialize(e.getTrailers().get(sInnerCauseKey)); } catch (Exception exc) { LOG.warn("Failed to deserialize the cause: {}", exc);
/** * Wraps the given {@link Throwable} in a {@link StatusRuntimeException}. If it contains an * embedded {@link StatusException} or {@link StatusRuntimeException}, the returned exception will * contain the embedded trailers and status, with the given exception as the cause. Otherwise, an * exception will be generated from an {@link Status#UNKNOWN} status. */ private static StatusRuntimeException toStatusRuntimeException(Throwable t) { Throwable cause = checkNotNull(t, "t"); while (cause != null) { // If we have an embedded status, use it and replace the cause if (cause instanceof StatusException) { StatusException se = (StatusException) cause; return new StatusRuntimeException(se.getStatus(), se.getTrailers()); } else if (cause instanceof StatusRuntimeException) { StatusRuntimeException se = (StatusRuntimeException) cause; return new StatusRuntimeException(se.getStatus(), se.getTrailers()); } cause = cause.getCause(); } return Status.UNKNOWN.withDescription("unexpected exception").withCause(t) .asRuntimeException(); }
} catch( StatusRuntimeException sre) { shutdown(candidate); logger.warn("Connecting to AxonServer node {}:{} failed: {}", nodeInfo.getHostName(), nodeInfo.getGrpcPort(), sre.getMessage()); if( sre.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) { unavailable = true;
StatusRuntimeException sre = (StatusRuntimeException) e; int errno = Proto.getErrno(sre.getMessage()); String sqlState = Proto.getSQLState(sre.getMessage()); switch (sre.getStatus().getCode()) { case INVALID_ARGUMENT: return new SQLSyntaxErrorException(sre.toString(), sqlState, errno, sre); case DEADLINE_EXCEEDED: return new SQLTimeoutException(sre.toString(), sqlState, errno, sre); case ALREADY_EXISTS: return new SQLIntegrityConstraintViolationException(sre.toString(), sqlState, errno, sre); case UNAUTHENTICATED: return new SQLInvalidAuthorizationSpecException(sre.toString(), sqlState, errno, sre); case UNAVAILABLE: return new SQLTransientException(sre.toString(), sqlState, errno, sre); case ABORTED: return new SQLRecoverableException(sre.toString(), sqlState, errno, sre); default: // Covers e.g. UNKNOWN. String advice = "";
@Override protected boolean matchesSafely(StatusRuntimeException item) { return Objects.equals(item.getTrailers().get(key), value); }
public void greet(String name){ HelloRequest request = HelloRequest.newBuilder().setName(name).build(); HelloReply response; try { response = blockingStub.sayHello(request); } catch (StatusRuntimeException e) { System.out.println("RPC调用失败:"+e.getMessage()); return; } System.out.println("服务器返回信息:"+response.getMessage()); }
/** * Issue {@link org.apache.nemo.runtime.common.message.MessageSender#send(Object)} rpc call. * * @param message a message to send */ void send(final ControlMessage.Message message) { LOG.debug("[SEND] request msg.id={}, msg.listenerId={}, msg.type={}", message.getId(), message.getListenerId(), message.getType()); try { blockingStub.send(message); } catch (final StatusRuntimeException e) { LOG.warn("RPC send call failed with msg.id={}, msg.listenerId={}, msg.type={}, e.cause={}, e.message={}", message.getId(), message.getListenerId(), message.getType(), e.getCause(), e.getMessage()); } }
assertThat(t.getCause()).isInstanceOfSatisfying( StatusCauseException.class, cause -> { assertThat(t.getCause().getCause()).isInstanceOfSatisfying( StatusCauseException.class, cause -> { assertThat(t.getCause().getCause().getCause()).isInstanceOfSatisfying( StatusCauseException.class, cause -> { assertThat(t.getCause().getCause().getCause().getCause()).isInstanceOfSatisfying( StatusCauseException.class, cause -> {
} catch( StatusRuntimeException sre) { shutdown(candidate); logger.warn("Connecting to AxonServer node {}:{} failed: {}", nodeInfo.getHostName(), nodeInfo.getGrpcPort(), sre.getMessage()); if( sre.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) { unavailable = true;
/** * Extract an error trailers from the causal chain of a {@link Throwable}. * * @return the trailers or {@code null} if not found. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4683") public static Metadata trailersFromThrowable(Throwable t) { Throwable cause = checkNotNull(t, "t"); while (cause != null) { if (cause instanceof StatusException) { return ((StatusException) cause).getTrailers(); } else if (cause instanceof StatusRuntimeException) { return ((StatusRuntimeException) cause).getTrailers(); } cause = cause.getCause(); } return null; }
public void greet(String name){ HelloRequest request = HelloRequest.newBuilder().setName(name).build(); HelloReply response; try { response = blockingStub.sayHello(request); } catch (StatusRuntimeException e) { System.out.println("RPC调用失败:"+e.getMessage()); return; } System.out.println("服务器返回信息:"+response.getMessage()); }
/** * Issue {@link org.apache.nemo.runtime.common.message.MessageSender#send(Object)} rpc call. * * @param message a message to send */ void send(final ControlMessage.Message message) { LOG.debug("[SEND] request msg.id={}, msg.listenerId={}, msg.type={}", message.getId(), message.getListenerId(), message.getType()); try { blockingStub.send(message); } catch (final StatusRuntimeException e) { LOG.warn("RPC send call failed with msg.id={}, msg.listenerId={}, msg.type={}, e.cause={}, e.message={}", message.getId(), message.getListenerId(), message.getType(), e.getCause(), e.getMessage()); } }
@Test public void runResourceExhaustedNoRetry() throws Exception { try { runTransaction( new StatusRuntimeException(Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value()))); fail("Expected exception"); } catch (SpannerException e) { // expected. } verify(txn).rollback(); }
@Override public void onError(Throwable throwable) { logger.debug("Lost instruction stream from {} - {}", name, throwable.getMessage()); disconnectListeners.forEach(Runnable::run); if( throwable instanceof StatusRuntimeException) { StatusRuntimeException sre = (StatusRuntimeException)throwable; if( sre.getStatus().getCode().equals(Status.Code.PERMISSION_DENIED)) return; } scheduleReconnect(true); }
private static RuntimeException convertStatusRuntimeException(StatusRuntimeException error) { Status status = error.getStatus(); Metadata trailers = error.getTrailers(); ErrorType errorType = trailers.get(ErrorType.KEY); if (errorType != null) { String message = status.getDescription(); return errorType.toException(message); } else { return error; } }