use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testCopyFileInvalidKmsId.
/**
* 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"));
}
}
use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testCopyFileInvalidKmsIdIllegalStateException.
/**
* 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());
}
}
use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testCopyFileInvalidKmsIdCancelled.
/**
* 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());
}
}
use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class S3ServiceTest method testCopyFile.
@Test
public void testCopyFile() throws InterruptedException {
// Create an S3 file copy request parameters DTO.
S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto();
// Create an S3 file transfer result DTO.
S3FileTransferResultsDto s3FileTransferResultsDto = new S3FileTransferResultsDto();
// Mock the external calls.
when(s3Dao.copyFile(s3FileCopyRequestParamsDto)).thenReturn(s3FileTransferResultsDto);
// Call the method under test.
S3FileTransferResultsDto result = s3Service.copyFile(s3FileCopyRequestParamsDto);
// Verify the external calls.
verify(s3Dao).copyFile(s3FileCopyRequestParamsDto);
verifyNoMoreInteractions(s3Dao);
// Validate the returned object.
assertEquals(s3FileTransferResultsDto, result);
}
use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class UploadDownloadHelperServiceImpl method performFileMoveImpl.
/**
* Moves an S3 file from the source bucket to the target bucket. Updates the target business object data status in the DTO based on the result of S3 copy
* operation.
*
* @param completeUploadSingleParamsDto the DTO that contains complete upload single message parameters
*/
protected void performFileMoveImpl(CompleteUploadSingleParamsDto completeUploadSingleParamsDto) {
// Create and initialize an S3 file copy request parameters DTO.
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());
String targetStatus;
try {
// Copy the file from source S3 bucket to target bucket, and mark the target business object data as VALID.
s3Dao.copyFile(params);
// Update the status of the target business object data to "VALID".
targetStatus = BusinessObjectDataStatusEntity.VALID;
} catch (Exception e) {
// Log the error.
LOGGER.error("Failed to copy the upload single file. s3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3BucketName=\"{}\" " + "sourceBusinessObjectDataKey={} targetBusinessObjectDataKey={}", completeUploadSingleParamsDto.getSourceFilePath(), completeUploadSingleParamsDto.getSourceBucketName(), completeUploadSingleParamsDto.getTargetBucketName(), jsonHelper.objectToJson(completeUploadSingleParamsDto.getSourceBusinessObjectDataKey()), jsonHelper.objectToJson(completeUploadSingleParamsDto.getTargetBusinessObjectDataKey()), e);
// Update the status of the target business object data to "INVALID".
targetStatus = BusinessObjectDataStatusEntity.INVALID;
}
// Update the DTO.
completeUploadSingleParamsDto.setTargetOldStatus(completeUploadSingleParamsDto.getTargetNewStatus());
completeUploadSingleParamsDto.setTargetNewStatus(targetStatus);
}
Aggregations