diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java index 3fd1fd5..1093381 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java @@ -31,20 +31,26 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.net.Node; import org.apache.hadoop.yarn.api.records.ContainerStatus; import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeState; +import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.ResourceUtilization; import org.apache.hadoop.yarn.server.api.records.NodeHealthStatus; import org.apache.hadoop.yarn.server.api.records.NodeStatus; -import org.apache.hadoop.yarn.server.resourcemanager.MockNM; import org.apache.hadoop.yarn.server.resourcemanager.MockRM; import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode; +import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeEvent; +import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeEventType; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeImpl; +import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeStartedEvent; import org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNodeStatusEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNodeReport; +import org.apache.hadoop.yarn.util.RackResolver; +import org.apache.hadoop.yarn.util.YarnVersionInfo; import org.apache.hadoop.yarn.webapp.GenericExceptionHandler; import org.apache.hadoop.yarn.webapp.JerseyTestBase; import org.apache.hadoop.yarn.webapp.WebServicesTestUtils; @@ -130,24 +136,21 @@ public void testNodesDefaultWithUnHealthyNode() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - rm.sendNodeStarted(nm1); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW); - - MockNM nm3 = rm.registerNode("h3:1236", 5122); - rm.NMwaitForState(nm3.getNodeId(), NodeState.NEW); - rm.sendNodeStarted(nm3); - rm.NMwaitForState(nm3.getNodeId(), NodeState.RUNNING); - RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes() - .get(nm3.getNodeId()); + addStartedNode("h1", 1234, 5120); + //h2 will be in NEW state + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); + + RMNode node3 = addStartedNode("h3", 1236, 5122); + NodeId nodeId3 = node3.getNodeID(); + + RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes().get(nodeId3); NodeHealthStatus nodeHealth = NodeHealthStatus.newInstance(false, "test health report", System.currentTimeMillis()); - NodeStatus nodeStatus = NodeStatus.newInstance(nm3.getNodeId(), 1, + NodeStatus nodeStatus = NodeStatus.newInstance(nodeId3, 1, new ArrayList(), null, nodeHealth, null, null, null); - node.handle(new RMNodeStatusEvent(nm3.getNodeId(), nodeStatus, null)); - rm.NMwaitForState(nm3.getNodeId(), NodeState.UNHEALTHY); + node.handle(new RMNodeStatusEvent(nodeId3, nodeStatus, null)); + rm.NMwaitForState(nodeId3, NodeState.UNHEALTHY); ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes") @@ -163,14 +166,41 @@ public void testNodesDefaultWithUnHealthyNode() throws JSONException, assertEquals("incorrect number of elements", 3, nodeArray.length()); } + private RMNode addStartedNode(String host, int port, int memory) { + NodeId nodeId1 = NodeId.newInstance(host, port); + RMNodeImpl rmnode1 = addRMNode(memory, nodeId1); + sendStartedEvent(nodeId1, rmnode1); + return rmnode1; + } + + private void sendStartedEvent(NodeId nodeId, RMNode node) { + ((RMNodeImpl) node).handle(new RMNodeStartedEvent(nodeId, null, null)); + } + + private void sendLostEvent(NodeId nodeId, RMNode node) { + ((RMNodeImpl) node) + .handle(new RMNodeEvent(nodeId, RMNodeEventType.EXPIRE)); + } + + private RMNodeImpl addRMNode(int memory, NodeId nodeId) { + Resource capability = Resource.newInstance(memory, 4); + Node node2 = RackResolver.resolve(nodeId.getHost()); + int port = nodeId.getPort(); + RMNodeImpl nodeImpl = + new RMNodeImpl(nodeId, rm.getRMContext(), nodeId.getHost(), port, port, + node2, capability, YarnVersionInfo.getVersion()); + rm.getRMContext().getRMNodes().put(nodeId, nodeImpl); + return nodeImpl; + } + @Test public void testNodesQueryNew() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - rm.sendNodeStarted(nm1); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW); + + addStartedNode("h1", 1234, 5120); + // h2 will be in NEW state + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + RMNodeImpl rmnode2 = addRMNode(5121, nodeId2); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").queryParam("states", NodeState.NEW.toString()) @@ -185,14 +215,16 @@ public void testNodesQueryNew() throws JSONException, Exception { assertEquals("incorrect number of elements", 1, nodeArray.length()); JSONObject info = nodeArray.getJSONObject(0); - verifyNodeInfo(info, nm2); + verifyNodeInfo(info, rmnode2); } @Test public void testNodesQueryStateNone() throws JSONException, Exception { WebResource r = resource(); - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes") @@ -207,8 +239,10 @@ public void testNodesQueryStateNone() throws JSONException, Exception { @Test public void testNodesQueryStateInvalid() throws JSONException, Exception { WebResource r = resource(); - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); try { r.path("ws").path("v1").path("cluster").path("nodes") @@ -238,22 +272,16 @@ public void testNodesQueryStateInvalid() throws JSONException, Exception { WebServicesTestUtils.checkStringMatch("exception classname", "java.lang.IllegalArgumentException", classname); - } finally { - rm.stop(); } } @Test public void testNodesQueryStateLost() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1234", 5120); - rm.sendNodeStarted(nm1); - rm.sendNodeStarted(nm2); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.RUNNING); - rm.sendNodeLost(nm1); - rm.sendNodeLost(nm2); + RMNode rmnode1 = addStartedNode("h1", 1234, 5120); + sendLostEvent(rmnode1.getNodeID(), rmnode1); + RMNode rmnode2 = addStartedNode("h2", 1235, 5121); + sendLostEvent(rmnode2.getNodeID(), rmnode2); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").queryParam("states", NodeState.LOST.toString()) @@ -280,14 +308,9 @@ public void testNodesQueryStateLost() throws JSONException, Exception { @Test public void testSingleNodeQueryStateLost() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1234", 5120); - rm.sendNodeStarted(nm1); - rm.sendNodeStarted(nm2); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.RUNNING); - rm.sendNodeLost(nm1); - rm.sendNodeLost(nm2); + addStartedNode("h1", 1234, 5120); + RMNode rmnode2 = addStartedNode("h2", 1234, 5121); + sendLostEvent(rmnode2.getNodeID(), rmnode2); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").path("h2:1234").accept(MediaType.APPLICATION_JSON) @@ -300,8 +323,8 @@ public void testSingleNodeQueryStateLost() throws JSONException, Exception { assertEquals("Incorrect Node Information.", "h2:1234", id); - NodeId nodeId = NodeId.newInstance("h2", 1234); - RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(nodeId); + RMNode rmNode = + rm.getRMContext().getInactiveRMNodes().get(rmnode2.getNodeID()); WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", "", info.getString("nodeHTTPAddress")); WebServicesTestUtils.checkStringMatch("state", @@ -311,11 +334,11 @@ public void testSingleNodeQueryStateLost() throws JSONException, Exception { @Test public void testNodesQueryRunning() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - rm.sendNodeStarted(nm1); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW); + addStartedNode("h1", 1234, 5120); + // h2 will be in NEW state + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); + ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").queryParam("states", "running") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); @@ -331,11 +354,11 @@ public void testNodesQueryRunning() throws JSONException, Exception { @Test public void testNodesQueryHealthyFalse() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - rm.sendNodeStarted(nm1); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW); + addStartedNode("h1", 1234, 5120); + // h2 will be in NEW state + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); + ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").queryParam("states", "UNHEALTHY") .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); @@ -348,12 +371,10 @@ public void testNodesQueryHealthyFalse() throws JSONException, Exception { public void testNodesHelper(String path, String media) throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - rm.sendNodeStarted(nm1); - rm.sendNodeStarted(nm2); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.RUNNING); + RMNode rmnode1 = addStartedNode("h1", 1234, 5120); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + RMNodeImpl rmnode2 = addRMNode(5121, nodeId2); + sendStartedEvent(nodeId2, rmnode2); ClientResponse response = r.path("ws").path("v1").path("cluster") .path(path).accept(media).get(ClientResponse.class); @@ -368,36 +389,36 @@ public void testNodesHelper(String path, String media) throws JSONException, String id = info.get("id").toString(); if (id.matches("h1:1234")) { - verifyNodeInfo(info, nm1); - verifyNodeInfo(nodeArray.getJSONObject(1), nm2); + verifyNodeInfo(info, rmnode1); + verifyNodeInfo(nodeArray.getJSONObject(1), rmnode2); } else { - verifyNodeInfo(info, nm2); - verifyNodeInfo(nodeArray.getJSONObject(1), nm1); + verifyNodeInfo(info, rmnode2); + verifyNodeInfo(nodeArray.getJSONObject(1), rmnode1); } } @Test public void testSingleNode() throws JSONException, Exception { - rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - testSingleNodeHelper("h2:1235", nm2, MediaType.APPLICATION_JSON); + addStartedNode("h1", 1234, 5120); + RMNode rmnode2 = addStartedNode("h2", 1235, 5121); + testSingleNodeHelper("h2:1235", rmnode2, MediaType.APPLICATION_JSON); } @Test public void testSingleNodeSlash() throws JSONException, Exception { - MockNM nm1 = rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); - testSingleNodeHelper("h1:1234/", nm1, MediaType.APPLICATION_JSON); + RMNode rmnode1 = addStartedNode("h1", 1234, 5120); + addStartedNode("h2", 1235, 5121); + testSingleNodeHelper("h1:1234/", rmnode1, MediaType.APPLICATION_JSON); } @Test public void testSingleNodeDefault() throws JSONException, Exception { - MockNM nm1 = rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); - testSingleNodeHelper("h1:1234/", nm1, ""); + RMNode rmnode1 = addStartedNode("h1", 1234, 5120); + addStartedNode("h2", 1235, 5121); + testSingleNodeHelper("h1:1234/", rmnode1, ""); } - public void testSingleNodeHelper(String nodeid, MockNM nm, String media) + public void testSingleNodeHelper(String nodeid, RMNode nm, String media) throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") @@ -412,8 +433,13 @@ public void testSingleNodeHelper(String nodeid, MockNM nm, String media) @Test public void testNonexistNode() throws JSONException, Exception { - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + // add h1 node in NEW state + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + // add h2 node in NEW state + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); + WebResource r = resource(); try { r.path("ws").path("v1").path("cluster").path("nodes") @@ -433,16 +459,16 @@ public void testNonexistNode() throws JSONException, Exception { String classname = exception.getString("javaClassName"); verifyNonexistNodeException(message, type, classname); - } finally { - rm.stop(); } } // test that the exception output defaults to JSON @Test public void testNonexistNodeDefault() throws JSONException, Exception { - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); WebResource r = resource(); try { r.path("ws").path("v1").path("cluster").path("nodes") @@ -460,16 +486,16 @@ public void testNonexistNodeDefault() throws JSONException, Exception { String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); verifyNonexistNodeException(message, type, classname); - } finally { - rm.stop(); } } // test that the exception output works in XML @Test public void testNonexistNodeXML() throws JSONException, Exception { - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); WebResource r = resource(); try { r.path("ws").path("v1").path("cluster").path("nodes") @@ -495,8 +521,6 @@ public void testNonexistNodeXML() throws JSONException, Exception { String classname = WebServicesTestUtils.getXmlString(element, "javaClassName"); verifyNonexistNodeException(message, type, classname); - } finally { - rm.stop(); } } @@ -511,8 +535,10 @@ private void verifyNonexistNodeException(String message, String type, String cla @Test public void testInvalidNode() throws JSONException, Exception { - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); WebResource r = resource(); try { @@ -538,17 +564,14 @@ public void testInvalidNode() throws JSONException, Exception { "IllegalArgumentException", type); WebServicesTestUtils.checkStringMatch("exception classname", "java.lang.IllegalArgumentException", classname); - } finally { - rm.stop(); } } @Test public void testNodesXML() throws JSONException, Exception { - rm.start(); WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - // MockNM nm2 = rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + RMNodeImpl rmnode1 = addRMNode(5120, nodeId1); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); @@ -563,16 +586,15 @@ public void testNodesXML() throws JSONException, Exception { assertEquals("incorrect number of elements", 1, nodesApps.getLength()); NodeList nodes = dom.getElementsByTagName("node"); assertEquals("incorrect number of elements", 1, nodes.getLength()); - verifyNodesXML(nodes, nm1); - rm.stop(); + verifyNodesXML(nodes, rmnode1); } @Test public void testSingleNodesXML() throws JSONException, Exception { - rm.start(); WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - // MockNM nm2 = rm.registerNode("h2:1235", 5121); + // add h2 node in NEW state + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + RMNodeImpl rmnode1 = addRMNode(5120, nodeId1); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").path("h1:1234").accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); @@ -587,16 +609,16 @@ public void testSingleNodesXML() throws JSONException, Exception { Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("node"); assertEquals("incorrect number of elements", 1, nodes.getLength()); - verifyNodesXML(nodes, nm1); - rm.stop(); + verifyNodesXML(nodes, rmnode1); } @Test public void testNodes2XML() throws JSONException, Exception { - rm.start(); WebResource r = resource(); - rm.registerNode("h1:1234", 5120); - rm.registerNode("h2:1235", 5121); + NodeId nodeId1 = NodeId.newInstance("h1", 1234); + addRMNode(5120, nodeId1); + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); @@ -612,20 +634,16 @@ public void testNodes2XML() throws JSONException, Exception { assertEquals("incorrect number of elements", 1, nodesApps.getLength()); NodeList nodes = dom.getElementsByTagName("node"); assertEquals("incorrect number of elements", 2, nodes.getLength()); - rm.stop(); } @Test public void testQueryAll() throws Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - MockNM nm2 = rm.registerNode("h2:1235", 5121); - MockNM nm3 = rm.registerNode("h3:1236", 5122); - rm.sendNodeStarted(nm1); - rm.sendNodeStarted(nm3); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW); - rm.sendNodeLost(nm3); + addStartedNode("h1", 1234, 5120); + // add h2 node in NEW state + NodeId nodeId2 = NodeId.newInstance("h2", 1235); + addRMNode(5121, nodeId2); + addStartedNode("h3", 1236, 5122); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes") @@ -643,23 +661,21 @@ public void testQueryAll() throws Exception { @Test public void testNodesResourceUtilization() throws JSONException, Exception { WebResource r = resource(); - MockNM nm1 = rm.registerNode("h1:1234", 5120); - rm.sendNodeStarted(nm1); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); - - RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes() - .get(nm1.getNodeId()); + RMNode rmnode1 = addStartedNode("h1", 1234, 5120); + NodeId nodeId1 = rmnode1.getNodeID(); NodeHealthStatus nodeHealth = NodeHealthStatus.newInstance(true, "test health report", System.currentTimeMillis()); ResourceUtilization nodeResource = ResourceUtilization.newInstance(4096, 0, (float) 10.5); ResourceUtilization containerResource = ResourceUtilization.newInstance( 2048, 0, (float) 5.05); - NodeStatus nodeStatus = NodeStatus.newInstance(nm1.getNodeId(), 0, + NodeStatus nodeStatus = + NodeStatus.newInstance(nodeId1, 0, new ArrayList(), null, nodeHealth, containerResource, nodeResource, null); - node.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus, null)); - rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING); + ((RMNodeImpl) rmnode1) + .handle(new RMNodeStatusEvent(nodeId1, nodeStatus, null)); + rm.NMwaitForState(nodeId1, NodeState.RUNNING); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("nodes").accept(MediaType.APPLICATION_JSON) @@ -675,10 +691,11 @@ public void testNodesResourceUtilization() throws JSONException, Exception { JSONObject info = nodeArray.getJSONObject(0); // verify the resource utilization - verifyNodeInfo(info, nm1); + verifyNodeInfo(info, rmnode1); } - public void verifyNodesXML(NodeList nodes, MockNM nm) throws JSONException, + public void verifyNodesXML(NodeList nodes, RMNode nm) + throws JSONException, Exception { for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); @@ -707,7 +724,7 @@ public void verifyNodesXML(NodeList nodes, MockNM nm) throws JSONException, } } - public void verifyNodeInfo(JSONObject nodeInfo, MockNM nm) + public void verifyNodeInfo(JSONObject nodeInfo, RMNode nm) throws JSONException, Exception { assertEquals("incorrect number of elements", 14, nodeInfo.length()); @@ -729,7 +746,7 @@ public void verifyNodeInfo(JSONObject nodeInfo, MockNM nm) resourceInfo.getDouble("containersCPUUsage")); } - public void verifyNodeInfoGeneric(MockNM nm, String state, String rack, + public void verifyNodeInfoGeneric(RMNode node, String state, String rack, String id, String nodeHostName, String nodeHTTPAddress, long lastHealthUpdate, String healthReport, int numContainers, long usedMemoryMB, long availMemoryMB, long usedVirtualCores, @@ -739,20 +756,21 @@ public void verifyNodeInfoGeneric(MockNM nm, String state, String rack, double containersCPUUsage) throws JSONException, Exception { - RMNode node = rm.getRMContext().getRMNodes().get(nm.getNodeId()); ResourceScheduler sched = rm.getResourceScheduler(); - SchedulerNodeReport report = sched.getNodeReport(nm.getNodeId()); + SchedulerNodeReport report = sched.getNodeReport(node.getNodeID()); WebServicesTestUtils.checkStringMatch("state", node.getState().toString(), state); WebServicesTestUtils.checkStringMatch("rack", node.getRackName(), rack); - WebServicesTestUtils.checkStringMatch("id", nm.getNodeId().toString(), id); - WebServicesTestUtils.checkStringMatch("nodeHostName", nm.getNodeId() + WebServicesTestUtils.checkStringMatch("id", node.getNodeID().toString(), + id); + WebServicesTestUtils.checkStringMatch("nodeHostName", + node.getNodeID() .getHost(), nodeHostName); WebServicesTestUtils.checkStringMatch("healthReport", String.valueOf(node.getHealthReport()), healthReport); - String expectedHttpAddress = nm.getNodeId().getHost() + ":" - + nm.getHttpPort(); + String expectedHttpAddress = + node.getNodeID().getHost() + ":" + node.getHttpPort(); WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", expectedHttpAddress, nodeHTTPAddress); WebServicesTestUtils.checkStringMatch("version",