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"));
}
}
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));
}
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"));
}
}
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;
}
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);
}
}
Aggregations