use of org.flyte.api.v1.WorkflowNode in project flytekit-java by flyteorg.
the class SdkWorkflowWithSdkRemoteLaunchPlanTest method applyShouldReturnASdkWorkflowNode.
@Test
void applyShouldReturnASdkWorkflowNode() {
SdkWorkflowBuilder builder = new SdkWorkflowBuilder();
new WorkflowExample().expand(builder);
Node expectedNode = Node.builder().id("some-node-id").workflowNode(WorkflowNode.builder().reference(WorkflowNode.Reference.ofLaunchPlanRef(PartialLaunchPlanIdentifier.builder().domain("dev").project("project-a").name("SomeLaunchPlan").version("version").build())).build()).upstreamNodeIds(Collections.emptyList()).inputs(Arrays.asList(Binding.builder().var_("a").binding(BindingData.ofOutputReference(OutputReference.builder().nodeId("start-node").var("a").build())).build(), Binding.builder().var_("b").binding(BindingData.ofOutputReference(OutputReference.builder().nodeId("start-node").var("b").build())).build())).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.WorkflowNode in project flytekit-java by flyteorg.
the class ProjectClosureTest method testCheckCycles.
@Test
public void testCheckCycles() {
TypedInterface emptyInterface = TypedInterface.builder().inputs(ImmutableMap.of()).outputs(ImmutableMap.of()).build();
WorkflowMetadata emptyMetadata = WorkflowMetadata.builder().build();
PartialWorkflowIdentifier rewrittenWorkflowRef = PartialWorkflowIdentifier.builder().project("project").name("name").version("version").domain("domain").build();
PartialWorkflowIdentifier otherRewrittenWorkflowRef = PartialWorkflowIdentifier.builder().project("project").name("other-name").version("version").domain("domain").build();
WorkflowIdentifier workflowRef = WorkflowIdentifier.builder().project("project").name("name").version("version").domain("domain").build();
WorkflowIdentifier otherWorkflowRef = WorkflowIdentifier.builder().project("project").name("other-name").version("version").domain("domain").build();
WorkflowNode workflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(rewrittenWorkflowRef)).build();
WorkflowNode otherWorkflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(otherRewrittenWorkflowRef)).build();
WorkflowTemplate workflowTemplate = WorkflowTemplate.builder().interface_(emptyInterface).metadata(emptyMetadata).nodes(ImmutableList.of(Node.builder().id("sub-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).workflowNode(otherWorkflowNode).build())).outputs(ImmutableList.of()).build();
WorkflowTemplate otherWorkflowTemplate = WorkflowTemplate.builder().interface_(emptyInterface).metadata(emptyMetadata).nodes(ImmutableList.of(Node.builder().id("sub-2").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).workflowNode(workflowNode).build())).outputs(ImmutableList.of()).build();
Map<WorkflowIdentifier, WorkflowTemplate> allWorkflows = ImmutableMap.of(workflowRef, workflowTemplate, otherWorkflowRef, otherWorkflowTemplate);
// workflow -> otherWorkflow -> workflow
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> ProjectClosure.checkCycles(allWorkflows));
assertEquals("Workflow [WorkflowIdentifier{name=name, domain=domain, project=project, version=version}] " + "cannot have itself as a node, directly or indirectly", exception.getMessage());
}
use of org.flyte.api.v1.WorkflowNode in project flytekit-java by flyteorg.
the class SdkWorkflow method apply.
@Override
public SdkNode apply(SdkWorkflowBuilder builder, String nodeId, List<String> upstreamNodeIds, @Nullable SdkNodeMetadata metadata, Map<String, SdkBindingData> inputs) {
PartialWorkflowIdentifier workflowId = PartialWorkflowIdentifier.builder().name(getName()).build();
SdkWorkflowBuilder innerBuilder = new SdkWorkflowBuilder();
expand(innerBuilder);
Map<String, Variable> inputVariableMap = WorkflowTemplateIdl.getInputVariableMap(innerBuilder);
List<CompilerError> errors = Compiler.validateApply(nodeId, inputs, inputVariableMap);
if (!errors.isEmpty()) {
throw new CompilerException(errors);
}
WorkflowNode workflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(workflowId)).build();
return new SdkWorkflowNode(builder, nodeId, upstreamNodeIds, metadata, workflowNode, inputs, innerBuilder.getOutputs());
}
use of org.flyte.api.v1.WorkflowNode in project flytekit-java by flyteorg.
the class ExecutionNodeCompiler method compile.
static ExecutionNode compile(Node node, Map<String, RunnableTask> runnableTasks, Map<String, DynamicWorkflowTask> dynamicWorkflowTasks) {
List<String> upstreamNodeIds = new ArrayList<>();
node.inputs().stream().map(Binding::binding).flatMap(ExecutionNodeCompiler::unpackBindingData).filter(x -> x.kind() == BindingData.Kind.PROMISE).map(x -> x.promise().nodeId()).forEach(upstreamNodeIds::add);
upstreamNodeIds.addAll(node.upstreamNodeIds());
if (upstreamNodeIds.isEmpty()) {
upstreamNodeIds.add(START_NODE_ID);
}
if (node.branchNode() != null) {
throw new IllegalArgumentException("BranchNode isn't yet supported for local execution");
}
if (node.workflowNode() != null) {
throw new IllegalArgumentException("WorkflowNode isn't yet supported for local execution");
}
String taskName = node.taskNode().referenceId().name();
DynamicWorkflowTask dynamicWorkflowTask = dynamicWorkflowTasks.get(taskName);
RunnableTask runnableTask = runnableTasks.get(taskName);
if (dynamicWorkflowTask != null) {
throw new IllegalArgumentException("DynamicWorkflowTask isn't yet supported for local execution");
}
Objects.requireNonNull(runnableTask, () -> String.format("Couldn't find task [%s]", taskName));
int attempts = runnableTask.getRetries().retries() + 1;
return ExecutionNode.builder().nodeId(node.id()).bindings(node.inputs()).runnableTask(runnableTask).upstreamNodeIds(upstreamNodeIds).attempts(attempts).build();
}
Aggregations