com.github.rholder.retry.RetryerBuilder Java Examples

The following examples show how to use com.github.rholder.retry.RetryerBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultPowerBiConnection.java    From powerbi-rest-java with MIT License 6 votes vote down vote up
@Override
public <T> Future<T> execute(final PowerBiOperation<T> val) {
    // use a retryer to keep attempting to send data to powerBI if we receive a rate limit exception.
    // use exponential backoff to create a window of time for the request to come through.

    // TODO : the time to wait is actually in the response header, come back and add that value.
    final Retryer<T> retryer = RetryerBuilder.<T>newBuilder()
            // we are retrying on these exceptions because they are able to be handled by just retrying this callable
            // again (assuming that the maximum retries value is greater than 1 and this isn't the last retry attempt
            // before giving up.
            .retryIfExceptionOfType(RateLimitExceededException.class)
            .retryIfExceptionOfType(RequestAuthenticationException.class)
            .withAttemptTimeLimiter(AttemptTimeLimiters.<T>fixedTimeLimit(maximumWaitTime, TimeUnit.MILLISECONDS))
            .withStopStrategy(StopStrategies.stopAfterAttempt(maximumRetries))
            .build();

    return executor.submit(new Callable<T>() {
        @Override
        public T call() throws Exception {
            return retryer.call(new PowerBiCallable<>(val, clientBuilder));
        }
    });
}
 
Example #2
Source File: RetryWriter.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * @return RetryerBuilder that retries on all exceptions except NonTransientException with exponential back off
 */
public static RetryerBuilder<Void> createRetryBuilder(State state) {
  Predicate<Throwable> transients = new Predicate<Throwable>() {
    @Override
    public boolean apply(Throwable t) {
      return !(t instanceof NonTransientException);
    }
  };

  long multiplier = state.getPropAsLong(RETRY_MULTIPLIER, 500L);
  long maxWaitMsPerInterval = state.getPropAsLong(RETRY_MAX_WAIT_MS_PER_INTERVAL, 10000);
  int maxAttempts = state.getPropAsInt(RETRY_MAX_ATTEMPTS, 5);
  return RetryerBuilder.<Void> newBuilder()
      .retryIfException(transients)
      .withWaitStrategy(WaitStrategies.exponentialWait(multiplier, maxWaitMsPerInterval, TimeUnit.MILLISECONDS)) //1, 2, 4, 8, 16 seconds delay
      .withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts)); //Total 5 attempts and fail.
}
 
Example #3
Source File: RetryWriter.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Build Retryer.
 * - If Writer implements Retriable, it will use the RetryerBuilder from the writer.
 * - Otherwise, it will use DEFAULT writer builder.
 *
 * - If Gobblin metrics is enabled, it will emit all failure count in to metrics.
 *
 * @param state
 * @return
 */
private Retryer<Void> buildRetryer(State state) {
  RetryerBuilder<Void> builder = null;
  if (writer instanceof Retriable) {
    builder = ((Retriable) writer).getRetryerBuilder();
  } else {
    builder = createRetryBuilder(state);
  }

  if (GobblinMetrics.isEnabled(state)) {
    final Optional<Meter> retryMeter = Optional.of(Instrumented.getMetricContext(state, getClass()).meter(FAILED_RETRY_WRITES_METER));

    builder.withRetryListener(new RetryListener() {
      @Override
      public <V> void onRetry(Attempt<V> attempt) {
        if (attempt.hasException()) {
          LOG.warn("Caught exception. This may be retried.", attempt.getExceptionCause());
          Instrumented.markMeter(retryMeter);
          failedWrites++;
        }
      }
    });
  }
  return builder.build();
}
 
Example #4
Source File: BaseJdbcBufferedInserter.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
public BaseJdbcBufferedInserter(State state, Connection conn) {
  this.conn = conn;
  this.batchSize = state.getPropAsInt(WRITER_JDBC_INSERT_BATCH_SIZE, DEFAULT_WRITER_JDBC_INSERT_BATCH_SIZE);
  if (this.batchSize < 1) {
    throw new IllegalArgumentException(WRITER_JDBC_INSERT_BATCH_SIZE + " should be a positive number");
  }

  int maxWait = state.getPropAsInt(WRITER_JDBC_INSERT_RETRY_TIMEOUT, DEFAULT_WRITER_JDBC_INSERT_RETRY_TIMEOUT);
  int maxAttempts =
      state.getPropAsInt(WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT, DEFAULT_WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT);

  //retry after 2, 4, 8, 16... sec, allow at most maxWait sec delay
  this.retryer = RetryerBuilder.<Boolean> newBuilder().retryIfException()
      .withWaitStrategy(WaitStrategies.exponentialWait(1000, maxWait, TimeUnit.SECONDS))
      .withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts)).build();
}
 
Example #5
Source File: ZuoraClientImpl.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
ZuoraClientImpl(WorkUnitState workUnitState) {
  _workUnitState = workUnitState;
  _hostName = _workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
  _postRetryer =
      RetryerBuilder.<CommandOutput<RestApiCommand, String>>newBuilder().retryIfExceptionOfType(IOException.class)
          .withStopStrategy(StopStrategies
              .stopAfterAttempt(workUnitState.getPropAsInt(ZuoraConfigurationKeys.ZUORA_API_RETRY_POST_COUNT, 20)))
          .withWaitStrategy(WaitStrategies
              .fixedWait(workUnitState.getPropAsInt(ZuoraConfigurationKeys.ZUORA_API_RETRY_POST_WAIT_TIME, 60000),
                  TimeUnit.MILLISECONDS)).build();
  _getRetryer = RetryerBuilder.<List<String>>newBuilder().retryIfExceptionOfType(IOException.class).withStopStrategy(
      StopStrategies
          .stopAfterAttempt(workUnitState.getPropAsInt(ZuoraConfigurationKeys.ZUORA_API_RETRY_GET_FILES_COUNT, 30)))
      .withWaitStrategy(WaitStrategies
          .fixedWait(workUnitState.getPropAsInt(ZuoraConfigurationKeys.ZUORA_API_RETRY_GET_FILES_WAIT_TIME, 30000),
              TimeUnit.MILLISECONDS)).build();
}
 
Example #6
Source File: RetryUtil.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a retryer.
 *
 * @param actionDescription a description of the action being performed
 * @param waitUntilTime     the latest time to wait to perform the action
 * @param sleepTimeMs       the sleep time in millisecond for retries
 * @param exceptionClass    the class of exception to throw
 * @param logger            the logger
 * @param <T>               the type of object returned
 * @return the retryer
 */
private static <T> Retryer<T> buildRetryer(String actionDescription, ZonedDateTime waitUntilTime, long sleepTimeMs,
        Class<? extends CcmException> exceptionClass, Logger logger) {
    StopStrategy stop;
    if (waitUntilTime != null) {
        // Given the time at which waiting should stop,
        // get the available number of millis from this instant
        stop = StopStrategyFactory.waitUntilDateTime(waitUntilTime);
        logger.info("Trying until {} to {}", waitUntilTime, actionDescription);
    } else {
        stop = StopStrategies.neverStop();
        logger.warn("Unbounded wait to {}", actionDescription);
    }

    WaitStrategy wait = WaitStrategies.fixedWait(sleepTimeMs, TimeUnit.MILLISECONDS);
    logger.info("Checking every {} milliseconds", sleepTimeMs);

    return RetryerBuilder.<T>newBuilder()
            .retryIfException(t -> exceptionClass.isInstance(t) && ((CcmException) t).isRetryable())
            .retryIfResult(Objects::isNull)
            .withStopStrategy(stop)
            .withWaitStrategy(wait)
            .build();
}
 
Example #7
Source File: DigdagClient.java    From digdag with Apache License 2.0 6 votes vote down vote up
private Response invokeWithRetry(Invocation request)
{
    Retryer<Response> retryer = RetryerBuilder.<Response>newBuilder()
            .retryIfException(not(DigdagClient::isDeterministicError))
            .withWaitStrategy(exponentialWait())
            .withStopStrategy(stopAfterAttempt(10))
            .build();

    try {
        return retryer.call(() -> {
            Response res = request.invoke();
            if (res.getStatusInfo().getFamily() != SUCCESSFUL) {
                res.close();
                return handleErrorStatus(res);
            }
            return res;
        });
    }
    catch (ExecutionException | RetryException e) {
        Throwable cause = e.getCause() != null ? e.getCause() : e;
        throw Throwables.propagate(cause);
    }
}
 
Example #8
Source File: ServiceProvider.java    From ranger with Apache License 2.0 6 votes vote down vote up
private void createPath() throws Exception {
    Retryer<Void> retryer = RetryerBuilder.<Void>newBuilder()
            .retryIfExceptionOfType(KeeperException.NodeExistsException.class) //Ephemeral node still exists
            .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
            .withBlockStrategy(BlockStrategies.threadSleepStrategy())
            .withStopStrategy(StopStrategies.neverStop())
            .build();
    try {
        retryer.call(() -> {
            curatorFramework.create().withMode(CreateMode.EPHEMERAL).forPath(
                    String.format("/%s/%s", serviceName, serviceNode.representation()),
                    serializer.serialize(serviceNode));
            return null;
        });
    } catch (Exception e) {
        final String message = String.format("Could not create node for %s after 60 retries (1 min). " +
                        "This service will not be discoverable. Retry after some time.", serviceName);
        logger.error(message, e);
        throw new Exception(message, e);
    }

}
 
Example #9
Source File: DockerUtils.java    From Singularity with Apache License 2.0 6 votes vote down vote up
private <T> T callWithRetriesAndTimeout(
  Callable<T> callable,
  Optional<Integer> retryCount
)
  throws Exception {
  RetryerBuilder<T> retryerBuilder = RetryerBuilder
    .<T>newBuilder()
    .withAttemptTimeLimiter(
      new FixedTimeLimit(
        configuration.getDockerClientTimeLimitSeconds(),
        TimeUnit.SECONDS,
        executor
      )
    );
  if (retryCount.isPresent()) {
    retryerBuilder.withStopStrategy(StopStrategies.stopAfterAttempt(retryCount.get()));
  }
  return retryerBuilder.build().call(callable);
}
 
Example #10
Source File: BigtableStorage.java    From styx with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
BigtableStorage(Connection connection,
                ExecutorService executor,
                WaitStrategy waitStrategy,
                StopStrategy retryStopStrategy) {
  this.connection = Objects.requireNonNull(connection, "connection");

  this.executor = MDCUtil.withMDC(Context.currentContextExecutor(
      register(closer, Objects.requireNonNull(executor, "executor"), "bigtable-storage")));

  retryer = RetryerBuilder.<Void>newBuilder()
      .retryIfExceptionOfType(IOException.class)
      .withWaitStrategy(Objects.requireNonNull(waitStrategy, "waitStrategy"))
      .withStopStrategy(Objects.requireNonNull(retryStopStrategy, "retryStopStrategy"))
      .withRetryListener(BigtableStorage::onRequestAttempt)
      .build();
}
 
Example #11
Source File: LifecycleHelper.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public void notifyService(String action) throws Exception {
  long start = System.currentTimeMillis();
  Retryer<AgentCheckInResponse> retryer = RetryerBuilder.<AgentCheckInResponse>newBuilder()
      .retryIfException()
      .withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxNotifyServiceAttempts()))
      .withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
      .build();

  AgentCheckInResponse agentCheckInResponse = retryer.call(checkInCallable(action, false));
  while ((agentCheckInResponse.getState() != TrafficSourceState.DONE
      && System.currentTimeMillis() - start < configuration.getAgentCheckInTimeoutMs())) {
    try {
      Thread.sleep(agentCheckInResponse.getWaitTime());
    } catch (InterruptedException ie) {
      LOG.error("Interrupted waiting for check in with service, shutting down early");
      break;
    }
    agentCheckInResponse = retryer.call(checkInCallable(action, true));
  }
  LOG.info("Finished agent check in");
}
 
Example #12
Source File: HelloDemo.java    From retry with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Callable<Boolean> callable = new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            // do something useful here
            LOGGER.info("call...");
            throw new RuntimeException();
        }
    };

    Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
            .retryIfResult(Predicates.isNull())
            .retryIfExceptionOfType(IOException.class)
            .retryIfRuntimeException()
            .withStopStrategy(StopStrategies.stopAfterAttempt(3))
            .build();
    try {
        retryer.call(callable);
    } catch (RetryException | ExecutionException e) {
        e.printStackTrace();
    }

}
 
Example #13
Source File: ExponentialBackoff.java    From retry with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Callable<Boolean> callable = new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            // do something useful here
            LOGGER.info("call...");
            throw new RuntimeException();
        }
    };

    Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
            .retryIfResult(Predicates.isNull())
            .retryIfExceptionOfType(IOException.class)
            .retryIfRuntimeException()
            .withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS))
            .withStopStrategy(StopStrategies.stopAfterAttempt(3))
            .build();
    try {
        retryer.call(callable);
    } catch (RetryException | ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example #14
Source File: HBaseRetryingUtils.java    From flinkDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 重试发送数据到hbase
 *
 * @param table
 * @param puts      List<Put>
 * @throws Exception 连接异常
 */
public static void retrying(Table table, List<Put> puts) throws Exception {
    // 异常或者返回null都继续重试、每3秒重试一次、最多重试5次
    Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
            .retryIfException()
            .withWaitStrategy(WaitStrategies.fixedWait(500, TimeUnit.MILLISECONDS))
            .withStopStrategy(StopStrategies.stopAfterAttempt(6))
            .build();

    try {
        retryer.call(() -> HBaseUtils.batchPuts(table, puts));
    } catch (Exception e) {
        LOGGER.error("多次重试发送数据到hbase失败!", e);
        throw new Exception("多次重试发送数据到hbase失败!", e);
    }
}
 
Example #15
Source File: SingularityClient.java    From Singularity with Apache License 2.0 5 votes vote down vote up
public SingularityClient(
  String contextPath,
  HttpClient httpClient,
  Provider<List<String>> hostsProvider,
  Optional<SingularityClientCredentials> credentials,
  boolean ssl,
  int retryAttempts,
  Predicate<HttpResponse> retryStrategy
) {
  this.httpClient = httpClient;
  this.contextPath = contextPath;

  this.hostsProvider = hostsProvider;
  this.random = new Random();

  this.credentials = credentials;
  this.ssl = ssl;

  this.httpResponseRetryer =
    RetryerBuilder
      .<HttpResponse>newBuilder()
      .withStopStrategy(StopStrategies.stopAfterAttempt(retryAttempts))
      .withWaitStrategy(WaitStrategies.exponentialWait())
      .retryIfResult(retryStrategy::test)
      .retryIfException()
      .build();
}
 
Example #16
Source File: ResyncListener.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private void reapplyConfigsWithRetry() {
  Callable<Void> callable = new Callable<Void>() {
    public Void call() throws Exception {
      if (!agentLock.tryLock(agentLockTimeoutMs, TimeUnit.MILLISECONDS)) {
        LOG.warn("Failed to acquire lock for config reapply");
        throw new LockTimeoutException(String.format("Failed to acquire lock to reapply most current configs in %s ms", agentLockTimeoutMs), agentLock);
      }
      try {
        lifecycleHelper.applyCurrentConfigs();
        return null;
      } finally {
        agentLock.unlock();
      }
    }
  };

  Retryer<Void> retryer = RetryerBuilder.<Void>newBuilder()
    .retryIfException()
    .withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxReapplyConfigAttempts()))
    .withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
    .build();

  try {
    retryer.call(callable);
  } catch (RetryException re) {
    LOG.error("Exception applying current configs", re.getLastFailedAttempt().getExceptionCause());
    lifecycleHelper.abort("Caught exception while trying to resync, aborting", re);
  } catch (ExecutionException ee) {
    LOG.error("Exception applying current configs", ee);
    lifecycleHelper.abort("Caught exception while trying to resync, aborting", ee);
  }
}
 
Example #17
Source File: SingularityUpstreamChecker.java    From Singularity with Apache License 2.0 5 votes vote down vote up
private void checkSyncUpstreamsState(
  LoadBalancerRequestId loadBalancerRequestId,
  String singularityRequestId
) {
  Retryer<SingularityLoadBalancerUpdate> syncingRetryer = RetryerBuilder
    .<SingularityLoadBalancerUpdate>newBuilder()
    .retryIfException()
    .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
    .retryIfResult(IS_WAITING_STATE)
    .build();
  try {
    LOG.info(
      "Checking load balancer request to sync upstreams for service {} using a retryer until the request state is no longer waiting.",
      singularityRequestId
    );
    SingularityLoadBalancerUpdate syncUpstreamsState = syncingRetryer.call(
      () -> lbClient.getState(loadBalancerRequestId)
    );
    if (syncUpstreamsState.getLoadBalancerState() == BaragonRequestState.SUCCESS) {
      LOG.debug(
        "Syncing upstreams for singularity request {} is {}.",
        singularityRequestId,
        syncUpstreamsState
      );
    } else {
      LOG.error(
        "Syncing upstreams for singularity request {} is {}.",
        singularityRequestId,
        syncUpstreamsState
      );
    }
  } catch (Exception e) {
    LOG.error(
      "Could not check sync upstream state for singularity request {}. ",
      singularityRequestId,
      e
    );
  }
}
 
Example #18
Source File: LifecycleHelper.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private Collection<BaragonServiceState> getGlobalStateWithRetry() {
  Retryer<Collection<BaragonServiceState>> retryer = RetryerBuilder.<Collection<BaragonServiceState>>newBuilder()
      .retryIfException()
      .withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxGetGloablStateAttempts()))
      .withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
      .build();

  try {
    return retryer.call(this::getGlobalState);
  } catch (Exception e) {
    LOG.error("Could not get global state from Baragon Service");
    throw Throwables.propagate(e);
  }
}
 
Example #19
Source File: AWSInstanceNameLookupProcessor.java    From graylog-plugin-aws with Apache License 2.0 5 votes vote down vote up
private void waitForMigrationCompletion(ClusterConfigService clusterConfigService) throws java.util.concurrent.ExecutionException, com.github.rholder.retry.RetryException {
    final Retryer<Boolean> waitingForMigrationCompletion = RetryerBuilder.<Boolean>newBuilder()
            .retryIfResult((result) -> result == null || !result)
            .build();

    waitingForMigrationCompletion.call(() -> clusterConfigService.get(
            V20200505121200_EncryptAWSSecretKey.MigrationCompleted.class
    ) != null);
}
 
Example #20
Source File: GobblinHelixJobScheduler.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private void cancelJobIfRequired(DeleteJobConfigArrivalEvent deleteJobArrival) throws InterruptedException {
  Properties jobConfig = deleteJobArrival.getJobConfig();
  if (PropertiesUtils.getPropAsBoolean(jobConfig, GobblinClusterConfigurationKeys.CANCEL_RUNNING_JOB_ON_DELETE,
      GobblinClusterConfigurationKeys.DEFAULT_CANCEL_RUNNING_JOB_ON_DELETE)) {
    LOGGER.info("Cancelling workflow: {}", deleteJobArrival.getJobName());

    //Workaround for preventing indefinite hangs observed in TaskDriver.getWorkflows() call.
    Callable<Map<String, String>> workflowsCallable = () -> HelixUtils.getWorkflowIdsFromJobNames(this.jobHelixManager,
        Collections.singletonList(deleteJobArrival.getJobName()));
    Retryer<Map<String, String>> retryer = RetryerBuilder.<Map<String, String>>newBuilder()
        .retryIfException()
        .withStopStrategy(StopStrategies.stopAfterAttempt(5))
        .withAttemptTimeLimiter(AttemptTimeLimiters.fixedTimeLimit(this.helixWorkflowListingTimeoutMillis, TimeUnit.MILLISECONDS)).build();
    Map<String, String> jobNameToWorkflowIdMap;
    try {
      jobNameToWorkflowIdMap = retryer.call(workflowsCallable);
    } catch (ExecutionException | RetryException e) {
      LOGGER.error("Exception encountered when getting workflows from Helix; likely a Helix/Zk issue.", e);
      return;
    }

    if (jobNameToWorkflowIdMap.containsKey(deleteJobArrival.getJobName())) {
      String workflowId = jobNameToWorkflowIdMap.get(deleteJobArrival.getJobName());
      TaskDriver taskDriver = new TaskDriver(this.jobHelixManager);
      taskDriver.waitToStop(workflowId, this.helixJobStopTimeoutMillis);
      LOGGER.info("Stopped workflow: {}", deleteJobArrival.getJobName());
      //Wait until the cancelled job is complete.
      waitForJobCompletion(deleteJobArrival.getJobName());
    } else {
      LOGGER.warn("Could not find Helix Workflow Id for job: {}", deleteJobArrival.getJobName());
    }
  }
}
 
Example #21
Source File: ThrottleWriter.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public RetryerBuilder<Void> getRetryerBuilder() {
  if (writer instanceof Retriable) {
    return ((Retriable) writer).getRetryerBuilder();
  }
  return RetryWriter.createRetryBuilder(state);
}
 
Example #22
Source File: CloseOnFlushWriterWrapper.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public RetryerBuilder<Void> getRetryerBuilder() {
  if (writer instanceof Retriable) {
    return ((Retriable) writer).getRetryerBuilder();
  }
  return RetryWriter.createRetryBuilder(state);
}
 
Example #23
Source File: CommonConfig.java    From txle with Apache License 2.0 5 votes vote down vote up
@Bean
public Retryer<Boolean> retryer() {
    return RetryerBuilder.<Boolean>newBuilder()
            .retryIfException()
            .retryIfResult(Predicates.equalTo(false))
            .withWaitStrategy(WaitStrategies.fixedWait(interval, TimeUnit.SECONDS))
            .withStopStrategy(StopStrategies.stopAfterAttempt(times))
            .build();
}
 
Example #24
Source File: ZuoraClientFilesStreamer.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public ZuoraClientFilesStreamer(WorkUnitState workUnitState, ZuoraClient client) {
  _workUnitState = workUnitState;
  _client = client;
  batchSize = workUnitState.getPropAsInt(ConfigurationKeys.SOURCE_QUERYBASED_FETCH_SIZE, 2000);
  outputFormat = _workUnitState.getProp(ZuoraConfigurationKeys.ZUORA_OUTPUT_FORMAT);
  _getRetryer = RetryerBuilder.<Void>newBuilder().retryIfExceptionOfType(IOException.class).withStopStrategy(
      StopStrategies
          .stopAfterAttempt(workUnitState.getPropAsInt(ZuoraConfigurationKeys.ZUORA_API_RETRY_STREAM_FILES_COUNT, 3)))
      .withWaitStrategy(WaitStrategies
          .fixedWait(workUnitState.getPropAsInt(ZuoraConfigurationKeys.ZUORA_API_RETRY_STREAM_FILES_WAIT_TIME, 10000),
              TimeUnit.MILLISECONDS)).build();
}
 
Example #25
Source File: AzkabanClient.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Child class should have a different builderMethodName.
 */
@Builder
protected AzkabanClient(String username,
                        String password,
                        String url,
                        long sessionExpireInMin,
                        CloseableHttpClient httpClient,
                        SessionManager sessionManager,
                        ExecutorService executorService)
    throws AzkabanClientException {
  this.username = username;
  this.password = password;
  this.url = url;
  this.sessionExpireInMin = sessionExpireInMin;
  this.httpClient = httpClient;
  this.sessionManager = sessionManager;
  this.executorService = executorService;
  this.initializeClient();
  this.initializeSessionManager();
  this.intializeExecutorService();
  this.retryer = RetryerBuilder.<AzkabanClientStatus>newBuilder()
      .retryIfExceptionOfType(InvalidSessionException.class)
      .withAttemptTimeLimiter(AttemptTimeLimiters.fixedTimeLimit(10, TimeUnit.SECONDS, this.executorService))
      .withWaitStrategy(WaitStrategies.exponentialWait(60, TimeUnit.SECONDS))
      .withStopStrategy(StopStrategies.stopAfterAttempt(3))
      .build();
  this.sessionId = this.sessionManager.fetchSession();
  this.sessionCreationTime = System.nanoTime();
}
 
Example #26
Source File: RetryerFactory.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private static <T> Retryer<T> newFixedAttemptBoundRetryer(Config config) {
  return RetryerBuilder.<T> newBuilder()
      .retryIfException(RETRY_EXCEPTION_PREDICATE)
      .withWaitStrategy(WaitStrategies.fixedWait(config.getLong(RETRY_INTERVAL_MS), TimeUnit.MILLISECONDS))
      .withStopStrategy(StopStrategies.stopAfterAttempt(config.getInt(RETRY_TIMES)))
      .build();
}
 
Example #27
Source File: RetryerFactory.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private static <T> Retryer<T> newExponentialRetryer(Config config) {
  return RetryerBuilder.<T> newBuilder()
      .retryIfException(RETRY_EXCEPTION_PREDICATE)
      .withWaitStrategy(WaitStrategies.exponentialWait(config.getLong(RETRY_MULTIPLIER),
                                                       config.getLong(RETRY_INTERVAL_MS),
                                                       TimeUnit.MILLISECONDS))
      .withStopStrategy(StopStrategies.stopAfterDelay(config.getLong(RETRY_TIME_OUT_MS), TimeUnit.MILLISECONDS))
      .build();
}
 
Example #28
Source File: RetryerFactory.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private static <T> Retryer<T> newFixedRetryer(Config config) {
  return RetryerBuilder.<T> newBuilder()
      .retryIfException(RETRY_EXCEPTION_PREDICATE)
      .withWaitStrategy(WaitStrategies.fixedWait(config.getLong(RETRY_INTERVAL_MS), TimeUnit.MILLISECONDS))
      .withStopStrategy(StopStrategies.stopAfterDelay(config.getLong(RETRY_TIME_OUT_MS), TimeUnit.MILLISECONDS))
      .build();
}
 
Example #29
Source File: RetryableTemplate.java    From java-samples with Apache License 2.0 5 votes vote down vote up
public static <T> T callWithRetry(Callable<T> callable)
    throws ExecutionException, RetryException {
  Retryer<T> retryer =
      RetryerBuilder.<T>newBuilder()
          .retryIfException(
              input -> {
                if (input instanceof GoogleJsonResponseException) {
                  GoogleJsonResponseException jsonException = (GoogleJsonResponseException) input;
                  int responseCode = jsonException.getDetails().getCode();
                  if (DONT_RETRY.contains(responseCode)) {
                    logger.log(
                        Level.WARNING,
                        "Encountered Non Retryable Error: " + jsonException.getMessage());
                    return false;
                  } else {
                    logger.log(
                        Level.WARNING,
                        "Encountered retryable error: "
                            + jsonException.getMessage()
                            + ".Retrying...");
                    return true;
                  }
                } else {
                  logger.log(
                      Level.WARNING,
                      "Encountered error: " + input.getMessage() + ". Retrying...");
                  return true;
                }
              })
          .withWaitStrategy(WaitStrategies.fixedWait(40, TimeUnit.SECONDS))
          .withStopStrategy(StopStrategies.stopAfterAttempt(1000))
          .build();
  return retryer.call(callable);
}
 
Example #30
Source File: KubernetesCleanupTest.java    From styx with Apache License 2.0 5 votes vote down vote up
private static <T> T retry(Callable<T> callable) {
  var retryer = RetryerBuilder.<T>newBuilder()
      .retryIfException()
      .withWaitStrategy(exponentialWait())
      .withStopStrategy(stopAfterDelay(30, SECONDS))
      .build();
  try {
    return retryer.call(callable);
  } catch (ExecutionException | RetryException e) {
    throw new RuntimeException(e);
  }
}