Search in sources :

Example 16 with Context

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

the class LockTask method lock.

public void lock(@InjectVariable("txId") String instanceId, String lockName, String scope) throws Exception {
    ApiClient apiClient = apiClientFactory.create(context);
    TaskResult taskResult = new LockTaskCommon(apiClient, UUID.fromString(instanceId)).lock(lockName, scope);
    if (taskResult instanceof TaskResult.SuspendResult) {
        context.suspend(((TaskResult.SuspendResult) taskResult).eventName());
    }
}
Also used : TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) ApiClient(com.walmartlabs.concord.ApiClient)

Example 17 with Context

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

the class IfCompiler method compile.

@Override
public Command compile(CompilerContext context, IfStep step) {
    Command thenCommand = compile(context, step.getThenSteps());
    Command elseCommand = compile(context, step.getElseSteps());
    return new IfCommand(step, thenCommand, elseCommand);
}
Also used : BlockCommand(com.walmartlabs.concord.runtime.v2.runner.vm.BlockCommand) IfCommand(com.walmartlabs.concord.runtime.v2.runner.vm.IfCommand) Command(com.walmartlabs.concord.svm.Command) IfCommand(com.walmartlabs.concord.runtime.v2.runner.vm.IfCommand)

Example 18 with Context

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

the class SwitchCompiler method compile.

@Override
public Command compile(CompilerContext context, SwitchStep step) {
    List<Map.Entry<String, Command>> caseCommands = new ArrayList<>();
    for (Map.Entry<String, List<Step>> kv : step.getCaseSteps()) {
        caseCommands.add(new AbstractMap.SimpleEntry<>(kv.getKey(), compile(context, kv.getValue())));
    }
    Command defaultCommand = compile(context, step.getDefaultSteps());
    return new SwitchCommand(step, caseCommands, defaultCommand);
}
Also used : AbstractMap(java.util.AbstractMap) SwitchCommand(com.walmartlabs.concord.runtime.v2.runner.vm.SwitchCommand) SwitchCommand(com.walmartlabs.concord.runtime.v2.runner.vm.SwitchCommand) BlockCommand(com.walmartlabs.concord.runtime.v2.runner.vm.BlockCommand) Command(com.walmartlabs.concord.svm.Command) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 19 with Context

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

the class TaskCallCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    Frame frame = state.peekFrame(threadId);
    frame.pop();
    Context ctx = runtime.getService(Context.class);
    TaskProviders taskProviders = runtime.getService(TaskProviders.class);
    ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
    TaskCall call = getStep();
    String taskName = call.getName();
    Task t = taskProviders.createTask(ctx, taskName);
    if (t == null) {
        throw new IllegalStateException("Task not found: '" + taskName + "'");
    }
    TaskCallInterceptor interceptor = runtime.getService(TaskCallInterceptor.class);
    CallContext callContext = CallContext.builder().taskName(taskName).correlationId(ctx.execution().correlationId()).currentStep(getStep()).processDefinition(ctx.execution().processDefinition()).build();
    TaskCallOptions opts = Objects.requireNonNull(call.getOptions());
    Variables input = new MapBackedVariables(VMUtils.prepareInput(expressionEvaluator, ctx, opts.input(), opts.inputExpression()));
    TaskResult result;
    try {
        result = interceptor.invoke(callContext, Method.of(t, "execute", Collections.singletonList(input)), () -> t.execute(input));
    } catch (TaskException e) {
        result = TaskResult.fail(e.getCause());
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TaskCallUtils.processTaskResult(runtime, ctx, taskName, opts, result);
}
Also used : CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) Frame(com.walmartlabs.concord.svm.Frame) TaskCall(com.walmartlabs.concord.runtime.v2.model.TaskCall) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator) CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)

Example 20 with Context

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

the class TaskResumeCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    Frame frame = state.peekFrame(threadId);
    frame.pop();
    Context ctx = runtime.getService(Context.class);
    String taskName = getStep().getName();
    TaskProviders taskProviders = runtime.getService(TaskProviders.class);
    Task task = taskProviders.createTask(ctx, getStep().getName());
    if (task == null) {
        throw new IllegalStateException("Task not found: " + taskName);
    }
    if (!(task instanceof ReentrantTask)) {
        throw new IllegalStateException("The task doesn't implement the " + ReentrantTask.class.getSimpleName() + " interface and cannot be used as a \"reentrant\" task: " + taskName);
    }
    ReentrantTask rt = (ReentrantTask) task;
    TaskCallInterceptor.CallContext callContext = TaskCallInterceptor.CallContext.builder().taskName(taskName).correlationId(ctx.execution().correlationId()).currentStep(getStep()).processDefinition(ctx.execution().processDefinition()).build();
    TaskCallInterceptor interceptor = runtime.getService(TaskCallInterceptor.class);
    TaskResult result;
    try {
        result = interceptor.invoke(callContext, TaskCallInterceptor.Method.of(rt, "resume", Collections.singletonList(event)), () -> rt.resume(event));
    } catch (TaskException e) {
        result = TaskResult.fail(e.getCause());
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TaskCallUtils.processTaskResult(runtime, ctx, taskName, getStep().getOptions(), result);
}
Also used : LogContext(com.walmartlabs.concord.runtime.v2.runner.logging.LogContext) Frame(com.walmartlabs.concord.svm.Frame) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)

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