use of com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcTask 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.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcTask in project titus-control-plane by Netflix.
the class NeedsMigrationQueryHandler method findMatchingTasks.
private List<com.netflix.titus.grpc.protogen.Task> findMatchingTasks(JobQueryCriteria<TaskStatus.TaskState, JobDescriptor.JobSpecCase> queryCriteria) {
JobSnapshot jobSnapshot = jobDataReplicator.getCurrent();
Map<String, Job<?>> jobMap = jobSnapshot.getJobMap();
Map<String, TaskRelocationPlan> relocationPlans = relocationDataReplicator.getCurrent().getPlans();
V3TaskQueryCriteriaEvaluator queryFilter = new V3TaskQueryCriteriaEvaluator(queryCriteria, titusRuntime);
V3TaskQueryCriteriaEvaluator queryFilterWithoutNeedsMigration = new V3TaskQueryCriteriaEvaluator(filterOutNeedsMigration(queryCriteria), titusRuntime);
List<com.netflix.titus.grpc.protogen.Task> matchingTasks = new ArrayList<>();
jobMap.forEach((jobId, job) -> {
Map<String, Task> tasks = jobSnapshot.getTasks(jobId);
if (!CollectionsExt.isNullOrEmpty(tasks)) {
tasks.forEach((taskId, task) -> {
TaskRelocationPlan plan = relocationPlans.get(task.getId());
Pair<Job<?>, Task> jobTaskPair = Pair.of(job, task);
if (plan != null) {
if (queryFilterWithoutNeedsMigration.test(jobTaskPair)) {
matchingTasks.add(newTaskWithRelocationPlan(GrpcJobManagementModelConverters.toGrpcTask(task, logStorageInfo), plan));
}
} else {
if (queryFilter.test(jobTaskPair)) {
matchingTasks.add(GrpcJobManagementModelConverters.toGrpcTask(task, logStorageInfo));
}
}
});
}
});
return matchingTasks;
}
Aggregations