Search in sources :

Example 21 with Context

use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.

the class DefaultContextFactory method create.

@Override
public Context create(Runtime runtime, State state, ThreadId currentThreadId, Step currentStep, UUID correlationId) {
    ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
    Compiler compiler = runtime.getService(Compiler.class);
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    return new ContextImpl(compiler, ee, currentThreadId, runtime, state, pd, currentStep, correlationId, workingDirectory.getValue(), processInstanceId.getValue(), fileService, dockerService, secretService, lockService, apiConfiguration, processConfiguration);
}
Also used : Compiler(com.walmartlabs.concord.runtime.v2.sdk.Compiler) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 22 with Context

use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.

the class GroupOfStepsCompiler method compile.

@Override
public Command compile(CompilerContext context, GroupOfSteps step) {
    Command cmd = compile(context, step.getSteps());
    GroupOfStepsOptions options = Objects.requireNonNull(step.getOptions());
    WithItems withItems = options.withItems();
    if (withItems != null) {
        return WithItemsWrapper.of(cmd, withItems, options.out(), Collections.emptyMap());
    }
    Loop loop = options.loop();
    if (loop != null) {
        cmd = LoopWrapper.of(context, cmd, loop, options.out(), Collections.emptyMap());
    }
    List<Step> errorSteps = options.errorSteps();
    if (!options.errorSteps().isEmpty()) {
        cmd = new ErrorWrapper(cmd, compile(context, errorSteps));
    }
    return cmd;
}
Also used : BlockCommand(com.walmartlabs.concord.runtime.v2.runner.vm.BlockCommand) Command(com.walmartlabs.concord.svm.Command) ErrorWrapper(com.walmartlabs.concord.runtime.v2.runner.vm.ErrorWrapper)

Example 23 with Context

use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.

the class StepCommand method eval.

@Override
public void eval(Runtime runtime, State state, ThreadId threadId) {
    ContextFactory contextFactory = runtime.getService(ContextFactory.class);
    T step = getStep();
    UUID correlationId = getCorrelationId();
    Context ctx = contextFactory.create(runtime, state, threadId, step, correlationId);
    LogContext logContext = getLogContext(runtime, ctx, correlationId);
    if (logContext == null) {
        executeWithContext(ctx, runtime, state, threadId);
    } else {
        runtime.getService(RunnerLogger.class).withContext(logContext, () -> executeWithContext(ctx, runtime, state, threadId));
    }
}
Also used : ContextFactory(com.walmartlabs.concord.runtime.v2.runner.context.ContextFactory) LogContext(com.walmartlabs.concord.runtime.v2.runner.logging.LogContext) Context(com.walmartlabs.concord.runtime.v2.sdk.Context) LogContext(com.walmartlabs.concord.runtime.v2.runner.logging.LogContext) UUID(java.util.UUID) RunnerLogger(com.walmartlabs.concord.runtime.v2.runner.logging.RunnerLogger)

Example 24 with Context

use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.

the class ExpressionCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    state.peekFrame(threadId).pop();
    Context ctx = runtime.getService(Context.class);
    Expression step = getStep();
    String expr = step.getExpr();
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    Object result = ee.eval(EvalContextFactory.global(ctx), expr, Object.class);
    ExpressionOptions opts = Objects.requireNonNull(step.getOptions());
    if (!opts.outExpr().isEmpty()) {
        ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
        Map<String, Object> vars = Collections.singletonMap("result", result);
        Map<String, Serializable> out = expressionEvaluator.evalAsMap(EvalContextFactory.global(ctx, vars), opts.outExpr());
        out.forEach((k, v) -> ctx.variables().set(k, v));
    } else if (opts.out() != null) {
        ctx.variables().set(opts.out(), result);
    }
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) Serializable(java.io.Serializable) ExpressionOptions(com.walmartlabs.concord.runtime.v2.model.ExpressionOptions) Expression(com.walmartlabs.concord.runtime.v2.model.Expression) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 25 with Context

use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.

the class FlowCallCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    state.peekFrame(threadId).pop();
    Context ctx = runtime.getService(Context.class);
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    EvalContext evalCtx = EvalContextFactory.global(ctx);
    FlowCall call = getStep();
    // the called flow's name
    String flowName = ee.eval(evalCtx, call.getFlowName(), String.class);
    // the called flow's steps
    Compiler compiler = runtime.getService(Compiler.class);
    ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
    ProcessConfiguration pc = runtime.getService(ProcessConfiguration.class);
    Command steps = CompilerUtils.compile(compiler, pc, pd, flowName);
    FlowCallOptions opts = Objects.requireNonNull(call.getOptions());
    Map<String, Object> input = VMUtils.prepareInput(ee, ctx, opts.input(), opts.inputExpression());
    // the call's frame should be a "root" frame
    // all local variables will have this frame as their base
    Frame innerFrame = Frame.builder().root().commands(steps).locals(input).build();
    // an "out" handler:
    // grab the out variable from the called flow's frame
    // and put it into the callee's frame
    Command processOutVars;
    if (!opts.outExpr().isEmpty()) {
        processOutVars = new EvalVariablesCommand(ctx, opts.outExpr(), innerFrame);
    } else {
        processOutVars = new CopyVariablesCommand(opts.out(), innerFrame, VMUtils::assertNearestRoot);
    }
    // push the out handler first so it executes after the called flow's frame is done
    state.peekFrame(threadId).push(processOutVars);
    state.pushFrame(threadId, innerFrame);
}
Also used : EvalContext(com.walmartlabs.concord.runtime.v2.runner.el.EvalContext) Context(com.walmartlabs.concord.runtime.v2.sdk.Context) Compiler(com.walmartlabs.concord.runtime.v2.sdk.Compiler) FlowCall(com.walmartlabs.concord.runtime.v2.model.FlowCall) EvalContext(com.walmartlabs.concord.runtime.v2.runner.el.EvalContext) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator) FlowCallOptions(com.walmartlabs.concord.runtime.v2.model.FlowCallOptions) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)

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