Search in sources :

Example 6 with Job

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

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

the class AggregatingJobServiceGatewayTest method createJobRouteToCorrectStack.

@Test
public void createJobRouteToCorrectStack() {
    // Build service handlers for each cell
    cellToServiceMap.forEach((cell, grpcServerRule) -> grpcServerRule.getServiceRegistry().addService(new CellWithCachedJobsService(cell.getName())));
    // Expected assignments based on routing rules in setUp()
    Map<String, String> expectedAssignmentMap = ImmutableMap.of("app1", "one", "app2", "one", "app3", "two", "app4", "one");
    expectedAssignmentMap.forEach((appName, expectedCellName) -> {
        // Create the job and let it get routed
        JobDescriptor jobDescriptor = JobDescriptor.newBuilder().setApplicationName(appName).setCapacityGroup(appName + "CapGroup").build();
        String jobId = service.createJob(jobDescriptor, JobManagerConstants.UNDEFINED_CALL_METADATA).toBlocking().first();
        // Get a client to the test gRPC service for the cell that we expect got it
        // TODO(Andrew L): This can use findJob() instead once AggregatingService implements it
        Cell expectedCell = getCellWithName(expectedCellName).orElseThrow(() -> TitusServiceException.cellNotFound(expectedCellName));
        JobManagementServiceStub expectedCellClient = JobManagementServiceGrpc.newStub(cellToServiceMap.get(expectedCell).getChannel());
        // Check that the cell has it with the correct attribute
        TestStreamObserver<Job> findJobResponse = new TestStreamObserver<>();
        expectedCellClient.findJob(JobId.newBuilder().setId(jobId).build(), findJobResponse);
        assertThatCode(() -> {
            Job job = findJobResponse.takeNext(1, TimeUnit.SECONDS);
            assertThat(job.getJobDescriptor().getAttributesOrThrow(JOB_ATTRIBUTES_CELL).equals(expectedCellName));
        }).doesNotThrowAnyException();
    });
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Job(com.netflix.titus.grpc.protogen.Job) Cell(com.netflix.titus.api.federation.model.Cell) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) Test(org.junit.Test)

Example 8 with Job

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

the class AggregatingJobServiceGatewayTest method killJob.

@Test
public void killJob() {
    Random random = new Random();
    List<Job> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(12, GrpcJobManagementModelConverters::toGrpcJob));
    List<Job> cellTwoSnapshot = new ArrayList<>(dataGenerator.newBatchJobs(7, GrpcJobManagementModelConverters::toGrpcJob));
    CellWithFixedJobsService cellOneService = new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize());
    CellWithFixedJobsService cellTwoService = new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize());
    cellOne.getServiceRegistry().addService(cellOneService);
    cellTwo.getServiceRegistry().addService(cellTwoService);
    Job killInCellOne = cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()));
    Job killInCellTwo = cellTwoSnapshot.get(random.nextInt(cellTwoSnapshot.size()));
    assertThat(cellOneService.currentJobs()).containsKey(killInCellOne.getId());
    assertThat(cellTwoService.currentJobs()).containsKey(killInCellTwo.getId());
    AssertableSubscriber<Void> testSubscriber = service.killJob(killInCellOne.getId(), UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertNoValues();
    testSubscriber.assertCompleted();
    assertThat(cellOneService.currentJobs()).doesNotContainKey(killInCellOne.getId());
    assertThat(cellTwoService.currentJobs()).doesNotContainKey(killInCellOne.getId());
    testSubscriber.unsubscribe();
    testSubscriber = service.killJob(killInCellTwo.getId(), UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertNoValues();
    testSubscriber.assertCompleted();
    assertThat(cellOneService.currentJobs()).doesNotContainKey(killInCellTwo.getId());
    assertThat(cellTwoService.currentJobs()).doesNotContainKey(killInCellTwo.getId());
    testSubscriber.unsubscribe();
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) Job(com.netflix.titus.grpc.protogen.Job) Test(org.junit.Test)

Example 9 with Job

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

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

the class CellWithFixedJobsService method observeJobs.

@Override
public void observeJobs(ObserveJobsQuery query, StreamObserver<JobChangeNotification> responseObserver) {
    // TODO: query criteria (filters) are not implemented
    for (Job job : jobsIndex.values()) {
        JobChangeNotification.JobUpdate update = JobChangeNotification.JobUpdate.newBuilder().setJob(job).build();
        JobChangeNotification notification = JobChangeNotification.newBuilder().setJobUpdate(update).build();
        responseObserver.onNext(notification);
    }
    SnapshotEnd snapshotEnd = SnapshotEnd.newBuilder().build();
    JobChangeNotification marker = JobChangeNotification.newBuilder().setSnapshotEnd(snapshotEnd).build();
    responseObserver.onNext(marker);
    final Subscription subscription = updates.subscribe(responseObserver::onNext, responseObserver::onError, responseObserver::onCompleted);
    GrpcUtil.attachCancellingCallback(responseObserver, subscription);
}
Also used : JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) SnapshotEnd(com.netflix.titus.grpc.protogen.JobChangeNotification.SnapshotEnd) Job(com.netflix.titus.grpc.protogen.Job) Subscription(rx.Subscription)

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