use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class UriProviderTest method executionUrl.
@Test
void executionUrl() {
Flow flow = TestsUtils.mockFlow();
Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
assertThat(uriProvider.executionUrl(execution).toString(), containsString("mysuperhost.com/subpath/ui"));
assertThat(uriProvider.executionUrl(execution).toString(), containsString(flow.getNamespace() + "/" + flow.getId() + "/" + execution.getId()));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class UriProviderTest method flowUrl.
@Test
void flowUrl() {
Flow flow = TestsUtils.mockFlow();
Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
assertThat(uriProvider.executionUrl(execution).toString(), containsString("mysuperhost.com/subpath/ui"));
assertThat(uriProvider.flowUrl(execution).toString(), containsString(flow.getNamespace() + "/" + flow.getId()));
assertThat(uriProvider.executionUrl(execution).toString(), containsString("mysuperhost.com/subpath/ui"));
assertThat(uriProvider.flowUrl(flow).toString(), containsString(flow.getNamespace() + "/" + flow.getId()));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class ExecutionControllerTest method webhook.
@SuppressWarnings("unchecked")
@Test
void webhook() {
Flow webhook = flowRepositoryInterface.findById(TESTS_FLOW_NS, "webhook").orElseThrow();
String key = ((Webhook) webhook.getTriggers().get(0)).getKey();
Execution execution = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key + "?name=john&age=12&age=13", ImmutableMap.of("a", 1, "b", true)), Execution.class);
assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("body")).get("a"), is(1));
assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("body")).get("b"), is(true));
assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("parameters")).get("name"), is(List.of("john")));
assertThat(((Map<String, List<Integer>>) execution.getTrigger().getVariables().get("parameters")).get("age"), containsInAnyOrder("12", "13"));
execution = client.toBlocking().retrieve(HttpRequest.PUT("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key, Collections.singletonList(ImmutableMap.of("a", 1, "b", true))), Execution.class);
assertThat(((List<Map<String, Object>>) execution.getTrigger().getVariables().get("body")).get(0).get("a"), is(1));
assertThat(((List<Map<String, Object>>) execution.getTrigger().getVariables().get("body")).get(0).get("b"), is(true));
execution = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key, "bla"), Execution.class);
assertThat(execution.getTrigger().getVariables().get("body"), is("bla"));
execution = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key), Execution.class);
assertThat(execution.getTrigger().getVariables().get("body"), is(nullValue()));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class ExecutionControllerTest method triggerAndFollow.
@Test
void triggerAndFollow() {
Execution result = triggerInputsFlowExecution();
RxSseClient sseClient = embeddedServer.getApplicationContext().createBean(RxSseClient.class, embeddedServer.getURL());
List<Event<Execution>> results = sseClient.eventStream("/api/v1/executions/" + result.getId() + "/follow", Execution.class).toList().blockingGet();
assertThat(results.size(), is(greaterThan(0)));
assertThat(results.get(results.size() - 1).getData().getState().getCurrent(), is(State.Type.SUCCESS));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class ExecutionControllerTest method restartFromTaskId.
@Test
void restartFromTaskId() throws Exception {
final String flowId = "restart_with_inputs";
final String referenceTaskId = "instant";
// Run execution until it ends
Execution parentExecution = runnerUtils.runOne(TESTS_FLOW_NS, flowId, null, (flow, execution1) -> runnerUtils.typedInputs(flow, execution1, inputs));
Optional<Flow> flow = flowRepositoryInterface.findById(TESTS_FLOW_NS, flowId);
assertThat(flow.isPresent(), is(true));
// Run child execution starting from a specific task and wait until it finishes
Execution finishedChildExecution = runnerUtils.awaitChildExecution(flow.get(), parentExecution, throwRunnable(() -> {
Thread.sleep(100);
Execution createdChidExec = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/" + parentExecution.getId() + "/replay?taskRunId=" + parentExecution.findTaskRunByTaskIdAndValue(referenceTaskId, List.of()).getId(), ImmutableMap.of()), Execution.class);
assertThat(createdChidExec, notNullValue());
assertThat(createdChidExec.getParentId(), is(parentExecution.getId()));
assertThat(createdChidExec.getTaskRunList().size(), is(4));
assertThat(createdChidExec.getState().getCurrent(), is(State.Type.RESTARTED));
IntStream.range(0, 3).mapToObj(value -> createdChidExec.getTaskRunList().get(value)).forEach(taskRun -> assertThat(taskRun.getState().getCurrent(), is(State.Type.SUCCESS)));
assertThat(createdChidExec.getTaskRunList().get(3).getState().getCurrent(), is(State.Type.RESTARTED));
assertThat(createdChidExec.getTaskRunList().get(3).getAttempts().size(), is(1));
}), Duration.ofSeconds(15));
assertThat(finishedChildExecution, notNullValue());
assertThat(finishedChildExecution.getParentId(), is(parentExecution.getId()));
assertThat(finishedChildExecution.getTaskRunList().size(), is(5));
finishedChildExecution.getTaskRunList().stream().map(TaskRun::getState).forEach(state -> assertThat(state.getCurrent(), is(State.Type.SUCCESS)));
}
Aggregations