YARN-3239. WebAppProxy does not support a final tracking url which has query fragments and params. Contributed by Jian He

This commit is contained in:
Jason Lowe 2015-02-25 16:14:34 +00:00
parent ad8ed3e802
commit 1a68fc4346
3 changed files with 40 additions and 7 deletions

View File

@ -655,6 +655,9 @@ Release 2.7.0 - UNRELEASED
YARN-3247. TestQueueMappings should use CapacityScheduler explicitly. YARN-3247. TestQueueMappings should use CapacityScheduler explicitly.
(Zhihai Xu via ozawa) (Zhihai Xu via ozawa)
YARN-3239. WebAppProxy does not support a final tracking url which has
query fragments and params (Jian He via jlowe)
Release 2.6.0 - 2014-11-18 Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -20,9 +20,9 @@ package org.apache.hadoop.yarn.server.webproxy;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.ObjectInputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -38,6 +38,7 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.UriBuilder;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HostConfiguration;
@ -58,6 +59,8 @@ import org.apache.hadoop.yarn.util.TrackingUriPlugin;
import org.apache.hadoop.yarn.webapp.MimeType; import org.apache.hadoop.yarn.webapp.MimeType;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -325,11 +328,17 @@ public class WebAppProxyServlet extends HttpServlet {
req.getQueryString(), true), runningUser, id); req.getQueryString(), true), runningUser, id);
return; return;
} }
URI toFetch = new URI(trackingUri.getScheme(),
trackingUri.getAuthority(), // Append the user-provided path and query parameter to the original
StringHelper.ujoin(trackingUri.getPath(), rest), req.getQueryString(), // tracking url.
null); List<NameValuePair> queryPairs =
URLEncodedUtils.parse(req.getQueryString(), null);
UriBuilder builder = UriBuilder.fromUri(trackingUri);
for (NameValuePair pair : queryPairs) {
builder.queryParam(pair.getName(), pair.getValue());
}
URI toFetch = builder.path(rest).build();
LOG.info("{} is accessing unchecked {}" LOG.info("{} is accessing unchecked {}"
+ " which is the app master GUI of {} owned by {}", + " which is the app master GUI of {} owned by {}",
remoteUser, toFetch, appId, runningUser); remoteUser, toFetch, appId, runningUser);

View File

@ -82,7 +82,7 @@ public class TestWebAppProxyServlet {
Context context = new Context(); Context context = new Context();
context.setContextPath("/foo"); context.setContextPath("/foo");
server.setHandler(context); server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar/"); context.addServlet(new ServletHolder(TestServlet.class), "/bar");
server.getConnectors()[0].setHost("localhost"); server.getConnectors()[0].setHost("localhost");
server.start(); server.start();
originalPort = server.getConnectors()[0].getLocalPort(); originalPort = server.getConnectors()[0].getLocalPort();
@ -181,6 +181,19 @@ public class TestWebAppProxyServlet {
proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true");
proxyConn.connect(); proxyConn.connect();
assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode());
// test user-provided path and query parameter can be appended to the
// original tracking url
appReportFetcher.answer = 5;
URL clientUrl = new URL("http://localhost:" + proxyPort
+ "/proxy/application_00_0/test/tez?x=y&h=p");
proxyConn = (HttpURLConnection) clientUrl.openConnection();
proxyConn.connect();
LOG.info("" + proxyConn.getURL());
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 { } finally {
proxy.close(); proxy.close();
} }
@ -344,6 +357,14 @@ public class TestWebAppProxyServlet {
return result; return result;
} else if (answer == 4) { } else if (answer == 4) {
throw new ApplicationNotFoundException("Application is not found"); 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);
return result;
} }
return null; return null;
} }