SLSUtils { public static Set<NodeDetails> parseNodesFromNodeFile( String nodeFile, Resource nmDefaultResource) throws IOException { Set<NodeDetails> nodeSet = new HashSet<>(); JsonFactory jsonF = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(); Reader input = new InputStreamReader(new FileInputStream(nodeFile), "UTF-8"); try { Iterator<Map> i = mapper.readValues(jsonF.createParser(input), Map.class); while (i.hasNext()) { Map jsonE = i.next(); String rack = "/" + jsonE.get("rack"); List tasks = (List) jsonE.get("nodes"); for (Object o : tasks) { Map jsonNode = (Map) o; NodeDetails nodeDetails = new NodeDetails( rack + "/" + jsonNode.get("node")); Resource nodeResource = Resources.clone(nmDefaultResource); ResourceInformation[] infors = ResourceUtils.getResourceTypesArray(); for (ResourceInformation info : infors) { if (jsonNode.get(info.getName()) != null) { nodeResource.setResourceValue(info.getName(), Integer.parseInt(jsonNode.get(info.getName()).toString())); } } nodeDetails.setNodeResource(nodeResource); if (jsonNode.get("labels") != null) { Set<NodeLabel> nodeLabels = new HashSet<>( YarnClientUtils.buildNodeLabelsFromStr( jsonNode.get("labels").toString())); nodeDetails.setLabels(nodeLabels); } nodeSet.add(nodeDetails); } } } finally { input.close(); } return nodeSet; }  static String[] getRackHostName(String hostname); static Set<NodeDetails> parseNodesFromRumenTrace(
      String jobTrace); static Set<NodeDetails> parseNodesFromSLSTrace(
      String jobTrace); static Set<NodeDetails> parseNodesFromNodeFile(
      String nodeFile, Resource nmDefaultResource); static Set<NodeDetails> generateNodes(int numNodes,
      int numRacks); final static String DEFAULT_JOB_TYPE; }
@Test public void testParseNodesFromNodeFile() throws Exception { String nodeFile = "src/test/resources/nodes.json"; Set<NodeDetails> nodeDetails = SLSUtils.parseNodesFromNodeFile( nodeFile, Resources.createResource(1024, 2)); Assert.assertEquals(20, nodeDetails.size()); nodeFile = "src/test/resources/nodes-with-resources.json"; nodeDetails = SLSUtils.parseNodesFromNodeFile( nodeFile, Resources.createResource(1024, 2)); Assert.assertEquals(4, nodeDetails.size()); for (NodeDetails nodeDetail : nodeDetails) { if (nodeDetail.getHostname().equals("/rack1/node1")) { Assert.assertEquals(2048, nodeDetail.getNodeResource().getMemorySize()); Assert.assertEquals(6, nodeDetail.getNodeResource().getVirtualCores()); } else if (nodeDetail.getHostname().equals("/rack1/node2")) { Assert.assertEquals(1024, nodeDetail.getNodeResource().getMemorySize()); Assert.assertEquals(2, nodeDetail.getNodeResource().getVirtualCores()); Assert.assertNull(nodeDetail.getLabels()); } else if (nodeDetail.getHostname().equals("/rack1/node3")) { Assert.assertEquals(1024, nodeDetail.getNodeResource().getMemorySize()); Assert.assertEquals(2, nodeDetail.getNodeResource().getVirtualCores()); Assert.assertEquals(2, nodeDetail.getLabels().size()); for (NodeLabel nodeLabel : nodeDetail.getLabels()) { if (nodeLabel.getName().equals("label1")) { Assert.assertTrue(nodeLabel.isExclusive()); } else if(nodeLabel.getName().equals("label2")) { Assert.assertFalse(nodeLabel.isExclusive()); } else { Assert.assertTrue("Unexepected label", false); } } } else if (nodeDetail.getHostname().equals("/rack1/node4")) { Assert.assertEquals(6144, nodeDetail.getNodeResource().getMemorySize()); Assert.assertEquals(12, nodeDetail.getNodeResource().getVirtualCores()); Assert.assertEquals(2, nodeDetail.getLabels().size()); } } }