use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testFindJobAndTaskByJobIdsV3.
@Test(timeout = 30_000)
public void testFindJobAndTaskByJobIdsV3() {
String job0 = batchJobsWithCreatedTasks.get(0);
String job2 = batchJobsWithCreatedTasks.get(2);
// Jobs
JobQueryResult jobQueryResult = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("jobIds", job0 + ',' + job2).setPage(PAGE).build());
final List<Job> itemsList = jobQueryResult.getItemsList();
assertThat(itemsList).hasSize(2);
// Tasks
TaskQueryResult taskQueryResult = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("jobIds", job0 + ',' + job2).setPage(PAGE).build());
assertThat(taskQueryResult.getItemsList()).hasSize(2);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByCellV3.
@Test(timeout = 30_000)
public void testSearchByCellV3() {
final int numberOfJobs = 3;
String[] expectedJobIds = new String[numberOfJobs];
String[] expectedTaskIds = new String[numberOfJobs];
for (int i = 0; i < numberOfJobs; i++) {
String jobId = jobsScenarioBuilder.scheduleAndReturnJob(BATCH_JOB_TEMPLATE.toBuilder().withApplicationName("testSearchByCellV3").build(), jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
expectedJobIds[i] = jobId;
expectedTaskIds[i] = jobsScenarioBuilder.takeJob(jobId).getTaskByIndex(0).getTask().getId();
}
// Jobs
JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByCellV3").setPage(PAGE);
JobQueryResult jobs1 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", "titus.cell,titus.stack").putFilteringCriteria("attributes.op", "or").build());
assertContainsJobs(jobs1, expectedJobIds);
jobs1.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
JobQueryResult jobs2 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", "titus.cell").putFilteringCriteria("attributes.op", "and").build());
assertContainsJobs(jobs2, expectedJobIds);
jobs2.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
JobQueryResult jobs3 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s,titus.stack:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "or").build());
assertContainsJobs(jobs3, expectedJobIds);
jobs3.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
JobQueryResult jobs4 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "and").build());
assertContainsJobs(jobs4, expectedJobIds);
jobs4.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
// Tasks
TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByCellV3").setPage(PAGE);
TaskQueryResult tasks1 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", "titus.cell,titus.stack").putFilteringCriteria("attributes.op", "or").build());
assertContainsTasks(tasks1, expectedTaskIds);
tasks1.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
TaskQueryResult tasks2 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", "titus.cell").putFilteringCriteria("attributes.op", "and").build());
assertContainsTasks(tasks2, expectedTaskIds);
tasks2.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
TaskQueryResult tasks3 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s,titus.stack:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "or").build());
assertContainsTasks(tasks3, expectedTaskIds);
tasks3.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
final TaskQueryResult tasks4 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "and").build());
assertContainsTasks(tasks4, expectedTaskIds);
tasks4.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByJobTypeV3.
@Test(timeout = 30_000)
public void testSearchByJobTypeV3() {
// Batch only (jobs)
JobQueryResult batchQueryJobs = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("jobType", "batch").setPage(PAGE).build());
Set<String> batchJobIds = batchQueryJobs.getItemsList().stream().map(Job::getId).collect(Collectors.toSet());
assertThat(batchJobIds).containsAll(batchJobsWithCreatedTasks);
// Batch only (tasks)
TaskQueryResult batchQueryTasks = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("jobType", "batch").setPage(PAGE).build());
Set<String> batchTaskIds = batchQueryTasks.getItemsList().stream().map(Task::getId).collect(Collectors.toSet());
assertThat(batchTaskIds).containsAll(batchTasks);
// Service only (jobs)
JobQueryResult serviceQueryJobs = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("jobType", "service").setPage(PAGE).build());
Set<String> serviceJobIds = serviceQueryJobs.getItemsList().stream().map(Job::getId).collect(Collectors.toSet());
assertThat(serviceJobIds).containsAll(serviceJobsWithCreatedTasks);
// Service only (tasks)
TaskQueryResult serviceQueryTasks = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("jobType", "service").setPage(PAGE).build());
Set<String> serviceTaskIds = serviceQueryTasks.getItemsList().stream().map(Task::getId).collect(Collectors.toSet());
assertThat(serviceTaskIds).containsAll(serviceTasks);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCursorQueryTest method testTaskQueryWithCursor.
@Test(timeout = TEST_TIMEOUT_MS)
public void testTaskQueryWithCursor() {
// Page 0
TaskQueryResult result0 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4)).build());
assertThat(result0.getItemsList()).containsExactlyElementsOf(allTasksInOrder.subList(0, 4));
assertThat(result0.getPagination().getCursor()).isNotEmpty();
assertThat(result0.getPagination().getCursorPosition()).isEqualTo(3);
assertThat(result0.getPagination().getHasMore()).isTrue();
assertThat(result0.getPagination().getCurrentPage().getPageNumber()).isEqualTo(0);
// Page 1
TaskQueryResult result1 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4).setCursor(result0.getPagination().getCursor())).build());
assertThat(result1.getItemsList()).containsExactlyElementsOf(allTasksInOrder.subList(4, 8));
assertThat(result1.getPagination().getCursor()).isNotEmpty();
assertThat(result1.getPagination().getCursorPosition()).isEqualTo(7);
assertThat(result1.getPagination().getHasMore()).isTrue();
assertThat(result1.getPagination().getCurrentPage().getPageNumber()).isEqualTo(1);
// Page 2
TaskQueryResult result2 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4).setCursor(result1.getPagination().getCursor())).build());
assertThat(result2.getItemsList()).containsExactlyElementsOf(allTasksInOrder.subList(8, 12));
assertThat(result2.getPagination().getHasMore()).isFalse();
assertThat(result2.getPagination().getCursor()).isNotEmpty();
assertThat(result2.getPagination().getCursorPosition()).isEqualTo(11);
assertThat(result2.getPagination().getCurrentPage().getPageNumber()).isEqualTo(2);
// Check cursor points to the latest returned element
TaskQueryResult result3 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4).setCursor(result2.getPagination().getCursor())).build());
assertThat(result3.getItemsList()).isEmpty();
assertThat(result3.getPagination().getCursor()).isEqualTo(result2.getPagination().getCursor());
assertThat(result3.getPagination().getCursorPosition()).isEqualTo(result2.getPagination().getCursorPosition());
assertThat(result3.getPagination().getHasMore()).isFalse();
assertThat(result3.getPagination().getCurrentPage().getPageNumber()).isEqualTo(result3.getPagination().getTotalPages());
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobScenarioBuilder method findTasks.
public JobScenarioBuilder findTasks(TaskQuery taskQuery, Predicate<List<com.netflix.titus.grpc.protogen.Task>> tasksPredicate) {
TestStreamObserver<TaskQueryResult> responseObserver = new TestStreamObserver<>();
client.findTasks(taskQuery, responseObserver);
TaskQueryResult result = rethrow(() -> responseObserver.getLast(TIMEOUT_MS, TimeUnit.MILLISECONDS));
if (result == null) {
throw new IllegalStateException("TaskQueryResult is null");
} else if (!tasksPredicate.test(result.getItemsList())) {
throw new IllegalStateException("Tasks predicate is false");
}
return this;
}
Aggregations