Search in sources :

Example 11 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class LazyExpressionEvaluator method createResolver.

/**
 * Based on the original code from {@link StandardELContext#getELResolver()}.
 * Creates a {@link ELResolver} instance with "sub-resolvers" in the original order.
 */
private ELResolver createResolver(LazyEvalContext evalContext, ExpressionFactory expressionFactory) {
    CompositeELResolver r = new CompositeELResolver();
    if (evalContext.scope() != null) {
        r.add(new VariableResolver(evalContext.scope()));
    }
    r.add(new VariableResolver(evalContext.variables()));
    if (evalContext.context() != null) {
        r.add(new TaskResolver(evalContext.context(), taskProviders));
    }
    r.add(expressionFactory.getStreamELResolver());
    r.add(new StaticFieldELResolver());
    r.add(new MapELResolver());
    r.add(new MethodAccessorResolver());
    r.add(new ResourceBundleELResolver());
    r.add(new ListELResolver());
    r.add(new ArrayELResolver());
    if (evalContext.context() != null) {
        r.add(new TaskMethodResolver(evalContext.context()));
    }
    r.add(new BeanELResolver());
    return r;
}
Also used : BeanELResolver(com.walmartlabs.concord.runtime.v2.runner.el.resolvers.BeanELResolver)

Example 12 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class MainTest method setUp.

@BeforeEach
public void setUp() throws IOException {
    workDir = Files.createTempDirectory("test");
    instanceId = UUID.randomUUID();
    Path formsDir = workDir.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME).resolve(Constants.Files.JOB_STATE_DIR_NAME).resolve(Constants.Files.JOB_FORMS_V2_DIR_NAME);
    formService = new FormService(formsDir);
    processStatusCallback = mock(ProcessStatusCallback.class);
    checkpointService = spy(new TestCheckpointUploader());
    testServices = new AbstractModule() {

        @Override
        protected void configure() {
            install(new BaseRunnerModule());
            bind(ClassLoader.class).annotatedWith(Names.named("runtime")).toInstance(MainTest.class.getClassLoader());
            bind(CheckpointUploader.class).toInstance(checkpointService);
            bind(CheckpointService.class).to(DefaultCheckpointService.class);
            bind(DependencyManager.class).to(DefaultDependencyManager.class);
            bind(DockerService.class).to(DefaultDockerService.class);
            bind(FileService.class).to(DefaultFileService.class);
            bind(LockService.class).to(DefaultLockService.class);
            bind(PersistenceService.class).toInstance(mock(PersistenceService.class));
            bind(ProcessStatusCallback.class).toInstance(processStatusCallback);
            bind(SecretService.class).to(DefaultSecretService.class);
            Multibinder<TaskProvider> taskProviders = Multibinder.newSetBinder(binder(), TaskProvider.class);
            taskProviders.addBinding().to(TaskV2Provider.class);
            Multibinder<TaskCallListener> taskCallListeners = Multibinder.newSetBinder(binder(), TaskCallListener.class);
            taskCallListeners.addBinding().to(TaskCallPolicyChecker.class);
            taskCallListeners.addBinding().to(TaskResultListener.class);
            Multibinder.newSetBinder(binder(), ExecutionListener.class);
        }
    };
    allLogs = null;
}
Also used : Path(java.nio.file.Path) DefaultCheckpointService(com.walmartlabs.concord.runtime.v2.runner.checkpoints.DefaultCheckpointService) Multibinder(com.google.inject.multibindings.Multibinder) TaskV2Provider(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskV2Provider) FormService(com.walmartlabs.concord.runtime.common.FormService) TaskCallListener(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallListener) TaskResultListener(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskResultListener) AbstractModule(com.google.inject.AbstractModule) BaseRunnerModule(com.walmartlabs.concord.runtime.v2.runner.guice.BaseRunnerModule) ExecutionListener(com.walmartlabs.concord.svm.ExecutionListener) TaskCallPolicyChecker(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallPolicyChecker) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders 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 14 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEval2.

@Test
public void testEval2() {
    Map<Object, Object> input = map("x", "${y}", "y", "${x}");
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.emptyMap();
    // ---
    try {
        ee.evalAsMap(global(vars), input);
        fail("exception expected");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("variable in '${y}'"));
    }
    // ---
    try {
        ee.evalAsMap(scope(vars), input);
        fail("exception expected");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("Key 'x' already in evaluation"));
    }
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 15 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEvaGlobal.

@Test
public void testEvaGlobal() {
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("name", "${Concord}");
    // ---
    String str = ee.eval(global(vars), "Hello ${name}", String.class);
    assertEquals("Hello ${Concord}", str);
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)18 Test (org.junit.jupiter.api.Test)15 Matchers.containsString (org.hamcrest.Matchers.containsString)14 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 Frame (com.walmartlabs.concord.svm.Frame)2 AbstractModule (com.google.inject.AbstractModule)1 Multibinder (com.google.inject.multibindings.Multibinder)1 FormService (com.walmartlabs.concord.runtime.common.FormService)1 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)1 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)1 DefaultCheckpointService (com.walmartlabs.concord.runtime.v2.runner.checkpoints.DefaultCheckpointService)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 BeanELResolver (com.walmartlabs.concord.runtime.v2.runner.el.resolvers.BeanELResolver)1 BaseRunnerModule (com.walmartlabs.concord.runtime.v2.runner.guice.BaseRunnerModule)1 LogContext (com.walmartlabs.concord.runtime.v2.runner.logging.LogContext)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 TaskCallListener (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallListener)1 TaskCallPolicyChecker (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallPolicyChecker)1 TaskResultListener (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskResultListener)1