Skip to content

Commit c956d3e

Browse files
committed
Endpoint discovery is now enabled by default for future services that will require it
1 parent c9950a9 commit c956d3e

File tree

17 files changed

+287
-18
lines changed

17 files changed

+287
-18
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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,25 @@ public IntermediateModel build() {
106106
Map<String, AuthorizerModel> authorizers =
107107
new HashMap<>(new AddCustomAuthorizers(this.service, getNamingStrategy()).constructAuthorizers());
108108

109+
// Iterate through every operation and build an 'endpointOperation' if at least one operation that supports
110+
// endpoint discovery is found. If -any operations that require- endpoint discovery are found, then the flag
111+
// 'endpointCacheRequired' will be set on the 'endpointOperation'. This 'endpointOperation' summary is then
112+
// passed directly into the constructor of the intermediate model and is referred to by the codegen.
109113
OperationModel endpointOperation = null;
114+
boolean endpointCacheRequired = false;
110115

111116
for (OperationModel o : operations.values()) {
112117
if (o.isEndpointOperation()) {
113118
endpointOperation = o;
114-
break;
115119
}
120+
121+
if (o.getEndpointDiscovery() != null && o.getEndpointDiscovery().isRequired()) {
122+
endpointCacheRequired = true;
123+
}
124+
}
125+
126+
if (endpointOperation != null) {
127+
endpointOperation.setEndpointCacheRequired(endpointCacheRequired);
116128
}
117129

118130
for (IntermediateModelShapeProcessor processor : shapeProcessors) {

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ public class CustomizationConfig {
159159
*/
160160
private UtilitiesMethod utilitiesMethod;
161161

162+
/**
163+
* Force generation of deprecated client builder method 'enableEndpointDiscovery'. Only services that already had
164+
* this method when it was deprecated require this flag to be set.
165+
*/
166+
private boolean enableEndpointDiscoveryMethodRequired = false;
167+
162168
private CustomizationConfig() {
163169
}
164170

@@ -406,4 +412,12 @@ public UtilitiesMethod getUtilitiesMethod() {
406412
public void setUtilitiesMethod(UtilitiesMethod utilitiesMethod) {
407413
this.utilitiesMethod = utilitiesMethod;
408414
}
415+
416+
public boolean isEnableEndpointDiscoveryMethodRequired() {
417+
return enableEndpointDiscoveryMethodRequired;
418+
}
419+
420+
public void setEnableEndpointDiscoveryMethodRequired(boolean enableEndpointDiscoveryMethodRequired) {
421+
this.enableEndpointDiscoveryMethodRequired = enableEndpointDiscoveryMethodRequired;
422+
}
409423
}

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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,32 @@ 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+
59+
if (model.getCustomizationConfig().isEnableEndpointDiscoveryMethodRequired()) {
60+
builder.addMethod(enableEndpointDiscovery());
61+
}
5862
}
5963

6064
return builder.addMethod(buildClientMethod()).build();
6165
}
6266

67+
private MethodSpec endpointDiscoveryEnabled() {
68+
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
69+
.addAnnotation(Override.class)
70+
.addModifiers(Modifier.PUBLIC)
71+
.returns(builderClassName)
72+
.addParameter(boolean.class, "endpointDiscoveryEnabled")
73+
.addStatement("this.endpointDiscoveryEnabled = endpointDiscoveryEnabled")
74+
.addStatement("return this")
75+
.build();
76+
}
77+
6378
private MethodSpec enableEndpointDiscovery() {
6479
return MethodSpec.methodBuilder("enableEndpointDiscovery")
6580
.addAnnotation(Override.class)
81+
.addAnnotation(Deprecated.class)
82+
.addJavadoc("@deprecated Use {@link #endpointDiscoveryEnabled($T)} instead.", boolean.class)
6683
.addModifiers(Modifier.PUBLIC)
6784
.returns(builderClassName)
6885
.addStatement("endpointDiscoveryEnabled = true")

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public TypeSpec poetSpec() {
5050
.addJavadoc(getJavadoc());
5151

5252
if (model.getEndpointOperation().isPresent()) {
53-
builder.addMethod(enableEndpointDiscovery());
53+
if (model.getCustomizationConfig().isEnableEndpointDiscoveryMethodRequired()) {
54+
builder.addMethod(enableEndpointDiscovery());
55+
}
56+
57+
builder.addMethod(endpointDiscovery());
5458
}
5559

5660
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
@@ -72,6 +76,16 @@ private MethodSpec enableEndpointDiscovery() {
7276
return MethodSpec.methodBuilder("enableEndpointDiscovery")
7377
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
7478
.returns(TypeVariableName.get("B"))
79+
.addAnnotation(Deprecated.class)
80+
.addJavadoc("@deprecated Use {@link #endpointDiscoveryEnabled($T)} instead.", boolean.class)
81+
.build();
82+
}
83+
84+
private MethodSpec endpointDiscovery() {
85+
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
86+
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
87+
.returns(TypeVariableName.get("B"))
88+
.addParameter(boolean.class, "endpointDiscovery")
7589
.build();
7690
}
7791

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,32 @@ 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+
59+
if (model.getCustomizationConfig().isEnableEndpointDiscoveryMethodRequired()) {
60+
builder.addMethod(enableEndpointDiscovery());
61+
}
5862
}
5963

6064
return builder.addMethod(buildClientMethod()).build();
6165
}
6266

67+
private MethodSpec endpointDiscoveryEnabled() {
68+
return MethodSpec.methodBuilder("endpointDiscoveryEnabled")
69+
.addAnnotation(Override.class)
70+
.addModifiers(Modifier.PUBLIC)
71+
.returns(builderClassName)
72+
.addParameter(boolean.class, "endpointDiscoveryEnabled")
73+
.addStatement("this.endpointDiscoveryEnabled = endpointDiscoveryEnabled")
74+
.addStatement("return this")
75+
.build();
76+
}
77+
6378
private MethodSpec enableEndpointDiscovery() {
6479
return MethodSpec.methodBuilder("enableEndpointDiscovery")
6580
.addAnnotation(Override.class)
81+
.addAnnotation(Deprecated.class)
82+
.addJavadoc("@deprecated Use {@link #endpointDiscoveryEnabled($T)} instead.", boolean.class)
6683
.addModifiers(Modifier.PUBLIC)
6784
.returns(builderClassName)
6885
.addStatement("endpointDiscoveryEnabled = true")

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)