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