Search in sources :

Example 1 with TaskCall

use of com.walmartlabs.concord.runtime.v2.model.TaskCall 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 2 with TaskCall

use of com.walmartlabs.concord.runtime.v2.model.TaskCall in project concord by walmartlabs.

the class EventRecordingExecutionListener method afterCommand.

@Override
public Result afterCommand(Runtime runtime, VM vm, State state, ThreadId threadId, Command cmd) {
    if (!eventConfiguration.recordEvents()) {
        return Result.CONTINUE;
    }
    if (!(cmd instanceof StepCommand)) {
        return Result.CONTINUE;
    }
    StepCommand<?> s = (StepCommand<?>) cmd;
    if (s.getStep() instanceof TaskCall || s.getStep() instanceof Expression) {
        return Result.CONTINUE;
    }
    ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
    Location loc = s.getStep().getLocation();
    Map<String, Object> m = new HashMap<>();
    m.put("processDefinitionId", ProcessDefinitionUtils.getCurrentFlowName(pd, s.getStep()));
    m.put("fileName", loc.fileName());
    m.put("line", loc.lineNum());
    m.put("column", loc.column());
    m.put("description", getDescription(s.getStep()));
    m.put("correlationId", s.getCorrelationId());
    ProcessEventRequest req = new ProcessEventRequest();
    // TODO constants
    req.setEventType("ELEMENT");
    req.setData(m);
    req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
    try {
        eventsApi.event(processInstanceId.getValue(), req);
    } catch (ApiException e) {
        log.warn("afterCommand [{}] -> error while sending an event to the server: {}", cmd, e.getMessage());
    }
    return Result.CONTINUE;
}
Also used : StepCommand(com.walmartlabs.concord.runtime.v2.runner.vm.StepCommand) ProcessEventRequest(com.walmartlabs.concord.client.ProcessEventRequest) HashMap(java.util.HashMap) ApiException(com.walmartlabs.concord.ApiException)

Example 3 with TaskCall

use of com.walmartlabs.concord.runtime.v2.model.TaskCall in project concord by walmartlabs.

the class ContextImpl method reentrantSuspend.

@Override
public void reentrantSuspend(String eventName, Map<String, Serializable> taskState) {
    Step step = execution().currentStep();
    if (!(step instanceof TaskCall)) {
        throw new IllegalStateException("Calling 'suspendResume' is allowed only in task calls. Current step: " + (step != null ? step.getClass() : "n/a"));
    }
    state.peekFrame(currentThreadId).push(new TaskSuspendCommand(correlationId, LogUtils.getContext(), eventName, (TaskCall) step, taskState));
}
Also used : TaskCall(com.walmartlabs.concord.runtime.v2.model.TaskCall) TaskSuspendCommand(com.walmartlabs.concord.runtime.v2.runner.vm.TaskSuspendCommand) Step(com.walmartlabs.concord.runtime.v2.model.Step)

Example 4 with TaskCall

use of com.walmartlabs.concord.runtime.v2.model.TaskCall in project concord by walmartlabs.

the class TaskCallStepSerializer method serialize.

@Override
public void serialize(TaskCall value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeStartObject();
    TaskCallOptions o = Objects.requireNonNull(value.getOptions());
    if ("log".equals(value.getName())) {
        gen.writeObjectField("log", o.input().get("msg"));
    } else {
        gen.writeObjectField("task", value.getName());
        writeNotEmptyObjectField("in", o.input(), gen);
        writeNotEmptyObjectField("in", o.inputExpression(), gen);
    }
    writeNotEmptyObjectField("out", o.out(), gen);
    writeNotEmptyObjectField("out", o.outExpr(), gen);
    if (o.withItems() != null) {
        WithItems items = Objects.requireNonNull(o.withItems());
        writeWithItems(items, gen);
    }
    writeLoop(o.loop(), gen);
    if (o.retry() != null) {
        gen.writeObjectField("retry", o.retry());
    }
    writeNotEmptyObjectField("error", o.errorSteps(), gen);
    writeNotEmptyObjectField("meta", o.meta(), gen);
    if (o.ignoreErrors()) {
        gen.writeObjectField("ignoreErrors", o.ignoreErrors());
    }
    gen.writeEndObject();
}
Also used : TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) WithItems(com.walmartlabs.concord.runtime.v2.model.WithItems)

Aggregations

TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)2 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)2 ApiException (com.walmartlabs.concord.ApiException)1 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)1 Step (com.walmartlabs.concord.runtime.v2.model.Step)1 WithItems (com.walmartlabs.concord.runtime.v2.model.WithItems)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)1 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)1 StepCommand (com.walmartlabs.concord.runtime.v2.runner.vm.StepCommand)1 TaskSuspendCommand (com.walmartlabs.concord.runtime.v2.runner.vm.TaskSuspendCommand)1 Frame (com.walmartlabs.concord.svm.Frame)1 HashMap (java.util.HashMap)1