Search in sources :

Example 1 with Compiler

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

the class Runner method start.

public ProcessSnapshot start(ProcessConfiguration processConfiguration, ProcessDefinition processDefinition, Map<String, Object> input) throws Exception {
    statusCallback.onRunning(instanceId.getValue());
    log.debug("start ['{}'] -> running...", processConfiguration.entryPoint());
    Command cmd = CompilerUtils.compile(compiler, processConfiguration, processDefinition, processConfiguration.entryPoint());
    State state = new InMemoryState(cmd);
    // install the exception handler into the root frame
    // takes care of all unhandled errors bubbling up
    VMUtils.assertNearestRoot(state, state.getRootThreadId()).setExceptionHandler(new SaveLastErrorCommand());
    VM vm = createVM(processDefinition);
    // update the global variables using the input map by running a special command
    // TODO merge with the cfg's arguments
    vm.run(state, new UpdateLocalsCommand(input));
    // start the normal execution
    vm.start(state);
    log.debug("start ['{}'] -> done", processConfiguration.entryPoint());
    return ProcessSnapshot.builder().vmState(state).processDefinition(processDefinition).build();
}
Also used : SaveLastErrorCommand(com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand) UpdateLocalsCommand(com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand) SaveLastErrorCommand(com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand) UpdateLocalsCommand(com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)

Example 2 with Compiler

use of com.walmartlabs.concord.runtime.v2.sdk.Compiler 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 3 with Compiler

use of com.walmartlabs.concord.runtime.v2.sdk.Compiler 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

ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)2 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)2 Compiler (com.walmartlabs.concord.runtime.v2.sdk.Compiler)2 FlowCall (com.walmartlabs.concord.runtime.v2.model.FlowCall)1 FlowCallOptions (com.walmartlabs.concord.runtime.v2.model.FlowCallOptions)1 EvalContext (com.walmartlabs.concord.runtime.v2.runner.el.EvalContext)1 SaveLastErrorCommand (com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand)1 UpdateLocalsCommand (com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)1