Search in sources :

Example 31 with NodeList

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

the class TestNMWebServicesContainers method testNodeSingleContainerXML.

@Test
public void testNodeSingleContainerXML() throws JSONException, Exception {
    WebResource r = resource();
    Application app = new MockApp(1);
    nmContext.getApplications().put(app.getAppId(), app);
    HashMap<String, String> hash = addAppContainers(app);
    Application app2 = new MockApp(2);
    nmContext.getApplications().put(app2.getAppId(), app2);
    addAppContainers(app2);
    client().addFilter(new LoggingFilter(System.out));
    for (String id : hash.keySet()) {
        ClientResponse response = r.path("ws").path("v1").path("node").path("containers").path(id).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        String xml = response.getEntity(String.class);
        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("container");
        assertEquals("incorrect number of elements", 1, nodes.getLength());
        verifyContainersInfoXML(nodes, nmContext.getContainers().get(ContainerId.fromString(id)));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 32 with NodeList

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

the class TestHsWebServicesJobConf method testJobConfXML.

@Test
public void testJobConfXML() throws JSONException, Exception {
    WebResource r = resource();
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (JobId id : jobsMap.keySet()) {
        String jobId = MRApps.toString(id);
        ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").path(jobId).path("conf").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        String xml = response.getEntity(String.class);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        Document dom = db.parse(is);
        NodeList info = dom.getElementsByTagName("conf");
        verifyHsJobConfXML(info, jobsMap.get(id));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) WebResource(com.sun.jersey.api.client.WebResource) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) Document(org.w3c.dom.Document) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) Test(org.junit.Test)

Example 33 with NodeList

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

the class TestHsWebServicesJobs method testJobIdInvalidXML.

// test that the exception output works in XML
@Test
public void testJobIdInvalidXML() throws JSONException, Exception {
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").path("job_foo").accept(MediaType.APPLICATION_XML).get(JSONObject.class);
        fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        String msg = response.getEntity(String.class);
        System.out.println(msg);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(msg));
        Document dom = db.parse(is);
        NodeList nodes = dom.getElementsByTagName("RemoteException");
        Element element = (Element) nodes.item(0);
        String message = WebServicesTestUtils.getXmlString(element, "message");
        String type = WebServicesTestUtils.getXmlString(element, "exception");
        String classname = WebServicesTestUtils.getXmlString(element, "javaClassName");
        verifyJobIdInvalid(message, type, classname);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputSource(org.xml.sax.InputSource) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 34 with NodeList

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

the class TestHsWebServicesJobs method verifyHsJobCountersXML.

public void verifyHsJobCountersXML(NodeList nodes, Job job) {
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        assertNotNull("Job not found - output incorrect", job);
        WebServicesTestUtils.checkStringMatch("id", MRApps.toString(job.getID()), WebServicesTestUtils.getXmlString(element, "id"));
        // just do simple verification of fields - not data is correct
        // in the fields
        NodeList groups = element.getElementsByTagName("counterGroup");
        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 mapValue = WebServicesTestUtils.getXmlLong(counter, "mapCounterValue");
                assertTrue("mapCounterValue not >= 0", mapValue >= 0);
                long reduceValue = WebServicesTestUtils.getXmlLong(counter, "reduceCounterValue");
                assertTrue("reduceCounterValue  >= 0", reduceValue >= 0);
                long totalValue = WebServicesTestUtils.getXmlLong(counter, "totalCounterValue");
                assertTrue("totalCounterValue  >= 0", totalValue >= 0);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList)

Example 35 with NodeList

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

the class TestHsWebServicesTasks method testTaskIdXML.

@Test
public void testTaskIdXML() throws JSONException, Exception {
    WebResource r = resource();
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (JobId id : jobsMap.keySet()) {
        String jobId = MRApps.toString(id);
        for (Task task : jobsMap.get(id).getTasks().values()) {
            String tid = MRApps.toString(task.getID());
            ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid).accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
            assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
            String xml = response.getEntity(String.class);
            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("task");
            for (int i = 0; i < nodes.getLength(); i++) {
                Element element = (Element) nodes.item(i);
                verifyHsSingleTaskXML(element, task);
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Task(org.apache.hadoop.mapreduce.v2.app.job.Task) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) Test(org.junit.Test)

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