use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.
the class DefaultV3JobOperations method updateTask.
@Override
public Completable updateTask(String taskId, Function<Task, Optional<Task>> changeFunction, Trigger trigger, String reason, CallMetadata callMetadata) {
Optional<ReconciliationEngine<JobManagerReconcilerEvent>> engineOpt = reconciliationFramework.findEngineByChildId(taskId).map(Pair::getLeft);
if (!engineOpt.isPresent()) {
return Completable.error(JobManagerException.taskNotFound(taskId));
}
ReconciliationEngine<JobManagerReconcilerEvent> engine = engineOpt.get();
TitusChangeAction changeAction = BasicTaskActions.updateTaskInRunningModel(taskId, trigger, jobManagerConfiguration, engine, changeFunction, reason, versionSupplier, titusRuntime, callMetadata);
return engine.changeReferenceModel(changeAction, taskId).toCompletable();
}
use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.
the class CellWithFixedJobsService method findJobs.
@Override
public void findJobs(JobQuery request, StreamObserver<JobQueryResult> responseObserver) {
Pair<List<Job>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getJobsList(), JobManagerCursors.jobCursorOrderComparator(), JobManagerCursors::jobIndexOf, JobManagerCursors::newCursorFrom);
Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
if (!fieldsFilter.isEmpty()) {
fieldsFilter.add("id");
page = page.mapLeft(jobs -> jobs.stream().map(job -> ProtobufExt.copy(job, fieldsFilter)).collect(Collectors.toList()));
}
JobQueryResult result = JobQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
responseObserver.onNext(result);
responseObserver.onCompleted();
}
use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.
the class CellWithFixedTasksService method findTasks.
@Override
public void findTasks(TaskQuery request, StreamObserver<TaskQueryResult> responseObserver) {
Pair<List<Task>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getTasksList(), JobManagerCursors.taskCursorOrderComparator(), JobManagerCursors::taskIndexOf, JobManagerCursors::newTaskCursorFrom);
Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
if (!fieldsFilter.isEmpty()) {
fieldsFilter.add("id");
page = page.mapLeft(tasks -> tasks.stream().map(task -> ProtobufExt.copy(task, fieldsFilter)).collect(Collectors.toList()));
}
TaskQueryResult result = TaskQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
responseObserver.onNext(result);
responseObserver.onCompleted();
}
use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.
the class ResourceConsumptionEvaluator method computeAllocationsByCapacityGroupAndAppName.
/**
* @return capacityGroups -> apps -> instanceTypes -> consumption
*/
private Pair<Map<String, Map<String, ResourceConsumption>>, Set<String>> computeAllocationsByCapacityGroupAndAppName() {
Map<String, Map<String, ResourceConsumption>> consumptionMap = new HashMap<>();
Set<String> undefinedCapacityGroups = new HashSet<>();
v3JobOperations.getJobsAndTasks().forEach(jobsAndTasks -> {
Job job = jobsAndTasks.getLeft();
List<Task> tasks = jobsAndTasks.getRight();
List<Task> runningTasks = getRunningWorkers(tasks);
ResourceDimension taskResources = perTaskResourceDimension(job);
String appName = Evaluators.getOrDefault(job.getJobDescriptor().getApplicationName(), DEFAULT_APPLICATION);
ResourceDimension currentConsumption = ResourceDimensions.multiply(taskResources, runningTasks.size());
ResourceDimension maxConsumption = ResourceDimensions.multiply(taskResources, getMaxJobSize(job));
Map<String, List<Task>> tasksByInstanceType = tasks.stream().collect(groupingBy(task -> task.getTaskContext().getOrDefault(TaskAttributes.TASK_ATTRIBUTES_AGENT_ITYPE, "unknown")));
Map<String, ResourceConsumption> consumptionByInstanceType = CollectionsExt.mapValuesWithKeys(tasksByInstanceType, (instanceType, instanceTypeTasks) -> {
List<Task> runningInstanceTypeTasks = getRunningWorkers(instanceTypeTasks);
ResourceDimension instanceTypeConsumption = ResourceDimensions.multiply(taskResources, runningInstanceTypeTasks.size());
return new ResourceConsumption(instanceType, ConsumptionLevel.InstanceType, instanceTypeConsumption, // maxConsumption is not relevant at ConsumptionLevel.InstanceType
instanceTypeConsumption, getWorkerStateMap(instanceTypeTasks));
}, HashMap::new);
ResourceConsumption jobConsumption = new CompositeResourceConsumption(appName, ConsumptionLevel.Application, currentConsumption, maxConsumption, // allowedConsumption is not relevant at ConsumptionLevel.Application
maxConsumption, getWorkerStateMap(tasks), consumptionByInstanceType, // we consider a job is always within its allowed usage since it can't go over its max
false);
String capacityGroup = resolveCapacityGroup(undefinedCapacityGroups, job, appName);
updateConsumptionMap(appName, capacityGroup, jobConsumption, consumptionMap);
});
// Add unused capacity groups
copyAndRemove(definedCapacityGroups, consumptionMap.keySet()).forEach(capacityGroup -> consumptionMap.put(capacityGroup, Collections.emptyMap()));
return Pair.of(consumptionMap, undefinedCapacityGroups);
}
use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.
the class TaskMigrationDescheduler method nextBestMatch.
Optional<Pair<TitusNode, List<Task>>> nextBestMatch() {
return evacuatedAgentsAllocationTracker.getRemovableAgentsById().values().stream().map(i -> Pair.of(i, computeFitness(i))).filter(p -> p.getRight().getLeft() > 0).max(Comparator.comparingDouble(p -> p.getRight().getLeft())).map(p -> {
TitusNode agent = p.getLeft();
List<Task> tasks = p.getRight().getRight();
tasks.forEach(task -> {
evacuatedAgentsAllocationTracker.descheduled(task);
Job<?> job = jobsById.get(task.getJobId());
if (job != null) {
evictionQuotaTracker.consumeQuota(task.getJobId(), isJobExemptFromSystemDisruptionWindow(job));
} else {
logger.warn("Missing job for ID = {}", task.getJobId());
evictionQuotaTracker.consumeQuota(task.getJobId(), false);
}
});
return Pair.of(agent, tasks);
});
}
Aggregations