Search in sources :

Example 1 with S3FileCopyRequestParamsDto

use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.

the class StorageHelper method getS3FileCopyRequestParamsDto.

/**
 * 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;
}
Also used : S3FileCopyRequestParamsDto(org.finra.herd.model.dto.S3FileCopyRequestParamsDto)

Example 2 with S3FileCopyRequestParamsDto

use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.

the class S3DaoTest method testPerformTransferAssertLogWhenStepCountGt300.

@Test
public void testPerformTransferAssertLogWhenStepCountGt300() throws Exception {
    S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
    S3Operations mockS3Operations = mock(S3Operations.class);
    ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
    // Shorten the sleep interval for faster tests
    long originalSleepIntervalsMillis = (long) ReflectionTestUtils.getField(s3Dao, "sleepIntervalsMillis");
    ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", 1l);
    try {
        S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto();
        s3FileCopyRequestParamsDto.setSourceBucketName("sourceBucketName");
        s3FileCopyRequestParamsDto.setSourceObjectKey("sourceObjectKey");
        s3FileCopyRequestParamsDto.setTargetBucketName("targetBucketName");
        s3FileCopyRequestParamsDto.setTargetObjectKey("targetObjectKey");
        s3FileCopyRequestParamsDto.setKmsKeyId("kmsKeyId");
        when(mockS3Operations.copyFile(any(), any())).then(new Answer<Copy>() {

            @Override
            public Copy answer(InvocationOnMock invocation) throws Throwable {
                Copy mockTransfer = mock(Copy.class);
                when(mockTransfer.getProgress()).thenReturn(new TransferProgress());
                when(mockTransfer.getState()).thenReturn(TransferState.Completed);
                when(mockTransfer.isDone()).then(new Answer<Boolean>() {

                    int callCount = 0;

                    @Override
                    public Boolean answer(InvocationOnMock invocation) throws Throwable {
                        return callCount++ > 600;
                    }
                });
                return mockTransfer;
            }
        });
        s3Dao.copyFile(s3FileCopyRequestParamsDto);
    } finally {
        ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
        ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", originalSleepIntervalsMillis);
    }
}
Also used : Answer(org.mockito.stubbing.Answer) S3FileCopyRequestParamsDto(org.finra.herd.model.dto.S3FileCopyRequestParamsDto) Copy(com.amazonaws.services.s3.transfer.Copy) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress) Test(org.junit.Test)

Example 3 with S3FileCopyRequestParamsDto

use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.

the class S3DaoTest method testPerformTransferAssertHandleFailedWithAmazonClientException.

@Test
public void testPerformTransferAssertHandleFailedWithAmazonClientException() throws Exception {
    S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
    S3Operations mockS3Operations = mock(S3Operations.class);
    ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
    // Shorten the sleep interval for faster tests
    long originalSleepIntervalsMillis = (long) ReflectionTestUtils.getField(s3Dao, "sleepIntervalsMillis");
    ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", 1l);
    try {
        S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto();
        s3FileCopyRequestParamsDto.setSourceBucketName("sourceBucketName");
        s3FileCopyRequestParamsDto.setSourceObjectKey("sourceObjectKey");
        s3FileCopyRequestParamsDto.setTargetBucketName("targetBucketName");
        s3FileCopyRequestParamsDto.setTargetObjectKey("targetObjectKey");
        s3FileCopyRequestParamsDto.setKmsKeyId("kmsKeyId");
        when(mockS3Operations.copyFile(any(), any())).then(new Answer<Copy>() {

            @Override
            public Copy answer(InvocationOnMock invocation) throws Throwable {
                Copy mockTransfer = mock(Copy.class);
                when(mockTransfer.getProgress()).thenReturn(new TransferProgress());
                when(mockTransfer.getState()).thenReturn(TransferState.Failed);
                when(mockTransfer.isDone()).thenReturn(true);
                when(mockTransfer.waitForException()).thenReturn(new AmazonClientException("message"));
                return mockTransfer;
            }
        });
        try {
            s3Dao.copyFile(s3FileCopyRequestParamsDto);
            fail();
        } catch (Exception e) {
            assertEquals(AmazonClientException.class, e.getClass());
            assertEquals("message", e.getMessage());
        }
    } finally {
        ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
        ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", originalSleepIntervalsMillis);
    }
}
Also used : S3FileCopyRequestParamsDto(org.finra.herd.model.dto.S3FileCopyRequestParamsDto) Copy(com.amazonaws.services.s3.transfer.Copy) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AmazonClientException(com.amazonaws.AmazonClientException) MultiObjectDeleteException(com.amazonaws.services.s3.model.MultiObjectDeleteException) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress) Test(org.junit.Test)

Example 4 with S3FileCopyRequestParamsDto

use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.

the class S3DaoTest method testCopyFile.

/**
 * 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());
}
Also used : S3FileCopyRequestParamsDto(org.finra.herd.model.dto.S3FileCopyRequestParamsDto) ByteArrayInputStream(java.io.ByteArrayInputStream) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 5 with S3FileCopyRequestParamsDto

use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.

the class S3DaoTest method testCopyFileNoKmsId.

/**
 * 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());
    }
}
Also used : S3FileCopyRequestParamsDto(org.finra.herd.model.dto.S3FileCopyRequestParamsDto) ByteArrayInputStream(java.io.ByteArrayInputStream) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Aggregations

S3FileCopyRequestParamsDto (org.finra.herd.model.dto.S3FileCopyRequestParamsDto)10 Test (org.junit.Test)8 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 S3FileTransferResultsDto (org.finra.herd.model.dto.S3FileTransferResultsDto)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 Copy (com.amazonaws.services.s3.transfer.Copy)2 TransferProgress (com.amazonaws.services.s3.transfer.TransferProgress)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 MultiObjectDeleteException (com.amazonaws.services.s3.model.MultiObjectDeleteException)1 IOException (java.io.IOException)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 Answer (org.mockito.stubbing.Answer)1