Skip to content

Commit 054c188

Browse files
committed
Default endpointDiscovery to true for services that require it. Deprecate enableEndpointDiscovery in client builder. Add endpointDiscoveryEnabled to client builder.
1 parent b2b805f commit 054c188

File tree

15 files changed

+253
-16
lines changed

15 files changed

+253
-16
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"description": "Endpoint discovery is now enabled by default for future services that will require it. A new method 'endpointDiscoveryEnabled' has been added to client builders that support endpoint discovery allowing a true or false value to be set. 'enableEndpointDiscovery' has been deprecated on the client builders as it is now superseded by 'endpointDiscoveryEnabled'."
5+
}

codegen/src/main/java/software/amazon/awssdk/codegen/IntermediateModelBuilder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ public IntermediateModel build() {
107107
new HashMap<>(new AddCustomAuthorizers(this.service, getNamingStrategy()).constructAuthorizers());
108108

109109
OperationModel endpointOperation = null;
110+
boolean endpointCacheRequired = false;
110111

111112
for (OperationModel o : operations.values()) {
112113
if (o.isEndpointOperation()) {
113114
endpointOperation = o;
114-
break;
115115
}
116+
117+
if (o.getEndpointDiscovery() != null && o.getEndpointDiscovery().isRequired()) {
118+
endpointCacheRequired = true;
119+
}
120+
}
121+
122+
if (endpointOperation != null) {
123+
endpointOperation.setEndpointCacheRequired(endpointCacheRequired);
116124
}
117125

118126
for (IntermediateModelShapeProcessor processor : shapeProcessors) {

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/OperationModel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class OperationModel extends DocumentationModel {
5050

5151
private boolean endpointOperation;
5252

53+
private boolean endpointCacheRequired;
54+
5355
private EndpointDiscovery endpointDiscovery;
5456

5557
@JsonIgnore
@@ -207,6 +209,14 @@ public void setEndpointOperation(boolean endpointOperation) {
207209
this.endpointOperation = endpointOperation;
208210
}
209211

212+
public boolean isEndpointCacheRequired() {
213+
return endpointCacheRequired;
214+
}
215+
216+
public void setEndpointCacheRequired(boolean endpointCacheRequired) {
217+
this.endpointCacheRequired = endpointCacheRequired;
218+
}
219+
210220
public boolean isPaginated() {
211221
return isPaginated;
212222
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/AsyncClientBuilderClass.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,24 @@ public TypeSpec poetSpec() {
5454
.addJavadoc("Internal implementation of {@link $T}.", builderInterfaceName);
5555

5656
if (model.getEndpointOperation().isPresent()) {
57-
builder.addMethod(enableEndpointDiscovery());
57+
builder.addMethod(endpointDiscoveryEnabled())
58+
.addMethod(enableEndpointDiscovery());
5859
}
5960

6061
return builder.addMethod(buildClientMethod()).build();
6162
}
6263

64+
private MethodSpec endpointDiscoveryEnabled() {
65+
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
66+
.addAnnotation(Override.class)
67+
.addModifiers(Modifier.PUBLIC)
68+
.returns(builderClassName)
69+
.addParameter(boolean.class, "endpointDiscoveryEnabled")
70+
.addStatement("this.endpointDiscoveryEnabled = endpointDiscoveryEnabled")
71+
.addStatement("return this")
72+
.build();
73+
}
74+
6375
private MethodSpec enableEndpointDiscovery() {
6476
return MethodSpec.methodBuilder("enableEndpointDiscovery")
6577
.addAnnotation(Override.class)

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder;
3636
import software.amazon.awssdk.codegen.internal.Utils;
3737
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
38+
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
3839
import software.amazon.awssdk.codegen.model.service.AuthType;
3940
import software.amazon.awssdk.codegen.poet.ClassSpec;
4041
import software.amazon.awssdk.codegen.poet.PoetUtils;
@@ -78,10 +79,12 @@ public TypeSpec poetSpec() {
7879
ClassName.get(basePackage, model.getMetadata().getSyncBuilder()),
7980
ClassName.get(basePackage, model.getMetadata().getAsyncBuilder()));
8081

82+
// Only services that require endpoint discovery for at least one of their operations get a default value of
83+
// 'true'
8184
if (model.getEndpointOperation().isPresent()) {
8285
builder.addField(FieldSpec.builder(boolean.class, "endpointDiscoveryEnabled")
8386
.addModifiers(PROTECTED)
84-
.initializer("false")
87+
.initializer(resolveDefaultEndpointDiscovery() ? "true" : "false")
8588
.build());
8689
}
8790

@@ -102,6 +105,12 @@ public TypeSpec poetSpec() {
102105
return builder.build();
103106
}
104107

108+
private boolean resolveDefaultEndpointDiscovery() {
109+
return model.getEndpointOperation()
110+
.map(OperationModel::isEndpointCacheRequired)
111+
.orElse(false);
112+
}
113+
105114
private MethodSpec signingNameMethod() {
106115
return MethodSpec.methodBuilder("signingName")
107116
.addAnnotation(Override.class)

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderInterface.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public TypeSpec poetSpec() {
5151

5252
if (model.getEndpointOperation().isPresent()) {
5353
builder.addMethod(enableEndpointDiscovery());
54+
builder.addMethod(endpointDiscovery());
5455
}
5556

5657
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
@@ -72,6 +73,16 @@ private MethodSpec enableEndpointDiscovery() {
7273
return MethodSpec.methodBuilder("enableEndpointDiscovery")
7374
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
7475
.returns(TypeVariableName.get("B"))
76+
.addAnnotation(Deprecated.class)
77+
.addJavadoc("@deprecated Use {@link #endpointDiscoveryEnabled($T)} instead.", boolean.class)
78+
.build();
79+
}
80+
81+
private MethodSpec endpointDiscovery() {
82+
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
83+
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
84+
.returns(TypeVariableName.get("B"))
85+
.addParameter(boolean.class, "endpointDiscovery")
7586
.build();
7687
}
7788

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/SyncClientBuilderClass.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,24 @@ public TypeSpec poetSpec() {
5454
.addJavadoc("Internal implementation of {@link $T}.", builderInterfaceName);
5555

5656
if (model.getEndpointOperation().isPresent()) {
57-
builder.addMethod(enableEndpointDiscovery());
57+
builder.addMethod(endpointDiscoveryEnabled())
58+
.addMethod(enableEndpointDiscovery());
5859
}
5960

6061
return builder.addMethod(buildClientMethod()).build();
6162
}
6263

64+
private MethodSpec endpointDiscoveryEnabled() {
65+
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
66+
.addAnnotation(Override.class)
67+
.addModifiers(Modifier.PUBLIC)
68+
.returns(builderClassName)
69+
.addParameter(boolean.class, "endpointDiscoveryEnabled")
70+
.addStatement("this.endpointDiscoveryEnabled = endpointDiscoveryEnabled")
71+
.addStatement("return this")
72+
.build();
73+
}
74+
6375
private MethodSpec enableEndpointDiscovery() {
6476
return MethodSpec.methodBuilder("enableEndpointDiscovery")
6577
.addAnnotation(Override.class)

codegen/src/test/java/software/amazon/awssdk/codegen/IntermediateModelBuilderTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
2022

2123
import java.io.File;
2224
import org.junit.Test;
@@ -59,4 +61,32 @@ public void sharedOutputShapesLinkCorrectlyToOperationOutputs() {
5961
assertEquals("SecurePingResponse", testModel.getOperation("SecurePing").getOutputShape().getShapeName());
6062
}
6163

64+
@Test
65+
public void defaultEndpointDiscovery_true() {
66+
final File modelFile = new File(IntermediateModelBuilderTest.class
67+
.getResource("poet/client/c2j/endpointdiscovery/service-2.json").getFile());
68+
IntermediateModel testModel = new IntermediateModelBuilder(
69+
C2jModels.builder()
70+
.serviceModel(ModelLoaderUtils.loadModel(ServiceModel.class, modelFile))
71+
.customizationConfig(CustomizationConfig.create())
72+
.build())
73+
.build();
74+
75+
assertTrue(testModel.getEndpointOperation().get().isEndpointCacheRequired());
76+
}
77+
78+
@Test
79+
public void defaultEndpointDiscovery_false() {
80+
final File modelFile = new File(IntermediateModelBuilderTest.class
81+
.getResource("poet/client/c2j/endpointdiscoveryoptional/service-2.json").getFile());
82+
IntermediateModel testModel = new IntermediateModelBuilder(
83+
C2jModels.builder()
84+
.serviceModel(ModelLoaderUtils.loadModel(ServiceModel.class, modelFile))
85+
.customizationConfig(CustomizationConfig.create())
86+
.build())
87+
.build();
88+
89+
assertFalse(testModel.getEndpointOperation().get().isEndpointCacheRequired());
90+
}
91+
6292
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"version":"2.0",
3+
"metadata":{
4+
"apiVersion":"2018-08-31",
5+
"endpointPrefix":"awsendpointdiscoverytestservice",
6+
"jsonVersion":"1.1",
7+
"protocol":"json",
8+
"serviceAbbreviation":"AwsEndpointDiscoveryTest",
9+
"serviceFullName":"AwsEndpointDiscoveryTest",
10+
"serviceId":"AwsEndpointDiscoveryTest",
11+
"signatureVersion":"v4",
12+
"signingName":"awsendpointdiscoverytestservice",
13+
"targetPrefix":"AwsEndpointDiscoveryTestService"
14+
},
15+
"operations":{
16+
"DescribeEndpoints":{
17+
"name":"DescribeEndpoints",
18+
"http":{
19+
"method":"POST",
20+
"requestUri":"/"
21+
},
22+
"input":{"shape":"DescribeEndpointsRequest"},
23+
"output":{"shape":"DescribeEndpointsResponse"},
24+
"endpointoperation":true
25+
},
26+
"TestDiscoveryOptional":{
27+
"name":"TestDiscoveryOptional",
28+
"http":{
29+
"method":"POST",
30+
"requestUri":"/"
31+
},
32+
"input":{"shape":"TestDiscoveryOptionalRequest"},
33+
"output":{"shape":"TestDiscoveryOptionalResponse"},
34+
"endpointdiscovery":{
35+
}
36+
}
37+
},
38+
"shapes": {
39+
"Boolean": {
40+
"type": "boolean"
41+
},
42+
"DescribeEndpointsRequest": {
43+
"type": "structure",
44+
"members": {
45+
"Operation": {
46+
"shape": "String"
47+
},
48+
"Identifiers": {
49+
"shape": "Identifiers"
50+
}
51+
}
52+
},
53+
"DescribeEndpointsResponse": {
54+
"type": "structure",
55+
"required": [
56+
"Endpoints"
57+
],
58+
"members": {
59+
"Endpoints": {
60+
"shape": "Endpoints"
61+
}
62+
}
63+
},
64+
"Endpoint": {
65+
"type": "structure",
66+
"required": [
67+
"Address",
68+
"CachePeriodInMinutes"
69+
],
70+
"members": {
71+
"Address": {
72+
"shape": "String"
73+
},
74+
"CachePeriodInMinutes": {
75+
"shape": "Long"
76+
}
77+
}
78+
},
79+
"Endpoints": {
80+
"type": "list",
81+
"member": {
82+
"shape": "Endpoint"
83+
}
84+
},
85+
"Identifiers": {
86+
"type": "map",
87+
"key": {
88+
"shape": "String"
89+
},
90+
"value": {
91+
"shape": "String"
92+
}
93+
},
94+
"Long": {
95+
"type": "long"
96+
},
97+
"String": {
98+
"type": "string"
99+
},
100+
"TestDiscoveryIdentifiersRequiredRequest": {
101+
"type": "structure",
102+
"required": [
103+
"Sdk"
104+
],
105+
"members": {
106+
"Sdk": {
107+
"shape": "String",
108+
"endpointdiscoveryid": true
109+
}
110+
}
111+
},
112+
"TestDiscoveryIdentifiersRequiredResponse": {
113+
"type": "structure",
114+
"members": {
115+
"DiscoveredEndpoint": {
116+
"shape": "Boolean"
117+
}
118+
}
119+
},
120+
"TestDiscoveryOptionalRequest": {
121+
"type": "structure",
122+
"members": {
123+
}
124+
},
125+
"TestDiscoveryOptionalResponse": {
126+
"type": "structure",
127+
"members": {
128+
"DiscoveredEndpoint": {
129+
"shape": "Boolean"
130+
}
131+
}
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)