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;
}
Aggregations