Search in sources :

Example 16 with Task

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)));
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 17 with Task

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());
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 18 with Task

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));
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) TaskContext(com.walmartlabs.concord.runtime.v2.runner.context.TaskContext)

Example 19 with Task

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);
}
Also used : Module(com.google.inject.Module) Task(com.walmartlabs.concord.runtime.v2.sdk.Task) WireModule(org.eclipse.sisu.wire.WireModule) TaskHolder(com.walmartlabs.concord.runtime.common.injector.TaskHolder) ArrayList(java.util.ArrayList) CurrentClasspathModule(com.walmartlabs.concord.runtime.v2.runner.guice.CurrentClasspathModule) AbstractModule(com.google.inject.AbstractModule) Module(com.google.inject.Module) CurrentClasspathModule(com.walmartlabs.concord.runtime.v2.runner.guice.CurrentClasspathModule) WireModule(org.eclipse.sisu.wire.WireModule) ProcessDependenciesModule(com.walmartlabs.concord.runtime.v2.runner.guice.ProcessDependenciesModule) DefaultRunnerModule(com.walmartlabs.concord.runtime.v2.runner.guice.DefaultRunnerModule) AbstractModule(com.google.inject.AbstractModule) V2(com.walmartlabs.concord.runtime.v2.runner.tasks.V2)

Example 20 with Task

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();
}
Also used : TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) WithItems(com.walmartlabs.concord.runtime.v2.model.WithItems)

Aggregations

TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)7 Test (org.junit.Test)7 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)6 HashMap (java.util.HashMap)5 List (java.util.List)5 MissingParameterException (com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException)4 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 Step (com.walmartlabs.concord.runtime.v2.model.Step)3 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.jupiter.api.Test)3 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)2 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)2 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 Task (com.walmartlabs.concord.runtime.v2.sdk.Task)2 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)2 Frame (com.walmartlabs.concord.svm.Frame)2 AbstractModule (com.google.inject.AbstractModule)1