Search in sources :

Example 6 with WorkflowNode

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());
}
Also used : WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) Node(org.flyte.api.v1.Node) WorkflowNode(org.flyte.api.v1.WorkflowNode) Test(org.junit.jupiter.api.Test)

Example 7 with WorkflowNode

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());
}
Also used : TypedInterface(org.flyte.api.v1.TypedInterface) WorkflowMetadata(org.flyte.api.v1.WorkflowMetadata) PartialWorkflowIdentifier(org.flyte.api.v1.PartialWorkflowIdentifier) WorkflowIdentifier(org.flyte.api.v1.WorkflowIdentifier) PartialWorkflowIdentifier(org.flyte.api.v1.PartialWorkflowIdentifier) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) WorkflowNode(org.flyte.api.v1.WorkflowNode) Test(org.junit.jupiter.api.Test)

Example 8 with WorkflowNode

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());
}
Also used : PartialWorkflowIdentifier(org.flyte.api.v1.PartialWorkflowIdentifier) Variable(org.flyte.api.v1.Variable) WorkflowNode(org.flyte.api.v1.WorkflowNode)

Example 9 with WorkflowNode

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();
}
Also used : Binding(org.flyte.api.v1.Binding) Node(org.flyte.api.v1.Node) Collections.emptyList(java.util.Collections.emptyList) START_NODE_ID(org.flyte.api.v1.Node.START_NODE_ID) DynamicWorkflowTask(org.flyte.api.v1.DynamicWorkflowTask) Set(java.util.Set) HashMap(java.util.HashMap) Binding(org.flyte.api.v1.Binding) Deque(java.util.Deque) RunnableTask(org.flyte.api.v1.RunnableTask) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) BindingData(org.flyte.api.v1.BindingData) Stream(java.util.stream.Stream) Map(java.util.Map) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) DynamicWorkflowTask(org.flyte.api.v1.DynamicWorkflowTask) ArrayList(java.util.ArrayList) RunnableTask(org.flyte.api.v1.RunnableTask)

Aggregations

WorkflowNode (org.flyte.api.v1.WorkflowNode)8 Test (org.junit.jupiter.api.Test)7 PartialWorkflowIdentifier (org.flyte.api.v1.PartialWorkflowIdentifier)5 Node (org.flyte.api.v1.Node)3 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)3 PartialLaunchPlanIdentifier (org.flyte.api.v1.PartialLaunchPlanIdentifier)2 TypedInterface (org.flyte.api.v1.TypedInterface)2 WorkflowIdentifier (org.flyte.api.v1.WorkflowIdentifier)2 WorkflowMetadata (org.flyte.api.v1.WorkflowMetadata)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1