use of org.flyte.api.v1.WorkflowTemplate in project flytekit-java by flyteorg.
the class LocalEngineTest method testFibonacci.
@Test
void testFibonacci() {
String workflowName = new FibonacciWorkflow().getName();
Literal fib0 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(0L)));
Literal fib1 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(1L)));
Literal fib2 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(1L)));
Literal fib3 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(2L)));
Literal fib4 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(3L)));
Literal fib5 = Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(5L)));
Map<String, WorkflowTemplate> workflows = loadWorkflows();
Map<String, RunnableTask> tasks = loadTasks();
TestingListener listener = new TestingListener();
Map<String, Literal> outputs = LocalEngine.compileAndExecute(workflows.get(workflowName), tasks, emptyMap(), ImmutableMap.of("fib0", fib0, "fib1", fib1), listener);
assertEquals(ImmutableMap.of("fib4", fib4, "fib5", fib5), outputs);
assertEquals(ImmutableList.<List<Object>>builder().add(ofPending("fib-2")).add(ofPending("fib-3")).add(ofPending("fib-4")).add(ofPending("fib-5")).add(ofStarting("fib-2", ImmutableMap.of("a", fib0, "b", fib1))).add(ofCompleted("fib-2", ImmutableMap.of("a", fib0, "b", fib1), ImmutableMap.of("c", fib2))).add(ofStarting("fib-3", ImmutableMap.of("a", fib1, "b", fib2))).add(ofCompleted("fib-3", ImmutableMap.of("a", fib1, "b", fib2), ImmutableMap.of("c", fib3))).add(ofStarting("fib-4", ImmutableMap.of("a", fib2, "b", fib3))).add(ofCompleted("fib-4", ImmutableMap.of("a", fib2, "b", fib3), ImmutableMap.of("c", fib4))).add(ofStarting("fib-5", ImmutableMap.of("a", fib3, "b", fib4))).add(ofCompleted("fib-5", ImmutableMap.of("a", fib3, "b", fib4), ImmutableMap.of("c", fib5))).build(), listener.actions);
}
use of org.flyte.api.v1.WorkflowTemplate in project flytekit-java by flyteorg.
the class LocalEngineTest method testRetryableTask_completed.
@Test
public void testRetryableTask_completed() {
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) {
RetryableTask.ATTEMPTS_BEFORE_SUCCESS.set(5L);
RetryableTask.ATTEMPTS.set(0L);
LocalEngine.compileAndExecute(workflow, tasks, emptyMap(), ImmutableMap.of(), listener);
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(ofCompleted("node-1", ImmutableMap.of(), ImmutableMap.of())).build(), listener.actions);
// will finish on attempt number 5 according to ATTEMPTS_BEFORE_SUCCESS
assertEquals(5L, RetryableTask.ATTEMPTS.get());
}
}
use of org.flyte.api.v1.WorkflowTemplate in project flytekit-java by flyteorg.
the class LocalEngineTest method testBindingCollection.
@Test
public void testBindingCollection() {
String workflowName = new ListWorkflow().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("list", Literal.ofCollection(ImmutableList.of(i3, i7))), outputs);
}
use of org.flyte.api.v1.WorkflowTemplate in project flytekit-java by flyteorg.
the class SdkWorkflowBuilderTest method testTimes2WorkflowIdl.
@Test
void testTimes2WorkflowIdl() {
SdkWorkflowBuilder builder = new SdkWorkflowBuilder();
new Times2Workflow().expand(builder);
Node expectedNode = Node.builder().id("square").taskNode(TaskNode.builder().referenceId(PartialTaskIdentifier.builder().name("org.flyte.flytekit.SdkWorkflowBuilderTest$MultiplicationTask").build()).build()).inputs(asList(Binding.builder().var_("a").binding(BindingData.ofOutputReference(OutputReference.builder().var("in").nodeId(Node.START_NODE_ID).build())).build(), Binding.builder().var_("b").binding(BindingData.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(2L)))).build())).upstreamNodeIds(emptyList()).build();
WorkflowTemplate expected = WorkflowTemplate.builder().metadata(WorkflowMetadata.builder().build()).interface_(expectedInterface()).outputs(expectedOutputs()).nodes(singletonList(expectedNode)).build();
assertEquals(expected, builder.toIdlTemplate());
}
use of org.flyte.api.v1.WorkflowTemplate in project flytekit-java by flyteorg.
the class SdkWorkflowTemplateRegistrar method load.
Map<WorkflowIdentifier, WorkflowTemplate> load(SdkConfig sdkConfig, List<SdkWorkflow> sdkWorkflows) {
LOG.fine("Discovering SdkWorkflow");
Map<WorkflowIdentifier, WorkflowTemplate> workflows = new HashMap<>();
for (SdkWorkflow sdkWorkflow : sdkWorkflows) {
String name = sdkWorkflow.getName();
WorkflowIdentifier workflowId = WorkflowIdentifier.builder().domain(sdkConfig.domain()).project(sdkConfig.project()).name(name).version(sdkConfig.version()).build();
LOG.fine(String.format("Discovered [%s]", name));
SdkWorkflowBuilder builder = new SdkWorkflowBuilder();
sdkWorkflow.expand(builder);
WorkflowTemplate workflow = WorkflowTemplateIdl.ofBuilder(builder);
WorkflowTemplate previous = workflows.put(workflowId, workflow);
if (previous != null) {
throw new IllegalArgumentException(String.format("Discovered a duplicate workflow [%s] [%s] [%s]", name, workflow, previous));
}
}
return workflows;
}
Aggregations