HostCapacity { boolean hasCapacity(Node dockerHost, NodeResources requestedCapacity) { return freeCapacityOf(dockerHost, false).satisfies(requestedCapacity) && freeIPs(dockerHost) > 0; } HostCapacity(NodeList allNodes, HostResourcesCalculator hostResourcesCalculator); NodeList allNodes(); Set<Node> findSpareHosts(List<Node> candidates, int count); NodeResources freeCapacityOf(Node host);  }
@Test public void hasCapacity() { assertTrue(capacity.hasCapacity(host1, resources1)); assertTrue(capacity.hasCapacity(host1, resources2)); assertTrue(capacity.hasCapacity(host2, resources1)); assertTrue(capacity.hasCapacity(host2, resources2)); assertFalse(capacity.hasCapacity(host3, resources1)); assertFalse(capacity.hasCapacity(host3, resources2)); Node nodeF = Node.createDockerNode(Set.of("::6"), "nodeF", "host1", resources1, NodeType.tenant); nodes.add(nodeF); capacity = new HostCapacity(new LockedNodeList(nodes, () -> {}), hostResourcesCalculator); assertFalse(capacity.hasCapacity(host1, resources1)); assertFalse(capacity.hasCapacity(host1, resources2)); }
@Test public void devhostCapacityTest() { var nodeFlavors = FlavorConfigBuilder.createDummies("devhost", "container"); var devHost = Node.create("devhost", new IP.Config(Set.of("::1"), generateIPs(2, 10)), "devhost", Optional.empty(), Optional.empty(), nodeFlavors.getFlavorOrThrow("devhost"), Optional.empty(), NodeType.devhost, Optional.empty()); var cfg = Node.createDockerNode(Set.of("::2"), "cfg", "devhost", resources1, NodeType.config); var nodes = new ArrayList<>(List.of(cfg)); var capacity = new HostCapacity(new LockedNodeList(nodes, () -> {}), hostResourcesCalculator); assertTrue(capacity.hasCapacity(devHost, resources1)); var container1 = Node.createDockerNode(Set.of("::3"), "container1", "devhost", resources1, NodeType.tenant); nodes = new ArrayList<>(List.of(cfg, container1)); capacity = new HostCapacity(new LockedNodeList(nodes, () -> {}), hostResourcesCalculator); assertFalse(capacity.hasCapacity(devHost, resources1)); }