Search in sources :

Example 1 with TaskUpdateEvent

use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.

the class JobScenarioBuilder method expectTaskEvent.

private TaskUpdateEvent expectTaskEvent(int taskIdx, int resubmit) {
    jobStore.expectTaskInStore(jobId, taskIdx, resubmit);
    JobManagerEvent<?> event = autoAdvance(() -> jobEventsSubscriber.takeNextTaskEvent(taskIdx, resubmit));
    assertThat(event).isNotNull();
    assertThat(event).isInstanceOf(TaskUpdateEvent.class);
    TaskUpdateEvent taskUpdateEvent = (TaskUpdateEvent) event;
    Task taskFromEvent = taskUpdateEvent.getCurrent();
    assertThat(jobStore.hasIndexAndResubmit(taskFromEvent, taskIdx, resubmit)).describedAs("Expected event for task index %i and resubmit %i, but got %s", taskIdx, resubmit, taskFromEvent.getId()).isTrue();
    return taskUpdateEvent;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Example 2 with TaskUpdateEvent

use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.

the class JobScenarioBuilder method expectTaskEvent.

public JobScenarioBuilder expectTaskEvent(int taskIdx, int resubmit, Consumer<TaskUpdateEvent> validator) {
    TaskUpdateEvent event = expectTaskEvent(taskIdx, resubmit);
    validator.accept(event);
    return this;
}
Also used : TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Example 3 with TaskUpdateEvent

use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.

the class AlwaysHealthyContainerHealthService method events.

@Override
public Flux<ContainerHealthEvent> events(boolean snapshot) {
    return ReactorExt.toFlux(jobOperations.observeJobs()).flatMap(event -> {
        if (event instanceof TaskUpdateEvent) {
            TaskUpdateEvent taskUpdateEvent = (TaskUpdateEvent) event;
            Task task = taskUpdateEvent.getCurrentTask();
            return Flux.just(ContainerHealthEvent.healthChanged(buildHealthStatus(task)));
        }
        return Flux.empty();
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Example 4 with TaskUpdateEvent

use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.

the class LocalCacheQueryProcessor method toObserveJobsEvent.

private Optional<JobChangeNotification> toObserveJobsEvent(JobSnapshot snapshot, JobManagerEvent<?> event, long now, V3JobQueryCriteriaEvaluator jobsPredicate, V3TaskQueryCriteriaEvaluator tasksPredicate, Set<String> jobFields, Set<String> taskFields) {
    if (event instanceof JobUpdateEvent) {
        JobUpdateEvent jobUpdateEvent = (JobUpdateEvent) event;
        Job<?> job = jobUpdateEvent.getCurrent();
        List<com.netflix.titus.api.jobmanager.model.job.Task> tasks = new ArrayList<>(snapshot.getTasks(job.getId()).values());
        return jobsPredicate.test(Pair.of(job, tasks)) ? Optional.of(toGrpcJobEvent(job, now, jobFields)) : Optional.empty();
    }
    if (event instanceof TaskUpdateEvent) {
        TaskUpdateEvent taskUpdateEvent = (TaskUpdateEvent) event;
        Job<?> job = taskUpdateEvent.getCurrentJob();
        com.netflix.titus.api.jobmanager.model.job.Task task = taskUpdateEvent.getCurrentTask();
        return tasksPredicate.test(Pair.of(job, task)) ? Optional.of(toGrpcTaskEvent(task, taskUpdateEvent.isMovedFromAnotherJob(), now, taskFields)) : Optional.empty();
    }
    return Optional.empty();
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) ArrayList(java.util.ArrayList) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Example 5 with TaskUpdateEvent

use of com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent in project titus-control-plane by Netflix.

the class ObserveJobsCommand method executeOnce.

private void executeOnce(Flux<JobManagerEvent<?>> events, JobEventPropagationMetrics metrics, boolean printLatency, boolean printEvents, boolean snapshotOnly) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    AtomicBoolean snapshotRead = new AtomicBoolean();
    Stopwatch stopwatch = Stopwatch.createStarted();
    Disposable disposable = events.subscribe(next -> {
        if (next == JobManagerEvent.snapshotMarker()) {
            logger.info("Emitted: snapshot marker in {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            snapshotRead.set(true);
            if (snapshotOnly) {
                latch.countDown();
            }
        } else if (next instanceof JobUpdateEvent) {
            Job<?> job = ((JobUpdateEvent) next).getCurrent();
            if (printEvents) {
                logger.info("Emitted job update: jobId={}({}), jobState={}, version={}", job.getId(), next.isArchived() ? "archived" : job.getStatus().getState(), job.getStatus(), job.getVersion());
            }
            Optional<EventPropagationTrace> trace = metrics.recordJob(((JobUpdateEvent) next).getCurrent(), !snapshotRead.get());
            if (printLatency) {
                trace.ifPresent(t -> {
                    logger.info("Event propagation data: stages={}", t);
                });
            }
        } else if (next instanceof TaskUpdateEvent) {
            Task task = ((TaskUpdateEvent) next).getCurrent();
            if (printEvents) {
                logger.info("Emitted task update: jobId={}({}), taskId={}, taskState={}, version={}", task.getJobId(), next.isArchived() ? "archived" : task.getStatus().getState(), task.getId(), task.getStatus(), task.getVersion());
            }
            Optional<EventPropagationTrace> trace = metrics.recordTask(((TaskUpdateEvent) next).getCurrent(), !snapshotRead.get());
            if (printLatency) {
                trace.ifPresent(t -> logger.info("Event propagation data: {}", t));
            }
        } else if (next instanceof JobKeepAliveEvent) {
            if (printEvents) {
                logger.info("Keep alive response: " + next);
            }
        } else {
            logger.info("Unrecognized event type: {}", next);
        }
    }, e -> {
        ErrorReports.handleReplyError("Error in the event stream", e);
        latch.countDown();
    }, () -> {
        logger.info("Event stream closed");
        latch.countDown();
    });
    latch.await();
    disposable.dispose();
}
Also used : Disposable(reactor.core.Disposable) CommandContext(com.netflix.titus.cli.CommandContext) Disposable(reactor.core.Disposable) Stopwatch(com.google.common.base.Stopwatch) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) Task(com.netflix.titus.api.jobmanager.model.job.Task) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StringExt(com.netflix.titus.common.util.StringExt) CliCommand(com.netflix.titus.cli.CliCommand) JobEventPropagationMetrics(com.netflix.titus.runtime.connector.jobmanager.JobEventPropagationMetrics) Option(org.apache.commons.cli.Option) EventPropagationTrace(com.netflix.titus.common.util.event.EventPropagationTrace) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) Set(java.util.Set) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) JobKeepAliveEvent(com.netflix.titus.api.jobmanager.model.job.event.JobKeepAliveEvent) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) JobManagementServiceBlockingStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceBlockingStub) Optional(java.util.Optional) ErrorReports(com.netflix.titus.cli.command.ErrorReports) Collections(java.util.Collections) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) RemoteJobManagementClient(com.netflix.titus.runtime.connector.jobmanager.RemoteJobManagementClient) Task(com.netflix.titus.api.jobmanager.model.job.Task) Optional(java.util.Optional) Stopwatch(com.google.common.base.Stopwatch) JobKeepAliveEvent(com.netflix.titus.api.jobmanager.model.job.event.JobKeepAliveEvent) CountDownLatch(java.util.concurrent.CountDownLatch) EventPropagationTrace(com.netflix.titus.common.util.event.EventPropagationTrace) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Aggregations

TaskUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)16 Task (com.netflix.titus.api.jobmanager.model.job.Task)11 Job (com.netflix.titus.api.jobmanager.model.job.Job)8 JobUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent)7 JobManagerEvent (com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent)5 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)4 List (java.util.List)4 Test (org.junit.Test)4 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)3 ExtTestSubscriber (com.netflix.titus.testkit.rx.ExtTestSubscriber)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)2 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)2 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)2 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)2 TitusRuntimes (com.netflix.titus.common.runtime.TitusRuntimes)2 ObserveJobsQuery (com.netflix.titus.grpc.protogen.ObserveJobsQuery)2 JobConnectorConfiguration (com.netflix.titus.runtime.connector.jobmanager.JobConnectorConfiguration)2 JobManagementClient (com.netflix.titus.runtime.connector.jobmanager.JobManagementClient)2