Search in sources :

Example 6 with AbstractDataStorageItem

use of com.epam.pipeline.entity.datastorage.AbstractDataStorageItem in project cloud-pipeline by epam.

the class S3Helper method listFiles.

private DataStorageListing listFiles(AmazonS3 client, String bucket, String requestPath, Integer pageSize, String marker) {
    ListObjectsV2Request req = new ListObjectsV2Request();
    req.setBucketName(bucket);
    req.setPrefix(requestPath);
    req.setDelimiter(S3Constants.DELIMITER);
    if (pageSize != null) {
        req.setMaxKeys(pageSize);
    }
    if (StringUtils.hasValue(marker)) {
        req.setStartAfter(marker);
    }
    ListObjectsV2Result listing;
    List<AbstractDataStorageItem> items = new ArrayList<>();
    String previous = null;
    do {
        listing = client.listObjectsV2(req);
        for (String name : listing.getCommonPrefixes()) {
            previous = getPreviousKey(previous, name);
            items.add(parseFolder(requestPath, name));
        }
        for (S3ObjectSummary s3ObjectSummary : listing.getObjectSummaries()) {
            DataStorageFile file = AbstractS3ObjectWrapper.getWrapper(s3ObjectSummary).convertToStorageFile(requestPath);
            if (file != null) {
                previous = getPreviousKey(previous, s3ObjectSummary.getKey());
                items.add(file);
            }
        }
        req.setContinuationToken(listing.getNextContinuationToken());
    } while (listing.isTruncated() && (pageSize == null || items.size() < pageSize));
    String returnToken = listing.isTruncated() ? previous : null;
    return new DataStorageListing(returnToken, items);
}
Also used : DataStorageListing(com.epam.pipeline.entity.datastorage.DataStorageListing) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) AbstractDataStorageItem(com.epam.pipeline.entity.datastorage.AbstractDataStorageItem) ArrayList(java.util.ArrayList) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Aggregations

AbstractDataStorageItem (com.epam.pipeline.entity.datastorage.AbstractDataStorageItem)6 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)5 DataStorageListing (com.epam.pipeline.entity.datastorage.DataStorageListing)4 ArrayList (java.util.ArrayList)3 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)2 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)2 DataStorageFolder (com.epam.pipeline.entity.datastorage.DataStorageFolder)2 NFSDataStorage (com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage)2 CmdExecutor (com.epam.pipeline.manager.CmdExecutor)2 File (java.io.File)2 FileUtils (org.apache.commons.io.FileUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ListObjectsV2Request (com.amazonaws.services.s3.model.ListObjectsV2Request)1 ListObjectsV2Result (com.amazonaws.services.s3.model.ListObjectsV2Result)1 ListVersionsRequest (com.amazonaws.services.s3.model.ListVersionsRequest)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 S3VersionSummary (com.amazonaws.services.s3.model.S3VersionSummary)1 VersionListing (com.amazonaws.services.s3.model.VersionListing)1 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)1 MessageConstants (com.epam.pipeline.common.MessageConstants)1