use of com.netflix.titus.grpc.protogen.JobQueryResult in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobsMergesAllCellsIntoSingleResult.
@Test
public void findJobsMergesAllCellsIntoSingleResult() {
Random random = new Random();
final List<Job> cellOneSnapshot = new ArrayList<>();
final List<Job> cellTwoSnapshot = new ArrayList<>();
for (int i = 0; i < 5; i++) {
cellOneSnapshot.addAll(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellTwoSnapshot.addAll(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellOneSnapshot.addAll(dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellTwoSnapshot.addAll(dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
clock.advanceTime(1, TimeUnit.MINUTES);
}
cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()));
cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()));
JobQuery query = JobQuery.newBuilder().setPage(toGrpcPage(Page.unlimited())).build();
final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors().assertCompleted();
testSubscriber.assertValueCount(1);
final List<JobQueryResult> results = testSubscriber.getOnNextEvents();
assertThat(results).hasSize(1);
// expect stackName to have changed
List<Job> expected = Stream.concat(cellOneSnapshot.stream(), cellTwoSnapshot.stream()).sorted(JobManagerCursors.jobCursorOrderComparator()).map(this::withStackName).collect(Collectors.toList());
assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected);
}
use of com.netflix.titus.grpc.protogen.JobQueryResult in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobsWithFailingCell.
@Test
public void findJobsWithFailingCell() {
List<Job> cellTwoSnapshot = new ArrayList<>();
for (int i = 0; i < 5; i++) {
cellTwoSnapshot.addAll(dataGenerator.newBatchJobs(5, GrpcJobManagementModelConverters::toGrpcJob));
cellTwoSnapshot.addAll(dataGenerator.newServiceJobs(5, GrpcJobManagementModelConverters::toGrpcJob));
clock.advanceTime(1, TimeUnit.MINUTES);
}
cellOne.getServiceRegistry().addService(new CellWithFailingJobManagementService());
cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()));
JobQuery query = JobQuery.newBuilder().setPage(toGrpcPage(Page.unlimited())).build();
final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertError(Status.INTERNAL.asRuntimeException().getClass());
testSubscriber.assertNoValues();
}
use of com.netflix.titus.grpc.protogen.JobQueryResult in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobsWithFieldFiltering.
@Test
public void findJobsWithFieldFiltering() {
Pair<List<Job>, List<Job>> cellSnapshots = generateTestJobs();
List<Job> allJobs = walkAllPages(10, request -> service.findJobs(request, UNDEFINED_CALL_METADATA), page -> JobQuery.newBuilder().setPage(page).addFields("jobDescriptor.owner").build(), JobQueryResult::getPagination, JobQueryResult::getItemsList);
assertThat(allJobs).hasSize(cellSnapshots.getLeft().size() + cellSnapshots.getRight().size());
for (Job job : allJobs) {
assertThat(job.getId()).isNotEmpty();
assertThat(job.getJobDescriptor().getOwner().getTeamEmail()).isNotEmpty();
assertThat(job.getStatus().getReasonMessage()).isEmpty();
assertThat(job.getStatusHistoryList()).isEmpty();
}
}
use of com.netflix.titus.grpc.protogen.JobQueryResult in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayWithSingleCellTest method findJobsAddsStackName.
@Test
public void findJobsAddsStackName() {
Random random = new Random();
final List<Job> cellSnapshot = new ArrayList<>();
for (int i = 0; i < 5; i++) {
cellSnapshot.addAll(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellSnapshot.addAll(dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
clock.advanceTime(1, TimeUnit.MINUTES);
}
cell.getServiceRegistry().addService(new CellWithFixedJobsService(cellSnapshot, PublishSubject.create()));
JobQuery query = JobQuery.newBuilder().setPage(toGrpcPage(Page.unlimited())).build();
final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors().assertCompleted();
testSubscriber.assertValueCount(1);
final List<JobQueryResult> results = testSubscriber.getOnNextEvents();
assertThat(results).hasSize(1);
// expect stackName to have changed
List<Job> expected = cellSnapshot.stream().sorted(JobManagerCursors.jobCursorOrderComparator()).map(this::withStackName).collect(Collectors.toList());
assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected);
}
use of com.netflix.titus.grpc.protogen.JobQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByJobState.
@Test(timeout = 30_000)
public void testSearchByJobState() throws Exception {
JobDescriptor<BatchJobExt> jobDescriptor = batchJobDescriptors().getValue().toBuilder().withApplicationName("testSearchByJobState").build();
String acceptedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
String killInitiatedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob()).killJob().expectJobUpdateEvent(job -> job.getStatus().getState() == JobState.KillInitiated, "Expected state: " + JobState.KillInitiated)).getId();
String acceptedTaskId = jobsScenarioBuilder.takeJob(acceptedJobId).getTaskByIndex(0).getTask().getId();
String killInitiatedTaskId = jobsScenarioBuilder.takeJob(killInitiatedJobId).getTaskByIndex(0).getTask().getId();
// Indexes are recomputed after events are sent, so if we run findJobs/findTasks immediately, they may use stale index.
Thread.sleep(10);
JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
// Jobs (Accepted)
JobQueryResult acceptedJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "Accepted").build());
assertThat(acceptedJobQueryResult.getItemsList()).hasSize(1);
Job acceptedJobQueryResultItem = acceptedJobQueryResult.getItems(0);
assertThat(acceptedJobQueryResultItem.getId()).isEqualTo(acceptedJobId);
// Jobs (KillInitiated)
JobQueryResult killInitJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
assertThat(killInitJobQueryResult.getItemsList()).hasSize(1);
Job killInitJobQueryResultItem = killInitJobQueryResult.getItems(0);
assertThat(killInitJobQueryResultItem.getId()).isEqualTo(killInitiatedJobId);
// Tasks (Accepted)
TaskQueryResult acceptedTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "Accepted").setPage(PAGE).build());
assertThat(acceptedTaskQueryResult.getItemsList()).hasSize(1);
assertThat(acceptedTaskQueryResult.getItems(0).getId()).isEqualTo(acceptedTaskId);
// Tasks (KillInitiated)
TaskQueryResult killInitTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
assertThat(killInitTaskQueryResult.getItemsList()).hasSize(1);
assertThat(killInitTaskQueryResult.getItems(0).getId()).isEqualTo(killInitiatedTaskId);
}
Aggregations