Search in sources :

Example 21 with Job

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());
    });
}
Also used : Logger(org.slf4j.Logger) ServiceJobSpec(com.netflix.titus.grpc.protogen.ServiceJobSpec) UInt32Value(com.google.protobuf.UInt32Value) JobStatus(com.netflix.titus.grpc.protogen.JobStatus) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Page(com.netflix.titus.grpc.protogen.Page) Observable(rx.Observable) Inject(javax.inject.Inject) List(java.util.List) Pair(com.netflix.titus.common.util.tuple.Pair) Optional(java.util.Optional) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobServiceGateway(com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway) JobCapacityWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobCapacityUpdateWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes) ServiceJobSpec(com.netflix.titus.grpc.protogen.ServiceJobSpec) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Job(com.netflix.titus.grpc.protogen.Job)

Example 22 with Job

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);
    }
}
Also used : ArrayList(java.util.ArrayList) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) V3JobQueryCriteriaEvaluator(com.netflix.titus.runtime.endpoint.v3.grpc.query.V3JobQueryCriteriaEvaluator) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) StatusRuntimeException(io.grpc.StatusRuntimeException) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) Pagination(com.netflix.titus.api.model.Pagination) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) JobComparators(com.netflix.titus.runtime.jobmanager.JobComparators) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.grpc.protogen.Job) HashSet(java.util.HashSet)

Example 23 with Job

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();
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) GrpcJobManagementModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters) 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 24 with Job

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

Example 25 with Job

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();
}
Also used : Job(com.netflix.titus.grpc.protogen.Job)

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