ClusterNodeTracker { public List<N> getNodesByResourceName(final String resourceName) { Preconditions.checkArgument( resourceName != null && !resourceName.isEmpty()); List<N> retNodes = new ArrayList<>(); if (ResourceRequest.ANY.equals(resourceName)) { retNodes.addAll(getAllNodes()); } else if (nodeNameToNodeMap.containsKey(resourceName)) { retNodes.add(nodeNameToNodeMap.get(resourceName)); } else if (nodesPerRack.containsKey(resourceName)) { retNodes.addAll(nodesPerRack.get(resourceName)); } else { LOG.info( "Could not find a node matching given resourceName " + resourceName); } return retNodes; } ClusterNodeTracker(); void addNode(N node); boolean exists(NodeId nodeId); N getNode(NodeId nodeId); SchedulerNodeReport getNodeReport(NodeId nodeId); int nodeCount(); int nodeCount(String rackName); Resource getClusterCapacity(); N removeNode(NodeId nodeId); void setConfiguredMaxAllocation(Resource resource); void setConfiguredMaxAllocationWaitTime(
      long configuredMaxAllocationWaitTime); Resource getMaxAllowedAllocation(); @VisibleForTesting void setForceConfiguredMaxAllocation(boolean flag); List<N> getAllNodes(); List<N> getNodes(NodeFilter nodeFilter); List<NodeId> getAllNodeIds(); List<NodeId> getNodeIds(NodeFilter nodeFilter); TreeSet<N> sortedNodeSet(Comparator<N> comparator); List<N> getNodesByResourceName(final String resourceName); List<NodeId> getNodeIdsByResourceName(final String resourceName); void updateNodesPerPartition(String partition, Set<NodeId> nodeIds); List<N> getNodesPerPartition(String partition);  }
@Test public void testGetNodesForResourceName() throws Exception { addEight4x4Nodes(); assertEquals("Incorrect number of nodes matching ANY", 8, nodeTracker.getNodesByResourceName(ResourceRequest.ANY).size()); assertEquals("Incorrect number of nodes matching rack", 4, nodeTracker.getNodesByResourceName("rack0").size()); assertEquals("Incorrect number of nodes matching node", 1, nodeTracker.getNodesByResourceName("host0").size()); }