use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGateway method addStackName.
private JobChangeNotification addStackName(JobChangeNotification notification) {
switch(notification.getNotificationCase()) {
case JOBUPDATE:
Job job = addStackName(notification.getJobUpdate().getJob());
job = JobEventPropagationUtil.recordChannelLatency(CHECKPOINT_FED_CLIENT, job, notification.getTimestamp(), titusRuntime.getClock());
JobUpdate jobUpdate = notification.getJobUpdate().toBuilder().setJob(job).build();
return notification.toBuilder().setJobUpdate(jobUpdate).build();
case TASKUPDATE:
Task task = addStackName(notification.getTaskUpdate().getTask());
task = JobEventPropagationUtil.recordChannelLatency(CHECKPOINT_FED_CLIENT, task, notification.getTimestamp(), titusRuntime.getClock());
TaskUpdate taskUpdate = notification.getTaskUpdate().toBuilder().setTask(task).build();
return notification.toBuilder().setTaskUpdate(taskUpdate).build();
default:
return notification;
}
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByJobState.
@Test(timeout = 30_000)
public void testSearchByJobState() throws Exception {
JobDescriptor<BatchJobExt> jobDescriptor = batchJobDescriptors().getValue().toBuilder().withApplicationName("testSearchByJobState").build();
String acceptedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
String killInitiatedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob()).killJob().expectJobUpdateEvent(job -> job.getStatus().getState() == JobState.KillInitiated, "Expected state: " + JobState.KillInitiated)).getId();
String acceptedTaskId = jobsScenarioBuilder.takeJob(acceptedJobId).getTaskByIndex(0).getTask().getId();
String killInitiatedTaskId = jobsScenarioBuilder.takeJob(killInitiatedJobId).getTaskByIndex(0).getTask().getId();
// Indexes are recomputed after events are sent, so if we run findJobs/findTasks immediately, they may use stale index.
Thread.sleep(10);
JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
// Jobs (Accepted)
JobQueryResult acceptedJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "Accepted").build());
assertThat(acceptedJobQueryResult.getItemsList()).hasSize(1);
Job acceptedJobQueryResultItem = acceptedJobQueryResult.getItems(0);
assertThat(acceptedJobQueryResultItem.getId()).isEqualTo(acceptedJobId);
// Jobs (KillInitiated)
JobQueryResult killInitJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
assertThat(killInitJobQueryResult.getItemsList()).hasSize(1);
Job killInitJobQueryResultItem = killInitJobQueryResult.getItems(0);
assertThat(killInitJobQueryResultItem.getId()).isEqualTo(killInitiatedJobId);
// Tasks (Accepted)
TaskQueryResult acceptedTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "Accepted").setPage(PAGE).build());
assertThat(acceptedTaskQueryResult.getItemsList()).hasSize(1);
assertThat(acceptedTaskQueryResult.getItems(0).getId()).isEqualTo(acceptedTaskId);
// Tasks (KillInitiated)
TaskQueryResult killInitTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
assertThat(killInitTaskQueryResult.getItemsList()).hasSize(1);
assertThat(killInitTaskQueryResult.getItems(0).getId()).isEqualTo(killInitiatedTaskId);
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testFindJobAndTaskByJobIdsV3.
@Test(timeout = 30_000)
public void testFindJobAndTaskByJobIdsV3() {
String job0 = batchJobsWithCreatedTasks.get(0);
String job2 = batchJobsWithCreatedTasks.get(2);
// Jobs
JobQueryResult jobQueryResult = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("jobIds", job0 + ',' + job2).setPage(PAGE).build());
final List<Job> itemsList = jobQueryResult.getItemsList();
assertThat(itemsList).hasSize(2);
// Tasks
TaskQueryResult taskQueryResult = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("jobIds", job0 + ',' + job2).setPage(PAGE).build());
assertThat(taskQueryResult.getItemsList()).hasSize(2);
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByCellV3.
@Test(timeout = 30_000)
public void testSearchByCellV3() {
final int numberOfJobs = 3;
String[] expectedJobIds = new String[numberOfJobs];
String[] expectedTaskIds = new String[numberOfJobs];
for (int i = 0; i < numberOfJobs; i++) {
String jobId = jobsScenarioBuilder.scheduleAndReturnJob(BATCH_JOB_TEMPLATE.toBuilder().withApplicationName("testSearchByCellV3").build(), jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
expectedJobIds[i] = jobId;
expectedTaskIds[i] = jobsScenarioBuilder.takeJob(jobId).getTaskByIndex(0).getTask().getId();
}
// Jobs
JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByCellV3").setPage(PAGE);
JobQueryResult jobs1 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", "titus.cell,titus.stack").putFilteringCriteria("attributes.op", "or").build());
assertContainsJobs(jobs1, expectedJobIds);
jobs1.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
JobQueryResult jobs2 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", "titus.cell").putFilteringCriteria("attributes.op", "and").build());
assertContainsJobs(jobs2, expectedJobIds);
jobs2.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
JobQueryResult jobs3 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s,titus.stack:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "or").build());
assertContainsJobs(jobs3, expectedJobIds);
jobs3.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
JobQueryResult jobs4 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "and").build());
assertContainsJobs(jobs4, expectedJobIds);
jobs4.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
// Tasks
TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByCellV3").setPage(PAGE);
TaskQueryResult tasks1 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", "titus.cell,titus.stack").putFilteringCriteria("attributes.op", "or").build());
assertContainsTasks(tasks1, expectedTaskIds);
tasks1.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
TaskQueryResult tasks2 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", "titus.cell").putFilteringCriteria("attributes.op", "and").build());
assertContainsTasks(tasks2, expectedTaskIds);
tasks2.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
TaskQueryResult tasks3 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s,titus.stack:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "or").build());
assertContainsTasks(tasks3, expectedTaskIds);
tasks3.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
final TaskQueryResult tasks4 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "and").build());
assertContainsTasks(tasks4, expectedTaskIds);
tasks4.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class JobObserveTest method observeByJobDescriptor.
private void observeByJobDescriptor(String jobId, ObserveJobsQuery query, Consumer<Job> check) throws InterruptedException {
TestStreamObserver<JobChangeNotification> subscriber = subscribe(query);
JobChangeNotification event;
while ((event = subscriber.takeNext(SHORT_TIMEOUT_MS, TimeUnit.MILLISECONDS)) != null) {
if (event.hasJobUpdate()) {
Job job = event.getJobUpdate().getJob();
assertThat(job.getId()).isEqualTo(jobId);
check.accept(job);
return;
}
}
fail(String.format("Expected job event not found: jobId=%s, query=%s", jobId, query));
}
Aggregations