Skip to content

URI cache for DynamoDB account id based endpoint #6087

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0b0126e
URI cache for dynamodb account-id based endpoints
L-Applin Apr 25, 2025
d693427
revised isAccountIdUri logic, added unit tests
L-Applin May 5, 2025
6893598
changelog
L-Applin May 5, 2025
7a718b8
Merge branch 'master' into feature/master/endpoint-id-cache
L-Applin May 5, 2025
d589a2b
java doc, logs
L-Applin May 5, 2025
d470d04
Merge remote-tracking branch 'origin/feature/master/endpoint-id-cache…
L-Applin May 5, 2025
a31c1e0
fix spotbugs and checkstyle
L-Applin May 6, 2025
c5a320e
fix exception thrown for malformed URI with newURI method
L-Applin May 6, 2025
1de5e42
Merge branch 'master' into feature/master/endpoint-id-cache
L-Applin May 6, 2025
331dec9
rename to SdkUri for checkstyle rules
L-Applin May 6, 2025
7c5926f
Merge remote-tracking branch 'origin/feature/master/endpoint-id-cache…
L-Applin May 6, 2025
5db3da6
Pr comments:
L-Applin May 7, 2025
dab0b83
Merge branch 'master' into feature/master/endpoint-id-cache
L-Applin May 7, 2025
254be85
use Lazy class for lazy initialization of singleton instance
L-Applin May 7, 2025
cb5f15d
Merge remote-tracking branch 'origin/feature/master/endpoint-id-cache…
L-Applin May 7, 2025
f4691f3
checkstyle
L-Applin May 7, 2025
c8d628c
checkstyle
L-Applin May 7, 2025
e79e164
Merge branch 'master' into feature/master/endpoint-id-cache
L-Applin May 7, 2025
a8181f1
checkstyle
L-Applin May 7, 2025
019c2de
changelog: category DynamoDB
L-Applin May 8, 2025
57ecb83
MAX_INT_DIGITS_BASE_10 as constant
L-Applin May 9, 2025
2c394e0
Merge branch 'master' into feature/master/endpoint-id-cache
L-Applin May 9, 2025
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
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-b405876.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "Amazon DyanmoDB",
"contributor": "",
"description": "Enable caching calls to URI constructors for account-id based endpoints"
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,8 @@
<Class name="software.amazon.awssdk.v2migration.EnumCasingToV2$Visitor"/>
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"/>
</Match>
<Match>
<Class name="software.amazon.awssdk.utils.uri.SdkUri" />
<Bug pattern="BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ public class CustomizationConfig {
*/
private boolean enableFastUnmarshaller;

/**
* A boolean flag to indicate if the code-generated endpoint providers class should cache the calls to URI constructors.
*/
private boolean enableEndpointProviderUriCaching;

private CustomizationConfig() {
}

Expand Down Expand Up @@ -924,4 +929,12 @@ public boolean getEnableFastUnmarshaller() {
public void setEnableFastUnmarshaller(boolean enableFastUnmarshaller) {
this.enableFastUnmarshaller = enableFastUnmarshaller;
}

public boolean getEnableEndpointProviderUriCaching() {
return enableEndpointProviderUriCaching;
}

public void setEnableEndpointProviderUriCaching(boolean enableEndpointProviderUriCaching) {
this.enableEndpointProviderUriCaching = enableEndpointProviderUriCaching;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme;
import software.amazon.awssdk.codegen.model.config.customization.KeyTypePair;
import software.amazon.awssdk.endpoints.Endpoint;
import software.amazon.awssdk.utils.uri.SdkUri;

public class CodeGeneratorVisitor extends WalkRuleExpressionVisitor {
private final CodeBlock.Builder builder;
private final RuleRuntimeTypeMirror typeMirror;
private final SymbolTable symbolTable;
private final Map<String, KeyTypePair> knownEndpointAttributes;
private final boolean endpointCaching;

public CodeGeneratorVisitor(RuleRuntimeTypeMirror typeMirror,
SymbolTable symbolTable,
Map<String, KeyTypePair> knownEndpointAttributes,
CodeBlock.Builder builder) {
CodeBlock.Builder builder,
boolean endpointCaching) {
this.builder = builder;
this.symbolTable = symbolTable;
this.knownEndpointAttributes = knownEndpointAttributes;
this.typeMirror = typeMirror;
this.endpointCaching = endpointCaching;
}

@Override
Expand Down Expand Up @@ -274,7 +278,11 @@ private void codegenTreeBody(RuleSetExpression expr) {
@Override
public Void visitEndpointExpression(EndpointExpression e) {
builder.add("return $T.endpoint(", typeMirror.rulesResult().type());
builder.add("$T.builder().url($T.create(", Endpoint.class, URI.class);
if (endpointCaching) {
builder.add("$T.builder().url($T.getInstance().create(", Endpoint.class, SdkUri.class);
} else {
builder.add("$T.builder().url($T.create(", Endpoint.class, URI.class);
}
e.url().accept(this);
builder.add("))");
e.headers().accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ private MethodSpec.Builder methodBuilderForRule(RuleSetExpression expr) {
}

private void codegenExpr(RuleExpression expr, CodeBlock.Builder builder) {
boolean useEndpointCaching = intermediateModel.getCustomizationConfig().getEnableEndpointProviderUriCaching();
CodeGeneratorVisitor visitor = new CodeGeneratorVisitor(typeMirror,
utils.symbolTable(),
knownEndpointAttributes,
builder);
builder,
useEndpointCaching);
expr.accept(visitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ public static IntermediateModel queryServiceModelsWithOverrideKnowProperties() {
return new IntermediateModelBuilder(models).build();
}

public static IntermediateModel queryServiceModelsWithUriCache() {
File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/query/service-2.json").getFile());
File customizationModel =
new File(ClientTestModels.class.getResource("client/c2j/query/customization-uri-cache.config").getFile());
File waitersModel = new File(ClientTestModels.class.getResource("client/c2j/query/waiters-2.json").getFile());
File endpointRuleSetModel =
new File(ClientTestModels.class.getResource("client/c2j/query/endpoint-rule-set.json").getFile());
File endpointTestsModel =
new File(ClientTestModels.class.getResource("client/c2j/query/endpoint-tests.json").getFile());

C2jModels models = C2jModels
.builder()
.serviceModel(getServiceModel(serviceModel))
.customizationConfig(getCustomizationConfig(customizationModel))
.waitersModel(getWaiters(waitersModel))
.endpointRuleSetModel(getEndpointRuleSet(endpointRuleSetModel))
.endpointTestSuiteModel(getEndpointTestSuite(endpointTestsModel))
.build();

return new IntermediateModelBuilder(models).build();
}

public static IntermediateModel queryServiceModelsEndpointAuthParamsWithAllowList() {
File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/query/service-2.json").getFile());
File customizationModel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ void knowPropertiesOverride() {
new EndpointProviderSpec2(ClientTestModels.queryServiceModelsWithOverrideKnowProperties());
assertThat(endpointProviderSpec, generatesTo("endpoint-provider-know-prop-override-class.java"));
}

@Test
void endpointProviderClassWithUriCache() {
ClassSpec endpointProviderSpec =
new EndpointProviderSpec2(ClientTestModels.queryServiceModelsWithUriCache());
assertThat(endpointProviderSpec, generatesTo("endpoint-provider-uri-cache-class.java"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"authPolicyActions" : {
"skip" : true
},
"skipEndpointTests": {
"test case 4": "Does not work"
},
"endpointParameters": {
"CustomEndpointArray": {
"required": false,
"documentation": "Parameter from the customization config",
"type": "StringArray"
},
"ArnList": {
"required": false,
"documentation": "Parameter from the customization config",
"type": "StringArray"
}
},
"customOperationContextParams": [
{
"operationName": "OperationWithCustomizedOperationContextParam",
"operationContextParamsMap": {
"customEndpointArray": {
"path": "ListMember.StringList[*].LeafString"
}
}
}
],
"preClientExecutionRequestCustomizer": {
"OperationWithCustomMember": {
"methodName": "dummyRequestModifier",
"className": "software.amazon.awssdk.codegen.internal.UtilsTest"
}
},
"enableEndpointProviderUriCaching": true
}
Loading
Loading