|
@@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.net.ConnectException;
|
|
|
import java.net.HttpCookie;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URI;
|
|
@@ -76,6 +77,7 @@ public class TestWebAppProxyServlet {
|
|
|
private static int numberOfHeaders = 0;
|
|
|
private static final String UNKNOWN_HEADER = "Unknown-Header";
|
|
|
private static boolean hasUnknownHeader = false;
|
|
|
+ Configuration configuration = new Configuration();
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -137,8 +139,6 @@ public class TestWebAppProxyServlet {
|
|
|
|
|
|
@Test(timeout=5000)
|
|
|
public void testWebAppProxyServlet() throws Exception {
|
|
|
-
|
|
|
- Configuration configuration = new Configuration();
|
|
|
configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
|
|
|
// overriding num of web server threads, see HttpServer.HTTP_MAXTHREADS
|
|
|
configuration.setInt("hadoop.http.max.threads", 5);
|
|
@@ -166,6 +166,7 @@ public class TestWebAppProxyServlet {
|
|
|
proxyConn.connect();
|
|
|
assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR,
|
|
|
proxyConn.getResponseCode());
|
|
|
+
|
|
|
// set true Application ID in url
|
|
|
URL url = new URL("http://localhost:" + proxyPort + "/proxy/application_00_0");
|
|
|
proxyConn = (HttpURLConnection) url.openConnection();
|
|
@@ -220,12 +221,69 @@ public class TestWebAppProxyServlet {
|
|
|
LOG.info("ProxyConn.getHeaderField(): " + proxyConn.getHeaderField(ProxyUtils.LOCATION));
|
|
|
assertEquals("http://localhost:" + originalPort
|
|
|
+ "/foo/bar/test/tez?a=b&x=y&h=p#main", proxyConn.getURL().toString());
|
|
|
-
|
|
|
} finally {
|
|
|
proxy.close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test(timeout=5000)
|
|
|
+ public void testAppReportForEmptyTrackingUrl() throws Exception {
|
|
|
+ configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9090");
|
|
|
+ // overriding num of web server threads, see HttpServer.HTTP_MAXTHREADS
|
|
|
+ configuration.setInt("hadoop.http.max.threads", 5);
|
|
|
+ WebAppProxyServerForTest proxy = new WebAppProxyServerForTest();
|
|
|
+ proxy.init(configuration);
|
|
|
+ proxy.start();
|
|
|
+
|
|
|
+ int proxyPort = proxy.proxy.proxyServer.getConnectorAddress(0).getPort();
|
|
|
+ AppReportFetcherForTest appReportFetcher = proxy.proxy.appReportFetcher;
|
|
|
+
|
|
|
+ try {
|
|
|
+ //set AHS_ENBALED = false to simulate getting the app report from RM
|
|
|
+ configuration.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
|
|
|
+ false);
|
|
|
+ ApplicationId app = ApplicationId.newInstance(0, 0);
|
|
|
+ appReportFetcher.answer = 6;
|
|
|
+ URL url = new URL("http://localhost:" + proxyPort +
|
|
|
+ "/proxy/" + app.toString());
|
|
|
+ HttpURLConnection proxyConn = (HttpURLConnection) url.openConnection();
|
|
|
+ proxyConn.connect();
|
|
|
+ try {
|
|
|
+ proxyConn.getResponseCode();
|
|
|
+ } catch (ConnectException e) {
|
|
|
+ // 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();
|
|
|
+ assertTrue("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.APPLICATION_HISTORY_ENABLED,
|
|
|
+ true);
|
|
|
+ proxyConn = (HttpURLConnection) url.openConnection();
|
|
|
+ proxyConn.connect();
|
|
|
+ try {
|
|
|
+ proxyConn.getResponseCode();
|
|
|
+ } catch (ConnectException e) {
|
|
|
+ // 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();
|
|
|
+ assertTrue("Webapp proxy servlet should have redirected to AHS",
|
|
|
+ proxyConn.getURL().toString().equals(appAddressInAhs));
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ proxy.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test(timeout=5000)
|
|
|
public void testWebAppProxyPassThroughHeaders() throws Exception {
|
|
|
Configuration configuration = new Configuration();
|
|
@@ -398,49 +456,70 @@ public class TestWebAppProxyServlet {
|
|
|
}
|
|
|
|
|
|
private class AppReportFetcherForTest extends AppReportFetcher {
|
|
|
-
|
|
|
int answer = 0;
|
|
|
|
|
|
public AppReportFetcherForTest(Configuration conf) {
|
|
|
super(conf);
|
|
|
}
|
|
|
|
|
|
- public ApplicationReport getApplicationReport(ApplicationId appId)
|
|
|
+ public FetchedAppReport getApplicationReport(ApplicationId appId)
|
|
|
throws YarnException {
|
|
|
if (answer == 0) {
|
|
|
return getDefaultApplicationReport(appId);
|
|
|
} else if (answer == 1) {
|
|
|
return null;
|
|
|
} else if (answer == 2) {
|
|
|
- ApplicationReport result = getDefaultApplicationReport(appId);
|
|
|
- result.setUser("user");
|
|
|
+ FetchedAppReport result = getDefaultApplicationReport(appId);
|
|
|
+ result.getApplicationReport().setUser("user");
|
|
|
return result;
|
|
|
} else if (answer == 3) {
|
|
|
- ApplicationReport result = getDefaultApplicationReport(appId);
|
|
|
- result.setYarnApplicationState(YarnApplicationState.KILLED);
|
|
|
+ FetchedAppReport result = getDefaultApplicationReport(appId);
|
|
|
+ result.getApplicationReport().
|
|
|
+ setYarnApplicationState(YarnApplicationState.KILLED);
|
|
|
return result;
|
|
|
} else if (answer == 4) {
|
|
|
throw new ApplicationNotFoundException("Application is not found");
|
|
|
} else if (answer == 5) {
|
|
|
// test user-provided path and query parameter can be appended to the
|
|
|
// original tracking url
|
|
|
- ApplicationReport result = getDefaultApplicationReport(appId);
|
|
|
- result.setOriginalTrackingUrl("localhost:" + originalPort
|
|
|
- + "/foo/bar?a=b#main");
|
|
|
- result.setYarnApplicationState(YarnApplicationState.FINISHED);
|
|
|
+ FetchedAppReport result = getDefaultApplicationReport(appId);
|
|
|
+ result.getApplicationReport().setOriginalTrackingUrl("localhost:"
|
|
|
+ + originalPort + "/foo/bar?a=b#main");
|
|
|
+ result.getApplicationReport().
|
|
|
+ setYarnApplicationState(YarnApplicationState.FINISHED);
|
|
|
return result;
|
|
|
+ } else if (answer == 6) {
|
|
|
+ return getDefaultApplicationReport(appId, false);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private ApplicationReport getDefaultApplicationReport(ApplicationId appId) {
|
|
|
+ /*
|
|
|
+ * If this method is called with isTrackingUrl=false, no tracking url
|
|
|
+ * will set in the app report. Hence, there will be a connection exception
|
|
|
+ * when the prxyCon tries to connect.
|
|
|
+ */
|
|
|
+ private FetchedAppReport getDefaultApplicationReport(ApplicationId appId,
|
|
|
+ boolean isTrackingUrl) {
|
|
|
+ FetchedAppReport fetchedReport;
|
|
|
ApplicationReport result = new ApplicationReportPBImpl();
|
|
|
result.setApplicationId(appId);
|
|
|
- result.setOriginalTrackingUrl("localhost:" + originalPort + "/foo/bar");
|
|
|
result.setYarnApplicationState(YarnApplicationState.RUNNING);
|
|
|
result.setUser(CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER);
|
|
|
- return result;
|
|
|
+ if (isTrackingUrl) {
|
|
|
+ result.setOriginalTrackingUrl("localhost:" + originalPort + "/foo/bar");
|
|
|
+ }
|
|
|
+ if(configuration.getBoolean(YarnConfiguration.
|
|
|
+ APPLICATION_HISTORY_ENABLED, false)) {
|
|
|
+ fetchedReport = new FetchedAppReport(result, AppReportSource.AHS);
|
|
|
+ } else {
|
|
|
+ fetchedReport = new FetchedAppReport(result, AppReportSource.RM);
|
|
|
+ }
|
|
|
+ return fetchedReport;
|
|
|
+ }
|
|
|
+
|
|
|
+ private FetchedAppReport getDefaultApplicationReport(ApplicationId appId) {
|
|
|
+ return getDefaultApplicationReport(appId, true);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|