use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testEval1.
@Test
public void testEval1() {
/*
* configuration:
* arguments:
* x: ${y}
* z: ${y.y1}
* y:
* y1: ${task(..)}
* y2: "asdasd"
* y3: ${z}
*/
Map<Object, Object> input = map("x", "${y}", "z", "${y.y1}", "y", map("y1", "${in}", "y2", "abc", "y3", "${z}"));
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
Map<String, Object> vars = Collections.singletonMap("in", "task");
// scope -> ok
// ---
Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
Map<Object, Object> y = map("y1", "task", "y2", "abc", "y3", "task");
assertThat(output, is(map("x", y, "z", "task", "y", y)));
// ---
try {
ee.evalAsMap(global(vars), input);
fail("exception expected");
} catch (RuntimeException e) {
assertThat(e.getMessage(), containsString("variable in '${y}'"));
}
// undef -> x = null, z = null, y ...y3 = null
// ---
output = ee.evalAsMap(undefAsNull(global(vars)), input);
y.put("y3", null);
assertThat(output, is(map("x", null, "z", null, "y", y)));
}
use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testEval3.
@Test
public void testEval3() {
/*
* configuration:
* arguments:
* x: ${y}
* z: ${y.y1}
* y:
* y1: ${task(y.y2)}
* y2: "asdasd"
* y3: ${z}
*/
Map<Object, Object> input = map("x", "${y}", "z", "${y.y1}", "y", map("y1", "${task.foo(y.y2)}", "y2", "abc", "y3", "${z}"));
TaskProviders providers = mock(TaskProviders.class);
TestTask task = spy(new TestTask());
when(providers.createTask(any(), eq("task"))).thenReturn(task);
ExpressionEvaluator ee = new DefaultExpressionEvaluator(providers);
Map<String, Object> vars = Collections.emptyMap();
// ---
try {
ee.evalAsMap(global(vars), input);
fail("exception expected");
} catch (Exception e) {
assertThat(e.getMessage(), containsString("variable in '${y}'"));
}
verify(task, times(0)).foo(anyString());
// scope:
// ---
Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
Map<Object, Object> y = map("y1", "from-task: abc", "y2", "abc", "y3", "from-task: abc");
assertThat(output, is(map("x", y, "z", "from-task: abc", "y", y)));
verify(task, times(1)).foo(anyString());
}
use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord by walmartlabs.
the class TaskV2Provider method createTask.
@Override
public Task createTask(Context ctx, String key) {
Class<? extends Task> klass = holder.get(key);
if (klass == null) {
return null;
}
Map<String, Object> defaultVariables = defaultTaskVariables.get(key);
TaskContext taskContext = new TaskContext(ctx, new MapBackedVariables(defaultVariables));
return ContextProvider.withContext(taskContext, () -> injector.getInstance(klass));
}
use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord by walmartlabs.
the class InjectorFactory method create.
public Injector create() {
List<Module> l = new ArrayList<>();
l.add(new ConfigurationModule(workDir, runnerCfg, processConfigurationProvider));
l.add(new CurrentClasspathModule());
com.google.inject.Module tasks = new AbstractModule() {
@Override
protected void configure() {
TaskHolder<Task> holder = new TaskHolder<>();
bindListener(InjectorUtils.subClassesOf(Task.class), InjectorUtils.taskClassesListener(holder));
bind(new TypeLiteral<TaskHolder<Task>>() {
}).annotatedWith(V2.class).toInstance(holder);
}
};
l.add(tasks);
if (modules != null) {
l.addAll(Arrays.asList(modules));
}
com.google.inject.Module m = new WireModule(l);
return Guice.createInjector(m);
}
use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord by walmartlabs.
the class TaskCallStepSerializer method serialize.
@Override
public void serialize(TaskCall value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
TaskCallOptions o = Objects.requireNonNull(value.getOptions());
if ("log".equals(value.getName())) {
gen.writeObjectField("log", o.input().get("msg"));
} else {
gen.writeObjectField("task", value.getName());
writeNotEmptyObjectField("in", o.input(), gen);
writeNotEmptyObjectField("in", o.inputExpression(), gen);
}
writeNotEmptyObjectField("out", o.out(), gen);
writeNotEmptyObjectField("out", o.outExpr(), gen);
if (o.withItems() != null) {
WithItems items = Objects.requireNonNull(o.withItems());
writeWithItems(items, gen);
}
writeLoop(o.loop(), gen);
if (o.retry() != null) {
gen.writeObjectField("retry", o.retry());
}
writeNotEmptyObjectField("error", o.errorSteps(), gen);
writeNotEmptyObjectField("meta", o.meta(), gen);
if (o.ignoreErrors()) {
gen.writeObjectField("ignoreErrors", o.ignoreErrors());
}
gen.writeEndObject();
}
Aggregations