protected List<FederationQueueWeight> parsePoliciesByXml(String policiesXml)
      throws IOException, SAXException, ParserConfigurationException {

    List<FederationQueueWeight> weights = new ArrayList<>();

    File xmlFile = new File(policiesXml);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(xmlFile);

    NodeList federationsList = document.getElementsByTagName(XML_TAG_FEDERATION_WEIGHTS);

    for (int i = 0; i < federationsList.getLength(); i++) {

      Node federationNode = federationsList.item(i);

      if (federationNode.getNodeType() == Node.ELEMENT_NODE) {
        Element federationElement = (Element) federationNode;
        NodeList queueList = federationElement.getElementsByTagName(XML_TAG_QUEUE);

        for (int j = 0; j < queueList.getLength(); j++) {

          Node queueNode = queueList.item(j);
          if (queueNode.getNodeType() == Node.ELEMENT_NODE) {
            Element queueElement = (Element) queueNode;
            // parse queueName.
            String queueName = queueElement.getElementsByTagName(XML_TAG_NAME)
                .item(0).getTextContent();

            // parse amrmPolicyWeights / routerPolicyWeights.
            String amrmWeight = parsePolicyWeightsNode(queueElement, XML_TAG_AMRMPOLICYWEIGHTS);
            String routerWeight = parsePolicyWeightsNode(queueElement, XML_TAG_ROUTERPOLICYWEIGHTS);

            // parse headroomAlpha.
            String headroomAlpha = queueElement.getElementsByTagName(XML_TAG_HEADROOMALPHA)
                .item(0).getTextContent();

            String policyManager = getConf().get(YarnConfiguration.FEDERATION_POLICY_MANAGER,
                YarnConfiguration.DEFAULT_FEDERATION_POLICY_MANAGER);

            LOG.debug("Queue: {}, AmrmPolicyWeights: {}, RouterWeight: {}, HeadroomAlpha: {}.",
                queueName, amrmWeight, routerWeight, headroomAlpha);

            FederationQueueWeight weight = FederationQueueWeight.newInstance(routerWeight,
                amrmWeight, headroomAlpha, queueName, policyManager);

            weights.add(weight);
          }
        }
      }
    }

    return weights;
  }
@Test
  public void testParsePoliciesByXml() throws Exception {
    String filePath =
        TestRouterCLI.class.getClassLoader().getResource("federation-weights.xml").getFile();
    List<FederationQueueWeight> federationQueueWeights = rmAdminCLI.parsePoliciesByXml(filePath);
    assertNotNull(federationQueueWeights);
    assertEquals(2, federationQueueWeights.size());

    // Queue1: root.a
    FederationQueueWeight queueWeight1 = federationQueueWeights.get(0);
    assertNotNull(queueWeight1);
    assertEquals("root.a", queueWeight1.getQueue());
    assertEquals("SC-1:0.7,SC-2:0.3", queueWeight1.getAmrmWeight());
    assertEquals("SC-1:0.6,SC-2:0.4", queueWeight1.getRouterWeight());

    // Queue2: root.b
    FederationQueueWeight queueWeight2 = federationQueueWeights.get(1);
    assertNotNull(queueWeight2);
    assertEquals("root.b", queueWeight2.getQueue());
    assertEquals("SC-1:0.8,SC-2:0.2", queueWeight2.getAmrmWeight());
    assertEquals("SC-1:0.6,SC-2:0.4", queueWeight2.getRouterWeight());
  }