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;
}
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"));
}
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;
}
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());
}
}
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);
}
Aggregations