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;
}
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;
}
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();
});
}
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();
}
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();
}
Aggregations