Search in sources :

Example 1 with ProcessConfiguration

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

the class FormCallCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    String eventRef = UUID.randomUUID().toString();
    Context ctx = runtime.getService(Context.class);
    ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
    EvalContext evalContext = EvalContextFactory.global(ctx);
    FormCall call = getStep();
    String formName = expressionEvaluator.eval(evalContext, call.getName(), String.class);
    ProcessDefinition processDefinition = runtime.getService(ProcessDefinition.class);
    ProcessConfiguration processConfiguration = runtime.getService(ProcessConfiguration.class);
    List<FormField> fields = assertFormFields(expressionEvaluator, evalContext, processConfiguration, processDefinition, formName, call);
    Form form = Form.builder().name(formName).eventName(eventRef).options(buildFormOptions(expressionEvaluator, evalContext, call)).fields(buildFormFields(expressionEvaluator, evalContext, fields, Objects.requireNonNull(call.getOptions()).values())).build();
    FormService formService = runtime.getService(FormService.class);
    formService.save(form);
    state.peekFrame(threadId).pop();
    state.setEventRef(threadId, eventRef);
    state.setStatus(threadId, ThreadStatus.SUSPENDED);
}
Also used : EvalContext(com.walmartlabs.concord.runtime.v2.runner.el.EvalContext) Context(com.walmartlabs.concord.runtime.v2.sdk.Context) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration) Form(com.walmartlabs.concord.forms.Form) FormService(com.walmartlabs.concord.runtime.common.FormService) EvalContext(com.walmartlabs.concord.runtime.v2.runner.el.EvalContext) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 2 with ProcessConfiguration

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

the class InjectorFactory method createDefault.

public static Injector createDefault(RunnerConfiguration runnerCfg) {
    Path src = Paths.get(System.getProperty("user.dir"));
    Provider<ProcessConfiguration> processCfgProvider = new DefaultProcessConfigurationProvider(src);
    WorkingDirectory workDir = new WorkingDirectory(src);
    return new InjectorFactory(workDir, runnerCfg, processCfgProvider, // bind default services
    new DefaultRunnerModule(), // grab process dependencies
    new ProcessDependenciesModule(workDir.getValue(), runnerCfg.dependencies(), runnerCfg.debug())).create();
}
Also used : Path(java.nio.file.Path) WorkingDirectory(com.walmartlabs.concord.runtime.v2.sdk.WorkingDirectory) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration) ProcessDependenciesModule(com.walmartlabs.concord.runtime.v2.runner.guice.ProcessDependenciesModule) DefaultRunnerModule(com.walmartlabs.concord.runtime.v2.runner.guice.DefaultRunnerModule)

Example 3 with ProcessConfiguration

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

the class Main method main.

public static void main(String[] args) throws Exception {
    RunnerConfiguration runnerCfg = readRunnerConfiguration(args);
    // create the inject with all dependencies and services available before
    // the actual process' working directory is ready. It allows us to load
    // all dependencies and have them available in "pre-fork" situations
    Injector injector = InjectorFactory.createDefault(runnerCfg);
    try {
        ProcessConfiguration processCfg = injector.getInstance(ProcessConfiguration.class);
        ApiClient apiClient = injector.getInstance(ApiClient.class);
        ProcessHeartbeat heartbeat = new ProcessHeartbeat(apiClient, processCfg.instanceId(), runnerCfg.api().maxNoHeartbeatInterval());
        heartbeat.start();
        Main main = injector.getInstance(Main.class);
        main.execute();
        System.exit(0);
    } catch (MultiException e) {
        log.error(e.getMessage());
        System.exit(1);
    } catch (Throwable t) {
        log.error("", t);
        System.exit(1);
    }
}
Also used : ProcessHeartbeat(com.walmartlabs.concord.runtime.common.ProcessHeartbeat) ProcessConfiguration(com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration) Injector(com.google.inject.Injector) RunnerConfiguration(com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration) ApiClient(com.walmartlabs.concord.ApiClient) MultiException(com.walmartlabs.concord.svm.MultiException)

Example 4 with ProcessConfiguration

use of com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration 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 5 with ProcessConfiguration

use of com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration 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)

Aggregations

ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)6 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)4 Injector (com.google.inject.Injector)3 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)3 Path (java.nio.file.Path)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 RunnerConfiguration (com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration)2 ProjectLoaderV2 (com.walmartlabs.concord.runtime.v2.ProjectLoaderV2)2 EvalContext (com.walmartlabs.concord.runtime.v2.runner.el.EvalContext)2 ProcessDependenciesModule (com.walmartlabs.concord.runtime.v2.runner.guice.ProcessDependenciesModule)2 Compiler (com.walmartlabs.concord.runtime.v2.sdk.Compiler)2 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)2 WorkingDirectory (com.walmartlabs.concord.runtime.v2.sdk.WorkingDirectory)2 AbstractModule (com.google.inject.AbstractModule)1 ApiClient (com.walmartlabs.concord.ApiClient)1 DependencyManager (com.walmartlabs.concord.dependencymanager.DependencyManager)1 Form (com.walmartlabs.concord.forms.Form)1 ImportManager (com.walmartlabs.concord.imports.ImportManager)1 ImportManagerFactory (com.walmartlabs.concord.imports.ImportManagerFactory)1 ImportProcessingException (com.walmartlabs.concord.imports.ImportProcessingException)1