Search in sources :

Example 6 with ProcessDefinition

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);
}
Also used : NoopImportManager(com.walmartlabs.concord.imports.NoopImportManager) ProjectLoaderV2(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2) NoopImportsNormalizer(com.walmartlabs.concord.runtime.v2.NoopImportsNormalizer) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)

Example 7 with ProcessDefinition

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();
}
Also used : ImportManager(com.walmartlabs.concord.imports.ImportManager) ProjectLoaderV2(com.walmartlabs.concord.runtime.v2.ProjectLoaderV2) URI(java.net.URI)

Example 8 with ProcessDefinition

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();
}
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 9 with ProcessDefinition

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);
}
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 10 with ProcessDefinition

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);
}
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

ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)6 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)5 ProjectLoaderV2 (com.walmartlabs.concord.runtime.v2.ProjectLoaderV2)4 ImportManager (com.walmartlabs.concord.imports.ImportManager)3 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)3 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)3 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)3 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)3 Imports (com.walmartlabs.concord.imports.Imports)2 NoopImportsNormalizer (com.walmartlabs.concord.runtime.v2.NoopImportsNormalizer)2 YamlParserV2 (com.walmartlabs.concord.runtime.v2.parser.YamlParserV2)2 EvalContext (com.walmartlabs.concord.runtime.v2.runner.el.EvalContext)2 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 Compiler (com.walmartlabs.concord.runtime.v2.sdk.Compiler)2 Frame (com.walmartlabs.concord.svm.Frame)2 URI (java.net.URI)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Injector (com.google.inject.Injector)1 ApiException (com.walmartlabs.concord.ApiException)1