Search in sources :

Example 21 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldSerializeWorkflowTemplate.

@Test
void shouldSerializeWorkflowTemplate() {
    Node nodeA = createNode("a").toBuilder().upstreamNodeIds(singletonList("b")).build();
    Node nodeB = createNode("b").toBuilder().metadata(NodeMetadata.builder().name("fancy-b").timeout(Duration.ofMinutes(15)).retries(RetryStrategy.builder().retries(3).build()).build()).build();
    ;
    WorkflowMetadata metadata = WorkflowMetadata.builder().build();
    TypedInterface interface_ = TypedInterface.builder().inputs(emptyMap()).outputs(emptyMap()).build();
    WorkflowTemplate template = WorkflowTemplate.builder().nodes(asList(nodeA, nodeB)).metadata(metadata).interface_(interface_).outputs(emptyList()).build();
    Workflow.Node expectedNode1 = Workflow.Node.newBuilder().setId("a").addUpstreamNodeIds("b").setTaskNode(Workflow.TaskNode.newBuilder().setReferenceId(IdentifierOuterClass.Identifier.newBuilder().setResourceType(TASK).setDomain(DOMAIN).setProject(PROJECT).setName("task-a").setVersion("version-a").build()).build()).addInputs(Literals.Binding.newBuilder().setVar("input-name-a").setBinding(Literals.BindingData.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("input-scalar-a").build()).build()).build()).build()).build();
    Workflow.Node expectedNode2 = Workflow.Node.newBuilder().setId("b").setMetadata(Workflow.NodeMetadata.newBuilder().setName("fancy-b").setTimeout(com.google.protobuf.Duration.newBuilder().setSeconds(15 * 60).build()).setRetries(Literals.RetryStrategy.newBuilder().setRetries(3).build()).build()).setTaskNode(Workflow.TaskNode.newBuilder().setReferenceId(IdentifierOuterClass.Identifier.newBuilder().setResourceType(TASK).setDomain(DOMAIN).setProject(PROJECT).setName("task-b").setVersion("version-b").build()).build()).addInputs(Literals.Binding.newBuilder().setVar("input-name-b").setBinding(Literals.BindingData.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("input-scalar-b").build()).build()).build()).build()).build();
    Workflow.WorkflowTemplate serializedTemplate = ProtoUtil.serialize(template);
    assertThat(serializedTemplate, equalTo(Workflow.WorkflowTemplate.newBuilder().setMetadata(Workflow.WorkflowMetadata.newBuilder().build()).setInterface(Interface.TypedInterface.newBuilder().setOutputs(Interface.VariableMap.newBuilder().build()).setInputs(Interface.VariableMap.newBuilder().build()).build()).addNodes(expectedNode1).addNodes(expectedNode2).build()));
}
Also used : WorkflowMetadata(org.flyte.api.v1.WorkflowMetadata) TypedInterface(org.flyte.api.v1.TypedInterface) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) TaskNode(org.flyte.api.v1.TaskNode) WorkflowNode(org.flyte.api.v1.WorkflowNode) BranchNode(org.flyte.api.v1.BranchNode) Node(org.flyte.api.v1.Node) Workflow(flyteidl.core.Workflow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class ProtoUtilTest method createNode.

private Node createNode(String id) {
    String taskName = "task-" + id;
    String version = "version-" + id;
    String input_name = "input-name-" + id;
    String input_scalar = "input-scalar-" + id;
    TaskNode taskNode = TaskNode.builder().referenceId(PartialTaskIdentifier.builder().domain(DOMAIN).project(PROJECT).name(taskName).version(version).build()).build();
    List<Binding> inputs = singletonList(Binding.builder().var_(input_name).binding(BindingData.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue(input_scalar)))).build());
    return Node.builder().id(id).taskNode(taskNode).inputs(inputs).upstreamNodeIds(emptyList()).build();
}
Also used : Binding(org.flyte.api.v1.Binding) TaskNode(org.flyte.api.v1.TaskNode) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 23 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldSerializeOutputReference.

@Test
void shouldSerializeOutputReference() {
    OutputReference input = OutputReference.builder().nodeId("node-id").var("var").build();
    Types.OutputReference expected = Types.OutputReference.newBuilder().setNodeId("node-id").setVar("var").build();
    Types.OutputReference output = ProtoUtil.serialize(input);
    assertEquals(expected, output);
}
Also used : Types(flyteidl.core.Types) OutputReference(org.flyte.api.v1.OutputReference) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class ProjectClosure method checkCycles.

static boolean checkCycles(WorkflowIdentifier workflowId, Map<WorkflowIdentifier, WorkflowTemplate> allWorkflows, Set<WorkflowIdentifier> beingVisited, Set<WorkflowIdentifier> visited) {
    beingVisited.add(workflowId);
    WorkflowTemplate workflow = allWorkflows.get(workflowId);
    List<Node> nodes = workflow.nodes().stream().flatMap(ProjectClosure::flatBranch).collect(toUnmodifiableList());
    for (Node node : nodes) {
        if (isSubWorkflowNode(node)) {
            PartialWorkflowIdentifier partialSubWorkflowId = Objects.requireNonNull(node.workflowNode()).reference().subWorkflowRef();
            WorkflowIdentifier subWorkflowId = WorkflowIdentifier.builder().project(partialSubWorkflowId.project()).name(partialSubWorkflowId.name()).domain(partialSubWorkflowId.domain()).version(partialSubWorkflowId.version()).build();
            if (// backward edge
            beingVisited.contains(subWorkflowId) || (!visited.contains(subWorkflowId) && checkCycles(subWorkflowId, allWorkflows, beingVisited, visited))) {
                return true;
            }
        }
    }
    beingVisited.remove(workflowId);
    visited.add(workflowId);
    return false;
}
Also used : PartialWorkflowIdentifier(org.flyte.api.v1.PartialWorkflowIdentifier) PartialWorkflowIdentifier(org.flyte.api.v1.PartialWorkflowIdentifier) WorkflowIdentifier(org.flyte.api.v1.WorkflowIdentifier) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) WorkflowNode(org.flyte.api.v1.WorkflowNode) Node(org.flyte.api.v1.Node)

Example 25 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class IdentifierRewriteTest method shouldRewriteBranchNodes.

@Test
void shouldRewriteBranchNodes() {
    ComparisonExpression comparison = ComparisonExpression.builder().operator(ComparisonExpression.Operator.EQ).leftValue(Operand.ofVar("a")).rightValue(Operand.ofVar("b")).build();
    BooleanExpression condition = BooleanExpression.ofComparison(comparison);
    PartialTaskIdentifier partialReference = PartialTaskIdentifier.builder().name("task-name").build();
    PartialTaskIdentifier rewrittenReference = PartialTaskIdentifier.builder().name("task-name").domain("rewritten-domain").version("rewritten-version").project("rewritten-project").build();
    TaskNode partialTaskNode = TaskNode.builder().referenceId(partialReference).build();
    TaskNode rewrittenTaskNode = TaskNode.builder().referenceId(rewrittenReference).build();
    Node partialNode = Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).taskNode(partialTaskNode).build();
    Node rewrittenNode = Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).taskNode(rewrittenTaskNode).build();
    IfBlock partialIfBlock = IfBlock.builder().condition(condition).thenNode(partialNode).build();
    IfBlock rewrittenIfBlock = IfBlock.builder().condition(condition).thenNode(rewrittenNode).build();
    BranchNode partialBranchNode = BranchNode.builder().ifElse(IfElseBlock.builder().case_(partialIfBlock).other(ImmutableList.of(partialIfBlock)).elseNode(partialNode).build()).build();
    BranchNode rewrittenBranchNode = BranchNode.builder().ifElse(IfElseBlock.builder().case_(rewrittenIfBlock).other(ImmutableList.of(rewrittenIfBlock)).elseNode(rewrittenNode).build()).build();
    assertThat(rewriter.visitor().visitBranchNode(partialBranchNode), equalTo(rewrittenBranchNode));
}
Also used : ComparisonExpression(org.flyte.api.v1.ComparisonExpression) BooleanExpression(org.flyte.api.v1.BooleanExpression) TaskNode(org.flyte.api.v1.TaskNode) BranchNode(org.flyte.api.v1.BranchNode) TaskNode(org.flyte.api.v1.TaskNode) BranchNode(org.flyte.api.v1.BranchNode) WorkflowNode(org.flyte.api.v1.WorkflowNode) Node(org.flyte.api.v1.Node) PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) IfBlock(org.flyte.api.v1.IfBlock) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)20 Node (org.flyte.api.v1.Node)15 TaskNode (org.flyte.api.v1.TaskNode)11 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)9 List (java.util.List)7 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)7 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)7 NodeAttributes (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)6 BranchNode (org.flyte.api.v1.BranchNode)6 WorkflowNode (org.flyte.api.v1.WorkflowNode)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 NodeAttributes (org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)6 Map (java.util.Map)5 Property (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property)5 Node (dataStructure.JunkCourse.ch04.Node)4