Skip to content

Commit

Permalink
Add retry strategy for throttling in clients
Browse files Browse the repository at this point in the history
This is expected for Review Readiness of the Uluru handlers.
  • Loading branch information
Alex-Vol-Amz committed Jul 8, 2024
1 parent fcf83fe commit 93158d6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
package software.amazon.transfer.server.clients;

import java.time.Duration;

import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting;
import software.amazon.awssdk.retries.api.BackoffStrategy;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.transfer.TransferClient;
import software.amazon.cloudformation.LambdaWrapper;

/** Create a TransferClient instance. */
public class ClientBuilder {
private static final BackoffStrategy TRANSFER_BACKOFF_THROTTLING_STRATEGY =
BackoffStrategy.exponentialDelay(Duration.ofMillis(2000), SdkDefaultRetrySetting.MAX_BACKOFF);

private static final RetryStrategy TRANSFER_RETRY_STRATEGY = AwsRetryStrategy.adaptiveRetryStrategy().toBuilder()
.backoffStrategy(TRANSFER_BACKOFF_THROTTLING_STRATEGY)
.maxAttempts(4)
.build();

/**
* Returns the TransferClient instance.
*
* @return the TransferClient instance.
*/
public static TransferClient getClient() {
return TransferClient.builder().httpClient(LambdaWrapper.HTTP_CLIENT).build();
return TransferClient.builder()
.httpClient(LambdaWrapper.HTTP_CLIENT)
.overrideConfiguration(ClientOverrideConfiguration.builder()
.retryStrategy(TRANSFER_RETRY_STRATEGY)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
package software.amazon.transfer.server.clients;

import java.time.Duration;

import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting;
import software.amazon.awssdk.retries.api.BackoffStrategy;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.cloudformation.LambdaWrapper;

/** Create an Ec2Client instance. */
public class Ec2ClientBuilder {
private static final BackoffStrategy EC2_BACKOFF_THROTTLING_STRATEGY =
BackoffStrategy.exponentialDelay(Duration.ofMillis(2000), SdkDefaultRetrySetting.MAX_BACKOFF);

private static final RetryStrategy EC2_RETRY_STRATEGY = AwsRetryStrategy.adaptiveRetryStrategy().toBuilder()
.backoffStrategy(EC2_BACKOFF_THROTTLING_STRATEGY)
.maxAttempts(4)
.build();

/**
* Returns the Ec2Client instance.
*
* @return the Ec2Client instance.
*/
public static Ec2Client getClient() {
return Ec2Client.builder().httpClient(LambdaWrapper.HTTP_CLIENT).build();
return Ec2Client.builder()
.httpClient(LambdaWrapper.HTTP_CLIENT)
.overrideConfiguration(ClientOverrideConfiguration.builder()
.retryStrategy(EC2_RETRY_STRATEGY)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
package software.amazon.transfer.user.clients;

import java.time.Duration;

import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting;
import software.amazon.awssdk.retries.api.BackoffStrategy;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.transfer.TransferClient;
import software.amazon.cloudformation.LambdaWrapper;

public final class ClientBuilder {
private ClientBuilder() {}
/** Create a TransferClient instance. */
public class ClientBuilder {
private static final BackoffStrategy TRANSFER_BACKOFF_THROTTLING_STRATEGY =
BackoffStrategy.exponentialDelay(Duration.ofMillis(2000), SdkDefaultRetrySetting.MAX_BACKOFF);

private static final RetryStrategy TRANSFER_RETRY_STRATEGY = AwsRetryStrategy.adaptiveRetryStrategy().toBuilder()
.backoffStrategy(TRANSFER_BACKOFF_THROTTLING_STRATEGY)
.maxAttempts(4)
.build();

/**
* Returns the TransferClient instance.
*
* @return the TransferClient instance.
*/
public static TransferClient getClient() {
return TransferClient.builder().httpClient(LambdaWrapper.HTTP_CLIENT).build();
return TransferClient.builder()
.httpClient(LambdaWrapper.HTTP_CLIENT)
.overrideConfiguration(ClientOverrideConfiguration.builder()
.retryStrategy(TRANSFER_RETRY_STRATEGY)
.build())
.build();
}
}

0 comments on commit 93158d6

Please sign in to comment.