Search in sources :

Example 6 with Task

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));
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) EmbeddedTitusMasters(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMasters) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) EmbeddedKubeClusters(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeClusters) ClassRule(org.junit.ClassRule) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) ImmutableMap(com.google.common.collect.ImmutableMap) PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) Set(java.util.Set) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Page(com.netflix.titus.grpc.protogen.Page) List(java.util.List) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) CellAssertions.assertCellInfo(com.netflix.titus.master.integration.v3.job.CellAssertions.assertCellInfo) BeforeClass(org.junit.BeforeClass) Job(com.netflix.titus.grpc.protogen.Job) Image(com.netflix.titus.api.jobmanager.model.job.Image) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Test(org.junit.Test) Pagination(com.netflix.titus.grpc.protogen.Pagination) JobScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) EmbeddedTitusCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCell) Collections(java.util.Collections) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 7 with Task

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);
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 8 with Task

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);
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) GrpcJobManagementModelConverters.toGrpcTask(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcTask) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 9 with Task

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);
    });
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.grpc.protogen.Task)

Example 10 with Task

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();
}
Also used : Logger(org.slf4j.Logger) Task(com.netflix.titus.grpc.protogen.Task) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) GrpcJobManagementModelConverters(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters) Scheduler(reactor.core.scheduler.Scheduler) Flux(reactor.core.publisher.Flux) Pair(com.netflix.titus.common.util.tuple.Pair) ConnectableFlux(reactor.core.publisher.ConnectableFlux) Map(java.util.Map) ElasticSearchUtils(com.netflix.titus.supplementary.taskspublisher.es.ElasticSearchUtils) Schedulers(reactor.core.scheduler.Schedulers) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) JobAttributes(com.netflix.titus.api.jobmanager.JobAttributes) Task(com.netflix.titus.grpc.protogen.Task) Mono(reactor.core.publisher.Mono) Job(com.netflix.titus.grpc.protogen.Job)

Aggregations

Task (com.netflix.titus.grpc.protogen.Task)30 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)11 TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)10 Job (com.netflix.titus.grpc.protogen.Job)8 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)6 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)6 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Pair (com.netflix.titus.common.util.tuple.Pair)4 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)4 Pagination (com.netflix.titus.api.model.Pagination)3 TitusServiceException (com.netflix.titus.api.service.TitusServiceException)3 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)3 JobQuery (com.netflix.titus.grpc.protogen.JobQuery)3 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)3 Page (com.netflix.titus.grpc.protogen.Page)3 TaskStatus (com.netflix.titus.grpc.protogen.TaskStatus)3 JobManagerCursors (com.netflix.titus.runtime.jobmanager.JobManagerCursors)3