Skip to content

Commit b78f5b3

Browse files
committed
Fix CRT/SDK POJO conversion and add more tests
1 parent 371b0ef commit b78f5b3

File tree

6 files changed

+586
-258
lines changed

6 files changed

+586
-258
lines changed

services-custom/s3-transfer-manager/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ S3TransferManager transferManager =
4545
To download an object, you just need to provide the destion file path and the `GetObjectRequest` that should be used for the download.
4646

4747
```java
48-
Download download = transferManager.download(b -> b.destination(path)
48+
Download download =
49+
transferManager.download(b -> b.destination(path)
4950
.getObjectRequest(r -> r.bucket("bucket")
5051
.key("key")));
5152
download.completionFuture().join();

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/CrtResponseDataConsumerAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public void onResponse(GetObjectOutput output) {
7373
return;
7474
}
7575

76-
GetObjectResponse response = S3CrtUtils.adaptGetObjectOutput(output,
77-
headerHandler.sdkHttpResponseFuture().join());
76+
GetObjectResponse response = S3CrtPojoConversion.fromCrtGetObjectOutput(output,
77+
headerHandler.sdkHttpResponseFuture().join());
7878
transformer.onResponse(response);
7979
transformer.onStream(publisher);
8080
}

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/DefaultS3CrtAsyncClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public DefaultS3CrtAsyncClient(DefaultS3CrtClientBuilder builder) {
4545
}
4646

4747
if (builder.credentialsProvider() != null) {
48-
configBuilder.credentialsProvider(S3CrtUtils.createCrtCredentialsProvider(builder.credentialsProvider()));
48+
configBuilder.credentialsProvider(S3CrtPojoConversion.createCrtCredentialsProvider(builder.credentialsProvider()));
4949
}
5050
configuration = configBuilder.build();
5151

@@ -62,7 +62,7 @@ public <ReturnT> CompletableFuture<ReturnT> getObject(
6262
GetObjectRequest getObjectRequest, AsyncResponseTransformer<GetObjectResponse, ReturnT> asyncResponseTransformer) {
6363

6464
CompletableFuture<ReturnT> future = new CompletableFuture<>();
65-
com.amazonaws.s3.model.GetObjectRequest crtGetObjectRequest = S3CrtUtils.toCrtGetObjectRequest(getObjectRequest);
65+
com.amazonaws.s3.model.GetObjectRequest crtGetObjectRequest = S3CrtPojoConversion.toCrtGetObjectRequest(getObjectRequest);
6666
CrtResponseDataConsumerAdapter<ReturnT> adapter = new CrtResponseDataConsumerAdapter<>(asyncResponseTransformer);
6767

6868
CompletableFuture<ReturnT> adapterFuture = adapter.transformerFuture();
@@ -83,7 +83,7 @@ public <ReturnT> CompletableFuture<ReturnT> getObject(
8383

8484
@Override
8585
public CompletableFuture<PutObjectResponse> putObject(PutObjectRequest putObjectRequest, AsyncRequestBody requestBody) {
86-
com.amazonaws.s3.model.PutObjectRequest adaptedRequest = S3CrtUtils.toCrtPutObjectRequest(putObjectRequest);
86+
com.amazonaws.s3.model.PutObjectRequest adaptedRequest = S3CrtPojoConversion.toCrtPutObjectRequest(putObjectRequest);
8787

8888
if (adaptedRequest.contentLength() == null && requestBody.contentLength().isPresent()) {
8989
adaptedRequest = adaptedRequest.toBuilder().contentLength(requestBody.contentLength().get())
@@ -93,7 +93,7 @@ public CompletableFuture<PutObjectResponse> putObject(PutObjectRequest putObject
9393
CompletableFuture<PutObjectOutput> putObjectOutputCompletableFuture = s3NativeClient.putObject(adaptedRequest,
9494
adaptToDataSupplier(requestBody));
9595

96-
return putObjectOutputCompletableFuture.thenApply(S3CrtUtils::fromCrtPutObjectOutput);
96+
return putObjectOutputCompletableFuture.thenApply(S3CrtPojoConversion::fromCrtPutObjectOutput);
9797
}
9898

9999
@Override
Lines changed: 111 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@
4747
import software.amazon.awssdk.services.s3.model.S3ResponseMetadata;
4848
import software.amazon.awssdk.utils.http.SdkHttpUtils;
4949

50+
/**
51+
* Helper class to convert CRT POJOs to SDK POJOs and vice versa
52+
*/
53+
//TODO: codegen this class in the future
5054
@SdkInternalApi
51-
public final class S3CrtUtils {
55+
public final class S3CrtPojoConversion {
5256
private static final String HEADER_USER_AGENT = "User-Agent";
5357
private static final String USER_AGENT_STRING = SdkUserAgent.create().userAgent() + " ft/s3-transfer";
5458

55-
private S3CrtUtils() {
59+
private S3CrtPojoConversion() {
5660
}
5761

58-
// TODO: Add more adapters if there are any new crt credentials providers.
59-
62+
// TODO: Move this method out of this util class and change to use DelegateCredentialsProvider
6063
/**
6164
* Adapter between the sdk credentials provider and the crt credentials provider.
6265
*/
@@ -74,16 +77,29 @@ public static CredentialsProvider createCrtCredentialsProvider(AwsCredentialsPro
7477
.build();
7578
}
7679

77-
// TODO: codegen and add tests
7880
public static com.amazonaws.s3.model.GetObjectRequest toCrtGetObjectRequest(GetObjectRequest request) {
7981
com.amazonaws.s3.model.GetObjectRequest.Builder getObjectBuilder =
8082
com.amazonaws.s3.model.GetObjectRequest.builder()
81-
.key(request.key())
8283
.bucket(request.bucket())
83-
.expectedBucketOwner(request.expectedBucketOwner())
8484
.ifMatch(request.ifMatch())
8585
.ifModifiedSince(request.ifModifiedSince())
86-
.ifNoneMatch(request.ifNoneMatch());
86+
.ifNoneMatch(request.ifNoneMatch())
87+
.ifUnmodifiedSince(request.ifUnmodifiedSince())
88+
.key(request.key())
89+
.range(request.range())
90+
.responseCacheControl(request.responseCacheControl())
91+
.responseContentDisposition(request.responseContentDisposition())
92+
.responseContentEncoding(request.responseContentEncoding())
93+
.responseContentLanguage(request.responseContentLanguage())
94+
.responseContentType(request.responseContentType())
95+
.responseExpires(request.responseExpires())
96+
.versionId(request.versionId())
97+
.sSECustomerAlgorithm(request.sseCustomerAlgorithm())
98+
.sSECustomerKey(request.sseCustomerKey())
99+
.sSECustomerKeyMD5(request.sseCustomerKeyMD5())
100+
.requestPayer(RequestPayer.fromValue(request.requestPayerAsString()))
101+
.partNumber(request.partNumber())
102+
.expectedBucketOwner(request.expectedBucketOwner());
87103

88104
processRequestOverrideConfiguration(request.overrideConfiguration().orElse(null),
89105
getObjectBuilder::customQueryParameters);
@@ -95,36 +111,70 @@ public static com.amazonaws.s3.model.GetObjectRequest toCrtGetObjectRequest(GetO
95111
}
96112

97113
// TODO: codegen and add tests
98-
public static GetObjectResponse adaptGetObjectOutput(GetObjectOutput response, SdkHttpResponse sdkHttpResponse) {
114+
public static GetObjectResponse fromCrtGetObjectOutput(GetObjectOutput response, SdkHttpResponse sdkHttpResponse) {
99115
S3ResponseMetadata s3ResponseMetadata = createS3ResponseMetadata(sdkHttpResponse);
100116

101-
return (GetObjectResponse) GetObjectResponse.builder()
102-
.bucketKeyEnabled(response.bucketKeyEnabled())
103-
.acceptRanges(response.acceptRanges())
104-
.contentDisposition(response.contentDisposition())
105-
.cacheControl(response.cacheControl())
106-
.contentEncoding(response.contentEncoding())
107-
.contentLanguage(response.contentLanguage())
108-
.contentRange(response.contentRange())
109-
.contentLength(response.contentLength())
110-
.contentType(response.contentType())
111-
.deleteMarker(response.deleteMarker())
112-
.eTag(response.eTag())
113-
.expiration(response.expiration())
114-
.expires(response.expires())
115-
.lastModified(response.lastModified())
116-
.metadata(response.metadata())
117-
.responseMetadata(s3ResponseMetadata)
118-
.sdkHttpResponse(sdkHttpResponse)
119-
.build();
117+
GetObjectResponse.Builder builder = GetObjectResponse.builder()
118+
.deleteMarker(response.deleteMarker())
119+
.acceptRanges(response.acceptRanges())
120+
.expiration(response.expiration())
121+
.restore(response.restore())
122+
.lastModified(response.lastModified())
123+
.contentLength(response.contentLength())
124+
.eTag(response.eTag())
125+
.missingMeta(response.missingMeta())
126+
.versionId(response.versionId())
127+
.cacheControl(response.cacheControl())
128+
.contentDisposition(response.contentDisposition())
129+
.contentEncoding(response.contentEncoding())
130+
.contentLanguage(response.contentLanguage())
131+
.contentRange(response.contentRange())
132+
.contentType(response.contentType())
133+
.expires(response.expires())
134+
.websiteRedirectLocation(response.websiteRedirectLocation())
135+
.metadata(response.metadata())
136+
.sseCustomerAlgorithm(response.sSECustomerAlgorithm())
137+
.sseCustomerKeyMD5(response.sSECustomerKeyMD5())
138+
.ssekmsKeyId(response.sSEKMSKeyId())
139+
.bucketKeyEnabled(response.bucketKeyEnabled())
140+
.partsCount(response.partsCount())
141+
.tagCount(response.tagCount())
142+
.objectLockRetainUntilDate(response.objectLockRetainUntilDate());
143+
144+
if (response.serverSideEncryption() != null) {
145+
builder.serverSideEncryption(response.serverSideEncryption().name());
146+
}
147+
148+
if (response.storageClass() != null) {
149+
builder.storageClass(response.storageClass().name());
150+
}
151+
152+
if (response.requestCharged() != null) {
153+
builder.requestCharged(response.requestCharged().name());
154+
}
155+
156+
if (response.replicationStatus() != null) {
157+
builder.replicationStatus(response.replicationStatus().name());
158+
}
159+
160+
if (response.objectLockMode() != null) {
161+
builder.objectLockMode(response.objectLockMode().name());
162+
}
163+
164+
if (response.objectLockLegalHoldStatus() != null) {
165+
builder.objectLockLegalHoldStatus(response.objectLockLegalHoldStatus().name());
166+
}
167+
168+
return (GetObjectResponse) builder.responseMetadata(s3ResponseMetadata)
169+
.sdkHttpResponse(sdkHttpResponse)
170+
.build();
171+
120172
}
121173

122-
// TODO: codegen and add tests
123174
public static com.amazonaws.s3.model.PutObjectRequest toCrtPutObjectRequest(PutObjectRequest sdkPutObject) {
124175
com.amazonaws.s3.model.PutObjectRequest.Builder putObjectBuilder =
125176
com.amazonaws.s3.model.PutObjectRequest.builder()
126177
.contentLength(sdkPutObject.contentLength())
127-
.aCL(ObjectCannedACL.fromValue(sdkPutObject.aclAsString()))
128178
.bucket(sdkPutObject.bucket())
129179
.key(sdkPutObject.key())
130180
.bucketKeyEnabled(sdkPutObject.bucketKeyEnabled())
@@ -141,23 +191,42 @@ public static com.amazonaws.s3.model.PutObjectRequest toCrtPutObjectRequest(PutO
141191
.grantReadACP(sdkPutObject.grantReadACP())
142192
.grantWriteACP(sdkPutObject.grantWriteACP())
143193
.metadata(sdkPutObject.metadata())
144-
.objectLockLegalHoldStatus(ObjectLockLegalHoldStatus.fromValue(
145-
sdkPutObject.objectLockLegalHoldStatusAsString()))
146-
.objectLockMode(ObjectLockMode.fromValue(
147-
sdkPutObject.objectLockModeAsString()))
148194
.objectLockRetainUntilDate(sdkPutObject.objectLockRetainUntilDate())
149-
.requestPayer(RequestPayer.fromValue(sdkPutObject.requestPayerAsString()))
150-
.serverSideEncryption(ServerSideEncryption.fromValue(
151-
sdkPutObject.requestPayerAsString()))
152195
.sSECustomerAlgorithm(sdkPutObject.sseCustomerAlgorithm())
153196
.sSECustomerKey(sdkPutObject.sseCustomerKey())
154197
.sSECustomerKeyMD5(sdkPutObject.sseCustomerKeyMD5())
155198
.sSEKMSEncryptionContext(sdkPutObject.ssekmsEncryptionContext())
156199
.sSEKMSKeyId(sdkPutObject.ssekmsKeyId())
157-
.storageClass(StorageClass.fromValue(sdkPutObject.storageClassAsString()))
158200
.tagging(sdkPutObject.tagging())
159201
.websiteRedirectLocation(sdkPutObject.websiteRedirectLocation());
160202

203+
if (sdkPutObject.acl() != null) {
204+
putObjectBuilder.aCL(ObjectCannedACL.fromValue(sdkPutObject.acl().name()));
205+
}
206+
207+
if (sdkPutObject.objectLockLegalHoldStatus() != null) {
208+
putObjectBuilder.objectLockLegalHoldStatus(ObjectLockLegalHoldStatus.fromValue(
209+
sdkPutObject.objectLockLegalHoldStatus().name()));
210+
}
211+
212+
if (sdkPutObject.objectLockMode() != null) {
213+
putObjectBuilder.objectLockMode(ObjectLockMode.fromValue(
214+
sdkPutObject.objectLockMode().name()));
215+
}
216+
217+
if (sdkPutObject.requestPayer() != null) {
218+
putObjectBuilder.requestPayer(RequestPayer.fromValue(sdkPutObject.requestPayer().name()));
219+
}
220+
221+
if (sdkPutObject.serverSideEncryption() != null) {
222+
putObjectBuilder.serverSideEncryption(ServerSideEncryption.fromValue(
223+
sdkPutObject.serverSideEncryption().name()));
224+
}
225+
226+
if (sdkPutObject.storageClass() != null) {
227+
putObjectBuilder.storageClass(StorageClass.fromValue(
228+
sdkPutObject.storageClass().name()));
229+
}
161230

162231
processRequestOverrideConfiguration(sdkPutObject.overrideConfiguration().orElse(null),
163232
putObjectBuilder::customQueryParameters);
@@ -182,11 +251,11 @@ public static PutObjectResponse fromCrtPutObjectOutput(PutObjectOutput crtPutObj
182251
.versionId(crtPutObjectOutput.versionId());
183252

184253
if (crtPutObjectOutput.requestCharged() != null) {
185-
builder.requestCharged(crtPutObjectOutput.requestCharged().value());
254+
builder.requestCharged(crtPutObjectOutput.requestCharged().name());
186255
}
187256

188257
if (crtPutObjectOutput.serverSideEncryption() != null) {
189-
builder.serverSideEncryption(crtPutObjectOutput.serverSideEncryption().value());
258+
builder.serverSideEncryption(crtPutObjectOutput.serverSideEncryption().name());
190259
}
191260

192261
return builder.build();
@@ -204,11 +273,11 @@ private static void throwExceptionForUnsupportedConfigurations(AwsRequestOverrid
204273
}
205274

206275
if (overrideConfiguration.signer().isPresent()) {
207-
throw new UnsupportedOperationException("signer are not supported");
276+
throw new UnsupportedOperationException("signer is not supported");
208277
}
209278

210279
if (!overrideConfiguration.apiNames().isEmpty()) {
211-
throw new UnsupportedOperationException("apiNames are not supported");
280+
throw new UnsupportedOperationException("apiNames is not supported");
212281
}
213282

214283
if (overrideConfiguration.apiCallAttemptTimeout().isPresent()) {

0 commit comments

Comments
 (0)