public virtual void TestContainerLogs() { WebResource r = Resource(); ContainerId containerId = BuilderUtils.NewContainerId(0, 0, 0, 0); string containerIdStr = BuilderUtils.NewContainerId(0, 0, 0, 0).ToString(); ApplicationAttemptId appAttemptId = containerId.GetApplicationAttemptId(); ApplicationId appId = appAttemptId.GetApplicationId(); string appIdStr = appId.ToString(); string filename = "logfile1"; string logMessage = "log message\n"; nmContext.GetApplications()[appId] = new ApplicationImpl(null, "user", appId, null , nmContext); MockContainer container = new MockContainer(appAttemptId, new AsyncDispatcher(), new Configuration(), "user", appId, 1); container.SetState(ContainerState.Running); nmContext.GetContainers()[containerId] = container; // write out log file Path path = dirsHandler.GetLogPathForWrite(ContainerLaunch.GetRelativeContainerLogDir (appIdStr, containerIdStr) + "/" + filename, false); FilePath logFile = new FilePath(path.ToUri().GetPath()); logFile.DeleteOnExit(); NUnit.Framework.Assert.IsTrue("Failed to create log dir", logFile.GetParentFile() .Mkdirs()); PrintWriter pw = new PrintWriter(logFile); pw.Write(logMessage); pw.Close(); // ask for it ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("containerlogs" ).Path(containerIdStr).Path(filename).Accept(MediaType.TextPlain).Get <ClientResponse >(); string responseText = response.GetEntity <string>(); NUnit.Framework.Assert.AreEqual(logMessage, responseText); // ask for file that doesn't exist response = r.Path("ws").Path("v1").Path("node").Path("containerlogs").Path(containerIdStr ).Path("uhhh").Accept(MediaType.TextPlain).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(ClientResponse.Status.NotFound.GetStatusCode(), response .GetStatus()); responseText = response.GetEntity <string>(); NUnit.Framework.Assert.IsTrue(responseText.Contains("Cannot find this log on the local disk." )); // After container is completed, it is removed from nmContext Sharpen.Collections.Remove(nmContext.GetContainers(), containerId); NUnit.Framework.Assert.IsNull(nmContext.GetContainers()[containerId]); response = r.Path("ws").Path("v1").Path("node").Path("containerlogs").Path(containerIdStr ).Path(filename).Accept(MediaType.TextPlain).Get <ClientResponse>(); responseText = response.GetEntity <string>(); NUnit.Framework.Assert.AreEqual(logMessage, responseText); }
public virtual void TestNodeAppsState() { WebResource r = Resource(); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app = new MockApp(1); nmContext.GetApplications()[app.GetAppId()] = app; AddAppContainers(app); MockApp app2 = new MockApp("foo", 1234, 2); nmContext.GetApplications()[app2.GetAppId()] = app2; Dictionary <string, string> hash2 = AddAppContainers(app2); app2.SetState(ApplicationState.Running); ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam ("state", ApplicationState.Running.ToString()).Accept(MediaType.ApplicationJson) .Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); JSONObject info = json.GetJSONObject("apps"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length()); JSONArray appInfo = info.GetJSONArray("app"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, appInfo.Length ()); VerifyNodeAppInfo(appInfo.GetJSONObject(0), app2, hash2); }
public virtual void TestTaskAttemptIdXMLCounters() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); foreach (Task task in jobsMap[id].GetTasks().Values) { string tid = MRApps.ToString(task.GetID()); foreach (TaskAttempt att in task.GetAttempts().Values) { TaskAttemptId attemptid = att.GetID(); string attid = MRApps.ToString(attemptid); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").Path(jobId).Path("tasks").Path(tid).Path("attempts").Path(attid). Path("counters").Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); 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("jobTaskAttemptCounters"); VerifyHsTaskCountersXML(nodes, att); } } } }
public virtual void TestTaskAttemptIdCounters() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); foreach (Task task in jobsMap[id].GetTasks().Values) { string tid = MRApps.ToString(task.GetID()); foreach (TaskAttempt att in task.GetAttempts().Values) { TaskAttemptId attemptid = att.GetID(); string attid = MRApps.ToString(attemptid); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").Path(jobId).Path("tasks").Path(tid).Path("attempts").Path(attid). Path("counters").Accept(MediaType.ApplicationJson).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); JSONObject info = json.GetJSONObject("jobTaskAttemptCounters"); VerifyHsJobTaskAttemptCounters(info, att); } } } }
public virtual void TestNodeAppsStateInvalidDefault() { WebResource r = Resource(); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app = new MockApp(1); nmContext.GetApplications()[app.GetAppId()] = app; AddAppContainers(app); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app2 = new MockApp("foo", 1234, 2); nmContext.GetApplications()[app2.GetAppId()] = app2; AddAppContainers(app2); try { r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam("state", "FOO_STATE" ).Get <JSONObject>(); NUnit.Framework.Assert.Fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.GetResponse(); NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus ()); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject msg = response.GetEntity <JSONObject>(); JSONObject exception = msg.GetJSONObject("RemoteException"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length ()); string message = exception.GetString("message"); string type = exception.GetString("exception"); string classname = exception.GetString("javaClassName"); VerifyStateInvalidException(message, type, classname); } }
public virtual void TestNodes2XML() { rm.Start(); WebResource r = Resource(); rm.RegisterNode("h1:1234", 5120); rm.RegisterNode("h2:1235", 5121); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").Accept (MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); 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"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodesApps.GetLength ()); NodeList nodes = dom.GetElementsByTagName("node"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, nodes.GetLength ()); rm.Stop(); }
public virtual void TestMultipleContainers() { ApplicationId appId = ApplicationId.NewInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(appId, 1); WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("applicationhistory").Path ("apps").Path(appId.ToString()).Path("appattempts").Path(appAttemptId.ToString() ).Path("containers").QueryParam("user.name", Users[round]).Accept(MediaType.ApplicationJson ).Get <ClientResponse>(); if (round == 1) { NUnit.Framework.Assert.AreEqual(ClientResponse.Status.Forbidden, response.GetClientResponseStatus ()); return; } NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); JSONObject containers = json.GetJSONObject("containers"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, containers.Length ()); JSONArray array = containers.GetJSONArray("container"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 5, array.Length() ); }
public virtual void TestNodeContainerXML() { WebResource r = Resource(); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app = new MockApp(1); nmContext.GetApplications()[app.GetAppId()] = app; AddAppContainers(app); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app2 = new MockApp(2); nmContext.GetApplications()[app2.GetAppId()] = app2; AddAppContainers(app2); ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("containers") .Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); 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("container"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 4, nodes.GetLength ()); }
/// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/> /// <exception cref="System.Exception"/> public virtual void TestNodeHelper(string path, string media) { WebResource r = Resource(); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app = new MockApp(1); nmContext.GetApplications()[app.GetAppId()] = app; AddAppContainers(app); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app2 = new MockApp(2); nmContext.GetApplications()[app2.GetAppId()] = app2; AddAppContainers(app2); ClientResponse response = r.Path("ws").Path("v1").Path("node").Path(path).Accept( media).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); JSONObject info = json.GetJSONObject("containers"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length()); JSONArray conInfo = info.GetJSONArray("container"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 4, conInfo.Length ()); for (int i = 0; i < conInfo.Length(); i++) { VerifyNodeContainerInfo(conInfo.GetJSONObject(i), nmContext.GetContainers()[ConverterUtils .ToContainerId(conInfo.GetJSONObject(i).GetString("id"))]); } }
public virtual void TestPerUserResourcesJSON() { //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 JSON WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("scheduler/" ).Accept(MediaType.ApplicationJson).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); JSONObject schedulerInfo = json.GetJSONObject("scheduler").GetJSONObject("schedulerInfo" ); JSONObject b1 = GetSubQueue(GetSubQueue(schedulerInfo, "b"), "b1"); //Check users user1 and user2 exist in b1 JSONArray users = b1.GetJSONObject("users").GetJSONArray("user"); for (int i = 0; i < 2; ++i) { JSONObject user = users.GetJSONObject(i); NUnit.Framework.Assert.IsTrue("User isn't user1 or user2", user.GetString("username" ).Equals("user1") || user.GetString("username").Equals("user2")); user.GetInt("numActiveApplications"); user.GetInt("numPendingApplications"); CheckResourcesUsed(user); } } finally { rm.Stop(); } }
public virtual void TestTasksXML() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); ClientResponse response = r.Path("ws").Path("v1").Path("mapreduce").Path("jobs"). Path(jobId).Path("tasks").Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList tasks = dom.GetElementsByTagName("tasks"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, tasks.GetLength ()); NodeList task = dom.GetElementsByTagName("task"); VerifyAMTaskXML(task, jobsMap[id]); } }
public virtual void TestJobsQueryFinishTimeBeginEnd() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); int size = jobsMap.Count; // figure out the mid end time - we expect atleast 3 jobs AList <long> finishTime = new AList <long>(size); foreach (KeyValuePair <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> entry in jobsMap) { finishTime.AddItem(entry.Value.GetReport().GetFinishTime()); } finishTime.Sort(); NUnit.Framework.Assert.IsTrue("Error we must have atleast 3 jobs", size >= 3); long midFinishTime = finishTime[size - 2]; ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").QueryParam("finishedTimeBegin", 40000.ToString()).QueryParam("finishedTimeEnd" , midFinishTime.ToString()).Accept(MediaType.ApplicationJson).Get <ClientResponse >(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); JSONObject jobs = json.GetJSONObject("jobs"); JSONArray arr = jobs.GetJSONArray("job"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", size - 1, arr.Length ()); }
public virtual void TestJobsQueryStateNone() { WebResource r = Resource(); AList <JobState> JobStates = new AList <JobState>(Arrays.AsList(JobState.Values())); // find a state that isn't in use IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (KeyValuePair <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> entry in jobsMap) { JobStates.Remove(entry.Value.GetState()); } NUnit.Framework.Assert.IsTrue("No unused job states", JobStates.Count > 0); JobState notInUse = JobStates[0]; ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").QueryParam("state", notInUse.ToString()).Accept(MediaType.ApplicationJson ).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); NUnit.Framework.Assert.AreEqual("jobs is not null", JSONObject.Null, json.Get("jobs" )); }
public virtual void TestJobsQueryStartTimeNegative() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").QueryParam("startedTimeBegin", (-1000).ToString()).Accept(MediaType .ApplicationJson).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus ()); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject msg = response.GetEntity <JSONObject>(); JSONObject exception = msg.GetJSONObject("RemoteException"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length ()); string message = exception.GetString("message"); string type = exception.GetString("exception"); string classname = exception.GetString("javaClassName"); WebServicesTestUtils.CheckStringMatch("exception message", "java.lang.Exception: startedTimeBegin must be greater than 0" , message); WebServicesTestUtils.CheckStringMatch("exception type", "BadRequestException", type ); WebServicesTestUtils.CheckStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException" , classname); }
public virtual void TestJobsQueryFinishTimeEndInvalidformat() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").QueryParam("finishedTimeEnd", "efsd").Accept(MediaType.ApplicationJson ).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus ()); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject msg = response.GetEntity <JSONObject>(); JSONObject exception = msg.GetJSONObject("RemoteException"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length ()); string message = exception.GetString("message"); string type = exception.GetString("exception"); string classname = exception.GetString("javaClassName"); WebServicesTestUtils.CheckStringMatch("exception message", "java.lang.Exception: Invalid number format: For input string: \"efsd\"" , message); WebServicesTestUtils.CheckStringMatch("exception type", "BadRequestException", type ); WebServicesTestUtils.CheckStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException" , classname); }
public virtual void TestNodesQueryNew() { 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); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").QueryParam ("states", NodeState.New.ToString()).Accept(MediaType.ApplicationJson).Get <ClientResponse >(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); 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", 1, nodeArray.Length ()); JSONObject info = nodeArray.GetJSONObject(0); VerifyNodeInfo(info, nm2); }
public virtual void TestJobsQueryStateInvalid() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").QueryParam("state", "InvalidState").Accept(MediaType.ApplicationJson ).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus ()); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject msg = response.GetEntity <JSONObject>(); JSONObject exception = msg.GetJSONObject("RemoteException"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length ()); string message = exception.GetString("message"); string type = exception.GetString("exception"); string classname = exception.GetString("javaClassName"); WebServicesTestUtils.CheckStringContains("exception message", "org.apache.hadoop.mapreduce.v2.api.records.JobState.InvalidState" , message); WebServicesTestUtils.CheckStringMatch("exception type", "IllegalArgumentException" , type); WebServicesTestUtils.CheckStringMatch("exception classname", "java.lang.IllegalArgumentException" , classname); }
public virtual void TestQueryAll() { 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); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").QueryParam ("states", Joiner.On(',').Join(EnumSet.AllOf <NodeState>())).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", 3, nodeArray.Length ()); }
public virtual void TestSingleAttempt() { ApplicationId appId = ApplicationId.NewInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(appId, 1); WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("applicationhistory").Path ("apps").Path(appId.ToString()).Path("appattempts").Path(appAttemptId.ToString() ).QueryParam("user.name", Users[round]).Accept(MediaType.ApplicationJson).Get <ClientResponse >(); if (round == 1) { NUnit.Framework.Assert.AreEqual(ClientResponse.Status.Forbidden, response.GetClientResponseStatus ()); return; } NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); JSONObject appAttempt = json.GetJSONObject("appAttempt"); NUnit.Framework.Assert.AreEqual(appAttemptId.ToString(), appAttempt.GetString("appAttemptId" )); NUnit.Framework.Assert.AreEqual("test host", appAttempt.GetString("host")); NUnit.Framework.Assert.AreEqual("test diagnostics info", appAttempt.GetString("diagnosticsInfo" )); NUnit.Framework.Assert.AreEqual("test tracking url", appAttempt.GetString("trackingUrl" )); NUnit.Framework.Assert.AreEqual(YarnApplicationAttemptState.Finished.ToString(), appAttempt.Get("appAttemptState")); }
public virtual void TestTaskIdXML() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); foreach (Task task in jobsMap[id].GetTasks().Values) { string tid = MRApps.ToString(task.GetID()); ClientResponse response = r.Path("ws").Path("v1").Path("mapreduce").Path("jobs"). Path(jobId).Path("tasks").Path(tid).Accept(MediaType.ApplicationXml).Get <ClientResponse >(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); 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("task"); for (int i = 0; i < nodes.GetLength(); i++) { Element element = (Element)nodes.Item(i); VerifyAMSingleTaskXML(element, task); } } } }
public virtual void TestNonexistNodeDefault() { rm.RegisterNode("h1:1234", 5120); rm.RegisterNode("h2:1235", 5121); WebResource r = Resource(); try { r.Path("ws").Path("v1").Path("cluster").Path("nodes").Path("node_invalid:99").Get <JSONObject>(); NUnit.Framework.Assert.Fail("should have thrown exception on non-existent nodeid" ); } catch (UniformInterfaceException ue) { ClientResponse response = ue.GetResponse(); NUnit.Framework.Assert.AreEqual(ClientResponse.Status.NotFound, response.GetClientResponseStatus ()); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject msg = response.GetEntity <JSONObject>(); JSONObject exception = msg.GetJSONObject("RemoteException"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length ()); string message = exception.GetString("message"); string type = exception.GetString("exception"); string classname = exception.GetString("javaClassName"); VerifyNonexistNodeException(message, type, classname); } finally { 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")); }
public virtual void TestSingleApp() { ApplicationId appId = ApplicationId.NewInstance(0, 1); WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("applicationhistory").Path ("apps").Path(appId.ToString()).QueryParam("user.name", Users[round]).Accept(MediaType .ApplicationJson).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); JSONObject app = json.GetJSONObject("app"); NUnit.Framework.Assert.AreEqual(appId.ToString(), app.GetString("appId")); NUnit.Framework.Assert.AreEqual("test app", app.Get("name")); NUnit.Framework.Assert.AreEqual(round == 0 ? "test diagnostics info" : string.Empty , app.Get("diagnosticsInfo")); NUnit.Framework.Assert.AreEqual("test queue", app.Get("queue")); NUnit.Framework.Assert.AreEqual("user1", app.Get("user")); NUnit.Framework.Assert.AreEqual("test app type", app.Get("type")); NUnit.Framework.Assert.AreEqual(FinalApplicationStatus.Undefined.ToString(), app. Get("finalAppStatus")); NUnit.Framework.Assert.AreEqual(YarnApplicationState.Finished.ToString(), app.Get ("appState")); }
public virtual void TestJobsQueryState() { WebResource r = Resource(); // we only create 3 jobs and it cycles through states so we should have 3 unique states IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); string queryState = "BOGUS"; JobId jid = null; foreach (KeyValuePair <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> entry in jobsMap) { jid = entry.Value.GetID(); queryState = entry.Value.GetState().ToString(); break; } ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").QueryParam("state", queryState).Accept(MediaType.ApplicationJson) .Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length()); JSONObject jobs = json.GetJSONObject("jobs"); JSONArray arr = jobs.GetJSONArray("job"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, arr.Length()); JSONObject info = arr.GetJSONObject(0); Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = appContext.GetPartialJob(jid); VerifyJobsUtils.VerifyHsJobPartial(info, job); }
public virtual void TestInvalidApp() { ApplicationId appId = ApplicationId.NewInstance(0, MaxApps + 1); WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("applicationhistory").Path ("apps").Path(appId.ToString()).QueryParam("user.name", Users[round]).Accept(MediaType .ApplicationJson).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual("404 not found expected", ClientResponse.Status.NotFound , response.GetClientResponseStatus()); }
public virtual void TestInfoXML() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("info/").Accept (MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); VerifyHSInfoXML(xml, appContext); }
public virtual void TestClusterSchedulerFifoXML() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("scheduler" ).Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); VerifySchedulerFifoXML(xml); }
public virtual void TestBlacklistedNodesXML() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("mapreduce").Path("blacklistednodes" ).Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); VerifyBlacklistedNodesInfoXML(xml, appContext); }
public virtual void TestNodeInfoDefault() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("info").Get <ClientResponse >(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); VerifyNodeInfo(json); }
public virtual void TestClusterSchedulerDefault() { WebResource r = Resource(); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("scheduler" ).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType() ); JSONObject json = response.GetEntity <JSONObject>(); VerifyClusterScheduler(json); }