use of com.walmartlabs.concord.server.process.ProcessException 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.process.ProcessException 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.process.ProcessException in project concord by walmartlabs.
the class ForkCleanupProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
Path stateDir = workspace.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME).resolve(Constants.Files.JOB_STATE_DIR_NAME);
try {
// otherwise the fork could try to resume a parent process' event
for (String m : MARKER_FILES) {
Path suspendMarker = stateDir.resolve(m);
Files.deleteIfExists(suspendMarker);
}
// remove the parent process' arguments file if a state snapshot is present
// we don't want the original process arguments to overwrite the process variables
Path stateSnapshot = stateDir.resolve(Constants.Files.LAST_KNOWN_VARIABLES_FILE_NAME);
if (Files.exists(stateSnapshot)) {
clearArguments(workspace);
}
} catch (IOException e) {
throw new ProcessException(payload.getProcessKey(), "Error while preparing the fork's data", e);
}
return chain.process(payload);
}
use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class ForkPolicyProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
UUID parentInstanceId = payload.getHeader(Payload.PARENT_INSTANCE_ID);
PolicyEngine policy = payload.getHeader(Payload.POLICY);
if (policy == null) {
return chain.process(payload);
}
logManager.info(processKey, "Applying fork policies...");
CheckResult<ForkDepthRule, Integer> result;
try {
result = policy.getForkDepthPolicy().check(() -> forkDepthDao.getDepth(parentInstanceId));
} catch (Exception e) {
log.error("process -> error", e);
throw new ProcessException(processKey, "Found fork policy check error", e);
}
if (!result.getDeny().isEmpty()) {
logManager.error(processKey, buildErrorMessage(result.getDeny()));
throw new ProcessException(processKey, "Found fork policy violations");
}
return chain.process(payload);
}
use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class AssertOutVariablesProcessor method isOutVariablesAllowed.
private boolean isOutVariablesAllowed(Payload payload) {
UUID projectId = payload.getHeader(Payload.PROJECT_ID);
if (projectId == null) {
return true;
}
ProjectEntry p = projectDao.get(projectId);
if (p == null) {
throw new ProcessException(payload.getProcessKey(), "Project not found: " + projectId);
}
OutVariablesMode m = p.getOutVariablesMode();
switch(m) {
case DISABLED:
{
return false;
}
case OWNERS:
{
return projectAccessManager.hasAccess(p, ResourceAccessLevel.OWNER, false);
}
case TEAM_MEMBERS:
{
return projectAccessManager.isTeamMember(p.getId());
}
case ORG_MEMBERS:
{
return userManager.isInOrganization(p.getOrgId());
}
case EVERYONE:
{
return true;
}
default:
throw new IllegalArgumentException("Unsupported out variables mode: " + m);
}
}
Aggregations