Search in sources :

Example 6 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class TemplateFilesProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    Object s = cfg.get(Constants.Request.TEMPLATE_KEY);
    if (!(s instanceof String)) {
        return chain.process(payload);
    }
    try {
        URI uri = getUri(processKey, (String) s);
        Path template = dependencyManager.resolveSingle(uri).getPath();
        extract(payload, template);
        return chain.process(payload);
    } catch (URISyntaxException | IOException e) {
        logManager.error(processKey, "Template error: " + s, e);
        throw new ProcessException(processKey, "Error while processing a template: " + s, e);
    }
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 7 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class TemplateScriptProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
    // process _main.js
    Path scriptPath = workspace.resolve(REQUEST_DATA_TEMPLATE_FILE_NAME);
    if (!Files.exists(scriptPath)) {
        return chain.process(payload);
    }
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> in = payload.getHeader(Payload.CONFIGURATION);
    Map<String, Object> out = processScript(processKey, in, scriptPath);
    Map<String, Object> merged = ConfigurationUtils.deepMerge(in, out);
    CycleChecker.CheckResult result = CycleChecker.check(INPUT_REQUEST_DATA_KEY, merged);
    if (result.isHasCycle()) {
        throw new ProcessException(processKey, "Found cycle in " + REQUEST_DATA_TEMPLATE_FILE_NAME + ": " + result.getNode1() + " <-> " + result.getNode2());
    }
    payload = payload.putHeader(Payload.CONFIGURATION, merged);
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) CycleChecker(com.walmartlabs.concord.common.CycleChecker) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Example 8 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class ContainerPolicyApplier method apply.

@Override
@SuppressWarnings("unchecked")
public void apply(Payload payload, PolicyEngine policy) {
    ProcessKey processKey = payload.getProcessKey();
    Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
    Path p = workDir.resolve(Constants.Files.CONFIGURATION_FILE_NAME);
    if (!Files.exists(p)) {
        return;
    }
    Map<String, Object> containerOptions;
    try (InputStream in = Files.newInputStream(p)) {
        Map<String, Object> m = objectMapper.readValue(in, Map.class);
        containerOptions = (Map<String, Object>) m.get(Constants.Request.CONTAINER);
    } catch (IOException e) {
        logManager.error(processKey, "Error while reading container configuration: {}", e);
        throw new ProcessException(processKey, "Error while reading container configuration", e);
    }
    CheckResult<ContainerRule, Object> result = policy.getContainerPolicy().check(containerOptions);
    result.getWarn().forEach(i -> {
        policyWarn.inc();
        logManager.warn(processKey, appendMsg("Potential container policy violation (policy: {})", i.getMsg()), i.getRule());
    });
    result.getDeny().forEach(i -> {
        policyDeny.inc();
        logManager.error(processKey, appendMsg("Container policy violation", i.getMsg()), i.getRule());
    });
    if (!result.getDeny().isEmpty()) {
        throw new ProcessException(processKey, "Found container policy violations");
    }
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) InputStream(java.io.InputStream) ContainerRule(com.walmartlabs.concord.policyengine.ContainerRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException)

Example 9 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey 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 10 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey 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)

Aggregations

ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)69 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)28 Path (java.nio.file.Path)27 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)25 ApiOperation (io.swagger.annotations.ApiOperation)22 ProcessException (com.walmartlabs.concord.server.process.ProcessException)20 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)16 IOException (java.io.IOException)16 UUID (java.util.UUID)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)7 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)7 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)7 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)7 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)6 HttpUtils (com.walmartlabs.concord.server.HttpUtils)5 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)5