Search in sources :

Example 1 with ProcessDefinition

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

the class ProjectLoaderV2 method export.

public void export(Path baseDir, Path destDir, ImportsNormalizer importsNormalizer, ImportsListener listener, CopyOption... options) throws Exception {
    YamlParserV2 parser = new YamlParserV2();
    ProcessDefinition root = loadRoot(parser, baseDir);
    Resources resources = root != null ? root.resources() : Resources.builder().build();
    boolean hasImports = root != null && root.imports() != null && !root.imports().isEmpty();
    if (!hasImports) {
        copyResources(baseDir, resources, destDir, options);
        return;
    }
    Path tmpDir = null;
    try {
        tmpDir = IOUtils.createTempDir("concord-export");
        copyResources(baseDir, resources, tmpDir, options);
        Imports imports = importsNormalizer.normalize(root.imports());
        importManager.process(imports, tmpDir, listener);
        copyResources(tmpDir, resources, destDir, options);
    } finally {
        if (tmpDir != null) {
            IOUtils.deleteRecursively(tmpDir);
        }
    }
}
Also used : YamlParserV2(com.walmartlabs.concord.runtime.v2.parser.YamlParserV2) Imports(com.walmartlabs.concord.imports.Imports)

Example 2 with ProcessDefinition

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

the class ProjectLoaderV2 method load.

public Result load(Path baseDir, ImportsNormalizer importsNormalizer, ImportsListener listener) throws Exception {
    YamlParserV2 parser = new YamlParserV2();
    // load the initial ProcessDefinition from the root concord.yml file
    // it will be used to determine whether we need to load other resources (e.g. imports)
    ProcessDefinition root = loadRoot(parser, baseDir);
    List<Snapshot> snapshots = Collections.emptyList();
    if (root != null) {
        Imports imports = importsNormalizer.normalize(root.imports());
        snapshots = importManager.process(imports, baseDir, listener);
    }
    List<Path> files = loadResources(baseDir, root != null ? root.resources() : Resources.builder().build());
    Collections.sort(files);
    List<ProcessDefinition> definitions = new ArrayList<>();
    for (Path p : files) {
        definitions.add(parser.parse(baseDir, p));
    }
    if (root != null) {
        definitions.add(root);
    }
    if (definitions.isEmpty()) {
        throw new IllegalStateException("Can't find any Concord process definition files in '" + baseDir + "'");
    }
    return new Result(snapshots, merge(definitions));
}
Also used : Snapshot(com.walmartlabs.concord.repository.Snapshot) YamlParserV2(com.walmartlabs.concord.runtime.v2.parser.YamlParserV2) Imports(com.walmartlabs.concord.imports.Imports)

Example 3 with ProcessDefinition

use of com.walmartlabs.concord.runtime.v2.model.ProcessDefinition 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);
    }
}
Also used : Task(com.walmartlabs.concord.runtime.v2.sdk.Task) Expression(com.walmartlabs.concord.runtime.v2.model.Expression) Step(com.walmartlabs.concord.runtime.v2.model.Step) CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) MethodNotFoundException(com.walmartlabs.concord.runtime.v2.runner.el.MethodNotFoundException) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor) MethodNotFoundException(com.walmartlabs.concord.runtime.v2.runner.el.MethodNotFoundException)

Example 4 with ProcessDefinition

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

the class CheckpointCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    state.peekFrame(threadId).pop();
    // eval the name in case it contains an expression
    Context ctx = runtime.getService(Context.class);
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    String name = ee.eval(EvalContextFactory.global(ctx), getStep().getName(), String.class);
    runtime.getService(SynchronizationService.class).point(() -> {
        CheckpointService checkpointService = runtime.getService(CheckpointService.class);
        ProcessDefinition processDefinition = runtime.getService(ProcessDefinition.class);
        // cleanup the internal state to reduce the serialized data size
        state.gc();
        // TODO validate checkpoint name
        checkpointService.create(threadId, getCorrelationId(), name, runtime, ProcessSnapshot.builder().vmState(state).processDefinition(processDefinition).build());
    });
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) SynchronizationService(com.walmartlabs.concord.runtime.v2.runner.SynchronizationService) CheckpointService(com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 5 with ProcessDefinition

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

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