Search in sources :

Example 16 with ResourceDimension

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());
}
Also used : ResourceDimension(com.netflix.titus.api.model.ResourceDimension) Test(org.junit.Test)

Example 17 with ResourceDimension

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;
}
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 18 with ResourceDimension

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);
}
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)

Aggregations

ResourceDimension (com.netflix.titus.api.model.ResourceDimension)18 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 CompositeResourceConsumption (com.netflix.titus.master.service.management.CompositeResourceConsumption)5 ArrayList (java.util.ArrayList)5 Tier (com.netflix.titus.api.model.Tier)4 ResourceDimensions (com.netflix.titus.master.model.ResourceDimensions)4 ResourceConsumption (com.netflix.titus.master.service.management.ResourceConsumption)4 Collections (java.util.Collections)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ContainerResources (com.netflix.titus.api.jobmanager.model.job.ContainerResources)3 ApplicationSLA (com.netflix.titus.api.model.ApplicationSLA)3 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)3 ConsumptionLevel (com.netflix.titus.master.service.management.ResourceConsumption.ConsumptionLevel)3 ResourceConsumptions (com.netflix.titus.master.service.management.ResourceConsumptions)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3