Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sugmanue/sra retries merge 2.25.70 snapshot #5279

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7ef8830
New API for the retries module (#3769)
sugmanue Mar 8, 2023
f40dd27
Add default backoff strategies (#3906)
sugmanue Apr 19, 2023
a806cd7
Add standard retry strategy (#3931)
sugmanue Apr 27, 2023
dd63b90
Add adaptive retry strategy (#3975)
sugmanue May 9, 2023
1a2da50
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue May 9, 2023
c6fb01d
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue May 9, 2023
1e4dfc4
Update retries and retries-api to snapshot version: 2.20.64-SNAPSHOT
sugmanue May 9, 2023
840a2bf
Fix SonarCloud code smells (#3991)
sugmanue May 10, 2023
3b1b732
Add legacy retry strategy (#3988)
sugmanue May 24, 2023
78bd7a1
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue May 24, 2023
ac50063
Remove those tests that are now part of a different class
sugmanue May 24, 2023
46e5194
Update version after merge from master
sugmanue May 24, 2023
4fbcdb6
Refactor retry strategies (#4039)
sugmanue May 27, 2023
7511e0d
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Jun 2, 2023
c434b26
Update sdk version
sugmanue Jun 2, 2023
03817c3
Fix the retry condition to just look for the initial cause
sugmanue Jun 2, 2023
811c9b1
Add new sync and async retryable stages (#4062)
sugmanue Jun 7, 2023
79a592c
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Jun 16, 2023
5b116d2
Update sdk version
sugmanue Jun 16, 2023
43fcfef
Change uses of RetryPolicy to RetryStrategy (#4125)
sugmanue Jun 23, 2023
0a3bbfa
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Jun 28, 2023
64648eb
Update sdk version
sugmanue Jun 28, 2023
75842c1
Deprecate legacy classes and use new when possible (#4154)
sugmanue Jun 30, 2023
7b76246
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Jul 7, 2023
4acd4e3
Fix minor logging issues
sugmanue Jul 7, 2023
0d0d819
Update sdk version
sugmanue Jul 7, 2023
802ae19
Add support for retryable trait (#4170)
sugmanue Jul 18, 2023
13c32f6
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Aug 14, 2023
5aec47f
Merge master
sugmanue Sep 7, 2023
696fd16
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue Oct 9, 2023
a5202ce
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Dec 14, 2023
53fc254
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue Apr 2, 2024
17a6c57
Update to support plugins
sugmanue Apr 5, 2024
0a75aac
Add support for AWS retryable conditions
sugmanue Apr 5, 2024
c1f76d8
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue Apr 17, 2024
c21eeed
Use the correct token bucket exception cost value
sugmanue Apr 22, 2024
67b7844
Add ADAPTIVE_V2 retry mode to support the legacy behavior (#5123)
sugmanue May 1, 2024
927a900
Remove a small typo
sugmanue May 1, 2024
490b5bd
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue May 1, 2024
42a8173
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue May 8, 2024
423c351
Dumy commit
joviegas May 10, 2024
a20250b
Dummy commit to kick the internal build
sugmanue May 10, 2024
2245f8c
Rename retries-api to retries-spi
sugmanue May 10, 2024
4f55d57
Add retry packages to brazil (#5215)
sugmanue May 10, 2024
ccce8b8
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue May 15, 2024
c8ac21e
Remove type params from RetryStrategy, but keep them in RetryStrategy…
sugmanue Jun 4, 2024
3b5cdbd
External names used for retry modes only support 'adaptive' (#5265)
sugmanue Jun 5, 2024
ac0717c
Merge remote-tracking branch 'upstream/master' into feature/master/sr…
sugmanue Jun 5, 2024
5d34646
Merge remote-tracking branch 'upstream/master' into sugmanue/sra-retr…
sugmanue Jun 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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-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"
}
10 changes: 10 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.squareup.javapoet.WildcardTypeName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -437,6 +438,7 @@ private List<MethodSpec> modelClassMethods() {
methodSpecs.add(builderMethod());
methodSpecs.add(serializableBuilderClass());
methodSpecs.addAll(memberGetters());
methodSpecs.addAll(retryableOverrides());
break;
default:
methodSpecs.addAll(addModifier(memberGetters(), FINAL));
Expand Down Expand Up @@ -689,6 +691,28 @@ private CodeBlock getterStatement(MemberModel model) {
return CodeBlock.of("return $N;", modelVariable.getVariableName());
}

private List<MethodSpec> retryableOverrides() {
if (shapeModel.isRetryable()) {
MethodSpec isRetryable = MethodSpec.methodBuilder("isRetryableException")
.addAnnotation(Override.class)
.addModifiers(PUBLIC)
.returns(TypeName.BOOLEAN)
.addStatement("return true")
.build();
if (shapeModel.isThrottling()) {
MethodSpec isThrottling = MethodSpec.methodBuilder("isThrottlingException")
.addAnnotation(Override.class)
.addModifiers(PUBLIC)
.returns(TypeName.BOOLEAN)
.addStatement("return true")
.build();
return Arrays.asList(isRetryable, isThrottling);
}
return Arrays.asList(isRetryable);
}
return emptyList();
}

private List<TypeSpec> nestedModelClassTypes() {
List<TypeSpec> nestedClasses = new ArrayList<>();
switch (shapeModel.getShapeType()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.poet.model;

import static org.hamcrest.MatcherAssert.assertThat;
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import java.io.File;
import java.io.IOException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.ShapeType;
import software.amazon.awssdk.codegen.model.service.ServiceModel;
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.utils.ModelLoaderUtils;

public class RetryableExceptionClassSpecTest {
private static IntermediateModel intermediateModel;

@BeforeAll
public static void setUp() throws IOException {
File serviceModelFile =
new File(RetryableExceptionClassSpecTest.class.getResource("exceptions/service-2.json").getFile());
File customizationConfigFile = new File(RetryableExceptionClassSpecTest.class.getResource("exceptions/customization.config")
.getFile());
intermediateModel = new IntermediateModelBuilder(
C2jModels.builder()
.serviceModel(ModelLoaderUtils.loadModel(ServiceModel.class, serviceModelFile))
.customizationConfig(ModelLoaderUtils.loadModel(CustomizationConfig.class, customizationConfigFile))
.build())
.build();
}

@Test
public void serviceCodegen_withErrorsWithRetryableTrait_ShouldOverrideIsRetryableAndIsThrottling() {
intermediateModel.getShapes().forEach((name, shape) -> {
if (shape.getShapeType() == ShapeType.Exception) {
ClassSpec spec = new AwsServiceModel(intermediateModel, shape);
assertThat(spec, generatesTo( "exceptions/" + name.toLowerCase() + ".java"));
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import software.amazon.MyServiceHttpConfig;
import software.amazon.MyServiceRetryPolicy;
import software.amazon.MyServiceRetryStrategy;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.credentials.TokenUtils;
Expand Down Expand Up @@ -153,6 +154,7 @@ protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientCon
.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED, finalServiceConfig.dualstackEnabled())
.option(AwsClientOption.FIPS_ENDPOINT_ENABLED, finalServiceConfig.fipsModeEnabled())
.option(SdkClientOption.RETRY_POLICY, MyServiceRetryPolicy.resolveRetryPolicy(config))
.option(SdkClientOption.RETRY_STRATEGY, MyServiceRetryStrategy.resolveRetryStrategy(config))
.option(SdkClientOption.SERVICE_CONFIGURATION, finalServiceConfig);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import software.amazon.MyServiceHttpConfig;
import software.amazon.MyServiceRetryPolicy;
import software.amazon.MyServiceRetryStrategy;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.credentials.TokenUtils;
Expand Down Expand Up @@ -146,6 +147,7 @@ protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientCon
.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED, finalServiceConfig.dualstackEnabled())
.option(AwsClientOption.FIPS_ENDPOINT_ENABLED, finalServiceConfig.fipsModeEnabled())
.option(SdkClientOption.RETRY_POLICY, MyServiceRetryPolicy.resolveRetryPolicy(config))
.option(SdkClientOption.RETRY_STRATEGY, MyServiceRetryStrategy.resolveRetryStrategy(config))
.option(SdkClientOption.SERVICE_CONFIGURATION, finalServiceConfig);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"hasFipsProperty": true
},
"customRetryPolicy": "software.amazon.MyServiceRetryPolicy",
"customRetryStrategy": "software.amazon.MyServiceRetryStrategy",
"verifiedSimpleMethods" : ["paginatedOperationWithResultKey"],
"excludedSimpleMethods" : [
"eventStreamOperation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"hasAccelerateModeEnabledProperty":true
},
"customRetryPolicy": "software.amazon.MyServiceRetryPolicy",
"customRetryStrategy": "software.amazon.MyServiceRetryStrategy",
"verifiedSimpleMethods" : ["paginatedOperationWithResultKey"],
"excludedSimpleMethods" : [
"eventStreamOperation"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{}

Loading
Loading