use of com.netflix.titus.runtime.jobmanager.JobComparators in project titus-control-plane by Netflix.
the class DefaultJobManagementServiceGrpc method findTasks.
@Override
public void findTasks(TaskQuery taskQuery, StreamObserver<TaskQueryResult> responseObserver) {
if (!checkPageIsValid(taskQuery.getPage(), responseObserver)) {
return;
}
try {
// We need to find all tasks to get the total number of them.
List<com.netflix.titus.api.jobmanager.model.job.Task> allFilteredTasks = new ArrayList<>();
for (Pair<com.netflix.titus.api.jobmanager.model.job.Job<?>, com.netflix.titus.api.jobmanager.model.job.Task> jobTaskPair : jobOperations.findTasks(new V3TaskQueryCriteriaEvaluator(toJobQueryCriteria(taskQuery), titusRuntime), 0, Integer.MAX_VALUE / 2)) {
com.netflix.titus.api.jobmanager.model.job.Task right = jobTaskPair.getRight();
allFilteredTasks.add(right);
}
Pair<List<com.netflix.titus.api.jobmanager.model.job.Task>, Pagination> queryResult = PaginationUtil.takePageWithCursorAndKeyExtractor(toPage(taskQuery.getPage()), allFilteredTasks, JobComparators::createTaskKeyOf, JobManagerCursors::coreTaskIndexOf, JobManagerCursors::newTaskCoreCursorFrom);
List<Task> grpcTasks = new ArrayList<>();
for (com.netflix.titus.api.jobmanager.model.job.Task task : queryResult.getLeft()) {
Task toGrpcTask = grpcObjectsCache.getTask(task);
grpcTasks.add(toGrpcTask);
}
TaskQueryResult grpcQueryResult;
if (taskQuery.getFieldsList().isEmpty()) {
grpcQueryResult = toTaskQueryResult(grpcTasks, queryResult.getRight());
} else {
Set<String> fields = new HashSet<>(taskQuery.getFieldsList());
fields.addAll(TASK_MINIMUM_FIELD_SET);
List<Task> filtered = new ArrayList<>();
for (Task t : grpcTasks) {
filtered.add(ProtobufExt.copy(t, fields));
}
grpcQueryResult = toTaskQueryResult(filtered, queryResult.getRight());
}
responseObserver.onNext(grpcQueryResult);
responseObserver.onCompleted();
} catch (Exception e) {
safeOnError(logger, e, responseObserver);
}
}
use of com.netflix.titus.runtime.jobmanager.JobComparators in project titus-control-plane by Netflix.
the class DefaultJobManagementServiceGrpc method findJobs.
@Override
public void findJobs(JobQuery jobQuery, StreamObserver<JobQueryResult> responseObserver) {
if (!checkPageIsValid(jobQuery.getPage(), responseObserver)) {
return;
}
try {
// We need to find all jobs to get the total number of them.
List<com.netflix.titus.api.jobmanager.model.job.Job<?>> allFilteredJobs = jobOperations.findJobs(new V3JobQueryCriteriaEvaluator(toJobQueryCriteria(jobQuery), titusRuntime), 0, Integer.MAX_VALUE / 2);
Pair<List<com.netflix.titus.api.jobmanager.model.job.Job<?>>, Pagination> queryResult = PaginationUtil.takePageWithCursorAndKeyExtractor(toPage(jobQuery.getPage()), allFilteredJobs, JobComparators::createJobKeyOf, JobManagerCursors::coreJobIndexOf, JobManagerCursors::newJobCoreCursorFrom);
List<Job> grpcJobs = new ArrayList<>();
for (com.netflix.titus.api.jobmanager.model.job.Job<?> job : queryResult.getLeft()) {
Job toGrpcJob = grpcObjectsCache.getJob(job);
grpcJobs.add(toGrpcJob);
}
JobQueryResult grpcQueryResult;
if (jobQuery.getFieldsList().isEmpty()) {
grpcQueryResult = toJobQueryResult(grpcJobs, queryResult.getRight());
} else {
Set<String> fields = new HashSet<>(jobQuery.getFieldsList());
fields.addAll(JOB_MINIMUM_FIELD_SET);
List<Job> list = new ArrayList<>();
for (Job j : grpcJobs) {
list.add(ProtobufExt.copy(j, fields));
}
grpcQueryResult = toJobQueryResult(list, queryResult.getRight());
}
responseObserver.onNext(grpcQueryResult);
responseObserver.onCompleted();
} catch (Exception e) {
safeOnError(logger, e, responseObserver);
}
}
Aggregations