Search in sources :

Example 6 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult 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);
}
Also used : Job(com.netflix.titus.grpc.protogen.Job) 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 TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult 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 8 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class JobCriteriaQueryTest method testSearchByJobTypeV3.

@Test(timeout = 30_000)
public void testSearchByJobTypeV3() {
    // Batch only (jobs)
    JobQueryResult batchQueryJobs = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("jobType", "batch").setPage(PAGE).build());
    Set<String> batchJobIds = batchQueryJobs.getItemsList().stream().map(Job::getId).collect(Collectors.toSet());
    assertThat(batchJobIds).containsAll(batchJobsWithCreatedTasks);
    // Batch only (tasks)
    TaskQueryResult batchQueryTasks = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("jobType", "batch").setPage(PAGE).build());
    Set<String> batchTaskIds = batchQueryTasks.getItemsList().stream().map(Task::getId).collect(Collectors.toSet());
    assertThat(batchTaskIds).containsAll(batchTasks);
    // Service only (jobs)
    JobQueryResult serviceQueryJobs = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("jobType", "service").setPage(PAGE).build());
    Set<String> serviceJobIds = serviceQueryJobs.getItemsList().stream().map(Job::getId).collect(Collectors.toSet());
    assertThat(serviceJobIds).containsAll(serviceJobsWithCreatedTasks);
    // Service only (tasks)
    TaskQueryResult serviceQueryTasks = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("jobType", "service").setPage(PAGE).build());
    Set<String> serviceTaskIds = serviceQueryTasks.getItemsList().stream().map(Task::getId).collect(Collectors.toSet());
    assertThat(serviceTaskIds).containsAll(serviceTasks);
}
Also used : 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 9 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class JobCursorQueryTest method testTaskQueryWithCursor.

@Test(timeout = TEST_TIMEOUT_MS)
public void testTaskQueryWithCursor() {
    // Page 0
    TaskQueryResult result0 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4)).build());
    assertThat(result0.getItemsList()).containsExactlyElementsOf(allTasksInOrder.subList(0, 4));
    assertThat(result0.getPagination().getCursor()).isNotEmpty();
    assertThat(result0.getPagination().getCursorPosition()).isEqualTo(3);
    assertThat(result0.getPagination().getHasMore()).isTrue();
    assertThat(result0.getPagination().getCurrentPage().getPageNumber()).isEqualTo(0);
    // Page 1
    TaskQueryResult result1 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4).setCursor(result0.getPagination().getCursor())).build());
    assertThat(result1.getItemsList()).containsExactlyElementsOf(allTasksInOrder.subList(4, 8));
    assertThat(result1.getPagination().getCursor()).isNotEmpty();
    assertThat(result1.getPagination().getCursorPosition()).isEqualTo(7);
    assertThat(result1.getPagination().getHasMore()).isTrue();
    assertThat(result1.getPagination().getCurrentPage().getPageNumber()).isEqualTo(1);
    // Page 2
    TaskQueryResult result2 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4).setCursor(result1.getPagination().getCursor())).build());
    assertThat(result2.getItemsList()).containsExactlyElementsOf(allTasksInOrder.subList(8, 12));
    assertThat(result2.getPagination().getHasMore()).isFalse();
    assertThat(result2.getPagination().getCursor()).isNotEmpty();
    assertThat(result2.getPagination().getCursorPosition()).isEqualTo(11);
    assertThat(result2.getPagination().getCurrentPage().getPageNumber()).isEqualTo(2);
    // Check cursor points to the latest returned element
    TaskQueryResult result3 = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(4).setCursor(result2.getPagination().getCursor())).build());
    assertThat(result3.getItemsList()).isEmpty();
    assertThat(result3.getPagination().getCursor()).isEqualTo(result2.getPagination().getCursor());
    assertThat(result3.getPagination().getCursorPosition()).isEqualTo(result2.getPagination().getCursorPosition());
    assertThat(result3.getPagination().getHasMore()).isFalse();
    assertThat(result3.getPagination().getCurrentPage().getPageNumber()).isEqualTo(result3.getPagination().getTotalPages());
}
Also used : TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 10 with TaskQueryResult

use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.

the class JobScenarioBuilder method findTasks.

public JobScenarioBuilder findTasks(TaskQuery taskQuery, Predicate<List<com.netflix.titus.grpc.protogen.Task>> tasksPredicate) {
    TestStreamObserver<TaskQueryResult> responseObserver = new TestStreamObserver<>();
    client.findTasks(taskQuery, responseObserver);
    TaskQueryResult result = rethrow(() -> responseObserver.getLast(TIMEOUT_MS, TimeUnit.MILLISECONDS));
    if (result == null) {
        throw new IllegalStateException("TaskQueryResult is null");
    } else if (!tasksPredicate.test(result.getItemsList())) {
        throw new IllegalStateException("Tasks predicate is false");
    }
    return this;
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult)

Aggregations

TaskQueryResult (com.netflix.titus.grpc.protogen.TaskQueryResult)29 Test (org.junit.Test)20 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)13 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)12 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)12 Task (com.netflix.titus.grpc.protogen.Task)11 JobQueryResult (com.netflix.titus.grpc.protogen.JobQueryResult)9 Page (com.netflix.titus.grpc.protogen.Page)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Job (com.netflix.titus.grpc.protogen.Job)7 ArrayList (java.util.ArrayList)7 Function (java.util.function.Function)6 JobQuery (com.netflix.titus.grpc.protogen.JobQuery)5 TaskStatus (com.netflix.titus.grpc.protogen.TaskStatus)5 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)3 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)3 Pair (com.netflix.titus.common.util.tuple.Pair)3