Search in sources :

Example 1 with GrpcJobManagementModelConverters.toGrpcTask

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();
}
Also used : MetricConstants(com.netflix.titus.gateway.MetricConstants) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) LoggerFactory(org.slf4j.LoggerFactory) JobDataReplicator(com.netflix.titus.runtime.connector.jobmanager.JobDataReplicator) JOB_MINIMUM_FIELD_SET(com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway.JOB_MINIMUM_FIELD_SET) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) PreDestroy(javax.annotation.PreDestroy) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) Matcher(java.util.regex.Matcher) JobSnapshot(com.netflix.titus.runtime.connector.jobmanager.snapshot.JobSnapshot) GrpcJobQueryModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters) Map(java.util.Map) Status(io.grpc.Status) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) Set(java.util.Set) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) CommonRuntimeGrpcModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.common.grpc.CommonRuntimeGrpcModelConverters.toGrpcPagination) PageResult(com.netflix.titus.api.model.PageResult) List(java.util.List) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) V3JobQueryCriteriaEvaluator(com.netflix.titus.runtime.endpoint.v3.grpc.query.V3JobQueryCriteriaEvaluator) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) RegExpExt(com.netflix.titus.common.util.RegExpExt) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobStatus(com.netflix.titus.grpc.protogen.JobStatus) Counter(com.netflix.spectator.api.Counter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Singleton(javax.inject.Singleton) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Observable(rx.Observable) HashSet(java.util.HashSet) Inject(javax.inject.Inject) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) SpectatorExt(com.netflix.titus.common.util.spectator.SpectatorExt) Pair(com.netflix.titus.common.util.tuple.Pair) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) Schedulers(reactor.core.scheduler.Schedulers) TASK_MINIMUM_FIELD_SET(com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway.TASK_MINIMUM_FIELD_SET) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) CommonRuntimeGrpcModelConverters.toPage(com.netflix.titus.runtime.endpoint.common.grpc.CommonRuntimeGrpcModelConverters.toPage) V3TaskQueryCriteriaEvaluator(com.netflix.titus.runtime.endpoint.v3.grpc.query.V3TaskQueryCriteriaEvaluator) Logger(org.slf4j.Logger) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) LogStorageInfo(com.netflix.titus.api.jobmanager.model.job.LogStorageInfo) Mono(reactor.core.publisher.Mono) GrpcJobManagementModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters) JobKeepAliveEvent(com.netflix.titus.api.jobmanager.model.job.event.JobKeepAliveEvent) StatusRuntimeException(io.grpc.StatusRuntimeException) Flux(reactor.core.publisher.Flux) ValueRangeCounter(com.netflix.titus.common.util.spectator.ValueRangeCounter) JobQueryCriteria(com.netflix.titus.runtime.endpoint.JobQueryCriteria) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Page(com.netflix.titus.api.model.Page) Registry(com.netflix.spectator.api.Registry) GrpcJobQueryModelConverters.toJobQueryCriteria(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toJobQueryCriteria) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) MetricSelector(com.netflix.titus.common.util.spectator.MetricSelector) Task(com.netflix.titus.grpc.protogen.Task) CommonRuntimeGrpcModelConverters.toPage(com.netflix.titus.runtime.endpoint.common.grpc.CommonRuntimeGrpcModelConverters.toPage) Page(com.netflix.titus.api.model.Page)

Example 2 with GrpcJobManagementModelConverters.toGrpcTask

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;
}
Also used : V3TaskQueryCriteriaEvaluator(com.netflix.titus.runtime.endpoint.v3.grpc.query.V3TaskQueryCriteriaEvaluator) Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) JobSnapshot(com.netflix.titus.runtime.connector.jobmanager.snapshot.JobSnapshot) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Aggregations

Job (com.netflix.titus.api.jobmanager.model.job.Job)2 JobSnapshot (com.netflix.titus.runtime.connector.jobmanager.snapshot.JobSnapshot)2 V3TaskQueryCriteriaEvaluator (com.netflix.titus.runtime.endpoint.v3.grpc.query.V3TaskQueryCriteriaEvaluator)2 ArrayList (java.util.ArrayList)2 Counter (com.netflix.spectator.api.Counter)1 Registry (com.netflix.spectator.api.Registry)1 LogStorageInfo (com.netflix.titus.api.jobmanager.model.job.LogStorageInfo)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 JobKeepAliveEvent (com.netflix.titus.api.jobmanager.model.job.event.JobKeepAliveEvent)1 JobManagerEvent (com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent)1 JobUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent)1 TaskUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)1 Page (com.netflix.titus.api.model.Page)1 PageResult (com.netflix.titus.api.model.PageResult)1 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)1 TaskRelocationPlan (com.netflix.titus.api.relocation.model.TaskRelocationPlan)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 ProtobufExt (com.netflix.titus.common.util.ProtobufExt)1 RegExpExt (com.netflix.titus.common.util.RegExpExt)1