Search in sources :

Example 41 with NodeList

use of org.w3c.dom.NodeList in project hadoop by apache.

the class TestHsWebServices method verifyHSInfoXML.

public void verifyHSInfoXML(String xml, AppContext ctx) throws JSONException, Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("historyInfo");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyHsInfoGeneric(WebServicesTestUtils.getXmlString(element, "hadoopVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "hadoopBuildVersion"), WebServicesTestUtils.getXmlString(element, "hadoopVersion"), WebServicesTestUtils.getXmlLong(element, "startedOn"));
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 42 with NodeList

use of org.w3c.dom.NodeList in project hadoop by apache.

the class TestHsWebServicesAttempts method verifyHsTaskCountersXML.

public void verifyHsTaskCountersXML(NodeList nodes, TaskAttempt att) {
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        WebServicesTestUtils.checkStringMatch("id", MRApps.toString(att.getID()), WebServicesTestUtils.getXmlString(element, "id"));
        // just do simple verification of fields - not data is correct
        // in the fields
        NodeList groups = element.getElementsByTagName("taskAttemptCounterGroup");
        for (int j = 0; j < groups.getLength(); j++) {
            Element counters = (Element) groups.item(j);
            assertNotNull("should have counters in the web service info", counters);
            String name = WebServicesTestUtils.getXmlString(counters, "counterGroupName");
            assertTrue("name not set", (name != null && !name.isEmpty()));
            NodeList counterArr = counters.getElementsByTagName("counter");
            for (int z = 0; z < counterArr.getLength(); z++) {
                Element counter = (Element) counterArr.item(z);
                String counterName = WebServicesTestUtils.getXmlString(counter, "name");
                assertTrue("counter name not set", (counterName != null && !counterName.isEmpty()));
                long value = WebServicesTestUtils.getXmlLong(counter, "value");
                assertTrue("value not >= 0", value >= 0);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList)

Example 43 with NodeList

use of org.w3c.dom.NodeList in project hadoop by apache.

the class TestRMWithCSRFFilter method verifyClusterInfoXML.

public void verifyClusterInfoXML(String xml) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("clusterInfo");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyClusterGeneric(WebServicesTestUtils.getXmlLong(element, "id"), WebServicesTestUtils.getXmlLong(element, "startedOn"), WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "haState"), WebServicesTestUtils.getXmlString(element, "haZooKeeperConnectionState"), WebServicesTestUtils.getXmlString(element, "hadoopVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "hadoopBuildVersion"), WebServicesTestUtils.getXmlString(element, "hadoopVersion"), WebServicesTestUtils.getXmlString(element, "resourceManagerVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "resourceManagerBuildVersion"), WebServicesTestUtils.getXmlString(element, "resourceManagerVersion"));
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 44 with NodeList

use of org.w3c.dom.NodeList in project hadoop by apache.

the class TestRMWebServices method verifySchedulerFifoXML.

public void verifySchedulerFifoXML(String xml) throws JSONException, Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList nodesSched = dom.getElementsByTagName("scheduler");
    assertEquals("incorrect number of elements", 1, nodesSched.getLength());
    NodeList nodes = dom.getElementsByTagName("schedulerInfo");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyClusterSchedulerFifoGeneric(WebServicesTestUtils.getXmlAttrString(element, "xsi:type"), WebServicesTestUtils.getXmlString(element, "qstate"), WebServicesTestUtils.getXmlFloat(element, "capacity"), WebServicesTestUtils.getXmlFloat(element, "usedCapacity"), WebServicesTestUtils.getXmlInt(element, "minQueueMemoryCapacity"), WebServicesTestUtils.getXmlInt(element, "maxQueueMemoryCapacity"), WebServicesTestUtils.getXmlInt(element, "numNodes"), WebServicesTestUtils.getXmlInt(element, "usedNodeCapacity"), WebServicesTestUtils.getXmlInt(element, "availNodeCapacity"), WebServicesTestUtils.getXmlInt(element, "totalNodeCapacity"), WebServicesTestUtils.getXmlInt(element, "numContainers"));
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 45 with NodeList

use of org.w3c.dom.NodeList in project hadoop by apache.

the class TestRMWebServices method verifyClusterMetricsXML.

public void verifyClusterMetricsXML(String xml) throws JSONException, Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("clusterMetrics");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyClusterMetrics(WebServicesTestUtils.getXmlInt(element, "appsSubmitted"), WebServicesTestUtils.getXmlInt(element, "appsCompleted"), WebServicesTestUtils.getXmlInt(element, "reservedMB"), WebServicesTestUtils.getXmlInt(element, "availableMB"), WebServicesTestUtils.getXmlInt(element, "allocatedMB"), WebServicesTestUtils.getXmlInt(element, "reservedVirtualCores"), WebServicesTestUtils.getXmlInt(element, "availableVirtualCores"), WebServicesTestUtils.getXmlInt(element, "allocatedVirtualCores"), WebServicesTestUtils.getXmlInt(element, "totalVirtualCores"), WebServicesTestUtils.getXmlInt(element, "containersAllocated"), WebServicesTestUtils.getXmlInt(element, "totalMB"), WebServicesTestUtils.getXmlInt(element, "totalNodes"), WebServicesTestUtils.getXmlInt(element, "lostNodes"), WebServicesTestUtils.getXmlInt(element, "unhealthyNodes"), WebServicesTestUtils.getXmlInt(element, "decommissionedNodes"), WebServicesTestUtils.getXmlInt(element, "rebootedNodes"), WebServicesTestUtils.getXmlInt(element, "activeNodes"), WebServicesTestUtils.getXmlInt(element, "shutdownNodes"));
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Aggregations

NodeList (org.w3c.dom.NodeList)1806 Node (org.w3c.dom.Node)1059 Element (org.w3c.dom.Element)902 Document (org.w3c.dom.Document)636 ArrayList (java.util.ArrayList)314 DocumentBuilder (javax.xml.parsers.DocumentBuilder)268 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)208 IOException (java.io.IOException)183 NamedNodeMap (org.w3c.dom.NamedNodeMap)144 InputSource (org.xml.sax.InputSource)131 HashMap (java.util.HashMap)121 Test (org.junit.Test)117 SAXException (org.xml.sax.SAXException)117 StringReader (java.io.StringReader)106 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)100 XPath (javax.xml.xpath.XPath)99 Attr (org.w3c.dom.Attr)80 XPathExpressionException (javax.xml.xpath.XPathExpressionException)76 File (java.io.File)64 HashSet (java.util.HashSet)59