use of com.walmartlabs.concord.runtime.v2.model.ProcessDefinition in project concord by walmartlabs.
the class Main method start.
private static ProcessSnapshot start(Runner runner, ProcessConfiguration cfg, Path workDir, Map<String, Object> args) throws Exception {
// assume all imports were processed by the agent
ProjectLoaderV2 loader = new ProjectLoaderV2(new NoopImportManager());
ProcessDefinition processDefinition = loader.load(workDir, new NoopImportsNormalizer(), ImportsListener.NOP_LISTENER).getProjectDefinition();
Map<String, Object> initiator = cfg.initiator();
if (initiator != null) {
// when the process starts the process' initiator and the current user are the same
args.put(Constants.Request.INITIATOR_KEY, initiator);
args.put(Constants.Request.CURRENT_USER_KEY, initiator);
}
return runner.start(cfg, processDefinition, args);
}
use of com.walmartlabs.concord.runtime.v2.model.ProcessDefinition in project concord by walmartlabs.
the class AbstractParserTest method load.
protected static ProcessDefinition load(String resource) throws Exception {
URI uri = ClassLoader.getSystemResource(resource).toURI();
ProjectLoaderV2 loader = new ProjectLoaderV2(mock(ImportManager.class));
return loader.loadFromFile(Paths.get(uri)).getProjectDefinition();
}
use of com.walmartlabs.concord.runtime.v2.model.ProcessDefinition 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();
}
use of com.walmartlabs.concord.runtime.v2.model.ProcessDefinition 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.model.ProcessDefinition 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