use of software.amazon.awssdk.services.s3.model.CopyObjectRequest in project herd by FINRAOS.
the class S3DaoImpl method copyFile.
@Override
public S3FileTransferResultsDto copyFile(final S3FileCopyRequestParamsDto params) throws InterruptedException {
LOGGER.info("Copying S3 object... sourceS3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3Key=\"{}\" targetS3BucketName=\"{}\"", params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(), params.getTargetBucketName());
// Perform the copy.
S3FileTransferResultsDto results = performTransfer(params, new Transferer() {
@Override
public Transfer performTransfer(TransferManager transferManager) {
// Create a copy request.
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(params.getSourceBucketName(), params.getSourceObjectKey(), params.getTargetBucketName(), params.getTargetObjectKey());
// If KMS Key ID is specified, set the AWS Key Management System parameters to be used to encrypt the object.
if (StringUtils.isNotBlank(params.getKmsKeyId())) {
copyObjectRequest.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(params.getKmsKeyId()));
} else // Otherwise, specify the server-side encryption algorithm for encrypting the object using AWS-managed keys.
{
ObjectMetadata metadata = new ObjectMetadata();
metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
copyObjectRequest.setNewObjectMetadata(metadata);
}
return s3Operations.copyFile(copyObjectRequest, transferManager);
}
});
LOGGER.info("Copied S3 object. sourceS3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3Key=\"{}\" targetS3BucketName=\"{}\" " + "totalBytesTransferred={} transferDuration=\"{}\"", params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(), params.getTargetBucketName(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
logOverallTransferRate(results);
return results;
}
use of software.amazon.awssdk.services.s3.model.CopyObjectRequest in project beam by apache.
the class S3FileSystemTest method testCopy.
private void testCopy(S3FileSystem s3FileSystem, SSECustomerKey sseCustomerKey) throws IOException {
S3ResourceId sourcePath = S3ResourceId.fromUri(s3FileSystem.getScheme() + "://bucket/from");
S3ResourceId destinationPath = S3ResourceId.fromUri(s3FileSystem.getScheme() + "://bucket/to");
HeadObjectResponse.Builder builder = HeadObjectResponse.builder().contentLength(0L);
String sseCustomerKeyMd5 = toMd5(sseCustomerKey);
if (sseCustomerKeyMd5 != null) {
builder.sseCustomerKeyMD5(sseCustomerKeyMd5);
}
HeadObjectResponse headObjectResponse = builder.build();
assertGetObjectHead(s3FileSystem, createObjectHeadRequest(sourcePath, sseCustomerKey), sseCustomerKeyMd5, headObjectResponse);
s3FileSystem.copy(sourcePath, destinationPath);
verify(s3FileSystem.getS3Client(), times(1)).copyObject(any(CopyObjectRequest.class));
// we simulate a big object >= 5GB so it takes the multiPart path
HeadObjectResponse bigHeadObjectResponse = headObjectResponse.toBuilder().contentLength(5_368_709_120L).build();
assertGetObjectHead(s3FileSystem, createObjectHeadRequest(sourcePath, sseCustomerKey), sseCustomerKeyMd5, bigHeadObjectResponse);
try {
s3FileSystem.copy(sourcePath, destinationPath);
} catch (NullPointerException e) {
// ignore failing unmocked path, this is covered by testMultipartCopy test
}
verify(s3FileSystem.getS3Client(), never()).copyObject((CopyObjectRequest) null);
}
use of software.amazon.awssdk.services.s3.model.CopyObjectRequest in project beam by apache.
the class S3FileSystemTest method testAtomicCopy.
private void testAtomicCopy(S3FileSystem s3FileSystem, SSECustomerKey sseCustomerKey) {
S3ResourceId sourcePath = S3ResourceId.fromUri(s3FileSystem.getScheme() + "://bucket/from");
S3ResourceId destinationPath = S3ResourceId.fromUri(s3FileSystem.getScheme() + "://bucket/to");
CopyObjectResult copyObjectResult = new CopyObjectResult();
String sseCustomerKeyMd5 = toMd5(sseCustomerKey);
if (sseCustomerKeyMd5 != null) {
copyObjectResult.setSSECustomerKeyMd5(sseCustomerKeyMd5);
}
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourcePath.getBucket(), sourcePath.getKey(), destinationPath.getBucket(), destinationPath.getKey());
copyObjectRequest.setSourceSSECustomerKey(sseCustomerKey);
copyObjectRequest.setDestinationSSECustomerKey(sseCustomerKey);
when(s3FileSystem.getAmazonS3Client().copyObject(any(CopyObjectRequest.class))).thenReturn(copyObjectResult);
assertEquals(sseCustomerKeyMd5, s3FileSystem.getAmazonS3Client().copyObject(copyObjectRequest).getSSECustomerKeyMd5());
ObjectMetadata sourceS3ObjectMetadata = new ObjectMetadata();
s3FileSystem.atomicCopy(sourcePath, destinationPath, sourceS3ObjectMetadata);
verify(s3FileSystem.getAmazonS3Client(), times(2)).copyObject(any(CopyObjectRequest.class));
}
use of software.amazon.awssdk.services.s3.model.CopyObjectRequest in project beam by apache.
the class S3FileSystem method atomicCopy.
@VisibleForTesting
CopyObjectResult atomicCopy(S3ResourceId sourcePath, S3ResourceId destinationPath, ObjectMetadata sourceObjectMetadata) throws AmazonClientException {
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourcePath.getBucket(), sourcePath.getKey(), destinationPath.getBucket(), destinationPath.getKey());
copyObjectRequest.setNewObjectMetadata(sourceObjectMetadata);
copyObjectRequest.setStorageClass(config.getS3StorageClass());
copyObjectRequest.setSourceSSECustomerKey(config.getSSECustomerKey());
copyObjectRequest.setDestinationSSECustomerKey(config.getSSECustomerKey());
return amazonS3.get().copyObject(copyObjectRequest);
}
use of software.amazon.awssdk.services.s3.model.CopyObjectRequest in project stocator by SparkTC.
the class COSAPIClient method copyFile.
/**
* Copy a single object in the bucket via a COPY operation.
* @param srcKey source object path
* @param dstKey destination object path
* @param size object size
* @throws AmazonClientException on failures inside the AWS SDK
* @throws InterruptedIOException the operation was interrupted
* @throws IOException Other IO problems
*/
private void copyFile(String srcKey, String dstKey, long size) throws IOException, InterruptedIOException, AmazonClientException {
LOG.debug("copyFile {} -> {} ", srcKey, dstKey);
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(mBucket, srcKey, mBucket, dstKey);
try {
ObjectMetadata srcmd = getObjectMetadata(srcKey);
if (srcmd != null) {
copyObjectRequest.setNewObjectMetadata(srcmd);
}
ProgressListener progressListener = new ProgressListener() {
public void progressChanged(ProgressEvent progressEvent) {
switch(progressEvent.getEventType()) {
case TRANSFER_PART_COMPLETED_EVENT:
break;
default:
break;
}
}
};
Copy copy = transfers.copy(copyObjectRequest);
copy.addProgressListener(progressListener);
try {
copy.waitForCopyResult();
} catch (InterruptedException e) {
throw new InterruptedIOException("Interrupted copying " + srcKey + " to " + dstKey + ", cancelling");
}
} catch (AmazonClientException e) {
throw translateException("copyFile(" + srcKey + ", " + dstKey + ")", srcKey, e);
}
}
Aggregations