diff options
author | Harald Musum <musum@verizonmedia.com> | 2019-08-14 20:25:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-14 20:25:52 +0200 |
commit | 4e52564e8d01d3af68d611d9bd88e497bbd08e25 (patch) | |
tree | ef0e2e43d1189ad03565e9d911a991474c0f9f6e /config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java | |
parent | fc6ebf45c0ef126043eb9db4cf613958ce665411 (diff) |
Revert "Bratseth/remove allocation by flavor"
Diffstat (limited to 'config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java')
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java | 96 |
1 files changed, 69 insertions, 27 deletions
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..7e90767c9c5 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; /** @@ -21,6 +22,11 @@ public class NodeResources { private final double diskGb; private final DiskSpeed diskSpeed; + private final boolean allocateByLegacyName; + + /** The legacy (flavor) name of this, or null if none */ + private final String legacyName; + /** Create node resources requiring fast disk */ public NodeResources(double vcpu, double memoryGb, double diskGb) { this(vcpu, memoryGb, diskGb, DiskSpeed.fast); @@ -31,6 +37,18 @@ public class NodeResources { this.memoryGb = memoryGb; this.diskGb = diskGb; this.diskSpeed = diskSpeed; + this.allocateByLegacyName = false; + this.legacyName = null; + } + + private NodeResources(double vcpu, double memoryGb, double diskGb, DiskSpeed diskSpeed, + boolean allocateByLegacyName, String legacyName) { + this.vcpu = vcpu; + this.memoryGb = memoryGb; + this.diskGb = diskGb; + this.diskSpeed = diskSpeed; + this.allocateByLegacyName = allocateByLegacyName; + this.legacyName = legacyName; } public double vcpu() { return vcpu; } @@ -64,17 +82,24 @@ public class NodeResources { combine(this.diskSpeed, other.diskSpeed)); } - // TODO: Remove after August 2019 + /** + * If this is true, a non-docker legacy name was used to specify this and we'll respect that by mapping directly. + * The other getters of this will return 0. + */ + public boolean allocateByLegacyName() { return allocateByLegacyName; } + + /** Returns the legacy name of this, or empty if none. */ public Optional<String> legacyName() { - return Optional.of(toString()); + return Optional.ofNullable(legacyName); } - // TODO: Remove after August 2019 - public boolean allocateByLegacyName() { return false; } - private boolean isInterchangeableWith(NodeResources other) { + if (this.allocateByLegacyName != other.allocateByLegacyName) return false; + if (this.allocateByLegacyName) return legacyName.equals(other.legacyName); + if (this.diskSpeed != DiskSpeed.any && other.diskSpeed != DiskSpeed.any && this.diskSpeed != other.diskSpeed) return false; + return true; } @@ -90,26 +115,40 @@ public class NodeResources { if (o == this) return true; if ( ! (o instanceof NodeResources)) return false; NodeResources other = (NodeResources)o; - if (this.vcpu != other.vcpu) return false; - if (this.memoryGb != other.memoryGb) return false; - if (this.diskGb != other.diskGb) return false; - if (this.diskSpeed != other.diskSpeed) return false; - return true; + if (allocateByLegacyName) { + return this.legacyName.equals(other.legacyName); + } + else { + if (this.vcpu != other.vcpu) return false; + if (this.memoryGb != other.memoryGb) return false; + if (this.diskGb != other.diskGb) 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()); + if (allocateByLegacyName) + return legacyName.hashCode(); + else + return (int)(2503 * vcpu + 22123 * memoryGb + 26987 * diskGb + diskSpeed.hashCode()); } @Override public String toString() { - return "[vcpu: " + vcpu + ", memory: " + memoryGb + " Gb, disk " + diskGb + " Gb" + - (diskSpeed != DiskSpeed.fast ? ", disk speed: " + diskSpeed : "") + "]"; + if (allocateByLegacyName) + return "flavor '" + legacyName + "'"; + else + return "[vcpu: " + vcpu + ", memory: " + memoryGb + " Gb, disk " + diskGb + " Gb" + + (diskSpeed != DiskSpeed.fast ? ", disk speed: " + diskSpeed : "") + "]"; } /** Returns true if all the resources of this are the same or larger than the given resources */ public boolean satisfies(NodeResources other) { + if (this.allocateByLegacyName || other.allocateByLegacyName) // resources are not available + return Objects.equals(this.legacyName, other.legacyName); + if (this.vcpu < other.vcpu) return false; if (this.memoryGb < other.memoryGb) return false; if (this.diskGb < other.diskGb) return false; @@ -124,6 +163,9 @@ public class NodeResources { /** Returns true if all the resources of this are the same as or compatible with the given resources */ public boolean compatibleWith(NodeResources other) { + if (this.allocateByLegacyName || other.allocateByLegacyName) // resources are not available + return Objects.equals(this.legacyName, other.legacyName); + if (this.vcpu != other.vcpu) return false; if (this.memoryGb != other.memoryGb) return false; if (this.diskGb != other.diskGb) return false; @@ -137,20 +179,20 @@ public class NodeResources { * * @throws IllegalArgumentException if the given string cannot be parsed as a serial form of this */ - public static NodeResources fromLegacyName(String name) { - if ( ! name.startsWith("d-")) - throw new IllegalArgumentException("A node specification string must start by 'd-' but was '" + name + "'"); - String[] parts = name.split("-"); - if (parts.length != 4) - throw new IllegalArgumentException("A node specification string must contain three numbers separated by '-' but was '" + name + "'"); - - double cpu = Integer.parseInt(parts[1]); - double mem = Integer.parseInt(parts[2]); - double dsk = Integer.parseInt(parts[3]); - if (cpu == 0) cpu = 0.5; - if (cpu == 2 && mem == 8 ) cpu = 1.5; - if (cpu == 2 && mem == 12 ) cpu = 2.3; - return new NodeResources(cpu, mem, dsk, DiskSpeed.fast); + public static NodeResources fromLegacyName(String flavorString) { + if (flavorString.startsWith("d-")) { // A legacy docker flavor: We still allocate by numbers + String[] parts = flavorString.split("-"); + double cpu = Integer.parseInt(parts[1]); + double mem = Integer.parseInt(parts[2]); + double dsk = Integer.parseInt(parts[3]); + if (cpu == 0) cpu = 0.5; + if (cpu == 2 && mem == 8 ) cpu = 1.5; + if (cpu == 2 && mem == 12 ) cpu = 2.3; + return new NodeResources(cpu, mem, dsk, DiskSpeed.fast, false, flavorString); + } + else { // Another legacy flavor: Allocate by direct matching + return new NodeResources(0, 0, 0, DiskSpeed.fast, true, flavorString); + } } } |