Search in sources :

Example 1 with TaskResult

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

the class ConfluenceTaskV2 method execute.

@Override
public TaskResult execute(Variables input) {
    Result result = new ConfluenceTaskCommon(context.workingDirectory(), context.variables().toMap()).execute(TaskParams.of(input, context.defaultVariables().toMap()));
    TaskResult.SimpleResult taskResult = TaskResult.of(result.ok, result.error);
    if (result.pageId != null) {
        taskResult.value("pageId", result.pageId);
    }
    if (result.childId != null) {
        taskResult.value("childId", result.childId);
    }
    if (result.data != null) {
        taskResult.value("data", result.data);
    }
    return taskResult;
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ConfluenceTaskCommon(com.walmartlabs.concord.plugins.confluence.ConfluenceTaskCommon) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) Result(com.walmartlabs.concord.plugins.confluence.Result)

Example 2 with TaskResult

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

the class TeamsV2TaskV2 method execute.

@Override
public TaskResult execute(Variables input) {
    Result r = delegate.execute(TeamsV2TaskParams.of(input, context.defaultVariables().toMap()));
    TaskResult.SimpleResult result = TaskResult.of(r.isOk(), r.getError()).value("data", r.getData());
    if (r.getActivityId() != null && r.getConversationId().contains(r.getActivityId())) {
        result.value("conversationId", r.getConversationId()).value("activityId", r.getActivityId());
    }
    return result;
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) Result(com.walmartlabs.concord.plugins.msteams.Result)

Example 3 with TaskResult

use of com.walmartlabs.concord.runtime.v2.sdk.TaskResult 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 4 with TaskResult

use of com.walmartlabs.concord.runtime.v2.sdk.TaskResult 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 5 with TaskResult

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

the class LockTask method lock.

public void lock(@InjectVariable("txId") String instanceId, String lockName, String scope) throws Exception {
    ApiClient apiClient = apiClientFactory.create(context);
    TaskResult taskResult = new LockTaskCommon(apiClient, UUID.fromString(instanceId)).lock(lockName, scope);
    if (taskResult instanceof TaskResult.SuspendResult) {
        context.suspend(((TaskResult.SuspendResult) taskResult).eventName());
    }
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ApiClient(com.walmartlabs.concord.ApiClient)

Aggregations

TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)6 ApiClient (com.walmartlabs.concord.ApiClient)3 Path (java.nio.file.Path)3 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)2 com.walmartlabs.concord.runtime.v2.sdk (com.walmartlabs.concord.runtime.v2.sdk)2 Frame (com.walmartlabs.concord.svm.Frame)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AnsibleSecretService (com.walmartlabs.concord.plugins.ansible.secrets.AnsibleSecretService)1 ConfluenceTaskCommon (com.walmartlabs.concord.plugins.confluence.ConfluenceTaskCommon)1 Result (com.walmartlabs.concord.plugins.confluence.Result)1 SUCCESS_EXIT_CODE (com.walmartlabs.concord.plugins.docker.DockerConstants.SUCCESS_EXIT_CODE)1 Result (com.walmartlabs.concord.plugins.msteams.Result)1 Result (com.walmartlabs.concord.plugins.s3.Result)1 TerraformTaskCommon.getAction (com.walmartlabs.concord.plugins.terraform.TerraformTaskCommon.getAction)1 TerraformTaskCommon.getEnv (com.walmartlabs.concord.plugins.terraform.TerraformTaskCommon.getEnv)1 TerraformActionResult (com.walmartlabs.concord.plugins.terraform.actions.TerraformActionResult)1