Search in sources :

Example 11 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.

the class SmtpTaskV2Test method testWithProcessDefaults.

@Test
public void testWithProcessDefaults() throws Exception {
    Map<String, Object> smtpParams = new HashMap<>();
    smtpParams.put("host", "localhost");
    smtpParams.put("port", mailServer.getSmtp().getPort());
    Map<String, Object> mail = new HashMap<>();
    mail.put("from", "me@localhost");
    mail.put("to", "you@localhost");
    mail.put("message", "Default vars from process arguments.");
    Context ctx = mock(Context.class);
    when(ctx.workingDirectory()).thenReturn(Paths.get(System.getProperty("user.dir")));
    when(ctx.variables()).thenReturn(new MapBackedVariables(Collections.singletonMap("smtpParams", smtpParams)));
    when(ctx.defaultVariables()).thenReturn(new MapBackedVariables(Collections.emptyMap()));
    SmtpTaskV2 t = new SmtpTaskV2(ctx);
    t.execute(new MapBackedVariables(Collections.singletonMap("mail", mail)));
    MimeMessage[] messages = mailServer.getReceivedMessages();
    assertEquals(1, messages.length);
    assertEquals("Default vars from process arguments.\r\n", messages[0].getContent());
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 12 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.

the class SlackClientTest method validateSlackClientPostingMessageWithJson.

@Test
public void validateSlackClientPostingMessageWithJson() throws Exception {
    Map<String, Object> cfgMap = new HashMap<>();
    cfgMap.put("apiToken", TestParams.TEST_API_TOKEN);
    SlackClient client = new SlackClient(SlackConfiguration.from(new SlackConfigurationParams(new MapBackedVariables(cfgMap))));
    String postJson = "{\n" + "  \"channel\": \"@SLACK_CHANNEL@\",\n" + "  \"attachments\": [\n" + "    {\n" + "      \"mrkdwn_in\": [\n" + "        \"text\"\n" + "      ],\n" + "      \"color\": \"#36a64f\",\n" + "      \"author_name\": \"Jason van Zyl\",\n" + "      \"author_link\": \"https://github.com/jvanzyl\",\n" + "      \"author_icon\": \"https://github.com/jvanzyl.png\",\n" + "      \"title\": \"#1234 Add JSON support for Slack messages\",\n" + "      \"title_link\": \"https://github.com/jvanzyl/test/commit/44921371d769d85e7ad7665c36a802c2db47aee1\",\n" + "      \"text\": \"Modify all the dodos to make JSON slack messages work.\",\n" + "      \"fields\": [\n" + "        {\n" + "          \"title\": \":hourglass_flowing_sand: *Unit Tests*\"\n" + "        },\n" + "        {\n" + "          \"title\": \":hourglass_flowing_sand: *Integration Tests*\"\n" + "        }\n" + "      ],\n" + "      \"footer\": \"walmartlabs/concord\",\n" + "      \"footer_icon\": \"https://github.com/github.png\"\n" + "    }\n" + "  ]\n" + "}";
    postJson = postJson.replace("@SLACK_CHANNEL@", TestParams.TEST_CHANNEL);
    SlackClient.Response postResponse = client.postJsonMessage(postJson);
    assertTrue(postResponse.isOk());
    Thread.sleep(2000);
    String ts = postResponse.getTs();
    String updateJson = "{\n" + "  \"channel\": \"@SLACK_CHANNEL@\",\n" + "  \"ts\": \"@TS@\",\n" + "  \"attachments\": [\n" + "    {\n" + "      \"mrkdwn_in\": [\n" + "        \"text\"\n" + "      ],\n" + "      \"color\": \"#36a64f\",\n" + "      \"author_name\": \"Jason van Zyl\",\n" + "      \"author_link\": \"https://github.com/jvanzyl\",\n" + "      \"author_icon\": \"https://github.com/jvanzyl.png\",\n" + "      \"title\": \"#1234 Add JSON support for Slack messages\",\n" + "      \"title_link\": \"https://github.com/jvanzyl/test/commit/44921371d769d85e7ad7665c36a802c2db47aee1\",\n" + "      \"text\": \"Modify all the dodos to make JSON slack messages work.\",\n" + "      \"fields\": [\n" + "        {\n" + "          \"title\": \":white_check_mark: *Unit Tests*\"\n" + "        },\n" + "        {\n" + "          \"title\": \":white_check_mark: *Integration Tests*\"\n" + "        }\n" + "      ],\n" + "      \"footer\": \"walmartlabs/concord\",\n" + "      \"footer_icon\": \"https://github.com/github.png\"\n" + "    }\n" + "  ]\n" + "}";
    updateJson = updateJson.replace("@TS@", ts);
    updateJson = updateJson.replace("@SLACK_CHANNEL@", TestParams.TEST_CHANNEL);
    System.out.println(updateJson);
    SlackClient.Response updateResponse = client.updateJsonMessage(updateJson);
    assertTrue(updateResponse.isOk());
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 13 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables 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);
}
Also used : CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) Frame(com.walmartlabs.concord.svm.Frame) TaskCall(com.walmartlabs.concord.runtime.v2.model.TaskCall) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator) CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)

Example 14 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables 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 15 with MapBackedVariables

use of com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables in project concord by walmartlabs.

the class SlackClientTest method validateSlackClientPostingMessageWithParameters.

@Test
public void validateSlackClientPostingMessageWithParameters() throws Exception {
    Map<String, Object> cfgMap = new HashMap<>();
    cfgMap.put("apiToken", TestParams.TEST_API_TOKEN);
    SlackClient client = new SlackClient(SlackConfiguration.from(new SlackConfigurationParams(new MapBackedVariables(cfgMap))));
    String channelId = TestParams.TEST_CHANNEL;
    SlackClient.Response response = client.message(channelId, null, false, "Hello from Concord!", null, null, null);
    assertTrue(response.isOk());
}
Also used : MapBackedVariables(com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)21 HashMap (java.util.HashMap)14 Test (org.junit.Test)10 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)9 Test (org.junit.jupiter.api.Test)6 SimpleResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult.SimpleResult)5 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)3 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)3 MimeMessage (javax.mail.internet.MimeMessage)3 ForkParams (com.walmartlabs.concord.client.ConcordTaskParams.ForkParams)1 ForkStartParams (com.walmartlabs.concord.client.ConcordTaskParams.ForkStartParams)1 HashiVaultTask (com.walmartlabs.concord.plugins.hashivault.v2.HashiVaultTask)1 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)1 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)1 TaskContext (com.walmartlabs.concord.runtime.v2.runner.context.TaskContext)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)1 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)1