Skip to content

Commit d01128a

Browse files
authored
refactor!: enable waiters
* refactor!: update retry namespaces (#504) * refactor: move request ID and error code metadata to smithy-kotlin (#515) * fix: update incorrect RequestId error metadata usage in S3 (#518) * tickle ci
1 parent fbb9e45 commit d01128a

File tree

8 files changed

+31
-35
lines changed

8 files changed

+31
-35
lines changed

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import aws.smithy.kotlin.runtime.http.operation.*
2121
import aws.smithy.kotlin.runtime.http.response.HttpResponse
2222
import aws.smithy.kotlin.runtime.io.Closeable
2323
import aws.smithy.kotlin.runtime.io.middleware.Phase
24-
import aws.smithy.kotlin.runtime.retries.impl.*
24+
import aws.smithy.kotlin.runtime.retries.StandardRetryStrategy
25+
import aws.smithy.kotlin.runtime.retries.StandardRetryStrategyOptions
26+
import aws.smithy.kotlin.runtime.retries.delay.ExponentialBackoffWithJitter
27+
import aws.smithy.kotlin.runtime.retries.delay.ExponentialBackoffWithJitterOptions
28+
import aws.smithy.kotlin.runtime.retries.delay.StandardRetryTokenBucket
29+
import aws.smithy.kotlin.runtime.retries.delay.StandardRetryTokenBucketOptions
2530
import aws.smithy.kotlin.runtime.time.Clock
2631
import aws.smithy.kotlin.runtime.util.Platform
2732
import aws.smithy.kotlin.runtime.util.PlatformProvider

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsRetryPolicy.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ package aws.sdk.kotlin.runtime.config.imds
88
import aws.smithy.kotlin.runtime.http.HttpStatusCode
99
import aws.smithy.kotlin.runtime.http.category
1010
import aws.smithy.kotlin.runtime.logging.Logger
11-
import aws.smithy.kotlin.runtime.retries.RetryDirective
12-
import aws.smithy.kotlin.runtime.retries.RetryErrorType
13-
import aws.smithy.kotlin.runtime.retries.RetryPolicy
11+
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective
12+
import aws.smithy.kotlin.runtime.retries.policy.RetryErrorType
13+
import aws.smithy.kotlin.runtime.retries.policy.RetryPolicy
1414

1515
internal class ImdsRetryPolicy : RetryPolicy<Any?> {
1616
override fun evaluate(result: Result<Any?>): RetryDirective = when {

aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/Exceptions.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,15 @@ import aws.smithy.kotlin.runtime.ServiceException as SmithyServiceException
1111

1212
public open class AwsErrorMetadata : ServiceErrorMetadata() {
1313
public companion object {
14-
public val ErrorCode: AttributeKey<String> = AttributeKey("AwsErrorCode")
1514
public val ErrorMessage: AttributeKey<String> = AttributeKey("AwsErrorMessage")
16-
public val RequestId: AttributeKey<String> = AttributeKey("AwsRequestId")
1715
}
1816

19-
/**
20-
* Returns the error code associated with the response
21-
*/
22-
public val errorCode: String?
23-
get() = attributes.getOrNull(ErrorCode)
24-
2517
/**
2618
* Returns the human readable error message. For errors with a `message` field as part of the model
2719
* this will match the `message` property of the exception.
2820
*/
2921
public val errorMessage: String?
3022
get() = attributes.getOrNull(ErrorMessage)
31-
32-
/**
33-
* The request ID that was returned by the called service
34-
*/
35-
public val requestId: String?
36-
get() = attributes.getOrNull(RequestId)
3723
}
3824

3925
/**

aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/ProtocolErrors.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public data class ErrorDetails(
4545
@InternalSdkApi
4646
public fun setAseErrorMetadata(exception: Any, response: HttpResponse, errorDetails: AwsErrorDetails?) {
4747
if (exception is AwsServiceException) {
48-
exception.sdkErrorMetadata.attributes.setIfValueNotNull(AwsErrorMetadata.ErrorCode, errorDetails?.code)
48+
exception.sdkErrorMetadata.attributes.setIfValueNotNull(ServiceErrorMetadata.ErrorCode, errorDetails?.code)
4949
exception.sdkErrorMetadata.attributes.setIfValueNotNull(AwsErrorMetadata.ErrorMessage, errorDetails?.message)
50-
exception.sdkErrorMetadata.attributes.setIfValueNotNull(AwsErrorMetadata.RequestId, response.headers[X_AMZN_REQUEST_ID_HEADER])
50+
exception.sdkErrorMetadata.attributes.setIfValueNotNull(ServiceErrorMetadata.RequestId, response.headers[X_AMZN_REQUEST_ID_HEADER])
5151
exception.sdkErrorMetadata.attributes[ServiceErrorMetadata.ProtocolResponse] = response
5252
}
5353
}

aws-runtime/aws-http/common/src/aws/sdk/kotlin/runtime/http/retries/AwsDefaultRetryPolicy.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
package aws.sdk.kotlin.runtime.http.retries
77

8-
import aws.sdk.kotlin.runtime.AwsServiceException
98
import aws.smithy.kotlin.runtime.ServiceErrorMetadata
9+
import aws.smithy.kotlin.runtime.ServiceException
1010
import aws.smithy.kotlin.runtime.http.response.HttpResponse
11-
import aws.smithy.kotlin.runtime.retries.RetryDirective
12-
import aws.smithy.kotlin.runtime.retries.RetryErrorType.*
13-
import aws.smithy.kotlin.runtime.retries.impl.StandardRetryPolicy
11+
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective
12+
import aws.smithy.kotlin.runtime.retries.policy.RetryErrorType.*
13+
import aws.smithy.kotlin.runtime.retries.policy.StandardRetryPolicy
1414

1515
public object AwsDefaultRetryPolicy : StandardRetryPolicy() {
1616
internal val knownErrorTypes = mapOf(
@@ -40,12 +40,12 @@ public object AwsDefaultRetryPolicy : StandardRetryPolicy() {
4040
504 to Timeout,
4141
)
4242

43-
override fun evaluateOtherExceptions(ex: Throwable): RetryDirective? = when (ex) {
44-
is AwsServiceException -> evaluateAwsServiceException(ex)
43+
override fun evaluateSpecificExceptions(ex: Throwable): RetryDirective? = when (ex) {
44+
is ServiceException -> evaluateServiceException(ex)
4545
else -> null
4646
}
4747

48-
private fun evaluateAwsServiceException(ex: AwsServiceException): RetryDirective? = with(ex.sdkErrorMetadata) {
48+
private fun evaluateServiceException(ex: ServiceException): RetryDirective? = with(ex.sdkErrorMetadata) {
4949
(knownErrorTypes[errorCode] ?: knownStatusCodes[statusCode])
5050
?.let { RetryDirective.RetryError(it) }
5151
}

aws-runtime/aws-http/common/test/aws/sdk/kotlin/runtime/http/retries/AwsDefaultRetryPolicyTest.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package aws.sdk.kotlin.runtime.http.retries
22

3-
import aws.sdk.kotlin.runtime.AwsErrorMetadata
4-
import aws.sdk.kotlin.runtime.AwsServiceException
3+
import aws.smithy.kotlin.runtime.ErrorMetadata
54
import aws.smithy.kotlin.runtime.ServiceErrorMetadata
5+
import aws.smithy.kotlin.runtime.ServiceException
66
import aws.smithy.kotlin.runtime.http.Headers
77
import aws.smithy.kotlin.runtime.http.HttpBody
88
import aws.smithy.kotlin.runtime.http.HttpStatusCode
99
import aws.smithy.kotlin.runtime.http.response.HttpResponse
10-
import aws.smithy.kotlin.runtime.retries.RetryDirective
10+
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective
1111
import kotlin.test.Test
1212
import kotlin.test.assertEquals
1313

1414
class AwsDefaultRetryPolicyTest {
1515
@Test
1616
fun testErrorsByErrorCode() {
1717
AwsDefaultRetryPolicy.knownErrorTypes.forEach { (errorCode, errorType) ->
18-
val ex = AwsServiceException()
19-
ex.sdkErrorMetadata.attributes[AwsErrorMetadata.ErrorCode] = errorCode
18+
val ex = ServiceException()
19+
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ErrorType] = ServiceException.ErrorType.Server
20+
ex.sdkErrorMetadata.attributes[ErrorMetadata.Retryable] = true
21+
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ErrorCode] = errorCode
2022
val result = AwsDefaultRetryPolicy.evaluate(Result.failure(ex))
2123
assertEquals(RetryDirective.RetryError(errorType), result)
2224
}
@@ -27,7 +29,9 @@ class AwsDefaultRetryPolicyTest {
2729
AwsDefaultRetryPolicy.knownStatusCodes.forEach { (statusCode, errorType) ->
2830
val modeledStatusCode = HttpStatusCode.fromValue(statusCode)
2931
val response = HttpResponse(modeledStatusCode, Headers.Empty, HttpBody.Empty)
30-
val ex = AwsServiceException()
32+
val ex = ServiceException()
33+
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ErrorType] = ServiceException.ErrorType.Server
34+
ex.sdkErrorMetadata.attributes[ErrorMetadata.Retryable] = true
3135
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ProtocolResponse] = response
3236
val result = AwsDefaultRetryPolicy.evaluate(Result.failure(ex))
3337
assertEquals(RetryDirective.RetryError(errorType), result)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sdkVersion=0.11.1-SNAPSHOT
1212
smithyVersion=1.13.1
1313
smithyGradleVersion=0.5.3
1414
# smithy-kotlin codegen and runtime are versioned together
15-
smithyKotlinVersion=0.7.6
15+
smithyKotlinVersion=0.7.7-SNAPSHOT
1616

1717
# kotlin
1818
kotlinVersion=1.6.10

services/s3/common/src/aws/sdk/kotlin/services/s3/internal/S3ErrorMetadata.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import aws.sdk.kotlin.runtime.*
88
import aws.sdk.kotlin.runtime.http.*
99
import aws.sdk.kotlin.services.s3.model.S3ErrorMetadata
1010
import aws.sdk.kotlin.services.s3.model.S3Exception
11+
import aws.smithy.kotlin.runtime.ServiceErrorMetadata
1112
import aws.smithy.kotlin.runtime.http.response.HttpResponse
1213
import aws.smithy.kotlin.runtime.serde.*
1314
import aws.smithy.kotlin.runtime.serde.xml.XmlDeserializer
@@ -33,7 +34,7 @@ internal data class S3ErrorDetails(
3334
internal fun setS3ErrorMetadata(exception: Any, response: HttpResponse, errorDetails: S3ErrorDetails?) {
3435
setAseErrorMetadata(exception, response, errorDetails)
3536
if (exception is AwsServiceException) {
36-
exception.sdkErrorMetadata.attributes.setIfValueNotNull(AwsErrorMetadata.RequestId, errorDetails?.requestId)
37+
exception.sdkErrorMetadata.attributes.setIfValueNotNull(ServiceErrorMetadata.RequestId, errorDetails?.requestId)
3738
}
3839
if (exception is S3Exception) {
3940
val requestId2 = errorDetails?.requestId2 ?: response.headers[X_AMZN_REQUEST_ID_2_HEADER]

0 commit comments

Comments
 (0)