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