Search in sources :

Example 6 with PartialWorkflowIdentifier

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

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

Aggregations

PartialWorkflowIdentifier (org.flyte.api.v1.PartialWorkflowIdentifier)7 WorkflowNode (org.flyte.api.v1.WorkflowNode)6 Test (org.junit.jupiter.api.Test)4 WorkflowIdentifier (org.flyte.api.v1.WorkflowIdentifier)3 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)3 Node (org.flyte.api.v1.Node)2 TypedInterface (org.flyte.api.v1.TypedInterface)2 WorkflowMetadata (org.flyte.api.v1.WorkflowMetadata)2 BooleanExpression (org.flyte.api.v1.BooleanExpression)1 BranchNode (org.flyte.api.v1.BranchNode)1 LaunchPlan (org.flyte.api.v1.LaunchPlan)1 Operand (org.flyte.api.v1.Operand)1 Primitive (org.flyte.api.v1.Primitive)1 Variable (org.flyte.api.v1.Variable)1 Test (org.junit.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1