Search in sources :

Example 1 with PartialTaskIdentifier

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

Example 2 with PartialTaskIdentifier

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

the class IdentifierRewriteTest method shouldRewriteTaskIdentifierWithValuesFromRewriterWhenOnlyNameIsSet.

@Test
void shouldRewriteTaskIdentifierWithValuesFromRewriterWhenOnlyNameIsSet() {
    PartialTaskIdentifier rewrittenTaskId = rewriter.apply(PartialTaskIdentifier.builder().name("internal-task").build());
    assertThat(rewrittenTaskId, equalTo(PartialTaskIdentifier.builder().project("rewritten-project").domain("rewritten-domain").name("internal-task").version("rewritten-version").build()));
}
Also used : PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) Test(org.junit.jupiter.api.Test)

Example 3 with PartialTaskIdentifier

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

the class SdkRemoteTask method apply.

@Override
public SdkNode apply(SdkWorkflowBuilder builder, String nodeId, List<String> upstreamNodeIds, @Nullable SdkNodeMetadata metadata, Map<String, SdkBindingData> inputs) {
    PartialTaskIdentifier taskId = PartialTaskIdentifier.builder().name(name()).project(project()).domain(domain()).version(version()).build();
    List<CompilerError> errors = Compiler.validateApply(nodeId, inputs, inputs().getVariableMap());
    if (!errors.isEmpty()) {
        throw new CompilerException(errors);
    }
    return new SdkTaskNode(builder, nodeId, taskId, upstreamNodeIds, metadata, inputs, outputs().getVariableMap());
}
Also used : PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier)

Example 4 with PartialTaskIdentifier

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

the class IdentifierRewriteTest method shouldRewriteTaskAllowingPingingVersionForTasksSameProject.

@Test
void shouldRewriteTaskAllowingPingingVersionForTasksSameProject() {
    PartialTaskIdentifier rewrittenTaskId = rewriter.apply(PartialTaskIdentifier.builder().name("internal-task").version("pinned-version").build());
    assertThat(rewrittenTaskId, equalTo(PartialTaskIdentifier.builder().project("rewritten-project").domain("rewritten-domain").name("internal-task").version("pinned-version").build()));
    verifyNoInteractions(client);
}
Also used : PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) Test(org.junit.jupiter.api.Test)

Example 5 with PartialTaskIdentifier

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

the class IdentifierRewriteTest method shouldRewriteTaskIdentifierWithLatestIdAndDomainForRewriter.

@Test
void shouldRewriteTaskIdentifierWithLatestIdAndDomainForRewriter() {
    when(client.fetchLatestTaskId(NamedEntityIdentifier.builder().project("external-project").domain("rewritten-domain").name("external-task").build())).thenReturn(TaskIdentifier.builder().project("external-project").domain("rewritten-domain").name("external-task").version("latest-version").build());
    PartialTaskIdentifier rewrittenTaskId = rewriter.apply(PartialTaskIdentifier.builder().project("external-project").name("external-task").build());
    assertThat(rewrittenTaskId, equalTo(PartialTaskIdentifier.builder().project("external-project").domain("rewritten-domain").name("external-task").version("latest-version").build()));
}
Also used : PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

PartialTaskIdentifier (org.flyte.api.v1.PartialTaskIdentifier)8 Test (org.junit.jupiter.api.Test)5 BooleanExpression (org.flyte.api.v1.BooleanExpression)1 BranchNode (org.flyte.api.v1.BranchNode)1 ComparisonExpression (org.flyte.api.v1.ComparisonExpression)1 IfBlock (org.flyte.api.v1.IfBlock)1 Node (org.flyte.api.v1.Node)1 TaskNode (org.flyte.api.v1.TaskNode)1 WorkflowNode (org.flyte.api.v1.WorkflowNode)1