Search in sources :

Example 1 with ProcessLog

use of com.walmartlabs.concord.agent.logging.ProcessLog in project concord by walmartlabs.

the class RunnerJobExecutor method exec.

private void exec(RunnerJob job, ProcessEntry pe) throws Exception {
    // the actual OS process
    Process proc = pe.getProcess();
    UUID instanceId = job.getInstanceId();
    ProcessLog processLog = job.getLog();
    // start the log's maintenance thread (e.g. streaming to the server)
    LogStream logStream = new LogStream(job, proc);
    logStream.start();
    try {
        // save the process' log
        processLog.log(proc.getInputStream());
        // wait for the process to finish
        int code;
        try {
            code = proc.waitFor();
        } catch (Exception e) {
            // wait for the log to finish
            logStream.waitForCompletion();
            handleError(job, proc, e.getMessage());
            throw new ExecutionException("Error while executing a job: " + e.getMessage());
        }
        // wait for the log to finish
        logStream.waitForCompletion();
        if (code != 0) {
            log.warn("exec ['{}'] -> finished with {}", instanceId, code);
            handleError(job, proc, "Process exit code: " + code);
            throw new ExecutionException("Error while executing a job, process exit code: " + code);
        }
        log.info("exec ['{}'] -> finished with {}", instanceId, code);
        processLog.info("Process finished with: {}", code);
    } finally {
        // wait for the log to finish
        logStream.waitForCompletion();
    }
}
Also used : ExecutionException(com.walmartlabs.concord.agent.ExecutionException) ProcessLog(com.walmartlabs.concord.agent.logging.ProcessLog) ExecutionException(com.walmartlabs.concord.agent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException)

Example 2 with ProcessLog

use of com.walmartlabs.concord.agent.logging.ProcessLog in project concord by walmartlabs.

the class RunnerJobExecutor method validateDependencies.

private void validateDependencies(RunnerJob job, Collection<DependencyEntity> resolvedDepEntities) throws ExecutionException {
    PolicyEngine policyEngine = job.getPolicyEngine();
    if (policyEngine == null) {
        return;
    }
    ProcessLog processLog = job.getLog();
    processLog.info("Checking the dependency policy...");
    CheckResult<DependencyRule, DependencyEntity> result = policyEngine.getDependencyPolicy().check(resolvedDepEntities);
    result.getWarn().forEach(d -> processLog.warn("Potentially restricted artifact '{}' (dependency policy: {})", d.getEntity(), d.getRule().getMsg()));
    result.getDeny().forEach(d -> processLog.warn("Artifact '{}' is forbidden by the dependency policy {}", d.getEntity(), d.getRule().getMsg()));
    if (!result.getDeny().isEmpty()) {
        throw new ExecutionException("Found restricted dependencies");
    }
}
Also used : DependencyEntity(com.walmartlabs.concord.dependencymanager.DependencyEntity) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) DependencyRule(com.walmartlabs.concord.policyengine.DependencyRule) ExecutionException(com.walmartlabs.concord.agent.ExecutionException) ProcessLog(com.walmartlabs.concord.agent.logging.ProcessLog)

Aggregations

ExecutionException (com.walmartlabs.concord.agent.ExecutionException)2 ProcessLog (com.walmartlabs.concord.agent.logging.ProcessLog)2 DependencyEntity (com.walmartlabs.concord.dependencymanager.DependencyEntity)1 DependencyRule (com.walmartlabs.concord.policyengine.DependencyRule)1 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1