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();
}
}
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();
});
}
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();
}
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);
}
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);
}
Aggregations