Example usage for com.amazonaws.services.cloudfront.model ListInvalidationsRequest ListInvalidationsRequest

List of usage examples for com.amazonaws.services.cloudfront.model ListInvalidationsRequest ListInvalidationsRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront.model ListInvalidationsRequest ListInvalidationsRequest.

Prototype

public ListInvalidationsRequest(String distributionId) 

Source Link

Document

Constructs a new ListInvalidationsRequest object.

Usage

From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java

License:Open Source License

/**
 * @param distribution Configuration//from w ww.  java 2s .c o m
 * @return Status message from service
 */
private String readInvalidationStatus(final AmazonCloudFront client, final Distribution distribution)
        throws BackgroundException {
    try {
        int pending = 0;
        int completed = 0;
        String marker = null;
        do {
            final ListInvalidationsResult response = client
                    .listInvalidations(new ListInvalidationsRequest(distribution.getId())
                            .withMaxItems(String.valueOf(1000)).withMarker(marker));
            for (InvalidationSummary s : response.getInvalidationList().getItems()) {
                // When the invalidation batch is finished, the status is Completed.
                if ("Completed".equals(s.getStatus())) {
                    // No schema for status enumeration. Fail.
                    completed++;
                } else {
                    // InProgress
                    pending++;
                }
            }
            marker = response.getInvalidationList().getNextMarker();
        } while (marker != null);
        if (pending > 0) {
            return MessageFormat.format(LocaleFactory.localizedString("{0} invalidations in progress", "S3"),
                    pending);
        }
        if (completed > 0) {
            return MessageFormat.format(LocaleFactory.localizedString("{0} invalidations completed", "S3"),
                    completed);
        }
        return LocaleFactory.localizedString("None");
    } catch (AmazonClientException e) {
        throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e);
    }
}