use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.
the class LockTask method lock.
public void lock(@InjectVariable("txId") String instanceId, String lockName, String scope) throws Exception {
ApiClient apiClient = apiClientFactory.create(context);
TaskResult taskResult = new LockTaskCommon(apiClient, UUID.fromString(instanceId)).lock(lockName, scope);
if (taskResult instanceof TaskResult.SuspendResult) {
context.suspend(((TaskResult.SuspendResult) taskResult).eventName());
}
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.
the class IfCompiler method compile.
@Override
public Command compile(CompilerContext context, IfStep step) {
Command thenCommand = compile(context, step.getThenSteps());
Command elseCommand = compile(context, step.getElseSteps());
return new IfCommand(step, thenCommand, elseCommand);
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context in project concord by walmartlabs.
the class SwitchCompiler method compile.
@Override
public Command compile(CompilerContext context, SwitchStep step) {
List<Map.Entry<String, Command>> caseCommands = new ArrayList<>();
for (Map.Entry<String, List<Step>> kv : step.getCaseSteps()) {
caseCommands.add(new AbstractMap.SimpleEntry<>(kv.getKey(), compile(context, kv.getValue())));
}
Command defaultCommand = compile(context, step.getDefaultSteps());
return new SwitchCommand(step, caseCommands, defaultCommand);
}
use of com.walmartlabs.concord.runtime.v2.sdk.Context 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.sdk.Context 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