Search in sources :

Example 26 with ProcessException

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");
    }
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) WorkspaceRule(com.walmartlabs.concord.policyengine.WorkspaceRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Example 27 with ProcessException

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);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException)

Example 28 with ProcessException

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);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) IOException(java.io.IOException)

Example 29 with ProcessException

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);
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ForkDepthRule(com.walmartlabs.concord.policyengine.ForkDepthRule) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Example 30 with ProcessException

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);
    }
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) ProcessException(com.walmartlabs.concord.server.process.ProcessException) OutVariablesMode(com.walmartlabs.concord.server.jooq.enums.OutVariablesMode) UUID(java.util.UUID)

Aggregations

ProcessException (com.walmartlabs.concord.server.process.ProcessException)31 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)20 Path (java.nio.file.Path)19 IOException (java.io.IOException)18 UUID (java.util.UUID)9 InputStream (java.io.InputStream)4 Map (java.util.Map)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)3 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)3 ProcessDefinition (com.walmartlabs.concord.process.loader.model.ProcessDefinition)2 Snapshot (com.walmartlabs.concord.repository.Snapshot)2 Payload (com.walmartlabs.concord.server.process.Payload)2 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)2 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)2 UserInfo (com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 CycleChecker (com.walmartlabs.concord.common.CycleChecker)1