use of com.netflix.titus.api.model.PageResult in project titus-control-plane by Netflix.
the class GatewayJobServiceGateway method findTasks.
@Override
public Observable<TaskQueryResult> findTasks(TaskQuery taskQuery, CallMetadata callMetadata) {
Map<String, String> filteringCriteriaMap = taskQuery.getFilteringCriteriaMap();
Set<String> v3JobIds = new HashSet<>(StringExt.splitByComma(filteringCriteriaMap.getOrDefault("jobIds", "")));
boolean needsMigrationFilter = "true".equalsIgnoreCase(filteringCriteriaMap.getOrDefault("needsMigration", "false"));
// "needsMigration" query is served from the local job and relocation cache.
if (needsMigrationFilter) {
PageResult<Task> pageResult = needsMigrationQueryHandler.findTasks(GrpcJobQueryModelConverters.toJobQueryCriteria(taskQuery), toPage(taskQuery.getPage()));
TaskQueryResult taskQueryResult = TaskQueryResult.newBuilder().setPagination(toGrpcPagination(pageResult.getPagination())).addAllItems(taskDataInjector.injectIntoTasks(pageResult.getItems())).build();
return Observable.just(taskQueryResult);
}
Set<String> taskStates = Sets.newHashSet(StringExt.splitByComma(taskQuery.getFilteringCriteriaMap().getOrDefault("taskStates", "")));
Observable<TaskQueryResult> observable;
if (v3JobIds.isEmpty()) {
// Active task set only
observable = newActiveTaskQueryAction(taskQuery, callMetadata);
} else {
if (!taskStates.contains(TaskState.Finished.name())) {
// Active task set only
observable = newActiveTaskQueryAction(taskQuery, callMetadata);
} else {
Page page = taskQuery.getPage();
boolean nextPageByNumber = StringExt.isEmpty(page.getCursor()) && page.getPageNumber() > 0;
if (nextPageByNumber) {
// In this case we ask for active and archived tasks using a page number > 0. Because of that
// we have to fetch as much tasks from master as we can. Tasks that we do not fetch, will not be
// visible to the client.
TaskQuery largePageQuery = taskQuery.toBuilder().setPage(taskQuery.getPage().toBuilder().setPageNumber(0).setPageSize(gatewayConfiguration.getMaxTaskPageSize())).build();
observable = newActiveTaskQueryAction(largePageQuery, callMetadata);
} else {
observable = newActiveTaskQueryAction(taskQuery, callMetadata);
}
observable = observable.flatMap(result -> retrieveArchivedTasksForJobs(v3JobIds, taskQuery).map(archivedTasks -> combineTaskResults(taskQuery, result, archivedTasks)));
}
}
return observable.timeout(tunablesConfiguration.getRequestTimeoutMs(), TimeUnit.MILLISECONDS).map(queryResult -> taskDataInjector.injectIntoTaskQueryResult(queryResult));
}
use of com.netflix.titus.api.model.PageResult in project titus-control-plane by Netflix.
the class LocalCacheQueryProcessor method findJobs.
public JobQueryResult findJobs(JobQuery jobQuery) {
JobQueryCriteria<TaskStatus.TaskState, JobDescriptor.JobSpecCase> queryCriteria = GrpcJobQueryModelConverters.toJobQueryCriteria(jobQuery);
Page page = toPage(jobQuery.getPage());
List<Job> matchingJobs = findMatchingJob(queryCriteria);
PageResult<Job> pageResult = JobManagerCursors.newCoreJobPaginationEvaluator().takePage(page, matchingJobs);
Set<String> fields = newFieldsFilter(jobQuery.getFieldsList(), JOB_MINIMUM_FIELD_SET);
List<com.netflix.titus.grpc.protogen.Job> grpcJob = pageResult.getItems().stream().map(coreJob -> {
com.netflix.titus.grpc.protogen.Job job = GrpcJobManagementModelConverters.toGrpcJob(coreJob);
if (!fields.isEmpty()) {
job = ProtobufExt.copy(job, fields);
}
return job;
}).collect(Collectors.toList());
return JobQueryResult.newBuilder().setPagination(toGrpcPagination(pageResult.getPagination())).addAllItems(grpcJob).build();
}
use of com.netflix.titus.api.model.PageResult 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();
}
Aggregations