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;
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations