public NodeInfo(RMNode ni, ResourceScheduler sched) { // JAXB needs this NodeId id = ni.GetNodeID(); SchedulerNodeReport report = sched.GetNodeReport(id); this.numContainers = 0; this.usedMemoryMB = 0; this.availMemoryMB = 0; if (report != null) { this.numContainers = report.GetNumContainers(); this.usedMemoryMB = report.GetUsedResource().GetMemory(); this.availMemoryMB = report.GetAvailableResource().GetMemory(); this.usedVirtualCores = report.GetUsedResource().GetVirtualCores(); this.availableVirtualCores = report.GetAvailableResource().GetVirtualCores(); } this.id = id.ToString(); this.rack = ni.GetRackName(); this.nodeHostName = ni.GetHostName(); this.state = ni.GetState(); this.nodeHTTPAddress = ni.GetHttpAddress(); this.lastHealthUpdate = ni.GetLastHealthReportTime(); this.healthReport = ni.GetHealthReport().ToString(); this.version = ni.GetNodeManagerVersion(); // add labels ICollection <string> labelSet = ni.GetNodeLabels(); if (labelSet != null) { Sharpen.Collections.AddAll(nodeLabels, labelSet); nodeLabels.Sort(); } }
/// <exception cref="System.Exception"/> public virtual void TestRMNodeStatusAfterReconnect() { // The node(127.0.0.1:1234) reconnected with RM. When it registered with // RM, RM set its lastNodeHeartbeatResponse's id to 0 asynchronously. But // the node's heartbeat come before RM succeeded setting the id to 0. DrainDispatcher dispatcher = new DrainDispatcher(); MockRM rm = new _MockRM_204(dispatcher); rm.Start(); MockNM nm1 = new MockNM("127.0.0.1:1234", 15120, rm.GetResourceTrackerService()); nm1.RegisterNode(); int i = 0; while (i < 3) { nm1.NodeHeartbeat(true); dispatcher.Await(); i++; } MockNM nm2 = new MockNM("127.0.0.1:1234", 15120, rm.GetResourceTrackerService()); nm2.RegisterNode(); RMNode rmNode = rm.GetRMContext().GetRMNodes()[nm2.GetNodeId()]; nm2.NodeHeartbeat(true); dispatcher.Await(); NUnit.Framework.Assert.AreEqual("Node is Not in Running state.", NodeState.Running , rmNode.GetState()); rm.Stop(); }
public virtual void TestSingleNodeQueryStateLost() { 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); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").Path ("h2:1234").Accept(MediaType.ApplicationJson).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); JSONObject info = json.GetJSONObject("node"); string id = info.Get("id").ToString(); NUnit.Framework.Assert.AreEqual("Incorrect Node Information.", "h2:1234", id); RMNode rmNode = rm.GetRMContext().GetInactiveRMNodes()["h2"]; WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", string.Empty, info.GetString ("nodeHTTPAddress")); WebServicesTestUtils.CheckStringMatch("state", rmNode.GetState().ToString(), info .GetString("state")); }
/// <exception cref="System.Exception"/> public virtual void NMwaitForState(NodeId nodeid, NodeState finalState) { RMNode node = GetRMContext().GetRMNodes()[nodeid]; NUnit.Framework.Assert.IsNotNull("node shouldn't be null", node); int timeoutSecs = 0; while (!finalState.Equals(node.GetState()) && timeoutSecs++ < 20) { System.Console.Out.WriteLine("Node State is : " + node.GetState() + " Waiting for state : " + finalState); Sharpen.Thread.Sleep(500); } System.Console.Out.WriteLine("Node State is : " + node.GetState()); NUnit.Framework.Assert.AreEqual("Node state is not correct (timedout)", finalState , node.GetState()); }
/// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/> /// <exception cref="System.Exception"/> public virtual void VerifyNodeInfoGeneric(MockNM nm, string state, string rack, string id, string nodeHostName, string nodeHTTPAddress, long lastHealthUpdate, string healthReport, int numContainers, long usedMemoryMB, long availMemoryMB, long usedVirtualCores , long availVirtualCores, string version) { RMNode node = rm.GetRMContext().GetRMNodes()[nm.GetNodeId()]; ResourceScheduler sched = rm.GetResourceScheduler(); SchedulerNodeReport report = sched.GetNodeReport(nm.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("healthReport", node.GetHealthReport().ToString (), healthReport); string expectedHttpAddress = nm.GetNodeId().GetHost() + ":" + nm.GetHttpPort(); WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", expectedHttpAddress, nodeHTTPAddress ); WebServicesTestUtils.CheckStringMatch("version", node.GetNodeManagerVersion(), version ); long expectedHealthUpdate = node.GetLastHealthReportTime(); NUnit.Framework.Assert.AreEqual("lastHealthUpdate doesn't match, got: " + lastHealthUpdate + " expected: " + expectedHealthUpdate, expectedHealthUpdate, lastHealthUpdate); if (report != null) { NUnit.Framework.Assert.AreEqual("numContainers doesn't match: " + numContainers, report.GetNumContainers(), numContainers); NUnit.Framework.Assert.AreEqual("usedMemoryMB doesn't match: " + usedMemoryMB, report .GetUsedResource().GetMemory(), usedMemoryMB); NUnit.Framework.Assert.AreEqual("availMemoryMB doesn't match: " + availMemoryMB, report.GetAvailableResource().GetMemory(), availMemoryMB); NUnit.Framework.Assert.AreEqual("usedVirtualCores doesn't match: " + usedVirtualCores , report.GetUsedResource().GetVirtualCores(), usedVirtualCores); NUnit.Framework.Assert.AreEqual("availVirtualCores doesn't match: " + availVirtualCores , report.GetAvailableResource().GetVirtualCores(), availVirtualCores); } }
public virtual void TestNodesQueryStateLost() { 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); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").QueryParam ("states", NodeState.Lost.ToString()).Accept(MediaType.ApplicationJson).Get <ClientResponse >(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); JSONObject nodes = json.GetJSONObject("nodes"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.Length() ); JSONArray nodeArray = nodes.GetJSONArray("node"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, nodeArray.Length ()); for (int i = 0; i < nodeArray.Length(); ++i) { JSONObject info = nodeArray.GetJSONObject(i); string host = info.Get("id").ToString().Split(":")[0]; RMNode rmNode = rm.GetRMContext().GetInactiveRMNodes()[host]; WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", string.Empty, info.GetString ("nodeHTTPAddress")); WebServicesTestUtils.CheckStringMatch("state", rmNode.GetState().ToString(), info .GetString("state")); } }