Search in sources :

Example 1 with ResourceDimension

use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.

the class JobAssertions method notExceedsComputeResources.

public Map<String, String> notExceedsComputeResources(String capacityGroup, Container container) {
    // As class-level constraints are evaluated after field-level constraints we have to check for null value here.
    if (container == null) {
        return Collections.emptyMap();
    }
    ResourceDimension maxContainerSize = maxContainerSizeResolver.apply(capacityGroup);
    ContainerResources resources = container.getContainerResources();
    Map<String, String> violations = new HashMap<>();
    check(resources::getCpu, maxContainerSize::getCpu).ifPresent(v -> violations.put("container.containerResources.cpu", v));
    check(resources::getGpu, maxContainerSize::getGpu).ifPresent(v -> violations.put("container.containerResources.gpu", v));
    check(resources::getMemoryMB, maxContainerSize::getMemoryMB).ifPresent(v -> violations.put("container.containerResources.memoryMB", v));
    check(resources::getDiskMB, maxContainerSize::getDiskMB).ifPresent(v -> violations.put("container.containerResources.diskMB", v));
    check(resources::getNetworkMbps, maxContainerSize::getNetworkMbs).ifPresent(v -> violations.put("container.containerResources.networkMbps", v));
    return violations;
}
Also used : HashMap(java.util.HashMap) ContainerResources(com.netflix.titus.api.jobmanager.model.job.ContainerResources) ResourceDimension(com.netflix.titus.api.model.ResourceDimension)

Example 2 with ResourceDimension

use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.

the class EmbeddedKubeScheduler method trySchedulePod.

private void trySchedulePod(V1Pod pod) {
    Set<String> zoneConstraints = getZonesOfPod(pod);
    Map<String, EmbeddedKubeNode> nodes = getNodesOf(pod, zoneConstraints);
    ResourceDimension podResources = EmbeddedKubeUtil.fromPodToResourceDimension(pod);
    for (EmbeddedKubeNode node : nodes.values()) {
        ResourceDimension unassignedResources = node.getUnassignedResources();
        if (unassignedResources.equals(podResources) || ResourceDimensions.isBigger(unassignedResources, podResources)) {
            embeddedKubeCluster.assignPodToNode(pod.getMetadata().getName(), node);
            return;
        }
    }
}
Also used : ResourceDimension(com.netflix.titus.api.model.ResourceDimension)

Example 3 with ResourceDimension

use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.

the class ResourceConsumptions method aggregate.

/**
 * Create a parent {@link CompositeResourceConsumption} instance from the provided consumption collection.
 */
public static CompositeResourceConsumption aggregate(String parentName, ResourceConsumption.ConsumptionLevel parentLevel, Collection<? extends ResourceConsumption> consumptions, ResourceDimension allowedUsage) {
    Map<String, ResourceConsumption> contributors = new HashMap<>();
    consumptions.forEach(c -> contributors.put(c.getConsumerName(), c));
    ResourceDimension currentUsage = addCurrentConsumptions(consumptions);
    ResourceDimension maxUsage = addMaxConsumptions(consumptions);
    Map<String, Object> mergedAttrs = mergeAttributesOf(consumptions);
    return new CompositeResourceConsumption(parentName, parentLevel, currentUsage, maxUsage, allowedUsage, mergedAttrs, contributors, !ResourceDimensions.isBigger(allowedUsage, maxUsage));
}
Also used : HashMap(java.util.HashMap) ResourceDimension(com.netflix.titus.api.model.ResourceDimension)

Example 4 with ResourceDimension

use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.

the class ResourceDimensions method add.

/**
 * Returns a new {@link ResourceDimension} instance with resources being some of all the provided.
 */
public static ResourceDimension add(ResourceDimension... parts) {
    if (isNullOrEmpty(parts)) {
        return ResourceDimension.empty();
    }
    double cpuSum = 0;
    long memorySum = 0;
    long diskSum = 0;
    long networkSum = 0;
    long gpuSum = 0;
    long opportunisticCpuSum = 0;
    for (ResourceDimension part : parts) {
        cpuSum += part.getCpu();
        memorySum += part.getMemoryMB();
        diskSum += part.getDiskMB();
        networkSum += part.getNetworkMbs();
        gpuSum += part.getGpu();
        opportunisticCpuSum += part.getOpportunisticCpu();
    }
    return ResourceDimension.newBuilder().withCpus(cpuSum).withMemoryMB(memorySum).withDiskMB(diskSum).withNetworkMbs(networkSum).withGpu(gpuSum).withOpportunisticCpus(opportunisticCpuSum).build();
}
Also used : ResourceDimension(com.netflix.titus.api.model.ResourceDimension)

Example 5 with ResourceDimension

use of com.netflix.titus.api.model.ResourceDimension in project titus-control-plane by Netflix.

the class ResourceDimensionsTest method testResourceDimensionMultiplication.

@Test
public void testResourceDimensionMultiplication() throws Exception {
    ResourceDimension small = ResourceDimensionSample.SmallWithGpuAndOpportunistic.build();
    ResourceDimension expected = ResourceDimensionSample.SmallWithGpuAndOpportunisticX2.build();
    assertThat(ResourceDimensions.multiply(small, 2)).isEqualTo(expected);
}
Also used : ResourceDimension(com.netflix.titus.api.model.ResourceDimension) Test(org.junit.Test)

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