From 20d3b9cc46e927c8a9265ade582e921fa52bc848 Mon Sep 17 00:00:00 2001 From: Viraj Jasani Date: Wed, 29 Mar 2023 16:13:10 -0700 Subject: [PATCH] HADOOP-18620 Avoid using grizzly-http-* APIs (#5356) (#5374) --- hadoop-common-project/hadoop-common/pom.xml | 5 - .../TestProxyUserAuthenticationFilter.java | 194 +++++++++++++++++- hadoop-project/pom.xml | 17 -- .../nodemanager/webapp/TestNMWebFilter.java | 158 +++++++++++++- .../hadoop-yarn-server-web-proxy/pom.xml | 6 - .../webproxy/amfilter/TestAmFilter.java | 159 +++++++++++++- pom.xml | 8 + 7 files changed, 510 insertions(+), 37 deletions(-) diff --git a/hadoop-common-project/hadoop-common/pom.xml b/hadoop-common-project/hadoop-common/pom.xml index f31d9afa3bf..5213401d632 100644 --- a/hadoop-common-project/hadoop-common/pom.xml +++ b/hadoop-common-project/hadoop-common/pom.xml @@ -200,11 +200,6 @@ assertj-core test - - org.glassfish.grizzly - grizzly-http-servlet - test - commons-beanutils commons-beanutils diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/authentication/server/TestProxyUserAuthenticationFilter.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/authentication/server/TestProxyUserAuthenticationFilter.java index 16c0e1eb112..978c15d8f2a 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/authentication/server/TestProxyUserAuthenticationFilter.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/authentication/server/TestProxyUserAuthenticationFilter.java @@ -18,21 +18,27 @@ package org.apache.hadoop.security.authentication.server; +import java.io.IOException; +import java.io.PrintWriter; import java.security.Principal; +import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import javax.servlet.FilterConfig; import javax.servlet.FilterChain; import javax.servlet.ServletContext; +import javax.servlet.ServletOutputStream; import javax.servlet.ServletResponse; import javax.servlet.ServletRequest; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import static org.assertj.core.api.Assertions.assertThat; -import org.glassfish.grizzly.servlet.HttpServletResponseImpl; import org.junit.Test; import org.mockito.Mockito; @@ -76,8 +82,192 @@ public class TestProxyUserAuthenticationFilter { } } - private class HttpServletResponseForTest extends HttpServletResponseImpl { + private class HttpServletResponseForTest implements HttpServletResponse { + @Override + public void addCookie(Cookie cookie) { + + } + + @Override + public boolean containsHeader(String name) { + return false; + } + + @Override + public String encodeURL(String url) { + return null; + } + + @Override + public String encodeRedirectURL(String url) { + return null; + } + + @Override + public String encodeUrl(String url) { + return null; + } + + @Override + public String encodeRedirectUrl(String url) { + return null; + } + + @Override + public void sendError(int sc, String msg) throws IOException { + + } + + @Override + public void sendError(int sc) throws IOException { + + } + + @Override + public void sendRedirect(String location) throws IOException { + + } + + @Override + public void setDateHeader(String name, long date) { + + } + + @Override + public void addDateHeader(String name, long date) { + + } + + @Override + public void setHeader(String name, String value) { + + } + + @Override + public void addHeader(String name, String value) { + + } + + @Override + public void setIntHeader(String name, int value) { + + } + + @Override + public void addIntHeader(String name, int value) { + + } + + @Override + public void setStatus(int sc) { + + } + + @Override + public void setStatus(int sc, String sm) { + + } + + @Override + public int getStatus() { + return 0; + } + + @Override + public String getHeader(String name) { + return null; + } + + @Override + public Collection getHeaders(String name) { + return null; + } + + @Override + public Collection getHeaderNames() { + return null; + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + @Override + public PrintWriter getWriter() throws IOException { + return null; + } + + @Override + public void setCharacterEncoding(String charset) { + + } + + @Override + public void setContentLength(int len) { + + } + + @Override + public void setContentLengthLong(long len) { + + } + + @Override + public void setContentType(String type) { + + } + + @Override + public void setBufferSize(int size) { + + } + + @Override + public int getBufferSize() { + return 0; + } + + @Override + public void flushBuffer() throws IOException { + + } + + @Override + public void resetBuffer() { + + } + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public void setLocale(Locale loc) { + + } + + @Override + public Locale getLocale() { + return null; + } } diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml index e89f2197468..6e388ece211 100644 --- a/hadoop-project/pom.xml +++ b/hadoop-project/pom.xml @@ -141,7 +141,6 @@ 1.4.10 1.1 5.2.0 - 2.2.21 2.9.0 3.2.4 3.10.6.Final @@ -1521,22 +1520,6 @@ ${jersey.version} - - org.glassfish.grizzly - grizzly-http-servlet - ${grizzly.version} - - - org.glassfish.grizzly - grizzly-http - ${grizzly.version} - - - org.glassfish.grizzly - grizzly-http-server - ${grizzly.version} - - ${leveldbjni.group} leveldbjni-all diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebFilter.java index 5dbe244e786..4ef988422e8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebFilter.java @@ -27,15 +27,18 @@ import com.google.inject.Injector; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.net.HttpURLConnection; +import java.util.Collection; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import javax.servlet.FilterChain; import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.hadoop.conf.Configuration; @@ -47,7 +50,6 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService; import org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext; import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application; -import org.glassfish.grizzly.servlet.HttpServletResponseImpl; import org.junit.Test; /** @@ -127,7 +129,7 @@ public class TestNMWebFilter { assertTrue(redirect.contains("start=10")); } - private class HttpServletResponseForTest extends HttpServletResponseImpl { + private class HttpServletResponseForTest implements HttpServletResponse { String redirectLocation = ""; int status; private String contentType; @@ -143,34 +145,184 @@ public class TestNMWebFilter { redirectLocation = location; } + @Override + public void setDateHeader(String name, long date) { + + } + + @Override + public void addDateHeader(String name, long date) { + + } + + @Override + public void addCookie(Cookie cookie) { + + } + + @Override + public boolean containsHeader(String name) { + return false; + } + + @Override + public String encodeURL(String url) { + return null; + } + @Override public String encodeRedirectURL(String url) { return url; } + @Override + public String encodeUrl(String url) { + return null; + } + + @Override + public String encodeRedirectUrl(String url) { + return null; + } + + @Override + public void sendError(int sc, String msg) throws IOException { + + } + + @Override + public void sendError(int sc) throws IOException { + + } + @Override public void setStatus(int status) { this.status = status; } + @Override + public void setStatus(int sc, String sm) { + + } + + @Override + public int getStatus() { + return 0; + } + @Override public void setContentType(String type) { this.contentType = type; } + @Override + public void setBufferSize(int size) { + + } + + @Override + public int getBufferSize() { + return 0; + } + + @Override + public void flushBuffer() throws IOException { + + } + + @Override + public void resetBuffer() { + + } + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public void setLocale(Locale loc) { + + } + + @Override + public Locale getLocale() { + return null; + } + @Override public void setHeader(String name, String value) { headers.put(name, value); } + @Override + public void addHeader(String name, String value) { + + } + + @Override + public void setIntHeader(String name, int value) { + + } + + @Override + public void addIntHeader(String name, int value) { + + } + public String getHeader(String name) { return headers.get(name); } + @Override + public Collection getHeaders(String name) { + return null; + } + + @Override + public Collection getHeaderNames() { + return null; + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + @Override public PrintWriter getWriter() throws IOException { body = new StringWriter(); return new PrintWriter(body); } + + @Override + public void setCharacterEncoding(String charset) { + + } + + @Override + public void setContentLength(int len) { + + } + + @Override + public void setContentLengthLong(long len) { + + } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml index 3d2f8c5fdc6..7cb159e46bc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/pom.xml @@ -104,12 +104,6 @@ jetty-server - - org.glassfish.grizzly - grizzly-http-servlet - test - - com.sun.jersey.jersey-test-framework diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java index 5fcdb62ea33..41162f9a605 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilter.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.net.HttpURLConnection; +import java.util.Locale; import java.util.Set; import java.util.HashSet; import java.util.Enumeration; @@ -37,9 +38,10 @@ import javax.servlet.FilterConfig; import javax.servlet.FilterChain; import javax.servlet.Filter; import javax.servlet.ServletContext; -import javax.servlet.ServletResponse; -import javax.servlet.ServletRequest; import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -60,7 +62,6 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.thread.QueuedThreadPool; -import org.glassfish.grizzly.servlet.HttpServletResponseImpl; import org.junit.Test; import org.mockito.Mockito; @@ -306,7 +307,7 @@ public class TestAmFilter { } - private class HttpServletResponseForTest extends HttpServletResponseImpl { + private class HttpServletResponseForTest implements HttpServletResponse { String redirectLocation = ""; int status; private String contentType; @@ -323,35 +324,185 @@ public class TestAmFilter { redirectLocation = location; } + @Override + public void setDateHeader(String name, long date) { + + } + + @Override + public void addDateHeader(String name, long date) { + + } + + @Override + public void addCookie(Cookie cookie) { + + } + + @Override + public boolean containsHeader(String name) { + return false; + } + + @Override + public String encodeURL(String url) { + return null; + } + @Override public String encodeRedirectURL(String url) { return url; } + @Override + public String encodeUrl(String url) { + return null; + } + + @Override + public String encodeRedirectUrl(String url) { + return null; + } + + @Override + public void sendError(int sc, String msg) throws IOException { + + } + + @Override + public void sendError(int sc) throws IOException { + + } + @Override public void setStatus(int status) { this.status = status; } + @Override + public void setStatus(int sc, String sm) { + + } + + @Override + public int getStatus() { + return 0; + } + @Override public void setContentType(String type) { this.contentType = type; } + @Override + public void setBufferSize(int size) { + + } + + @Override + public int getBufferSize() { + return 0; + } + + @Override + public void flushBuffer() throws IOException { + + } + + @Override + public void resetBuffer() { + + } + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public void setLocale(Locale loc) { + + } + + @Override + public Locale getLocale() { + return null; + } + @Override public void setHeader(String name, String value) { headers.put(name, value); } + @Override + public void addHeader(String name, String value) { + + } + + @Override + public void setIntHeader(String name, int value) { + + } + + @Override + public void addIntHeader(String name, int value) { + + } + public String getHeader(String name) { return headers.get(name); } + @Override + public Collection getHeaders(String name) { + return null; + } + + @Override + public Collection getHeaderNames() { + return null; + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + @Override public PrintWriter getWriter() throws IOException { body = new StringWriter(); return new PrintWriter(body); } + + @Override + public void setCharacterEncoding(String charset) { + + } + + @Override + public void setContentLength(int len) { + + } + + @Override + public void setContentLengthLong(long len) { + + } } diff --git a/pom.xml b/pom.xml index d9b296a3860..57822cdd01a 100644 --- a/pom.xml +++ b/pom.xml @@ -184,6 +184,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x org.apache.curator.shaded.** + + true + Use HttpServlet APIs instead + + org.glassfish.grizzly + org.glassfish.grizzly.** + +