Skip to content

Attach crossRegionAccessEnabled as CustomClientParams to a client Builder, also mention of Composers are renamed as decorators #4151

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.awscore.internal.client.ClientComposer;
import software.amazon.awssdk.codegen.model.service.ClientContextParam;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.core.traits.PayloadTrait;
import software.amazon.awssdk.utils.AttributeMap;
Expand Down Expand Up @@ -216,16 +216,16 @@ public class CustomizationConfig {
/**
* Fully qualified name of a class that given the default sync client instance can return the final client instance,
* for instance by decorating the client with specific-purpose implementations of the client interface.
* The class should implement the {@link ClientComposer} interface. See S3 customization.config for an example.
* See S3 customization.config for an example.
*/
private String syncClientComposer;
private String syncClientDecorator;

/**
* Fully qualified name of a class that given the default async client instance can return the final client instance,
* for instance by decorating the client with specific-purpose implementations of the client interface.
* The class should implement the {@link ClientComposer} interface. See S3 customization.config for an example.
* See S3 customization.config for an example.
*/
private String asyncClientComposer;
private String asyncClientDecorator;

/**
* Whether to skip generating endpoint tests from endpoint-tests.json
Expand All @@ -251,6 +251,11 @@ public class CustomizationConfig {
*/
private boolean requiredTraitValidationEnabled = false;

/**
* Customization to attach map of Custom client param configs that can be set on a client builder.
*/
private Map<String, ClientContextParam> customClientContextParams;

private CustomizationConfig() {
}

Expand Down Expand Up @@ -581,20 +586,20 @@ public void setDelegateAsyncClientClass(boolean delegateAsyncClientClass) {
this.delegateAsyncClientClass = delegateAsyncClientClass;
}

public String getSyncClientComposer() {
return syncClientComposer;
public String getSyncClientDecorator() {
return syncClientDecorator;
}

public void setSyncClientComposer(String syncClientComposer) {
this.syncClientComposer = syncClientComposer;
public void setSyncClientDecorator(String syncClientDecorator) {
this.syncClientDecorator = syncClientDecorator;
}

public String getAsyncClientComposer() {
return asyncClientComposer;
public String getAsyncClientDecorator() {
return asyncClientDecorator;
}

public void setAsyncClientComposer(String asyncClientComposer) {
this.asyncClientComposer = asyncClientComposer;
public void setAsyncClientDecorator(String asyncClientDecorator) {
this.asyncClientDecorator = asyncClientDecorator;
}

public boolean isDelegateSyncClientClass() {
Expand Down Expand Up @@ -652,4 +657,12 @@ public boolean isRequiredTraitValidationEnabled() {
public void setRequiredTraitValidationEnabled(boolean requiredTraitValidationEnabled) {
this.requiredTraitValidationEnabled = requiredTraitValidationEnabled;
}

public Map<String, ClientContextParam> getCustomClientContextParams() {
return customClientContextParams;
}

public void setCustomClientContextParams(Map<String, ClientContextParam> customClientContextParams) {
this.customClientContextParams = customClientContextParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,17 @@ public String getSdkResponseBaseClassName() {
}
}

public Optional<String> syncClientComposerClassName() {
if (customizationConfig.getSyncClientComposer() != null) {
return Optional.of(customizationConfig.getSyncClientComposer());
public Optional<String> syncClientDecoratorClassName() {
if (customizationConfig.getSyncClientDecorator() != null) {
return Optional.of(customizationConfig.getSyncClientDecorator());
}
return Optional.empty();
}

public Optional<String> asyncClientComposerClassName() {
String asyncClientComposer = customizationConfig.getAsyncClientComposer();
if (customizationConfig.getAsyncClientComposer() != null) {
return Optional.of(asyncClientComposer);
public Optional<String> asyncClientDecoratorClassName() {
String asyncClientDecorator = customizationConfig.getAsyncClientDecorator();
if (customizationConfig.getAsyncClientDecorator() != null) {
return Optional.of(asyncClientDecorator);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.internal.client.ClientComposer;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.PoetExtension;
Expand Down Expand Up @@ -148,11 +147,9 @@ private MethodSpec buildClientMethod() {

builder.addStatement("$1T client = new $2T(serviceClientConfiguration, clientConfiguration)",
clientInterfaceName, clientClassName);
if (model.asyncClientComposerClassName().isPresent()) {
builder.addStatement("$1T composer = new $2T()",
ClientComposer.class,
PoetUtils.classNameFromFqcn(model.asyncClientComposerClassName().get()));
builder.addStatement("return ($T) composer.compose(client, clientConfiguration)", clientInterfaceName);
if (model.asyncClientDecoratorClassName().isPresent()) {
builder.addStatement("return new $T().decorate(client, clientConfiguration, clientContextParams.copy().build())",
PoetUtils.classNameFromFqcn(model.asyncClientDecoratorClassName().get()));
} else {
builder.addStatement("return client");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public TypeSpec poetSpec() {
});
}

if (hasSdkClientContextParams()) {
model.getCustomizationConfig().getCustomClientContextParams().forEach((n, m) -> {
builder.addMethod(clientContextParamSetter(n, m));
});
}

if (model.getCustomizationConfig().getServiceConfig().getClassName() != null) {
builder.addMethod(setServiceConfigurationMethod())
.addMethod(beanStyleSetServiceConfigurationMethod());
Expand Down Expand Up @@ -609,6 +615,12 @@ private boolean hasClientContextParams() {
return clientContextParams != null && !clientContextParams.isEmpty();
}

private boolean hasSdkClientContextParams() {
return model.getCustomizationConfig() != null
&& model.getCustomizationConfig().getCustomClientContextParams() != null
&& !model.getCustomizationConfig().getCustomClientContextParams().isEmpty();
}

private MethodSpec validateClientOptionsMethod() {
MethodSpec.Builder builder = MethodSpec.methodBuilder("validateClientOptions")
.addModifiers(PROTECTED, Modifier.STATIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public TypeSpec poetSpec() {
});
}

if (hasSdkClientContextParams()) {
model.getCustomizationConfig().getCustomClientContextParams().forEach((n, m) -> {
builder.addMethod(clientContextParamSetter(n, m));
});
}

if (generateTokenProviderMethod()) {
builder.addMethod(tokenProviderMethod());
}
Expand Down Expand Up @@ -193,4 +199,10 @@ public ClassName className() {
private boolean hasClientContextParams() {
return model.getClientContextParams() != null && !model.getClientContextParams().isEmpty();
}

private boolean hasSdkClientContextParams() {
return model.getCustomizationConfig() != null
&& model.getCustomizationConfig().getCustomClientContextParams() != null
&& !model.getCustomizationConfig().getCustomClientContextParams().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.internal.client.ClientComposer;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.PoetExtension;
Expand Down Expand Up @@ -141,16 +140,13 @@ private MethodSpec buildClientMethod() {
.addStatement("$T serviceClientConfiguration = initializeServiceClientConfig"
+ "(clientConfiguration)",
serviceConfigClassName);

addQueryProtocolInterceptors(builder);

builder.addStatement("$1T client = new $2T(serviceClientConfiguration, clientConfiguration)",
clientInterfaceName, clientClassName);
if (model.syncClientComposerClassName().isPresent()) {
builder.addStatement("$1T composer = new $2T()",
ClientComposer.class,
PoetUtils.classNameFromFqcn(model.syncClientComposerClassName().get()));
builder.addStatement("return ($T) composer.compose(client, clientConfiguration)", clientInterfaceName);
if (model.syncClientDecoratorClassName().isPresent()) {
builder.addStatement("return new $T().decorate(client, clientConfiguration, clientContextParams.copy().build())",
PoetUtils.classNameFromFqcn(model.syncClientDecoratorClassName().get()));
} else {
builder.addStatement("return client");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public TypeSpec poetSpec() {
b.addField(paramDeclaration(n, m));
});

if (model.getCustomizationConfig() != null && model.getCustomizationConfig().getCustomClientContextParams() != null) {
model.getCustomizationConfig().getCustomClientContextParams().forEach((n, m) -> {
b.addField(paramDeclaration(n, m));
});
}

return b.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ public void syncComposedClientBuilderClass() throws Exception {
validateComposedClientGeneration(SyncClientBuilderClass::new, "test-composed-sync-client-builder-class.java");
}

@Test
public void syncComposedDefaultClientBuilderClass() throws Exception {
validateComposedClientGeneration(BaseClientBuilderClass::new, "test-composed-sync-default-client-builder.java");
}

@Test
public void syncHasCrossRegionAccessEnabledPropertyBuilderClass() throws Exception {
validateComposedClientGeneration(BaseClientBuilderInterface::new, "test-customcontextparams-sync-client-builder-class.java");
}


@Test
public void asyncClientBuilderInterface() throws Exception {
validateGeneration(AsyncClientBuilderInterface::new, "test-async-client-builder-interface.java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.internal.client.ClientComposer;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.services.builder.AsyncClientComposer;
import software.amazon.awssdk.services.builder.AsyncClientDecorator;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

/**
Expand Down Expand Up @@ -37,8 +36,7 @@ protected final JsonAsyncClient buildClient() {
this.validateClientOptions(clientConfiguration);
JsonServiceClientConfiguration serviceClientConfiguration = initializeServiceClientConfig(clientConfiguration);
JsonAsyncClient client = new DefaultJsonAsyncClient(serviceClientConfiguration, clientConfiguration);
ClientComposer composer = new AsyncClientComposer();
return (JsonAsyncClient) composer.compose(client, clientConfiguration);
return new AsyncClientDecorator().decorate(client, clientConfiguration, clientContextParams.copy().build());
}

private JsonServiceClientConfiguration initializeServiceClientConfig(SdkClientConfiguration clientConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.internal.client.ClientComposer;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.endpoints.EndpointProvider;
import software.amazon.awssdk.services.builder.SyncClientComposer;
import software.amazon.awssdk.services.builder.SyncClientDecorator;
import software.amazon.awssdk.services.json.endpoints.JsonEndpointProvider;

/**
Expand Down Expand Up @@ -37,8 +36,7 @@ protected final JsonClient buildClient() {
this.validateClientOptions(clientConfiguration);
JsonServiceClientConfiguration serviceClientConfiguration = initializeServiceClientConfig(clientConfiguration);
JsonClient client = new DefaultJsonClient(serviceClientConfiguration, clientConfiguration);
ClientComposer composer = new SyncClientComposer();
return (JsonClient) composer.compose(client, clientConfiguration);
return new SyncClientDecorator().decorate(client, clientConfiguration, clientContextParams.copy().build());
}

private JsonServiceClientConfiguration initializeServiceClientConfig(SdkClientConfiguration clientConfig) {
Expand Down
Loading