use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class CellWithFixedTasksService method findTasks.
@Override
public void findTasks(TaskQuery request, StreamObserver<TaskQueryResult> responseObserver) {
Pair<List<Task>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getTasksList(), JobManagerCursors.taskCursorOrderComparator(), JobManagerCursors::taskIndexOf, JobManagerCursors::newTaskCursorFrom);
Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
if (!fieldsFilter.isEmpty()) {
fieldsFilter.add("id");
page = page.mapLeft(tasks -> tasks.stream().map(task -> ProtobufExt.copy(task, fieldsFilter)).collect(Collectors.toList()));
}
TaskQueryResult result = TaskQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
responseObserver.onNext(result);
responseObserver.onCompleted();
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobManagementSpringResourceTest method testFindTasks.
@Test
public void testFindTasks() throws Exception {
TaskQuery forwardedRequest = TaskQuery.newBuilder().putFilteringCriteria("filter1", "value1").setPage(NEXT_PAGE_OF_2).build();
TaskQueryResult expectedResult = TaskQueryResult.newBuilder().setPagination(paginationOf(NEXT_PAGE_OF_2)).addAllItems(asList(TASK_1, TASK_2)).build();
when(jobServiceGatewayMock.findTasks(forwardedRequest, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(expectedResult));
TaskQueryResult entity = SpringMockMvcUtil.doPaginatedGet(mockMvc, "/api/v3/tasks", TaskQueryResult.class, NEXT_PAGE_OF_2, "filter1", "value1");
assertThat(entity).isEqualTo(expectedResult);
verify(jobServiceGatewayMock, times(1)).findTasks(forwardedRequest, JUNIT_REST_CALL_METADATA);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class LocalCacheQueryProcessor method findTasks.
public TaskQueryResult findTasks(TaskQuery taskQuery) {
JobQueryCriteria<TaskStatus.TaskState, JobDescriptor.JobSpecCase> queryCriteria = GrpcJobQueryModelConverters.toJobQueryCriteria(taskQuery);
Page page = toPage(taskQuery.getPage());
List<com.netflix.titus.api.jobmanager.model.job.Task> matchingTasks = findMatchingTasks(queryCriteria);
PageResult<com.netflix.titus.api.jobmanager.model.job.Task> pageResult = JobManagerCursors.newCoreTaskPaginationEvaluator().takePage(page, matchingTasks);
Set<String> fields = newFieldsFilter(taskQuery.getFieldsList(), TASK_MINIMUM_FIELD_SET);
List<Task> grpcTasks = pageResult.getItems().stream().map(task -> {
Task grpcTask = GrpcJobManagementModelConverters.toGrpcTask(task, logStorageInfo);
if (!fields.isEmpty()) {
grpcTask = ProtobufExt.copy(grpcTask, fields);
}
return grpcTask;
}).collect(Collectors.toList());
return TaskQueryResult.newBuilder().setPagination(toGrpcPagination(pageResult.getPagination())).addAllItems(grpcTasks).build();
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class LocalCacheQueryProcessorTest method testFindTasks.
@Test
public void testFindTasks() {
List<Task> tasks1 = addToJobDataReplicator(newJobAndTasks("job1", 2)).getRight();
List<Task> tasks2 = addToJobDataReplicator(newJobAndTasks("job2", 4)).getRight();
List<Task> tasks3 = addToJobDataReplicator(newJobAndTasks("job3", 0)).getRight();
// Expect three pages
TaskQueryResult page1Result = processor.findTasks(TASK_QUERY_ALL_WITH_PAGE_SIZE_2);
assertThat(page1Result.getItemsList()).hasSize(2);
Page page2 = Page.newBuilder().setPageSize(2).setCursor(page1Result.getPagination().getCursor()).build();
TaskQueryResult page2Result = processor.findTasks(TaskQuery.newBuilder().setPage(page2).build());
assertThat(page2Result.getItemsList()).hasSize(2);
Page page3 = Page.newBuilder().setPageSize(2).setCursor(page2Result.getPagination().getCursor()).build();
TaskQueryResult page3Result = processor.findTasks(TaskQuery.newBuilder().setPage(page3).build());
assertThat(page3Result.getItemsList()).hasSize(2);
assertThat(page3Result.getPagination().getHasMore()).isFalse();
List<String> taskIds = CollectionsExt.merge(page1Result.getItemsList().stream().map(com.netflix.titus.grpc.protogen.Task::getId).collect(Collectors.toList()), page2Result.getItemsList().stream().map(com.netflix.titus.grpc.protogen.Task::getId).collect(Collectors.toList()), page3Result.getItemsList().stream().map(com.netflix.titus.grpc.protogen.Task::getId).collect(Collectors.toList()));
List<String> expectedTaskIds = CollectionsExt.merge(tasks1.stream().map(Task::getId).collect(Collectors.toList()), tasks2.stream().map(Task::getId).collect(Collectors.toList()), tasks3.stream().map(Task::getId).collect(Collectors.toList()));
assertThat(taskIds).containsAll(expectedTaskIds);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class TaskDataInjectorTest method testFindTasksWithLegacyMigration.
@Test
public void testFindTasksWithLegacyMigration() {
long deadline1 = titusRuntime.getClock().wallTime() + 1_000;
long legacyDeadline2 = titusRuntime.getClock().wallTime() + 2_000;
Task legacyTask = toLegacyTask(TASK2, legacyDeadline2);
TaskQueryResult queryResult = TaskQueryResult.newBuilder().addItems(TASK1).addItems(legacyTask).build();
when(relocationDataReplicator.getCurrent()).thenReturn(newRelocationSnapshot(newRelocationPlan(TASK1, deadline1)));
TaskQueryResult merged = Observable.just(queryResult).map(queryResult1 -> taskDataInjector.injectIntoTaskQueryResult(queryResult1)).toBlocking().first();
assertThat(merged.getItems(0).getMigrationDetails().getNeedsMigration()).isTrue();
assertThat(merged.getItems(0).getMigrationDetails().getDeadline()).isEqualTo(deadline1);
assertThat(merged.getItems(1)).isEqualTo(legacyTask);
}
Aggregations