Search in sources :

Example 1 with JobNewModelReconcilerEvent

use of com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobNewModelReconcilerEvent in project titus-control-plane by Netflix.

the class DefaultV3JobOperations method toJobManagerEvent.

private List<JobManagerEvent<?>> toJobManagerEvent(Predicate<Pair<Job<?>, List<Task>>> jobsPredicate, Predicate<Pair<Job<?>, Task>> tasksPredicate, boolean withCheckpoints, JobManagerReconcilerEvent event) {
    if (event instanceof JobCheckpointReconcilerEvent) {
        if (withCheckpoints) {
            JobCheckpointReconcilerEvent checkpoint = (JobCheckpointReconcilerEvent) event;
            return Collections.singletonList(JobManagerEvent.keepAliveEvent(checkpoint.getTimestampNano()));
        }
        return Collections.emptyList();
    }
    if (event instanceof JobNewModelReconcilerEvent) {
        JobNewModelReconcilerEvent newModelEvent = (JobNewModelReconcilerEvent) event;
        return toNewJobUpdateEvent(newModelEvent, jobsPredicate);
    }
    if (!(event instanceof JobModelUpdateReconcilerEvent)) {
        return Collections.emptyList();
    }
    JobModelUpdateReconcilerEvent modelUpdateEvent = (JobModelUpdateReconcilerEvent) event;
    if (modelUpdateEvent.getModelActionHolder().getModel() != Model.Reference) {
        return Collections.emptyList();
    }
    if (modelUpdateEvent.getChangedEntityHolder().getEntity() instanceof Job) {
        // We have to emit for this case both task archived event followed by job update event.
        if (modelUpdateEvent.getChangeAction().getTrigger() == Trigger.ReconcilerServiceTaskRemoved) {
            Task archivedTask = modelUpdateEvent.getChangeAction().getTask().orElse(null);
            if (archivedTask != null) {
                Job<?> job = modelUpdateEvent.getJob();
                TaskUpdateEvent archiveEvent = TaskUpdateEvent.taskArchived(job, archivedTask, modelUpdateEvent.getCallMetadata());
                List<JobManagerEvent<?>> events = new ArrayList<>();
                events.add(archiveEvent);
                events.addAll(toJobUpdateEvent(modelUpdateEvent, jobsPredicate));
                return events;
            }
        }
        return toJobUpdateEvent(modelUpdateEvent, jobsPredicate);
    }
    return toTaskUpdateEvent(modelUpdateEvent, tasksPredicate);
}
Also used : JobCheckpointReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobCheckpointReconcilerEvent) JobModelUpdateReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobModelUpdateReconcilerEvent) Task(com.netflix.titus.api.jobmanager.model.job.Task) JobNewModelReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobNewModelReconcilerEvent) JobManagerEvent(com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent) ArrayList(java.util.ArrayList) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Aggregations

Job (com.netflix.titus.api.jobmanager.model.job.Job)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 JobManagerEvent (com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent)1 TaskUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)1 JobCheckpointReconcilerEvent (com.netflix.titus.master.jobmanager.service.event.JobCheckpointReconcilerEvent)1 JobModelUpdateReconcilerEvent (com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobModelUpdateReconcilerEvent)1 JobNewModelReconcilerEvent (com.netflix.titus.master.jobmanager.service.event.JobModelReconcilerEvent.JobNewModelReconcilerEvent)1 ArrayList (java.util.ArrayList)1