Search in sources :

Example 26 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord by walmartlabs.

the class DockerTaskV2 method execute.

@Override
public TaskResult execute(Variables input) throws Exception {
    Path workDir = this.workDir.getValue();
    TaskParams params = new TaskParams(input);
    boolean logStdOut = input.getBoolean(LOG_STD_OUT_KEY, true);
    boolean logStdError = input.getBoolean(LOG_STD_ERR_KEY, true);
    boolean saveStdOut = input.getBoolean(SAVE_STD_OUT_KEY, false);
    boolean saveStdError = input.getBoolean(SAVE_STD_ERR_KEY, false);
    boolean redirectErrorStream = input.getBoolean(REDIRECT_ERROR_STREAM_KEY, false);
    String stdOutFilePath = null;
    if (saveStdOut) {
        Path logFile = DockerTaskCommon.createTmpFile(workDir, "stdout", ".log");
        stdOutFilePath = workDir.relativize(logFile).toString();
    }
    DockerContainerSpec spec = DockerContainerSpec.builder().image(params.image()).env(DockerTaskCommon.stringify(params.env())).envFile(DockerTaskCommon.getEnvFile(workDir, params)).entryPoint(DockerTaskCommon.prepareEntryPoint(workDir, params)).forcePull(params.forcePull()).options(DockerContainerSpec.Options.builder().hosts(params.hosts()).build()).debug(params.debug()).redirectErrorStream(redirectErrorStream).stdOutFilePath(stdOutFilePath).pullRetryCount(params.pullRetryCount()).pullRetryInterval(params.pullRetryInterval()).build();
    StringBuilder stdErr = new StringBuilder();
    int code = dockerService.start(spec, logStdOut ? line -> processLog.info("DOCKER: {}", line) : null, logStdError || saveStdError ? line -> {
        if (logStdError) {
            processLog.info("DOCKER: {}", line);
        }
        if (saveStdError) {
            stdErr.append(line).append("\n");
        }
    } : null);
    String stdOut = null;
    if (stdOutFilePath != null) {
        InputStream inputStream = Files.newInputStream(Paths.get(stdOutFilePath));
        stdOut = DockerTaskCommon.toString(inputStream);
    }
    if (code != SUCCESS_EXIT_CODE) {
        log.warn("call ['{}', '{}', '{}'] -> finished with code {}", params.image(), params.cmd(), workDir, code);
        return TaskResult.fail("Docker process finished with exit code " + code).value("stdout", stdOut).value("stderr", stdErr.toString());
    }
    log.info("call ['{}', '{}', '{}', '{}'] -> done", params.image(), params.cmd(), workDir, params.hosts());
    return TaskResult.success().value("stdout", stdOut).value("stderr", stdErr.toString());
}
Also used : Path(java.nio.file.Path) com.walmartlabs.concord.runtime.v2.sdk(com.walmartlabs.concord.runtime.v2.sdk) Inject(javax.inject.Inject) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Paths(java.nio.file.Paths) SUCCESS_EXIT_CODE(com.walmartlabs.concord.plugins.docker.DockerConstants.SUCCESS_EXIT_CODE) LoggerFactory(org.slf4j.LoggerFactory) Named(javax.inject.Named) Path(java.nio.file.Path) InputStream(java.io.InputStream) InputStream(java.io.InputStream)

Example 27 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord by walmartlabs.

the class ConcordTaskParams method of.

public static ConcordTaskParams of(Variables input, Map<String, Object> defaults) {
    Map<String, Object> variablesMap = new HashMap<>(defaults != null ? defaults : Collections.emptyMap());
    variablesMap.putAll(input.toMap());
    Variables variables = new MapBackedVariables(variablesMap);
    ConcordTaskParams p = new ConcordTaskParams(variables);
    switch(p.action()) {
        case START:
            {
                return new StartParams(variables);
            }
        case STARTEXTERNAL:
            {
                return new StartExternalParams(variables);
            }
        case FORK:
            {
                return new ForkParams(variables);
            }
        case KILL:
            {
                return new KillParams(variables);
            }
        default:
            {
                throw new IllegalArgumentException("Unsupported action type: " + p.action());
            }
    }
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)

Example 28 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class TaskParams method of.

public static TaskParams of(Variables input, Map<String, Object> defaults) {
    Variables variables = merge(input, defaults);
    Action action = new TaskParams(variables).action();
    switch(action) {
        case CREATEPAGE:
            {
                return new CreatePageParams(variables);
            }
        case UPDATEPAGE:
            {
                return new UpdatePageParams(variables);
            }
        case ADDCOMMENTSTOPAGE:
            {
                return new AddCommentsToPage(variables);
            }
        case UPLOADATTACHMENT:
            {
                return new UploadAttachmentParams(variables);
            }
        case CREATECHILDPAGE:
            {
                return new CreateChildPageParams(variables);
            }
        case GETPAGECONTENT:
            {
                return new GetPageParams(variables);
            }
        case DELETEPAGE:
            {
                return new DeletePageParams(variables);
            }
        default:
            throw new IllegalArgumentException("Unsupported action type: " + action);
    }
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

Example 29 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class HashiVaultTaskV2Test method testReadTokenFromSecretV2.

@Test
public void testReadTokenFromSecretV2() throws Exception {
    Map<String, Object> varMap = new HashMap<>();
    Map<String, Object> secretInfo = new HashMap<>(3);
    secretInfo.put("org", "my-org");
    secretInfo.put("name", "my-secret");
    varMap.put("apiTokenSecret", secretInfo);
    varMap.put("baseUrl", getBaseUrl());
    varMap.put("path", "cubbyhole/hello");
    Variables vars = new MapBackedVariables(varMap);
    SimpleResult result = getTask(false).execute(vars);
    Assert.assertTrue(result.ok());
    final Map<String, Object> data = MapUtils.assertMap(result.values(), "data");
    assertEquals("cubbyVal", data.get("cubbyKey"));
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) SimpleResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult) Test(org.junit.Test)

Example 30 with Variables

use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.

the class HashiVaultTaskV2Test method testReadKvSingleV2.

@Test
public void testReadKvSingleV2() throws Exception {
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("path", "secret/testing");
    varMap.put("key", "db_password");
    Variables vars = new MapBackedVariables(varMap);
    SimpleResult result = getTask(true).execute(vars);
    Assert.assertTrue(result.ok());
    final String data = MapUtils.getString(result.values(), "data");
    assertEquals("dbpassword1", data);
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) SimpleResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult) Test(org.junit.Test)

Aggregations

Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)24 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)16 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 SimpleResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)5 Path (java.nio.file.Path)4 Map (java.util.Map)4 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)3 UpdateLocalsCommand (com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)3 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)2 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)2 com.walmartlabs.concord.runtime.v2.sdk (com.walmartlabs.concord.runtime.v2.sdk)2 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Injector (com.google.inject.Injector)1 ApiClient (com.walmartlabs.concord.ApiClient)1 DependencyManager (com.walmartlabs.concord.dependencymanager.DependencyManager)1