Skip to content

Commit

Permalink
Merge retries (#5283)
Browse files Browse the repository at this point in the history
* New API for the retries module (#3769)

This new module includes the interfaces and classes that will be used
to implement the new retry logic within the SDK.

* Add default backoff strategies (#3906)

* Add default backoff strategies

* Moved the backoff strategires to the SPI package

* Use AssertJ instead of Hamcrest

* Add standard retry strategy (#3931)

* Add standard retry strategy

* Fix the AcquireInitialTokenRequestImpl API annotation

Also add the package to the test/tests-coverage-reporting/pom.xml to get coverage reporting

* Add adaptive retry strategy (#3975)

* Add adaptive retry strategy

* Address pull request comments

* Address PR comments

* Address PR comments

* Update retries and retries-api to snapshot version: 2.20.64-SNAPSHOT

* Fix SonarCloud code smells (#3991)

* Fix SonarCloud code smells

* Move AdaptiveRetryStrategyResourceConstrainedTest to an integration test

This change is to workaround the SonarCloud code smell of the Sleep usage in this test

* Add legacy retry strategy (#3988)

* Add legacy retry strategy

* Remove public modifiers from test classes to make SonarCloud happy

* Fix another SonarCloud code smell

* WIP

* Address PR comments

* Rename all the strategies to use Default prefix instead of Impl suffix

* Address PR comments

* Remove those tests that are now part of a different class

* Update version after merge from master

* Refactor retry strategies (#4039)

* Refactor the retry strategies

This change uses a single class to implement the core logic of all the
retries strategies and adds extension points to tailor the behavior
when needed.

* Rename to BaseRetryStrategy and make it abstract

* Remove previous implementations and rename the new ones

* Update sdk version

* Fix the retry condition to just look for the initial cause

* Add new sync and async retryable stages (#4062)

* Add new sync and async retryable stages

* Address PR comments

* Update sdk version

* Change uses of RetryPolicy to RetryStrategy (#4125)

* Update sdk version

* Deprecate legacy classes and use new when possible (#4154)

* Deprecate legacy classes and use new when possible

* Fix checkstyle and add some more validation

* Add missing @deprecated annotation

* Add missing dependency to the retries-api module

* Fix minor logging issues

* Update sdk version

* Add support for retryable trait (#4170)

* Merge master

* Update to support plugins

* Add support for AWS retryable conditions

* Use the correct token bucket exception cost value

* Add ADAPTIVE_V2 retry mode to support the legacy behavior (#5123)

* Add a new ADAPTIVE2 mode to support the legacy behavior

* Fix dynamodb test to use adaptive2 mode

* Fixes and tests for the expected behaviors

* Rename the new adaptive mode to ADAPTIVE_V2

* More fixes related to the rename from adaptive2 to adaptive_v2

* Fix dynamodb retry resolver logic for adaptive mode

* Properly clean up the test state

* Address PR comments

* Remove a small typo

* Dumy commit

* Dummy commit to kick the internal build

* Rename retries-api to retries-spi

* Add retry packages to brazil (#5215)

* Add retry packages to brazil

* Update pom's as per the new module checklist

* Remove type params from RetryStrategy, but keep them in RetryStrategy… (#5262)

* Remove type params from RetryStrategy, but keep them in RetryStrategy.Builder

* Rename from `none` to `doNotRetry` to clarify the behavior

* External names used for retry modes only support 'adaptive' (#5265)

* Externally named retry modes only support 'adaptive'

Behind the scenes this will be mapped to RetryMode.ADAPTIVE_V2 which
makes it a non-backwards compatible behavioral change.

* Sneak in a fix from the previous PR

* Fix a test that expects adaptive to map to `RetryMode.ADAPTIVE`

* Fix typos in the comments

* Retries release (#5280)

* Bump version to 2.26.0-SNAPSHOT

* Add retry release changlog entry

* Add missing deprecation annotation and javadoc tag

* Archive the last changelog from the 2.25 series

---------

Co-authored-by: John Viegas <70235430+joviegas@users.noreply.github.com>
  • Loading branch information
sugmanue and joviegas committed Jun 11, 2024
1 parent bef4dd8 commit b8f136c
Show file tree
Hide file tree
Showing 692 changed files with 9,181 additions and 737 deletions.
2 changes: 2 additions & 0 deletions .brazil.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"http-auth-aws": { "packageName": "AwsJavaSdk-Core-HttpAuthAws" },
"http-auth-aws-crt": { "packageName": "AwsJavaSdk-Core-HttpAuthAwsCrt" },
"http-auth-aws-eventstream": { "packageName": "AwsJavaSdk-Core-HttpAuthAwsEventStream" },
"retries-spi": { "packageName": "AwsJavaSdk-Core-RetriesSpi" },
"retries": { "packageName": "AwsJavaSdk-Core-Retries" },

"dynamodb": { "packageName": "AwsJavaSdk-DynamoDb" },
"waf": { "packageName": "AwsJavaSdk-Waf" },
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-85d899c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Fixed an issue in async client where the future would get stuck if there is a server error and the server fails to return response body that matches with the content length specified in the response header. See [#4354](https://github.com/aws/aws-sdk-java-v2/issues/4354)"
}
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-05480c7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "\"AWS SDK for Java v2\"",
"contributor": "sugmanue",
"type": "feature",
"description": "This release contains a major internal refactor of retries and is part\nof moving the SDK to a standardized AWS SDK architecture. It\nintroduces the interface `RetryStrategy` and three subclasses\n`StandardRetryStrategy`, `LegacyRetryStrategy` , and\n`AdaptiveRetryStrategy`. The new interfaces live in the `retry-spi`\nmodule, and the implementation classes live in the `retries` module.\n\nNote 1) This change marks RetryPolicy as as deprecated and we\nencourage users to migrate to its replacement, RetryStrategy. However,\nretry policies are, and will for the foreseeable future be fully\nsupported. Clients configured to use retry policies will not need any\ncode changes and won\u2019t see any behavioral change with this release.\n\nNote 2) The original implementation of adaptive mode (see\n[#2658](https://github.com/aws/aws-sdk-java-v2/pull/2658)) that was\nreleased with the retry policy API contains a bug in its rate-limiter\nlogic which prevents it from remembering state across requests. In\nthis release of the retry strategy API, we introduce\n`RetryMode.ADAPTIVE_V2`, which implements the correct adaptive\nbehavior. `RetryMode.ADAPTIVE` is still present in order to maintain\nbackwards compatibility, but is now marked as deprecated.\n\nNote 3) When configuring retry mode through system settings or\nenvironment variables, users can only choose adaptive mode. This\nsetting will map to `RetryMode.ADAPTIVE_V2` instead of\n`RetryMode.ADAPTIVE` with this release, giving users the correct\nbehavior and still keeping the settings consistent across all\nSDKs. The list of configuration options are: profile file `retry_mode`\nsetting, the `aws.retryMode` system property and the `AWS_RETRY_MODE`\nenvironment variable."
}
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-b456b1c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "sugmanue",
"type": "feature",
"description": "Adds the new module retries API module"
}
2 changes: 1 addition & 1 deletion archetypes/archetype-app-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>archetypes</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion archetypes/archetype-lambda/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>archetypes</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>archetype-lambda</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion archetypes/archetype-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>archetypes</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion archetypes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>aws-sdk-java-pom</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>archetypes</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>aws-sdk-java</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>aws-sdk-java-pom</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
12 changes: 11 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>bom</artifactId>
Expand Down Expand Up @@ -172,6 +172,16 @@
<artifactId>http-client-spi</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>retries</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>retries-spi</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ public void visit(Method method) {
}
} else if (isBuildable && method.getName().equals("toBuilder") && method.getSignature().startsWith("()")) {
// This is a buildable toBuilder
constructorsInvokedFromToBuilder.computeIfAbsent(getDottedClassName(), n -> new HashMap<>());
toBuilderModifiedFields.computeIfAbsent(getDottedClassName(), n -> new HashMap<>());
String dottedClassName = getDottedClassName();
constructorsInvokedFromToBuilder.computeIfAbsent(dottedClassName, n -> new HashMap<>());
toBuilderModifiedFields.computeIfAbsent(dottedClassName, n -> new HashMap<>());
inBuildableToBuilder = true;
inBuilderConstructor = false;

if (method.isAbstract()) {
// Ignore abstract toBuilder methods, we will still validate the actual implementations.
ignoredBuildables.add(dottedClassName);
}
registerIgnoredFields();
} else {
inBuildableToBuilder = false;
Expand Down
2 changes: 1 addition & 1 deletion bundle-logging-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<artifactId>bundle-logging-bridge</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion bundle-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<artifactId>bundle-sdk</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<artifactId>bundle</artifactId>
<packaging>jar</packaging>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion codegen-lite-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>codegen-lite-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion codegen-lite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<artifactId>codegen-lite</artifactId>
<name>AWS Java SDK :: Code Generator Lite</name>
Expand Down
2 changes: 1 addition & 1 deletion codegen-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>codegen-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java-pom</artifactId>
<version>2.25.71-SNAPSHOT</version>
<version>2.26.0-SNAPSHOT</version>
</parent>
<artifactId>codegen</artifactId>
<name>AWS Java SDK :: Code Generator</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ private Map<String, ShapeModel> constructExceptionShapes() {
// Java shape models, to be constructed
Map<String, ShapeModel> javaShapes = new HashMap<>();

for (Map.Entry<String, Shape> shape : getServiceModel().getShapes().entrySet()) {
if (shape.getValue().isException()) {
String errorShapeName = shape.getKey();
for (Map.Entry<String, Shape> kvp : getServiceModel().getShapes().entrySet()) {
if (kvp.getValue().isException()) {
Shape shape = kvp.getValue();
String errorShapeName = kvp.getKey();
String javaClassName = getNamingStrategy().getExceptionName(errorShapeName);

ShapeModel exceptionShapeModel = generateShapeModel(javaClassName,
Expand All @@ -55,8 +56,10 @@ private Map<String, ShapeModel> constructExceptionShapes() {
exceptionShapeModel.setType(ShapeType.Exception.getValue());
exceptionShapeModel.setErrorCode(getErrorCode(errorShapeName));
exceptionShapeModel.setHttpStatusCode(getHttpStatusCode(errorShapeName));
exceptionShapeModel.withIsRetryable(shape.isRetryable());
exceptionShapeModel.withIsThrottling(shape.isThrottling());
if (exceptionShapeModel.getDocumentation() == null) {
exceptionShapeModel.setDocumentation(shape.getValue().getDocumentation());
exceptionShapeModel.setDocumentation(shape.getDocumentation());
}

javaShapes.put(javaClassName, exceptionShapeModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ protected final ShapeModel generateShapeModel(String javaClassName, String shape
shapeModel.withXmlNamespace(shape.getXmlNamespace());
shapeModel.withIsUnion(shape.isUnion());
shapeModel.withIsFault(shape.isFault());
shapeModel.withIsRetryable(shape.isRetryable());
shapeModel.withIsThrottling(shape.isThrottling());

boolean hasHeaderMember = false;
boolean hasStatusCodeMember = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public class CustomizationConfig {
*/
private String customRetryPolicy;

/**
* Custom Retry strategy
*/
private String customRetryStrategy;

private boolean skipSyncClientGeneration;

/**
Expand Down Expand Up @@ -533,10 +538,18 @@ public String getCustomRetryPolicy() {
return customRetryPolicy;
}

public String getCustomRetryStrategy() {
return customRetryStrategy;
}

public void setCustomRetryPolicy(String customRetryPolicy) {
this.customRetryPolicy = customRetryPolicy;
}

public void setCustomRetryStrategy(String customRetryStrategy) {
this.customRetryStrategy = customRetryStrategy;
}

public boolean isSkipSyncClientGeneration() {
return skipSyncClientGeneration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public String getCustomRetryPolicy() {
return customizationConfig.getCustomRetryPolicy();
}

public String getCustomRetryStrategy() {
return customizationConfig.getCustomRetryStrategy();
}

public String getSdkModeledExceptionBaseFqcn() {
return String.format("%s.%s",
metadata.getFullModelPackageName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public class ShapeModel extends DocumentationModel implements HasDeprecation {

private boolean union;

private boolean retryable;
private boolean throttling;

public ShapeModel() {
}

Expand Down Expand Up @@ -648,4 +651,22 @@ public ShapeModel withIsFault(boolean fault) {
this.fault = fault;
return this;
}

public boolean isRetryable() {
return retryable;
}

public ShapeModel withIsRetryable(boolean retryable) {
this.retryable = retryable;
return this;
}

public boolean isThrottling() {
return throttling;
}

public ShapeModel withIsThrottling(boolean throttling) {
this.throttling = throttling;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.model.service;

public class RetryableTrait {

private Boolean throttling;

public void setThrottling(boolean throttling) {
this.throttling = throttling;
}

public Boolean getThrottling() {
return throttling;
}

public boolean isThrottling() {
return Boolean.TRUE.equals(throttling);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class Shape {

private boolean union;

private RetryableTrait retryable;

public boolean isFault() {
return fault;
}
Expand Down Expand Up @@ -345,4 +347,16 @@ public boolean isUnion() {
public void setUnion(boolean union) {
this.union = union;
}

public void setRetryable(RetryableTrait retryable) {
this.retryable = retryable;
}

public boolean isRetryable() {
return retryable != null;
}

public boolean isThrottling() {
return retryable != null && retryable.isThrottling();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ private MethodSpec finalizeServiceConfigurationMethod() {
PoetUtils.classNameFromFqcn(model.getCustomizationConfig().getCustomRetryPolicy()));
}

if (StringUtils.isNotBlank(model.getCustomizationConfig().getCustomRetryStrategy())) {
builder.addCode(".option($1T.RETRY_STRATEGY, $2T.resolveRetryStrategy(config))",
SdkClientOption.class,
PoetUtils.classNameFromFqcn(model.getCustomizationConfig().getCustomRetryStrategy()));
}

if (StringUtils.isNotBlank(clientConfigClassName)) {
builder.addCode(".option($T.SERVICE_CONFIGURATION, finalServiceConfig)", SdkClientOption.class);
}
Expand Down
Loading

0 comments on commit b8f136c

Please sign in to comment.