/// <exception cref="System.Exception"/> public virtual void TestAppReportForEmptyTrackingUrl() { configuration.Set(YarnConfiguration.ProxyAddress, "localhost:9090"); // overriding num of web server threads, see HttpServer.HTTP_MAXTHREADS configuration.SetInt("hadoop.http.max.threads", 5); TestWebAppProxyServlet.WebAppProxyServerForTest proxy = new TestWebAppProxyServlet.WebAppProxyServerForTest (this); proxy.Init(configuration); proxy.Start(); int proxyPort = proxy.proxy.proxyServer.GetConnectorAddress(0).Port; TestWebAppProxyServlet.AppReportFetcherForTest appReportFetcher = proxy.proxy.appReportFetcher; try { //set AHS_ENBALED = false to simulate getting the app report from RM configuration.SetBoolean(YarnConfiguration.ApplicationHistoryEnabled, false); ApplicationId app = ApplicationId.NewInstance(0, 0); appReportFetcher.answer = 6; Uri url = new Uri("http://localhost:" + proxyPort + "/proxy/" + app.ToString()); HttpURLConnection proxyConn = (HttpURLConnection)url.OpenConnection(); proxyConn.Connect(); try { proxyConn.GetResponseCode(); } catch (ConnectException) { } // Connection Exception is expected as we have set // appReportFetcher.answer = 6, which does not set anything for // original tracking url field in the app report. string appAddressInRm = WebAppUtils.GetResolvedRMWebAppURLWithScheme(configuration ) + "/cluster" + "/app/" + app.ToString(); NUnit.Framework.Assert.IsTrue("Webapp proxy servlet should have redirected to RM" , proxyConn.GetURL().ToString().Equals(appAddressInRm)); //set AHS_ENBALED = true to simulate getting the app report from AHS configuration.SetBoolean(YarnConfiguration.ApplicationHistoryEnabled, true); proxyConn = (HttpURLConnection)url.OpenConnection(); proxyConn.Connect(); try { proxyConn.GetResponseCode(); } catch (ConnectException) { } // Connection Exception is expected as we have set // appReportFetcher.answer = 6, which does not set anything for // original tracking url field in the app report. string appAddressInAhs = WebAppUtils.GetHttpSchemePrefix(configuration) + WebAppUtils .GetAHSWebAppURLWithoutScheme(configuration) + "/applicationhistory" + "/apps/" + app.ToString(); NUnit.Framework.Assert.IsTrue("Webapp proxy servlet should have redirected to AHS" , proxyConn.GetURL().ToString().Equals(appAddressInAhs)); } finally { proxy.Close(); } }
/// <exception cref="System.Exception"/> public virtual void TestWebAppProxyServlet() { configuration.Set(YarnConfiguration.ProxyAddress, "localhost:9090"); // overriding num of web server threads, see HttpServer.HTTP_MAXTHREADS configuration.SetInt("hadoop.http.max.threads", 5); TestWebAppProxyServlet.WebAppProxyServerForTest proxy = new TestWebAppProxyServlet.WebAppProxyServerForTest (this); proxy.Init(configuration); proxy.Start(); int proxyPort = proxy.proxy.proxyServer.GetConnectorAddress(0).Port; TestWebAppProxyServlet.AppReportFetcherForTest appReportFetcher = proxy.proxy.appReportFetcher; // wrong url try { // wrong url. Set wrong app ID Uri wrongUrl = new Uri("http://localhost:" + proxyPort + "/proxy/app"); HttpURLConnection proxyConn = (HttpURLConnection)wrongUrl.OpenConnection(); proxyConn.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpInternalError, proxyConn.GetResponseCode ()); // set true Application ID in url Uri url = new Uri("http://localhost:" + proxyPort + "/proxy/application_00_0"); proxyConn = (HttpURLConnection)url.OpenConnection(); // set cookie proxyConn.SetRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, proxyConn.GetResponseCode ()); NUnit.Framework.Assert.IsTrue(IsResponseCookiePresent(proxyConn, "checked_application_0_0000" , "true")); // cannot found application 1: null appReportFetcher.answer = 1; proxyConn = (HttpURLConnection)url.OpenConnection(); proxyConn.SetRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpNotFound, proxyConn.GetResponseCode ()); NUnit.Framework.Assert.IsFalse(IsResponseCookiePresent(proxyConn, "checked_application_0_0000" , "true")); // cannot found application 2: ApplicationNotFoundException appReportFetcher.answer = 4; proxyConn = (HttpURLConnection)url.OpenConnection(); proxyConn.SetRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpNotFound, proxyConn.GetResponseCode ()); NUnit.Framework.Assert.IsFalse(IsResponseCookiePresent(proxyConn, "checked_application_0_0000" , "true")); // wrong user appReportFetcher.answer = 2; proxyConn = (HttpURLConnection)url.OpenConnection(); proxyConn.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, proxyConn.GetResponseCode ()); string s = ReadInputStream(proxyConn.GetInputStream()); NUnit.Framework.Assert.IsTrue(s.Contains("to continue to an Application Master web interface owned by" )); NUnit.Framework.Assert.IsTrue(s.Contains("WARNING: The following page may not be safe!" )); //case if task has a not running status appReportFetcher.answer = 3; proxyConn = (HttpURLConnection)url.OpenConnection(); proxyConn.SetRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpOk, proxyConn.GetResponseCode ()); // test user-provided path and query parameter can be appended to the // original tracking url appReportFetcher.answer = 5; Uri clientUrl = new Uri("http://localhost:" + proxyPort + "/proxy/application_00_0/test/tez?x=y&h=p" ); proxyConn = (HttpURLConnection)clientUrl.OpenConnection(); proxyConn.Connect(); Log.Info(string.Empty + proxyConn.GetURL()); Log.Info("ProxyConn.getHeaderField(): " + proxyConn.GetHeaderField(ProxyUtils.Location )); NUnit.Framework.Assert.AreEqual("http://localhost:" + originalPort + "/foo/bar/test/tez?a=b&x=y&h=p#main" , proxyConn.GetURL().ToString()); } finally { proxy.Close(); } }