Search in sources :

Example 6 with RunnableTask

use of org.flyte.api.v1.RunnableTask in project flytekit-java by flyteorg.

the class ProjectClosure method createTaskTemplates.

static Map<TaskIdentifier, TaskTemplate> createTaskTemplates(ExecutionConfig config, Map<TaskIdentifier, RunnableTask> runnableTasks, Map<TaskIdentifier, DynamicWorkflowTask> dynamicWorkflowTasks) {
    Map<TaskIdentifier, TaskTemplate> taskTemplates = new HashMap<>();
    runnableTasks.forEach((id, task) -> {
        TaskTemplate taskTemplate = createTaskTemplateForRunnableTask(task, config.image());
        taskTemplates.put(id, taskTemplate);
    });
    dynamicWorkflowTasks.forEach((id, task) -> {
        TaskTemplate taskTemplate = createTaskTemplateForDynamicWorkflow(task, config.image());
        taskTemplates.put(id, taskTemplate);
    });
    return taskTemplates;
}
Also used : TaskTemplate(org.flyte.api.v1.TaskTemplate) TaskIdentifier(org.flyte.api.v1.TaskIdentifier) PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) HashMap(java.util.HashMap)

Example 7 with RunnableTask

use of org.flyte.api.v1.RunnableTask in project flytekit-java by flyteorg.

the class ProjectClosureTest method testCreateTaskTemplateForRunnableTask.

@Test
public void testCreateTaskTemplateForRunnableTask() {
    // given
    RunnableTask task = createRunnableTask(null);
    String image = "my-image";
    Resources expectedResources = Resources.builder().build();
    // when
    TaskTemplate result = ProjectClosure.createTaskTemplateForRunnableTask(task, image);
    // then
    Container container = result.container();
    assertNotNull(container);
    assertThat(container.image(), equalTo(image));
    assertThat(container.resources(), equalTo(expectedResources));
    assertThat(result.interface_(), equalTo(TypedInterface.builder().inputs(SdkTypes.nulls().getVariableMap()).outputs(SdkTypes.nulls().getVariableMap()).build()));
    assertThat(result.custom(), equalTo(Struct.of(emptyMap())));
    assertThat(result.retries(), equalTo(RetryStrategy.builder().retries(0).build()));
    assertThat(result.type(), equalTo("java-task"));
}
Also used : TaskTemplate(org.flyte.api.v1.TaskTemplate) Container(org.flyte.api.v1.Container) RunnableTask(org.flyte.api.v1.RunnableTask) ByteString(com.google.protobuf.ByteString) Resources(org.flyte.api.v1.Resources) Test(org.junit.jupiter.api.Test)

Example 8 with RunnableTask

use of org.flyte.api.v1.RunnableTask in project flytekit-java by flyteorg.

the class SdkRunnableTaskRegistrar method load.

@Override
@SuppressWarnings("rawtypes")
public Map<TaskIdentifier, RunnableTask> load(Map<String, String> env, ClassLoader classLoader) {
    ServiceLoader<SdkRunnableTask> loader = ServiceLoader.load(SdkRunnableTask.class, classLoader);
    LOG.fine("Discovering SdkRunnableTask");
    Map<TaskIdentifier, RunnableTask> tasks = new HashMap<>();
    SdkConfig sdkConfig = SdkConfig.load(env);
    for (SdkRunnableTask<?, ?> sdkTask : loader) {
        String name = sdkTask.getName();
        TaskIdentifier taskId = TaskIdentifier.builder().domain(sdkConfig.domain()).project(sdkConfig.project()).name(name).version(sdkConfig.version()).build();
        LOG.fine(String.format("Discovered [%s]", name));
        RunnableTask task = new RunnableTaskImpl<>(sdkTask);
        RunnableTask previous = tasks.put(taskId, task);
        if (previous != null) {
            throw new IllegalArgumentException(String.format("Discovered a duplicate task [%s] [%s] [%s]", name, task, previous));
        }
    }
    return tasks;
}
Also used : TaskIdentifier(org.flyte.api.v1.TaskIdentifier) HashMap(java.util.HashMap) RunnableTask(org.flyte.api.v1.RunnableTask)

Example 9 with RunnableTask

use of org.flyte.api.v1.RunnableTask in project flytekit-java by flyteorg.

the class LocalEngineTest method testRetryableTask_failed.

@Test
public void testRetryableTask_failed() {
    String workflowName = new RetryableWorkflow().getName();
    Map<String, WorkflowTemplate> workflows = loadWorkflows();
    Map<String, RunnableTask> tasks = loadTasks();
    WorkflowTemplate workflow = workflows.get(workflowName);
    TestingListener listener = new TestingListener();
    // make sure we don't run two tests in parallel
    synchronized (RetryableTask.class) {
        // will never succeed within retry limit
        RetryableTask.ATTEMPTS_BEFORE_SUCCESS.set(10);
        RetryableTask.ATTEMPTS.set(0L);
        RuntimeException e = Assertions.assertThrows(RuntimeException.class, () -> LocalEngine.compileAndExecute(workflow, tasks, emptyMap(), ImmutableMap.of(), listener));
        assertEquals("oops", e.getMessage());
        assertEquals(ImmutableList.<List<Object>>builder().add(ofPending("node-1")).add(ofStarting("node-1", ImmutableMap.of())).add(ofRetrying("node-1", ImmutableMap.of(), "oops", /* attempt= */
        1)).add(ofRetrying("node-1", ImmutableMap.of(), "oops", /* attempt= */
        2)).add(ofRetrying("node-1", ImmutableMap.of(), "oops", /* attempt= */
        3)).add(ofRetrying("node-1", ImmutableMap.of(), "oops", /* attempt= */
        4)).add(ofRetrying("node-1", ImmutableMap.of(), "oops", /* attempt= */
        5)).add(ofError("node-1", ImmutableMap.of(), "oops")).build(), listener.actions);
        // getRetries() returns 5, so we have 6 attempts/executions total
        assertEquals(6L, RetryableTask.ATTEMPTS.get());
    }
}
Also used : RetryableWorkflow(org.flyte.localengine.examples.RetryableWorkflow) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) RetryableTask(org.flyte.localengine.examples.RetryableTask) List(java.util.List) RunnableTask(org.flyte.api.v1.RunnableTask) Test(org.junit.jupiter.api.Test)

Example 10 with RunnableTask

use of org.flyte.api.v1.RunnableTask in project flytekit-java by flyteorg.

the class LocalEngineTest method testBindingMap.

@Test
public void testBindingMap() {
    String workflowName = new MapWorkflow().getName();
    Map<String, WorkflowTemplate> workflows = loadWorkflows();
    Map<String, RunnableTask> tasks = loadTasks();
    WorkflowTemplate workflow = workflows.get(workflowName);
    Map<String, Literal> outputs = LocalEngine.compileAndExecute(workflow, tasks, emptyMap(), ImmutableMap.of());
    // 3 = 1 + 2, 7 = 3 + 4
    Literal i3 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(3)));
    Literal i7 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(7)));
    assertEquals(ImmutableMap.of("map", Literal.ofMap(ImmutableMap.of("e", i3, "f", i7))), outputs);
}
Also used : WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) Literal(org.flyte.api.v1.Literal) RunnableTask(org.flyte.api.v1.RunnableTask) MapWorkflow(org.flyte.localengine.examples.MapWorkflow) Test(org.junit.jupiter.api.Test)

Aggregations

RunnableTask (org.flyte.api.v1.RunnableTask)14 Test (org.junit.jupiter.api.Test)10 Literal (org.flyte.api.v1.Literal)8 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)8 HashMap (java.util.HashMap)5 TaskTemplate (org.flyte.api.v1.TaskTemplate)5 List (java.util.List)4 TaskIdentifier (org.flyte.api.v1.TaskIdentifier)4 DynamicWorkflowTask (org.flyte.api.v1.DynamicWorkflowTask)3 Resources (org.flyte.api.v1.Resources)3 ByteString (com.google.protobuf.ByteString)2 Container (org.flyte.api.v1.Container)2 ContainerError (org.flyte.api.v1.ContainerError)2 PartialTaskIdentifier (org.flyte.api.v1.PartialTaskIdentifier)2 ClassLoaders.withClassLoader (org.flyte.jflyte.ClassLoaders.withClassLoader)2 FileSystem (org.flyte.jflyte.api.FileSystem)2 RetryableTask (org.flyte.localengine.examples.RetryableTask)2 RetryableWorkflow (org.flyte.localengine.examples.RetryableWorkflow)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1