diff options
author | Harald Musum <musum@yahooinc.com> | 2023-06-22 14:39:30 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-06-22 14:39:30 +0200 |
commit | 432df9cb42bb3f8d4c3d71d49ec2b7bfe0823219 (patch) | |
tree | 5e088dbd6ae0a3199825ec010bd7fc3344f7564f | |
parent | 03dd815c3cbc58f0f3f51af86d331b98d41fff36 (diff) |
Split out some methods
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java index c73f2215774..6bd7917333d 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainer.java @@ -106,11 +106,8 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { attempts++; // Any hosts that are no longer empty should be marked as such, and excluded from removal. - if (currentNodesByParent.getOrDefault(Optional.of(host.hostname()), List.of()) - .stream().anyMatch(n -> ! canDeprovision(n))) { - if (host.hostEmptyAt().isPresent()) { - nodeRepository().nodes().write(host.withHostEmptyAt(null), lock); - } + if (someChildrenCannotBeDeprovisioned(currentNodesByParent, host) && host.hostEmptyAt().isPresent()) { + nodeRepository().nodes().write(host.withHostEmptyAt(null), lock); } // If the host is still empty, we can mark it as empty now, or mark it for removal if it has already expired. else { @@ -275,7 +272,6 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { nodeResources, nodeRepository().clock().instant())) .toList(); - } private static NodeResources toNodeResources(ClusterCapacity clusterCapacity) { @@ -289,9 +285,7 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { // Find all hosts that we once thought were empty (first clause), or whose children are now all removable (second clause). return getHosts(nodesByParent).stream() - .filter(host -> host.hostEmptyAt().isPresent() - || nodesByParent.getOrDefault(Optional.of(host.hostname()), List.of()) - .stream().allMatch(HostCapacityMaintainer::canDeprovision)) + .filter(host -> host.hostEmptyAt().isPresent() || allChildrenCanBeDeprovisioned(nodesByParent, host)) .toList(); } @@ -299,4 +293,16 @@ public class HostCapacityMaintainer extends NodeRepositoryMaintainer { return nodesByParent.get(Optional.<String>empty()); } + private static List<Node> getChildren(Map<Optional<String>, List<Node>> nodesByParent, Node host) { + return nodesByParent.getOrDefault(Optional.of(host.hostname()), List.of()); + } + + private static boolean allChildrenCanBeDeprovisioned(Map<Optional<String>, List<Node>> nodesByParent, Node host) { + return getChildren(nodesByParent, host).stream().allMatch(HostCapacityMaintainer::canDeprovision); + } + + private static boolean someChildrenCannotBeDeprovisioned(Map<Optional<String>, List<Node>> nodesByParent, Node host) { + return ! allChildrenCanBeDeprovisioned(nodesByParent, host); + } + } |