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