From c2455394cbbb1f62610e2f0e1d4ceeceed456ac3 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 30 Aug 2019 11:26:36 +0200 Subject: Use a single node type in controller --- .../api/integration/configserver/Node.java | 10 +++- .../integration/configserver/NodeRepository.java | 60 +++++++++++++--------- .../integration/resource/ResourceAllocation.java | 23 ++++----- .../api/integration/resource/ResourceSnapshot.java | 15 +++--- 4 files changed, 62 insertions(+), 46 deletions(-) (limited to 'controller-api') 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 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 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 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 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 nodes, Instant timestamp) { + public static ResourceSnapshot from(List nodes, Instant timestamp) { Set 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 ); } -- cgit v1.2.3