use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.
the class ResourceDimensionsTest method testResourceDimensionDivide.
@Test
public void testResourceDimensionDivide() throws Exception {
ResourceDimension large = ResourceDimensionSample.SmallWithGpuAndOpportunisticX2.build();
ResourceDimension small = ResourceDimensionSample.SmallWithGpuAndOpportunistic.build();
Pair<Long, ResourceDimension> result = ResourceDimensions.divide(large, small);
assertThat(result.getLeft()).isEqualTo(2);
assertThat(result.getRight()).isEqualTo(ResourceDimension.empty());
}
use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.
the class ConsumptionModelGenerator method buildApplicationConsumptions.
private List<ResourceConsumption> buildApplicationConsumptions(String capacityGroupName) {
Map<String, ResourceDimension> actual = actualConsumptionByGroupAndApp.get(capacityGroupName);
Map<String, ResourceDimension> max = maxConsumptionByApp.get(capacityGroupName);
List<ResourceConsumption> appConsumptions = new ArrayList<>();
for (String appName : actual.keySet()) {
ResourceConsumption byInstanceType = new ResourceConsumption(appName, ConsumptionLevel.InstanceType, actual.get(appName), max.get(appName), Collections.emptyMap());
appConsumptions.add(new CompositeResourceConsumption(appName, ConsumptionLevel.Application, actual.get(appName), max.get(appName), max.get(appName), Collections.emptyMap(), Collections.singletonMap("itype.test", byInstanceType), !ResourceDimensions.isBigger(max.get(appName), actual.get(appName))));
}
return appConsumptions;
}
use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.
the class ConsumptionModelGenerator method getEvaluation.
DefaultResourceConsumptionService.ConsumptionEvaluationResult getEvaluation() {
Map<String, CompositeResourceConsumption> groupConsumptionMap = new HashMap<>();
Set<String> definedCapacityGroups = new HashSet<>(capacityGroupMap.keySet());
// Used capacity groups
Set<String> capacityGroupNames = actualConsumptionByGroupAndApp.keySet();
for (String capacityGroupName : capacityGroupNames) {
List<ResourceConsumption> appConsumptions = buildApplicationConsumptions(capacityGroupName);
CompositeResourceConsumption groupConsumption = ResourceConsumptions.aggregate(capacityGroupName, ConsumptionLevel.CapacityGroup, appConsumptions, capacityGroupLimit(capacityGroupMap.getOrDefault(capacityGroupName, DEFAULT_SLA)));
groupConsumptionMap.put(capacityGroupName, groupConsumption);
}
// Unused capacity groups
CollectionsExt.copyAndRemove(definedCapacityGroups, capacityGroupNames).forEach(capacityGroup -> {
ApplicationSLA sla = capacityGroupMap.getOrDefault(capacityGroup, DEFAULT_SLA);
ResourceDimension limit = capacityGroupLimit(sla);
groupConsumptionMap.put(capacityGroup, new CompositeResourceConsumption(capacityGroup, ConsumptionLevel.CapacityGroup, ResourceDimension.empty(), ResourceDimension.empty(), limit, Collections.emptyMap(), Collections.emptyMap(), false));
});
// Undefined capacity groups
Set<String> undefinedCapacityGroups = CollectionsExt.copyAndRemove(capacityGroupNames, definedCapacityGroups);
// Tier consumption
Map<Tier, List<CompositeResourceConsumption>> tierCapacityGroups = groupConsumptionMap.values().stream().collect(Collectors.groupingBy(rc -> {
ApplicationSLA sla = capacityGroupMap.get(rc.getConsumerName());
if (sla == null) {
sla = capacityGroupMap.get(DEFAULT_SLA.getAppName());
}
return sla.getTier();
}));
Map<String, CompositeResourceConsumption> tierConsumptions = new HashMap<>();
tierCapacityGroups.forEach((tier, consumptions) -> tierConsumptions.put(tier.name(), ResourceConsumptions.aggregate(tier.name(), ConsumptionLevel.Tier, consumptions)));
// System consumption
CompositeResourceConsumption systemConsumption = ResourceConsumptions.aggregate(ResourceConsumption.SYSTEM_CONSUMER, ConsumptionLevel.System, tierConsumptions.values());
return new DefaultResourceConsumptionService.ConsumptionEvaluationResult(definedCapacityGroups, undefinedCapacityGroups, systemConsumption);
}
Aggregations