use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.
the class SleepTask method execute.
@Override
public void execute(Context ctx) throws Exception {
Supplier<Suspender> suspender = () -> {
ApiClient apiClient = apiClientFactory.create(ApiClientConfiguration.builder().context(ctx).build());
return new Suspender(apiClient, ContextUtils.getTxId(ctx));
};
Map<String, Object> cfg = createCfg(ctx);
TaskResult taskResult = new SleepTaskCommon(suspender).execute(new TaskParams(cfg));
if (taskResult instanceof TaskResult.SuspendResult) {
ctx.suspend(((TaskResult.SuspendResult) taskResult).eventName());
}
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.
the class TaskPolicy method paramMatches.
@SuppressWarnings("unchecked")
private static boolean paramMatches(String[] names, int nameIndex, List<Object> values, Object param, boolean isProtected) {
if (param == null) {
return values.contains(null);
}
if (param instanceof Map) {
if (names == null) {
return false;
}
Map<String, Object> m = (Map<String, Object>) param;
String name = names[nameIndex];
nameIndex += 1;
return paramMatches(names, nameIndex, values, m.get(name), isProtected);
} else if (param instanceof Context) {
if (names == null) {
return false;
}
Context ctx = (Context) param;
String name = names[nameIndex];
nameIndex += 1;
Object v = isProtected ? ctx.getProtectedVariable(name) : ctx.getVariable(name);
return paramMatches(names, nameIndex, values, v, isProtected);
} else if (param instanceof Variables) {
Variables vars = (Variables) param;
String name = names[nameIndex];
nameIndex += 1;
Object v = vars.get(name);
return paramMatches(names, nameIndex, values, v, isProtected);
} else if (param instanceof com.walmartlabs.concord.runtime.v2.sdk.Context) {
com.walmartlabs.concord.runtime.v2.sdk.Context ctx = (com.walmartlabs.concord.runtime.v2.sdk.Context) param;
String name = names[nameIndex];
nameIndex += 1;
Object v = ctx.variables().get(name);
return paramMatches(names, nameIndex, values, v, isProtected);
} else if (param instanceof String) {
return Utils.matchAny(values.stream().map(Object::toString).collect(Collectors.toList()), param.toString());
} else {
for (Object v : values) {
if (v != null && v.equals(param)) {
return true;
}
}
}
return false;
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.
the class SecretsTask method execute.
@Override
public void execute(Context ctx) throws Exception {
SecretsTaskParams in = SecretsTaskParams.of(new ContextBackedVariables(ctx));
TaskResult.SimpleResult result = new SecretsTaskCommon(clientFactory.create(ctx), getProcessOrgName(ctx)).execute(in);
ctx.setVariable(RESULT_KEY, result.toMap());
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord-plugins by walmartlabs.
the class HashiVaultTask method createParams.
private TaskParams createParams(Context ctx, Map<String, Object> input) {
final MapBackedVariables vars = new MapBackedVariables(input);
final SecretExporterV1 exporterV1 = new SecretExporterV1(ctx, secretService);
return TaskParams.of(vars, defaults, exporterV1);
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context 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