Skip to content

Fix CRT client builder #2349

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 1 commit into from
Mar 26, 2021
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 @@ -15,9 +15,14 @@

package software.amazon.awssdk.services.s3;

import java.net.URI;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.SdkPreviewApi;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.regions.Region;

/**
* A builder for creating an instance of {@link S3CrtAsyncClient}. This can be created with the static
Expand All @@ -26,8 +31,25 @@
@SdkPreviewApi
@SdkPublicApi
public interface S3CrtAsyncClientBuilder extends AwsClientBuilder<S3CrtAsyncClientBuilder, S3CrtAsyncClient> {
@Override
S3CrtAsyncClientBuilder credentialsProvider(AwsCredentialsProvider credentialsProvider);

S3CrtAsyncClientBuilder partSizeBytes(long partSizeBytes);
@Override
S3CrtAsyncClientBuilder region(Region region);

S3CrtAsyncClientBuilder maxThroughputGbps(double maxThroughputGbps);
@Override
S3CrtAsyncClientBuilder overrideConfiguration(ClientOverrideConfiguration overrideConfiguration);

@Override
S3CrtAsyncClientBuilder overrideConfiguration(Consumer<ClientOverrideConfiguration.Builder> overrideConfiguration);

@Override
S3CrtAsyncClientBuilder endpointOverride(URI endpointOverride);

S3CrtAsyncClientBuilder partSizeBytes(Long partSizeBytes);

S3CrtAsyncClientBuilder maxThroughputGbps(Double maxThroughputGbps);

@Override
S3CrtAsyncClient build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
import software.amazon.awssdk.crt.auth.credentials.CredentialsProvider;
import software.amazon.awssdk.services.s3.S3CrtAsyncClient;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
Expand All @@ -38,15 +37,25 @@ public final class DefaultS3CrtAsyncClient implements S3CrtAsyncClient {
private final S3NativeClientConfiguration configuration;

public DefaultS3CrtAsyncClient(DefaultS3CrtClientBuilder builder) {
CredentialsProvider credentialsProvider = builder.credentialsProvider() == null ? null :
createCrtCredentialsProvider(builder.credentialsProvider());

this.configuration = S3NativeClientConfiguration.builder()
.credentialsProvider(credentialsProvider)
.signingRegion(builder.region() == null ? null : builder.region().id())
.partSizeBytes(builder.partSizeBytes())
.maxThroughputGbps(builder.maxThroughputGbps())
.build();
S3NativeClientConfiguration.Builder configBuilder = S3NativeClientConfiguration.builder();

if (builder.region() != null) {
configBuilder.signingRegion(builder.region().id());
}

if (builder.credentialsProvider() != null) {
configBuilder.credentialsProvider(createCrtCredentialsProvider(builder.credentialsProvider()));
}

if (builder.maxThroughputGbps() != null) {
configBuilder.maxThroughputGbps(builder.maxThroughputGbps());
}

if (builder.partSizeBytes() != null) {
configBuilder.partSizeBytes(builder.partSizeBytes());
}

configuration = configBuilder.build();

this.s3NativeClient = new S3NativeClient(configuration.signingRegion(),
configuration.clientBootstrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
public final class DefaultS3CrtClientBuilder implements S3CrtAsyncClientBuilder {
private AwsCredentialsProvider credentialsProvider;
private Region region;
private long partSizeBytes;
private double maxThroughputGbps;
private Long partSizeBytes;
private Double maxThroughputGbps;

public AwsCredentialsProvider credentialsProvider() {
return credentialsProvider;
Expand All @@ -39,11 +39,11 @@ public Region region() {
return region;
}

public long partSizeBytes() {
public Long partSizeBytes() {
return partSizeBytes;
}

public double maxThroughputGbps() {
public Double maxThroughputGbps() {
return maxThroughputGbps;
}

Expand Down Expand Up @@ -78,13 +78,13 @@ public S3CrtAsyncClientBuilder endpointOverride(URI endpointOverride) {
}

@Override
public S3CrtAsyncClientBuilder partSizeBytes(long partSizeBytes) {
public S3CrtAsyncClientBuilder partSizeBytes(Long partSizeBytes) {
this.partSizeBytes = partSizeBytes;
return this;
}

@Override
public S3CrtAsyncClientBuilder maxThroughputGbps(double maxThroughputGbps) {
public S3CrtAsyncClientBuilder maxThroughputGbps(Double maxThroughputGbps) {
this.maxThroughputGbps = maxThroughputGbps;
return this;
}
Expand Down