diff options
Diffstat (limited to 'node-repository')
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java (renamed from node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeList.java) | 40 | ||||
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java | 34 | ||||
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirer.java | 2 | ||||
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java | 4 | ||||
-rw-r--r-- | node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirerTest.java | 9 |
5 files changed, 56 insertions, 33 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeList.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java index b80583c5a28..29f3786481c 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeList.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java @@ -2,15 +2,22 @@ package com.yahoo.vespa.hosted.provision; import com.google.common.collect.ImmutableList; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.config.provision.NodeType; +import java.util.Collection; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; +import static java.util.stream.Collectors.collectingAndThen; + /** * A filterable node list * * @author bratseth + * @author mpolden */ public class NodeList { @@ -45,6 +52,39 @@ public class NodeList { return new NodeList(nodes.stream().filter(node -> node.allocation().get().membership().cluster().type().equals(type)).collect(Collectors.toList())); } + /** Returns the subset of nodes owned by the given application */ + public NodeList owner(ApplicationId application) { + return nodes.stream() + .filter(node -> node.allocation().map(a -> a.owner().equals(application)).orElse(false)) + .collect(collectingAndThen(Collectors.toList(), NodeList::new)); + } + + /** Returns the subset of nodes matching the given node type */ + public NodeList nodeType(NodeType nodeType) { + return nodes.stream() + .filter(node -> node.type() == nodeType) + .collect(collectingAndThen(Collectors.toList(), NodeList::new)); + } + + /** Returns the parent nodes of the given child nodes */ + public NodeList parentNodes(Collection<Node> childNodes) { + return childNodes.stream() + .map(Node::parentHostname) + .filter(Optional::isPresent) + .map(Optional::get) + .map(hostName -> nodes.stream().filter(node -> node.hostname().equals(hostName)).findFirst()) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(collectingAndThen(Collectors.toList(), NodeList::new)); + } + + /** Returns the child nodes of the given parent node */ + public NodeList childNodes(Node parentNode) { + return nodes.stream() + .filter(n -> n.parentHostname().map(hostName -> hostName.equals(parentNode.hostname())).orElse(false)) + .collect(collectingAndThen(Collectors.toList(), NodeList::new)); + } + public int size() { return nodes.size(); } /** Returns the immutable list of nodes in this */ diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java index 8d850d60cd8..839b60ca612 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeRepository.java @@ -150,13 +150,13 @@ public class NodeRepository extends AbstractComponent { /** * Returns a set of nodes that should be trusted by the given node. */ - private Set<Node> getTrustedNodes(Node node) { - final Set<Node> trustedNodes = new TreeSet<>(Comparator.comparing(Node::hostname)); + private Set<Node> getTrustedNodes(Node node, NodeList candidates) { + Set<Node> trustedNodes = new TreeSet<>(Comparator.comparing(Node::hostname)); // For all cases below, trust: // - nodes in same application // - config servers - node.allocation().ifPresent(allocation -> trustedNodes.addAll(getNodes(allocation.owner()))); + node.allocation().ifPresent(allocation -> trustedNodes.addAll(candidates.owner(allocation.owner()).asList())); trustedNodes.addAll(getConfigNodes()); switch (node.type()) { @@ -165,20 +165,20 @@ public class NodeRepository extends AbstractComponent { // - proxy nodes // - parent (Docker) hosts of already trusted nodes. This is needed in a transition period, while // we migrate away from IPv4-only nodes - trustedNodes.addAll(getDockerHosts(trustedNodes)); // TODO: Remove when we no longer have IPv4-only nodes - trustedNodes.addAll(getNodes(NodeType.proxy)); + trustedNodes.addAll(candidates.parentNodes(trustedNodes).asList()); // TODO: Remove when we no longer have IPv4-only nodes + trustedNodes.addAll(candidates.nodeType(NodeType.proxy).asList()); if (node.state() == Node.State.ready) { // Tenant nodes in state ready, trust: // - All tenant nodes in zone. When a ready node is allocated to a an application there's a brief // window where current ACLs have not yet been applied on the node. To avoid service disruption // during this window, ready tenant nodes trust all other tenant nodes. - trustedNodes.addAll(getNodes(NodeType.tenant)); + trustedNodes.addAll(candidates.nodeType(NodeType.tenant).asList()); } break; case config: // Config servers trust all nodes - trustedNodes.addAll(getNodes()); + trustedNodes.addAll(candidates.asList()); break; case proxy: @@ -203,13 +203,14 @@ public class NodeRepository extends AbstractComponent { * @return List of node ACLs */ public List<NodeAcl> getNodeAcls(Node node, boolean children) { - final List<NodeAcl> nodeAcls = new ArrayList<>(); + List<NodeAcl> nodeAcls = new ArrayList<>(); + NodeList candidates = new NodeList(getNodes()); if (children) { - final List<Node> childNodes = getChildNodes(node.hostname()); - childNodes.forEach(childNode -> nodeAcls.add(new NodeAcl(childNode, getTrustedNodes(childNode)))); + List<Node> childNodes = candidates.childNodes(node).asList(); + childNodes.forEach(childNode -> nodeAcls.add(new NodeAcl(childNode, getTrustedNodes(childNode, candidates)))); } else { - nodeAcls.add(new NodeAcl(node, getTrustedNodes(node))); + nodeAcls.add(new NodeAcl(node, getTrustedNodes(node, candidates))); } return Collections.unmodifiableList(nodeAcls); @@ -513,17 +514,6 @@ public class NodeRepository extends AbstractComponent { .collect(Collectors.toList()); } - private List<Node> getDockerHosts(Set<Node> nodes) { - return nodes.stream() - .map(Node::parentHostname) - .filter(Optional::isPresent) - .map(Optional::get) - .map(hostName -> getNode(hostName)) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); - } - /** Returns the time keeper of this system */ public Clock clock() { return clock; } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirer.java index 2a7121b3e7a..79c0eff874a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirer.java @@ -56,7 +56,7 @@ public class FailedExpirer extends Expirer { } private boolean failCountIndicatesHwFail(Zone zone) { - if (zone.system() == SystemName.cd || zone.system() == SystemName.ci) { + if (zone.system() == SystemName.cd) { return false; } return zone.environment() == Environment.prod || zone.environment() == Environment.staging; diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java index 37fa903380d..f86a6923dba 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java @@ -82,6 +82,7 @@ public class NodeRepositoryProvisioner implements Provisioner { ", downscaling to " + nodeCount + " nodes in " + zone.environment()); Optional<String> defaultFlavorOverride = nodeRepository.getDefaultFlavorOverride(application); Flavor flavor = capacityPolicies.decideFlavor(requestedCapacity, cluster, defaultFlavorOverride); + log.log(LogLevel.DEBUG, () -> "Decided flavor for requested tenant nodes: " + flavor); effectiveGroups = wantedGroups > nodeCount ? nodeCount : wantedGroups; // cannot have more groups than nodes requestedNodes = NodeSpec.from(nodeCount, flavor); } @@ -109,9 +110,10 @@ public class NodeRepositoryProvisioner implements Provisioner { } private List<HostSpec> asSortedHosts(List<Node> nodes) { - nodes.sort(Comparator.comparingInt((Node node) -> node.allocation().get().membership().index())); + nodes.sort(Comparator.comparingInt(node -> node.allocation().get().membership().index())); List<HostSpec> hosts = new ArrayList<>(nodes.size()); for (Node node : nodes) { + log.log(LogLevel.DEBUG, () -> "Prepared node " + node.hostname() + " - " + node.flavor()); hosts.add(new HostSpec(node.hostname(), node.allocation().orElseThrow(IllegalStateException::new).membership(), node.flavor())); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirerTest.java index e73ca518beb..b5a9f688b87 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirerTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/FailedExpirerTest.java @@ -60,15 +60,6 @@ public class FailedExpirerTest { } @Test - public void ensure_failed_nodes_are_deallocated_in_ci() throws InterruptedException { - NodeRepository nodeRepository = failureScenarioIn(SystemName.ci, Environment.prod); - - assertEquals(1, nodeRepository.getNodes(NodeType.tenant, Node.State.failed).size()); - assertEquals(2, nodeRepository.getNodes(NodeType.tenant, Node.State.dirty).size()); - assertEquals("node2", nodeRepository.getNodes(NodeType.tenant, Node.State.failed).get(0).hostname()); - } - - @Test public void ensure_failed_nodes_are_deallocated_in_cd() throws InterruptedException { NodeRepository nodeRepository = failureScenarioIn(SystemName.cd, Environment.prod); |