Search in sources :

Example 1 with JobQueryResult

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);
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Job(com.netflix.titus.grpc.protogen.Job) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) Test(org.junit.Test)

Example 2 with JobQueryResult

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();
}
Also used : ArrayList(java.util.ArrayList) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Job(com.netflix.titus.grpc.protogen.Job) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) Test(org.junit.Test)

Example 3 with JobQueryResult

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();
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Job(com.netflix.titus.grpc.protogen.Job) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) Test(org.junit.Test)

Example 4 with JobQueryResult

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);
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Job(com.netflix.titus.grpc.protogen.Job) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) Test(org.junit.Test)

Example 5 with JobQueryResult

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);
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) EmbeddedTitusMasters(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMasters) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) EmbeddedKubeClusters(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeClusters) ClassRule(org.junit.ClassRule) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) ImmutableMap(com.google.common.collect.ImmutableMap) PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) Set(java.util.Set) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Page(com.netflix.titus.grpc.protogen.Page) List(java.util.List) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) CellAssertions.assertCellInfo(com.netflix.titus.master.integration.v3.job.CellAssertions.assertCellInfo) BeforeClass(org.junit.BeforeClass) Job(com.netflix.titus.grpc.protogen.Job) Image(com.netflix.titus.api.jobmanager.model.job.Image) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Test(org.junit.Test) Pagination(com.netflix.titus.grpc.protogen.Pagination) JobScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) EmbeddedTitusCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCell) Collections(java.util.Collections) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Job(com.netflix.titus.grpc.protogen.Job) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Aggregations

JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)23 Test (org.junit.Test)17 Job (com.netflix.titus.grpc.protogen.Job)12 JobQuery (com.netflix.titus.grpc.protogen.JobQuery)12 ArrayList (java.util.ArrayList)11 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)9 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)9 TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)8 List (java.util.List)6 Page (com.netflix.titus.grpc.protogen.Page)5 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4 JobManagerCursors (com.netflix.titus.runtime.jobmanager.JobManagerCursors)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Image (com.netflix.titus.api.jobmanager.model.job.Image)2 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)2 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)2 JobGroupInfo (com.netflix.titus.api.jobmanager.model.job.JobGroupInfo)2 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)2