use of io.kestra.core.models.tasks.Task in project kestra by kestra-io.
the class TemplateControllerTest method updateTemplate.
@Test
void updateTemplate() {
Template template = createTemplate();
client.toBlocking().retrieve(POST("/api/v1/templates", template), Template.class);
Template createdTemplate = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()), Template.class);
assertThat(template.getTasks().size(), is(2));
Task t3 = Return.builder().id("task-3").type(Return.class.getName()).format("test").build();
Template updateTemplate = Template.builder().id(template.getId()).namespace(template.getNamespace()).tasks(Arrays.asList(t3)).build();
client.toBlocking().retrieve(PUT("/api/v1/templates/" + template.getNamespace() + "/" + template.getId(), updateTemplate), Template.class);
Template updatedTemplate = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()), Template.class);
assertThat(updatedTemplate.getTasks().size(), is(1));
assertThat(updatedTemplate.getTasks().get(0).getId(), is("task-3"));
}
use of io.kestra.core.models.tasks.Task in project kestra by kestra-io.
the class FlowTest method updateTask.
@Test
void updateTask() throws InternalException {
Flow flow = this.parse("flows/valids/each-sequential-nested.yaml");
Flow updated = flow.updateTask("1-2-2_return", Return.builder().id("1-2-2_return").type(Return.class.getName()).format("{{task.id}}").build());
Task findUpdated = updated.findTaskByTaskId("1-2-2_return");
assertThat(((Return) findUpdated).getFormat(), is("{{task.id}}"));
}
use of io.kestra.core.models.tasks.Task in project kestra by kestra-io.
the class ExecutorService method childNextsTaskRun.
private List<TaskRun> childNextsTaskRun(Executor executor, TaskRun parentTaskRun) throws InternalException {
Task parent = executor.getFlow().findTaskByTaskId(parentTaskRun.getTaskId());
if (parent instanceof FlowableTask) {
FlowableTask<?> flowableParent = (FlowableTask<?>) parent;
List<NextTaskRun> nexts = flowableParent.resolveNexts(runContextFactory.of(executor.getFlow(), parent, executor.getExecution(), parentTaskRun), executor.getExecution(), parentTaskRun);
if (nexts.size() > 0) {
return this.saveFlowableOutput(nexts, executor, parentTaskRun);
}
}
return new ArrayList<>();
}
use of io.kestra.core.models.tasks.Task in project kestra by kestra-io.
the class Flow method updateTask.
public Flow updateTask(String taskId, Task newValue) throws InternalException {
Task task = this.findTaskByTaskId(taskId);
Map<String, Object> map = JacksonMapper.toMap(this);
return JacksonMapper.toMap(recursiveUpdate(map, task, newValue), Flow.class);
}
use of io.kestra.core.models.tasks.Task in project kestra by kestra-io.
the class Flow method validate.
public Optional<ConstraintViolationException> validate() {
Set<ConstraintViolation<?>> violations = new HashSet<>();
List<Task> allTasks = allTasksWithChilds();
// unique id
List<String> ids = allTasks.stream().map(Task::getId).collect(Collectors.toList());
List<String> duplicates = ids.stream().distinct().filter(entry -> Collections.frequency(ids, entry) > 1).collect(Collectors.toList());
if (duplicates.size() > 0) {
violations.add(ManualConstraintViolation.of("Duplicate task id with name [" + String.join(", ", duplicates) + "]", this, Flow.class, "flow.tasks", String.join(", ", duplicates)));
}
// validate tasks
allTasks.forEach(task -> {
if (task instanceof TaskValidationInterface) {
violations.addAll(((TaskValidationInterface<?>) task).failedConstraints());
}
});
if (violations.size() > 0) {
return Optional.of(new ConstraintViolationException(violations));
} else {
return Optional.empty();
}
}
Aggregations