Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(StringArrayEndpointParams) Customization of Operation Context params and adding customizations for S3 #5159

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,27 @@ public IntermediateModel build() {

namingStrategy.validateCustomerVisibleNaming(trimmedModel);
customizeEndpointParameters(fullModel, endpointRuleSet);
customizeOperationContextParams(fullModel, trimmedModel);
return trimmedModel;
}

private static void customizeOperationContextParams(IntermediateModel fullModel, IntermediateModel trimmedModel) {
if (!CollectionUtils.isNullOrEmpty(fullModel.getCustomizationConfig().getOperationContextParams())) {
L-Applin marked this conversation as resolved.
Show resolved Hide resolved
fullModel.getCustomizationConfig().getOperationContextParams().forEach((operationName, operationContextParamMap) -> {
OperationModel operation = trimmedModel.getOperation(operationName);
if (operation == null) {
throw new IllegalStateException(
"Could not find operation " + operationName + " to customize Operation Context Params.");
}
if (operation.getOperationContextParams() != null) {
throw new IllegalStateException(
"Cannot customize operation " + operationName + " which already has OperationContextParams.");
}
operation.setOperationContextParams(operationContextParamMap);
});
}
}

private void customizeEndpointParameters(IntermediateModel fullModel, EndpointRuleSetModel endpointRuleSet) {
if (fullModel.getCustomizationConfig().getEndpointParameters() != null) {
fullModel.getCustomizationConfig().getEndpointParameters().keySet().forEach(key -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import software.amazon.awssdk.codegen.model.rules.endpoints.ParameterModel;
import software.amazon.awssdk.codegen.model.service.ClientContextParam;
import software.amazon.awssdk.codegen.model.service.OperationContextParam;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.core.traits.PayloadTrait;
import software.amazon.awssdk.utils.AttributeMap;
Expand Down Expand Up @@ -324,6 +325,7 @@ public class CustomizationConfig {
* This should be removed once the service updates its models
*/
private Map<String, ParameterModel> endpointParameters;
private Map<String, Map<String, OperationContextParam>> operationContextParams;
L-Applin marked this conversation as resolved.
Show resolved Hide resolved

private CustomizationConfig() {
}
Expand Down Expand Up @@ -858,4 +860,12 @@ public Map<String, ParameterModel> getEndpointParameters() {
public void setEndpointParameters(Map<String, ParameterModel> endpointParameters) {
this.endpointParameters = endpointParameters;
}

public Map<String, Map<String, OperationContextParam>> getOperationContextParams() {
return operationContextParams;
}

public void setOperationContextParams(Map<String, Map<String, OperationContextParam>> operationContextParams) {
this.operationContextParams = operationContextParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,23 @@ public void endpointParametersWithDuplicatesInCustomizationConfig() {
ClientTestModels.queryServiceModelWithSpecialCustomization("customization-with-duplicate-endpointparameter.config")))
.withMessageContaining("Duplicate parameters found in customizationConfig");
}

@Test
public void endpointParametersWithDuplicatesOperationContextInCustomizationConfig() {
assertThatIllegalStateException()
.isThrownBy(() -> new EndpointParametersClassSpec(
ClientTestModels.queryServiceModelWithSpecialCustomization("customization-with-duplicate-operationcontextparams.config")))
.withMessageContaining("Cannot customize operation OperationWithOperationContextParam which already has OperationContextParams.");
}

@Test
public void endpointParametersWithIncorrectNameOperationContextInCustomizationConfig() {
assertThatIllegalStateException()
.isThrownBy(() -> new EndpointParametersClassSpec(
ClientTestModels.queryServiceModelWithSpecialCustomization("customization-with-incorrectName-operationcontextparams.config")))
.withMessageContaining("Could not find operation randomOperatoinName to customize Operation Context Params.");
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"operationContextParams":
{
"OperationWithOperationContextParam": {
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"operationContextParams":
{
"randomOperatoinName": {
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,16 @@
"documentation": "Parameter from the customization config",
"type": "StringArray"
}
},
"operationContextParams": {
"OperationWithCustomizedOperationContextParam": {
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
}
}
}
,
"CustomEndpointArray": {
"required": false,
"documentation": "Parameter from the customization config",
"type": "StringArray"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@
"requestUri": "/"
},
"operationContextParams":{
"deleteKeys":{"value":"ListMember.StringList[*].LeafString"}
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
},
"input":{"shape":"WithOperationContextParam"}
},
"OperationWithCustomizedOperationContextParam": {
"name": "OperationWithCustomizedOperationContextParam",
"http": {
"method": "POST",
"requestUri": "/"
},
"input":{"shape":"WithOperationContextParam"}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredResponse;
import software.amazon.awssdk.services.query.model.OperationWithContextParamRequest;
import software.amazon.awssdk.services.query.model.OperationWithContextParamResponse;
import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamRequest;
import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamResponse;
import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeRequest;
import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeResponse;
import software.amazon.awssdk.services.query.model.OperationWithOperationContextParamRequest;
Expand All @@ -72,6 +74,7 @@
import software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithChecksumRequiredRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithContextParamRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithCustomizedOperationContextParamRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithNoneAuthTypeRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithOperationContextParamRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithRequestCompressionRequestMarshaller;
Expand Down Expand Up @@ -467,6 +470,65 @@ public CompletableFuture<OperationWithContextParamResponse> operationWithContext
}
}

/**
* Invokes the OperationWithCustomizedOperationContextParam operation asynchronously.
*
* @param operationWithCustomizedOperationContextParamRequest
* @return A Java Future containing the result of the OperationWithCustomizedOperationContextParam operation
* returned by the service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.</li>
* </ul>
* @sample QueryAsyncClient.OperationWithCustomizedOperationContextParam
* @see <a
* href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/OperationWithCustomizedOperationContextParam"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<OperationWithCustomizedOperationContextParamResponse> operationWithCustomizedOperationContextParam(
OperationWithCustomizedOperationContextParamRequest operationWithCustomizedOperationContextParamRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(
operationWithCustomizedOperationContextParamRequest, this.clientConfiguration);
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration,
operationWithCustomizedOperationContextParamRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithCustomizedOperationContextParam");

HttpResponseHandler<OperationWithCustomizedOperationContextParamResponse> responseHandler = protocolFactory
.createResponseHandler(OperationWithCustomizedOperationContextParamResponse::builder);

HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();

CompletableFuture<OperationWithCustomizedOperationContextParamResponse> executeFuture = clientHandler
.execute(new ClientExecutionParams<OperationWithCustomizedOperationContextParamRequest, OperationWithCustomizedOperationContextParamResponse>()
.withOperationName("OperationWithCustomizedOperationContextParam")
.withProtocolMetadata(protocolMetadata)
.withMarshaller(new OperationWithCustomizedOperationContextParamRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(operationWithCustomizedOperationContextParamRequest));
CompletableFuture<OperationWithCustomizedOperationContextParamResponse> whenCompleteFuture = null;
whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}

/**
* Invokes the OperationWithNoneAuthType operation asynchronously.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredResponse;
import software.amazon.awssdk.services.query.model.OperationWithContextParamRequest;
import software.amazon.awssdk.services.query.model.OperationWithContextParamResponse;
import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamRequest;
import software.amazon.awssdk.services.query.model.OperationWithCustomizedOperationContextParamResponse;
import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeRequest;
import software.amazon.awssdk.services.query.model.OperationWithNoneAuthTypeResponse;
import software.amazon.awssdk.services.query.model.OperationWithOperationContextParamRequest;
Expand All @@ -66,6 +68,7 @@
import software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithChecksumRequiredRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithContextParamRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithCustomizedOperationContextParamRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithNoneAuthTypeRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithOperationContextParamRequestMarshaller;
import software.amazon.awssdk.services.query.transform.OperationWithRequestCompressionRequestMarshaller;
Expand Down Expand Up @@ -401,6 +404,55 @@ public OperationWithContextParamResponse operationWithContextParam(
}
}

/**
* Invokes the OperationWithCustomizedOperationContextParam operation.
*
* @param operationWithCustomizedOperationContextParamRequest
* @return Result of the OperationWithCustomizedOperationContextParam operation returned by the service.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws QueryException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample QueryClient.OperationWithCustomizedOperationContextParam
* @see <a
* href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/OperationWithCustomizedOperationContextParam"
* target="_top">AWS API Documentation</a>
*/
@Override
public OperationWithCustomizedOperationContextParamResponse operationWithCustomizedOperationContextParam(
OperationWithCustomizedOperationContextParamRequest operationWithCustomizedOperationContextParamRequest)
throws AwsServiceException, SdkClientException, QueryException {

HttpResponseHandler<OperationWithCustomizedOperationContextParamResponse> responseHandler = protocolFactory
.createResponseHandler(OperationWithCustomizedOperationContextParamResponse::builder);

HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(
operationWithCustomizedOperationContextParamRequest, this.clientConfiguration);
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration,
operationWithCustomizedOperationContextParamRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithCustomizedOperationContextParam");

return clientHandler
.execute(new ClientExecutionParams<OperationWithCustomizedOperationContextParamRequest, OperationWithCustomizedOperationContextParamResponse>()
.withOperationName("OperationWithCustomizedOperationContextParam")
.withProtocolMetadata(protocolMetadata).withResponseHandler(responseHandler)
.withErrorResponseHandler(errorResponseHandler).withRequestConfiguration(clientConfiguration)
.withInput(operationWithCustomizedOperationContextParamRequest)
.withMetricCollector(apiCallMetricCollector)
.withMarshaller(new OperationWithCustomizedOperationContextParamRequestMarshaller(protocolFactory)));
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}

/**
* Invokes the OperationWithNoneAuthType operation.
*
Expand Down