use of com.netflix.titus.grpc.protogen.Task 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.Task in project titus-control-plane by Netflix.
the class JobDirectQueryTest method testFindTaskByIdV3.
@Test(timeout = 30_000)
public void testFindTaskByIdV3() throws Exception {
Task task = client.findTask(TaskId.newBuilder().setId(v3BatchTaskId).build());
assertThat(task.getId()).isEqualTo(v3BatchTaskId);
}
use of com.netflix.titus.grpc.protogen.Task in project titus-control-plane by Netflix.
the class JobManagementSpringResourceTest method testFindTask.
@Test
public void testFindTask() throws Exception {
when(jobServiceGatewayMock.findTask(TASK_ID_1, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(TASK_1));
Task entity = SpringMockMvcUtil.doGet(mockMvc, String.format("/api/v3/tasks/%s", TASK_ID_1), Task.class);
assertThat(entity).isEqualTo(TASK_1);
verify(jobServiceGatewayMock, times(1)).findTask(TASK_ID_1, JUNIT_REST_CALL_METADATA);
}
use of com.netflix.titus.grpc.protogen.Task in project titus-control-plane by Netflix.
the class JobManagerCursors method taskIndexOf.
/**
* Find an index of the element pointed to by the cursor, or if not found, the element immediately preceding it.
* <p>
* If the element pointed to by the cursor would be the first element in the list (index=0) this returns -1.
*
* @deprecated Use core model entities.
*/
@Deprecated
public static Optional<Integer> taskIndexOf(List<Task> tasks, String cursor) {
return decode(cursor).map(cursorValues -> {
String taskId = cursorValues.getLeft();
long timestamp = cursorValues.getRight();
Task referenceTask = Task.newBuilder().setId(taskId).setStatus(TaskStatus.newBuilder().setState(TaskStatus.TaskState.Accepted).setTimestamp(timestamp)).build();
int idx = Collections.binarySearch(tasks, referenceTask, taskCursorOrderComparator());
if (idx >= 0) {
return idx;
}
return Math.max(-1, -idx - 2);
});
}
use of com.netflix.titus.grpc.protogen.Task in project titus-control-plane by Netflix.
the class TaskEventsGenerator method buildEventStream.
private void buildEventStream() {
taskEvents = titusClient.getJobAndTaskUpdates().publishOn(scheduler).flatMap(jobOrTaskUpdate -> jobOrTaskUpdate.hasTask() ? Flux.just(jobOrTaskUpdate.getTask()) : Flux.empty()).map(task -> {
final Mono<Job> jobById = titusClient.getJobById(task.getJobId());
return Pair.of(task, jobById);
}).flatMap(taskMonoPair -> {
final Task task = taskMonoPair.getLeft();
return taskMonoPair.getRight().flatMap(job -> {
try {
final com.netflix.titus.api.jobmanager.model.job.Job coreJob = GrpcJobManagementModelConverters.toCoreJob(job);
final com.netflix.titus.api.jobmanager.model.job.Task coreTask = GrpcJobManagementModelConverters.toCoreTask(coreJob, task);
return Mono.just(TaskDocument.fromV3Task(coreTask, coreJob, ElasticSearchUtils.DATE_FORMAT, buildTaskContext(task)));
} catch (Exception e) {
// If the mapping fails, we do not want to break the pipeline, and possible cause an infinite number
// of retries, each failing on the same bad job/task record. Instead, we log the error.
titusRuntime.getCodeInvariants().unexpectedError(String.format("Cannot map Titus job/task to ES TaskDocument: job=%s, task=%s", job, task), e);
logger.warn("Cannot map Titus job/task to ES TaskDocument", e);
return Mono.empty();
}
}).flux();
}).doOnError(error -> logger.error("TitusClient event stream error", error)).retryWhen(TaskPublisherRetryUtil.buildRetryHandler(TaskPublisherRetryUtil.INITIAL_RETRY_DELAY_MS, TaskPublisherRetryUtil.MAX_RETRY_DELAY_MS, -1)).publish();
}
Aggregations