@Override public boolean datasetExists(final String name) throws DatasetManagementException { return Retries.callWithRetries(new Retries.Callable<Boolean, DatasetManagementException>() { @Override public Boolean call() throws DatasetManagementException { return datasetFramework.getDatasetSpec(createInstanceId(name)) != null; } }, retryStrategy); }
/** * The same as calling {@link #runWithRetries(Runnable, RetryStrategy, Predicate)} where a retryable failure * is defined as a {@link RetryableException}. * * @param runnable the callable to run * @param retryStrategy the retry strategy to use if the supplier fails in a retryable way * @param <T> the type of throwable * @throws T if the runnable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <T extends Throwable> void runWithRetries(Runnable<T> runnable, RetryStrategy retryStrategy) throws T { runWithRetries(runnable, retryStrategy, DEFAULT_PREDICATE); }
protected <V> V supplyWithRetries(Supplier<V> supplier) { return Retries.supplyWithRetries(supplier, retryStrategy, IS_RETRYABLE); }
/** * Executes a {@link Runnable}, retrying if it throws something retryable. * * @param runnable the runnable to run * @param retryStrategy the retry strategy to use if the callable fails in a retryable way * @param isRetryable predicate to determine whether the callable failure is retryable or not * @param <T> the type of throwable * @throws InterruptedException if the call was interrupted between retries. The last Throwable that triggered the * retry will be added as a suppressed exception. * @throws T if the callable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. */ public static <T extends Throwable> void runWithInterruptibleRetries(Runnable<T> runnable, RetryStrategy retryStrategy, Predicate<Throwable> isRetryable) throws T, InterruptedException { callWithInterruptibleRetries((Callable<Void, T>) () -> { runnable.run(); return null; }, retryStrategy, isRetryable); }
@Override public BootstrapStepResult execute(String label, JsonObject argumentsObj) throws InterruptedException { T arguments; try { arguments = GSON.fromJson(argumentsObj, getArgumentsType()); } catch (JsonParseException e) { LOG.warn("Bootstrap step {} failed because its arguments are malformed: {}", label, e.getMessage()); return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, String.format("Argument decoding failed. Reason: %s", e.getMessage())); } try { arguments.validate(); } catch (RuntimeException e) { LOG.warn("Bootstrap step {} failed due to invalid arguments: {}", label, e.getMessage()); return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage()); } try { LOG.debug("Executing bootstrap step {}", label); Retries.runWithInterruptibleRetries(() -> execute(arguments), getRetryStrategy(), t -> t instanceof RetryableException); LOG.debug("Bootstrap step {} completed successfully", label); return new BootstrapStepResult(label, BootstrapStepResult.Status.SUCCEEDED); } catch (InterruptedException e) { throw e; } catch (Exception e) { LOG.warn("Bootstrap step {} failed to execute", label, e); return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage()); } }
/** * Executes a {@link Runnable}, retrying if it throws something retryable. * * @param runnable the runnable to run * @param retryStrategy the retry strategy to use if the callable fails in a retryable way * @param isRetryable predicate to determine whether the callable failure is retryable or not * @param <T> the type of throwable * @throws InterruptedException if the call was interrupted between retries. The last Throwable that triggered the * retry will be added as a suppressed exception. * @throws T if the callable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. */ public static <T extends Throwable> void runWithInterruptibleRetries(Runnable<T> runnable, RetryStrategy retryStrategy, Predicate<Throwable> isRetryable) throws T, InterruptedException { callWithInterruptibleRetries((Callable<Void, T>) () -> { runnable.run(); return null; }, retryStrategy, isRetryable); }
@Override public BootstrapStepResult execute(String label, JsonObject argumentsObj) throws InterruptedException { T arguments; try { arguments = GSON.fromJson(argumentsObj, getArgumentsType()); } catch (JsonParseException e) { LOG.warn("Bootstrap step {} failed because its arguments are malformed: {}", label, e.getMessage()); return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, String.format("Argument decoding failed. Reason: %s", e.getMessage())); } try { arguments.validate(); } catch (RuntimeException e) { LOG.warn("Bootstrap step {} failed due to invalid arguments: {}", label, e.getMessage()); return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage()); } try { LOG.debug("Executing bootstrap step {}", label); Retries.runWithInterruptibleRetries(() -> execute(arguments), getRetryStrategy(), t -> t instanceof RetryableException); LOG.debug("Bootstrap step {} completed successfully", label); return new BootstrapStepResult(label, BootstrapStepResult.Status.SUCCEEDED); } catch (InterruptedException e) { throw e; } catch (Exception e) { LOG.warn("Bootstrap step {} failed to execute", label, e); return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage()); } }
@Override public boolean datasetExists(final String name) throws DatasetManagementException { return Retries.callWithRetries(new Retries.Callable<Boolean, DatasetManagementException>() { @Override public Boolean call() throws DatasetManagementException { return datasetFramework.getDatasetSpec(createInstanceId(name)) != null; } }, retryStrategy); }
/** * The same as calling {@link #runWithRetries(Runnable, RetryStrategy, Predicate)} where a retryable failure * is defined as a {@link RetryableException}. * * @param runnable the callable to run * @param retryStrategy the retry strategy to use if the supplier fails in a retryable way * @param <T> the type of throwable * @throws T if the runnable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <T extends Throwable> void runWithRetries(Runnable<T> runnable, RetryStrategy retryStrategy) throws T { runWithRetries(runnable, retryStrategy, DEFAULT_PREDICATE); }
protected <V> V supplyWithRetries(Supplier<V> supplier) { return Retries.supplyWithRetries(supplier, retryStrategy, IS_RETRYABLE); }
LOG.debug("Executing {} subtask {} for program run {}.", taskInfo.getProvisioningOp().getType(), state, programRunId); taskInfoOptional = Retries.callWithInterruptibleRetries(() -> subtask.execute(taskInfo), retryStrategy, t -> t instanceof RetryableProvisionException); LOG.debug("Completed {} subtask {} for program run {}.",
@Override public String getDatasetType(final String name) throws DatasetManagementException { return Retries.callWithRetries(new Retries.Callable<String, DatasetManagementException>() { @Override public String call() throws DatasetManagementException { DatasetSpecification spec = datasetFramework.getDatasetSpec(createInstanceId(name)); if (spec == null) { throw new InstanceNotFoundException(name); } return spec.getType(); } }, retryStrategy); }
@Override public void deleteTopic(final String topic) throws TopicNotFoundException, IOException { if (messagingAdmin == null) { throw new UnsupportedOperationException("Messaging not supported"); } try { Retries.runWithRetries(() -> messagingAdmin.deleteTopic(topic), retryStrategy); } catch (TopicNotFoundException | IOException | RuntimeException | Error e) { throw e; } catch (Exception e) { // this should never happen throw new RuntimeException(e); } }
/** * The same as calling {@link #supplyWithRetries(Supplier, RetryStrategy, Predicate)} where a retryable failure * is defined as a {@link RetryableException}. * * @param supplier the callable to run * @param retryStrategy the retry strategy to use if the supplier throws a {@link RetryableException} * @param <V> the type of object returned by the supplier * @return the return value of the supplier * @throws RuntimeException if the supplier failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <V> V supplyWithRetries(Supplier<V> supplier, RetryStrategy retryStrategy) { return supplyWithRetries(supplier, retryStrategy, DEFAULT_PREDICATE); }
LOG.debug("Executing {} subtask {} for program run {}.", taskInfo.getProvisioningOp().getType(), state, programRunId); taskInfoOptional = Retries.callWithInterruptibleRetries(() -> subtask.execute(taskInfo), retryStrategy, t -> t instanceof RetryableProvisionException); LOG.debug("Completed {} subtask {} for program run {}.",
@Override public DatasetProperties getDatasetProperties(final String name) throws DatasetManagementException { return Retries.callWithRetries(new Retries.Callable<DatasetProperties, DatasetManagementException>() { @Override public DatasetProperties call() throws DatasetManagementException { DatasetSpecification spec = datasetFramework.getDatasetSpec(createInstanceId(name)); if (spec == null) { throw new InstanceNotFoundException(name); } return DatasetProperties.of(spec.getOriginalProperties()); } }, retryStrategy); }
@Override public void createTopic(final String topic) throws TopicAlreadyExistsException, IOException { if (messagingAdmin == null) { throw new UnsupportedOperationException("Messaging not supported"); } try { Retries.runWithRetries(() -> messagingAdmin.createTopic(topic), retryStrategy); } catch (TopicAlreadyExistsException | IOException | RuntimeException | Error e) { throw e; } catch (Exception e) { // this should never happen throw new RuntimeException(e); } }
/** * The same as calling {@link #supplyWithRetries(Supplier, RetryStrategy, Predicate)} where a retryable failure * is defined as a {@link RetryableException}. * * @param supplier the callable to run * @param retryStrategy the retry strategy to use if the supplier throws a {@link RetryableException} * @param <V> the type of object returned by the supplier * @return the return value of the supplier * @throws RuntimeException if the supplier failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <V> V supplyWithRetries(Supplier<V> supplier, RetryStrategy retryStrategy) { return supplyWithRetries(supplier, retryStrategy, DEFAULT_PREDICATE); }
try { return Retries.callWithInterruptibleRetries(() -> Transactionals.execute(transactional, dsContext -> { ProvisionerDataset dataset = ProvisionerDataset.get(dsContext, datasetFramework); ProvisioningTaskInfo currentState = dataset.getTaskInfo(taskKey);
private void write(final String stream, final ByteBuffer data, final Map<String, String> headers) throws IOException { Retries.callWithRetries(new Retries.Callable<Void, IOException>() { @Override public Void call() throws IOException { HttpRequest.Builder requestBuilder = remoteClient.requestBuilder(HttpMethod.POST, stream).withBody(data); for (Map.Entry<String, String> header : headers.entrySet()) { requestBuilder.addHeader(stream + "." + header.getKey(), header.getValue()); } writeToStream(namespace.stream(stream), requestBuilder); return null; } }, retryStrategy); }