Skip to content

Commit 9d192d1

Browse files
chrisradekshorea
authored andcommitted
feat(core): Adds OperationName to the ExecutionContext class.
1 parent 911496d commit 9d192d1

File tree

9 files changed

+50
-1
lines changed

9 files changed

+50
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"type": "feature",
4+
"description": "Adds the operation name of the calling API to the ExecutionContext class. This exposes a way to get the API name from within an ExecutionInterceptor."
5+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ public CodeBlock executionHandler(OperationModel opModel) {
163163
CodeBlock.Builder codeBlock = CodeBlock
164164
.builder()
165165
.add("\n\nreturn clientHandler.execute(new $T<$T, $T>()\n" +
166+
".withOperationName(\"$N\")\n" +
166167
".withResponseHandler($N)\n" +
167168
".withErrorResponseHandler($N)\n" +
168169
hostPrefixExpression(opModel) +
169170
".withInput($L)\n",
170171
ClientExecutionParams.class,
171172
requestType,
172173
responseType,
174+
opModel.getOperationName(),
173175
"responseHandler",
174176
"errorResponseHandler",
175177
opModel.getInput().getVariableName());
@@ -228,6 +230,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
228230
String protocolFactory = protocolFactoryLiteral(opModel);
229231
String customerResponseHandler = opModel.hasEventStreamOutput() ? "asyncResponseHandler" : "asyncResponseTransformer";
230232
builder.add("\n\n$L clientHandler.execute(new $T<$T, $T>()\n" +
233+
".withOperationName(\"$N\")\n" +
231234
".withMarshaller(new $T($L))\n" +
232235
"$L" +
233236
"$L" +
@@ -242,6 +245,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
242245
ClientExecutionParams.class,
243246
requestType,
244247
opModel.hasEventStreamOutput() && !isRestJson ? SdkResponse.class : pojoResponseType,
248+
opModel.getOperationName(),
245249
marshaller,
246250
protocolFactory,
247251
opModel.hasEventStreamInput() ? CodeBlock.builder()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ public CodeBlock executionHandler(OperationModel opModel) {
9696
CodeBlock.Builder codeBlock = CodeBlock
9797
.builder()
9898
.add("\n\nreturn clientHandler.execute(new $T<$T, $T>()" +
99+
".withOperationName(\"$N\")\n" +
99100
".withResponseHandler($N)" +
100101
".withErrorResponseHandler($N)" +
101102
hostPrefixExpression(opModel) +
102103
".withInput($L)",
103104
ClientExecutionParams.class,
104105
requestType,
105106
responseType,
107+
opModel.getOperationName(),
106108
"responseHandler",
107109
"errorResponseHandler",
108110
opModel.getInput().getVariableName());
@@ -126,6 +128,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
126128
String asyncRequestBody = opModel.hasStreamingInput() ? ".withAsyncRequestBody(requestBody)"
127129
: "";
128130
return CodeBlock.builder().add("\n\nreturn clientHandler.execute(new $T<$T, $T>()\n" +
131+
".withOperationName(\"$N\")\n" +
129132
".withMarshaller(new $T(protocolFactory))" +
130133
".withResponseHandler(responseHandler)" +
131134
".withErrorResponseHandler($N)\n" +
@@ -135,6 +138,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
135138
ClientExecutionParams.class,
136139
requestType,
137140
pojoResponseType,
141+
opModel.getOperationName(),
138142
marshaller,
139143
"errorResponseHandler",
140144
opModel.getInput().getVariableName(),

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public CompletableFuture<APostOperationResponse> aPostOperation(APostOperationRe
159159
operationMetadata);
160160

161161
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>()
162+
.withOperationName("APostOperation")
162163
.withMarshaller(new APostOperationRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler)
163164
.withErrorResponseHandler(errorResponseHandler).hostPrefixExpression(resolvedHostExpression)
164165
.withInput(aPostOperationRequest));
@@ -205,6 +206,7 @@ public CompletableFuture<APostOperationWithOutputResponse> aPostOperationWithOut
205206

206207
return clientHandler
207208
.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>()
209+
.withOperationName("APostOperationWithOutput")
208210
.withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory))
209211
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
210212
.withInput(aPostOperationWithOutputRequest));
@@ -272,6 +274,7 @@ public CompletableFuture<Void> eventStreamOperation(EventStreamOperationRequest
272274

273275
clientHandler.execute(
274276
new ClientExecutionParams<EventStreamOperationRequest, EventStreamOperationResponse>()
277+
.withOperationName("EventStreamOperation")
275278
.withMarshaller(new EventStreamOperationRequestMarshaller(protocolFactory))
276279
.withAsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody.fromPublisher(adapted))
277280
.withFullDuplex(true).withResponseHandler(responseHandler)
@@ -337,6 +340,7 @@ public CompletableFuture<EventStreamOperationWithOnlyInputResponse> eventStreamO
337340

338341
return clientHandler
339342
.execute(new ClientExecutionParams<EventStreamOperationWithOnlyInputRequest, EventStreamOperationWithOnlyInputResponse>()
343+
.withOperationName("EventStreamOperationWithOnlyInput")
340344
.withMarshaller(new EventStreamOperationWithOnlyInputRequestMarshaller(protocolFactory))
341345
.withAsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody.fromPublisher(adapted))
342346
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
@@ -384,6 +388,7 @@ public CompletableFuture<GetWithoutRequiredMembersResponse> getWithoutRequiredMe
384388

385389
return clientHandler
386390
.execute(new ClientExecutionParams<GetWithoutRequiredMembersRequest, GetWithoutRequiredMembersResponse>()
391+
.withOperationName("GetWithoutRequiredMembers")
387392
.withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory))
388393
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
389394
.withInput(getWithoutRequiredMembersRequest));
@@ -427,6 +432,7 @@ public CompletableFuture<PaginatedOperationWithResultKeyResponse> paginatedOpera
427432

428433
return clientHandler
429434
.execute(new ClientExecutionParams<PaginatedOperationWithResultKeyRequest, PaginatedOperationWithResultKeyResponse>()
435+
.withOperationName("PaginatedOperationWithResultKey")
430436
.withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory))
431437
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
432438
.withInput(paginatedOperationWithResultKeyRequest));
@@ -543,6 +549,7 @@ public CompletableFuture<PaginatedOperationWithoutResultKeyResponse> paginatedOp
543549

544550
return clientHandler
545551
.execute(new ClientExecutionParams<PaginatedOperationWithoutResultKeyRequest, PaginatedOperationWithoutResultKeyResponse>()
552+
.withOperationName("PaginatedOperationWithoutResultKey")
546553
.withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory))
547554
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
548555
.withInput(paginatedOperationWithoutResultKeyRequest));
@@ -664,6 +671,7 @@ public CompletableFuture<StreamingInputOperationResponse> streamingInputOperatio
664671

665672
return clientHandler
666673
.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>()
674+
.withOperationName("StreamingInputOperation")
667675
.withMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory))
668676
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
669677
.withAsyncRequestBody(requestBody).withInput(streamingInputOperationRequest));
@@ -719,6 +727,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingInputOutputOperation(
719727

720728
return clientHandler.execute(
721729
new ClientExecutionParams<StreamingInputOutputOperationRequest, StreamingInputOutputOperationResponse>()
730+
.withOperationName("StreamingInputOutputOperation")
722731
.withMarshaller(new StreamingInputOutputOperationRequestMarshaller(protocolFactory))
723732
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
724733
.withAsyncRequestBody(requestBody).withInput(streamingInputOutputOperationRequest),
@@ -774,6 +783,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingOutputOperation(
774783

775784
return clientHandler.execute(
776785
new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>()
786+
.withOperationName("StreamingOutputOperation")
777787
.withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory))
778788
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
779789
.withInput(streamingOutputOperationRequest), asyncResponseTransformer).whenComplete((r, e) -> {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public APostOperationResponse aPostOperation(APostOperationRequest aPostOperatio
115115
operationMetadata);
116116

117117
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>()
118+
.withOperationName("APostOperation")
118119
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
119120
.hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest)
120121
.withMarshaller(new APostOperationRequestMarshaller(protocolFactory)));
@@ -155,6 +156,7 @@ public APostOperationWithOutputResponse aPostOperationWithOutput(
155156

156157
return clientHandler
157158
.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>()
159+
.withOperationName("APostOperationWithOutput")
158160
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
159161
.withInput(aPostOperationWithOutputRequest)
160162
.withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)));
@@ -195,6 +197,7 @@ public GetWithoutRequiredMembersResponse getWithoutRequiredMembers(
195197

196198
return clientHandler
197199
.execute(new ClientExecutionParams<GetWithoutRequiredMembersRequest, GetWithoutRequiredMembersResponse>()
200+
.withOperationName("GetWithoutRequiredMembers")
198201
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
199202
.withInput(getWithoutRequiredMembersRequest)
200203
.withMarshaller(new GetWithoutRequiredMembersRequestMarshaller(protocolFactory)));
@@ -231,6 +234,7 @@ public PaginatedOperationWithResultKeyResponse paginatedOperationWithResultKey(
231234

232235
return clientHandler
233236
.execute(new ClientExecutionParams<PaginatedOperationWithResultKeyRequest, PaginatedOperationWithResultKeyResponse>()
237+
.withOperationName("PaginatedOperationWithResultKey")
234238
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
235239
.withInput(paginatedOperationWithResultKeyRequest)
236240
.withMarshaller(new PaginatedOperationWithResultKeyRequestMarshaller(protocolFactory)));
@@ -341,6 +345,7 @@ public PaginatedOperationWithoutResultKeyResponse paginatedOperationWithoutResul
341345

342346
return clientHandler
343347
.execute(new ClientExecutionParams<PaginatedOperationWithoutResultKeyRequest, PaginatedOperationWithoutResultKeyResponse>()
348+
.withOperationName("PaginatedOperationWithoutResultKey")
344349
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
345350
.withInput(paginatedOperationWithoutResultKeyRequest)
346351
.withMarshaller(new PaginatedOperationWithoutResultKeyRequestMarshaller(protocolFactory)));
@@ -461,6 +466,7 @@ public StreamingInputOperationResponse streamingInputOperation(StreamingInputOpe
461466
operationMetadata);
462467

463468
return clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>()
469+
.withOperationName("StreamingInputOperation")
464470
.withResponseHandler(responseHandler)
465471
.withErrorResponseHandler(errorResponseHandler)
466472
.withInput(streamingInputOperationRequest)
@@ -522,6 +528,7 @@ public <ReturnT> ReturnT streamingInputOutputOperation(
522528

523529
return clientHandler.execute(
524530
new ClientExecutionParams<StreamingInputOutputOperationRequest, StreamingInputOutputOperationResponse>()
531+
.withOperationName("StreamingInputOutputOperation")
525532
.withResponseHandler(responseHandler)
526533
.withErrorResponseHandler(errorResponseHandler)
527534
.withInput(streamingInputOutputOperationRequest)
@@ -570,6 +577,7 @@ public <ReturnT> ReturnT streamingOutputOperation(StreamingOutputOperationReques
570577

571578
return clientHandler.execute(
572579
new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>()
580+
.withOperationName("StreamingOutputOperation")
573581
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
574582
.withInput(streamingOutputOperationRequest)
575583
.withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public APostOperationResponse aPostOperation(APostOperationRequest aPostOperatio
7777
HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
7878

7979
return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>()
80+
.withOperationName("APostOperation")
8081
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
8182
.hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest)
8283
.withMarshaller(new APostOperationRequestMarshaller(protocolFactory)));
@@ -114,6 +115,7 @@ public APostOperationWithOutputResponse aPostOperationWithOutput(
114115

115116
return clientHandler
116117
.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>()
118+
.withOperationName("APostOperationWithOutput")
117119
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
118120
.withInput(aPostOperationWithOutputRequest)
119121
.withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)));

core/aws-core/src/main/java/software/amazon/awssdk/awscore/client/handler/AwsClientHandlerUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public static <InputT extends SdkRequest, OutputT extends SdkResponse> Execution
8080
.putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION, clientConfig.option(AwsClientOption.SIGNING_REGION))
8181
.putAttribute(SdkInternalExecutionAttribute.IS_FULL_DUPLEX, executionParams.isFullDuplex())
8282
.putAttribute(SdkExecutionAttribute.CLIENT_TYPE, clientConfig.option(SdkClientOption.CLIENT_TYPE))
83-
.putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfig.option(SdkClientOption.SERVICE_NAME));
83+
.putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfig.option(SdkClientOption.SERVICE_NAME))
84+
.putAttribute(SdkExecutionAttribute.OPERATION_NAME, executionParams.getOperationName());
8485

8586
ExecutionInterceptorChain executionInterceptorChain =
8687
new ExecutionInterceptorChain(clientConfig.option(SdkClientOption.EXECUTION_INTERCEPTORS));

core/sdk-core/src/main/java/software/amazon/awssdk/core/client/handler/ClientExecutionParams.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class ClientExecutionParams<InputT extends SdkRequest, OutputT> {
4242
private HttpResponseHandler<? extends SdkException> errorResponseHandler;
4343
private boolean fullDuplex;
4444
private String hostPrefixExpression;
45+
private String operationName;
4546

4647
public Marshaller<InputT> getMarshaller() {
4748
return marshaller;
@@ -111,6 +112,18 @@ public ClientExecutionParams<InputT, OutputT> withFullDuplex(boolean fullDuplex)
111112
return this;
112113
}
113114

115+
public String getOperationName() {
116+
return operationName;
117+
}
118+
119+
/**
120+
* Sets the operation name of the API.
121+
*/
122+
public ClientExecutionParams<InputT, OutputT> withOperationName(String operationName) {
123+
this.operationName = operationName;
124+
return this;
125+
}
126+
114127
public String hostPrefixExpression() {
115128
return hostPrefixExpression;
116129
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/SdkExecutionAttribute.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class SdkExecutionAttribute {
4343
public static final ExecutionAttribute<Integer> TIME_OFFSET = new ExecutionAttribute<>("TimeOffset");
4444

4545
public static final ExecutionAttribute<ClientType> CLIENT_TYPE = new ExecutionAttribute<>("ClientType");
46+
47+
public static final ExecutionAttribute<String> OPERATION_NAME = new ExecutionAttribute<>("OperationName");
4648

4749
protected SdkExecutionAttribute() {
4850
}

0 commit comments

Comments
 (0)