use of org.flyte.api.v1.TypedInterface 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());
}
use of org.flyte.api.v1.TypedInterface in project flytekit-java by flyteorg.
the class SdkRunnableTaskRegistrarTest method shouldLoadRunnableTasksFromDiscoveredRegistries.
@Test
void shouldLoadRunnableTasksFromDiscoveredRegistries() {
// given
String testTaskName = "org.flyte.flytekit.SdkRunnableTaskRegistrarTest$TestTask";
String otherTestTaskName = "org.flyte.flytekit.SdkRunnableTaskRegistrarTest$OtherTestTask";
TaskIdentifier expectedTestTaskId = TaskIdentifier.builder().project("project").domain("domain").name(testTaskName).version("version").build();
TypedInterface typedInterface = TypedInterface.builder().inputs(SdkTypes.nulls().getVariableMap()).outputs(SdkTypes.nulls().getVariableMap()).build();
RetryStrategy retries = RetryStrategy.builder().retries(0).build();
RetryStrategy otherRetries = RetryStrategy.builder().retries(1).build();
Map<Resources.ResourceName, String> limits = new HashMap<>();
limits.put(Resources.ResourceName.CPU, "0.5");
limits.put(Resources.ResourceName.MEMORY, "2Gi");
Map<Resources.ResourceName, String> requests = new HashMap<>();
requests.put(Resources.ResourceName.CPU, "2");
requests.put(Resources.ResourceName.MEMORY, "5Gi");
Resources resources = Resources.builder().limits(limits).requests(requests).build();
RunnableTask expectedTask = createRunnableTask(testTaskName, typedInterface, retries, null);
TaskIdentifier expectedOtherTestTaskId = TaskIdentifier.builder().project("project").domain("domain").name(otherTestTaskName).version("version").build();
RunnableTask expectedOtherTask = createRunnableTask(otherTestTaskName, typedInterface, otherRetries, resources);
// when
Map<TaskIdentifier, RunnableTask> tasks = registrar.load(ENV);
// then
assertAll(() -> assertThat(tasks, hasKey(is(expectedTestTaskId))), () -> assertThat(tasks, hasKey(is(expectedOtherTestTaskId))));
assertTaskEquals(tasks.get(expectedTestTaskId), expectedTask);
assertTaskEquals(tasks.get(expectedOtherTestTaskId), expectedOtherTask);
}
Aggregations