Skip to content

Commit 17d093b

Browse files
committed
Updating per feedback
1 parent 93e4ef2 commit 17d093b

File tree

8 files changed

+54
-26
lines changed

8 files changed

+54
-26
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public IntermediateModel build() {
111111
for (OperationModel o : operations.values()) {
112112
if (o.isEndpointOperation()) {
113113
endpointOperation = o;
114+
break;
114115
}
115116
}
116117

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import software.amazon.awssdk.core.client.config.SdkClientOption;
6161
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
6262
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache;
63+
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
6364
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
6465
import software.amazon.awssdk.utils.CompletableFutureUtils;
6566
import software.amazon.awssdk.utils.FunctionalUtils;
@@ -192,11 +193,13 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation
192193
if (opModel.getEndpointDiscovery() != null) {
193194
builder.addStatement("\n\nString key = clientConfiguration.option($T.CREDENTIALS_PROVIDER).resolveCredentials()" +
194195
".accessKeyId()", AwsClientOption.class);
195-
builder.addStatement("$T cachedEndpoint = $L.get(key, $L.endpointDiscoveryRequest(), " +
196+
builder.addStatement("EndpointDiscoveryRequest endpointDiscoveryRequest = $T.builder().required($L).build()",
197+
EndpointDiscoveryRequest.class,
198+
opModel.getInputShape().getEndpointDiscovery().isRequired());
199+
builder.addStatement("$T cachedEndpoint = $L.get(key, endpointDiscoveryRequest, " +
196200
"clientConfiguration.option($T.ENDPOINT))",
197201
URI.class,
198202
"endpointDiscoveryCache",
199-
opModel.getInputShape().getVariable().getVariableName(),
200203
SdkClientOption.class);
201204
}
202205

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import software.amazon.awssdk.core.client.config.SdkClientOption;
5151
import software.amazon.awssdk.core.client.handler.SyncClientHandler;
5252
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache;
53+
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
5354

5455
//TODO Make SyncClientClass extend SyncClientInterface (similar to what we do in AsyncClientClass)
5556
public class SyncClientClass implements ClassSpec {
@@ -164,11 +165,13 @@ private List<MethodSpec> operationMethodSpecs(OperationModel opModel) {
164165
if (opModel.getEndpointDiscovery() != null) {
165166
method.addStatement("\n\nString key = clientConfiguration.option($T.CREDENTIALS_PROVIDER)." +
166167
"resolveCredentials().accessKeyId()", AwsClientOption.class);
167-
method.addStatement("$T cachedEndpoint = $L.get(key, $L.endpointDiscoveryRequest(), " +
168+
method.addStatement("EndpointDiscoveryRequest endpointDiscoveryRequest = $T.builder().required($L).build()",
169+
EndpointDiscoveryRequest.class,
170+
opModel.getInputShape().getEndpointDiscovery().isRequired());
171+
method.addStatement("$T cachedEndpoint = $L.get(key, endpointDiscoveryRequest, " +
168172
"clientConfiguration.option($T.ENDPOINT))",
169173
URI.class,
170174
"endpointDiscoveryCache",
171-
opModel.getInputShape().getVariable().getVariableName(),
172175
SdkClientOption.class);
173176
}
174177

codegen/src/main/java/software/amazon/awssdk/codegen/poet/model/AwsServiceModel.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
5454
import software.amazon.awssdk.core.SdkField;
5555
import software.amazon.awssdk.core.SdkPojo;
56-
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
5756
import software.amazon.awssdk.core.runtime.TypeConverter;
5857
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
5958

@@ -332,9 +331,6 @@ private List<MethodSpec> modelClassMethods() {
332331
methodSpecs.add(modelMethodOverrides.equalsMethod(shapeModel));
333332
methodSpecs.add(modelMethodOverrides.toStringMethod(shapeModel));
334333
methodSpecs.add(getValueForField());
335-
if (shapeModel.getEndpointDiscovery() != null) {
336-
methodSpecs.add(endpointDiscoveryRequest());
337-
}
338334
break;
339335
}
340336

@@ -372,16 +368,6 @@ private MethodSpec getValueForField() {
372368
return methodBuilder.build();
373369
}
374370

375-
private MethodSpec endpointDiscoveryRequest() {
376-
return MethodSpec.methodBuilder("endpointDiscoveryRequest")
377-
.addModifiers(PUBLIC)
378-
.returns(EndpointDiscoveryRequest.class)
379-
.addStatement("return $T.builder().required($L).build()",
380-
EndpointDiscoveryRequest.class,
381-
shapeModel.getEndpointDiscovery().isRequired())
382-
.build();
383-
}
384-
385371
private List<MethodSpec> memberGetters() {
386372
return shapeModel.getNonStreamingMembers().stream()
387373
.filter(m -> !m.getHttp().getIsStreaming())

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-endpoint-discovery-async.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
1717
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
1818
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache;
19+
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
1920
import software.amazon.awssdk.core.http.HttpResponseHandler;
2021
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
2122
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
@@ -137,8 +138,8 @@ public CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> testDiscovery
137138
operationMetadata);
138139

139140
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
140-
URI cachedEndpoint = endpointDiscoveryCache.get(key,
141-
testDiscoveryIdentifiersRequiredRequest.endpointDiscoveryRequest(),
141+
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).build();
142+
URI cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest,
142143
clientConfiguration.option(SdkClientOption.ENDPOINT));
143144

144145
return clientHandler
@@ -183,7 +184,8 @@ public CompletableFuture<TestDiscoveryOptionalResponse> testDiscoveryOptional(
183184
operationMetadata);
184185

185186
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
186-
URI cachedEndpoint = endpointDiscoveryCache.get(key, testDiscoveryOptionalRequest.endpointDiscoveryRequest(),
187+
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false).build();
188+
URI cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest,
187189
clientConfiguration.option(SdkClientOption.ENDPOINT));
188190

189191
return clientHandler.execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>()
@@ -227,7 +229,8 @@ public CompletableFuture<TestDiscoveryRequiredResponse> testDiscoveryRequired(
227229
operationMetadata);
228230

229231
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
230-
URI cachedEndpoint = endpointDiscoveryCache.get(key, testDiscoveryRequiredRequest.endpointDiscoveryRequest(),
232+
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).build();
233+
URI cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest,
231234
clientConfiguration.option(SdkClientOption.ENDPOINT));
232235

233236
return clientHandler.execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>()

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-endpoint-discovery-sync.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
1212
import software.amazon.awssdk.core.client.handler.SyncClientHandler;
1313
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache;
14+
import software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest;
1415
import software.amazon.awssdk.core.exception.SdkClientException;
1516
import software.amazon.awssdk.core.http.HttpResponseHandler;
1617
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
@@ -120,7 +121,8 @@ public TestDiscoveryIdentifiersRequiredResponse testDiscoveryIdentifiersRequired
120121
operationMetadata);
121122

122123
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
123-
URI cachedEndpoint = endpointDiscoveryCache.get(key, testDiscoveryIdentifiersRequiredRequest.endpointDiscoveryRequest(),
124+
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).build();
125+
URI cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest,
124126
clientConfiguration.option(SdkClientOption.ENDPOINT));
125127

126128
return clientHandler
@@ -158,7 +160,8 @@ public TestDiscoveryOptionalResponse testDiscoveryOptional(TestDiscoveryOptional
158160
operationMetadata);
159161

160162
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
161-
URI cachedEndpoint = endpointDiscoveryCache.get(key, testDiscoveryOptionalRequest.endpointDiscoveryRequest(),
163+
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false).build();
164+
URI cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest,
162165
clientConfiguration.option(SdkClientOption.ENDPOINT));
163166

164167
return clientHandler.execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>()
@@ -195,7 +198,8 @@ public TestDiscoveryRequiredResponse testDiscoveryRequired(TestDiscoveryRequired
195198
operationMetadata);
196199

197200
String key = clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER).resolveCredentials().accessKeyId();
198-
URI cachedEndpoint = endpointDiscoveryCache.get(key, testDiscoveryRequiredRequest.endpointDiscoveryRequest(),
201+
EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).build();
202+
URI cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest,
199203
clientConfiguration.option(SdkClientOption.ENDPOINT));
200204

201205
return clientHandler.execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>()

core/sdk-core/src/main/java/software/amazon/awssdk/core/endpointdiscovery/EndpointDiscoveryRefreshCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public URI get(String accessKey, EndpointDiscoveryRequest request, URI defaultEn
7171
if (endpoint.expirationTime().isBefore(Instant.now())) {
7272
cache.put(key, endpoint.toBuilder().expirationTime(Instant.now().plusSeconds(60)).build());
7373
String finalKey = key;
74-
discoverEndpoint(null).thenApply(v -> cache.put(finalKey, v));
74+
discoverEndpoint(request).thenApply(v -> cache.put(finalKey, v));
7575
}
7676

7777
return endpoint.endpoint();

core/sdk-core/src/main/java/software/amazon/awssdk/core/endpointdiscovery/EndpointDiscoveryRequest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,41 @@ public Builder toBuilder() {
6262
return new BuilderImpl(this);
6363
}
6464

65+
/**
66+
* Builder interface for constructing a {@link EndpointDiscoveryRequest}.
67+
*/
6568
public interface Builder extends CopyableBuilder<Builder, EndpointDiscoveryRequest> {
69+
70+
/**
71+
* The name of the operation being used in the customer's request.
72+
*
73+
* @param operationName The name of the operation.
74+
* @return Returns a reference to this object so that method calls can be chained together.
75+
*/
6676
Builder operationName(String operationName);
6777

78+
/**
79+
* Specifies a map containing a set identifiers mapped to the name of the field in the request.
80+
*
81+
* @param identifiers A map of identifiers for the request.
82+
* @return Returns a reference to this object so that method calls can be chained together.
83+
*/
6884
Builder identifiers(Map<String, String> identifiers);
6985

86+
/**
87+
* The cache key to use for a given cache entry.
88+
*
89+
* @param cacheKey A cache key.
90+
* @return Returns a reference to this object so that method calls can be chained together.
91+
*/
7092
Builder cacheKey(String cacheKey);
7193

94+
/**
95+
* Whether or not endpoint discovery is required for this request.
96+
*
97+
* @param required boolean specifying if endpoint discovery is required.
98+
* @return Returns a reference to this object so that method calls can be chained together.
99+
*/
72100
Builder required(boolean required);
73101
}
74102

0 commit comments

Comments
 (0)