Search in sources :

Example 1 with Task

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

the class AggregatingJobServiceGatewayTest method findTask.

@Test
public void findTask() {
    Random random = new Random();
    List<Task> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobWithTasks());
    cellOne.getServiceRegistry().addService(new CellWithFixedTasksService(cellOneSnapshot));
    cellTwo.getServiceRegistry().addService(new CellWithFixedTasksService(Collections.emptyList()));
    Task expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size())));
    AssertableSubscriber<Task> testSubscriber = service.findTask(expected.getId(), UNDEFINED_CALL_METADATA).test();
    testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue(expected);
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) Random(java.util.Random) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with Task

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

the class AggregatingJobServiceGatewayTest method findTasksWithFieldFiltering.

@Test
public void findTasksWithFieldFiltering() {
    Pair<List<Task>, List<Task>> cellSnapshots = generateTestJobsWithTasks();
    List<Task> allTasks = walkAllPages(6, request -> service.findTasks(request, UNDEFINED_CALL_METADATA), page -> TaskQuery.newBuilder().setPage(page).addFields("jobId").build(), TaskQueryResult::getPagination, TaskQueryResult::getItemsList);
    assertThat(allTasks).hasSize(cellSnapshots.getLeft().size() + cellSnapshots.getRight().size());
    for (Task task : allTasks) {
        assertThat(task.getId()).isNotEmpty();
        assertThat(task.getJobId()).isNotEmpty();
        assertThat(task.getStatus().getReasonMessage()).isEmpty();
        assertThat(task.getStatusHistoryList()).isEmpty();
    }
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Test(org.junit.Test)

Example 3 with Task

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

the class GrpcJobManagementModelConvertersTest method coreTaskLogAttributes.

@Test
public void coreTaskLogAttributes() {
    String taskId = "tid-1";
    String uiLocation = "http://titus-ui/tasks/" + taskId;
    String liveStream = "http://agentIp:8080/logs/" + taskId;
    String s3Bucket = "bucket-1";
    String s3Key = "key-1";
    String s3AccountId = "acc-1";
    String s3AccountName = "acc-name-1";
    String s3Region = "us-east-1";
    Map<String, String> taskContext = new HashMap<>();
    taskContext.put(TASK_ATTRIBUTES_TASK_ORIGINAL_ID, taskId);
    taskContext.put(TASK_ATTRIBUTES_RESUBMIT_NUMBER, "1");
    Task grpcTask = Task.newBuilder().setId(taskId).putAllTaskContext(taskContext).setLogLocation(LogLocation.newBuilder().setUi(LogLocation.UI.newBuilder().setUrl(uiLocation)).setLiveStream(LogLocation.LiveStream.newBuilder().setUrl(liveStream).build()).setS3(LogLocation.S3.newBuilder().setRegion(s3Region).setBucket(s3Bucket).setKey(s3Key).setAccountId(s3AccountId).setAccountName(s3AccountName)).build()).build();
    com.netflix.titus.api.jobmanager.model.job.Task coreTask = GrpcJobManagementModelConverters.toCoreTask(grpcTask);
    assertThat(coreTask).isNotNull();
    assertThat(coreTask.getAttributes()).hasSizeGreaterThan(0);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_KEY)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_KEY)).isEqualTo(s3Key);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_BUCKET_NAME)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_BUCKET_NAME)).isEqualTo(s3Bucket);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_ID)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_ID)).isEqualTo(s3AccountId);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_NAME)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_ACCOUNT_NAME)).isEqualTo(s3AccountName);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_S3_REGION)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_S3_REGION)).isEqualTo(s3Region);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_UI_LOCATION)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_UI_LOCATION)).isEqualTo(uiLocation);
    assertThat(coreTask.getAttributes().containsKey(TASK_ATTRIBUTE_LOG_LIVE_STREAM)).isTrue();
    assertThat(coreTask.getAttributes().get(TASK_ATTRIBUTE_LOG_LIVE_STREAM)).isEqualTo(liveStream);
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with Task

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

Example 5 with Task

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

the class DefaultJobManagementServiceGrpc method findTasks.

@Override
public void findTasks(TaskQuery taskQuery, StreamObserver<TaskQueryResult> responseObserver) {
    if (!checkPageIsValid(taskQuery.getPage(), responseObserver)) {
        return;
    }
    try {
        // We need to find all tasks to get the total number of them.
        List<com.netflix.titus.api.jobmanager.model.job.Task> allFilteredTasks = new ArrayList<>();
        for (Pair<com.netflix.titus.api.jobmanager.model.job.Job<?>, com.netflix.titus.api.jobmanager.model.job.Task> jobTaskPair : jobOperations.findTasks(new V3TaskQueryCriteriaEvaluator(toJobQueryCriteria(taskQuery), titusRuntime), 0, Integer.MAX_VALUE / 2)) {
            com.netflix.titus.api.jobmanager.model.job.Task right = jobTaskPair.getRight();
            allFilteredTasks.add(right);
        }
        Pair<List<com.netflix.titus.api.jobmanager.model.job.Task>, Pagination> queryResult = PaginationUtil.takePageWithCursorAndKeyExtractor(toPage(taskQuery.getPage()), allFilteredTasks, JobComparators::createTaskKeyOf, JobManagerCursors::coreTaskIndexOf, JobManagerCursors::newTaskCoreCursorFrom);
        List<Task> grpcTasks = new ArrayList<>();
        for (com.netflix.titus.api.jobmanager.model.job.Task task : queryResult.getLeft()) {
            Task toGrpcTask = grpcObjectsCache.getTask(task);
            grpcTasks.add(toGrpcTask);
        }
        TaskQueryResult grpcQueryResult;
        if (taskQuery.getFieldsList().isEmpty()) {
            grpcQueryResult = toTaskQueryResult(grpcTasks, queryResult.getRight());
        } else {
            Set<String> fields = new HashSet<>(taskQuery.getFieldsList());
            fields.addAll(TASK_MINIMUM_FIELD_SET);
            List<Task> filtered = new ArrayList<>();
            for (Task t : grpcTasks) {
                filtered.add(ProtobufExt.copy(t, fields));
            }
            grpcQueryResult = toTaskQueryResult(filtered, queryResult.getRight());
        }
        responseObserver.onNext(grpcQueryResult);
        responseObserver.onCompleted();
    } catch (Exception e) {
        safeOnError(logger, e, responseObserver);
    }
}
Also used : Task(com.netflix.titus.grpc.protogen.Task) V3TaskQueryCriteriaEvaluator(com.netflix.titus.runtime.endpoint.v3.grpc.query.V3TaskQueryCriteriaEvaluator) ArrayList(java.util.ArrayList) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Pagination(com.netflix.titus.api.model.Pagination) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) JobComparators(com.netflix.titus.runtime.jobmanager.JobComparators) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.grpc.protogen.Job) HashSet(java.util.HashSet) StatusRuntimeException(io.grpc.StatusRuntimeException) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult)

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