use of com.netflix.titus.grpc.protogen.JobQuery in project titus-control-plane by Netflix.
the class CellWithFixedJobsService method findJobs.
@Override
public void findJobs(JobQuery request, StreamObserver<JobQueryResult> responseObserver) {
Pair<List<Job>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getJobsList(), JobManagerCursors.jobCursorOrderComparator(), JobManagerCursors::jobIndexOf, JobManagerCursors::newCursorFrom);
Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
if (!fieldsFilter.isEmpty()) {
fieldsFilter.add("id");
page = page.mapLeft(jobs -> jobs.stream().map(job -> ProtobufExt.copy(job, fieldsFilter)).collect(Collectors.toList()));
}
JobQueryResult result = JobQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
responseObserver.onNext(result);
responseObserver.onCompleted();
}
use of com.netflix.titus.grpc.protogen.JobQuery 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.grpc.protogen.JobQuery in project titus-control-plane by Netflix.
the class JobsScenarioBuilder method loadJobs.
private List<JobScenarioBuilder> loadJobs() {
JobQuery query = JobQuery.newBuilder().setPage(Page.newBuilder().setPageSize(1000)).build();
Throwable lastFailure = null;
// since we do not have retry interceptor installed, we make a few attempts directly.
for (int i = 0; i < 3; i++) {
try {
TestStreamObserver<JobQueryResult> responseObserver = new TestStreamObserver<>();
client.findJobs(query, responseObserver);
JobQueryResult queryResult = rethrow(() -> responseObserver.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS));
List<JobScenarioBuilder> result = new ArrayList<>();
queryResult.getItemsList().forEach(job -> {
result.add(new JobScenarioBuilder(titusOperations, this, job.getId()));
});
return result;
} catch (Exception e) {
lastFailure = e;
logger.info("Cannot load jobs from TitusMaster (might be not ready yet). Waiting 1sec before next try...");
try {
Thread.sleep(1_000);
} catch (InterruptedException ignore) {
}
}
}
throw new IllegalStateException("Cannot load jobs: " + lastFailure, lastFailure);
}
Aggregations