YARN-4947. Test timeout is happening for TestRMWebServicesNodes. Contributed by Bibin A Chundatt
(cherry picked from commit 75e0450593
)
This commit is contained in:
parent
313b4dbf28
commit
5aad4070b2
|
@ -34,17 +34,22 @@ import org.apache.hadoop.conf.Configuration;
|
|||
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 +135,21 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
Exception {
|
||||
|
||||
WebResource r = resource();
|
||||
MockNM nm1 = rm.registerNode("h1:1234", 5120);
|
||||
MockNM nm2 = rm.registerNode("h2:1235", 5121);
|
||||
rm.sendNodeStarted(nm1);
|
||||
rm.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.NEW);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
// h2 will be in NEW state
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
|
||||
MockNM nm3 = rm.registerNode("h3:1236", 5122);
|
||||
rm.waitForState(nm3.getNodeId(), NodeState.NEW);
|
||||
rm.sendNodeStarted(nm3);
|
||||
rm.waitForState(nm3.getNodeId(), NodeState.RUNNING);
|
||||
RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes()
|
||||
.get(nm3.getNodeId());
|
||||
RMNode node3 = getRunningRMNode("h3", 1236, 5122);
|
||||
NodeId nodeId3 = node3.getNodeID();
|
||||
|
||||
RMNode node = 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<ContainerStatus>(), null, nodeHealth, null, null, null);
|
||||
node.handle(new RMNodeStatusEvent(nm3.getNodeId(), nodeStatus, null));
|
||||
rm.waitForState(nm3.getNodeId(), NodeState.UNHEALTHY);
|
||||
((RMNodeImpl) node)
|
||||
.handle(new RMNodeStatusEvent(nodeId3, nodeStatus, null));
|
||||
rm.waitForState(nodeId3, NodeState.UNHEALTHY);
|
||||
|
||||
ClientResponse response =
|
||||
r.path("ws").path("v1").path("cluster").path("nodes")
|
||||
|
@ -163,14 +165,38 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
assertEquals("incorrect number of elements", 3, nodeArray.length());
|
||||
}
|
||||
|
||||
private RMNode getRunningRMNode(String host, int port, int memory) {
|
||||
RMNodeImpl rmnode1 = getNewRMNode(host, port, memory);
|
||||
sendStartedEvent(rmnode1);
|
||||
return rmnode1;
|
||||
}
|
||||
|
||||
private void sendStartedEvent(RMNode node) {
|
||||
((RMNodeImpl) node)
|
||||
.handle(new RMNodeStartedEvent(node.getNodeID(), null, null));
|
||||
}
|
||||
|
||||
private void sendLostEvent(RMNode node) {
|
||||
((RMNodeImpl) node)
|
||||
.handle(new RMNodeEvent(node.getNodeID(), RMNodeEventType.EXPIRE));
|
||||
}
|
||||
|
||||
private RMNodeImpl getNewRMNode(String host, int port, int memory) {
|
||||
NodeId nodeId = NodeId.newInstance(host, port);
|
||||
RMNodeImpl nodeImpl = new RMNodeImpl(nodeId, rm.getRMContext(),
|
||||
nodeId.getHost(), nodeId.getPort(), nodeId.getPort() + 1,
|
||||
RackResolver.resolve(nodeId.getHost()), Resource.newInstance(memory, 4),
|
||||
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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.NEW);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
// h2 will be in NEW state
|
||||
RMNode rmnode2 = getNewRMNode("h2", 1235, 5121);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").queryParam("states", NodeState.NEW.toString())
|
||||
|
@ -185,14 +211,14 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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);
|
||||
getNewRMNode("h1", 1234, 5120);
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes")
|
||||
|
@ -207,8 +233,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
@Test
|
||||
public void testNodesQueryStateInvalid() throws JSONException, Exception {
|
||||
WebResource r = resource();
|
||||
rm.registerNode("h1:1234", 5120);
|
||||
rm.registerNode("h2:1235", 5121);
|
||||
getNewRMNode("h1", 1234, 5120);
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
|
||||
try {
|
||||
r.path("ws").path("v1").path("cluster").path("nodes")
|
||||
|
@ -238,22 +264,16 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.RUNNING);
|
||||
rm.sendNodeLost(nm1);
|
||||
rm.sendNodeLost(nm2);
|
||||
RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
|
||||
sendLostEvent(rmnode1);
|
||||
RMNode rmnode2 = getRunningRMNode("h2", 1235, 5121);
|
||||
sendLostEvent(rmnode2);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").queryParam("states", NodeState.LOST.toString())
|
||||
|
@ -280,14 +300,9 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
@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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.RUNNING);
|
||||
rm.sendNodeLost(nm1);
|
||||
rm.sendNodeLost(nm2);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
RMNode rmnode2 = getRunningRMNode("h2", 1234, 5121);
|
||||
sendLostEvent(rmnode2);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").path("h2:1234").accept(MediaType.APPLICATION_JSON)
|
||||
|
@ -300,8 +315,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
|
||||
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 +326,9 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
@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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.NEW);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
// h2 will be in NEW state
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").queryParam("states", "running")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
|
@ -331,11 +344,9 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
@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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.NEW);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
// h2 will be in NEW state
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").queryParam("states", "UNHEALTHY")
|
||||
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
|
||||
|
@ -348,12 +359,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.RUNNING);
|
||||
RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
|
||||
RMNode rmnode2 = getRunningRMNode("h2", 1235, 5121);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path(path).accept(media).get(ClientResponse.class);
|
||||
|
@ -368,36 +375,36 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
RMNode rmnode2 = getRunningRMNode("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 = getRunningRMNode("h1", 1234, 5120);
|
||||
getRunningRMNode("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 = getRunningRMNode("h1", 1234, 5120);
|
||||
getRunningRMNode("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 +419,10 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
|
||||
@Test
|
||||
public void testNonexistNode() throws JSONException, Exception {
|
||||
rm.registerNode("h1:1234", 5120);
|
||||
rm.registerNode("h2:1235", 5121);
|
||||
// add h1 node in NEW state
|
||||
getNewRMNode("h1", 1234, 5120);
|
||||
// add h2 node in NEW state
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
WebResource r = resource();
|
||||
try {
|
||||
r.path("ws").path("v1").path("cluster").path("nodes")
|
||||
|
@ -433,16 +442,14 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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);
|
||||
getNewRMNode("h1", 1234, 5120);
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
WebResource r = resource();
|
||||
try {
|
||||
r.path("ws").path("v1").path("cluster").path("nodes")
|
||||
|
@ -460,16 +467,14 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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);
|
||||
getNewRMNode("h1", 1234, 5120);
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
WebResource r = resource();
|
||||
try {
|
||||
r.path("ws").path("v1").path("cluster").path("nodes")
|
||||
|
@ -495,8 +500,6 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
String classname = WebServicesTestUtils.getXmlString(element,
|
||||
"javaClassName");
|
||||
verifyNonexistNodeException(message, type, classname);
|
||||
} finally {
|
||||
rm.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -511,8 +514,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
|
||||
@Test
|
||||
public void testInvalidNode() throws JSONException, Exception {
|
||||
rm.registerNode("h1:1234", 5120);
|
||||
rm.registerNode("h2:1235", 5121);
|
||||
getNewRMNode("h1", 1234, 5120);
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
|
||||
WebResource r = resource();
|
||||
try {
|
||||
|
@ -538,16 +541,13 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
"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);
|
||||
RMNodeImpl rmnode1 = getNewRMNode("h1", 1234, 5120);
|
||||
// MockNM nm2 = rm.registerNode("h2:1235", 5121);
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").accept(MediaType.APPLICATION_XML)
|
||||
|
@ -563,15 +563,14 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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);
|
||||
// add h2 node in NEW state
|
||||
RMNodeImpl rmnode1 = getNewRMNode("h1", 1234, 5120);
|
||||
// MockNM nm2 = rm.registerNode("h2:1235", 5121);
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").path("h1:1234").accept(MediaType.APPLICATION_XML)
|
||||
|
@ -587,16 +586,14 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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);
|
||||
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);
|
||||
|
@ -612,20 +609,17 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
rm.waitForState(nm2.getNodeId(), NodeState.NEW);
|
||||
rm.sendNodeLost(nm3);
|
||||
getRunningRMNode("h1", 1234, 5120);
|
||||
// add h2 node in NEW state
|
||||
getNewRMNode("h2", 1235, 5121);
|
||||
// add lost node
|
||||
RMNode nm3 = getRunningRMNode("h3", 1236, 5122);
|
||||
sendLostEvent(nm3);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes")
|
||||
|
@ -643,23 +637,22 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
@Test
|
||||
public void testNodesResourceUtilization() throws JSONException, Exception {
|
||||
WebResource r = resource();
|
||||
MockNM nm1 = rm.registerNode("h1:1234", 5120);
|
||||
rm.sendNodeStarted(nm1);
|
||||
rm.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
RMNode rmnode1 = getRunningRMNode("h1", 1234, 5120);
|
||||
NodeId nodeId1 = rmnode1.getNodeID();
|
||||
|
||||
RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes()
|
||||
.get(nm1.getNodeId());
|
||||
RMNodeImpl node = (RMNodeImpl) rm.getRMContext().getRMNodes().get(nodeId1);
|
||||
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<ContainerStatus>(), null, nodeHealth, containerResource,
|
||||
nodeResource, null);
|
||||
node.handle(new RMNodeStatusEvent(nm1.getNodeId(), nodeStatus, null));
|
||||
rm.waitForState(nm1.getNodeId(), NodeState.RUNNING);
|
||||
node.handle(new RMNodeStatusEvent(nodeId1, nodeStatus, null));
|
||||
rm.waitForState(nodeId1, NodeState.RUNNING);
|
||||
|
||||
ClientResponse response = r.path("ws").path("v1").path("cluster")
|
||||
.path("nodes").accept(MediaType.APPLICATION_JSON)
|
||||
|
@ -675,10 +668,11 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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 +701,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
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 +723,7 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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 +733,20 @@ public class TestRMWebServicesNodes extends JerseyTestBase {
|
|||
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()
|
||||
.getHost(), nodeHostName);
|
||||
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",
|
||||
|
|
Loading…
Reference in New Issue