use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class DefaultAppAutoScalingCallbackService method getScalableTargetResourceInfo.
@Override
public Observable<ScalableTargetResourceInfo> getScalableTargetResourceInfo(String jobId, CallMetadata callMetadata) {
TaskQuery taskQuery = TaskQuery.newBuilder().putFilteringCriteria("jobIds", jobId).putFilteringCriteria("taskStates", "Started").setPage(Page.newBuilder().setPageSize(1).build()).build();
return jobServiceGateway.findTasks(taskQuery, callMetadata).map(taskQueryResult -> taskQueryResult.getPagination().getTotalItems()).flatMap(numStartedTasks -> jobServiceGateway.findJob(jobId, callMetadata).map(job -> Pair.of(job, numStartedTasks))).flatMap(jobTasksPair -> {
Job job = jobTasksPair.getLeft();
Integer numRunningTasks = jobTasksPair.getRight();
if (!job.getJobDescriptor().hasService()) {
return Observable.error(JobManagerException.notServiceJob(jobId));
}
ServiceJobSpec jobSpec = job.getJobDescriptor().getService();
ScalableTargetResourceInfo.Builder scalableTargetResourceInfoBuilder = ScalableTargetResourceInfo.newBuilder().actualCapacity(jobTasksPair.getRight()).desiredCapacity(jobSpec.getCapacity().getDesired()).dimensionName(DIMENSION_NAME).resourceName(jobId).scalableTargetDimensionId(jobId).version(buildVersion(job));
if (jobSpec.getCapacity().getDesired() != numRunningTasks) {
scalableTargetResourceInfoBuilder.scalingStatus(ScalingStatus.InProgress.name());
} else {
scalableTargetResourceInfoBuilder.scalingStatus(ScalingStatus.Successful.name());
}
return Observable.just(scalableTargetResourceInfoBuilder.build());
});
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class DefaultJobManagementServiceGrpc method findJobs.
@Override
public void findJobs(JobQuery jobQuery, StreamObserver<JobQueryResult> responseObserver) {
if (!checkPageIsValid(jobQuery.getPage(), responseObserver)) {
return;
}
try {
// We need to find all jobs to get the total number of them.
List<com.netflix.titus.api.jobmanager.model.job.Job<?>> allFilteredJobs = jobOperations.findJobs(new V3JobQueryCriteriaEvaluator(toJobQueryCriteria(jobQuery), titusRuntime), 0, Integer.MAX_VALUE / 2);
Pair<List<com.netflix.titus.api.jobmanager.model.job.Job<?>>, Pagination> queryResult = PaginationUtil.takePageWithCursorAndKeyExtractor(toPage(jobQuery.getPage()), allFilteredJobs, JobComparators::createJobKeyOf, JobManagerCursors::coreJobIndexOf, JobManagerCursors::newJobCoreCursorFrom);
List<Job> grpcJobs = new ArrayList<>();
for (com.netflix.titus.api.jobmanager.model.job.Job<?> job : queryResult.getLeft()) {
Job toGrpcJob = grpcObjectsCache.getJob(job);
grpcJobs.add(toGrpcJob);
}
JobQueryResult grpcQueryResult;
if (jobQuery.getFieldsList().isEmpty()) {
grpcQueryResult = toJobQueryResult(grpcJobs, queryResult.getRight());
} else {
Set<String> fields = new HashSet<>(jobQuery.getFieldsList());
fields.addAll(JOB_MINIMUM_FIELD_SET);
List<Job> list = new ArrayList<>();
for (Job j : grpcJobs) {
list.add(ProtobufExt.copy(j, fields));
}
grpcQueryResult = toJobQueryResult(list, queryResult.getRight());
}
responseObserver.onNext(grpcQueryResult);
responseObserver.onCompleted();
} catch (Exception e) {
safeOnError(logger, e, responseObserver);
}
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobsEmptyPage.
@Test
public void findJobsEmptyPage() {
Random random = new Random();
final List<Job> cellOneSnapshot = new ArrayList<>();
final List<Job> cellTwoSnapshot = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Iterables.addAll(cellOneSnapshot, Iterables.concat(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob), dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob)));
Iterables.addAll(cellTwoSnapshot, Iterables.concat(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob), 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.empty())).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);
assertThat(results.get(0).getItemsList()).isEmpty();
assertThat(results.get(0).getPagination().getHasMore()).isFalse();
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobWithFailingCell.
@Test
public void findJobWithFailingCell() {
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 CellWithFailingJobManagementService());
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);
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class CellWithFixedJobsService method findJob.
@Override
public void findJob(JobId request, StreamObserver<Job> responseObserver) {
Job job = jobsIndex.get(request.getId());
if (job == null) {
responseObserver.onError(NOT_FOUND.asRuntimeException());
return;
}
responseObserver.onNext(job);
responseObserver.onCompleted();
}
Aggregations