Search in sources :

Example 66 with Element

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

the class TestRMWebServicesAppsModification method validateGetNewApplicationXMLResponse.

protected String validateGetNewApplicationXMLResponse(String response) throws ParserConfigurationException, IOException, SAXException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(response));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("NewApplication");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    Element element = (Element) nodes.item(0);
    String appId = WebServicesTestUtils.getXmlString(element, "application-id");
    assertTrue(!appId.isEmpty());
    NodeList maxResourceNodes = element.getElementsByTagName("maximum-resource-capability");
    assertEquals(1, maxResourceNodes.getLength());
    Element maxResourceCapability = (Element) maxResourceNodes.item(0);
    long memory = WebServicesTestUtils.getXmlLong(maxResourceCapability, "memory");
    long vCores = WebServicesTestUtils.getXmlLong(maxResourceCapability, "vCores");
    assertTrue(memory != 0);
    assertTrue(vCores != 0);
    return appId;
}
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 67 with Element

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

the class TestRMWebServicesAppsModification method verifyAppQueueXML.

protected static void verifyAppQueueXML(ClientResponse response, String queue) throws ParserConfigurationException, IOException, SAXException {
    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("appqueue");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    Element element = (Element) nodes.item(0);
    String responseQueue = WebServicesTestUtils.getXmlString(element, "queue");
    assertEquals(queue, responseQueue);
}
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 68 with Element

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

the class TestRMWebServicesForCSWithPartitions method verifyQueueBInfoXML.

private void verifyQueueBInfoXML(Element queueElem) {
    assertEquals("Invalid default Label expression", LABEL_LX, WebServicesTestUtils.getXmlString(queueElem, "defaultNodeLabelExpression"));
    NodeList children = queueElem.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
        Element queueChildElem = (Element) children.item(j);
        if (queueChildElem.getTagName().equals(CAPACITIES)) {
            NodeList capacitiesListInfos = queueChildElem.getChildNodes();
            assertEquals("incorrect number of partitions", 2, capacitiesListInfos.getLength());
            for (int k = 0; k < capacitiesListInfos.getLength(); k++) {
                Element partitionCapacitiesInfo = (Element) capacitiesListInfos.item(k);
                String partitionName = WebServicesTestUtils.getXmlString(partitionCapacitiesInfo, "partitionName");
                switch(partitionName) {
                    case LABEL_LX:
                        verifyPartitionCapacityInfoXML(partitionCapacitiesInfo, 30, 0, 100, 30, 0, 100);
                        break;
                    case DEFAULT_PARTITION:
                        verifyPartitionCapacityInfoXML(partitionCapacitiesInfo, 30, 0, 50, 30, 0, 50);
                        break;
                    default:
                        Assert.fail("Unexpected partition" + partitionName);
                }
            }
        } else if (queueChildElem.getTagName().equals("resources")) {
            verifyResourceUsageInfoXML(queueChildElem);
        }
    }
    assertEquals("Node Labels are not matching", LABEL_LX, WebServicesTestUtils.getXmlString(queueElem, "nodeLabels"));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 69 with Element

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

the class TestRMWebServicesForCSWithPartitions method verifyQcCapacitiesInfoXML.

private void verifyQcCapacitiesInfoXML(Element partitionCapacitiesElem, float lxCaps, float lxMaxCaps, float lxAbsCaps, float lxAbsMaxCaps, float lyCaps, float lyMaxCaps, float lyAbsCaps, float lyAbsMaxCaps, float defCaps, float defMaxCaps, float defAbsCaps, float defAbsMaxCaps) {
    NodeList capacitiesListInfos = partitionCapacitiesElem.getChildNodes();
    assertEquals("incorrect number of partitions", 3, capacitiesListInfos.getLength());
    for (int k = 0; k < capacitiesListInfos.getLength(); k++) {
        Element partitionCapacitiesInfo = (Element) capacitiesListInfos.item(k);
        String partitionName = WebServicesTestUtils.getXmlString(partitionCapacitiesInfo, "partitionName");
        switch(partitionName) {
            case LABEL_LX:
                verifyPartitionCapacityInfoXML(partitionCapacitiesInfo, lxCaps, 0, lxMaxCaps, lxAbsCaps, 0, lxAbsMaxCaps);
                break;
            case LABEL_LY:
                verifyPartitionCapacityInfoXML(partitionCapacitiesInfo, lyCaps, 0, lyMaxCaps, lyAbsCaps, 0, lyAbsMaxCaps);
                break;
            case DEFAULT_PARTITION:
                verifyPartitionCapacityInfoXML(partitionCapacitiesInfo, defCaps, 0, defMaxCaps, defAbsCaps, 0, defAbsMaxCaps);
                break;
            default:
                Assert.fail("Unexpected partition" + partitionName);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 70 with Element

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

the class TestRMWebServicesNodes method testNonexistNodeXML.

// test that the exception output works in XML
@Test
public void testNonexistNodeXML() throws JSONException, Exception {
    getNewRMNode("h1", 1234, 5120);
    getNewRMNode("h2", 1235, 5121);
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("cluster").path("nodes").path("node_invalid:99").accept(MediaType.APPLICATION_XML).get(JSONObject.class);
        fail("should have thrown exception on non-existent nodeid");
    } 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");
        verifyNonexistNodeException(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