use of org.flyte.api.v1.PartialWorkflowIdentifier in project flytekit-java by flyteorg.
the class ProjectClosureTest method testCollectSubWorkflows.
@Test
public void testCollectSubWorkflows() {
TypedInterface emptyInterface = TypedInterface.builder().inputs(ImmutableMap.of()).outputs(ImmutableMap.of()).build();
WorkflowMetadata emptyMetadata = WorkflowMetadata.builder().build();
PartialWorkflowIdentifier rewrittenSubWorkflowRef = PartialWorkflowIdentifier.builder().project("project").name("name").version("version").domain("domain").build();
WorkflowIdentifier subWorkflowRef = WorkflowIdentifier.builder().project("project").name("name").version("version").domain("domain").build();
WorkflowIdentifier otherSubWorkflowRef = WorkflowIdentifier.builder().project("project").name("other-name").version("version").domain("domain").build();
PartialWorkflowIdentifier rewrittenNestedSubWorkflowRef = PartialWorkflowIdentifier.builder().project("project").name("nested").version("version").domain("domain").build();
WorkflowIdentifier nestedSubWorkflowRef = WorkflowIdentifier.builder().project("project").name("nested").version("version").domain("domain").build();
PartialWorkflowIdentifier rewrittenNestedOtherSubWorkflowRef = PartialWorkflowIdentifier.builder().project("project").name("nested-other").version("version").domain("domain").build();
WorkflowIdentifier nestedOtherSubWorkflowRef = WorkflowIdentifier.builder().project("project").name("nested-other").version("version").domain("domain").build();
WorkflowNode workflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(rewrittenSubWorkflowRef)).build();
WorkflowNode nestedWorkflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(rewrittenNestedSubWorkflowRef)).build();
WorkflowNode nestedOtherWorkflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(rewrittenNestedOtherSubWorkflowRef)).build();
WorkflowTemplate emptyWorkflowTemplate = WorkflowTemplate.builder().interface_(emptyInterface).metadata(emptyMetadata).nodes(ImmutableList.of()).outputs(ImmutableList.of()).build();
WorkflowTemplate nestedWorkflowTemplate = WorkflowTemplate.builder().interface_(emptyInterface).metadata(emptyMetadata).nodes(ImmutableList.of(Node.builder().id("nested-node").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).workflowNode(nestedOtherWorkflowNode).build())).outputs(ImmutableList.of()).build();
Operand opTrue = Operand.ofPrimitive(Primitive.ofBooleanValue(true));
BooleanExpression exprTrue = BooleanExpression.ofComparison(ComparisonExpression.builder().leftValue(opTrue).rightValue(opTrue).operator(ComparisonExpression.Operator.EQ).build());
List<Node> nodes = ImmutableList.of(Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).workflowNode(workflowNode).build(), // Same sub-workflow
Node.builder().id("node-2").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).workflowNode(workflowNode).build(), // Sub-workflow which has a nested sub-workflow in branch (nestedOtherWorkflowNode)
Node.builder().id("node-3").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).branchNode(BranchNode.builder().ifElse(IfElseBlock.builder().case_(IfBlock.builder().condition(exprTrue).thenNode(Node.builder().id("node-4").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).workflowNode(nestedWorkflowNode).build()).build()).other(ImmutableList.of()).build()).build()).build());
// nestedOtherWorkflowNode is not in the previous list because
// that node belongs to the template of a sub-workflow
Map<WorkflowIdentifier, WorkflowTemplate> allWorkflows = ImmutableMap.of(subWorkflowRef, emptyWorkflowTemplate, otherSubWorkflowRef, emptyWorkflowTemplate, nestedSubWorkflowRef, nestedWorkflowTemplate, nestedOtherSubWorkflowRef, emptyWorkflowTemplate);
Map<WorkflowIdentifier, WorkflowTemplate> collectedSubWorkflows = ProjectClosure.collectSubWorkflows(nodes, allWorkflows);
assertThat(collectedSubWorkflows, equalTo(ImmutableMap.of(subWorkflowRef, emptyWorkflowTemplate, nestedSubWorkflowRef, nestedWorkflowTemplate, nestedOtherSubWorkflowRef, emptyWorkflowTemplate)));
}
use of org.flyte.api.v1.PartialWorkflowIdentifier in project flytekit-java by flyteorg.
the class ProtoUtilTest method shouldSerializeWorkflowNodeForSubWorkflowRef.
@Test
void shouldSerializeWorkflowNodeForSubWorkflowRef() {
PartialWorkflowIdentifier subWorkflowRef = PartialWorkflowIdentifier.builder().domain("domain").project("project").name("name").version("version").build();
WorkflowNode workflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(subWorkflowRef)).build();
assertThat(ProtoUtil.serialize(workflowNode), equalTo(Workflow.WorkflowNode.newBuilder().setSubWorkflowRef(IdentifierOuterClass.Identifier.newBuilder().setResourceType(WORKFLOW).setDomain("domain").setProject("project").setName("name").setVersion("version").build()).build()));
}
use of org.flyte.api.v1.PartialWorkflowIdentifier 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;
}
use of org.flyte.api.v1.PartialWorkflowIdentifier in project flytekit-java by flyteorg.
the class IdentifierRewriteTest method shouldRewriteWorkflowNodeForSubWorkflowRef.
@Test
void shouldRewriteWorkflowNodeForSubWorkflowRef() {
PartialWorkflowIdentifier identifier = PartialWorkflowIdentifier.builder().name("name").build();
PartialWorkflowIdentifier rewrittenIdentifier = PartialWorkflowIdentifier.builder().name("name").domain("rewritten-domain").version("rewritten-version").project("rewritten-project").build();
WorkflowNode workflowNode = WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(identifier)).build();
assertThat(rewriter.visitor().visitWorkflowNode(workflowNode), equalTo(WorkflowNode.builder().reference(WorkflowNode.Reference.ofSubWorkflowRef(rewrittenIdentifier)).build()));
}
use of org.flyte.api.v1.PartialWorkflowIdentifier in project flytekit-java by flyteorg.
the class FlyteAdminClientTest method shouldPropagateLaunchPlanToStub.
@Test
public void shouldPropagateLaunchPlanToStub() {
PartialWorkflowIdentifier wfIdentifier = PartialWorkflowIdentifier.builder().project(PROJECT).domain(DOMAIN).name(WF_NAME).version(WF_VERSION).build();
Primitive defaultPrimitive = Primitive.ofStringValue("default-bar");
LaunchPlan launchPlan = LaunchPlan.builder().workflowId(wfIdentifier).name(LP_NAME).fixedInputs(Collections.singletonMap("foo", Literal.ofScalar(Scalar.ofPrimitive(Primitive.ofStringValue("bar"))))).defaultInputs(Collections.singletonMap("default-foo", Parameter.create(Variable.builder().description("").literalType(LiteralType.ofSimpleType(SimpleType.STRING)).build(), Literal.ofScalar(Scalar.ofPrimitive(defaultPrimitive))))).cronSchedule(CronSchedule.builder().schedule("daily").offset(Duration.ofHours(1).toString()).build()).build();
client.createLaunchPlan(LP_IDENTIFIER, launchPlan);
assertThat(stubService.createLaunchPlanRequest, equalTo(LaunchPlanOuterClass.LaunchPlanCreateRequest.newBuilder().setId(newIdentifier(ResourceType.LAUNCH_PLAN, LP_NAME, LP_VERSION)).setSpec(LaunchPlanOuterClass.LaunchPlanSpec.newBuilder().setWorkflowId(newIdentifier(ResourceType.WORKFLOW, WF_NAME, WF_VERSION)).setFixedInputs(Literals.LiteralMap.newBuilder().putLiterals("foo", Literals.Literal.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("bar").build()).build()).build()).build()).setDefaultInputs(Interface.ParameterMap.newBuilder().putParameters("default-foo", Interface.Parameter.newBuilder().setVar(Interface.Variable.newBuilder().setDescription("").setType(Types.LiteralType.newBuilder().setSimple(Types.SimpleType.STRING).build())).setDefault(Literals.Literal.newBuilder().setScalar(Literals.Scalar.newBuilder().setPrimitive(Literals.Primitive.newBuilder().setStringValue("default-bar").build()).build()).build()).build()).build()).setEntityMetadata(LaunchPlanOuterClass.LaunchPlanMetadata.newBuilder().setSchedule(ScheduleOuterClass.Schedule.newBuilder().setCronSchedule(ScheduleOuterClass.CronSchedule.newBuilder().setSchedule("daily").setOffset("PT1H").build()).build()).build()).build()).build()));
}
Aggregations