Search in sources :

Example 6 with Pagination

use of com.netflix.titus.api.model.Pagination 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();
}
Also used : NOT_FOUND(io.grpc.Status.NOT_FOUND) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) TaskId(com.netflix.titus.grpc.protogen.TaskId) Set(java.util.Set) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) ArrayList(java.util.ArrayList) GrpcJobQueryModelConverters.toPage(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPage) HashSet(java.util.HashSet) Empty(com.google.protobuf.Empty) List(java.util.List) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) StreamObserver(io.grpc.stub.StreamObserver) Pair(com.netflix.titus.common.util.tuple.Pair) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Map(java.util.Map) Pagination(com.netflix.titus.api.model.Pagination) Collections(java.util.Collections) PaginationUtil(com.netflix.titus.api.model.PaginationUtil) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) TaskKillRequest(com.netflix.titus.grpc.protogen.TaskKillRequest) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) Pagination(com.netflix.titus.api.model.Pagination) ArrayList(java.util.ArrayList) List(java.util.List) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) HashSet(java.util.HashSet)

Aggregations

Pagination (com.netflix.titus.api.model.Pagination)6 List (java.util.List)5 GrpcJobQueryModelConverters.toGrpcPagination (com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination)4 JobManagerCursors (com.netflix.titus.runtime.jobmanager.JobManagerCursors)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Job (com.netflix.titus.grpc.protogen.Job)3 GrpcJobQueryModelConverters.toPage (com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPage)3 Empty (com.google.protobuf.Empty)2 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)2 PaginationUtil (com.netflix.titus.api.model.PaginationUtil)2 TitusServiceException (com.netflix.titus.api.service.TitusServiceException)2 ProtobufExt (com.netflix.titus.common.util.ProtobufExt)2 Pair (com.netflix.titus.common.util.tuple.Pair)2 JobManagementServiceGrpc (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc)2 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)2 Task (com.netflix.titus.grpc.protogen.Task)2 TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)2 JobComparators (com.netflix.titus.runtime.jobmanager.JobComparators)2 NOT_FOUND (io.grpc.Status.NOT_FOUND)2