diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-11-24 14:07:25 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-11-25 13:16:48 +0100 |
commit | 3b2a0d112250e0b41421b3c2bee0ac32bdbd8e3e (patch) | |
tree | f77da9ea7b16dbe8004cffe25009266d32e03916 /controller-api | |
parent | a31a20d27a02c7fb80307f6e53b5c98784d893c5 (diff) |
Use NodeResources in Node
Diffstat (limited to 'controller-api')
5 files changed, 160 insertions, 133 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java index cff7d9551a1..e7ca5c9b7f8 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.configserver; import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.NodeType; import java.util.Objects; @@ -21,6 +22,7 @@ public class Node { private final Optional<HostName> parentHostname; private final State state; private final NodeType type; + private final NodeResources resources; private final Optional<ApplicationId> owner; private final Version currentVersion; private final Version wantedVersion; @@ -31,24 +33,20 @@ public class Node { private final long wantedRestartGeneration; private final long rebootGeneration; private final long wantedRebootGeneration; - private final double vcpu; - private final double memoryGb; - private final double diskGb; - private final double bandwidthGbps; - private final boolean fastDisk; private final int cost; private final String canonicalFlavor; private final String clusterId; private final ClusterType clusterType; - public Node(HostName hostname, Optional<HostName> parentHostname, State state, NodeType type, Optional<ApplicationId> owner, + public Node(HostName hostname, Optional<HostName> parentHostname, State state, NodeType type, NodeResources resources, Optional<ApplicationId> owner, Version currentVersion, Version wantedVersion, Version currentOsVersion, Version wantedOsVersion, ServiceState serviceState, long restartGeneration, long wantedRestartGeneration, long rebootGeneration, long wantedRebootGeneration, - double vcpu, double memoryGb, double diskGb, double bandwidthGbps, boolean fastDisk, int cost, String canonicalFlavor, String clusterId, ClusterType clusterType) { + int cost, String canonicalFlavor, String clusterId, ClusterType clusterType) { this.hostname = hostname; this.parentHostname = parentHostname; this.state = state; this.type = type; + this.resources = resources; this.owner = owner; this.currentVersion = currentVersion; this.wantedVersion = wantedVersion; @@ -59,12 +57,6 @@ public class Node { this.wantedRestartGeneration = wantedRestartGeneration; this.rebootGeneration = rebootGeneration; this.wantedRebootGeneration = wantedRebootGeneration; - this.vcpu = vcpu; - this.memoryGb = memoryGb; - this.diskGb = diskGb; - this.bandwidthGbps = bandwidthGbps; - this.fastDisk = fastDisk; - this.remoteStorage = remoteStorage; this.cost = cost; this.canonicalFlavor = canonicalFlavor; this.clusterId = clusterId; @@ -85,6 +77,10 @@ public class Node { return type; } + public NodeResources resources() { + return resources; + } + public Optional<ApplicationId> owner() { return owner; } @@ -125,26 +121,6 @@ public class Node { return wantedRebootGeneration; } - public double vcpu() { - return vcpu; - } - - public double memoryGb() { - return memoryGb; - } - - public double diskGb() { - return diskGb; - } - - public double bandwidthGbps() { - return bandwidthGbps; - } - - public boolean fastDisk() { - return fastDisk; - } - public int cost() { return cost; } @@ -207,6 +183,7 @@ public class Node { private Optional<HostName> parentHostname = Optional.empty(); private State state; private NodeType type; + private NodeResources resources; private Optional<ApplicationId> owner = Optional.empty(); private Version currentVersion; private Version wantedVersion; @@ -217,11 +194,6 @@ public class Node { private long wantedRestartGeneration; private long rebootGeneration; private long wantedRebootGeneration; - private double vcpu; - private double memoryGb; - private double diskGb; - private double bandwidthGbps; - private boolean fastDisk; private int cost; private String canonicalFlavor; private String clusterId; @@ -234,6 +206,7 @@ public class Node { this.parentHostname = node.parentHostname; this.state = node.state; this.type = node.type; + this.resources = node.resources; this.owner = node.owner; this.currentVersion = node.currentVersion; this.wantedVersion = node.wantedVersion; @@ -244,11 +217,6 @@ public class Node { this.wantedRestartGeneration = node.wantedRestartGeneration; this.rebootGeneration = node.rebootGeneration; this.wantedRebootGeneration = node.wantedRebootGeneration; - this.vcpu = node.vcpu; - this.memoryGb = node.memoryGb; - this.diskGb = node.diskGb; - this.bandwidthGbps = node.bandwidthGbps; - this.fastDisk = node.fastDisk; this.cost = node.cost; this.canonicalFlavor = node.canonicalFlavor; this.clusterId = node.clusterId; @@ -275,6 +243,11 @@ public class Node { return this; } + public Builder resources(NodeResources resources) { + this.resources = resources; + return this; + } + public Builder owner(ApplicationId owner) { this.owner = Optional.ofNullable(owner); return this; @@ -325,31 +298,6 @@ public class Node { return this; } - public Builder vcpu(double vcpu) { - this.vcpu = vcpu; - return this; - } - - public Builder memoryGb(double memoryGb) { - this.memoryGb = memoryGb; - return this; - } - - public Builder diskGb(double diskGb) { - this.diskGb = diskGb; - return this; - } - - public Builder bandwidthGbps(double bandwidthGbps) { - this.bandwidthGbps = bandwidthGbps; - return this; - } - - public Builder fastDisk(boolean fastDisk) { - this.fastDisk = fastDisk; - return this; - } - public Builder cost(int cost) { this.cost = cost; return this; @@ -371,9 +319,9 @@ public class Node { } public Node build() { - return new Node(hostname, parentHostname, state, type, owner, currentVersion, wantedVersion, currentOsVersion, + return new Node(hostname, parentHostname, state, type, resources, owner, currentVersion, wantedVersion, currentOsVersion, wantedOsVersion, serviceState, restartGeneration, wantedRestartGeneration, rebootGeneration, wantedRebootGeneration, - vcpu, memoryGb, diskGb, bandwidthGbps, fastDisk, cost, canonicalFlavor, clusterId, clusterType); + cost, canonicalFlavor, clusterId, clusterType); } } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java index 2dcbf4ca930..52d2ab2f242 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.configserver; import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.NodeType; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeList; @@ -77,10 +78,18 @@ public interface NodeRepository { .map(owner -> ApplicationId.from(owner.getTenant(), owner.getApplication(), owner.getInstance())); var parentHostname = Optional.ofNullable(node.getParentHostname()).map(HostName::from); + var resources = new NodeResources( + toDouble(node.getResources().getVcpu()), + toDouble(node.getResources().getMemoryGb()), + toDouble(node.getResources().getDiskGb()), + toDouble(node.getResources().getBandwidthGbps()), + diskSpeedFromString(node.getResources().getDiskSpeed()), + storageTypeFromString(node.getResources().getStorageType())); return new Node(HostName.from(node.getHostname()), parentHostname, fromJacksonState(node.getState()), fromJacksonType(node.getType()), + resources, application, versionFrom(node.getVespaVersion()), versionFrom(node.getWantedVespaVersion()), @@ -91,11 +100,6 @@ public interface NodeRepository { toInt(node.getRestartGeneration()), toInt(node.getCurrentRebootGeneration()), toInt(node.getRebootGeneration()), - toDouble(node.getMinCpuCores()), - toDouble(node.getMinMainMemoryAvailableGb()), - toDouble(node.getMinDiskAvailableGb()), - toDouble(node.getBandwidthGbps()), - toBoolean(node.getFastDisk()), toInt(node.getCost()), node.getCanonicalFlavor(), clusterIdOf(node.getMembership()), @@ -143,6 +147,26 @@ public interface NodeRepository { return Node.State.unknown; } + private static NodeResources.DiskSpeed diskSpeedFromString(String diskSpeed) { + if (diskSpeed == null) return NodeResources.DiskSpeed.getDefault(); + switch (diskSpeed) { + case "fast": return NodeResources.DiskSpeed.fast; + case "slow": return NodeResources.DiskSpeed.slow; + case "any": return NodeResources.DiskSpeed.any; + default: throw new IllegalArgumentException("Unknown disk speed '" + diskSpeed + "'"); + } + } + + private static NodeResources.StorageType storageTypeFromString(String storageType) { + if (storageType == null) return NodeResources.StorageType.getDefault(); + switch (storageType) { + case "remote": return NodeResources.StorageType.remote; + case "local": return NodeResources.StorageType.local; + case "any": return NodeResources.StorageType.any; + default: throw new IllegalArgumentException("Unknown storage type '" + storageType + "'"); + } + } + private static Node.ServiceState fromBoolean(Boolean allowedDown) { return (allowedDown == null) ? Node.ServiceState.unorchestrated diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryNode.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryNode.java index 227f35498ce..33079122862 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryNode.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryNode.java @@ -32,6 +32,10 @@ public class NodeRepositoryNode { private String flavor; @JsonProperty("canonicalFlavor") private String canonicalFlavor; + @JsonProperty("resources") + private NodeResources resources; + @JsonProperty("requestedResources") + private NodeResources requestedResources; @JsonProperty("membership") private NodeMembership membership; @JsonProperty("owner") @@ -68,18 +72,8 @@ public class NodeRepositoryNode { private Boolean wantToRetire; @JsonProperty("wantToDeprovision") private Boolean wantToDeprovision; - @JsonProperty("minDiskAvailableGb") - private Double minDiskAvailableGb; - @JsonProperty("minMainMemoryAvailableGb") - private Double minMainMemoryAvailableGb; @JsonProperty("cost") private Integer cost; - @JsonProperty("minCpuCores") - private Double minCpuCores; - @JsonProperty("bandwidthGbps") - private Double bandwidthGbps; - @JsonProperty("fastDisk") - private Boolean fastDisk; @JsonProperty("description") private String description; @JsonProperty("history") @@ -163,6 +157,22 @@ public class NodeRepositoryNode { this.canonicalFlavor = canonicalFlavor; } + public NodeResources getResources() { + return resources; + } + + public void setResources(NodeResources resources) { + this.resources = resources; + } + + public NodeResources getRequestedResources() { + return requestedResources; + } + + public void setRequestedResources(NodeResources requestedResources) { + this.requestedResources = requestedResources; + } + public NodeMembership getMembership() { return membership; } @@ -289,22 +299,6 @@ public class NodeRepositoryNode { this.wantToDeprovision = wantToDeprovision; } - public Double getMinDiskAvailableGb() { - return minDiskAvailableGb; - } - - public void setMinDiskAvailableGb(Double minDiskAvailableGb) { - this.minDiskAvailableGb = minDiskAvailableGb; - } - - public Double getMinMainMemoryAvailableGb() { - return minMainMemoryAvailableGb; - } - - public void setMinMainMemoryAvailableGb(Double minMainMemoryAvailableGb) { - this.minMainMemoryAvailableGb = minMainMemoryAvailableGb; - } - public Integer getCost() { return cost; } @@ -313,30 +307,6 @@ public class NodeRepositoryNode { this.cost = cost; } - public Double getMinCpuCores() { - return minCpuCores; - } - - public void setMinCpuCores(Double minCpuCores) { - this.minCpuCores = minCpuCores; - } - - public Double getBandwidthGbps() { - return bandwidthGbps; - } - - public void setBandwidthGbps(Double bandwidthGbps) { - this.bandwidthGbps = bandwidthGbps; - } - - public Boolean getFastDisk() { - return fastDisk; - } - - public void setFastDisk(Boolean fastDisk) { - this.fastDisk = fastDisk; - } - public String getDescription() { return description; } @@ -401,6 +371,8 @@ public class NodeRepositoryNode { ", openStackId='" + openStackId + '\'' + ", flavor='" + flavor + '\'' + ", canonicalFlavor='" + canonicalFlavor + '\'' + + ", resources=" + resources + + ", requestedResources=" + requestedResources + ", membership=" + membership + ", owner=" + owner + ", restartGeneration=" + restartGeneration + @@ -419,12 +391,7 @@ public class NodeRepositoryNode { ", parentHostname='" + parentHostname + '\'' + ", wantToRetire=" + wantToRetire + ", wantToDeprovision=" + wantToDeprovision + - ", minDiskAvailableGb=" + minDiskAvailableGb + - ", minMainMemoryAvailableGb=" + minMainMemoryAvailableGb + ", cost=" + cost + - ", minCpuCores=" + minCpuCores + - ", bandwidthGbps=" + bandwidthGbps + - ", fastDisk=" + fastDisk + ", description='" + description + '\'' + ", history=" + Arrays.toString(history) + ", allowedToBeDown=" + allowedToBeDown + diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeResources.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeResources.java new file mode 100644 index 00000000000..ded61c7a94e --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeResources.java @@ -0,0 +1,87 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.noderepository; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author freva + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class NodeResources { + + @JsonProperty + private Double vcpu; + @JsonProperty + private Double memoryGb; + @JsonProperty + private Double diskGb; + @JsonProperty + private Double bandwidthGbps; + @JsonProperty + private String diskSpeed; + @JsonProperty + private String storageType; + + public Double getVcpu() { + return vcpu; + } + + public void setVcpu(Double vcpu) { + this.vcpu = vcpu; + } + + public Double getMemoryGb() { + return memoryGb; + } + + public void setMemoryGb(Double memoryGb) { + this.memoryGb = memoryGb; + } + + public Double getDiskGb() { + return diskGb; + } + + public void setDiskGb(Double diskGb) { + this.diskGb = diskGb; + } + + public Double getBandwidthGbps() { + return bandwidthGbps; + } + + public void setBandwidthGbps(Double bandwidthGbps) { + this.bandwidthGbps = bandwidthGbps; + } + + public String getDiskSpeed() { + return diskSpeed; + } + + public void setDiskSpeed(String diskSpeed) { + this.diskSpeed = diskSpeed; + } + + public String getStorageType() { + return storageType; + } + + public void setStorageType(String storageType) { + this.storageType = storageType; + } + + @Override + public String toString() { + return "NodeResources{" + + "vcpu=" + vcpu + + ", memoryGb=" + memoryGb + + ", diskGb=" + diskGb + + ", bandwidthGbps=" + bandwidthGbps + + ", diskSpeed='" + diskSpeed + '\'' + + ", storageType='" + storageType + '\'' + + '}'; + } +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java index 5ee6df9f034..cfe0f18260a 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node; @@ -37,9 +38,9 @@ public class ResourceSnapshot { return new ResourceSnapshot( applicationIds.iterator().next(), - nodes.stream().mapToDouble(Node::vcpu).sum(), - nodes.stream().mapToDouble(Node::memoryGb).sum(), - nodes.stream().mapToDouble(Node::diskGb).sum(), + nodes.stream().map(Node::resources).mapToDouble(NodeResources::vcpu).sum(), + nodes.stream().map(Node::resources).mapToDouble(NodeResources::memoryGb).sum(), + nodes.stream().map(Node::resources).mapToDouble(NodeResources::diskGb).sum(), timestamp, zoneId ); |