use of org.craftercms.deployer.api.exceptions.DeployerException in project deployer by craftercms.
the class FindAndReplaceProcessor method doMainProcess.
/**
* {@inheritDoc}
*/
@Override
protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException {
logger.info("Performing find & replace. Pattern '{}' will be replaced with '{}'...", textPattern, replacement);
for (String file : ListUtils.union(filteredChangeSet.getCreatedFiles(), filteredChangeSet.getUpdatedFiles())) {
try {
Path path = Paths.get(localRepoUrl, file);
String content = new String(Files.readAllBytes(path));
String updated = content.replaceAll(textPattern, replacement);
if (StringUtils.equals(content, updated)) {
logger.debug("No matches found for file {}", file);
} else {
logger.debug("Writing changes to file {}", file);
Files.write(path, updated.getBytes());
}
} catch (Exception e) {
throw new DeployerException("Error performing find and replace on file " + file, e);
}
}
return null;
}
use of org.craftercms.deployer.api.exceptions.DeployerException in project deployer by craftercms.
the class HttpMethodCallProcessor method doMainProcess.
@Override
protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException {
HttpUriRequest request = createRequest();
logger.info("Executing request {}...", request);
try (CloseableHttpResponse response = httpClient.execute(request)) {
int status = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String body = entity != null ? EntityUtils.toString(entity) : null;
if (StringUtils.isEmpty(body)) {
body = "empty";
}
if (status >= 200 && status < 300) {
logger.info("Successful response for request {}: status = {}, body = {}", request, status, body);
execution.setStatusDetails("Successful response for request " + request + ": status = " + status);
} else {
logger.error("Error response for request {}: status = {}, body = {}", request, status, body);
execution.setStatusDetails("Error response for request " + request + ": status = " + status);
execution.endExecution(Deployment.Status.FAILURE);
}
} catch (IOException e) {
throw new DeployerException("IO error on HTTP request " + request, e);
}
return null;
}
use of org.craftercms.deployer.api.exceptions.DeployerException in project deployer by craftercms.
the class ScriptProcessor method doMainProcess.
@Override
protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException {
if (sandboxInterceptor != null) {
sandboxInterceptor.register();
}
try {
Binding binding = new Binding();
binding.setVariable(SCRIPT_VAR_LOGGER, logger);
binding.setVariable(SCRIPT_VAR_APP_CTX, applicationContext);
binding.setVariable(SCRIPT_VAR_DEPLOYMENT, deployment);
binding.setVariable(SCRIPT_VAR_EXECUTION, execution);
binding.setVariable(SCRIPT_VAR_FILTERED_CHANGE_SET, filteredChangeSet);
binding.setVariable(SCRIPT_VAR_ORIGINAL_CHANGE_SET, originalChangeSet);
logger.info("Starting execution of script {}", scriptPath);
Object result = scriptEngine.run(scriptPath, binding);
logger.info("Completed execution of script {}", scriptPath);
if (result != null && !ChangeSet.class.isAssignableFrom(result.getClass())) {
throw new DeployerException("Incompatible type " + result.getClass().getName() + " returned by script " + scriptPath);
}
return (ChangeSet) result;
} catch (Throwable e) {
throw new DeployerException("Error executing script " + scriptPath, e);
} finally {
if (sandboxInterceptor != null) {
sandboxInterceptor.unregister();
}
}
}
use of org.craftercms.deployer.api.exceptions.DeployerException 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;
}
use of org.craftercms.deployer.api.exceptions.DeployerException in project deployer by craftercms.
the class CommandLineProcessor method executeProcess.
protected void executeProcess(String site, String operation, String file) throws DeployerException {
List<String> fullCommand = new LinkedList<>();
Collections.addAll(fullCommand, command.split("\\s"));
if (isNoneEmpty(site, operation, file)) {
fullCommand.add(site);
fullCommand.add(operation);
fullCommand.add(file);
}
ProcessBuilder processBuilder = new ProcessBuilder(fullCommand);
if (StringUtils.isNotEmpty(workingDir)) {
processBuilder.directory(new File(workingDir));
}
processBuilder.redirectErrorStream(true);
logger.info("Executing command: {}", command);
try {
Process process = processBuilder.start();
process.waitFor(processTimeoutSecs, TimeUnit.SECONDS);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String str;
while ((str = reader.readLine()) != null) {
logger.info("PROCESS OUTPUT: {}", str);
}
}
logger.info("Process finished with exit code {}", process.exitValue());
} catch (IOException | InterruptedException e) {
throw new DeployerException("Error while executing command", e);
}
}
Aggregations