summaryrefslogtreecommitdiffstats
path: root/controller-api/src
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-08-30 11:26:36 +0200
committerMartin Polden <mpolden@mpolden.no>2019-08-30 11:27:39 +0200
commitc2455394cbbb1f62610e2f0e1d4ceeceed456ac3 (patch)
tree807076d2e7d1f160a4e8541024f9a150b12c4692 /controller-api/src
parent0847ebeec917d7d0c99e1c037300c793b41ab6d2 (diff)
Use a single node type in controller
Diffstat (limited to 'controller-api/src')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java10
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java60
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java23
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceSnapshot.java15
4 files changed, 62 insertions, 46 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 e6639a33738..c2d39236b8f 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
@@ -36,6 +36,7 @@ public class Node {
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;
@@ -43,7 +44,7 @@ public class Node {
public Node(HostName hostname, State state, NodeType type, 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, String canonicalFlavor, String clusterId, ClusterType clusterType) {
+ double vcpu, double memoryGb, double diskGb, double bandwidthGbps, boolean fastDisk, int cost, String canonicalFlavor, String clusterId, ClusterType clusterType) {
this.hostname = hostname;
this.state = state;
this.type = type;
@@ -62,6 +63,7 @@ public class Node {
this.diskGb = diskGb;
this.bandwidthGbps = bandwidthGbps;
this.fastDisk = fastDisk;
+ this.cost = cost;
this.canonicalFlavor = canonicalFlavor;
this.clusterId = clusterId;
this.clusterType = clusterType;
@@ -72,7 +74,7 @@ public class Node {
Version currentVersion, Version wantedVersion) {
this(hostname, state, type, owner, currentVersion, wantedVersion,
Version.emptyVersion, Version.emptyVersion, ServiceState.unorchestrated, 0, 0, 0, 0,
- 2, 8, 50, 1, true, "d-2-8-50", "cluster", ClusterType.container);
+ 2, 8, 50, 1, true, 0, "d-2-8-50", "cluster", ClusterType.container);
}
public HostName hostname() {
@@ -145,6 +147,10 @@ public class Node {
return fastDisk;
}
+ public int cost() {
+ return cost;
+ }
+
public String canonicalFlavor() {
return canonicalFlavor;
}
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 fd6b5b48d10..19486b6c2c5 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
@@ -34,30 +34,18 @@ public interface NodeRepository {
NodeList listNodes(ZoneId zone, ApplicationId application);
+ /** List all nodes in given zone */
+ default List<Node> list(ZoneId zone) {
+ return listNodes(zone).nodes().stream()
+ .map(NodeRepository::toNode)
+ .collect(Collectors.toUnmodifiableList());
+ }
+
/** List all nodes in zone owned by given application */
default List<Node> list(ZoneId zone, ApplicationId application) {
return listNodes(zone, application).nodes().stream()
- .map(n -> new Node(com.yahoo.config.provision.HostName.from(n.getHostname()),
- fromJacksonState(n.getState()),
- fromJacksonType(n.getType()), Optional.of(application),
- Version.fromString(n.getVespaVersion()),
- Version.fromString(n.getWantedVespaVersion()),
- Version.fromString(n.getCurrentOsVersion()),
- Version.fromString(n.getWantedOsVersion()),
- fromBoolean(n.getAllowedToBeDown()),
- n.getCurrentRestartGeneration(),
- n.getRestartGeneration(),
- n.getCurrentRebootGeneration(),
- n.getRebootGeneration(),
- n.getMinCpuCores(),
- n.getMinMainMemoryAvailableGb(),
- n.getMinDiskAvailableGb(),
- n.getBandwidth() / 1000,
- n.getFastDisk(),
- n.getCanonicalFlavor(),
- n.getMembership().clusterid,
- clusterTypeOf(n.getMembership().clustertype)))
- .collect(Collectors.toUnmodifiableList());
+ .map(NodeRepository::toNode)
+ .collect(Collectors.toUnmodifiableList());
}
/** List all nodes in states, in zone owned by given application */
@@ -79,9 +67,35 @@ public interface NodeRepository {
/** Cancels firmware checks on all hosts in the given zone. */
void cancelFirmwareCheck(ZoneId zone);
+ private static Node toNode(NodeRepositoryNode node) {
+ var application = Optional.ofNullable(node.getOwner())
+ .map(owner -> ApplicationId.from(owner.getTenant(), owner.getApplication(),
+ owner.getInstance()));
+ return new Node(com.yahoo.config.provision.HostName.from(node.getHostname()),
+ fromJacksonState(node.getState()),
+ fromJacksonType(node.getType()),
+ application,
+ Version.fromString(node.getVespaVersion()),
+ Version.fromString(node.getWantedVespaVersion()),
+ Version.fromString(node.getCurrentOsVersion()),
+ Version.fromString(node.getWantedOsVersion()),
+ fromBoolean(node.getAllowedToBeDown()),
+ node.getCurrentRestartGeneration(),
+ node.getRestartGeneration(),
+ node.getCurrentRebootGeneration(),
+ node.getRebootGeneration(),
+ node.getMinCpuCores(),
+ node.getMinMainMemoryAvailableGb(),
+ node.getMinDiskAvailableGb(),
+ node.getBandwidth() / 1000,
+ node.getFastDisk(),
+ node.getCost() == null ? 0 : node.getCost(),
+ node.getCanonicalFlavor(),
+ node.getMembership().clusterid,
+ clusterTypeOf(node.getMembership().clustertype));
+ }
-
- private Node.ClusterType clusterTypeOf(String type) {
+ private static Node.ClusterType clusterTypeOf(String type) {
switch (type) {
case "admin": return Node.ClusterType.admin;
case "content": return Node.ClusterType.content;
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java
index a6f47e34170..e30d2d55f77 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceAllocation.java
@@ -1,17 +1,15 @@
// 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.resource;
-import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeRepositoryNode;
-
-import java.util.List;
-
/**
- * Stores the total amount of resources allocated to a list of nodes
+ * An allocation of node resources.
*
- * @author leandroalves
+ * @author ldalves
*/
public class ResourceAllocation {
+ public static final ResourceAllocation ZERO = new ResourceAllocation(0, 0, 0);
+
private final double cpuCores;
private final double memoryGb;
private final double diskGb;
@@ -22,14 +20,6 @@ public class ResourceAllocation {
this.diskGb = diskGb;
}
- public static ResourceAllocation from(List<NodeRepositoryNode> nodes) {
- return new ResourceAllocation(
- nodes.stream().mapToDouble(NodeRepositoryNode::getMinCpuCores).sum(),
- nodes.stream().mapToDouble(NodeRepositoryNode::getMinMainMemoryAvailableGb).sum(),
- nodes.stream().mapToDouble(NodeRepositoryNode::getMinDiskAvailableGb).sum()
- );
- }
-
public double usageFraction(ResourceAllocation total) {
return (cpuCores / total.cpuCores + memoryGb / total.memoryGb + diskGb / total.diskGb) / 3;
}
@@ -46,5 +36,10 @@ public class ResourceAllocation {
return diskGb;
}
+ /** Returns a copy of this with the given allocation added */
+ public ResourceAllocation plus(ResourceAllocation allocation) {
+ return new ResourceAllocation(cpuCores + allocation.cpuCores, memoryGb + allocation.memoryGb, diskGb + allocation.diskGb);
+ }
+
}
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 bd4d31e53ae..a378bcb63bd 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,7 +2,7 @@
package com.yahoo.vespa.hosted.controller.api.integration.resource;
import com.yahoo.config.provision.ApplicationId;
-import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeRepositoryNode;
+import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node;
import java.time.Instant;
import java.util.List;
@@ -24,18 +24,19 @@ public class ResourceSnapshot {
this.timestamp = timestamp;
}
- public static ResourceSnapshot from(List<NodeRepositoryNode> nodes, Instant timestamp) {
+ public static ResourceSnapshot from(List<Node> nodes, Instant timestamp) {
Set<ApplicationId> applicationIds = nodes.stream()
- .map(n -> ApplicationId.from(n.getOwner().tenant, n.getOwner().application, n.getOwner().instance))
- .collect(Collectors.toSet());
+ .filter(node -> node.owner().isPresent())
+ .map(node -> node.owner().get())
+ .collect(Collectors.toSet());
if (applicationIds.size() != 1) throw new IllegalArgumentException("List of nodes can only represent one application");
return new ResourceSnapshot(
applicationIds.iterator().next(),
- nodes.stream().mapToDouble(NodeRepositoryNode::getMinCpuCores).sum(),
- nodes.stream().mapToDouble(NodeRepositoryNode::getMinMainMemoryAvailableGb).sum(),
- nodes.stream().mapToDouble(NodeRepositoryNode::getMinDiskAvailableGb).sum(),
+ nodes.stream().mapToDouble(Node::vcpu).sum(),
+ nodes.stream().mapToDouble(Node::memoryGb).sum(),
+ nodes.stream().mapToDouble(Node::diskGb).sum(),
timestamp
);
}