Search code examples
javaamazon-s3blobstorejclouds

Apache jclouds, best way to delete blob from blobstore older than a date


Hi I try to implement a method removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit) that mean I want to delete every unused blob older than minimumAge inside my S3 container. But I don't find which method to use in my BlobStore object to achieve this.

Does JClouds provide a such feature ?


Solution

  • jclouds does not provide a utility method for this but you can roll your own:

    String marker = null;
    while (true) {
        PageSet<StorageMetadata> set = blobStore.list(containerName,
                new ListContainerOptions().afterMarker(marker);
        for (StorageMetadata sm : set) {
            if (sm.getCreateDate() < expiryDate) {
                blobStore.removeBlob(containerName, sm.getName());
            }
        }
        marker = set.getNextMarker();
        if (marker == null) {
            break;
        }
    }