Search in sources :

Example 31 with Context

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());
    }
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ApiClient(com.walmartlabs.concord.ApiClient)

Example 32 with Context

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;
}
Also used : Context(com.walmartlabs.concord.sdk.Context) Variables(com.walmartlabs.concord.runtime.v2.sdk.Variables)

Example 33 with Context

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());
}
Also used : ContextBackedVariables(com.walmartlabs.concord.client.v1.ContextBackedVariables) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult)

Example 34 with Context

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);
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)

Example 35 with Context

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;
}
Also used : ProjectInfo(com.walmartlabs.concord.runtime.v2.sdk.ProjectInfo)

Aggregations

Context (com.walmartlabs.concord.runtime.v2.sdk.Context)18 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)15 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)6 HashMap (java.util.HashMap)6 ContextFactory (com.walmartlabs.concord.runtime.v2.runner.context.ContextFactory)5 EvalContext (com.walmartlabs.concord.runtime.v2.runner.el.EvalContext)4 EvalContextFactory (com.walmartlabs.concord.runtime.v2.runner.el.EvalContextFactory)4 TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)4 Map (java.util.Map)4 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)3 ApiClient (com.walmartlabs.concord.ApiClient)3 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)3 BlockCommand (com.walmartlabs.concord.runtime.v2.runner.vm.BlockCommand)3 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)3 Command (com.walmartlabs.concord.svm.Command)3 MimeMessage (javax.mail.internet.MimeMessage)3 Test (org.junit.jupiter.api.Test)3 HashiVaultTask (com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask)2 Step (com.walmartlabs.concord.runtime.v2.model.Step)2 LogContext (com.walmartlabs.concord.runtime.v2.runner.logging.LogContext)2