Search in sources :

Example 6 with TaskIdentifier

use of org.flyte.api.v1.TaskIdentifier 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 TaskIdentifier

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

the class ProtoUtilTest method shouldDeserializeTaskId.

@Test
void shouldDeserializeTaskId() {
    TaskIdentifier taskId = ProtoUtil.deserializeTaskId(IdentifierOuterClass.Identifier.newBuilder().setResourceType(TASK).setProject(PROJECT).setDomain(DOMAIN).setName(TASK_NAME).setVersion(VERSION).build());
    assertThat(taskId, equalTo(TaskIdentifier.builder().project(PROJECT).domain(DOMAIN).name(TASK_NAME).version(VERSION).build()));
}
Also used : TaskIdentifier(org.flyte.api.v1.TaskIdentifier) PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with TaskIdentifier

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

the class ProtoUtilTest method shouldSerializeTaskIdentifiers.

@Test
void shouldSerializeTaskIdentifiers() {
    String name = "task-a";
    TaskIdentifier id = TaskIdentifier.builder().domain(DOMAIN).project(PROJECT).name(name).version(VERSION).build();
    IdentifierOuterClass.Identifier serializedId = ProtoUtil.serialize(id);
    assertThat(serializedId, equalTo(IdentifierOuterClass.Identifier.newBuilder().setResourceType(TASK).setDomain(DOMAIN).setProject(PROJECT).setName(name).setVersion(VERSION).build()));
}
Also used : TaskIdentifier(org.flyte.api.v1.TaskIdentifier) PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) Matchers.containsString(org.hamcrest.Matchers.containsString) IdentifierOuterClass(flyteidl.core.IdentifierOuterClass) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with TaskIdentifier

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

the class SdkDynamicWorkflowTaskRegistrar method load.

@Override
@SuppressWarnings("rawtypes")
public Map<TaskIdentifier, DynamicWorkflowTask> load(Map<String, String> env, ClassLoader classLoader) {
    ServiceLoader<SdkDynamicWorkflowTask> loader = ServiceLoader.load(SdkDynamicWorkflowTask.class, classLoader);
    LOG.fine("Discovering SdkDynamicWorkflowTask");
    Map<TaskIdentifier, DynamicWorkflowTask> tasks = new HashMap<>();
    SdkConfig sdkConfig = SdkConfig.load(env);
    for (SdkDynamicWorkflowTask<?, ?> 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));
        DynamicWorkflowTask task = new DynamicWorkflowTaskImpl<>(sdkTask);
        DynamicWorkflowTask previous = tasks.put(taskId, task);
        if (previous != null) {
            throw new IllegalArgumentException(String.format("Discovered a duplicate dynamic workflow task [%s] [%s] [%s]", name, task, previous));
        }
    }
    return tasks;
}
Also used : TaskIdentifier(org.flyte.api.v1.TaskIdentifier) DynamicWorkflowTask(org.flyte.api.v1.DynamicWorkflowTask) HashMap(java.util.HashMap)

Example 10 with TaskIdentifier

use of org.flyte.api.v1.TaskIdentifier 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)

Aggregations

TaskIdentifier (org.flyte.api.v1.TaskIdentifier)11 PartialTaskIdentifier (org.flyte.api.v1.PartialTaskIdentifier)8 HashMap (java.util.HashMap)4 RunnableTask (org.flyte.api.v1.RunnableTask)3 TaskTemplate (org.flyte.api.v1.TaskTemplate)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 DynamicWorkflowTask (org.flyte.api.v1.DynamicWorkflowTask)2 RetryStrategy (org.flyte.api.v1.RetryStrategy)2 TypedInterface (org.flyte.api.v1.TypedInterface)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 IdentifierOuterClass (flyteidl.core.IdentifierOuterClass)1 Container (org.flyte.api.v1.Container)1 ContainerError (org.flyte.api.v1.ContainerError)1 DynamicJobSpec (org.flyte.api.v1.DynamicJobSpec)1 DynamicWorkflowTaskRegistrar (org.flyte.api.v1.DynamicWorkflowTaskRegistrar)1 Literal (org.flyte.api.v1.Literal)1 PartialWorkflowIdentifier (org.flyte.api.v1.PartialWorkflowIdentifier)1 Resources (org.flyte.api.v1.Resources)1 RunnableTaskRegistrar (org.flyte.api.v1.RunnableTaskRegistrar)1