|
2 | 2 |
|
3 | 3 | import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
|
4 | 4 | import software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting;
|
| 5 | +import software.amazon.awssdk.core.exception.AbortedException; |
| 6 | +import software.amazon.awssdk.core.exception.SdkClientException; |
5 | 7 | import software.amazon.awssdk.core.retry.RetryPolicy;
|
6 | 8 | import software.amazon.awssdk.core.retry.backoff.BackoffStrategy;
|
7 | 9 | import software.amazon.awssdk.core.retry.backoff.EqualJitterBackoffStrategy;
|
| 10 | +import software.amazon.awssdk.core.retry.conditions.OrRetryCondition; |
| 11 | +import software.amazon.awssdk.core.retry.conditions.RetryCondition; |
8 | 12 | import software.amazon.awssdk.http.SdkHttpClient;
|
9 | 13 | import software.amazon.awssdk.http.apache.ApacheHttpClient;
|
10 | 14 | import software.amazon.awssdk.services.codeguruprofiler.CodeGuruProfilerClient;
|
@@ -70,23 +74,41 @@ private static RetryPolicy getRetryPolicy() {
|
70 | 74 | .backoffStrategy(failureBackoffStrategy)
|
71 | 75 | .throttlingBackoffStrategy(throttlingBackoffStrategy)
|
72 | 76 | .numRetries(MAX_ERROR_RETRY) // We can be a bit slower in CloudFormation for the sake of not failing the deployment!
|
| 77 | + .retryCondition(getRetryCondition()) |
73 | 78 | .build();
|
74 | 79 | }
|
75 | 80 |
|
| 81 | + private static RetryCondition getRetryCondition() { |
| 82 | + return OrRetryCondition.create( |
| 83 | + RetryCondition.defaultRetryCondition(), // Pull in SDK defaults |
| 84 | + retryAbortedExceptionCondition() // https://github.com/aws/aws-sdk-java-v2/issues/1684 |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + private static RetryCondition retryAbortedExceptionCondition() { |
| 89 | + return c -> c.exception().getClass().equals(SdkClientException.class) && |
| 90 | + c.exception().getCause() != null && |
| 91 | + c.exception().getCause().getClass().equals(AbortedException.class); |
| 92 | + } |
| 93 | + |
76 | 94 | private static SdkHttpClient getHttpClient() {
|
77 | 95 | return ApacheHttpClient.builder()
|
78 | 96 | .connectionTimeout(CONNECTION_TIMEOUT)
|
79 | 97 | .socketTimeout(SOCKET_TIMEOUT)
|
80 | 98 | .build();
|
81 | 99 | }
|
82 | 100 |
|
| 101 | + public static ClientOverrideConfiguration getClientConfiguration() { |
| 102 | + return ClientOverrideConfiguration.builder() |
| 103 | + .retryPolicy(getRetryPolicy()) |
| 104 | + .apiCallTimeout(OVERALL_TIMEOUT) |
| 105 | + .apiCallAttemptTimeout(ATTEMPT_TIMEOUT) |
| 106 | + .build(); |
| 107 | + } |
| 108 | + |
83 | 109 | public static CodeGuruProfilerClient create() {
|
84 | 110 | return CodeGuruProfilerClient.builder()
|
85 |
| - .overrideConfiguration(ClientOverrideConfiguration.builder() |
86 |
| - .retryPolicy(getRetryPolicy()) |
87 |
| - .apiCallTimeout(OVERALL_TIMEOUT) |
88 |
| - .apiCallAttemptTimeout(ATTEMPT_TIMEOUT) |
89 |
| - .build()) |
| 111 | + .overrideConfiguration(getClientConfiguration()) |
90 | 112 | .httpClient(getHttpClient())
|
91 | 113 | .build();
|
92 | 114 | }
|
|
0 commit comments