use of com.netflix.titus.master.service.management.ApplicationSlaManagementService.DEFAULT_APPLICATION 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);
}
Aggregations