Search in sources :

Example 96 with ObjectListing

use of com.amazonaws.services.s3.model.ObjectListing in project herd by FINRAOS.

the class S3DaoTest method testListDirectoryAssertTruncatedResult.

@Test
public void testListDirectoryAssertTruncatedResult() {
    S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
    S3Operations mockS3Operations = mock(S3Operations.class);
    ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
    try {
        String s3BucketName = "s3BucketName";
        String s3KeyPrefix = "s3KeyPrefix";
        String expectedFilePath = "key";
        long expectedFileSize = 1024l;
        S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
        s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
        boolean ignoreZeroByteDirectoryMarkers = true;
        when(mockS3Operations.listObjects(any(), any())).then(new Answer<ObjectListing>() {

            @Override
            public ObjectListing answer(InvocationOnMock invocation) throws Throwable {
                ListObjectsRequest listObjectsRequest = invocation.getArgument(0);
                String marker = listObjectsRequest.getMarker();
                ObjectListing objectListing = new ObjectListing();
                if (marker == null) {
                    objectListing.setNextMarker("marker");
                    objectListing.setTruncated(true);
                } else {
                    assertEquals("marker", marker);
                    S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
                    s3ObjectSummary.setKey(expectedFilePath);
                    s3ObjectSummary.setSize(expectedFileSize);
                    objectListing.getObjectSummaries().add(s3ObjectSummary);
                }
                return objectListing;
            }
        });
        List<S3ObjectSummary> s3ObjectSummaries = s3Dao.listDirectory(s3FileTransferRequestParamsDto, ignoreZeroByteDirectoryMarkers);
        assertEquals(1, s3ObjectSummaries.size());
        assertEquals(expectedFilePath, s3ObjectSummaries.get(0).getKey());
        assertEquals(expectedFileSize, s3ObjectSummaries.get(0).getSize());
    } finally {
        ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
    }
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 97 with ObjectListing

use of com.amazonaws.services.s3.model.ObjectListing in project opencast by opencast.

the class AwsS3DistributionServiceImplTest method testCreateAWSBucketWhenAlreadyExists.

@Test
public void testCreateAWSBucketWhenAlreadyExists() {
    // Bucket exists
    ObjectListing list = EasyMock.createNiceMock(ObjectListing.class);
    EasyMock.replay(list);
    EasyMock.expect(s3.listObjects(BUCKET_NAME)).andReturn(list).once();
    EasyMock.replay(s3);
    service.createAWSBucket();
    // Verify that all expected methods were called
    EasyMock.verify(s3);
}
Also used : ObjectListing(com.amazonaws.services.s3.model.ObjectListing) Test(org.junit.Test)

Example 98 with ObjectListing

use of com.amazonaws.services.s3.model.ObjectListing in project acs-aem-commons by Adobe-Consulting-Services.

the class S3AssetIngestor method importAssets.

void importAssets(ActionManager manager) {
    manager.deferredWithResolver(rr -> {
        JcrUtil.createPath(jcrBasePath, DEFAULT_FOLDER_TYPE, DEFAULT_FOLDER_TYPE, rr.adaptTo(Session.class), true);
        manager.setCurrentItem(baseItemName);
        ObjectListing listing = s3Client.listObjects(bucket, s3BasePath);
        importAssets(manager, listing);
    });
}
Also used : ObjectListing(com.amazonaws.services.s3.model.ObjectListing) Session(javax.jcr.Session)

Example 99 with ObjectListing

use of com.amazonaws.services.s3.model.ObjectListing in project acs-aem-commons by Adobe-Consulting-Services.

the class S3AssetIngestor method createFolders.

void createFolders(ActionManager manager) {
    manager.deferredWithResolver(r -> {
        JcrUtil.createPath(jcrBasePath, DEFAULT_FOLDER_TYPE, DEFAULT_FOLDER_TYPE, r.adaptTo(Session.class), true);
        manager.setCurrentItem(baseItemName);
        ObjectListing listing = s3Client.listObjects(bucket, s3BasePath);
        createFolders(manager, listing);
    });
}
Also used : ObjectListing(com.amazonaws.services.s3.model.ObjectListing) Session(javax.jcr.Session)

Example 100 with ObjectListing

use of com.amazonaws.services.s3.model.ObjectListing in project spring-integration-aws by spring-projects.

the class S3Session method listNames.

@Override
public String[] listNames(String path) throws IOException {
    String[] bucketPrefix = splitPathToBucketAndKey(path, false);
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketPrefix[0]);
    if (bucketPrefix.length > 1) {
        listObjectsRequest.setPrefix(bucketPrefix[1]);
    }
    /*
		For listing objects, Amazon S3 returns up to 1,000 keys in the response.
		If you have more than 1,000 keys in your bucket, the response will be truncated.
		You should always check for if the response is truncated.
		*/
    ObjectListing objectListing;
    List<String> names = new ArrayList<>();
    do {
        objectListing = this.amazonS3.listObjects(listObjectsRequest);
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            names.add(objectSummary.getKey());
        }
        listObjectsRequest.setMarker(objectListing.getNextMarker());
    } while (objectListing.isTruncated());
    return names.toArray(new String[names.size()]);
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) ArrayList(java.util.ArrayList) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Aggregations

ObjectListing (com.amazonaws.services.s3.model.ObjectListing)104 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)81 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)55 ArrayList (java.util.ArrayList)44 AmazonS3 (com.amazonaws.services.s3.AmazonS3)22 AmazonClientException (com.amazonaws.AmazonClientException)17 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)16 IOException (java.io.IOException)14 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)12 Date (java.util.Date)12 Test (org.junit.Test)11 Test (org.testng.annotations.Test)11 AmazonServiceException (com.amazonaws.AmazonServiceException)10 HashMap (java.util.HashMap)10 Path (org.apache.hadoop.fs.Path)9 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)8 DeleteObjectsResult (com.amazonaws.services.s3.model.DeleteObjectsResult)7 S3Object (com.amazonaws.services.s3.model.S3Object)7 Properties (java.util.Properties)6 FileStatus (org.apache.hadoop.fs.FileStatus)6