-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry strategy for throttling in clients
This is expected for Review Readiness of the Uluru handlers.
- Loading branch information
1 parent
fcf83fe
commit 93158d6
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
22 changes: 21 additions & 1 deletion
22
aws-transfer-server/src/main/java/software/amazon/transfer/server/clients/ClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
22 changes: 21 additions & 1 deletion
22
...ansfer-server/src/main/java/software/amazon/transfer/server/clients/Ec2ClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
30 changes: 27 additions & 3 deletions
30
aws-transfer-user/src/main/java/software/amazon/transfer/user/clients/ClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |