Search in sources :

Example 1 with GrpcJobManagementModelConverters.toCoreJob

use of com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toCoreJob 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)

Aggregations

JobAttributes (com.netflix.titus.api.jobmanager.JobAttributes)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 Job (com.netflix.titus.grpc.protogen.Job)1 Task (com.netflix.titus.grpc.protogen.Task)1 GrpcJobManagementModelConverters (com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters)1 ElasticSearchUtils (com.netflix.titus.supplementary.taskspublisher.es.ElasticSearchUtils)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 ConnectableFlux (reactor.core.publisher.ConnectableFlux)1 Flux (reactor.core.publisher.Flux)1 Mono (reactor.core.publisher.Mono)1 Scheduler (reactor.core.scheduler.Scheduler)1 Schedulers (reactor.core.scheduler.Schedulers)1