YARN-3217. Remove httpclient dependency from hadoop-yarn-server-web-proxy. Contributed by Brahma Reddy Battula.
(cherry picked from commit 773b6515ac
)
This commit is contained in:
parent
f83d2e4410
commit
dc348f4894
|
@ -288,6 +288,9 @@ Release 2.7.0 - UNRELEASED
|
||||||
YARN-2797. Add -help to yarn logs and nodes CLI command.
|
YARN-2797. Add -help to yarn logs and nodes CLI command.
|
||||||
(Jagadesh Kiran N via devaraj)
|
(Jagadesh Kiran N via devaraj)
|
||||||
|
|
||||||
|
YARN-3217. Remove httpclient dependency from hadoop-yarn-server-web-proxy.
|
||||||
|
(Brahma Reddy Battula via ozawa).
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
YARN-2990. FairScheduler's delay-scheduling always waits for node-local and
|
YARN-2990. FairScheduler's delay-scheduling always waits for node-local and
|
||||||
|
|
|
@ -78,10 +78,6 @@
|
||||||
<artifactId>hadoop-yarn-api</artifactId>
|
<artifactId>hadoop-yarn-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-httpclient</groupId>
|
|
||||||
<artifactId>commons-httpclient</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
|
|
|
@ -40,13 +40,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.Header;
|
|
||||||
import org.apache.commons.httpclient.HostConfiguration;
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
|
||||||
import org.apache.commons.httpclient.cookie.CookiePolicy;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
import org.apache.commons.httpclient.params.HttpClientParams;
|
|
||||||
import org.apache.hadoop.io.IOUtils;
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
||||||
|
@ -59,8 +52,15 @@ 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.Header;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.params.ClientPNames;
|
||||||
|
import org.apache.http.client.params.CookiePolicy;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
|
import org.apache.http.conn.params.ConnRoutePNames;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -155,23 +155,22 @@ public class WebAppProxyServlet extends HttpServlet {
|
||||||
private static void proxyLink(HttpServletRequest req,
|
private static void proxyLink(HttpServletRequest req,
|
||||||
HttpServletResponse resp, URI link, Cookie c, String proxyHost)
|
HttpServletResponse resp, URI link, Cookie c, String proxyHost)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
org.apache.commons.httpclient.URI uri =
|
DefaultHttpClient client = new DefaultHttpClient();
|
||||||
new org.apache.commons.httpclient.URI(link.toString(), false);
|
client
|
||||||
HttpClientParams params = new HttpClientParams();
|
.getParams()
|
||||||
params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
|
.setParameter(ClientPNames.COOKIE_POLICY,
|
||||||
params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
|
CookiePolicy.BROWSER_COMPATIBILITY)
|
||||||
HttpClient client = new HttpClient(params);
|
.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
|
||||||
// Make sure we send the request from the proxy address in the config
|
// Make sure we send the request from the proxy address in the config
|
||||||
// since that is what the AM filter checks against. IP aliasing or
|
// since that is what the AM filter checks against. IP aliasing or
|
||||||
// similar could cause issues otherwise.
|
// similar could cause issues otherwise.
|
||||||
HostConfiguration config = new HostConfiguration();
|
|
||||||
InetAddress localAddress = InetAddress.getByName(proxyHost);
|
InetAddress localAddress = InetAddress.getByName(proxyHost);
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("local InetAddress for proxy host: {}", localAddress);
|
LOG.debug("local InetAddress for proxy host: {}", localAddress);
|
||||||
}
|
}
|
||||||
config.setLocalAddress(localAddress);
|
client.getParams()
|
||||||
HttpMethod method = new GetMethod(uri.getEscapedURI());
|
.setParameter(ConnRoutePNames.LOCAL_ADDRESS, localAddress);
|
||||||
method.setRequestHeader("Connection","close");
|
HttpGet httpGet = new HttpGet(link);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Enumeration<String> names = req.getHeaderNames();
|
Enumeration<String> names = req.getHeaderNames();
|
||||||
while(names.hasMoreElements()) {
|
while(names.hasMoreElements()) {
|
||||||
|
@ -181,30 +180,31 @@ public class WebAppProxyServlet extends HttpServlet {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("REQ HEADER: {} : {}", name, value);
|
LOG.debug("REQ HEADER: {} : {}", name, value);
|
||||||
}
|
}
|
||||||
method.setRequestHeader(name, value);
|
httpGet.setHeader(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String user = req.getRemoteUser();
|
String user = req.getRemoteUser();
|
||||||
if (user != null && !user.isEmpty()) {
|
if (user != null && !user.isEmpty()) {
|
||||||
method.setRequestHeader("Cookie",
|
httpGet.setHeader("Cookie",
|
||||||
PROXY_USER_COOKIE_NAME + "=" + URLEncoder.encode(user, "ASCII"));
|
PROXY_USER_COOKIE_NAME + "=" + URLEncoder.encode(user, "ASCII"));
|
||||||
}
|
}
|
||||||
OutputStream out = resp.getOutputStream();
|
OutputStream out = resp.getOutputStream();
|
||||||
try {
|
try {
|
||||||
resp.setStatus(client.executeMethod(config, method));
|
HttpResponse httpResp = client.execute(httpGet);
|
||||||
for(Header header : method.getResponseHeaders()) {
|
resp.setStatus(httpResp.getStatusLine().getStatusCode());
|
||||||
|
for (Header header : httpResp.getAllHeaders()) {
|
||||||
resp.setHeader(header.getName(), header.getValue());
|
resp.setHeader(header.getName(), header.getValue());
|
||||||
}
|
}
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
resp.addCookie(c);
|
resp.addCookie(c);
|
||||||
}
|
}
|
||||||
InputStream in = method.getResponseBodyAsStream();
|
InputStream in = httpResp.getEntity().getContent();
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
IOUtils.copyBytes(in, out, 4096, true);
|
IOUtils.copyBytes(in, out, 4096, true);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
method.releaseConnection();
|
httpGet.releaseConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue