Search in sources :

Example 1 with Job

use of com.netflix.titus.grpc.protogen.Job 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 Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class AggregatingJobServiceGatewayTest method singleJobUpdates.

@Test
public void singleJobUpdates() {
    Random random = new Random();
    List<String> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(12)).stream().map(job -> job.getId()).collect(Collectors.toList());
    List<String> cellTwoSnapshot = new ArrayList<>(dataGenerator.newBatchJobs(7)).stream().map(job -> job.getId()).collect(Collectors.toList());
    CellWithJobIds cellOneService = new CellWithJobIds(cellOneSnapshot);
    CellWithJobIds cellTwoService = new CellWithJobIds(cellTwoSnapshot);
    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(cellTwoService);
    String cellOneJobId = cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()));
    String cellTwoJobId = cellTwoSnapshot.get(random.nextInt(cellTwoSnapshot.size()));
    assertThat(cellOneService.containsCapacityUpdates(cellOneJobId)).isFalse();
    assertThat(cellTwoService.containsCapacityUpdates(cellOneJobId)).isFalse();
    JobCapacityUpdate cellOneUpdate = JobCapacityUpdate.newBuilder().setJobId(cellOneJobId).setCapacity(Capacity.newBuilder().setMax(1).setDesired(2).setMax(3).build()).build();
    AssertableSubscriber<Void> testSubscriber = service.updateJobCapacity(cellOneUpdate, UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertNoValues();
    testSubscriber.assertCompleted();
    assertThat(cellOneService.containsCapacityUpdates(cellOneJobId)).isTrue();
    assertThat(cellTwoService.containsCapacityUpdates(cellOneJobId)).isFalse();
    testSubscriber.unsubscribe();
    JobCapacityUpdate cellTwoUpdate = JobCapacityUpdate.newBuilder().setJobId(cellTwoJobId).setCapacity(Capacity.newBuilder().setMax(2).setDesired(2).setMax(2).build()).build();
    testSubscriber = service.updateJobCapacity(cellTwoUpdate, UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertNoValues();
    testSubscriber.assertCompleted();
    assertThat(cellOneService.containsCapacityUpdates(cellTwoJobId)).isFalse();
    assertThat(cellTwoService.containsCapacityUpdates(cellTwoJobId)).isTrue();
    testSubscriber.unsubscribe();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ServiceTests.walkAllPages(com.netflix.titus.federation.service.ServiceTests.walkAllPages) Arrays(java.util.Arrays) NOT_FOUND(io.grpc.Status.NOT_FOUND) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) JOB_ATTRIBUTES_STACK(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_STACK) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Capacity(com.netflix.titus.grpc.protogen.Capacity) TaskUpdate(com.netflix.titus.grpc.protogen.JobChangeNotification.TaskUpdate) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) JobCapacityUpdate(com.netflix.titus.grpc.protogen.JobCapacityUpdate) Map(java.util.Map) After(org.junit.After) Status(io.grpc.Status) UNDEFINED_CALL_METADATA(com.netflix.titus.api.jobmanager.service.JobManagerConstants.UNDEFINED_CALL_METADATA) UNAVAILABLE(io.grpc.Status.UNAVAILABLE) TaskKillRequest(com.netflix.titus.grpc.protogen.TaskKillRequest) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) ImmutableMap(com.google.common.collect.ImmutableMap) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Cell(com.netflix.titus.api.federation.model.Cell) Task(com.netflix.titus.grpc.protogen.Task) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) JobUpdate(com.netflix.titus.grpc.protogen.JobChangeNotification.JobUpdate) Optional(java.util.Optional) GrpcServerRule(io.grpc.testing.GrpcServerRule) TestClock(com.netflix.titus.common.util.time.TestClock) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) Mockito.any(org.mockito.Mockito.any) PublishSubject(rx.subjects.PublishSubject) ApplicationCellRouter(com.netflix.titus.federation.service.router.ApplicationCellRouter) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) Mockito.mock(org.mockito.Mockito.mock) Iterables(com.google.common.collect.Iterables) JobManagerConstants(com.netflix.titus.api.jobmanager.service.JobManagerConstants) JobStatus(com.netflix.titus.grpc.protogen.JobStatus) Job(com.netflix.titus.grpc.protogen.Job) EventPropagationUtil(com.netflix.titus.common.util.event.EventPropagationUtil) ArrayList(java.util.ArrayList) AssertableSubscriber(rx.observers.AssertableSubscriber) TitusFederationConfiguration(com.netflix.titus.federation.startup.TitusFederationConfiguration) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) INTERNAL(io.grpc.Status.INTERNAL) Pair(com.netflix.titus.common.util.tuple.Pair) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) LinkedList(java.util.LinkedList) SnapshotEnd(com.netflix.titus.grpc.protogen.JobChangeNotification.SnapshotEnd) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Before(org.junit.Before) Clocks(com.netflix.titus.common.util.time.Clocks) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Test(org.junit.Test) GrpcJobManagementModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters) Mockito.when(org.mockito.Mockito.when) DEADLINE_EXCEEDED(io.grpc.Status.DEADLINE_EXCEEDED) TimeUnit(java.util.concurrent.TimeUnit) StatusRuntimeException(io.grpc.StatusRuntimeException) GrpcJobQueryModelConverters.toGrpcPage(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPage) Rule(org.junit.Rule) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Page(com.netflix.titus.api.model.Page) JOB_ATTRIBUTES_CELL(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_CELL) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Collections(java.util.Collections) JobCapacityUpdate(com.netflix.titus.grpc.protogen.JobCapacityUpdate) Random(java.util.Random) Test(org.junit.Test)

Example 3 with Job

use of com.netflix.titus.grpc.protogen.Job 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 4 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class AggregatingJobServiceGatewayTest method findJob.

@Test
public void findJob() {
    Random random = new Random();
    List<Job> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(10, GrpcJobManagementModelConverters::toGrpcJob));
    cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()));
    cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(Collections.emptyList(), cellTwoUpdates.serialize()));
    Job expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size())));
    AssertableSubscriber<Job> testSubscriber = service.findJob(expected.getId(), UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue(expected);
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) Job(com.netflix.titus.grpc.protogen.Job) Test(org.junit.Test)

Example 5 with Job

use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.

the class AggregatingJobServiceGatewayTest method observeJobsWaitsForAllMarkers.

@Test
public void observeJobsWaitsForAllMarkers() {
    final List<Job> cellOneSnapshot = Arrays.asList(Job.newBuilder().setId("cell-1-job-1").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-1-job-2").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-1-job-3").setStatus(ACCEPTED_STATE).build());
    final List<Job> cellTwoSnapshot = Arrays.asList(Job.newBuilder().setId("cell-2-job-1").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-2-job-2").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-2-job-3").setStatus(ACCEPTED_STATE).build());
    cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()));
    cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()));
    final AssertableSubscriber<JobChangeNotification> testSubscriber = service.observeJobs(ObserveJobsQuery.getDefaultInstance(), UNDEFINED_CALL_METADATA).test();
    List<JobChangeNotification> expected = Stream.concat(cellOneSnapshot.stream().map(this::toNotification).map(this::withStackName), cellTwoSnapshot.stream().map(this::toNotification).map(this::withStackName)).collect(Collectors.toList());
    // single marker for all cells
    final JobChangeNotification mergedMarker = JobChangeNotification.newBuilder().setSnapshotEnd(SnapshotEnd.newBuilder()).build();
    expected.add(mergedMarker);
    testSubscriber.awaitValueCount(7, 1, TimeUnit.SECONDS);
    List<JobChangeNotification> onNextEvents = testSubscriber.getOnNextEvents().stream().map(this::removeEventPropagationData).collect(Collectors.toList());
    assertThat(onNextEvents).last().isEqualTo(mergedMarker);
    assertThat(onNextEvents).containsExactlyInAnyOrder(expected.toArray(new JobChangeNotification[expected.size()]));
    // more updates are flowing
    final JobChangeNotification cellOneUpdate = toNotification(Job.newBuilder().setId("cell-1-job-10").setStatus(ACCEPTED_STATE).build());
    final JobChangeNotification cellTwoUpdate = toNotification(Job.newBuilder().setId("cell-2-job-10").setStatus(ACCEPTED_STATE).build());
    cellOneUpdates.onNext(cellOneUpdate);
    cellTwoUpdates.onNext(cellTwoUpdate);
    testSubscriber.awaitValueCount(9, 1, TimeUnit.SECONDS);
    onNextEvents = testSubscriber.getOnNextEvents().stream().map(this::removeEventPropagationData).collect(Collectors.toList());
    assertThat(onNextEvents).last().isNotEqualTo(mergedMarker);
    assertThat(onNextEvents).contains(withStackName(cellOneUpdate), withStackName(cellTwoUpdate));
}
Also used : JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) Job(com.netflix.titus.grpc.protogen.Job) Test(org.junit.Test)

Aggregations

Job (com.netflix.titus.grpc.protogen.Job)36 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)14 Task (com.netflix.titus.grpc.protogen.Task)10 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)9 JobQuery (com.netflix.titus.grpc.protogen.JobQuery)9 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)9 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)9 List (java.util.List)9 TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)7 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)6 Pair (com.netflix.titus.common.util.tuple.Pair)6 JobManagementServiceGrpc (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc)6 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)6 JobManagementServiceStub (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)5 Page (com.netflix.titus.grpc.protogen.Page)5 Random (java.util.Random)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5