Skip to content

Commit

Permalink
fix(core): missing template freeze the executor
Browse files Browse the repository at this point in the history
close #588
  • Loading branch information
tchiotludo committed Sep 20, 2022
1 parent 61d2088 commit 59f990b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/io/kestra/core/tasks/flows/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ public static Flow injectTemplate(Flow flow, Execution execution, BiFunction<Str
ExecutorTemplate.of(templateTask, template)
)
);
} else {
throw new InternalException("Unable to find template '" + templateTask.getNamespace() + "." + templateTask.getTemplateId() + "'");
}

}));

haveTemplate = templates.size() > 0;
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/io/kestra/core/tasks/flows/TemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,23 @@ public static void withTemplate(RunnerUtils runnerUtils, TemplateRepositoryInter
void withTemplate() throws TimeoutException, IOException, URISyntaxException {
TemplateTest.withTemplate(runnerUtils, templateRepository, repositoryLoader, logQueue);
}


public static void withFailedTemplate(RunnerUtils runnerUtils, TemplateRepositoryInterface templateRepository, LocalFlowRepositoryLoader repositoryLoader, QueueInterface<LogEntry> logQueue) throws TimeoutException, IOException, URISyntaxException {
repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/with-failed-template.yaml")));

List<LogEntry> logs = new ArrayList<>();
logQueue.receive(logs::add);

Execution execution = runnerUtils.runOne("io.kestra.tests", "with-failed-template", Duration.ofSeconds(60));

assertThat(execution.getTaskRunList(), hasSize(1));
assertThat(execution.getState().getCurrent(), is(State.Type.FAILED));
assertThat(logs.stream().filter(logEntry -> logEntry.getMessage().equals("Can't find flow template 'io.kestra.tests.invalid'")).findFirst().orElseThrow().getLevel(), is(Level.ERROR));
}

@Test
void withFailedTemplate() throws TimeoutException, IOException, URISyntaxException {
TemplateTest.withFailedTemplate(runnerUtils, templateRepository, repositoryLoader, logQueue);
}
}
8 changes: 8 additions & 0 deletions core/src/test/resources/flows/tests/with-failed-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id: with-failed-template
namespace: io.kestra.tests

tasks:
- id: template
type: io.kestra.core.tasks.flows.Template
namespace: io.kestra.tests
templateId: invalid
5 changes: 5 additions & 0 deletions jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ void withTemplate() throws Exception {
TemplateTest.withTemplate(runnerUtils, templateRepository, repositoryLoader, logsQueue);
}

@Test
void withFailedTemplate() throws Exception {
TemplateTest.withFailedTemplate(runnerUtils, templateRepository, repositoryLoader, logsQueue);
}

@Test
void taskDefaults() throws TimeoutException, IOException, URISyntaxException {
repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/task-defaults.yaml")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Executor joinFlow(Executor executor, Boolean withDefaults) {
(namespace, id) -> this.templateExecutorInterface.findById(namespace, id).orElse(null)
);
} catch (InternalException e) {
log.warn("Failed to inject template", e);
log.debug("Failed to inject template", e);
}

Flow flowWithDefaults = taskDefaultService.injectDefaults(flow, executor.getExecution());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ void withTemplate() throws Exception {
TemplateTest.withTemplate(runnerUtils, templateRepository, repositoryLoader, logsQueue);
}

@Test
void withFailedTemplate() throws Exception {
TemplateTest.withFailedTemplate(runnerUtils, templateRepository, repositoryLoader, logsQueue);
}

@Test
void taskDefaults() throws TimeoutException, IOException, URISyntaxException {
repositoryLoader.load(Objects.requireNonNull(ListenersTest.class.getClassLoader().getResource("flows/tests/task-defaults.yaml")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private Flow transform(Flow flow, Execution execution) {
(namespace, id) -> templateExecutorInterface.findById(namespace, id).orElse(null)
);
} catch (InternalException e) {
log.warn("Failed to inject template", e);
log.debug("Failed to inject template", e);
}

return taskDefaultService.injectDefaults(flow, execution);
Expand Down

0 comments on commit 59f990b

Please sign in to comment.