Search in sources :

Example 16 with Job

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

the class JobManagementSpringResourceTest method testFindJob.

@Test
public void testFindJob() throws Exception {
    when(jobServiceGatewayMock.findJob(JOB_ID_1, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(JOB_1));
    Job entity = SpringMockMvcUtil.doGet(mockMvc, String.format("/api/v3/jobs/%s", JOB_ID_1), Job.class);
    assertThat(entity).isEqualTo(JOB_1);
    verify(jobServiceGatewayMock, times(1)).findJob(JOB_ID_1, JUNIT_REST_CALL_METADATA);
}
Also used : GrpcJobManagementModelConverters.toGrpcJob(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcJob) Job(com.netflix.titus.grpc.protogen.Job) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 17 with Job

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

the class JobManagerCursors method jobIndexOf.

/**
 * Find an index of the element pointed to by the cursor, or if not found, the element immediately preceding it.
 * <p>
 * If the element pointed to by the cursor would be the first element in the list (index=0) this returns -1.
 *
 * @deprecated Use core model entities.
 */
@Deprecated
public static Optional<Integer> jobIndexOf(List<Job> jobs, String cursor) {
    return decode(cursor).map(cursorValues -> {
        String jobId = cursorValues.getLeft();
        long timestamp = cursorValues.getRight();
        Job referenceJob = Job.newBuilder().setId(jobId).setStatus(JobStatus.newBuilder().setState(JobStatus.JobState.Accepted).setTimestamp(timestamp)).build();
        int idx = Collections.binarySearch(jobs, referenceJob, jobCursorOrderComparator());
        if (idx >= 0) {
            return idx;
        }
        return Math.max(-1, -idx - 2);
    });
}
Also used : Job(com.netflix.titus.grpc.protogen.Job)

Example 18 with Job

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

the class TaskEventsGenerator method buildEventStream.

private void buildEventStream() {
    taskEvents = titusClient.getJobAndTaskUpdates().publishOn(scheduler).flatMap(jobOrTaskUpdate -> jobOrTaskUpdate.hasTask() ? Flux.just(jobOrTaskUpdate.getTask()) : Flux.empty()).map(task -> {
        final Mono<Job> jobById = titusClient.getJobById(task.getJobId());
        return Pair.of(task, jobById);
    }).flatMap(taskMonoPair -> {
        final Task task = taskMonoPair.getLeft();
        return taskMonoPair.getRight().flatMap(job -> {
            try {
                final com.netflix.titus.api.jobmanager.model.job.Job coreJob = GrpcJobManagementModelConverters.toCoreJob(job);
                final com.netflix.titus.api.jobmanager.model.job.Task coreTask = GrpcJobManagementModelConverters.toCoreTask(coreJob, task);
                return Mono.just(TaskDocument.fromV3Task(coreTask, coreJob, ElasticSearchUtils.DATE_FORMAT, buildTaskContext(task)));
            } catch (Exception e) {
                // If the mapping fails, we do not want to break the pipeline, and possible cause an infinite number
                // of retries, each failing on the same bad job/task record. Instead, we log the error.
                titusRuntime.getCodeInvariants().unexpectedError(String.format("Cannot map Titus job/task to ES TaskDocument: job=%s, task=%s", job, task), e);
                logger.warn("Cannot map Titus job/task to ES TaskDocument", e);
                return Mono.empty();
            }
        }).flux();
    }).doOnError(error -> logger.error("TitusClient event stream error", error)).retryWhen(TaskPublisherRetryUtil.buildRetryHandler(TaskPublisherRetryUtil.INITIAL_RETRY_DELAY_MS, TaskPublisherRetryUtil.MAX_RETRY_DELAY_MS, -1)).publish();
}
Also used : Logger(org.slf4j.Logger) Task(com.netflix.titus.grpc.protogen.Task) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) GrpcJobManagementModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters) Scheduler(reactor.core.scheduler.Scheduler) Flux(reactor.core.publisher.Flux) Pair(com.netflix.titus.common.util.tuple.Pair) ConnectableFlux(reactor.core.publisher.ConnectableFlux) Map(java.util.Map) ElasticSearchUtils(com.netflix.titus.supplementary.taskspublisher.es.ElasticSearchUtils) Schedulers(reactor.core.scheduler.Schedulers) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) JobAttributes(com.netflix.titus.api.jobmanager.JobAttributes) Task(com.netflix.titus.grpc.protogen.Task) Mono(reactor.core.publisher.Mono) Job(com.netflix.titus.grpc.protogen.Job)

Example 19 with Job

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

the class TitusClientImpl method getJobAndTaskUpdates.

@Override
public Flux<JobOrTaskUpdate> getJobAndTaskUpdates() {
    return Flux.create(sink -> attachCallerId(jobManagementService, CLIENT_ID).observeJobs(ObserveJobsQuery.newBuilder().build(), new StreamObserver<JobChangeNotification>() {

        @Override
        public void onNext(JobChangeNotification jobChangeNotification) {
            switch(jobChangeNotification.getNotificationCase()) {
                case JOBUPDATE:
                    final Job job = jobChangeNotification.getJobUpdate().getJob();
                    jobs.put(job.getId(), CompletableFuture.completedFuture(job));
                    logger.debug("<{}> JobUpdate {}", Thread.currentThread().getName(), jobChangeNotification.getJobUpdate().getJob().getId());
                    sink.next(JobOrTaskUpdate.jobUpdate(job));
                    numJobUpdates.incrementAndGet();
                    break;
                case TASKUPDATE:
                    logger.debug("<{}> TaskUpdate {}", Thread.currentThread().getName(), jobChangeNotification.getTaskUpdate().getTask().getId());
                    final Task task = jobChangeNotification.getTaskUpdate().getTask();
                    sink.next(JobOrTaskUpdate.taskUpdate(task));
                    numTaskUpdates.incrementAndGet();
                    break;
                case SNAPSHOTEND:
                    logger.info("<{}> SnapshotEnd {}", Thread.currentThread().getName(), jobChangeNotification);
                    numSnapshotUpdates.incrementAndGet();
                    break;
                default:
                    logger.error("<{}> Unknown Notification ? {}", Thread.currentThread().getName(), jobChangeNotification.getNotificationCase());
            }
        }

        @Override
        public void onError(Throwable t) {
            logger.error("Exception in ObserveJobs :: ", t);
            apiErrors.incrementAndGet();
            sink.error(t);
        }

        @Override
        public void onCompleted() {
            logger.info("STREAM completed ?");
            sink.complete();
        }
    }));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Task(com.netflix.titus.grpc.protogen.Task) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) Job(com.netflix.titus.grpc.protogen.Job)

Example 20 with Job

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

the class DefaultAppAutoScalingCallbackService method setScalableTargetResourceInfo.

@Override
public Observable<ScalableTargetResourceInfo> setScalableTargetResourceInfo(String jobId, ScalableTargetResourceInfo scalableTargetResourceInfo, CallMetadata callMetadata) {
    logger.info("(BEFORE setting job instances) for jobId {} :: {}", jobId, scalableTargetResourceInfo);
    JobCapacityWithOptionalAttributes jobCapacityWithOptionalAttributes = JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(scalableTargetResourceInfo.getDesiredCapacity()).build()).build();
    JobCapacityUpdateWithOptionalAttributes jobCapacityRequest = JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(jobCapacityWithOptionalAttributes).build();
    return jobServiceGateway.updateJobCapacityWithOptionalAttributes(jobCapacityRequest, callMetadata).andThen(getScalableTargetResourceInfo(jobId, callMetadata).map(scalableTargetResourceInfoReturned -> {
        scalableTargetResourceInfoReturned.setScalingStatus(ScalingStatus.Pending.name());
        logger.info("(set job instances) Returning value Instances for jobId {} :: {}", jobId, scalableTargetResourceInfo);
        return scalableTargetResourceInfoReturned;
    }));
}
Also used : JobCapacityUpdateWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes) 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) JobCapacityWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes)

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