Search in sources :

Example 71 with Element

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

the class TestRMWebServicesNodes method verifyNodesXML.

public void verifyNodesXML(NodeList nodes, RMNode nm) throws JSONException, Exception {
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyNodeInfoGeneric(nm, WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "rack"), WebServicesTestUtils.getXmlString(element, "id"), WebServicesTestUtils.getXmlString(element, "nodeHostName"), WebServicesTestUtils.getXmlString(element, "nodeHTTPAddress"), WebServicesTestUtils.getXmlLong(element, "lastHealthUpdate"), WebServicesTestUtils.getXmlString(element, "healthReport"), WebServicesTestUtils.getXmlInt(element, "numContainers"), WebServicesTestUtils.getXmlLong(element, "usedMemoryMB"), WebServicesTestUtils.getXmlLong(element, "availMemoryMB"), WebServicesTestUtils.getXmlLong(element, "usedVirtualCores"), WebServicesTestUtils.getXmlLong(element, "availableVirtualCores"), WebServicesTestUtils.getXmlString(element, "version"), WebServicesTestUtils.getXmlInt(element, "nodePhysicalMemoryMB"), WebServicesTestUtils.getXmlInt(element, "nodeVirtualMemoryMB"), WebServicesTestUtils.getXmlFloat(element, "nodeCPUUsage"), WebServicesTestUtils.getXmlInt(element, "aggregatedContainersPhysicalMemoryMB"), WebServicesTestUtils.getXmlInt(element, "aggregatedContainersVirtualMemoryMB"), WebServicesTestUtils.getXmlFloat(element, "containersCPUUsage"), WebServicesTestUtils.getXmlInt(element, "numRunningOpportContainers"), WebServicesTestUtils.getXmlLong(element, "usedMemoryOpportGB"), WebServicesTestUtils.getXmlInt(element, "usedVirtualCoresOpport"), WebServicesTestUtils.getXmlInt(element, "numQueuedContainers"));
    }
}
Also used : Element(org.w3c.dom.Element)

Example 72 with Element

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

the class TestRMWebServicesForCSWithPartitions method verifyResourceUsageInfoXML.

private void verifyResourceUsageInfoXML(Element queueChildElem) {
    NodeList resourceUsageInfo = queueChildElem.getChildNodes();
    assertEquals("incorrect number of partitions", 1, resourceUsageInfo.getLength());
    Element partitionResourceUsageInfo = (Element) resourceUsageInfo.item(0);
    String partitionName = WebServicesTestUtils.getXmlString(partitionResourceUsageInfo, "partitionName");
    assertTrue("invalid PartitionCapacityInfo", DEFAULT_PARTITION.equals(partitionName));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 73 with Element

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

the class TestRMWebServicesApps method verifyAppsXML.

public void verifyAppsXML(NodeList nodes, RMApp app) throws JSONException, Exception {
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyAppInfoGeneric(app, WebServicesTestUtils.getXmlString(element, "id"), WebServicesTestUtils.getXmlString(element, "user"), WebServicesTestUtils.getXmlString(element, "name"), WebServicesTestUtils.getXmlString(element, "applicationType"), WebServicesTestUtils.getXmlString(element, "queue"), WebServicesTestUtils.getXmlInt(element, "priority"), WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "finalStatus"), WebServicesTestUtils.getXmlFloat(element, "progress"), WebServicesTestUtils.getXmlString(element, "trackingUI"), WebServicesTestUtils.getXmlString(element, "diagnostics"), WebServicesTestUtils.getXmlLong(element, "clusterId"), WebServicesTestUtils.getXmlLong(element, "startedTime"), WebServicesTestUtils.getXmlLong(element, "finishedTime"), WebServicesTestUtils.getXmlLong(element, "elapsedTime"), WebServicesTestUtils.getXmlString(element, "amHostHttpAddress"), WebServicesTestUtils.getXmlString(element, "amContainerLogs"), WebServicesTestUtils.getXmlInt(element, "allocatedMB"), WebServicesTestUtils.getXmlInt(element, "allocatedVCores"), WebServicesTestUtils.getXmlInt(element, "runningContainers"), WebServicesTestUtils.getXmlFloat(element, "queueUsagePercentage"), WebServicesTestUtils.getXmlFloat(element, "clusterUsagePercentage"), WebServicesTestUtils.getXmlInt(element, "preemptedResourceMB"), WebServicesTestUtils.getXmlInt(element, "preemptedResourceVCores"), WebServicesTestUtils.getXmlInt(element, "numNonAMContainerPreempted"), WebServicesTestUtils.getXmlInt(element, "numAMContainerPreempted"), WebServicesTestUtils.getXmlString(element, "logAggregationStatus"), WebServicesTestUtils.getXmlBoolean(element, "unmanagedApplication"), WebServicesTestUtils.getXmlString(element, "appNodeLabelExpression"), WebServicesTestUtils.getXmlString(element, "amNodeLabelExpression"), WebServicesTestUtils.getXmlString(element, "amRPCAddress"));
        assertEquals(element.getElementsByTagName("resourceRequests").getLength(), 1);
        Element resourceRequests = (Element) element.getElementsByTagName("resourceRequests").item(0);
        Element capability = (Element) resourceRequests.getElementsByTagName("capability").item(0);
        verifyResourceRequestsGeneric(app, WebServicesTestUtils.getXmlString(resourceRequests, "nodeLabelExpression"), WebServicesTestUtils.getXmlInt(resourceRequests, "numContainers"), WebServicesTestUtils.getXmlBoolean(resourceRequests, "relaxLocality"), WebServicesTestUtils.getXmlInt(resourceRequests, "priority"), WebServicesTestUtils.getXmlString(resourceRequests, "resourceName"), WebServicesTestUtils.getXmlLong(capability, "memory"), WebServicesTestUtils.getXmlLong(capability, "vCores"), WebServicesTestUtils.getXmlString(resourceRequests, "executionType"), WebServicesTestUtils.getXmlBoolean(resourceRequests, "enforceExecutionType"));
    }
}
Also used : Element(org.w3c.dom.Element)

Example 74 with Element

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

the class WebServicesTestUtils method getXmlString.

public static String getXmlString(Element element, String name) {
    NodeList id = element.getElementsByTagName(name);
    Element line = (Element) id.item(0);
    if (line == null) {
        return null;
    }
    Node first = line.getFirstChild();
    // handle empty <key></key>
    if (first == null) {
        return "";
    }
    String val = first.getNodeValue();
    if (val == null) {
        return "";
    }
    return val;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node)

Example 75 with Element

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

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