Search in sources :

Example 1 with CreateInvalidationResult

use of com.amazonaws.services.cloudfront.model.CreateInvalidationResult in project deployer by craftercms.

the class CloudFrontInvalidationProcessor method doMainProcess.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException {
    logger.info("Performing Cloudfront invalidation...");
    AmazonCloudFront client = buildClient();
    List<String> changedFiles = ListUtils.union(filteredChangeSet.getUpdatedFiles(), filteredChangeSet.getDeletedFiles());
    if (CollectionUtils.isNotEmpty(changedFiles)) {
        changedFiles = changedFiles.stream().map(f -> UriUtils.encodePath(f, StandardCharsets.UTF_8)).collect(Collectors.toList());
        Paths paths = new Paths().withItems(changedFiles).withQuantity(changedFiles.size());
        logger.info("Will invalidate {} files", changedFiles.size());
        for (String distribution : distributions) {
            try {
                String caller = UUID.randomUUID().toString();
                logger.info("Creating invalidation for distribution {} with reference {}", distribution, caller);
                InvalidationBatch batch = new InvalidationBatch().withPaths(paths).withCallerReference(caller);
                CreateInvalidationRequest request = new CreateInvalidationRequest(distribution, batch);
                CreateInvalidationResult result = client.createInvalidation(request);
                logger.info("Created invalidation {} for distribution {}", result.getInvalidation().getId(), distribution);
            } catch (Exception e) {
                throw new DeployerException("Error invalidating changed files for distribution " + distribution, e);
            }
        }
    } else {
        logger.info("No actual files that need to be invalidated");
    }
    return null;
}
Also used : InvalidationBatch(com.amazonaws.services.cloudfront.model.InvalidationBatch) CreateInvalidationResult(com.amazonaws.services.cloudfront.model.CreateInvalidationResult) DeployerException(org.craftercms.deployer.api.exceptions.DeployerException) AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront) Paths(com.amazonaws.services.cloudfront.model.Paths) CreateInvalidationRequest(com.amazonaws.services.cloudfront.model.CreateInvalidationRequest) DeployerException(org.craftercms.deployer.api.exceptions.DeployerException) ConfigurationException(org.craftercms.commons.config.ConfigurationException)

Aggregations

AmazonCloudFront (com.amazonaws.services.cloudfront.AmazonCloudFront)1 CreateInvalidationRequest (com.amazonaws.services.cloudfront.model.CreateInvalidationRequest)1 CreateInvalidationResult (com.amazonaws.services.cloudfront.model.CreateInvalidationResult)1 InvalidationBatch (com.amazonaws.services.cloudfront.model.InvalidationBatch)1 Paths (com.amazonaws.services.cloudfront.model.Paths)1 ConfigurationException (org.craftercms.commons.config.ConfigurationException)1 DeployerException (org.craftercms.deployer.api.exceptions.DeployerException)1