use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class FilePolicyApplier method apply.
@Override
public void apply(Payload payload, PolicyEngine policy) throws Exception {
ProcessKey processKey = payload.getProcessKey();
Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
CheckResult<FileRule, Path> result = policy.getFilePolicy().check(workDir);
result.getWarn().forEach(i -> {
policyWarn.inc();
logManager.warn(processKey, "Potentially restricted file '{}' (file policy: {})", workDir.relativize(i.getEntity()), i.getRule());
});
result.getDeny().forEach(i -> {
policyDeny.inc();
logManager.error(processKey, "File '{}' is forbidden by the file policy {}", workDir.relativize(i.getEntity()), i.getRule());
});
if (!result.getDeny().isEmpty()) {
throw new ProcessException(processKey, "Found forbidden files");
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessTimeoutPolicyApplier method apply.
@Override
public void apply(Payload payload, PolicyEngine policy) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
if (cfg == null) {
return;
}
Object processTimeout = cfg.get(Constants.Request.PROCESS_TIMEOUT);
if (processTimeout == null) {
return;
}
CheckResult<ProcessTimeoutRule, Object> result = policy.getProcessTimeoutPolicy().check(processTimeout);
result.getDeny().forEach(i -> {
policyDeny.inc();
String msg = i.getRule().getMsg() != null ? i.getRule().getMsg() : DEFAULT_PROCESS_TIMEOUT_MSG;
Object actualTimeout = i.getEntity();
String limit = i.getRule().getMax();
logManager.error(processKey, MessageFormat.format(msg, actualTimeout, limit));
});
if (!result.getDeny().isEmpty()) {
throw new ProcessException(processKey, "'processTimeout' value policy violation");
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class WorkspacePolicyApplier method apply.
@Override
public void apply(Payload payload, PolicyEngine policy) throws Exception {
ProcessKey processKey = payload.getProcessKey();
Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
CheckResult<WorkspaceRule, Path> result = policy.getWorkspacePolicy().check(workDir);
result.getWarn().forEach(i -> {
policyWarn.inc();
logManager.warn(processKey, appendMsg("Potential workspace policy violation (policy: {})", i.getMsg()), i.getRule());
});
result.getDeny().forEach(i -> {
policyDeny.inc();
logManager.error(processKey, appendMsg("Workspace policy violation", i.getMsg()), i.getRule());
});
if (!result.getDeny().isEmpty()) {
throw new ProcessException(processKey, "Found workspace policy violations");
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class DependencyVersionsExportProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
if (cfg.getPath() == null) {
return chain.process(payload);
}
logManager.info(processKey, "Storing default dependency versions...");
Path ws = payload.getHeader(Payload.WORKSPACE_DIR);
try {
Path dst = Files.createDirectories(ws.resolve(Constants.Files.CONCORD_SYSTEM_DIR_NAME));
IOUtils.copy(cfg.getPath(), dst.resolve(Constants.Files.DEPENDENCY_VERSIONS_FILE_NAME), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
logManager.error(processKey, "Error while storing dependency versions: {}", e);
throw new ProcessException(processKey, "Error while storing dependency versions: " + e.getMessage(), e);
}
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class FailProcessor method process.
@Override
public void process(Payload payload, Exception e) {
ProcessKey processKey = payload.getProcessKey();
boolean hasQueueRecord = queueDao.exists(processKey);
if (!hasQueueRecord) {
// the process failed before we had a chance to create the initial queue record
return;
}
logManager.error(processKey, "Process failed: {}", e.getMessage());
if (!(e instanceof InvalidProcessStateException)) {
queueManager.updateStatus(processKey, ProcessStatus.FAILED);
}
}
Aggregations