private static RetryableException createRetryableExceptionWithGenericMessage(Exception cause, Date retryAfter) { return new RetryableException("Timeout", cause, retryAfter); } }
private RetryableException retryable(Throwable ex) { return new RetryableException("", ex, Date.from(Instant.EPOCH)); }
static FeignException errorExecuting(Request request, IOException cause) { return new RetryableException( format("%s executing %s %s", cause.getMessage(), request.method(), request.url()), cause, null); } }
@Override public Exception decode(String methodKey, Response response) { Exception exception = super.decode(methodKey, response); if (response.status() >= 500) { return new RetryableException( exception.getMessage(), exception, null ); } return exception; } }
/** * Returns the ID of the object created or null. */ static String awaitComplete(CloudDNS api, Job job) { RetryableException retryableException = new RetryableException( format("Job %s did not complete. Check your logs.", job.id), null); Retryer retryer = new Retryer.Default(500, 1000, 30); while (true) { job = api.getStatus(job.id); if ("COMPLETED".equals(job.status)) { return job.resultId; } else if ("ERROR".equals(job.status)) { throw new IllegalStateException( format("Job %s failed with error: %s", job.id, job.errorDetails)); } retryer.continueOrPropagate(retryableException); } }
@Override public Exception decode(String methodKey, Response response) { FeignException exception = errorStatus(methodKey, response); Date retryAfter = retryAfterDecoder.apply(firstOrNull(response.headers(), RETRY_AFTER)); if (retryAfter != null) { return new RetryableException(exception.getMessage(), exception, retryAfter); } return exception; }
@Override public Exception decode(String methodKey, Response response) { String details; try { details = IOUtils.toString(response.body().asInputStream(), "UTF-8"); } catch (NullPointerException | IOException e) { details = "Unable to read response body"; } DCOSException e = new DCOSException(response.status(), response.reason(), methodKey, details); // WARNING: THIS IF STATEMENT IS NOT THREAD SAFE // TODO: Fix the thread safety of this if statement or token refresh/clear in general if (authTokenHeaderInterceptor != null && response.status() == 401 && authTokenHeaderInterceptor.hasToken()) { authTokenHeaderInterceptor.clearToken(); return new RetryableException(response.reason(), e, null); } return e; } }
return new RetryableException("getting service unavailable, retrying ...", Request.HttpMethod.GET, null);
return new RetryableException("getting service unavailable, retrying ...", Request.HttpMethod.GET, null);
return new RetryableException("getting service unavailable, retrying ...", Request.HttpMethod.GET, null);
case 500: //INTERNAL_SERVER_ERROR case 503: //SERVICE_UNAVAILABLE return new RetryableException(message, null); default: return new MetacatException(message);
@Test public void shouldThrowRetryException() { wireMockRule.stubFor(get(urlEqualTo("/icecream/orders/1")) .withHeader("Accept", equalTo("application/json")) .willReturn(aResponse().withStatus(HttpStatus.SC_SERVICE_UNAVAILABLE))); IcecreamServiceApi client = builder() .statusHandler(throwOnStatus( status -> status == HttpStatus.SC_SERVICE_UNAVAILABLE, (methodTag, response) -> new RetryableException("Should retry on next node", null))) .target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port()); StepVerifier.create(client.findFirstOrder()) .expectError(RetryableException.class); }
throwOnStatus( status -> status == HttpStatus.SC_SERVICE_UNAVAILABLE, (methodTag, response) -> new RetryableException("Should retry on next node", null)), throwOnStatus( status -> status == HttpStatus.SC_UNAUTHORIZED,