Search in sources :

Example 11 with TaskUpdateEvent

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

the class LocalCacheQueryProcessorTest method testObserveJobsWithFieldsFiltering.

@Test
public void testObserveJobsWithFieldsFiltering() throws InterruptedException {
    Pair<Job<?>, List<Task>> jobAndTasks = addToJobDataReplicator(newJobAndTasks("job1", 1));
    Job<?> job1 = jobAndTasks.getLeft();
    Task task1 = jobAndTasks.getRight().get(0);
    ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
    ObserveJobsQuery query = ObserveJobsQuery.newBuilder().addJobFields("status").addTaskFields("taskContext").build();
    processor.observeJobs(query).subscribe(subscriber);
    // Snapshot
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobManagerEvent.snapshotMarker()));
    expectJobUpdateEvent(subscriber, j -> {
        assertThat(j.getId()).isEqualTo(job1.getId());
        assertThat(j.getStatus().getReasonMessage()).isEqualTo("<not_given>");
        assertThat(j.getJobDescriptor()).isEqualTo(JobDescriptor.getDefaultInstance());
    });
    expectTaskUpdateEvent(subscriber, t -> {
        assertThat(t.getId()).isEqualTo(task1.getId());
        assertThat(t.getStatus()).isEqualTo(TaskStatus.getDefaultInstance());
        assertThat(t.getTaskContextMap()).containsAllEntriesOf(task1.getTaskContext());
    });
    expectSnapshot(subscriber);
    // Updates after snapshot marker
    Pair<Job<?>, List<Task>> jobAndTasks2 = addToJobDataReplicator(newJobAndTasks("job2", 1));
    Job<?> job2 = jobAndTasks2.getLeft();
    Task task2 = jobAndTasks2.getRight().get(0);
    JobUpdateEvent jobUpdateEvent = JobUpdateEvent.newJob(job2, JUNIT_CALL_METADATA);
    TaskUpdateEvent taskUpdateEvent = TaskUpdateEvent.newTask(job2, task2, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), jobUpdateEvent));
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectJobUpdateEvent(subscriber, j -> {
        assertThat(j.getId()).isEqualTo(job2.getId());
        assertThat(j.getStatus().getReasonMessage()).isEqualTo("<not_given>");
        assertThat(j.getJobDescriptor()).isEqualTo(JobDescriptor.getDefaultInstance());
    });
    expectTaskUpdateEvent(subscriber, t -> {
        assertThat(t.getId()).isEqualTo(task2.getId());
        assertThat(t.getStatus()).isEqualTo(TaskStatus.getDefaultInstance());
        assertThat(t.getTaskContextMap()).containsAllEntriesOf(task2.getTaskContext());
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) Test(org.junit.Test)

Example 12 with TaskUpdateEvent

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

the class LocalCacheQueryProcessorTest method testObserveJob.

@Test
public void testObserveJob() throws InterruptedException {
    ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
    processor.observeJob("job1").subscribe(subscriber);
    Pair<Job<?>, List<Task>> jobAndTasks = addToJobDataReplicator(newJobAndTasks("job1", 2));
    Job<?> job2 = addToJobDataReplicator(newJobAndTasks("job2", 2)).getLeft();
    Job<?> job1 = jobAndTasks.getLeft();
    Task task1 = jobAndTasks.getRight().get(0);
    Task task2 = jobAndTasks.getRight().get(1);
    // Job update event, which also triggers snapshot
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobUpdateEvent.newJob(job2, JUNIT_CALL_METADATA)));
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobUpdateEvent.newJob(job1, JUNIT_CALL_METADATA)));
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job1.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectSnapshot(subscriber);
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job1.getId()));
    // Task update event
    TaskUpdateEvent taskUpdateEvent = TaskUpdateEvent.newTask(job1, task1, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task1.getId()));
    // Check that is correctly terminated
    jobDataReplicatorSink.tryEmitError(new RuntimeException("simulated stream error"));
    await().until(() -> subscriber.getError() != null);
    assertThat(subscriber.getError()).isInstanceOf(RuntimeException.class);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) Test(org.junit.Test)

Example 13 with TaskUpdateEvent

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

the class LocalCacheQueryProcessorTest method testObserveJobs.

@Test
public void testObserveJobs() throws InterruptedException {
    ExtTestSubscriber<JobChangeNotification> subscriber = new ExtTestSubscriber<>();
    processor.observeJobs(ObserveJobsQuery.getDefaultInstance()).subscribe(subscriber);
    Pair<Job<?>, List<Task>> jobAndTasks = addToJobDataReplicator(newJobAndTasks("job1", 2));
    Job<?> job = jobAndTasks.getLeft();
    Task task1 = jobAndTasks.getRight().get(0);
    Task task2 = jobAndTasks.getRight().get(1);
    // Job update event, which also triggers snapshot
    JobUpdateEvent jobUpdateEvent = JobUpdateEvent.newJob(job, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), jobUpdateEvent));
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isIn(task1.getId(), task2.getId()));
    expectSnapshot(subscriber);
    expectJobUpdateEvent(subscriber, j -> assertThat(j.getId()).isEqualTo(job.getId()));
    // Task update event
    TaskUpdateEvent taskUpdateEvent = TaskUpdateEvent.newTask(job, task1, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task1.getId()));
    // Job replicator re-sends events if there is nothing new to keep the stream active. Make sure that
    // we filter the keep alive events.
    TaskUpdateEvent taskUpdateEvent2 = TaskUpdateEvent.newTask(job, task2, JUNIT_CALL_METADATA);
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), JobManagerEvent.keepAliveEvent(-1)));
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent2));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task2.getId()));
    // Now repeat taskUpdateEvent which this time should go through.
    emitEvent(Pair.of(jobDataReplicator.getCurrent(), taskUpdateEvent));
    expectTaskUpdateEvent(subscriber, t -> assertThat(t.getId()).isEqualTo(task1.getId()));
    // Check that is correctly terminated
    jobDataReplicatorSink.tryEmitError(new RuntimeException("simulated stream error"));
    await().until(() -> subscriber.getError() != null);
    assertThat(subscriber.getError()).isInstanceOf(RuntimeException.class);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ExtTestSubscriber(com.netflix.titus.testkit.rx.ExtTestSubscriber) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent) JobUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.JobUpdateEvent) Test(org.junit.Test)

Example 14 with TaskUpdateEvent

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

the class JobScenarioBuilder method expectArchivedTaskEvent.

public JobScenarioBuilder expectArchivedTaskEvent(int taskIdx, int resubmit) {
    JobManagerEvent<?> event = autoAdvance(() -> jobEventsSubscriber.takeNextTaskEvent(taskIdx, resubmit));
    assertThat(event).isNotNull();
    assertThat(event).isInstanceOf(TaskUpdateEvent.class);
    TaskUpdateEvent taskUpdateEvent = (TaskUpdateEvent) event;
    assertThat(taskUpdateEvent.isArchived()).isTrue();
    return this;
}
Also used : TaskUpdateEvent(com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)

Example 15 with TaskUpdateEvent

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

the class JobScenarioBuilder method expectTaskStateChangeEvent.

public JobScenarioBuilder expectTaskStateChangeEvent(int taskIdx, int resubmit, TaskState taskState, String reasonCode) {
    TaskUpdateEvent event = expectTaskEvent(taskIdx, resubmit);
    TaskStatus status = event.getCurrent().getStatus();
    assertThat(status.getState()).isEqualTo(taskState);
    assertThat(status.getReasonCode()).isEqualTo(reasonCode);
    return this;
}
Also used : TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) 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