Example usage for com.amazonaws.services.s3.model S3ObjectSummary getKey

List of usage examples for com.amazonaws.services.s3.model S3ObjectSummary getKey

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model S3ObjectSummary getKey.

Prototype

public String getKey() 

Source Link

Document

Gets the key under which this object is stored in Amazon S3.

Usage

From source file:com.miovision.oss.awsbillingtools.s3.scanner.S3BillingRecordFileScanner.java

License:Open Source License

protected S3BillingRecordFile parse(S3ObjectSummary s3ObjectSummary) {
    final String bucketName = s3ObjectSummary.getBucketName();
    final String key = s3ObjectSummary.getKey();

    return S3BillingRecordFile.parseS3Key(bucketName, key, DELIMITER).orElse(null);
}

From source file:com.moxtra.S3StorageManager.java

License:Open Source License

/**
 * Deletes the specified S3 object from the S3 storage service.  If a
 * storage path is passed in that has child S3 objects, it will recursively
 * delete the underlying objects.//from   ww  w .j a  v a 2 s .  co  m
 * @param bucketname
 * @param key
 */

public void delete(String bucketname, String key) {

    if (key == null || key.equals("")) {
        logger.log(Level.WARNING, "Empty storage path passed to delete method");
        return; // We don't want to delete everything in a path
    }

    try {

        // Go through the store structure and delete child objects
        ObjectListing listing = s3Client.listObjects(bucketname, key);
        while (true) {
            List<S3ObjectSummary> objectList = listing.getObjectSummaries();
            for (S3ObjectSummary summary : objectList) {
                s3Client.deleteObject(bucketname, summary.getKey());
            }
            if (listing.isTruncated()) {
                listing = s3Client.listNextBatchOfObjects(listing);
            } else {
                break;
            }
        }
    } catch (Exception e) {
        // unable to remove item
        logger.log(Level.FINEST, "Unable to remove: " + bucketname + "/" + key);

    }

}

From source file:com.moxtra.S3StorageManager.java

License:Open Source License

/**
 * list objects/*from  w w  w .j a v a  2 s . co m*/
 * @param bucketname
 * @param prefix
 * @return
 * @throws Exception
 */

public List<byte[]> listObjects(String bucketname, String prefix) throws Exception {

    List<byte[]> list = new ArrayList<byte[]>();

    ObjectListing listing = s3Client.listObjects(bucketname, prefix);
    while (true) {
        List<S3ObjectSummary> objectList = listing.getObjectSummaries();
        for (S3ObjectSummary summary : objectList) {

            byte[] bytes = this.getData(bucketname, summary.getKey());

            list.add(bytes);
        }
        if (listing.isTruncated()) {
            listing = s3Client.listNextBatchOfObjects(listing);
        } else {
            break;
        }
    }

    return list;
}

From source file:com.mycompany.mytubeaws.ListServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from ww w  . j a v  a2s. c o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ArrayList<String> nameList = new ArrayList<>();
    ArrayList<String> sizeList = new ArrayList<>();
    ArrayList<String> dateList = new ArrayList<>();

    ObjectListing objects = s3.listObjects(bucketName);
    do {
        for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
            nameList.add(objectSummary.getKey());
            sizeList.add(Long.toString(objectSummary.getSize()));
            dateList.add(StringUtils.fromDate(objectSummary.getLastModified()));
        }
        objects = s3.listNextBatchOfObjects(objects);
    } while (objects.isTruncated());

    request.setAttribute("nameList", nameList);
    request.setAttribute("sizeList", sizeList);
    request.setAttribute("dateList", dateList);
    request.getRequestDispatcher("/UploadResult.jsp").forward(request, response);
}

From source file:com.netflix.exhibitor.core.backup.s3.S3BackupProvider.java

License:Apache License

@Override
public List<BackupMetaData> getAvailableBackups(Exhibitor exhibitor, Map<String, String> configValues)
        throws Exception {
    String keyPrefix = getKeyPrefix(configValues);

    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(configValues.get(CONFIG_BUCKET.getKey()));
    request.setPrefix(keyPrefix);//from   ww  w.  ja va2 s.c o m

    List<BackupMetaData> completeList = Lists.newArrayList();

    ObjectListing listing = null;
    do {
        listing = (listing == null) ? s3Client.listObjects(request) : s3Client.listNextBatchOfObjects(listing);

        Iterable<S3ObjectSummary> filtered = Iterables.filter(listing.getObjectSummaries(),
                new Predicate<S3ObjectSummary>() {
                    @Override
                    public boolean apply(S3ObjectSummary summary) {
                        return fromKey(summary.getKey()) != null;
                    }
                });

        Iterable<BackupMetaData> transformed = Iterables.transform(filtered,
                new Function<S3ObjectSummary, BackupMetaData>() {
                    @Override
                    public BackupMetaData apply(S3ObjectSummary summary) {
                        return fromKey(summary.getKey());
                    }
                });

        completeList.addAll(Lists.newArrayList(transformed));
    } while (listing.isTruncated());
    return completeList;
}

From source file:com.netflix.exhibitor.core.config.s3.S3PseudoLock.java

License:Apache License

@Override
protected List<String> getFileNames(String lockPrefix) throws Exception {
    ListObjectsRequest request = new ListObjectsRequest();
    request.setBucketName(bucket);/*from   ww  w . j  av  a2  s.  c o m*/
    request.setPrefix(lockPrefix);
    ObjectListing objectListing = client.listObjects(request);

    return Lists.transform(objectListing.getObjectSummaries(), new Function<S3ObjectSummary, String>() {
        @Override
        public String apply(S3ObjectSummary summary) {
            return summary.getKey();
        }
    });
}

From source file:com.netflix.hollow.example.producer.infrastructure.S3Publisher.java

License:Apache License

private void addSnapshotStateId(S3ObjectSummary obj, List<Long> snapshotIdx) {
    String key = obj.getKey();
    try {// w w  w  .  jav  a  2 s  .  c o  m
        snapshotIdx.add(Long.parseLong(key.substring(key.lastIndexOf("-") + 1)));
    } catch (NumberFormatException ignore) {
    }
}

From source file:com.netflix.ice.basic.BasicManagers.java

License:Apache License

private void doWork() {

    logger.info("trying to find new tag group and data managers...");
    Set<Product> products = Sets.newHashSet(this.products);
    Map<Product, BasicTagGroupManager> tagGroupManagers = Maps.newHashMap(this.tagGroupManagers);
    TreeMap<Key, BasicDataManager> costManagers = Maps.newTreeMap(this.costManagers);
    TreeMap<Key, BasicDataManager> usageManagers = Maps.newTreeMap(this.usageManagers);

    Set<Product> newProducts = Sets.newHashSet();
    AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
    for (S3ObjectSummary s3ObjectSummary : s3Client
            .listObjects(config.workS3BucketName, config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX)
            .getObjectSummaries()) {/*from w  w w  .j ava 2s .  c  om*/
        String key = s3ObjectSummary.getKey();
        Product product;
        if (key.endsWith("_all")) {
            product = null;
        } else {
            String name = key.substring((config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).length());
            product = config.productService.getProductByName(name);
        }
        if (!products.contains(product)) {
            products.add(product);
            newProducts.add(product);
        }
    }

    for (Product product : newProducts) {
        tagGroupManagers.put(product, new BasicTagGroupManager(product));
        for (ConsolidateType consolidateType : ConsolidateType.values()) {
            Key key = new Key(product, consolidateType);
            costManagers.put(key, new BasicDataManager(product, consolidateType, true));
            usageManagers.put(key, new BasicDataManager(product, consolidateType, false));
        }
    }

    if (newProducts.size() > 0) {
        this.costManagers = costManagers;
        this.usageManagers = usageManagers;
        this.tagGroupManagers = tagGroupManagers;
        this.products = products;
    }
}

From source file:com.netflix.ice.basic.MapDb.java

License:Apache License

MapDb(String name) {
    this.config = ProcessorConfig.getInstance();

    this.dbName = "db_" + name;
    File file = new File(config.localDir, dbName);
    if (!file.exists()) {
        AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
        for (S3ObjectSummary s3ObjectSummary : s3Client
                .listObjects(config.workS3BucketName, config.workS3BucketPrefix + this.dbName)
                .getObjectSummaries()) {
            File dbFile = new File(config.localDir,
                    s3ObjectSummary.getKey().substring(config.workS3BucketPrefix.length()));
            AwsUtils.downloadFileIfNotExist(config.workS3BucketName, config.workS3BucketPrefix, dbFile);
        }//w w  w  .  ja  v a2 s . c  o m
    }
    this.db = DBMaker.newFileDB(new File(config.localDir, this.dbName)).make();
    try {
        this.items = db.createHashMap(name, false, null, null);
    } catch (IllegalArgumentException e) {
        this.items = db.getHashMap(name);
        logger.info("found " + this.items.size() + " items from mapdb for " + name);
    }
}

From source file:com.netflix.ice.common.AwsUtils.java

License:Apache License

/**
 * Get list of months in from the file names.
 * @param bucket/*w w  w  . j  a v  a2 s . co  m*/
 * @param prefix
 * @return
 */
public static Set<DateTime> listMonths(String bucket, String prefix) {
    List<S3ObjectSummary> objects = listAllObjects(bucket, prefix);
    Set<DateTime> result = Sets.newTreeSet();
    for (S3ObjectSummary object : objects) {
        String fileName = object.getKey().substring(prefix.length());
        result.add(monthDateFormat.parseDateTime(fileName));
    }

    return result;
}