use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method getTask.
private HashiVaultTask getTask(boolean setDefaults) {
Map<String, Object> vars = new HashMap<>();
if (setDefaults) {
Map<String, Object> defaults = new HashMap<>();
defaults.put("baseUrl", getBaseUrl());
defaults.put("apiToken", getApiToken());
vars.put("hashivaultParams", defaults);
}
Context ctx = new MockContextV2(vars, null);
SecretService s = new MockSecretServiceV2(new MockSecretServiceDelegate() {
@Override
public String exportString(String o, String n, String p) {
return getApiToken();
}
});
return new HashiVaultTask(ctx, s);
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method writeAndRead.
private void writeAndRead(String path, String prefix) throws Exception {
HashiVaultTask task = getTask(true);
Map<String, Object> vars1 = new HashMap<>();
vars1.put("action", "writeKV");
vars1.put("path", path);
Map<String, Object> kvPairs = new HashMap<>(2);
kvPairs.put("key1", prefix + "Value1");
kvPairs.put("key2", prefix + "Value2");
vars1.put("kvPairs", kvPairs);
Variables input1 = new MapBackedVariables(vars1);
SimpleResult writeResult = task.execute(input1);
assertTrue(writeResult.ok());
// -- now get the values back
// resets context
task = getTask(true);
Map<String, Object> vars2 = new HashMap<>();
vars2.put("action", "readKV");
vars2.put("path", path);
Variables input2 = new MapBackedVariables(vars2);
SimpleResult readResult = task.execute(input2);
assertTrue(readResult.ok());
Map<String, Object> data = MapUtils.getMap(readResult.values(), "data", Collections.emptyMap());
assertEquals(prefix + "Value1", MapUtils.getString(data, "key1"));
assertEquals(prefix + "Value2", MapUtils.getString(data, "key2"));
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context 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.Context in project concord by walmartlabs.
the class RunPlaybookTask2 method run.
private void run(Context ctx, Path workDir, Map<String, Object> args) throws Exception {
ApiClient apiClient = apiClientFactory.create(ApiClientConfiguration.builder().context(context).build());
AnsibleSecretServiceV1 ansibleSecretService = new AnsibleSecretServiceV1(context, secretService);
AnsibleTask task = new AnsibleTask(apiClient, new AnsibleAuthFactory(ansibleSecretService), ansibleSecretService);
Map<String, Object> projectInfo = getMap(context, Constants.Request.PROJECT_INFO_KEY, null);
String orgName = projectInfo != null ? (String) projectInfo.get("orgName") : null;
AnsibleContext context = AnsibleContext.builder().apiBaseUrl(apiClient.getBasePath()).instanceId(UUID.fromString(txId)).workDir(workDir).tmpDir(createTmpDir(workDir)).defaults(defaults != null ? defaults : Collections.emptyMap()).args(args).sessionToken(apiCfg.getSessionToken(ctx)).eventCorrelationId(ctx.getEventCorrelationId()).orgName(orgName).retryCount((Integer) ctx.getVariable(Constants.Context.CURRENT_RETRY_COUNTER)).build();
PlaybookProcessRunner runner = new PlaybookProcessRunnerFactory(new AnsibleDockerServiceV1(ctx, dockerService), workDir).create(args);
TaskResult.SimpleResult result = task.run(context, runner);
result.values().forEach(ctx::setVariable);
if (!result.ok()) {
throw new IllegalStateException("Process finished with exit code " + result.values().get("exitCode"));
}
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context 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;
}
Aggregations