/** * Create an instance of {@link S3FileCopyRequestParamsDto } * */ public S3FileCopyRequestParamsDto createS3FileCopyRequestParamsDto() { return new S3FileCopyRequestParamsDto(); }
.info("Copying S3 object... sourceS3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3Key=\"{}\" targetS3BucketName=\"{}\"", params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(), params.getTargetBucketName()); "totalBytesTransferred={} transferDuration=\"{}\"", params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(), params.getTargetBucketName(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
/** * Test S3 file copy without any errors. */ @Test public void testCopyFile() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID); S3FileTransferResultsDto resultsDto = s3Dao.copyFile(transferDto); assertEquals(Long.valueOf(1L), resultsDto.getTotalFilesTransferred()); }
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); super.copyTo(locator, draftCopy, strategy); if (draftCopy instanceof S3FileCopyRequestParamsDto) { if (sourceBucketNameShouldBeCopiedAndSet == Boolean.TRUE) { String sourceSourceBucketName; sourceSourceBucketName = this.getSourceBucketName(); String copySourceBucketName = ((String) strategy.copy(LocatorUtils.property(locator, "sourceBucketName", sourceSourceBucketName), sourceSourceBucketName, (this.sourceBucketName!= null))); copy.setSourceBucketName(copySourceBucketName); } else { if (sourceBucketNameShouldBeCopiedAndSet == Boolean.FALSE) { if (targetBucketNameShouldBeCopiedAndSet == Boolean.TRUE) { String sourceTargetBucketName; sourceTargetBucketName = this.getTargetBucketName(); String copyTargetBucketName = ((String) strategy.copy(LocatorUtils.property(locator, "targetBucketName", sourceTargetBucketName), sourceTargetBucketName, (this.targetBucketName!= null))); copy.setTargetBucketName(copyTargetBucketName); } else { if (targetBucketNameShouldBeCopiedAndSet == Boolean.FALSE) { if (sourceObjectKeyShouldBeCopiedAndSet == Boolean.TRUE) { String sourceSourceObjectKey; sourceSourceObjectKey = this.getSourceObjectKey(); String copySourceObjectKey = ((String) strategy.copy(LocatorUtils.property(locator, "sourceObjectKey", sourceSourceObjectKey), sourceSourceObjectKey, (this.sourceObjectKey!= null))); copy.setSourceObjectKey(copySourceObjectKey); } else { if (sourceObjectKeyShouldBeCopiedAndSet == Boolean.FALSE) { if (targetObjectKeyShouldBeCopiedAndSet == Boolean.TRUE) {
S3FileCopyRequestParamsDto params = new S3FileCopyRequestParamsDto(); params.setSourceBucketName(completeUploadSingleParamsDto.getSourceBucketName()); params.setTargetBucketName(completeUploadSingleParamsDto.getTargetBucketName()); params.setSourceObjectKey(completeUploadSingleParamsDto.getSourceFilePath()); params.setTargetObjectKey(completeUploadSingleParamsDto.getTargetFilePath()); params.setKmsKeyId(completeUploadSingleParamsDto.getKmsKeyId()); params.setHttpProxyHost(completeUploadSingleParamsDto.getAwsParams().getHttpProxyHost()); params.setHttpProxyPort(completeUploadSingleParamsDto.getAwsParams().getHttpProxyPort());
/** * Test S3 file copy without a KMS ID specified. */ @Test public void testCopyFileNoKmsId() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); // Perform an S3 file copy operation when KMS ID value is not specified. for (String kmsId : Arrays.asList(BLANK_TEXT, null)) { S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(kmsId); S3FileTransferResultsDto resultsDto = s3Dao.copyFile(transferDto); assertEquals(Long.valueOf(1L), resultsDto.getTotalFilesTransferred()); } }
S3FileCopyRequestParamsDto params = new S3FileCopyRequestParamsDto(); params.setSourceBucketName(completeUploadSingleParamsDto.getSourceBucketName()); params.setTargetBucketName(completeUploadSingleParamsDto.getTargetBucketName()); params.setSourceObjectKey(completeUploadSingleParamsDto.getSourceFilePath()); params.setTargetObjectKey(completeUploadSingleParamsDto.getTargetFilePath()); params.setKmsKeyId(completeUploadSingleParamsDto.getKmsKeyId()); params.setHttpProxyHost(completeUploadSingleParamsDto.getAwsParams().getHttpProxyHost()); params.setHttpProxyPort(completeUploadSingleParamsDto.getAwsParams().getHttpProxyPort());
/** * Test S3 file copy with an invalid KMS Id that throws an IllegalStateException because no AmazonServiceException was found. */ @Test public void testCopyFileInvalidKmsIdIllegalStateException() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); try { S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID_FAILED_TRANSFER_NO_EXCEPTION); s3Dao.copyFile(transferDto); fail("An IllegalStateException was expected but not thrown."); } catch (IllegalStateException ex) { assertEquals("Invalid IllegalStateException message returned.", "The transfer operation \"" + MockS3OperationsImpl.MOCK_TRANSFER_DESCRIPTION + "\" failed for an unknown reason.", ex.getMessage()); } }
@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())); } // Otherwise, specify the server-side encryption algorithm for encrypting the object using AWS-managed keys. else { ObjectMetadata metadata = new ObjectMetadata(); metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(metadata); } return s3Operations.copyFile(copyObjectRequest, transferManager); } });
public Object createNewInstance() { return new S3FileCopyRequestParamsDto(); }
/** * Test S3 file copy with an invalid KMS Id that will result in a cancelled transfer. */ @Test public void testCopyFileInvalidKmsIdCancelled() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); try { S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID_CANCELED_TRANSFER); s3Dao.copyFile(transferDto); fail("An IllegalStateException was expected but not thrown."); } catch (IllegalStateException ex) { assertEquals("Invalid IllegalStateException message returned.", "The transfer operation \"" + MockS3OperationsImpl.MOCK_TRANSFER_DESCRIPTION + "\" did not complete successfully. " + "Current state: \"" + Transfer.TransferState.Canceled + "\".", ex.getMessage()); } }
.info("Copying S3 object... sourceS3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3Key=\"{}\" targetS3BucketName=\"{}\"", params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(), params.getTargetBucketName()); "totalBytesTransferred={} transferDuration=\"{}\"", params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(), params.getTargetBucketName(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
/** * Returns a new {@link org.finra.herd.model.dto.S3FileCopyRequestParamsDto} with proxy host and port populated from the configuration. * * @return {@link org.finra.herd.model.dto.S3FileCopyRequestParamsDto} with proxy host and port. */ public S3FileCopyRequestParamsDto getS3FileCopyRequestParamsDto() { S3FileCopyRequestParamsDto params = new S3FileCopyRequestParamsDto(); // Update the parameters with proxy host and port retrieved from the configuration. setProxyHostAndPort(params); return params; }
/** * Test S3 file copy with an invalid KMS Id. This should throw an AmazonServiceException. */ @Test public void testCopyFileInvalidKmsId() throws InterruptedException { // Put a 1 byte file in S3. s3Operations .putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null); try { S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto(); transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName()); transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName()); transferDto.setSourceObjectKey(TARGET_S3_KEY); transferDto.setTargetObjectKey(TARGET_S3_KEY); transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID_FAILED_TRANSFER); s3Dao.copyFile(transferDto); fail("An AmazonServiceException was expected but not thrown."); } catch (AmazonServiceException ex) { Assert.assertTrue("Invalid AmazonServiceException message returned.", ex.getMessage().contains("Key '" + MockS3OperationsImpl.MOCK_KMS_ID_FAILED_TRANSFER + "' does not exist")); } }
@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())); } // Otherwise, specify the server-side encryption algorithm for encrypting the object using AWS-managed keys. else { ObjectMetadata metadata = new ObjectMetadata(); metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); copyObjectRequest.setNewObjectMetadata(metadata); } return s3Operations.copyFile(copyObjectRequest, transferManager); } });
/** * Returns a new {@link org.finra.herd.model.dto.S3FileCopyRequestParamsDto} with proxy host and port populated from the configuration. * * @return {@link org.finra.herd.model.dto.S3FileCopyRequestParamsDto} with proxy host and port. */ public S3FileCopyRequestParamsDto getS3FileCopyRequestParamsDto() { S3FileCopyRequestParamsDto params = new S3FileCopyRequestParamsDto(); // Update the parameters with proxy host and port retrieved from the configuration. setProxyHostAndPort(params); return params; }
S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto(); s3FileCopyRequestParamsDto.setSourceBucketName("sourceBucketName"); s3FileCopyRequestParamsDto.setSourceObjectKey("sourceObjectKey"); s3FileCopyRequestParamsDto.setTargetBucketName("targetBucketName"); s3FileCopyRequestParamsDto.setTargetObjectKey("targetObjectKey"); s3FileCopyRequestParamsDto.setKmsKeyId("kmsKeyId");
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { super.appendFields(locator, buffer, strategy); { String theSourceBucketName; theSourceBucketName = this.getSourceBucketName(); strategy.appendField(locator, this, "sourceBucketName", buffer, theSourceBucketName, (this.sourceBucketName!= null)); } { String theTargetBucketName; theTargetBucketName = this.getTargetBucketName(); strategy.appendField(locator, this, "targetBucketName", buffer, theTargetBucketName, (this.targetBucketName!= null)); } { String theSourceObjectKey; theSourceObjectKey = this.getSourceObjectKey(); strategy.appendField(locator, this, "sourceObjectKey", buffer, theSourceObjectKey, (this.sourceObjectKey!= null)); } { String theTargetObjectKey; theTargetObjectKey = this.getTargetObjectKey(); strategy.appendField(locator, this, "targetObjectKey", buffer, theTargetObjectKey, (this.targetObjectKey!= null)); } return buffer; }
@Override public S3FileCopyRequestParamsDto build() { if (_storedValue == null) { return this.init(new S3FileCopyRequestParamsDto()); } else { return ((S3FileCopyRequestParamsDto) _storedValue); } }
S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto(); s3FileCopyRequestParamsDto.setSourceBucketName("sourceBucketName"); s3FileCopyRequestParamsDto.setSourceObjectKey("sourceObjectKey"); s3FileCopyRequestParamsDto.setTargetBucketName("targetBucketName"); s3FileCopyRequestParamsDto.setTargetObjectKey("targetObjectKey"); s3FileCopyRequestParamsDto.setKmsKeyId("kmsKeyId");