Search in sources :

Example 6 with ResourceConsumption

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;
}
Also used : CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ArrayList(java.util.ArrayList) ResourceDimension(com.netflix.titus.api.model.ResourceDimension)

Example 7 with ResourceConsumption

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);
}
Also used : ResourceConsumptionEvent(com.netflix.titus.master.service.management.ResourceConsumptionEvents.ResourceConsumptionEvent) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Set(java.util.Set) HashMap(java.util.HashMap) Tier(com.netflix.titus.api.model.Tier) ResourceDimensions(com.netflix.titus.master.model.ResourceDimensions) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ApplicationSlaSample(com.netflix.titus.testkit.data.core.ApplicationSlaSample) List(java.util.List) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) Map(java.util.Map) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ConsumptionLevel(com.netflix.titus.master.service.management.ResourceConsumption.ConsumptionLevel) Collections(java.util.Collections) ResourceDimension(com.netflix.titus.api.model.ResourceDimension) ResourceConsumptions(com.netflix.titus.master.service.management.ResourceConsumptions) HashMap(java.util.HashMap) Tier(com.netflix.titus.api.model.Tier) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) ArrayList(java.util.ArrayList) List(java.util.List) ResourceDimension(com.netflix.titus.api.model.ResourceDimension) HashSet(java.util.HashSet)

Example 8 with ResourceConsumption

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();
}
Also used : CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Aggregations

CompositeResourceConsumption (com.netflix.titus.master.service.management.CompositeResourceConsumption)8 ResourceConsumption (com.netflix.titus.master.service.management.ResourceConsumption)8 ResourceDimension (com.netflix.titus.api.model.ResourceDimension)5 List (java.util.List)5 Job (com.netflix.titus.api.jobmanager.model.job.Job)4 Tier (com.netflix.titus.api.model.Tier)4 ResourceDimensions (com.netflix.titus.master.model.ResourceDimensions)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Set (java.util.Set)4 ContainerResources (com.netflix.titus.api.jobmanager.model.job.ContainerResources)3 Task (com.netflix.titus.api.jobmanager.model.job.Task)3 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)3 ApplicationSLA (com.netflix.titus.api.model.ApplicationSLA)3 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)3 Pair (com.netflix.titus.common.util.tuple.Pair)3 ApplicationSlaManagementService (com.netflix.titus.master.service.management.ApplicationSlaManagementService)3 ConsumptionLevel (com.netflix.titus.master.service.management.ResourceConsumption.ConsumptionLevel)3