Skip to content

Commit f0531d0

Browse files
committed
Address PR feedback
1 parent 2eb5187 commit f0531d0

File tree

4 files changed

+46
-114
lines changed

4 files changed

+46
-114
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@
2525
import com.squareup.javapoet.TypeName;
2626
import com.squareup.javapoet.TypeVariableName;
2727
import com.squareup.javapoet.WildcardTypeName;
28-
import java.util.ArrayList;
29-
import java.util.List;
3028
import java.util.Optional;
3129
import java.util.concurrent.CompletableFuture;
32-
import java.util.function.Consumer;
3330
import java.util.function.Function;
3431
import javax.lang.model.element.Modifier;
35-
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
3632
import software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer;
3733
import software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier;
3834
import software.amazon.awssdk.awscore.eventstream.RestEventStreamAsyncResponseTransformer;
@@ -52,7 +48,6 @@
5248
import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait;
5349
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
5450
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
55-
import software.amazon.awssdk.core.ApiName;
5651
import software.amazon.awssdk.core.SdkPojoBuilder;
5752
import software.amazon.awssdk.core.SdkResponse;
5853
import software.amazon.awssdk.core.async.AsyncRequestBody;
@@ -61,7 +56,6 @@
6156
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
6257
import software.amazon.awssdk.core.http.HttpResponseHandler;
6358
import software.amazon.awssdk.core.protocol.VoidSdkResponse;
64-
import software.amazon.awssdk.core.useragent.BusinessMetricFeatureId;
6559
import software.amazon.awssdk.protocols.cbor.AwsCborProtocolFactory;
6660
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
6761
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
@@ -230,10 +224,7 @@ public CodeBlock executionHandler(OperationModel opModel) {
230224
.add(discoveredEndpoint(opModel))
231225
.add(credentialType(opModel, model))
232226
.add(".withRequestConfiguration(clientConfiguration)")
233-
.add(".withInput($L)\n",
234-
model.getMetadata().isRpcV2CborProtocol() ?
235-
"applyRpcV2CborUserAgent(" + opModel.getInput().getVariableName() + ")" :
236-
opModel.getInput().getVariableName())
227+
.add(".withInput($L)\n", opModel.getInput().getVariableName())
237228
.add(".withMetricCollector(apiCallMetricCollector)")
238229
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
239230
.add(HttpChecksumTrait.create(opModel));
@@ -329,10 +320,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
329320

330321
builder.add(RequestCompressionTrait.create(opModel, model))
331322
.add(".withInput($L)$L)",
332-
intermediateModel.getMetadata().isRpcV2CborProtocol() ?
333-
"applyRpcV2CborUserAgent(" + opModel.getInput().getVariableName() + ")" :
334-
opModel.getInput().getVariableName(),
335-
asyncResponseTransformerVariable(isStreaming, isRestJson, opModel))
323+
opModel.getInput().getVariableName(), asyncResponseTransformerVariable(isStreaming, isRestJson, opModel))
336324
.add(opModel.getEndpointDiscovery() != null ? ");" : ";");
337325

338326
if (opModel.hasStreamingOutput()) {
@@ -580,49 +568,4 @@ private String protocolFactoryLiteral(IntermediateModel model, OperationModel op
580568
private boolean isRestJson(IntermediateModel model) {
581569
return model.getMetadata().getProtocol() == Protocol.REST_JSON;
582570
}
583-
584-
@Override
585-
public List<MethodSpec> additionalMethods() {
586-
List<MethodSpec> methods = new ArrayList<>();
587-
588-
applyRpcV2CborUserAgentMethod().ifPresent(methods::add);
589-
590-
return methods;
591-
}
592-
593-
private Optional<MethodSpec> applyRpcV2CborUserAgentMethod() {
594-
if (!model.getMetadata().isRpcV2CborProtocol()) {
595-
return Optional.empty();
596-
}
597-
598-
TypeVariableName typeVariableName =
599-
TypeVariableName.get("T", poetExtensions.getModelClass(model.getSdkRequestBaseClassName()));
600-
601-
ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName
602-
.get(ClassName.get(Consumer.class), ClassName.get(AwsRequestOverrideConfiguration.Builder.class));
603-
604-
CodeBlock codeBlock = CodeBlock.builder()
605-
.addStatement("$T userAgentApplier = b -> "
606-
+ "b.addApiName($T.builder().name($S).version($S).build())",
607-
parameterizedTypeName, ApiName.class,
608-
"sdk-metrics",
609-
BusinessMetricFeatureId.PROTOCOL_RPC_V2_CBOR.value())
610-
.addStatement("$T overrideConfiguration =\n"
611-
+ " request.overrideConfiguration().map(c -> c.toBuilder()"
612-
+ ".applyMutation(userAgentApplier).build())\n"
613-
+ " .orElse((AwsRequestOverrideConfiguration.builder()"
614-
+ ".applyMutation(userAgentApplier).build()))",
615-
AwsRequestOverrideConfiguration.class)
616-
.addStatement("return (T) request.toBuilder().overrideConfiguration(overrideConfiguration)"
617-
+ ".build()")
618-
.build();
619-
620-
return Optional.of(MethodSpec.methodBuilder("applyRpcV2CborUserAgent")
621-
.addModifiers(Modifier.PRIVATE, Modifier.STATIC)
622-
.addParameter(typeVariableName, "request")
623-
.addTypeVariable(typeVariableName)
624-
.addCode(codeBlock)
625-
.returns(typeVariableName)
626-
.build());
627-
}
628571
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-rpcv2-async-client-class.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
import org.slf4j.LoggerFactory;
1313
import software.amazon.awssdk.annotations.Generated;
1414
import software.amazon.awssdk.annotations.SdkInternalApi;
15-
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
1615
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
1716
import software.amazon.awssdk.awscore.exception.AwsServiceException;
1817
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
1918
import software.amazon.awssdk.awscore.internal.AwsServiceProtocol;
2019
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
21-
import software.amazon.awssdk.core.ApiName;
2220
import software.amazon.awssdk.core.RequestOverrideConfiguration;
2321
import software.amazon.awssdk.core.SdkPlugin;
2422
import software.amazon.awssdk.core.SdkRequest;
@@ -68,7 +66,6 @@
6866
import software.amazon.awssdk.services.smithyrpcv2protocol.model.SimpleScalarPropertiesRequest;
6967
import software.amazon.awssdk.services.smithyrpcv2protocol.model.SimpleScalarPropertiesResponse;
7068
import software.amazon.awssdk.services.smithyrpcv2protocol.model.SmithyRpcV2ProtocolException;
71-
import software.amazon.awssdk.services.smithyrpcv2protocol.model.SmithyRpcV2ProtocolRequest;
7269
import software.amazon.awssdk.services.smithyrpcv2protocol.model.SparseNullsOperationRequest;
7370
import software.amazon.awssdk.services.smithyrpcv2protocol.model.SparseNullsOperationResponse;
7471
import software.amazon.awssdk.services.smithyrpcv2protocol.model.ValidationException;
@@ -176,7 +173,7 @@ public CompletableFuture<EmptyInputOutputResponse> emptyInputOutput(EmptyInputOu
176173
.withMarshaller(new EmptyInputOutputRequestMarshaller(protocolFactory))
177174
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
178175
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
179-
.withInput(applyRpcV2CborUserAgent(emptyInputOutputRequest)));
176+
.withInput(emptyInputOutputRequest));
180177
CompletableFuture<EmptyInputOutputResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
181178
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
182179
});
@@ -249,7 +246,7 @@ public CompletableFuture<Float16Response> float16(Float16Request float16Request)
249246
.withProtocolMetadata(protocolMetadata).withMarshaller(new Float16RequestMarshaller(protocolFactory))
250247
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
251248
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
252-
.withInput(applyRpcV2CborUserAgent(float16Request)));
249+
.withInput(float16Request));
253250
CompletableFuture<Float16Response> whenCompleted = executeFuture.whenComplete((r, e) -> {
254251
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
255252
});
@@ -324,7 +321,7 @@ public CompletableFuture<FractionalSecondsResponse> fractionalSeconds(Fractional
324321
.withMarshaller(new FractionalSecondsRequestMarshaller(protocolFactory))
325322
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
326323
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
327-
.withInput(applyRpcV2CborUserAgent(fractionalSecondsRequest)));
324+
.withInput(fractionalSecondsRequest));
328325
CompletableFuture<FractionalSecondsResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
329326
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
330327
});
@@ -401,7 +398,7 @@ public CompletableFuture<GreetingWithErrorsResponse> greetingWithErrors(Greeting
401398
.withMarshaller(new GreetingWithErrorsRequestMarshaller(protocolFactory))
402399
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
403400
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
404-
.withInput(applyRpcV2CborUserAgent(greetingWithErrorsRequest)));
401+
.withInput(greetingWithErrorsRequest));
405402
CompletableFuture<GreetingWithErrorsResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
406403
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
407404
});
@@ -475,7 +472,7 @@ public CompletableFuture<NoInputOutputResponse> noInputOutput(NoInputOutputReque
475472
.withMarshaller(new NoInputOutputRequestMarshaller(protocolFactory))
476473
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
477474
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
478-
.withInput(applyRpcV2CborUserAgent(noInputOutputRequest)));
475+
.withInput(noInputOutputRequest));
479476
CompletableFuture<NoInputOutputResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
480477
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
481478
});
@@ -552,7 +549,7 @@ public CompletableFuture<OperationWithDefaultsResponse> operationWithDefaults(
552549
.withMarshaller(new OperationWithDefaultsRequestMarshaller(protocolFactory))
553550
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
554551
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
555-
.withInput(applyRpcV2CborUserAgent(operationWithDefaultsRequest)));
552+
.withInput(operationWithDefaultsRequest));
556553
CompletableFuture<OperationWithDefaultsResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
557554
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
558555
});
@@ -628,7 +625,7 @@ public CompletableFuture<OptionalInputOutputResponse> optionalInputOutput(
628625
.withMarshaller(new OptionalInputOutputRequestMarshaller(protocolFactory))
629626
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
630627
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
631-
.withInput(applyRpcV2CborUserAgent(optionalInputOutputRequest)));
628+
.withInput(optionalInputOutputRequest));
632629
CompletableFuture<OptionalInputOutputResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
633630
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
634631
});
@@ -703,7 +700,7 @@ public CompletableFuture<RecursiveShapesResponse> recursiveShapes(RecursiveShape
703700
.withMarshaller(new RecursiveShapesRequestMarshaller(protocolFactory))
704701
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
705702
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
706-
.withInput(applyRpcV2CborUserAgent(recursiveShapesRequest)));
703+
.withInput(recursiveShapesRequest));
707704
CompletableFuture<RecursiveShapesResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
708705
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
709706
});
@@ -779,7 +776,7 @@ public CompletableFuture<RpcV2CborDenseMapsResponse> rpcV2CborDenseMaps(RpcV2Cbo
779776
.withMarshaller(new RpcV2CborDenseMapsRequestMarshaller(protocolFactory))
780777
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
781778
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
782-
.withInput(applyRpcV2CborUserAgent(rpcV2CborDenseMapsRequest)));
779+
.withInput(rpcV2CborDenseMapsRequest));
783780
CompletableFuture<RpcV2CborDenseMapsResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
784781
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
785782
});
@@ -854,7 +851,7 @@ public CompletableFuture<RpcV2CborListsResponse> rpcV2CborLists(RpcV2CborListsRe
854851
.withMarshaller(new RpcV2CborListsRequestMarshaller(protocolFactory))
855852
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
856853
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
857-
.withInput(applyRpcV2CborUserAgent(rpcV2CborListsRequest)));
854+
.withInput(rpcV2CborListsRequest));
858855
CompletableFuture<RpcV2CborListsResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
859856
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
860857
});
@@ -931,7 +928,7 @@ public CompletableFuture<RpcV2CborSparseMapsResponse> rpcV2CborSparseMaps(
931928
.withMarshaller(new RpcV2CborSparseMapsRequestMarshaller(protocolFactory))
932929
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
933930
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
934-
.withInput(applyRpcV2CborUserAgent(rpcV2CborSparseMapsRequest)));
931+
.withInput(rpcV2CborSparseMapsRequest));
935932
CompletableFuture<RpcV2CborSparseMapsResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
936933
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
937934
});
@@ -1007,7 +1004,7 @@ public CompletableFuture<SimpleScalarPropertiesResponse> simpleScalarProperties(
10071004
.withMarshaller(new SimpleScalarPropertiesRequestMarshaller(protocolFactory))
10081005
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
10091006
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
1010-
.withInput(applyRpcV2CborUserAgent(simpleScalarPropertiesRequest)));
1007+
.withInput(simpleScalarPropertiesRequest));
10111008
CompletableFuture<SimpleScalarPropertiesResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
10121009
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
10131010
});
@@ -1083,7 +1080,7 @@ public CompletableFuture<SparseNullsOperationResponse> sparseNullsOperation(
10831080
.withMarshaller(new SparseNullsOperationRequestMarshaller(protocolFactory))
10841081
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
10851082
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
1086-
.withInput(applyRpcV2CborUserAgent(sparseNullsOperationRequest)));
1083+
.withInput(sparseNullsOperationRequest));
10871084
CompletableFuture<SparseNullsOperationResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
10881085
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
10891086
});
@@ -1105,15 +1102,6 @@ public final String serviceName() {
11051102
return SERVICE_NAME;
11061103
}
11071104

1108-
private static <T extends SmithyRpcV2ProtocolRequest> T applyRpcV2CborUserAgent(T request) {
1109-
Consumer<AwsRequestOverrideConfiguration.Builder> userAgentApplier = b -> b.addApiName(ApiName.builder()
1110-
.name("sdk-metrics").version("M").build());
1111-
AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration()
1112-
.map(c -> c.toBuilder().applyMutation(userAgentApplier).build())
1113-
.orElse((AwsRequestOverrideConfiguration.builder().applyMutation(userAgentApplier).build()));
1114-
return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
1115-
}
1116-
11171105
private <T extends BaseAwsJsonProtocolFactory.Builder<T>> T init(T builder) {
11181106
return builder.clientConfiguration(clientConfiguration)
11191107
.defaultServiceExceptionSupplier(SmithyRpcV2ProtocolException::builder)

0 commit comments

Comments
 (0)