public static Set<NodeDetails> parseNodesFromNodeFile(
      String nodeFile, Resource nmDefaultResource) throws IOException {
    Set<NodeDetails> nodeSet = new HashSet<>();
    ObjectMapper mapper = JacksonUtil.createBasicObjectMapper();
    Reader input =
        new InputStreamReader(new FileInputStream(nodeFile), StandardCharsets.UTF_8);
    try {
      Iterator<Map> i = mapper.readValues(mapper.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;
  }
@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.fail("Unexpected label");
          }
        }
      } 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());
      }
    }
  }