-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make AWS retry policy inheritable (#1122)
- Loading branch information
Showing
7 changed files
with
86 additions
and
65 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "4cbc20ed-789f-4040-b81c-328ecd3d0700", | ||
"type": "feature", | ||
"description": "Make the AWS retry policy inheritable", | ||
"issues": [ | ||
"awslabs/aws-sdk-kotlin#1055" | ||
] | ||
} |
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
55 changes: 0 additions & 55 deletions
55
aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/retries/AwsDefaultRetryPolicy.kt
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/retries/AwsRetryPolicy.kt
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package aws.sdk.kotlin.runtime.http.retries | ||
|
||
import aws.smithy.kotlin.runtime.ServiceErrorMetadata | ||
import aws.smithy.kotlin.runtime.ServiceException | ||
import aws.smithy.kotlin.runtime.http.response.HttpResponse | ||
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective | ||
import aws.smithy.kotlin.runtime.retries.policy.RetryErrorType.* | ||
import aws.smithy.kotlin.runtime.retries.policy.StandardRetryPolicy | ||
|
||
public open class AwsRetryPolicy : StandardRetryPolicy() { | ||
public companion object { | ||
/** | ||
* The default [aws.smithy.kotlin.runtime.retries.policy.RetryPolicy] used by AWS service clients | ||
*/ | ||
public val Default: AwsRetryPolicy = AwsRetryPolicy() | ||
|
||
internal val knownErrorTypes = mapOf( | ||
"BandwidthLimitExceeded" to Throttling, | ||
"EC2ThrottledException" to Throttling, | ||
"IDPCommunicationError" to Transient, | ||
"LimitExceededException" to Throttling, | ||
"PriorRequestNotComplete" to Throttling, | ||
"ProvisionedThroughputExceededException" to Throttling, | ||
"RequestLimitExceeded" to Throttling, | ||
"RequestThrottled" to Throttling, | ||
"RequestThrottledException" to Throttling, | ||
"RequestTimeout" to Transient, | ||
"RequestTimeoutException" to Transient, | ||
"SlowDown" to Throttling, | ||
"ThrottledException" to Throttling, | ||
"Throttling" to Throttling, | ||
"ThrottlingException" to Throttling, | ||
"TooManyRequestsException" to Throttling, | ||
"TransactionInProgressException" to Throttling, | ||
) | ||
|
||
internal val knownStatusCodes = mapOf( | ||
500 to Transient, | ||
502 to Transient, | ||
503 to Transient, | ||
504 to Transient, | ||
) | ||
} | ||
|
||
override fun evaluateSpecificExceptions(ex: Throwable): RetryDirective? = when (ex) { | ||
is ServiceException -> evaluateServiceException(ex) | ||
else -> null | ||
} | ||
|
||
private fun evaluateServiceException(ex: ServiceException): RetryDirective? = with(ex.sdkErrorMetadata) { | ||
(knownErrorTypes[errorCode] ?: knownStatusCodes[statusCode]) | ||
?.let { RetryDirective.RetryError(it) } | ||
} | ||
|
||
private val ServiceErrorMetadata.statusCode: Int? | ||
get() = (protocolResponse as? HttpResponse)?.status?.value | ||
} |
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
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
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