Search in sources :

Example 16 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class CellWithFixedTasksService method findTasks.

@Override
public void findTasks(TaskQuery request, StreamObserver<TaskQueryResult> responseObserver) {
    Pair<List<Task>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getTasksList(), JobManagerCursors.taskCursorOrderComparator(), JobManagerCursors::taskIndexOf, JobManagerCursors::newTaskCursorFrom);
    Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
    if (!fieldsFilter.isEmpty()) {
        fieldsFilter.add("id");
        page = page.mapLeft(tasks -> tasks.stream().map(task -> ProtobufExt.copy(task, fieldsFilter)).collect(Collectors.toList()));
    }
    TaskQueryResult result = TaskQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
    responseObserver.onNext(result);
    responseObserver.onCompleted();
}
Also used : NOT_FOUND(io.grpc.Status.NOT_FOUND) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) TaskId(com.netflix.titus.grpc.protogen.TaskId) Set(java.util.Set) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) ArrayList(java.util.ArrayList) GrpcJobQueryModelConverters.toPage(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPage) HashSet(java.util.HashSet) Empty(com.google.protobuf.Empty) List(java.util.List) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) StreamObserver(io.grpc.stub.StreamObserver) Pair(com.netflix.titus.common.util.tuple.Pair) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Map(java.util.Map) Pagination(com.netflix.titus.api.model.Pagination) Collections(java.util.Collections) PaginationUtil(com.netflix.titus.api.model.PaginationUtil) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) TaskKillRequest(com.netflix.titus.grpc.protogen.TaskKillRequest) 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) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) HashSet(java.util.HashSet)

Example 17 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class JobManagementSpringResourceTest method testFindTasks.

@Test
public void testFindTasks() throws Exception {
    TaskQuery forwardedRequest = TaskQuery.newBuilder().putFilteringCriteria("filter1", "value1").setPage(NEXT_PAGE_OF_2).build();
    TaskQueryResult expectedResult = TaskQueryResult.newBuilder().setPagination(paginationOf(NEXT_PAGE_OF_2)).addAllItems(asList(TASK_1, TASK_2)).build();
    when(jobServiceGatewayMock.findTasks(forwardedRequest, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(expectedResult));
    TaskQueryResult entity = SpringMockMvcUtil.doPaginatedGet(mockMvc, "/api/v3/tasks", TaskQueryResult.class, NEXT_PAGE_OF_2, "filter1", "value1");
    assertThat(entity).isEqualTo(expectedResult);
    verify(jobServiceGatewayMock, times(1)).findTasks(forwardedRequest, JUNIT_REST_CALL_METADATA);
}
Also used : TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 18 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult 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 19 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class LocalCacheQueryProcessorTest method testFindTasks.

@Test
public void testFindTasks() {
    List<Task> tasks1 = addToJobDataReplicator(newJobAndTasks("job1", 2)).getRight();
    List<Task> tasks2 = addToJobDataReplicator(newJobAndTasks("job2", 4)).getRight();
    List<Task> tasks3 = addToJobDataReplicator(newJobAndTasks("job3", 0)).getRight();
    // Expect three pages
    TaskQueryResult page1Result = processor.findTasks(TASK_QUERY_ALL_WITH_PAGE_SIZE_2);
    assertThat(page1Result.getItemsList()).hasSize(2);
    Page page2 = Page.newBuilder().setPageSize(2).setCursor(page1Result.getPagination().getCursor()).build();
    TaskQueryResult page2Result = processor.findTasks(TaskQuery.newBuilder().setPage(page2).build());
    assertThat(page2Result.getItemsList()).hasSize(2);
    Page page3 = Page.newBuilder().setPageSize(2).setCursor(page2Result.getPagination().getCursor()).build();
    TaskQueryResult page3Result = processor.findTasks(TaskQuery.newBuilder().setPage(page3).build());
    assertThat(page3Result.getItemsList()).hasSize(2);
    assertThat(page3Result.getPagination().getHasMore()).isFalse();
    List<String> taskIds = CollectionsExt.merge(page1Result.getItemsList().stream().map(com.netflix.titus.grpc.protogen.Task::getId).collect(Collectors.toList()), page2Result.getItemsList().stream().map(com.netflix.titus.grpc.protogen.Task::getId).collect(Collectors.toList()), page3Result.getItemsList().stream().map(com.netflix.titus.grpc.protogen.Task::getId).collect(Collectors.toList()));
    List<String> expectedTaskIds = CollectionsExt.merge(tasks1.stream().map(Task::getId).collect(Collectors.toList()), tasks2.stream().map(Task::getId).collect(Collectors.toList()), tasks3.stream().map(Task::getId).collect(Collectors.toList()));
    assertThat(taskIds).containsAll(expectedTaskIds);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) Page(com.netflix.titus.grpc.protogen.Page) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Test(org.junit.Test)

Example 20 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class TaskDataInjectorTest method testFindTasksWithLegacyMigration.

@Test
public void testFindTasksWithLegacyMigration() {
    long deadline1 = titusRuntime.getClock().wallTime() + 1_000;
    long legacyDeadline2 = titusRuntime.getClock().wallTime() + 2_000;
    Task legacyTask = toLegacyTask(TASK2, legacyDeadline2);
    TaskQueryResult queryResult = TaskQueryResult.newBuilder().addItems(TASK1).addItems(legacyTask).build();
    when(relocationDataReplicator.getCurrent()).thenReturn(newRelocationSnapshot(newRelocationPlan(TASK1, deadline1)));
    TaskQueryResult merged = Observable.just(queryResult).map(queryResult1 -> taskDataInjector.injectIntoTaskQueryResult(queryResult1)).toBlocking().first();
    assertThat(merged.getItems(0).getMigrationDetails().getNeedsMigration()).isTrue();
    assertThat(merged.getItems(0).getMigrationDetails().getDeadline()).isEqualTo(deadline1);
    assertThat(merged.getItems(1)).isEqualTo(legacyTask);
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Test(org.junit.Test)

Aggregations

TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)29 Test (org.junit.Test)20 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)13 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)12 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)12 Task (com.netflix.titus.grpc.protogen.Task)11 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)9 Page (com.netflix.titus.grpc.protogen.Page)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Job (com.netflix.titus.grpc.protogen.Job)7 ArrayList (java.util.ArrayList)7 Function (java.util.function.Function)6 JobQuery (com.netflix.titus.grpc.protogen.JobQuery)5 TaskStatus (com.netflix.titus.grpc.protogen.TaskStatus)5 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)3 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)3 Pair (com.netflix.titus.common.util.tuple.Pair)3