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());
}
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());
}
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);
}
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));
}
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());
}
Aggregations