Search in sources :

Example 21 with TaskQueryResult

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

the class TaskDataInjectorTest method testFindTasksWithRelocationDeadline.

@Test
public void testFindTasksWithRelocationDeadline() {
    long deadline1 = titusRuntime.getClock().wallTime() + 1_000;
    long deadline2 = titusRuntime.getClock().wallTime() + 2_000;
    TaskQueryResult queryResult = TaskQueryResult.newBuilder().addItems(TASK1).addItems(TASK2).build();
    when(relocationDataReplicator.getCurrent()).thenReturn(newRelocationSnapshot(newRelocationPlan(TASK1, deadline1), newRelocationPlan(TASK2, deadline2)));
    TaskQueryResult merged = Observable.just(queryResult).map(queryResult1 -> taskDataInjector.injectIntoTaskQueryResult(queryResult1)).toBlocking().first();
    assertThat(merged.getItems(0).getMigrationDetails().getNeedsMigration()).isTrue();
    assertThat(merged.getItems(0).getMigrationDetails().getDeadline()).isEqualTo(deadline1);
    assertThat(merged.getItems(1).getMigrationDetails().getNeedsMigration()).isTrue();
    assertThat(merged.getItems(1).getMigrationDetails().getDeadline()).isEqualTo(deadline2);
}
Also used : TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Test(org.junit.Test)

Example 22 with TaskQueryResult

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

the class GatewayJobServiceGatewayTest method testCombineActiveAndArchiveTaskResultSet.

private void testCombineActiveAndArchiveTaskResultSet(Function<Pagination, TaskQuery> queryFunction, Function<Integer, TaskQueryResult> activePageResultFunction) {
    // First page
    TaskQueryResult combinedResult = testCombineForFirstPage();
    // Iterate using page numbers
    // Archive tasks first.
    Pagination lastPagination = combinedResult.getPagination();
    for (int p = 1; p < ARCHIVED_TASKS_COUNT / PAGE_SIZE; p++) {
        TaskQuery cursorQuery = queryFunction.apply(lastPagination);
        TaskQueryResult cursorResult = GatewayJobServiceGateway.combineTaskResults(cursorQuery, activePageResultFunction.apply(0), ARCHIVED_TASKS);
        checkCombinedResult(cursorResult, ARCHIVED_TASKS.subList(p * PAGE_SIZE, (p + 1) * PAGE_SIZE));
        lastPagination = cursorResult.getPagination();
    }
    // Now fetch the active data
    for (int p = 0; p < JOB_SIZE / PAGE_SIZE; p++) {
        TaskQuery cursorQuery = queryFunction.apply(lastPagination);
        TaskQueryResult cursorResult = GatewayJobServiceGateway.combineTaskResults(cursorQuery, activePageResultFunction.apply(p), ARCHIVED_TASKS);
        checkCombinedResult(cursorResult, ACTIVE_TASKS.subList(p * PAGE_SIZE, (p + 1) * PAGE_SIZE));
        lastPagination = cursorResult.getPagination();
    }
}
Also used : Pagination(com.netflix.titus.grpc.protogen.Pagination) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult)

Example 23 with TaskQueryResult

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

the class JobCriteriaQueryTest method testPagination.

@Test(timeout = 30_000)
public void testPagination() {
    // We have 3 batch and 3 service jobs.
    Page firstPageOf5 = Page.newBuilder().setPageNumber(0).setPageSize(5).build();
    Page secondPageOf5 = Page.newBuilder().setPageNumber(1).setPageSize(5).build();
    // Jobs
    JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("attributes", PRE_CREATED_JOBS_LABEL);
    JobQueryResult jobQueryResult = client.findJobs(jobQueryBuilder.setPage(firstPageOf5).build());
    assertThat(jobQueryResult.getItemsList()).hasSize(5);
    checkPage(jobQueryResult.getPagination(), firstPageOf5, 2, 6, true);
    JobQueryResult jobQueryResult2 = client.findJobs(jobQueryBuilder.setPage(secondPageOf5).build());
    assertThat(jobQueryResult2.getItemsList()).hasSize(1);
    checkPage(jobQueryResult2.getPagination(), secondPageOf5, 2, 6, false);
    Set<String> foundJobIds = new HashSet<>();
    jobQueryResult.getItemsList().forEach(j -> foundJobIds.add(j.getId()));
    jobQueryResult2.getItemsList().forEach(j -> foundJobIds.add(j.getId()));
    assertThat(foundJobIds).hasSize(6);
    // Tasks
    TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("attributes", PRE_CREATED_JOBS_LABEL);
    TaskQueryResult taskQueryResult = client.findTasks(taskQueryBuilder.setPage(firstPageOf5).build());
    assertThat(taskQueryResult.getItemsList()).hasSize(5);
    checkPage(taskQueryResult.getPagination(), firstPageOf5, 2, 6, true);
    TaskQueryResult taskQueryResult2 = client.findTasks(taskQueryBuilder.setPage(secondPageOf5).build());
    assertThat(taskQueryResult2.getItemsList()).hasSize(1);
    checkPage(taskQueryResult2.getPagination(), secondPageOf5, 2, 6, false);
    Set<String> foundTasksIds = new HashSet<>();
    taskQueryResult.getItemsList().forEach(j -> foundTasksIds.add(j.getId()));
    taskQueryResult2.getItemsList().forEach(j -> foundTasksIds.add(j.getId()));
    assertThat(foundTasksIds).hasSize(6);
}
Also used : TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Page(com.netflix.titus.grpc.protogen.Page) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) HashSet(java.util.HashSet) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 24 with TaskQueryResult

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

the class JobCriteriaQueryTest method testSearchByTaskStateV3.

private void testSearchByTaskStateV3(String taskState, String expectedJobId, String expectedTaskId) {
    // Job
    JobQueryResult jobQueryResult = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByTaskStateV3").putFilteringCriteria("taskStates", taskState).setPage(PAGE).build());
    assertThat(jobQueryResult.getItemsList()).hasSize(1);
    Job jobQueryResultItem = jobQueryResult.getItems(0);
    assertThat(jobQueryResultItem.getId()).isEqualTo(expectedJobId);
    // Task
    TaskQueryResult taskQueryResult = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByTaskStateV3").putFilteringCriteria("taskStates", taskState).setPage(PAGE).build());
    assertThat(taskQueryResult.getItemsList()).hasSize(1);
    assertThat(taskQueryResult.getItems(0).getId()).isEqualTo(expectedTaskId);
}
Also used : Job(com.netflix.titus.grpc.protogen.Job) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult)

Example 25 with TaskQueryResult

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

the class JobCriteriaQueryTest method testFindJobAndTaskByTaskIdsV3.

@Test(timeout = 30_000)
public void testFindJobAndTaskByTaskIdsV3() {
    String task0 = jobsScenarioBuilder.takeJob(batchJobsWithCreatedTasks.get(0)).getTaskByIndex(0).getTask().getId();
    String task2 = jobsScenarioBuilder.takeJob(batchJobsWithCreatedTasks.get(2)).getTaskByIndex(0).getTask().getId();
    // Jobs
    JobQueryResult jobQueryResult = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("taskIds", task0 + ',' + task2).setPage(PAGE).build());
    final List<Job> itemsList = jobQueryResult.getItemsList();
    assertThat(itemsList).hasSize(2);
    // Tasks
    TaskQueryResult taskQueryResult = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("taskIds", task0 + ',' + task2).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)

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