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);
}
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();
}
}
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);
}
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;
}
}
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);
}
}
Aggregations