CapacityChecker { protected List<Node> findOvercommittedHosts() { List<Node> overcommittedNodes = new ArrayList<>(); for (var entry : availableResources.entrySet()) { var resources = entry.getValue().nodeResources; if (resources.vcpu() < 0 || resources.memoryGb() < 0 || resources.diskGb() < 0) { overcommittedNodes.add(entry.getKey()); } } return overcommittedNodes; } CapacityChecker(NodeList allNodes); List<Node> getHosts(); Optional<HostFailurePath> worstCaseHostLossLeadingToFailure(); List<Node> nodesFromHostnames(List<String> hostnames); Optional<HostFailurePath> findHostRemovalFailure(List<Node> hostsToRemove); public AllocationHistory allocationHistory; }
@Test public void testOvercommittedHosts() { CapacityCheckerTester tester = new CapacityCheckerTester(); tester.createNodes(7, 4, 10, new NodeResources(-1, 10, 100, 1), 10, 0, new NodeResources(1, 10, 100, 1), 10); int overcommittedHosts = tester.capacityChecker.findOvercommittedHosts().size(); assertEquals(tester.nodeRepository.getNodes(NodeType.host).size(), overcommittedHosts); }