@Override public V allocate(final Slot slot) throws Exception { return retryer.call(new Callable<V>() { @Override public V call() throws Exception { return allocator.allocate(slot); } }); }
private BulkResult runBulkRequest(final Bulk request, int count) { try { return BULK_REQUEST_RETRYER.call(() -> client.execute(request)); } catch (ExecutionException | RetryException e) { if (e instanceof RetryException) { LOG.error("Could not bulk index {} messages. Giving up after {} attempts.", count, ((RetryException) e).getNumberOfFailedAttempts()); } else { LOG.error("Couldn't bulk index " + count + " messages.", e); } throw new RuntimeException(e); } }
JOURNAL_WRITE_RETRYER.call(new Callable<Void>() { @Override public Void call() throws Exception {
public static void mkdirsWithRecursivePermissionWithRetry(final FileSystem fs, final Path path, FsPermission perm, Config retrierConfig) throws IOException { if (fs.exists(path)) { return; } if (path.getParent() != null && !fs.exists(path.getParent())) { mkdirsWithRecursivePermissionWithRetry(fs, path.getParent(), perm, retrierConfig); } if (!fs.mkdirs(path, perm)) { throw new IOException(String.format("Unable to mkdir %s with permission %s", path, perm)); } if (retrierConfig != NO_RETRY_CONFIG) { //Wait until file is not there as it can happen the file fail to exist right away on eventual consistent fs like Amazon S3 Retryer<Void> retryer = RetryerFactory.newInstance(retrierConfig); try { retryer.call(() -> { if (!fs.exists(path)) { throw new IOException("Path " + path + " does not exist however it should. Will wait more."); } return null; }); } catch (Exception e) { throw new IOException("Path " + path + "does not exist however it should. Giving up..."+ e); } } // Double check permission, since fs.mkdirs() may not guarantee to set the permission correctly if (!fs.getFileStatus(path).getPermission().equals(perm)) { fs.setPermission(path, perm); } }
retryer.call(checkForEmptyBuffers); } catch (RetryException e) { LOG.info("Buffers not empty after {} {}. Giving up.", maxWait, timeUnit.name().toLowerCase(Locale.ENGLISH));
private void moveTmpPathToOutputPath() throws IOException { Retryer<Void> retryer = RetryerFactory.newInstance(this.retrierConfig); LOG.info(String.format("Moving %s to %s", this.dataset.outputTmpPath(), this.dataset.outputPath())); this.fs.delete(this.dataset.outputPath(), true); if (this.isRetryEnabled) { try { retryer.call(() -> { if (fs.exists(this.dataset.outputPath())) { throw new IOException("Path " + this.dataset.outputPath() + " exists however it should not. Will wait more."); } return null; }); } catch (Exception e) { throw new IOException(e); } } WriterUtils.mkdirsWithRecursivePermissionWithRetry(MRCompactorJobRunner.this.fs, this.dataset.outputPath().getParent(), this.perm, this.retrierConfig); Log.info("Moving from fs: ("+MRCompactorJobRunner.this.tmpFs.getUri()+") path: "+ this.dataset.outputTmpPath() + " to "+ "fs: ("+ FileSystem.get(this.dataset.outputPath().getParent().toUri(), this.fs.getConf()).getUri()+") output path: " + this.dataset.outputPath()); HadoopUtils.movePath (MRCompactorJobRunner.this.tmpFs, this.dataset.outputTmpPath(), FileSystem.get(this.dataset.outputPath().getParent().toUri(), this.fs.getConf()), this.dataset.outputPath(), false, this.fs.getConf()) ; }
UnsampledReport result = null; try { result = retryer.call(new Callable<UnsampledReport>() {
return retryer.call(supplierCommand::get); } catch (ExecutionException executionException) { String errorMessage = String.format("Operation '%s:%s' failed for the %d time in RetryUtil", operationName,
.build(); try { retryer.call(() -> mongoDBSessionService.saveWithoutValidation(dbSession)); } catch (ExecutionException e) { LOG.warn("Unexpected exception when saving session to MongoDB. Failed to update session.", e);
/** * Retry to execute callable command. * * @param callable callable command * @param <T> return type * @return execute result */ public <T> Optional<T> execute(final Callable<T> callable) { Retryer<T> retryer = RetryerBuilder.<T>newBuilder() .retryIfExceptionOfType(TimeoutException.class) .retryIfExceptionOfType(ExecutionException.class) .retryIfExceptionOfType(InterruptedException.class) .withWaitStrategy(WaitStrategies.fixedWait(config.getRetryIntervalMilliseconds(), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(config.getMaxRetries())) .build(); try { return Optional.fromNullable(retryer.call(callable)); } catch (final ExecutionException | RetryException ex) { throw new RegistryCenterException(ex); } } }
return retryer.call(new Callable<UnsampledReport>() { @Override public UnsampledReport call() throws Exception {
private HttpResponse executeRequest(Function<String, String> hostToUri, Method method, Optional<?> body, Map<String, ?> queryParams) { HttpRequest.Builder request = HttpRequest.newBuilder().setMethod(method); if (body.isPresent()) { request.setBody(body.get()); } addQueryParams(request, queryParams); addCredentials(request); List<String> hosts = new ArrayList<>(hostsProvider.get()); request .setRetryStrategy(RetryStrategy.NEVER_RETRY) .setMaxRetries(1); try { return httpResponseRetryer.call(() -> { if (hosts.isEmpty()) { // We've tried everything we started with. Look again. hosts.addAll(hostsProvider.get()); } int selection = random.nextInt(hosts.size()); String host = hosts.get(selection); String url = hostToUri.apply(host); hosts.remove(selection); LOG.info("Making {} request to {}", method, url); request.setUrl(url); return httpClient.execute(request.build()); }); } catch (ExecutionException | RetryException exn) { throw new SingularityClientException("Failed request to Singularity", exn); } }
private <T> T callWithRetriesAndTimeout(Callable<T> callable, Optional<Integer> retryCount) throws Exception { RetryerBuilder<T> retryerBuilder = RetryerBuilder.<T>newBuilder() .withAttemptTimeLimiter(AttemptTimeLimiters.<T>fixedTimeLimit(configuration.getDockerClientTimeLimitSeconds(), TimeUnit.SECONDS, executor)); if (retryCount.isPresent()) { retryerBuilder.withStopStrategy(StopStrategies.stopAfterAttempt(retryCount.get())); } return retryerBuilder.build().call(callable); } }
.build(); retryer.call(() -> { final long start = System.currentTimeMillis();
private void runHealthcheck() { Optional<HealthcheckOptions> maybeOptions = task.getTaskDefinition().getHealthcheckOptions(); Optional<String> expectedHealthcheckResultFilePath = task.getTaskDefinition().getHealthcheckResultFilePath(); if (maybeOptions.isPresent() && expectedHealthcheckResultFilePath.isPresent()) { LOG.debug("Checking for healthcheck file {}", expectedHealthcheckResultFilePath.get()); String taskAppDirectory = task.getTaskDefinition().getTaskAppDirectory(); File fullHealthcheckPath = Paths.get(taskAppDirectory, expectedHealthcheckResultFilePath.get()).toFile(); try { Integer healthcheckMaxRetries = maybeOptions.get().getMaxRetries().or(configuration.getDefaultHealthcheckMaxRetries()); Integer retryInterval = maybeOptions.get().getIntervalSeconds().or(5); Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder() .retryIfResult(bool -> !bool) .withWaitStrategy(WaitStrategies.fixedWait(retryInterval, TimeUnit.SECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(healthcheckMaxRetries)) .build(); retryer.call(() -> fullHealthcheckPath.exists()); executorUtils.sendStatusUpdate(task.getDriver(), task.getTaskInfo().getTaskId(), Protos.TaskState.TASK_RUNNING, String.format("Task running process %s (health check file found successfully).", getCurrentProcessToString()), task.getLog()); } catch (ExecutionException | RetryException e) { executorUtils.sendStatusUpdate(task.getDriver(), task.getTaskInfo().getTaskId(), TaskState.TASK_FAILED, String.format("Task timed out on health checks (health check file not found)."), task.getLog()); } } else { executorUtils.sendStatusUpdate(task.getDriver(), task.getTaskInfo().getTaskId(), Protos.TaskState.TASK_RUNNING, String.format("Task running process %s", getCurrentProcessToString()), task.getLog()); } } }
.build(); retryer.call(() -> { final long start = System.currentTimeMillis();
/** * Makes the enclosing retryer call the wrapped callable. * * @see Retryer#call(Callable) */ @Override public X call() throws ExecutionException, RetryException { return retryer.call(callable); } }
private void markAsConsumed(final TrackedEntry trackedEntry) throws ExecutionException, RetryException { RETRY_BUILDER.build().call(new Callable<Void>() { @Override public Void call() throws Exception { feedTracker.markAsConsumed(trackedEntry.id); return null; } }); }
private BulkResult runBulkRequest(final Bulk request, int count) { try { return BULK_REQUEST_RETRYER.call(() -> client.execute(request)); } catch (ExecutionException | RetryException e) { if (e instanceof RetryException) { LOG.error("Could not bulk index {} messages. Giving up after {} attempts.", count, ((RetryException) e).getNumberOfFailedAttempts()); } else { LOG.error("Couldn't bulk index " + count + " messages.", e); } throw new RuntimeException(e); } }
private <T> T retry(Callable<T> f) throws ExecutionException, RetryException { final Retryer<T> retryer = RetryerBuilder.<T>newBuilder() .retryIfException(Impl::isRetryableException) .withWaitStrategy(WaitStrategies.join(exponentialWait(), randomWait(1, SECONDS))) .withStopStrategy(retryStopStrategy) .withRetryListener(Impl::onRequestAttempt) .build(); return retryer.call(f); }