com.amazonaws.services.s3.model.CopyObjectResult Java Examples

The following examples show how to use com.amazonaws.services.s3.model.CopyObjectResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: S3FileSystem.java    From beam with Apache License 2.0 6 votes vote down vote up
@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(options.getS3StorageClass());
  copyObjectRequest.setSourceSSECustomerKey(options.getSSECustomerKey());
  copyObjectRequest.setDestinationSSECustomerKey(options.getSSECustomerKey());
  return amazonS3.get().copyObject(copyObjectRequest);
}
 
Example #2
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private void testAtomicCopy(S3Options options) {
  S3FileSystem s3FileSystem = buildMockedS3FileSystem(options);

  S3ResourceId sourcePath = S3ResourceId.fromUri("s3://bucket/from");
  S3ResourceId destinationPath = S3ResourceId.fromUri("s3://bucket/to");

  CopyObjectResult copyObjectResult = new CopyObjectResult();
  if (getSSECustomerKeyMd5(options) != null) {
    copyObjectResult.setSSECustomerKeyMd5(getSSECustomerKeyMd5(options));
  }
  CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(
          sourcePath.getBucket(),
          sourcePath.getKey(),
          destinationPath.getBucket(),
          destinationPath.getKey());
  copyObjectRequest.setSourceSSECustomerKey(options.getSSECustomerKey());
  copyObjectRequest.setDestinationSSECustomerKey(options.getSSECustomerKey());
  when(s3FileSystem.getAmazonS3Client().copyObject(any(CopyObjectRequest.class)))
      .thenReturn(copyObjectResult);
  assertEquals(
      getSSECustomerKeyMd5(options),
      s3FileSystem.getAmazonS3Client().copyObject(copyObjectRequest).getSSECustomerKeyMd5());

  ObjectMetadata sourceS3ObjectMetadata = new ObjectMetadata();
  s3FileSystem.atomicCopy(sourcePath, destinationPath, sourceS3ObjectMetadata);

  verify(s3FileSystem.getAmazonS3Client(), times(2)).copyObject(any(CopyObjectRequest.class));
}
 
Example #3
Source File: S3FileManagerImpl.java    From entrada with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean move(String src, String dst, boolean archive) {
  log.info("Move: {} to {}", src, dst);
  // s3 has no move operation, so do a copy and delete
  // this is not an atomic operation
  Optional<S3Details> srcDetails = S3Details.from(src);
  Optional<S3Details> dstDetails = S3Details.from(dst);

  if (srcDetails.isPresent() && dstDetails.isPresent()) {
    CopyObjectRequest cor = new CopyObjectRequest(srcDetails.get().getBucket(),
        srcDetails.get().getKey(), dstDetails.get().getBucket(), dstDetails.get().getKey());
    // make sure to set the storage class for file copy
    if (archive) {
      // set class for archive file
      cor.setStorageClass(StorageClass.fromValue(StringUtils.upperCase(archiveStorageClass)));
    } else {
      // set class for parquet files
      cor.setStorageClass(StorageClass.fromValue(StringUtils.upperCase(uploadStorageClass)));
    }
    try {
      CopyObjectResult r = amazonS3.copyObject(cor);

      if (Objects.nonNull(r.getETag())) {
        // copy ok, delete src
        amazonS3.deleteObject(srcDetails.get().getBucket(), srcDetails.get().getKey());
      }

      return true;
    } catch (Exception e) {
      log.error("Error during copying {} to ", src, dst, e);
    }
  }
  return false;
}
 
Example #4
Source File: S3KeyCopyingTOCPayloadHandler.java    From s3-bucket-loader with Apache License 2.0 5 votes vote down vote up
@Override
public void handlePayload(TOCPayload payload, WorkerState workerState) throws Exception {
	
	TocInfo tocInfo = payload.tocInfo;
	
	String logPrefix = "handlePayload() KeyCopy s3://" + this.sourceS3BucketName + "/" + tocInfo.path + 
			" => s3://" + this.targetS3BucketName +"/"+ tocInfo.path;
	
	try {
	
		CopyObjectRequest copyRequest = new CopyObjectRequest(this.sourceS3BucketName, 
															  tocInfo.path, 
															  this.targetS3BucketName, 
															  tocInfo.path);
		copyRequest.setStorageClass(storageClass);
		// copyRequest.setGeneralProgressListener(this);
		
		if (this.enableServerSideEncryption) {
			copyRequest.putCustomRequestHeader("x-amz-server-side-encryption", "AES256");
		}
		
		CopyObjectResult copyResult = s3Client.copyObject(copyRequest);
		
		logger.debug(logPrefix + " copied OK");
		workerState.addTocPathWritten(new TocPathOpResult(payload.mode, true, tocInfo.path, "s3.copyKey", "OK"));
		
	} catch(Exception e) {
		logger.error(logPrefix + " unexpected ERROR: " + e.getMessage(),e);
		workerState.addTocPathWriteFailure(
				new TocPathOpResult(payload.mode, false, tocInfo.path, "s3.copyKey", logPrefix + " " + e.getMessage()));
	}
	
}
 
Example #5
Source File: AWSS3Service.java    From tutorials with MIT License 5 votes vote down vote up
public CopyObjectResult copyObject(
  String sourceBucketName,
  String sourceKey,
  String destinationBucketName,
  String destinationKey
) {
    return s3client.copyObject(
      sourceBucketName, 
      sourceKey, 
      destinationBucketName, 
      destinationKey
    );
}
 
Example #6
Source File: AWSS3ServiceIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test 
public void whenVerifyingCopyObject_thenCorrect() { 
    CopyObjectResult result = mock(CopyObjectResult.class); 
    when(s3.copyObject(anyString(), anyString(), anyString(), anyString())).thenReturn(result); 
 
    assertThat(service.copyObject(BUCKET_NAME, KEY_NAME, BUCKET_NAME2, KEY_NAME2)).isEqualTo(result); 
    verify(s3).copyObject(BUCKET_NAME, KEY_NAME, BUCKET_NAME2, KEY_NAME2);
}
 
Example #7
Source File: EncryptingAmazonS3Client.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public CopyObjectResult copyObject(final CopyObjectRequest request) {
  encrypter.addEncryption(request);
  return super.copyObject(request);
}
 
Example #8
Source File: EncryptingAmazonS3Client.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public CopyObjectResult copyObject(final String sourceBucketName, final String sourceKey,
                                   final String destinationBucketName, final String destinationKey) {
  return copyObject(new CopyObjectRequest(sourceBucketName, sourceKey, destinationBucketName, destinationKey));
}
 
Example #9
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public CopyObjectResult copyObject(String srcBucketName, String srcKey, String destBucketName,
    String destKey) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #10
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public CopyObjectResult copyObject(CopyObjectRequest cpObjReq) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #11
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName,
    String destinationKey) throws AmazonClientException, AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}
 
Example #12
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest) throws AmazonClientException,
    AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}