private Optional<HostRemovalFailure> findHostRemovalFailure(List<Node> hostsToRemove, List<Node> allHosts,
                                                                Map<Node, List<Node>> nodechildren,
                                                                Map<Node, AllocationResources> availableResources) {
        var containedAllocations = collateAllocations(nodechildren);
        var resourceMap = new HashMap<>(availableResources);
        List<Node> validAllocationTargets = allHosts.stream()
                                                    .filter(h -> !hostsToRemove.contains(h))
                                                    .filter(host -> !host.status().wantToRetire() &&
                                                            !host.status().wantToFail())
                                                    .toList();
        if (validAllocationTargets.size() == 0)
            return Optional.of(HostRemovalFailure.none());

        allocationHistory = new AllocationHistory();
        for (var host : hostsToRemove) {
            Optional<Node> unallocatedNode = tryAllocateNodes(nodechildren.get(host),
                                                              validAllocationTargets,
                                                              resourceMap,
                                                              containedAllocations,
                                                              true);

            if (unallocatedNode.isPresent()) {
                AllocationFailureReasonList failures = collateAllocationFailures(unallocatedNode.get(),
                                                                                 validAllocationTargets,
                                                                                 resourceMap,
                                                                                 containedAllocations);
                return Optional.of(HostRemovalFailure.create(host, unallocatedNode.get(), failures));
            }
        }
        return Optional.empty();
    }
Tests whether it's possible to remove the provided hosts.
Does not mutate any input variable.

@return empty optional if removal is possible, information on what caused the failure otherwise
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityChecker.java