Skip to content

Commit

Permalink
[HOPS-1642] Bump jetty-server to 9.4.41.v20210516
Browse files Browse the repository at this point in the history
Co-authored-By: Siyao Meng <[email protected]>
Signed-off-by: Wei-Chiu Chuang <[email protected]>

Co-authored-By: Siyao Meng <[email protected]>
Signed-off-by: Wei-Chiu Chuang <[email protected]>
  • Loading branch information
2 people authored and berthoug committed Aug 31, 2021
1 parent a8f495a commit a3e07fd
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 41 deletions.
37 changes: 37 additions & 0 deletions hadoop-client-modules/hadoop-client-minicluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,36 @@
<exclude>ehcache-core.xsd</exclude>
</excludes>
</filter>
<!-- Jetty 9.4.x: jetty-client and jetty-xml are depended by org.eclipse.jetty.websocket:websocket-client.
But we are only excluding jetty-client not jetty-xml because HttpServer2 implicitly uses the shaded package name.
-->
<filter>
<artifact>org.eclipse.jetty:jetty-client</artifact>
<excludes>
<exclude>*/**</exclude>
</excludes>
</filter>
<!-- Jetty 9.4.x: jetty-client and jetty-xml are depended by org.eclipse.jetty.websocket:websocket-client.
But we are only excluding jetty-client not jetty-xml because HttpServer2 implicitly uses the shaded package name.
-->
<filter>
<artifact>org.eclipse.jetty:jetty-client</artifact>
<excludes>
<exclude>*/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.eclipse.jetty:jetty-util-ajax</artifact>
<excludes>
<exclude>*/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.eclipse.jetty:jetty-server</artifact>
<excludes>
<exclude>jetty-dir.css</exclude>
</excludes>
</filter>
</filters>

<!-- relocate classes from mssql-jdbc -->
Expand Down Expand Up @@ -924,6 +954,13 @@
<exclude>**/pom.xml</exclude>
</excludes>
</relocation>
<relocation>
<pattern>javax/websocket/</pattern>
<shadedPattern>${shaded.dependency.prefix}.javax.websocket.</shadedPattern>
<excludes>
<exclude>**/pom.xml</exclude>
</excludes>
</relocation>
<relocation>
<pattern>jersey/</pattern>
<shadedPattern>${shaded.dependency.prefix}.jersey.</shadedPattern>
Expand Down
9 changes: 9 additions & 0 deletions hadoop-client-modules/hadoop-client-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@
<!-- the jdk ships part of the javax.annotation namespace, so if we want to relocate this we'll have to care it out by class :( -->
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>io.dropwizard.metrics:metrics-core</exclude>
<exclude>org.eclipse.jetty.websocket:*</exclude>
<exclude>org.eclipse.jetty:jetty-servlet</exclude>
<exclude>org.eclipse.jetty:jetty-security</exclude>
<exclude>org.eclipse.jetty:jetty-client</exclude>
<exclude>org.eclipse.jetty:jetty-http</exclude>
<exclude>org.eclipse.jetty:jetty-xml</exclude>
<exclude>org.ow2.asm:*</exclude>
<!-- Leave bouncycastle unshaded because it's signed with a special Oracle certificate so it can be a custom JCE security provider -->
<exclude>org.bouncycastle:*</exclude>
</excludes>
</artifactSet>
<filters>
Expand Down
4 changes: 4 additions & 0 deletions hadoop-common-project/hadoop-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
<artifactId>guava</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.hadoop.security.authentication.client.AuthenticationException;
import org.apache.hadoop.security.authentication.client.KerberosAuthenticator;
import org.apache.hadoop.security.authentication.util.*;
import org.eclipse.jetty.server.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -619,11 +620,20 @@ && getMaxInactiveInterval() > 0) {
KerberosAuthenticator.WWW_AUTHENTICATE))) {
errCode = HttpServletResponse.SC_FORBIDDEN;
}
// After Jetty 9.4.21, sendError() no longer allows a custom message.
// use setStatusWithReason() to set a custom message.
String reason;
if (authenticationEx == null) {
httpResponse.sendError(errCode, "Authentication required");
reason = "Authentication required";
} else {
httpResponse.sendError(errCode, authenticationEx.getMessage());
reason = authenticationEx.getMessage();
}

if (httpResponse instanceof Response) {
((Response)httpResponse).setStatusWithReason(errCode, reason);
}

httpResponse.sendError(errCode, reason);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.apache.commons.logging.LogConfigurationException;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Appender;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.AsyncRequestLogWriter;
import org.eclipse.jetty.server.CustomRequestLog;
import org.eclipse.jetty.server.RequestLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -85,10 +86,11 @@ public static RequestLog getRequestLog(String name) {
if (appender instanceof HttpRequestLogAppender) {
HttpRequestLogAppender requestLogAppender
= (HttpRequestLogAppender)appender;
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename(requestLogAppender.getFilename());
requestLog.setRetainDays(requestLogAppender.getRetainDays());
return requestLog;
AsyncRequestLogWriter logWriter = new AsyncRequestLogWriter();
logWriter.setFilename(requestLogAppender.getFilename());
logWriter.setRetainDays(requestLogAppender.getRetainDays());
return new CustomRequestLog(logWriter,
CustomRequestLog.EXTENDED_NCSA_FORMAT);
} else {
LOG.warn("Jetty request log for {} was of the wrong class", loggerName);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SessionManager;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.session.AbstractSessionManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.FilterHolder;
Expand Down Expand Up @@ -506,7 +504,8 @@ private ServerConnector createHttpsChannelConnector(
httpConfig.addCustomizer(new SecureRequestCustomizer());
ServerConnector conn = createHttpChannelConnector(server, httpConfig);

SslContextFactory sslContextFactory = new SslContextFactory();
SslContextFactory.Server sslContextFactory =
new SslContextFactory.Server();
sslContextFactory.setNeedClientAuth(needsClientAuth);
sslContextFactory.setKeyManagerPassword(keyPassword);
if (keyStore != null) {
Expand Down Expand Up @@ -574,12 +573,9 @@ private void initializeWebServer(String name, String hostName,
threadPool.setMaxThreads(maxThreads);
}

SessionManager sm = webAppContext.getSessionHandler().getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager)sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
SessionHandler handler = webAppContext.getSessionHandler();
handler.setHttpOnly(true);
handler.getSessionCookieConfig().setSecure(true);

ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLog requestLog = HttpRequestLog.getRequestLog(name);
Expand Down Expand Up @@ -718,12 +714,8 @@ protected void addDefaultApps(ContextHandlerCollection parent,
}
logContext.setDisplayName("logs");
SessionHandler handler = new SessionHandler();
SessionManager sm = handler.getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
handler.setHttpOnly(true);
handler.getSessionCookieConfig().setSecure(true);
logContext.setSessionHandler(handler);
setContextAttributes(logContext, conf);
addNoCacheFilter(logContext);
Expand All @@ -740,12 +732,8 @@ protected void addDefaultApps(ContextHandlerCollection parent,
params.put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
params.put("org.eclipse.jetty.servlet.Default.gzip", "true");
SessionHandler handler = new SessionHandler();
SessionManager sm = handler.getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
handler.setHttpOnly(true);
handler.getSessionCookieConfig().setSecure(true);
staticContext.setSessionHandler(handler);
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
Expand Down Expand Up @@ -1198,7 +1186,7 @@ private static void bindListener(ServerConnector listener) throws Exception {
* @return
*/
private static BindException constructBindException(ServerConnector listener,
BindException ex) {
IOException ex) {
BindException be = new BindException("Port in use: "
+ listener.getHost() + ":" + listener.getPort());
if (ex != null) {
Expand All @@ -1220,7 +1208,7 @@ private void bindForSinglePort(ServerConnector listener, int port)
try {
bindListener(listener);
break;
} catch (BindException ex) {
} catch (IOException ex) {
if (port == 0 || !findPort) {
throw constructBindException(listener, ex);
}
Expand All @@ -1240,13 +1228,13 @@ private void bindForSinglePort(ServerConnector listener, int port)
*/
private void bindForPortRange(ServerConnector listener, int startPort)
throws Exception {
BindException bindException = null;
IOException ioException = null;
try {
bindListener(listener);
return;
} catch (BindException ex) {
} catch (IOException ex) {
// Ignore exception.
bindException = ex;
ioException = ex;
}
for(Integer port : portRanges) {
if (port == startPort) {
Expand All @@ -1259,10 +1247,10 @@ private void bindForPortRange(ServerConnector listener, int startPort)
return;
} catch (BindException ex) {
// Ignore exception. Move to next port.
bindException = ex;
ioException = ex;
}
}
throw constructBindException(listener, bindException);
throw constructBindException(listener, ioException);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configuration;

import org.eclipse.jetty.server.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -271,6 +272,10 @@ public void proceed() throws IOException, ServletException {

@Override
public void sendError(int code, String message) throws IOException {
if (httpResponse instanceof Response) {
((Response)httpResponse).setStatusWithReason(code, message);
}

httpResponse.sendError(code, message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.http;

import org.apache.log4j.Logger;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.CustomRequestLog;
import org.eclipse.jetty.server.RequestLog;
import org.junit.Test;

Expand All @@ -42,6 +42,7 @@ public void testAppenderDefined() {
RequestLog requestLog = HttpRequestLog.getRequestLog("test");
Logger.getLogger("http.requests.test").removeAppender(requestLogAppender);
assertNotNull("RequestLog should not be null", requestLog);
assertEquals("Class mismatch", NCSARequestLog.class, requestLog.getClass());
assertEquals("Class mismatch",
CustomRequestLog.class, requestLog.getClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationHandler;
import org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticationHandler;
import org.apache.hadoop.security.token.delegation.web.PseudoDelegationTokenAuthenticationHandler;
import org.eclipse.jetty.server.Response;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
Expand Down Expand Up @@ -106,6 +107,18 @@ public void setStatus(int sc) {
public void sendError(int sc, String msg) throws IOException {
statusCode = sc;
this.msg = msg;

ServletResponse response = getResponse();

// After Jetty 9.4.21, sendError() no longer allows a custom message.
// use setStatusWithReason() to set a custom message.
if (response instanceof Response) {
((Response) response).setStatusWithReason(sc, msg);
} else {
KMS.LOG.warn("The wrapped response object is instance of {}" +
", not org.eclipse.jetty.server.Response. Can't set custom error " +
"message", response.getClass());
}
super.sendError(sc, HtmlQuoting.quoteHtmlChars(msg));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ private Server createJettyServer() {
conn.setHost(host);
conn.setPort(port);
if (ssl) {
SslContextFactory sslContextFactory = new SslContextFactory();
SslContextFactory.Server sslContextFactory =
new SslContextFactory.Server();
sslContextFactory.setNeedClientAuth(false);
sslContextFactory.setKeyStorePath(keyStore);
sslContextFactory.setKeyStoreType(keyStoreType);
Expand Down
2 changes: 1 addition & 1 deletion hadoop-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<failIfNoTests>false</failIfNoTests>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
<jetty.version>9.3.24.v20180605</jetty.version>
<jetty.version>9.4.20.v20190813</jetty.version>
<test.exclude>_</test.exclude>
<test.exclude.pattern>_</test.exclude.pattern>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
import org.apache.hadoop.yarn.util.UTCClock;
import org.apache.hadoop.yarn.util.resource.ResourceUtils;
import org.apache.hadoop.yarn.util.resource.Resources;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -332,7 +331,7 @@ private void startNM() throws YarnException, IOException,

// create NM simulators
Random random = new Random();
Set<String> rackSet = new ConcurrentHashSet<>();
Set<String> rackSet = ConcurrentHashMap.newKeySet();
int threadPoolSize = Math.max(poolSize,
SLSConfiguration.RUNNER_POOL_SIZE_DEFAULT);
ExecutorService executorService = Executors.
Expand Down

0 comments on commit a3e07fd

Please sign in to comment.