use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor in project concord by walmartlabs.
the class TaskMethodResolver method invoke.
@Override
public Object invoke(ELContext elContext, Object base, Object method, Class<?>[] paramTypes, Object[] params) {
Step step = context.execution().currentStep();
if (!(step instanceof Expression) || !(base instanceof Task) || !(method instanceof String)) {
return null;
}
String taskName = getName(base);
if (taskName == null) {
return null;
}
CallContext callContext = TaskCallInterceptor.CallContext.builder().taskName(taskName).correlationId(context.execution().correlationId()).currentStep(step).processDefinition(context.execution().processDefinition()).build();
TaskCallInterceptor interceptor = context.execution().runtime().getService(TaskCallInterceptor.class);
try {
return interceptor.invoke(callContext, Method.of(base, (String) method, Arrays.asList(params)), () -> super.invoke(elContext, base, method, paramTypes, params));
} catch (javax.el.MethodNotFoundException e) {
throw new MethodNotFoundException(base, method, paramTypes);
} catch (javax.el.ELException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor 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);
}
use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor 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);
}
Aggregations