From 9e71fc626233f0989c34b10b9fc81f1db66cdfd3 Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Mon, 19 Aug 2019 16:36:56 +0200 Subject: Add bandwidth to NodeResources --- .../java/com/yahoo/config/provision/Flavor.java | 6 ++---- .../com/yahoo/config/provision/NodeResources.java | 25 +++++++++++++++++----- .../serialization/AllocatedHostsSerializer.java | 6 ++++++ 3 files changed, 28 insertions(+), 9 deletions(-) (limited to 'config-provisioning/src') diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/Flavor.java b/config-provisioning/src/main/java/com/yahoo/config/provision/Flavor.java index 2bc70efbc15..fd0fe724809 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/Flavor.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/Flavor.java @@ -20,7 +20,6 @@ public class Flavor { private final String name; private final int cost; private final Type type; - private final double bandwidth; /** The hardware resources of this flavor */ private NodeResources resources; @@ -34,8 +33,8 @@ public class Flavor { this.resources = new NodeResources(flavorConfig.minCpuCores(), flavorConfig.minMainMemoryAvailableGb(), flavorConfig.minDiskAvailableGb(), + flavorConfig.bandwidth(), flavorConfig.fastDisk() ? NodeResources.DiskSpeed.fast : NodeResources.DiskSpeed.slow); - this.bandwidth = flavorConfig.bandwidth(); } /** Creates a *node* flavor from a node resources spec */ @@ -45,7 +44,6 @@ public class Flavor { this.name = resources.toString(); this.cost = 0; this.type = Type.DOCKER_CONTAINER; - this.bandwidth = 1; this.resources = resources; } @@ -74,7 +72,7 @@ public class Flavor { public boolean hasFastDisk() { return resources.diskSpeed() == NodeResources.DiskSpeed.fast; } - public double getBandwidth() { return bandwidth; } + public double getBandwidth() { return resources.bandwidthMbps(); } public double getMinCpuCores() { return resources.vcpu(); } diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java index 8ef48f7048f..3a945a95812 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java @@ -1,6 +1,7 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.provision; +import java.util.Objects; import java.util.Optional; /** @@ -19,31 +20,39 @@ public class NodeResources { private final double vcpu; private final double memoryGb; private final double diskGb; + private final double bandwidthMbps; private final DiskSpeed diskSpeed; - /** Create node resources requiring fast disk */ + /** Create node resources requiring fast disk and no bandwidth */ public NodeResources(double vcpu, double memoryGb, double diskGb) { - this(vcpu, memoryGb, diskGb, DiskSpeed.fast); + this(vcpu, memoryGb, diskGb, 0, DiskSpeed.fast); } + /** Create node resources requiring no bandwidth */ public NodeResources(double vcpu, double memoryGb, double diskGb, DiskSpeed diskSpeed) { + this(vcpu, memoryGb, diskGb, 0, diskSpeed); + } + + public NodeResources(double vcpu, double memoryGb, double diskGb, double bandwidthMbps, DiskSpeed diskSpeed) { this.vcpu = vcpu; this.memoryGb = memoryGb; this.diskGb = diskGb; + this.bandwidthMbps = bandwidthMbps; this.diskSpeed = diskSpeed; } public double vcpu() { return vcpu; } public double memoryGb() { return memoryGb; } public double diskGb() { return diskGb; } + public double bandwidthMbps() { return bandwidthMbps; } public DiskSpeed diskSpeed() { return diskSpeed; } public NodeResources withDiskSpeed(DiskSpeed speed) { - return new NodeResources(vcpu, memoryGb, diskGb, speed); + return new NodeResources(vcpu, memoryGb, diskGb, bandwidthMbps, speed); } public NodeResources withVcpu(double vcpu) { - return new NodeResources(vcpu, memoryGb, diskGb, diskSpeed); + return new NodeResources(vcpu, memoryGb, diskGb, bandwidthMbps, diskSpeed); } public NodeResources subtract(NodeResources other) { @@ -52,6 +61,7 @@ public class NodeResources { return new NodeResources(vcpu - other.vcpu, memoryGb - other.memoryGb, diskGb - other.diskGb, + bandwidthMbps - other.bandwidthMbps, combine(this.diskSpeed, other.diskSpeed)); } @@ -61,6 +71,7 @@ public class NodeResources { return new NodeResources(vcpu + other.vcpu, memoryGb + other.memoryGb, diskGb + other.diskGb, + bandwidthMbps + other.bandwidthMbps, combine(this.diskSpeed, other.diskSpeed)); } @@ -93,18 +104,20 @@ public class NodeResources { if (this.vcpu != other.vcpu) return false; if (this.memoryGb != other.memoryGb) return false; if (this.diskGb != other.diskGb) return false; + if (this.bandwidthMbps != other.bandwidthMbps) return false; if (this.diskSpeed != other.diskSpeed) return false; return true; } @Override public int hashCode() { - return (int)(2503 * vcpu + 22123 * memoryGb + 26987 * diskGb + diskSpeed.hashCode()); + return Objects.hash(vcpu, memoryGb, diskGb, bandwidthMbps, diskSpeed); } @Override public String toString() { return "[vcpu: " + vcpu + ", memory: " + memoryGb + " Gb, disk " + diskGb + " Gb" + + (bandwidthMbps > 0 ? ", bandwidth: " + bandwidthMbps + " Mbps" : "") + (diskSpeed != DiskSpeed.fast ? ", disk speed: " + diskSpeed : "") + "]"; } @@ -113,6 +126,7 @@ public class NodeResources { if (this.vcpu < other.vcpu) return false; if (this.memoryGb < other.memoryGb) return false; if (this.diskGb < other.diskGb) return false; + if (this.bandwidthMbps < other.bandwidthMbps) return false; // Why doesn't a fast disk satisfy a slow disk? Because if slow disk is explicitly specified // (i.e not "any"), you should not randomly, sometimes get a faster disk as that means you may @@ -127,6 +141,7 @@ public class NodeResources { if (this.vcpu != other.vcpu) return false; if (this.memoryGb != other.memoryGb) return false; if (this.diskGb != other.diskGb) return false; + if (this.bandwidthMbps != other.bandwidthMbps) return false; if (other.diskSpeed != DiskSpeed.any && other.diskSpeed != this.diskSpeed) return false; return true; diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/serialization/AllocatedHostsSerializer.java b/config-provisioning/src/main/java/com/yahoo/config/provision/serialization/AllocatedHostsSerializer.java index 9fcee6b60ed..db5f0ca94ed 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/serialization/AllocatedHostsSerializer.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/serialization/AllocatedHostsSerializer.java @@ -52,6 +52,7 @@ public class AllocatedHostsSerializer { private static final String vcpuKey = "vcpu"; private static final String memoryKey = "memory"; private static final String diskKey = "disk"; + private static final String bandwidthKey = "bandwidth"; private static final String diskSpeedKey = "diskSpeed"; /** Wanted version */ @@ -143,9 +144,14 @@ public class AllocatedHostsSerializer { } else if (object.field(resourcesKey).valid()) { Inspector resources = object.field(resourcesKey); + double bandwidth = Optional.of(resources.field(bandwidthKey)) + .filter(Inspector::valid) + .map(Inspector::asDouble) + .orElse(0d); return Optional.of(new Flavor(new NodeResources(resources.field(vcpuKey).asDouble(), resources.field(memoryKey).asDouble(), resources.field(diskKey).asDouble(), + bandwidth, diskSpeedFromSlime(resources.field(diskSpeedKey))))); } else { -- cgit v1.2.3