use of com.netflix.titus.master.service.management.ResourceConsumption 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.master.service.management.ResourceConsumption 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);
}
use of com.netflix.titus.master.service.management.ResourceConsumption in project titus-control-plane by Netflix.
the class ResourceConsumptionEvaluatorTest method testEvaluation.
@Test
public void testEvaluation() {
when(applicationSlaManagementService.getApplicationSLAs()).thenReturn(asList(ConsumptionModelGenerator.DEFAULT_SLA, ConsumptionModelGenerator.CRITICAL_SLA_1, ConsumptionModelGenerator.NOT_USED_SLA));
// Job with defined capacity group SLA
Pair<Job, List<Task>> goodCapacity = newServiceJob("goodCapacityJob", jd -> jd.toBuilder().withCapacityGroup(ConsumptionModelGenerator.CRITICAL_SLA_1.getAppName()).build());
Job goodCapacityJob = goodCapacity.getLeft();
// Job without appName defined
Pair<Job, List<Task>> noAppName = newServiceJob("badCapacityJob", jd -> jd.toBuilder().withApplicationName("").withCapacityGroup(ConsumptionModelGenerator.DEFAULT_SLA.getAppName()).build());
Job noAppNameJob = noAppName.getLeft();
// Job with capacity group for which SLA is not defined
Pair<Job, List<Task>> badCapacity = newServiceJob("goodCapacityJob", jd -> jd.toBuilder().withCapacityGroup("missingCapacityGroup").build());
Job badCapacityJob = badCapacity.getLeft();
// Evaluate
ResourceConsumptionEvaluator evaluator = new ResourceConsumptionEvaluator(applicationSlaManagementService, v3JobOperations);
Set<String> undefined = evaluator.getUndefinedCapacityGroups();
assertThat(undefined).contains("missingCapacityGroup");
CompositeResourceConsumption systemConsumption = evaluator.getSystemConsumption();
Map<String, ResourceConsumption> tierConsumptions = systemConsumption.getContributors();
assertThat(tierConsumptions).containsKeys(Tier.Critical.name(), Tier.Flex.name());
// Critical capacity group
CompositeResourceConsumption criticalConsumption = (CompositeResourceConsumption) findConsumption(systemConsumption, Tier.Critical.name(), ConsumptionModelGenerator.CRITICAL_SLA_1.getAppName()).get();
// We have single worker in Started state
assertThat(criticalConsumption.getCurrentConsumption()).isEqualTo(perTaskResourceDimension(goodCapacityJob));
assertThat(criticalConsumption.getAllowedConsumption()).isEqualTo(ConsumptionModelGenerator.capacityGroupLimit(ConsumptionModelGenerator.CRITICAL_SLA_1));
assertThat(criticalConsumption.isAboveLimit()).isTrue();
// Default capacity group
CompositeResourceConsumption defaultConsumption = (CompositeResourceConsumption) findConsumption(systemConsumption, Tier.Flex.name(), ConsumptionModelGenerator.DEFAULT_SLA.getAppName()).get();
assertThat(defaultConsumption.getCurrentConsumption()).isEqualTo(ResourceDimensions.add(perTaskResourceDimension(noAppNameJob), perTaskResourceDimension(badCapacityJob)));
assertThat(defaultConsumption.getAllowedConsumption()).isEqualTo(ConsumptionModelGenerator.capacityGroupLimit(ConsumptionModelGenerator.DEFAULT_SLA));
assertThat(defaultConsumption.isAboveLimit()).isFalse();
// Not used capacity group
CompositeResourceConsumption notUsedConsumption = (CompositeResourceConsumption) findConsumption(systemConsumption, Tier.Critical.name(), ConsumptionModelGenerator.NOT_USED_SLA.getAppName()).get();
assertThat(notUsedConsumption.getCurrentConsumption()).isEqualTo(ResourceDimension.empty());
assertThat(notUsedConsumption.getAllowedConsumption()).isEqualTo(ConsumptionModelGenerator.capacityGroupLimit(ConsumptionModelGenerator.NOT_USED_SLA));
assertThat(notUsedConsumption.isAboveLimit()).isFalse();
}
Aggregations