Search in sources :

Example 76 with Element

use of org.w3c.dom.Element 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 77 with Element

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

the class TestHsWebServicesTasks method verifyHsTaskXML.

public void verifyHsTaskXML(NodeList nodes, Job job) {
    assertEquals("incorrect number of elements", 2, nodes.getLength());
    for (Task task : job.getTasks().values()) {
        TaskId id = task.getID();
        String tid = MRApps.toString(id);
        Boolean found = false;
        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.item(i);
            if (tid.matches(WebServicesTestUtils.getXmlString(element, "id"))) {
                found = true;
                verifyHsSingleTaskXML(element, task);
            }
        }
        assertTrue("task with id: " + tid + " not in web service output", found);
    }
}
Also used : Task(org.apache.hadoop.mapreduce.v2.app.job.Task) TaskId(org.apache.hadoop.mapreduce.v2.api.records.TaskId) Element(org.w3c.dom.Element)

Example 78 with Element

use of org.w3c.dom.Element 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)

Example 79 with Element

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

the class TestHsWebServicesJobs method verifyHsJobPartialXML.

public void verifyHsJobPartialXML(NodeList nodes, MockHistoryContext appContext) {
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        Job job = appContext.getPartialJob(MRApps.toJobID(WebServicesTestUtils.getXmlString(element, "id")));
        assertNotNull("Job not found - output incorrect", job);
        VerifyJobsUtils.verifyHsJobGeneric(job, WebServicesTestUtils.getXmlString(element, "id"), WebServicesTestUtils.getXmlString(element, "user"), WebServicesTestUtils.getXmlString(element, "name"), WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "queue"), WebServicesTestUtils.getXmlLong(element, "startTime"), WebServicesTestUtils.getXmlLong(element, "finishTime"), WebServicesTestUtils.getXmlInt(element, "mapsTotal"), WebServicesTestUtils.getXmlInt(element, "mapsCompleted"), WebServicesTestUtils.getXmlInt(element, "reducesTotal"), WebServicesTestUtils.getXmlInt(element, "reducesCompleted"));
    }
}
Also used : Element(org.w3c.dom.Element) Job(org.apache.hadoop.mapreduce.v2.app.job.Job)

Example 80 with Element

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

the class TestQueueConfigurationParser method testQueueConfigurationParser.

/**
 * test xml generation 
 * @throws ParserConfigurationException
 * @throws Exception 
 */
@Test(timeout = 5000)
public void testQueueConfigurationParser() throws ParserConfigurationException, Exception {
    JobQueueInfo info = new JobQueueInfo("root", "rootInfo");
    JobQueueInfo infoChild1 = new JobQueueInfo("child1", "child1Info");
    JobQueueInfo infoChild2 = new JobQueueInfo("child2", "child1Info");
    info.addChild(infoChild1);
    info.addChild(infoChild2);
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
    Document document = builder.newDocument();
    // test QueueConfigurationParser.getQueueElement 
    Element e = QueueConfigurationParser.getQueueElement(document, info);
    // transform result to string for check
    DOMSource domSource = new DOMSource(e);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.transform(domSource, result);
    String str = writer.toString();
    assertTrue(str.endsWith("<queue><name>root</name><properties/><state>running</state><queue><name>child1</name><properties/><state>running</state></queue><queue><name>child2</name><properties/><state>running</state></queue></queue>"));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

Element (org.w3c.dom.Element)9072 Document (org.w3c.dom.Document)2651 NodeList (org.w3c.dom.NodeList)2103 Node (org.w3c.dom.Node)1855 ArrayList (java.util.ArrayList)957 DocumentBuilder (javax.xml.parsers.DocumentBuilder)793 IOException (java.io.IOException)732 Test (org.junit.Test)693 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)591 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)489 HashMap (java.util.HashMap)434 SAXException (org.xml.sax.SAXException)406 File (java.io.File)358 Attr (org.w3c.dom.Attr)333 InputStream (java.io.InputStream)309 QName (javax.xml.namespace.QName)292 Map (java.util.Map)285 JAXBElement (javax.xml.bind.JAXBElement)285 NamedNodeMap (org.w3c.dom.NamedNodeMap)266 List (java.util.List)264