Search in sources :

Example 1 with Task

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"));
}
Also used : Task(io.kestra.core.models.tasks.Task) Return(io.kestra.core.tasks.debugs.Return) Template(io.kestra.core.models.templates.Template) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 2 with Task

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}}"));
}
Also used : Task(io.kestra.core.models.tasks.Task) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 3 with Task

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<>();
}
Also used : FlowableTask(io.kestra.core.models.tasks.FlowableTask) ResolvedTask(io.kestra.core.models.tasks.ResolvedTask) Task(io.kestra.core.models.tasks.Task) FlowableTask(io.kestra.core.models.tasks.FlowableTask) ArrayList(java.util.ArrayList) NextTaskRun(io.kestra.core.models.executions.NextTaskRun)

Example 4 with Task

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);
}
Also used : Task(io.kestra.core.models.tasks.Task) FlowableTask(io.kestra.core.models.tasks.FlowableTask)

Example 5 with Task

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();
    }
}
Also used : java.util(java.util) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) JacksonMapper(io.kestra.core.serializers.JacksonMapper) AbstractTrigger(io.kestra.core.models.triggers.AbstractTrigger) LoggerFactory(org.slf4j.LoggerFactory) DeletedInterface(io.kestra.core.models.DeletedInterface) Listener(io.kestra.core.models.listeners.Listener) Valid(javax.validation.Valid) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) ConstraintViolation(javax.validation.ConstraintViolation) Logger(org.slf4j.Logger) TaskValidationInterface(io.kestra.core.models.tasks.TaskValidationInterface) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SuperBuilder(lombok.experimental.SuperBuilder) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) javax.validation.constraints(javax.validation.constraints) Execution(io.kestra.core.models.executions.Execution) Collectors(java.util.stream.Collectors) InternalException(io.kestra.core.exceptions.InternalException) lombok(lombok) ManualConstraintViolation(io.kestra.core.models.validations.ManualConstraintViolation) Task(io.kestra.core.models.tasks.Task) Introspected(io.micronaut.core.annotation.Introspected) Stream(java.util.stream.Stream) ConstraintViolationException(javax.validation.ConstraintViolationException) FlowableTask(io.kestra.core.models.tasks.FlowableTask) Task(io.kestra.core.models.tasks.Task) FlowableTask(io.kestra.core.models.tasks.FlowableTask) TaskValidationInterface(io.kestra.core.models.tasks.TaskValidationInterface) ConstraintViolation(javax.validation.ConstraintViolation) ManualConstraintViolation(io.kestra.core.models.validations.ManualConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException)

Aggregations

Task (io.kestra.core.models.tasks.Task)17 Test (org.junit.jupiter.api.Test)7 Flow (io.kestra.core.models.flows.Flow)6 Execution (io.kestra.core.models.executions.Execution)5 FlowableTask (io.kestra.core.models.tasks.FlowableTask)5 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)5 TaskRun (io.kestra.core.models.executions.TaskRun)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ResolvedTask (io.kestra.core.models.tasks.ResolvedTask)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 NextTaskRun (io.kestra.core.models.executions.NextTaskRun)2 AbstractTrigger (io.kestra.core.models.triggers.AbstractTrigger)2 AbstractMemoryRunnerTest (io.kestra.core.runners.AbstractMemoryRunnerTest)2 Return (io.kestra.core.tasks.debugs.Return)2 Parallel (io.kestra.core.tasks.flows.Parallel)2 ArrayList (java.util.ArrayList)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)1 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)1