use of com.walmartlabs.concord.runtime.v2.sdk.ProjectInfo 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.ProjectInfo 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.ProjectInfo in project concord by walmartlabs.
the class CryptoTaskV2 method encryptString.
public String encryptString(String value) throws Exception {
ProjectInfo projectInfo = processCfg.projectInfo();
String orgName = projectInfo.orgName();
String projectName = projectInfo.projectName();
if (orgName == null || projectName == null) {
throw new IllegalStateException("The process must run in a project in order to be able to encrypt strings.");
}
return secretService.encryptString(orgName, projectName, value);
}
use of com.walmartlabs.concord.runtime.v2.sdk.ProjectInfo in project concord-plugins by walmartlabs.
the class ConcordV2Backend method getStateId.
private static String getStateId(Context ctx, Map<String, Object> cfg) {
String s = MapUtils.getString(cfg, TaskConstants.STATE_ID_KEY);
if (s != null) {
return s;
}
ProjectInfo projectInfo = ctx.processConfiguration().projectInfo();
if (projectInfo == null || projectInfo.projectName() == null) {
throw new IllegalArgumentException("Can't determine '" + TaskConstants.STATE_ID_KEY + "'. The 'concord' backend can only be used for processes running in a project.");
}
s = "tfState-" + projectInfo.projectName();
String repoName = projectInfo.repoName();
if (repoName != null) {
s += "-" + repoName;
}
return s;
}
Aggregations