use of org.w3c.dom.Document in project hadoop by apache.
the class TestRMWebServicesNodes method testNodes2XML.
@Test
public void testNodes2XML() throws JSONException, Exception {
WebResource r = resource();
getNewRMNode("h1", 1234, 5120);
getNewRMNode("h2", 1235, 5121);
ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes").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 nodesApps = dom.getElementsByTagName("nodes");
assertEquals("incorrect number of elements", 1, nodesApps.getLength());
NodeList nodes = dom.getElementsByTagName("node");
assertEquals("incorrect number of elements", 2, nodes.getLength());
}
use of org.w3c.dom.Document in project hadoop by apache.
the class TestRMWebServicesApps method testAppsXML.
@Test
public void testAppsXML() throws JSONException, Exception {
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
RMApp app1 = rm.submitApp(CONTAINER_MB, "testwordcount", "user1");
amNodeManager.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").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 nodesApps = dom.getElementsByTagName("apps");
assertEquals("incorrect number of elements", 1, nodesApps.getLength());
NodeList nodes = dom.getElementsByTagName("app");
assertEquals("incorrect number of elements", 1, nodes.getLength());
verifyAppsXML(nodes, app1);
rm.stop();
}
use of org.w3c.dom.Document in project hadoop by apache.
the class TestRMWebServicesCapacitySched method testPerUserResourcesXML.
/**
* Test per user resources and resourcesUsed elements in the web services XML
* @throws Exception
*/
@Test
public void testPerUserResourcesXML() throws Exception {
//Start RM so that it accepts app submissions
rm.start();
try {
rm.submitApp(10, "app1", "user1", null, "b1");
rm.submitApp(20, "app2", "user2", null, "b1");
//Get the XML from ws/v1/cluster/scheduler
WebResource r = resource();
ClientResponse response = r.path("ws/v1/cluster/scheduler").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
String xml = response.getEntity(String.class);
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
//Parse the XML we got
Document dom = db.parse(is);
//Get all users elements (1 for each leaf queue)
NodeList allUsers = dom.getElementsByTagName("users");
for (int i = 0; i < allUsers.getLength(); ++i) {
Node perUserResources = allUsers.item(i);
String queueName = getChildNodeByName(perUserResources.getParentNode(), "queueName").getTextContent();
if (queueName.equals("b1")) {
//b1 should have two users (user1 and user2) which submitted jobs
assertEquals(2, perUserResources.getChildNodes().getLength());
NodeList users = perUserResources.getChildNodes();
for (int j = 0; j < users.getLength(); ++j) {
Node user = users.item(j);
String username = getChildNodeByName(user, "username").getTextContent();
assertTrue(username.equals("user1") || username.equals("user2"));
//Should be a parsable integer
Integer.parseInt(getChildNodeByName(getChildNodeByName(user, "resourcesUsed"), "memory").getTextContent());
Integer.parseInt(getChildNodeByName(user, "numActiveApplications").getTextContent());
Integer.parseInt(getChildNodeByName(user, "numPendingApplications").getTextContent());
}
} else {
//Queues other than b1 should have 0 users
assertEquals(0, perUserResources.getChildNodes().getLength());
}
}
NodeList allResourcesUsed = dom.getElementsByTagName("resourcesUsed");
for (int i = 0; i < allResourcesUsed.getLength(); ++i) {
Node resourcesUsed = allResourcesUsed.item(i);
Integer.parseInt(getChildNodeByName(resourcesUsed, "memory").getTextContent());
Integer.parseInt(getChildNodeByName(resourcesUsed, "vCores").getTextContent());
}
} finally {
rm.stop();
}
}
use of org.w3c.dom.Document in project hadoop by apache.
the class TestRMWebServicesCapacitySched method testClusterSchedulerXML.
@Test
public void testClusterSchedulerXML() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler/").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 scheduler = dom.getElementsByTagName("scheduler");
assertEquals("incorrect number of elements", 1, scheduler.getLength());
NodeList schedulerInfo = dom.getElementsByTagName("schedulerInfo");
assertEquals("incorrect number of elements", 1, schedulerInfo.getLength());
verifyClusterSchedulerXML(schedulerInfo);
}
use of org.w3c.dom.Document in project hadoop by apache.
the class TestRMWebServicesApps method testSingleAppsXML.
@Test
public void testSingleAppsXML() throws JSONException, Exception {
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
RMApp app1 = rm.submitApp(CONTAINER_MB, "testwordcount", "user1");
amNodeManager.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster").path("apps").path(app1.getApplicationId().toString()).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("app");
assertEquals("incorrect number of elements", 1, nodes.getLength());
verifyAppsXML(nodes, app1);
rm.stop();
}
Aggregations