Search in sources :

Example 6 with JobQuery

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();
}
Also used : NOT_FOUND(io.grpc.Status.NOT_FOUND) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) Job(com.netflix.titus.grpc.protogen.Job) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Observable(rx.Observable) HashSet(java.util.HashSet) Empty(com.google.protobuf.Empty) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) GrpcUtil(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil) StreamObserver(io.grpc.stub.StreamObserver) Pair(com.netflix.titus.common.util.tuple.Pair) Map(java.util.Map) SnapshotEnd(com.netflix.titus.grpc.protogen.JobChangeNotification.SnapshotEnd) PaginationUtil(com.netflix.titus.api.model.PaginationUtil) Set(java.util.Set) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) GrpcJobQueryModelConverters.toPage(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPage) List(java.util.List) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Pagination(com.netflix.titus.api.model.Pagination) Collections(java.util.Collections) Subscription(rx.Subscription) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) Pagination(com.netflix.titus.api.model.Pagination) ArrayList(java.util.ArrayList) List(java.util.List) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) HashSet(java.util.HashSet)

Example 7 with JobQuery

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();
}
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) CommonRuntimeGrpcModelConverters.toPage(com.netflix.titus.runtime.endpoint.common.grpc.CommonRuntimeGrpcModelConverters.toPage) Page(com.netflix.titus.api.model.Page) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 8 with JobQuery

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);
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) ArrayList(java.util.ArrayList) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult)

Aggregations

JobQuery (com.netflix.titus.grpc.protogen.JobQuery)8 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)8 ArrayList (java.util.ArrayList)7 Job (com.netflix.titus.grpc.protogen.Job)5 Test (org.junit.Test)4 ProtobufExt (com.netflix.titus.common.util.ProtobufExt)2 Pair (com.netflix.titus.common.util.tuple.Pair)2 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)2 ObserveJobsQuery (com.netflix.titus.grpc.protogen.ObserveJobsQuery)2 GrpcJobManagementModelConverters (com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters)2 JobManagerCursors (com.netflix.titus.runtime.jobmanager.JobManagerCursors)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Random (java.util.Random)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Observable (rx.Observable)2