use of com.netflix.titus.grpc.protogen.TaskQuery 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.TaskQuery in project titus-control-plane by Netflix.
the class DefaultAppAutoScalingCallbackService method getScalableTargetResourceInfo.
@Override
public Observable<ScalableTargetResourceInfo> getScalableTargetResourceInfo(String jobId, CallMetadata callMetadata) {
TaskQuery taskQuery = TaskQuery.newBuilder().putFilteringCriteria("jobIds", jobId).putFilteringCriteria("taskStates", "Started").setPage(Page.newBuilder().setPageSize(1).build()).build();
return jobServiceGateway.findTasks(taskQuery, callMetadata).map(taskQueryResult -> taskQueryResult.getPagination().getTotalItems()).flatMap(numStartedTasks -> jobServiceGateway.findJob(jobId, callMetadata).map(job -> Pair.of(job, numStartedTasks))).flatMap(jobTasksPair -> {
Job job = jobTasksPair.getLeft();
Integer numRunningTasks = jobTasksPair.getRight();
if (!job.getJobDescriptor().hasService()) {
return Observable.error(JobManagerException.notServiceJob(jobId));
}
ServiceJobSpec jobSpec = job.getJobDescriptor().getService();
ScalableTargetResourceInfo.Builder scalableTargetResourceInfoBuilder = ScalableTargetResourceInfo.newBuilder().actualCapacity(jobTasksPair.getRight()).desiredCapacity(jobSpec.getCapacity().getDesired()).dimensionName(DIMENSION_NAME).resourceName(jobId).scalableTargetDimensionId(jobId).version(buildVersion(job));
if (jobSpec.getCapacity().getDesired() != numRunningTasks) {
scalableTargetResourceInfoBuilder.scalingStatus(ScalingStatus.InProgress.name());
} else {
scalableTargetResourceInfoBuilder.scalingStatus(ScalingStatus.Successful.name());
}
return Observable.just(scalableTargetResourceInfoBuilder.build());
});
}
use of com.netflix.titus.grpc.protogen.TaskQuery 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.TaskQuery 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));
}
use of com.netflix.titus.grpc.protogen.TaskQuery 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();
}
Aggregations