use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class GatewayJobServiceGatewayTest method testCombineForFirstPage.
private TaskQueryResult testCombineForFirstPage() {
TaskQuery taskQuery = TaskQuery.newBuilder().setPage(FIRST_PAGE).build();
TaskQueryResult page0ActiveSetResult = takeActivePage(0);
TaskQueryResult combinedResult = GatewayJobServiceGateway.combineTaskResults(taskQuery, page0ActiveSetResult, ARCHIVED_TASKS);
checkCombinedResult(combinedResult, ARCHIVED_TASKS.subList(0, PAGE_SIZE));
return combinedResult;
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class LocalCacheQueryProcessorTest method testFindTasksWithFieldsFilter.
@Test
public void testFindTasksWithFieldsFilter() {
List<Task> tasks1 = addToJobDataReplicator(newJobAndTasks("job1", 2)).getRight();
TaskQueryResult page1Result = processor.findTasks(TaskQuery.newBuilder().addFields("status").setPage(Page.newBuilder().setPageSize(2).build()).build());
assertThat(page1Result.getItemsList()).hasSize(2);
Task originalTask = tasks1.get(0);
com.netflix.titus.grpc.protogen.Task fetchedTask = page1Result.getItemsList().stream().filter(t -> t.getId().equals(originalTask.getId())).findFirst().get();
// Check that expected fields are set
assertThat(fetchedTask.getId()).isEqualTo(originalTask.getId());
assertThat(fetchedTask.getStatus().getReasonMessage()).isEqualTo(originalTask.getStatus().getReasonMessage());
// Check that not requested fields are not set
assertThat(fetchedTask.getLogLocation()).isEqualTo(LogLocation.getDefaultInstance());
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class TaskDataInjectorTest method testFindTasksWithoutRelocationDeadline.
@Test
public void testFindTasksWithoutRelocationDeadline() {
long deadline1 = titusRuntime.getClock().wallTime() + 1_000;
TaskQueryResult queryResult = TaskQueryResult.newBuilder().addItems(TASK1).addItems(TASK2).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).getMigrationDetails().getNeedsMigration()).isFalse();
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayWithSingleCellTest method findTasksMergesAllCellsIntoSingleResult.
@Test
public void findTasksMergesAllCellsIntoSingleResult() {
List<Task> cellSnapshot = new ArrayList<>();
// 10 jobs on each cell with TASKS_IN_GENERATED_JOBS tasks each
for (int i = 0; i < 5; i++) {
cellSnapshot.addAll(dataGenerator.newBatchJobWithTasks());
cellSnapshot.addAll(dataGenerator.newServiceJobWithTasks());
clock.advanceTime(1, TimeUnit.MINUTES);
}
cell.getServiceRegistry().addService(new CellWithFixedTasksService(cellSnapshot));
TaskQuery query = TaskQuery.newBuilder().setPage(toGrpcPage(Page.unlimited())).build();
final AssertableSubscriber<TaskQueryResult> testSubscriber = service.findTasks(query, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors().assertCompleted();
testSubscriber.assertValueCount(1);
final List<TaskQueryResult> results = testSubscriber.getOnNextEvents();
assertThat(results).hasSize(1);
// expect stackName to have changed
List<Task> expected = cellSnapshot.stream().sorted(JobManagerCursors.taskCursorOrderComparator()).map(this::withStackName).collect(Collectors.toList());
assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class GatewayJobServiceGateway method findTasks.
@Override
public Observable<TaskQueryResult> findTasks(TaskQuery taskQuery, CallMetadata callMetadata) {
Map<String, String> filteringCriteriaMap = taskQuery.getFilteringCriteriaMap();
Set<String> v3JobIds = new HashSet<>(StringExt.splitByComma(filteringCriteriaMap.getOrDefault("jobIds", "")));
boolean needsMigrationFilter = "true".equalsIgnoreCase(filteringCriteriaMap.getOrDefault("needsMigration", "false"));
// "needsMigration" query is served from the local job and relocation cache.
if (needsMigrationFilter) {
PageResult<Task> pageResult = needsMigrationQueryHandler.findTasks(GrpcJobQueryModelConverters.toJobQueryCriteria(taskQuery), toPage(taskQuery.getPage()));
TaskQueryResult taskQueryResult = TaskQueryResult.newBuilder().setPagination(toGrpcPagination(pageResult.getPagination())).addAllItems(taskDataInjector.injectIntoTasks(pageResult.getItems())).build();
return Observable.just(taskQueryResult);
}
Set<String> taskStates = Sets.newHashSet(StringExt.splitByComma(taskQuery.getFilteringCriteriaMap().getOrDefault("taskStates", "")));
Observable<TaskQueryResult> observable;
if (v3JobIds.isEmpty()) {
// Active task set only
observable = newActiveTaskQueryAction(taskQuery, callMetadata);
} else {
if (!taskStates.contains(TaskState.Finished.name())) {
// Active task set only
observable = newActiveTaskQueryAction(taskQuery, callMetadata);
} else {
Page page = taskQuery.getPage();
boolean nextPageByNumber = StringExt.isEmpty(page.getCursor()) && page.getPageNumber() > 0;
if (nextPageByNumber) {
// In this case we ask for active and archived tasks using a page number > 0. Because of that
// we have to fetch as much tasks from master as we can. Tasks that we do not fetch, will not be
// visible to the client.
TaskQuery largePageQuery = taskQuery.toBuilder().setPage(taskQuery.getPage().toBuilder().setPageNumber(0).setPageSize(gatewayConfiguration.getMaxTaskPageSize())).build();
observable = newActiveTaskQueryAction(largePageQuery, callMetadata);
} else {
observable = newActiveTaskQueryAction(taskQuery, callMetadata);
}
observable = observable.flatMap(result -> retrieveArchivedTasksForJobs(v3JobIds, taskQuery).map(archivedTasks -> combineTaskResults(taskQuery, result, archivedTasks)));
}
}
return observable.timeout(tunablesConfiguration.getRequestTimeoutMs(), TimeUnit.MILLISECONDS).map(queryResult -> taskDataInjector.injectIntoTaskQueryResult(queryResult));
}
Aggregations