use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord by walmartlabs.
the class DockerTaskV2 method execute.
@Override
public TaskResult execute(Variables input) throws Exception {
Path workDir = this.workDir.getValue();
TaskParams params = new TaskParams(input);
boolean logStdOut = input.getBoolean(LOG_STD_OUT_KEY, true);
boolean logStdError = input.getBoolean(LOG_STD_ERR_KEY, true);
boolean saveStdOut = input.getBoolean(SAVE_STD_OUT_KEY, false);
boolean saveStdError = input.getBoolean(SAVE_STD_ERR_KEY, false);
boolean redirectErrorStream = input.getBoolean(REDIRECT_ERROR_STREAM_KEY, false);
String stdOutFilePath = null;
if (saveStdOut) {
Path logFile = DockerTaskCommon.createTmpFile(workDir, "stdout", ".log");
stdOutFilePath = workDir.relativize(logFile).toString();
}
DockerContainerSpec spec = DockerContainerSpec.builder().image(params.image()).env(DockerTaskCommon.stringify(params.env())).envFile(DockerTaskCommon.getEnvFile(workDir, params)).entryPoint(DockerTaskCommon.prepareEntryPoint(workDir, params)).forcePull(params.forcePull()).options(DockerContainerSpec.Options.builder().hosts(params.hosts()).build()).debug(params.debug()).redirectErrorStream(redirectErrorStream).stdOutFilePath(stdOutFilePath).pullRetryCount(params.pullRetryCount()).pullRetryInterval(params.pullRetryInterval()).build();
StringBuilder stdErr = new StringBuilder();
int code = dockerService.start(spec, logStdOut ? line -> processLog.info("DOCKER: {}", line) : null, logStdError || saveStdError ? line -> {
if (logStdError) {
processLog.info("DOCKER: {}", line);
}
if (saveStdError) {
stdErr.append(line).append("\n");
}
} : null);
String stdOut = null;
if (stdOutFilePath != null) {
InputStream inputStream = Files.newInputStream(Paths.get(stdOutFilePath));
stdOut = DockerTaskCommon.toString(inputStream);
}
if (code != SUCCESS_EXIT_CODE) {
log.warn("call ['{}', '{}', '{}'] -> finished with code {}", params.image(), params.cmd(), workDir, code);
return TaskResult.fail("Docker process finished with exit code " + code).value("stdout", stdOut).value("stderr", stdErr.toString());
}
log.info("call ['{}', '{}', '{}', '{}'] -> done", params.image(), params.cmd(), workDir, params.hosts());
return TaskResult.success().value("stdout", stdOut).value("stderr", stdErr.toString());
}
use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord by walmartlabs.
the class ConcordTaskParams method of.
public static ConcordTaskParams of(Variables input, Map<String, Object> defaults) {
Map<String, Object> variablesMap = new HashMap<>(defaults != null ? defaults : Collections.emptyMap());
variablesMap.putAll(input.toMap());
Variables variables = new MapBackedVariables(variablesMap);
ConcordTaskParams p = new ConcordTaskParams(variables);
switch(p.action()) {
case START:
{
return new StartParams(variables);
}
case STARTEXTERNAL:
{
return new StartExternalParams(variables);
}
case FORK:
{
return new ForkParams(variables);
}
case KILL:
{
return new KillParams(variables);
}
default:
{
throw new IllegalArgumentException("Unsupported action type: " + p.action());
}
}
}
use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.
the class TaskParams method of.
public static TaskParams of(Variables input, Map<String, Object> defaults) {
Variables variables = merge(input, defaults);
Action action = new TaskParams(variables).action();
switch(action) {
case CREATEPAGE:
{
return new CreatePageParams(variables);
}
case UPDATEPAGE:
{
return new UpdatePageParams(variables);
}
case ADDCOMMENTSTOPAGE:
{
return new AddCommentsToPage(variables);
}
case UPLOADATTACHMENT:
{
return new UploadAttachmentParams(variables);
}
case CREATECHILDPAGE:
{
return new CreateChildPageParams(variables);
}
case GETPAGECONTENT:
{
return new GetPageParams(variables);
}
case DELETEPAGE:
{
return new DeletePageParams(variables);
}
default:
throw new IllegalArgumentException("Unsupported action type: " + action);
}
}
use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method testReadTokenFromSecretV2.
@Test
public void testReadTokenFromSecretV2() throws Exception {
Map<String, Object> varMap = new HashMap<>();
Map<String, Object> secretInfo = new HashMap<>(3);
secretInfo.put("org", "my-org");
secretInfo.put("name", "my-secret");
varMap.put("apiTokenSecret", secretInfo);
varMap.put("baseUrl", getBaseUrl());
varMap.put("path", "cubbyhole/hello");
Variables vars = new MapBackedVariables(varMap);
SimpleResult result = getTask(false).execute(vars);
Assert.assertTrue(result.ok());
final Map<String, Object> data = MapUtils.assertMap(result.values(), "data");
assertEquals("cubbyVal", data.get("cubbyKey"));
}
use of com.walmartlabs.concord.runtime.v2.sdk.Variables in project concord-plugins by walmartlabs.
the class HashiVaultTaskV2Test method testReadKvSingleV2.
@Test
public void testReadKvSingleV2() throws Exception {
Map<String, Object> varMap = new HashMap<>();
varMap.put("path", "secret/testing");
varMap.put("key", "db_password");
Variables vars = new MapBackedVariables(varMap);
SimpleResult result = getTask(true).execute(vars);
Assert.assertTrue(result.ok());
final String data = MapUtils.getString(result.values(), "data");
assertEquals("dbpassword1", data);
}
Aggregations