com.google.api.gax.retrying.RetrySettings Java Examples

The following examples show how to use com.google.api.gax.retrying.RetrySettings. 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: AbstractGCSProcessor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected StorageOptions getServiceOptions(ProcessContext context, GoogleCredentials credentials) {
    final String projectId = context.getProperty(PROJECT_ID).evaluateAttributeExpressions().getValue();
    final Integer retryCount = context.getProperty(RETRY_COUNT).asInteger();

    StorageOptions.Builder storageOptionsBuilder = StorageOptions.newBuilder()
            .setCredentials(credentials)
            .setRetrySettings(RetrySettings.newBuilder()
                    .setMaxAttempts(retryCount)
                    .build());

    if (projectId != null && !projectId.isEmpty()) {
        storageOptionsBuilder.setProjectId(projectId);
    }

    return  storageOptionsBuilder.setTransportOptions(getTransportOptions(context)).build();
}
 
Example #2
Source File: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
private RetrySettings buildRetrySettings(GcpPubSubProperties.Retry retryProperties) {
	Builder builder = RetrySettings.newBuilder();

	return ifNotNull(retryProperties.getInitialRetryDelaySeconds(),
			(x) -> builder.setInitialRetryDelay(Duration.ofSeconds(x)))
			.apply(ifNotNull(retryProperties.getInitialRpcTimeoutSeconds(),
					(x) -> builder.setInitialRpcTimeout(Duration.ofSeconds(x)))
			.apply(ifNotNull(retryProperties.getJittered(), builder::setJittered)
			.apply(ifNotNull(retryProperties.getMaxAttempts(), builder::setMaxAttempts)
			.apply(ifNotNull(retryProperties.getMaxRetryDelaySeconds(),
					(x) -> builder.setMaxRetryDelay(Duration.ofSeconds(x)))
			.apply(ifNotNull(retryProperties.getMaxRpcTimeoutSeconds(),
					(x) -> builder.setMaxRpcTimeout(Duration.ofSeconds(x)))
			.apply(ifNotNull(retryProperties.getRetryDelayMultiplier(), builder::setRetryDelayMultiplier)
			.apply(ifNotNull(retryProperties.getTotalTimeoutSeconds(),
					(x) -> builder.setTotalTimeout(Duration.ofSeconds(x)))
			.apply(ifNotNull(retryProperties.getRpcTimeoutMultiplier(), builder::setRpcTimeoutMultiplier)
			.apply(false))))))))) ? builder.build() : null;
}
 
Example #3
Source File: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PublisherFactory defaultPublisherFactory(
		@Qualifier("publisherExecutorProvider") ExecutorProvider executorProvider,
		@Qualifier("publisherBatchSettings") ObjectProvider<BatchingSettings> batchingSettings,
		@Qualifier("publisherRetrySettings") ObjectProvider<RetrySettings> retrySettings,
		TransportChannelProvider transportChannelProvider) {
	DefaultPublisherFactory factory = new DefaultPublisherFactory(this.finalProjectIdProvider);
	factory.setExecutorProvider(executorProvider);
	factory.setCredentialsProvider(this.finalCredentialsProvider);
	factory.setHeaderProvider(this.headerProvider);
	factory.setChannelProvider(transportChannelProvider);
	retrySettings.ifAvailable(factory::setRetrySettings);
	batchingSettings.ifAvailable(factory::setBatchingSettings);
	return factory;
}
 
Example #4
Source File: GcpPubSubEmulatorAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubscriberRetrySettings() {
	this.contextRunner.run((context) -> {
		RetrySettings settings = context.getBean("subscriberRetrySettings",
				RetrySettings.class);
		assertThat(settings.getTotalTimeout()).isEqualTo(Duration.ofSeconds(1));
		assertThat(settings.getInitialRetryDelay()).isEqualTo(Duration.ofSeconds(2));
		assertThat(settings.getRetryDelayMultiplier()).isEqualTo(3, DELTA);
		assertThat(settings.getMaxRetryDelay()).isEqualTo(Duration.ofSeconds(4));
		assertThat(settings.getMaxAttempts()).isEqualTo(5);
		assertThat(settings.isJittered()).isTrue();
		assertThat(settings.getInitialRpcTimeout()).isEqualTo(Duration.ofSeconds(6));
		assertThat(settings.getRpcTimeoutMultiplier()).isEqualTo(7, DELTA);
		assertThat(settings.getMaxRpcTimeout()).isEqualTo(Duration.ofSeconds(8));
	});
}
 
Example #5
Source File: GcpPubSubEmulatorAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublisherRetrySettings() {
	this.contextRunner.run((context) -> {
		RetrySettings settings = context.getBean("publisherRetrySettings",
				RetrySettings.class);
		assertThat(settings.getTotalTimeout()).isEqualTo(Duration.ofSeconds(9));
		assertThat(settings.getInitialRetryDelay()).isEqualTo(Duration.ofSeconds(10));
		assertThat(settings.getRetryDelayMultiplier()).isEqualTo(11, DELTA);
		assertThat(settings.getMaxRetryDelay()).isEqualTo(Duration.ofSeconds(12));
		assertThat(settings.getMaxAttempts()).isEqualTo(13);
		assertThat(settings.isJittered()).isTrue();
		assertThat(settings.getInitialRpcTimeout()).isEqualTo(Duration.ofSeconds(14));
		assertThat(settings.getRpcTimeoutMultiplier()).isEqualTo(15, DELTA);
		assertThat(settings.getMaxRpcTimeout()).isEqualTo(Duration.ofSeconds(16));
	});
}
 
Example #6
Source File: GoogleCloudPubSubSinkConfiguration.java    From divolte-collector with Apache License 2.0 6 votes vote down vote up
private SinkFactory createFlushingPool(final RetrySettings retrySettings,
                                       final BatchingSettings batchingSettings) {
    return (vc, sinkName, registry) -> {
        final String projectId = vc.configuration().global.gcps.projectId.orElseThrow(IllegalStateException::new);
        final ProjectTopicName topicName = ProjectTopicName.of(projectId, topic);
        final Publisher.Builder builder =
            Publisher.newBuilder(topicName)
                     .setRetrySettings(retrySettings)
                     .setBatchingSettings(batchingSettings);
        final Publisher publisher = IOExceptions.wrap(builder::build).get();
        return new GoogleCloudPubSubFlushingPool(sinkName,
                                                 vc.configuration().global.gcps.threads,
                                                 vc.configuration().global.gcps.bufferSize,
                                                 publisher,
                                                 Optional.empty(),
                                                 registry.getSchemaBySinkName(sinkName));
    };
}
 
Example #7
Source File: AbstractBigQueryProcessor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected BigQueryOptions getServiceOptions(ProcessContext context, GoogleCredentials credentials) {
    final String projectId = context.getProperty(PROJECT_ID).evaluateAttributeExpressions().getValue();
    final Integer retryCount = Integer.valueOf(context.getProperty(RETRY_COUNT).getValue());

    final BigQueryOptions.Builder builder = BigQueryOptions.newBuilder();

    if (!StringUtils.isBlank(projectId)) {
        builder.setProjectId(projectId);
    }

    return builder.setCredentials(credentials)
            .setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(retryCount).build())
            .setTransportOptions(getTransportOptions(context))
            .build();
}
 
Example #8
Source File: GoogleCloudPubSubSinkConfiguration.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
private SinkFactory createFlushingPool(final RetrySettings retrySettings,
                                       final BatchingSettings batchingSettings,
                                       final String hostPort) {
    // Based on Google's PubSub documentation:
    //   https://cloud.google.com/pubsub/docs/emulator#pubsub-emulator-java
    // What's going on here? Well…
    //  - Authentication is disabled; the emulator doesn't use or support it.
    //  - When Pub/Sub wants an I/O channel to talk to its Google Cloud endpoint, we're substituting our
    //    own endpoint instead. This channel also has TLS disabled, because the emulator doesn't need, use
    //    or support it.
    //
    return (vc, sinkName, registry) -> {
        logger.info("Configuring sink to use Google Cloud Pub/Sub emulator: {}", sinkName, hostPort);
        final String projectId = vc.configuration().global.gcps.projectId.orElseThrow(IllegalStateException::new);
        final ProjectTopicName topicName = ProjectTopicName.of(projectId, topic);
        final ManagedChannel channel = ManagedChannelBuilder.forTarget(hostPort).usePlaintext().build();
        final TransportChannelProvider channelProvider =
            FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
        // There's no easy way to create topics for the emulator, so we create the topic ourselves.
        createTopic(hostPort, channelProvider, topicName);
        final Publisher.Builder builder =
            Publisher.newBuilder(topicName)
                     .setRetrySettings(retrySettings)
                     .setBatchingSettings(batchingSettings)
                     .setChannelProvider(channelProvider)
                     .setCredentialsProvider(NoCredentialsProvider.create());
        final Publisher publisher = IOExceptions.wrap(builder::build).get();
        return new GoogleCloudPubSubFlushingPool(sinkName,
                                                 vc.configuration().global.gcps.threads,
                                                 vc.configuration().global.gcps.bufferSize,
                                                 publisher,
                                                 Optional.of(channel),
                                                 registry.getSchemaBySinkName(sinkName));
    };
}
 
Example #9
Source File: GooglePubSubRetryConfiguration.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
public RetrySettings createRetrySettings() {
    return RetrySettings.newBuilder()
                        .setMaxAttempts(maxAttempts)
                        .setTotalTimeout(to310bp(totalTimeout))
                        .setInitialRetryDelay(to310bp(initialRetryDelay))
                        .setRetryDelayMultiplier(retryDelayMultiplier)
                        .setMaxRetryDelay(to310bp(maxRetryDelay))
                        .setInitialRpcTimeout(to310bp(initialRpcTimeout))
                        .setRpcTimeoutMultiplier(rpcTimeoutMultiplier)
                        .setMaxRpcTimeout(to310bp(maxRpcTimeout)).build();
}
 
Example #10
Source File: GoogleCloudPubSubSinkConfiguration.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Override
public SinkFactory getFactory() {
    final RetrySettings retrySettings = this.retrySettings.createRetrySettings();
    final BatchingSettings batchingSettings = this.batchingSettings.createBatchingSettings();
    final Optional<String> emulator = Optional.ofNullable(System.getenv("PUBSUB_EMULATOR_HOST"));
    return emulator.map(hostport -> createFlushingPool(retrySettings, batchingSettings, hostport))
                   .orElseGet(() -> createFlushingPool(retrySettings, batchingSettings));
}
 
Example #11
Source File: CloudPubSubSinkTask.java    From pubsub with Apache License 2.0 5 votes vote down vote up
private void createPublisher() {
  ProjectTopicName fullTopic = ProjectTopicName.of(cpsProject, cpsTopic);
  com.google.cloud.pubsub.v1.Publisher.Builder builder =
      com.google.cloud.pubsub.v1.Publisher.newBuilder(fullTopic)
          .setCredentialsProvider(gcpCredentialsProvider)
          .setBatchingSettings(
              BatchingSettings.newBuilder()
                  .setDelayThreshold(Duration.ofMillis(maxDelayThresholdMs))
                  .setElementCountThreshold(maxBufferSize)
                  .setRequestByteThreshold(maxBufferBytes)
                  .build())
          .setRetrySettings(
              RetrySettings.newBuilder()
                  // All values that are not configurable come from the defaults for the publisher
                  // client library.
                  .setTotalTimeout(Duration.ofMillis(maxTotalTimeoutMs))
                  .setMaxRpcTimeout(Duration.ofMillis(maxRequestTimeoutMs))
                  .setInitialRetryDelay(Duration.ofMillis(5))
                  .setRetryDelayMultiplier(2)
                  .setMaxRetryDelay(Duration.ofMillis(Long.MAX_VALUE))
                  .setInitialRpcTimeout(Duration.ofSeconds(10))
                  .setRpcTimeoutMultiplier(2)
                  .build());
  try {
    publisher = builder.build();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #12
Source File: GoogleCloudPubSubSinkConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultRetryConfigurationValid() {
    // Check that we can generate settings from our defaults.
    final RetrySettings retrySettings =
        GoogleCloudPubSubSinkConfiguration.DEFAULT_RETRY_SETTINGS.createRetrySettings();
    assertNotNull(retrySettings);
}
 
Example #13
Source File: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SubscriberFactory defaultSubscriberFactory(
		@Qualifier("subscriberExecutorProvider") ExecutorProvider executorProvider,
		@Qualifier("subscriberSystemExecutorProvider")
		ObjectProvider<ExecutorProvider> systemExecutorProvider,
		@Qualifier("subscriberFlowControlSettings")
				ObjectProvider<FlowControlSettings> flowControlSettings,
		@Qualifier("subscriberApiClock") ObjectProvider<ApiClock> apiClock,
		@Qualifier("subscriberRetrySettings") ObjectProvider<RetrySettings> retrySettings,
		TransportChannelProvider transportChannelProvider) {
	DefaultSubscriberFactory factory = new DefaultSubscriberFactory(this.finalProjectIdProvider);
	factory.setExecutorProvider(executorProvider);
	factory.setCredentialsProvider(this.finalCredentialsProvider);
	factory.setHeaderProvider(this.headerProvider);
	factory.setChannelProvider(transportChannelProvider);
	systemExecutorProvider.ifAvailable(factory::setSystemExecutorProvider);
	flowControlSettings.ifAvailable(factory::setFlowControlSettings);
	apiClock.ifAvailable(factory::setApiClock);
	retrySettings.ifAvailable(factory::setSubscriberStubRetrySettings);
	if (this.gcpPubSubProperties.getSubscriber().getMaxAckExtensionPeriod() != null) {
		factory.setMaxAckExtensionPeriod(Duration.ofSeconds(
				this.gcpPubSubProperties.getSubscriber().getMaxAckExtensionPeriod()));
	}
	if (this.gcpPubSubProperties.getSubscriber().getParallelPullCount() != null) {
		factory.setParallelPullCount(
				this.gcpPubSubProperties.getSubscriber().getParallelPullCount());
	}
	if (this.gcpPubSubProperties.getSubscriber()
			.getPullEndpoint() != null) {
		factory.setPullEndpoint(
				this.gcpPubSubProperties.getSubscriber().getPullEndpoint());
	}
	return factory;
}
 
Example #14
Source File: ImportDataset.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
static void importDataset(String projectId, String datasetId, String path)
    throws IOException, ExecutionException, InterruptedException, TimeoutException {
  Duration totalTimeout = Duration.ofMinutes(45);
  RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build();
  AutoMlSettings.Builder builder = AutoMlSettings.newBuilder();
  builder.importDataSettings().setRetrySettings(retrySettings).build();
  AutoMlSettings settings = builder.build();

  // Initialize client that will be used to send requests. This client only needs to be created
  // once, and can be reused for multiple requests. After completing all of your requests, call
  // the "close" method on the client to safely clean up any remaining background resources.
  try (AutoMlClient client = AutoMlClient.create(settings)) {
    // Get the complete path of the dataset.
    DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);

    // Get multiple Google Cloud Storage URIs to import data from
    GcsSource gcsSource =
        GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();

    // Import data from the input URI
    InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
    System.out.println("Processing import...");

    // Start the import job
    OperationFuture<Empty, OperationMetadata> operation = client
        .importDataAsync(datasetFullId, inputConfig);

    System.out.format("Operation name: %s%n", operation.getName());

    // If you want to wait for the operation to finish, adjust the timeout appropriately. The
    // operation will still run if you choose not to wait for it to complete. You can check the
    // status of your operation using the operation's name.
    Empty response = operation.get(45, TimeUnit.MINUTES);
    System.out.format("Dataset imported. %s%n", response);
  } catch (TimeoutException e) {
    System.out.println("The operation's polling period was not long enough.");
    System.out.println("You can use the Operation's name to get the current status.");
    System.out.println("The import job is still running and will complete as expected.");
    throw e;
  }
}
 
Example #15
Source File: SpannerAccessor.java    From beam with Apache License 2.0 4 votes vote down vote up
private static SpannerAccessor createAndConnect(SpannerConfig spannerConfig) {
  SpannerOptions.Builder builder = SpannerOptions.newBuilder();

  ValueProvider<Duration> commitDeadline = spannerConfig.getCommitDeadline();
  if (commitDeadline != null && commitDeadline.get().getMillis() > 0) {

    // Set the GRPC deadline on the Commit API call.
    UnaryCallSettings.Builder commitSettings =
        builder.getSpannerStubSettingsBuilder().commitSettings();
    RetrySettings.Builder commitRetrySettings = commitSettings.getRetrySettings().toBuilder();
    commitSettings.setRetrySettings(
        commitRetrySettings
            .setTotalTimeout(org.threeten.bp.Duration.ofMillis(commitDeadline.get().getMillis()))
            .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(commitDeadline.get().getMillis()))
            .setInitialRpcTimeout(
                org.threeten.bp.Duration.ofMillis(commitDeadline.get().getMillis()))
            .build());
  }

  ValueProvider<String> projectId = spannerConfig.getProjectId();
  if (projectId != null) {
    builder.setProjectId(projectId.get());
  }
  ServiceFactory<Spanner, SpannerOptions> serviceFactory = spannerConfig.getServiceFactory();
  if (serviceFactory != null) {
    builder.setServiceFactory(serviceFactory);
  }
  ValueProvider<String> host = spannerConfig.getHost();
  if (host != null) {
    builder.setHost(host.get());
  }
  String userAgentString = USER_AGENT_PREFIX + "/" + ReleaseInfo.getReleaseInfo().getVersion();
  builder.setHeaderProvider(FixedHeaderProvider.create("user-agent", userAgentString));
  SpannerOptions options = builder.build();

  Spanner spanner = options.getService();
  String instanceId = spannerConfig.getInstanceId().get();
  String databaseId = spannerConfig.getDatabaseId().get();
  DatabaseClient databaseClient =
      spanner.getDatabaseClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId));
  BatchClient batchClient =
      spanner.getBatchClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId));
  DatabaseAdminClient databaseAdminClient = spanner.getDatabaseAdminClient();

  return new SpannerAccessor(
      spanner, databaseClient, databaseAdminClient, batchClient, spannerConfig);
}
 
Example #16
Source File: GoogleCloudPubSubSinkConfigurationTest.java    From divolte-collector with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetryMaxRpcTimeoutDefaultsToInitialRpcTimeout() {
    final RetrySettings retrySettings =
        new GooglePubSubRetryConfiguration(null, null, null, null, null, java.time.Duration.ofNanos(138263), null, null).createRetrySettings();
    assertEquals(retrySettings.getInitialRpcTimeout(), retrySettings.getMaxRpcTimeout());
}
 
Example #17
Source File: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = "publisherRetrySettings")
public RetrySettings publisherRetrySettings() {
	return buildRetrySettings(this.gcpPubSubProperties.getPublisher().getRetry());
}
 
Example #18
Source File: MutateJobServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .createMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .getMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listMutateJobResultsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .runMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .addMutateJobOperationsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .runMutateJobOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<RunMutateJobRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(MutateJobMetadata.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #19
Source File: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = "subscriberRetrySettings")
public RetrySettings subscriberRetrySettings() {
	return buildRetrySettings(this.gcpPubSubProperties.getSubscriber().getRetry());
}
 
Example #20
Source File: PhotosLibraryUploadCallable.java    From java-photoslibrary with Apache License 2.0 4 votes vote down vote up
/** Executes upload process for the request. */
@Override
public UploadMediaItemResponse call() throws Exception {
  long initialMillis = clientContext.getClock().millisTime();
  // Gets upload url (resume url)
  String uploadUrl = getUploadUrl();
  this.atomicResumeUrl.set(uploadUrl);
  checkForTimeout(initialMillis);

  Optional<HttpResponse> response = Optional.empty();
  RetrySettings retrySettings =
      photosLibrarySettings.uploadMediaItemSettings().getRetrySettings();

  // There is no error by default
  boolean successful = false;
  int retries = 0;
  OptionalLong previousDelayMillis = OptionalLong.empty();

  while (!successful
      && (retrySettings.getMaxAttempts() == UNLIMITED_RETRIES
          || retries < retrySettings.getMaxAttempts())) {
    retries++;
    // Keeps uploading bytes from the request media item by chunk
    long receivedByteCount = getReceivedByteCount(uploadUrl);
    // Moves the cursor to the correct position and reset failure indicator
    // before starting/resuming an upload
    request.seekCursor(receivedByteCount);
    successful = true;

    while (receivedByteCount < request.getFileSize()) {
      // Uploads the next chunk
      response = Optional.of(uploadNextChunk(uploadUrl, receivedByteCount));
      checkForTimeout(initialMillis);

      if (!isStatusOk(response.get().getStatusLine().getStatusCode())) {
        successful = false;
        break;
      }

      // Verifies the amount of data that has been received
      receivedByteCount = getReceivedByteCount(uploadUrl);
      checkForTimeout(initialMillis);
    }

    // There are some failures while uploading the media item and maxAttempts
    // has not been exceeded
    if (!successful && retries < retrySettings.getMaxAttempts()) {
      // Calculates delay millis for the current retry
      long delayMillis = retrySettings.getInitialRetryDelay().get(MILLIS);
      if (previousDelayMillis.isPresent()) {
        delayMillis =
            (long) (previousDelayMillis.getAsLong() * retrySettings.getRetryDelayMultiplier());
      }
      // Calculates actual delay millis and randomizes the duration if necessary
      long actualDelayMillis =
          Math.min(delayMillis, retrySettings.getMaxRetryDelay().get(MILLIS));
      if (retrySettings.isJittered()) {
        actualDelayMillis = ThreadLocalRandom.current().nextLong(actualDelayMillis);
      }

      // Sleeps
      Thread.sleep(actualDelayMillis);
      checkForTimeout(initialMillis);

      // Update previousDelayMillis
      previousDelayMillis = OptionalLong.of(actualDelayMillis);
    }
  }

  if (!successful) {
    if (response.isPresent()) {
      throw new HttpResponseException(
          response.get().getStatusLine().getStatusCode(), ExceptionStrings.INVALID_UPLOAD_RESULT);
    } else {
      throw new IllegalStateException(ExceptionStrings.UNKNOWN_ERROR);
    }
  }

  // Builds an upload response from the final httpResponse
  return buildUploadMediaItemResponse(response);
}
 
Example #21
Source File: CampaignDraftServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .getCampaignDraftSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .mutateCampaignDraftsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .promoteCampaignDraftSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listCampaignDraftAsyncErrorsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .promoteCampaignDraftOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<PromoteCampaignDraftRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #22
Source File: CampaignExperimentServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .getCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .createCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .mutateCampaignExperimentsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .graduateCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .promoteCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .endCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listCampaignExperimentAsyncErrorsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .createCampaignExperimentOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<CreateCampaignExperimentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(
                  CreateCampaignExperimentMetadata.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));
      builder
          .promoteCampaignExperimentOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<PromoteCampaignExperimentRequest, OperationSnapshot>
                      newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #23
Source File: MutateJobServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .createMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .getMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listMutateJobResultsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .runMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .addMutateJobOperationsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .runMutateJobOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<RunMutateJobRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(MutateJobMetadata.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #24
Source File: OfflineUserDataJobServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .createOfflineUserDataJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .getOfflineUserDataJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .addOfflineUserDataJobOperationsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .runOfflineUserDataJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .runOfflineUserDataJobOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<RunOfflineUserDataJobRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(300000L))
                      .setRetryDelayMultiplier(1.25)
                      .setMaxRetryDelay(Duration.ofMillis(3600000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(43200000L))
                      .build()));

      return builder;
    }
 
Example #25
Source File: CampaignDraftServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .getCampaignDraftSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .mutateCampaignDraftsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .promoteCampaignDraftSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listCampaignDraftAsyncErrorsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .promoteCampaignDraftOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<PromoteCampaignDraftRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #26
Source File: CampaignExperimentServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .getCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .createCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .mutateCampaignExperimentsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .graduateCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .promoteCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .endCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listCampaignExperimentAsyncErrorsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .createCampaignExperimentOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<CreateCampaignExperimentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(
                  CreateCampaignExperimentMetadata.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));
      builder
          .promoteCampaignExperimentOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<PromoteCampaignExperimentRequest, OperationSnapshot>
                      newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #27
Source File: MutateJobServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .createMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .getMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listMutateJobResultsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .runMutateJobSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .addMutateJobOperationsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .runMutateJobOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<RunMutateJobRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(MutateJobMetadata.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #28
Source File: CampaignDraftServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .getCampaignDraftSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .mutateCampaignDraftsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .promoteCampaignDraftSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listCampaignDraftAsyncErrorsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .promoteCampaignDraftOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<PromoteCampaignDraftRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #29
Source File: CampaignExperimentServiceStubSettings.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private static Builder initDefaults(Builder builder) {

      builder
          .getCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .createCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .mutateCampaignExperimentsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .graduateCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .promoteCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .endCampaignExperimentSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

      builder
          .listCampaignExperimentAsyncErrorsSettings()
          .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
          .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
      builder
          .createCampaignExperimentOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<CreateCampaignExperimentRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(
                  CreateCampaignExperimentMetadata.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));
      builder
          .promoteCampaignExperimentOperationSettings()
          .setInitialCallSettings(
              UnaryCallSettings
                  .<PromoteCampaignExperimentRequest, OperationSnapshot>
                      newUnaryCallSettingsBuilder()
                  .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
                  .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"))
                  .build())
          .setResponseTransformer(
              ProtoOperationTransformers.ResponseTransformer.create(Empty.class))
          .setMetadataTransformer(
              ProtoOperationTransformers.MetadataTransformer.create(Empty.class))
          .setPollingAlgorithm(
              OperationTimedPollAlgorithm.create(
                  RetrySettings.newBuilder()
                      .setInitialRetryDelay(Duration.ofMillis(500L))
                      .setRetryDelayMultiplier(1.5)
                      .setMaxRetryDelay(Duration.ofMillis(5000L))
                      .setInitialRpcTimeout(Duration.ZERO) // ignored
                      .setRpcTimeoutMultiplier(1.0) // ignored
                      .setMaxRpcTimeout(Duration.ZERO) // ignored
                      .setTotalTimeout(Duration.ofMillis(300000L))
                      .build()));

      return builder;
    }
 
Example #30
Source File: DefaultSubscriberFactory.java    From spring-cloud-gcp with Apache License 2.0 2 votes vote down vote up
/**
 * Set the retry settings for the generated subscriber stubs.
 * @param subscriberStubRetrySettings parameters for retrying pull requests when they fail,
 * including jitter logic, timeout, and exponential backoff
 */
public void setSubscriberStubRetrySettings(RetrySettings subscriberStubRetrySettings) {
	this.subscriberStubRetrySettings = subscriberStubRetrySettings;
}