Search in sources :

Example 11 with Variables

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

the class JiraTask method getStatus.

public String getStatus(@InjectVariable("context") Context ctx, String issueKey) {
    Variables vars = TaskParams.merge(new ContextVariables(ctx), defaults);
    Map<String, Object> result = delegate(ctx).execute(new TaskParams.CurrentStatusParams(vars) {

        @Override
        public String issueKey() {
            return issueKey;
        }
    });
    return MapUtils.getString(result, JIRA_ISSUE_STATUS_KEY);
}
Also used : Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

Example 12 with Variables

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

the class ConcordTaskCommon method continueAfterSuspend.

public TaskResult continueAfterSuspend(ResumePayload payload) throws Exception {
    List<Result> results = new ArrayList<>();
    for (UUID processId : payload.jobs()) {
        Result r = continueAfterSuspend(payload.baseUrl(), payload.apiKey(), processId, payload.collectOutVars());
        results.add(r);
    }
    Map<String, ProcessEntry> instances = new HashMap<>();
    for (Result r : results) {
        UUID id = r.processEntry.getInstanceId();
        instances.put(id.toString(), r.processEntry);
    }
    handleResults(instances, payload.ignoreFailures());
    HashMap<String, Object> vars = new HashMap<>();
    for (Result r : results) {
        String id = r.processEntry.getInstanceId().toString();
        if (r.out != null) {
            vars.put(id, r.out);
        }
    }
    TaskResult.SimpleResult result = TaskResult.success().value("ids", payload.jobs().stream().map(UUID::toString).collect(Collectors.toList())).values(vars);
    boolean single = payload.jobs().size() == 1;
    if (single) {
        // for single job also put all variables at the top level of the result
        String id = payload.jobs().get(0).toString();
        Map<String, Object> out = results.get(0).out;
        result.value("id", id).values(out);
    }
    return result;
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult)

Example 13 with Variables

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

the class AnsibleTaskV2 method execute.

@Override
public TaskResult execute(Variables input) throws Exception {
    Map<String, Object> in = input.toMap();
    Path workDir = context.workingDirectory();
    PlaybookProcessRunner runner = new PlaybookProcessRunnerFactory(new AnsibleDockerServiceV2(context.dockerService()), workDir).create(in);
    AnsibleSecretService secretService = new AnsibleSecretServiceV2(context.secretService());
    AnsibleTask task = new AnsibleTask(apiClient, new AnsibleAuthFactory(secretService), secretService);
    UUID instanceId = Objects.requireNonNull(context.processInstanceId());
    Path tmpDir = context.fileService().createTempDirectory("ansible");
    ProjectInfo projectInfo = context.processConfiguration().projectInfo();
    AnsibleContext ctx = AnsibleContext.builder().apiBaseUrl(apiClient.getBasePath()).instanceId(instanceId).workDir(workDir).tmpDir(tmpDir).defaults(defaults).args(in).sessionToken(context.processConfiguration().processInfo().sessionToken()).eventCorrelationId(context.execution().correlationId()).orgName(projectInfo != null ? projectInfo.orgName() : null).retryCount(ContextUtils.getCurrentRetryAttemptNumber(context)).build();
    TaskResult.SimpleResult result = task.run(ctx, runner);
    if (!result.ok()) {
        throw new IllegalStateException("Process finished with exit code " + result.values().get("exitCode"));
    }
    return result;
}
Also used : Path(java.nio.file.Path) AnsibleSecretService(com.walmartlabs.concord.plugins.ansible.secrets.AnsibleSecretService) ProjectInfo(com.walmartlabs.concord.runtime.v2.sdk.ProjectInfo) UUID(java.util.UUID)

Example 14 with Variables

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

the class HasVariableFunction method hasVariable.

@SuppressWarnings("unchecked")
public static boolean hasVariable(String name) {
    if (name == null || name.trim().isEmpty()) {
        return false;
    }
    Variables variables = ThreadLocalEvalContext.get().variables();
    String[] path = name.split("\\.");
    if (path.length == 1) {
        return variables.has(name);
    } else {
        Object maybeMap = variables.get(path[0]);
        if (!(maybeMap instanceof Map)) {
            return false;
        }
        return ConfigurationUtils.has((Map<String, Object>) maybeMap, Arrays.copyOfRange(path, 1, path.length));
    }
}
Also used : Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables) Map(java.util.Map)

Example 15 with Variables

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

the class SlackChannelTaskParams method of.

public static SlackChannelTaskParams of(Variables input, Map<String, Object> defaults) {
    Variables variables = Utils.merge(input, defaults);
    SlackChannelTaskParams p = new SlackChannelTaskParams(variables);
    switch(p.action()) {
        case CREATE:
            {
                return new CreateChannelParams(variables);
            }
        case CREATEGROUP:
            {
                return new CreateGroupParams(variables);
            }
        case ARCHIVE:
            {
                return new ArchiveChannelParams(variables);
            }
        case ARCHIVEGROUP:
            {
                return new ArchiveGroupParams(variables);
            }
        default:
            {
                throw new IllegalArgumentException("Unsupported action type: " + p.action());
            }
    }
}
Also used : Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

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