Search in sources :

Example 11 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class ConfigurationProcessor method getWorkspaceCfg.

@SuppressWarnings("unchecked")
private static Map<String, Object> getWorkspaceCfg(Payload payload) {
    Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
    Path src = workspace.resolve(Constants.Files.CONFIGURATION_FILE_NAME);
    if (!Files.exists(src)) {
        return Collections.emptyMap();
    }
    try (InputStream in = Files.newInputStream(src)) {
        ObjectMapper om = new ObjectMapper();
        return om.readValue(in, Map.class);
    } catch (IOException e) {
        throw new ProcessException(payload.getProcessKey(), "Invalid request data format", e, Status.BAD_REQUEST);
    }
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class ConfigurationProcessor method getProject.

private ProjectEntry getProject(Payload payload) {
    UUID projectId = payload.getHeader(Payload.PROJECT_ID);
    if (projectId == null) {
        return null;
    }
    ProjectEntry e = projectDao.get(projectId);
    if (e == null) {
        throw new ProcessException(payload.getProcessKey(), "Project not found: " + projectId, Status.BAD_REQUEST);
    }
    return e;
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) ProcessException(com.walmartlabs.concord.server.process.ProcessException) UUID(java.util.UUID)

Example 13 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class ConfigurationStoringProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    if (cfg == null) {
        return chain.process(payload);
    }
    Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
    Path dst = workspace.resolve(Constants.Files.CONFIGURATION_FILE_NAME);
    try (OutputStream out = Files.newOutputStream(dst)) {
        ObjectMapper om = new ObjectMapper();
        om.writeValue(out, cfg);
    } catch (IOException e) {
        logManager.error(processKey, "Error while saving a metadata file: " + dst, e);
        throw new ProcessException(processKey, "Error while saving a metadata file: " + dst, e);
    }
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) OutputStream(java.io.OutputStream) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class DependenciesProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    // get a list of dependencies from the cfg data
    Collection<String> deps = deps(processKey, cfg);
    if (deps == null) {
        return chain.process(payload);
    }
    boolean failed = false;
    for (String d : deps) {
        try {
            new URI(d);
        } catch (URISyntaxException e) {
            logManager.error(processKey, "Invalid dependency URL: " + d);
            failed = true;
        }
    }
    if (failed) {
        throw new ProcessException(processKey, "Invalid dependency list");
    }
    cfg.put(Constants.Request.DEPENDENCIES_KEY, deps);
    payload = payload.putHeader(Payload.CONFIGURATION, cfg);
    return chain.process(payload);
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 15 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class ForkRepositoryInfoProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    UUID parentInstanceId = payload.getHeader(Payload.PARENT_INSTANCE_ID);
    ProcessEntry parent = queueManager.get(PartialProcessKey.from(parentInstanceId));
    if (parent == null) {
        throw new ProcessException(payload.getProcessKey(), "Parent process '" + parentInstanceId + "' not found");
    }
    RepositoryProcessor.CommitInfo ci = new RepositoryProcessor.CommitInfo(parent.commitId(), parent.commitBranch(), null, parent.commitMsg());
    RepositoryProcessor.RepositoryInfo i = new RepositoryProcessor.RepositoryInfo(parent.repoId(), parent.repoName(), parent.repoUrl(), parent.repoPath(), parent.commitBranch(), parent.commitId(), ci);
    payload = payload.putHeader(REPOSITORY_INFO_KEY, i);
    return chain.process(payload);
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) UUID(java.util.UUID) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

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