From 5ec0a00e8437017cf358c004373f190e6bc75331 Mon Sep 17 00:00:00 2001 From: Apekshit Sharma Date: Sat, 21 Oct 2017 18:12:07 -0700 Subject: [PATCH] HBASE-19053 Split out o.a.h.h.http from hbase-server into a separate module Change-Id: Ie3a688b789104df7feaf34ac9fb326a79d6a3960 --- hbase-common/pom.xml | 4 + .../org/apache/hadoop/hbase/util/JSONBean.java | 30 -- .../apache/hadoop/hbase/util/JSONMetricUtil.java | 2 +- hbase-endpoint/pom.xml | 6 + hbase-http/pom.xml | 513 +++++++++++++++++++++ .../hadoop/hbase/http/AdminAuthorizedServlet.java | 0 .../hbase/http/ClickjackingPreventionFilter.java | 0 .../apache/hadoop/hbase/http/FilterContainer.java | 0 .../hadoop/hbase/http/FilterInitializer.java | 2 +- .../org/apache/hadoop/hbase/http/HtmlQuoting.java | 14 +- .../org/apache/hadoop/hbase/http/HttpConfig.java | 0 .../apache/hadoop/hbase/http/HttpRequestLog.java | 0 .../hadoop/hbase/http/HttpRequestLogAppender.java | 0 .../org/apache/hadoop/hbase/http/HttpServer.java | 0 .../apache/hadoop/hbase/http}/HttpServerUtil.java | 2 +- .../org/apache/hadoop/hbase/http/InfoServer.java | 2 +- .../apache/hadoop/hbase/http/NoCacheFilter.java | 0 .../hadoop/hbase/http/ServerConfigurationKeys.java | 2 +- .../apache/hadoop/hbase/http/conf/ConfServlet.java | 0 .../hadoop/hbase/http/jmx/JMXJsonServlet.java | 34 +- .../apache/hadoop/hbase/http/jmx/package-info.java | 4 +- .../hadoop/hbase/http/lib/StaticUserWebFilter.java | 14 +- .../apache/hadoop/hbase/http/lib/package-info.java | 0 .../org/apache/hadoop/hbase/http/log/LogLevel.java | 0 .../org/apache/hadoop/hbase/http/package-info.java | 0 .../hbase/http/HttpServerFunctionalTest.java | 8 +- .../apache/hadoop/hbase/http/TestGlobalFilter.java | 12 +- .../apache/hadoop/hbase/http/TestHtmlQuoting.java | 10 +- .../hadoop/hbase/http/TestHttpRequestLog.java | 0 .../hbase/http/TestHttpRequestLogAppender.java | 0 .../apache/hadoop/hbase/http/TestHttpServer.java | 48 +- .../hadoop/hbase/http/TestHttpServerLifecycle.java | 0 .../hadoop/hbase/http/TestHttpServerWebapps.java | 0 .../apache/hadoop/hbase/http/TestPathFilter.java | 16 +- .../hadoop/hbase/http/TestSSLHttpServer.java | 0 .../hadoop/hbase/http/TestServletFilter.java | 31 +- .../hadoop/hbase/http/TestSpnegoHttpServer.java | 0 .../hadoop/hbase/http/conf/TestConfServlet.java | 2 +- .../hadoop/hbase/http/jmx/TestJMXJsonServlet.java | 22 +- .../hbase/http/lib/TestStaticUserWebFilter.java | 14 +- .../apache/hadoop/hbase/http/log/TestLogLevel.java | 0 .../hadoop/hbase/http/resource/JerseyResource.java | 0 .../hadoop/hbase/http/ssl/KeyStoreTestUtil.java | 16 +- hbase-http/src/test/resources/log4j.properties | 68 +++ .../src/test/resources/webapps/static/test.css | 21 + .../src/test/resources/webapps/test/testjsp.jsp | 21 + .../org/apache/hadoop/hbase/rest/RESTServer.java | 4 +- .../hadoop/hbase/rest/HBaseRESTTestingUtility.java | 4 +- hbase-server/pom.xml | 45 +- .../regionserver/DumpRegionServerMetrics.java | 60 +++ .../hadoop/hbase/regionserver/HRegionServer.java | 3 +- .../org/apache/hadoop/hbase/GenericTestUtils.java | 74 ++- hbase-shaded/hbase-shaded-mapreduce/pom.xml | 4 + pom.xml | 23 + 54 files changed, 898 insertions(+), 237 deletions(-) rename {hbase-server => hbase-common}/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java (91%) rename {hbase-server => hbase-common}/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java (99%) create mode 100644 hbase-http/pom.xml rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/AdminAuthorizedServlet.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/ClickjackingPreventionFilter.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/FilterContainer.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java (96%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java (99%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/HttpConfig.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLog.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLogAppender.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java (100%) rename {hbase-server/src/main/java/org/apache/hadoop/hbase/util => hbase-http/src/main/java/org/apache/hadoop/hbase/http}/HttpServerUtil.java (98%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java (99%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/NoCacheFilter.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java (99%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/conf/ConfServlet.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java (96%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java (99%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java (96%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/lib/package-info.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java (100%) rename {hbase-server => hbase-http}/src/main/java/org/apache/hadoop/hbase/http/package-info.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java (99%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java (99%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java (98%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestHttpRequestLog.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestHttpRequestLogAppender.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestHttpServer.java (98%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerLifecycle.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerWebapps.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java (99%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestSSLHttpServer.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java (91%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/TestSpnegoHttpServer.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java (98%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java (97%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java (98%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/resource/JerseyResource.java (100%) rename {hbase-server => hbase-http}/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java (99%) create mode 100644 hbase-http/src/test/resources/log4j.properties create mode 100644 hbase-http/src/test/resources/webapps/static/test.css create mode 100644 hbase-http/src/test/resources/webapps/test/testjsp.jsp create mode 100644 hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DumpRegionServerMetrics.java diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml index 9bf40324a3..135e720557 100644 --- a/hbase-common/pom.xml +++ b/hbase-common/pom.xml @@ -263,6 +263,10 @@ com.github.stephenc.findbugs findbugs-annotations + + com.fasterxml.jackson.core + jackson-databind + org.mockito mockito-all diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java similarity index 91% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java rename to hbase-common/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java index f4a146ecdb..23759b5ff5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java @@ -340,31 +340,6 @@ public class JSONBean { } } - /** - * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out. - * @throws MalformedObjectNameException - * @throws IOException - */ - public static String dumpRegionServerMetrics() throws MalformedObjectNameException, IOException { - StringWriter sw = new StringWriter(1024 * 100); // Guess this size - try (PrintWriter writer = new PrintWriter(sw)) { - JSONBean dumper = new JSONBean(); - try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) { - MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); - jsonBeanWriter.write(mbeanServer, - new ObjectName("java.lang:type=Memory"), null, false); - jsonBeanWriter.write(mbeanServer, - new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"), null, false); - jsonBeanWriter.write(mbeanServer, - new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false); - jsonBeanWriter.write(mbeanServer, - new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false); - } - } - sw.close(); - return sw.toString(); - } - /** * Dump out all registered mbeans as json on System.out. * @throws IOException @@ -379,9 +354,4 @@ public class JSONBean { } } } - - public static void main(String[] args) throws IOException, MalformedObjectNameException { - String str = dumpRegionServerMetrics(); - System.out.println(str); - } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java similarity index 99% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java rename to hbase-common/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java index 879f32e63a..d10610e37b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java @@ -91,7 +91,7 @@ public final class JSONMetricUtil { /** * Returns a subset of mbeans defined by qry. - * Modeled after {@link JSONBean#dumpRegionServerMetrics()} + * Modeled after DumpRegionServerMetrics#dumpMetrics. * Example: String qry= "java.lang:type=Memory" * @throws MalformedObjectNameException if json have bad format * @throws IOException / diff --git a/hbase-endpoint/pom.xml b/hbase-endpoint/pom.xml index fdb4784fcc..ef2584c1ec 100644 --- a/hbase-endpoint/pom.xml +++ b/hbase-endpoint/pom.xml @@ -174,6 +174,12 @@ test-jar test + + org.apache.hbase + hbase-http + test-jar + test + diff --git a/hbase-http/pom.xml b/hbase-http/pom.xml new file mode 100644 index 0000000000..77a1e993c1 --- /dev/null +++ b/hbase-http/pom.xml @@ -0,0 +1,513 @@ + + + + 4.0.0 + + hbase-build-configuration + org.apache.hbase + 3.0.0-SNAPSHOT + ../hbase-build-configuration + + hbase-http + Apache HBase - HTTP + HTTP functionality for HBase Servers + + + + + + + src/test/resources/META-INF/ + META-INF/ + + NOTICE + + true + + + src/test/resources + + **/** + + + + + + org.apache.maven.plugins + maven-site-plugin + + true + + + + + org.apache.maven.plugins + maven-remote-resources-plugin + 1.5 + + + default + + false + + ${build.year} + ${license.debug.print.included} + ${license.bundles.dependencies} + ${license.bundles.jquery} + ${license.bundles.logo} + ${license.bundles.bootstrap} + + + ${project.groupId}:hbase-resource-bundle:${project.version} + + + ${project.groupId}:hbase-resource-bundle:${project.version} + + + supplemental-models.xml + + + + + + + + + maven-assembly-plugin + + true + + + + + org.apache.maven.plugins + maven-source-plugin + + + package + + jar + test-jar + + + + + + + org.codehaus.mojo + findbugs-maven-plugin + + + + maven-surefire-plugin + + + + listener + org.apache.hadoop.hbase.ResourceCheckerJUnitListener + + + + target/test-classes/webapps + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + + + + + + org.apache.maven.plugins + maven-antrun-plugin + [1.6,) + + run + + + + + false + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + [2.8,) + + build-classpath + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + [3.2,) + + compile + + + + + + + + + + + + + + + + org.apache.hbase.thirdparty + hbase-shaded-miscellaneous + + + + org.apache.hbase + hbase-common + + + org.apache.hbase + hbase-common + test-jar + test + + + org.apache.hbase + hbase-annotations + test-jar + test + + + + org.apache.hbase + hbase-resource-bundle + ${project.version} + true + + + org.eclipse.jetty + jetty-server + + + org.eclipse.jetty + jetty-servlet + + + org.eclipse.jetty + jetty-util + + + org.eclipse.jetty + jetty-util-ajax + + + org.eclipse.jetty + jetty-webapp + + + org.eclipse.jetty + jetty-http + + + org.eclipse.jetty + jetty-security + + + org.glassfish.jersey.core + jersey-server + + + org.glassfish.jersey.containers + jersey-container-servlet-core + + + + commons-logging + commons-logging + + + log4j + log4j + + + javax.servlet + javax.servlet-api + + + javax.ws.rs + javax.ws.rs-api + + + + + org.apache.kerby + kerb-simplekdc + test + + + org.bouncycastle + bcprov-jdk16 + test + + + org.apache.kerby + kerb-core + test + + + org.apache.httpcomponents + httpclient + test + + + org.apache.httpcomponents + httpcore + test + + + junit + junit + test + + + org.mockito + mockito-all + test + + + + + + apache-release + + + + org.apache.maven.plugins + maven-resources-plugin + + + license-javadocs + prepare-package + + copy-resources + + + ${project.build.directory}/apidocs + + + src/main/javadoc/META-INF/ + META-INF/ + + LICENSE + NOTICE + + true + + + + + + + + + + + + skipServerTests + + + skipServerTests + + + + true + true + + + + + native + + false + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + make + compile + run + + + + + + + + + + + + + + + + + + + + + + + hadoop-2.0 + + + + !hadoop.profile + + + + + org.apache.hadoop + hadoop-common + + + org.apache.hadoop + hadoop-minicluster + + + com.google.guava + guava + + + + + org.apache.hadoop + hadoop-auth + + + + + + maven-dependency-plugin + + + create-mrapp-generated-classpath + generate-test-resources + + build-classpath + + + + ${project.build.directory}/test-classes/mrapp-generated-classpath + + + + + + + + + + hadoop-3.0 + + + hadoop.profile + 3.0 + + + + ${hadoop-three.version} + + + + org.apache.hadoop + hadoop-common + + + org.apache.hadoop + hadoop-minicluster + + + com.google.guava + guava + + + + + + + + maven-dependency-plugin + + + create-mrapp-generated-classpath + generate-test-resources + + build-classpath + + + + ${project.build.directory}/test-classes/mrapp-generated-classpath + + + + + + + + + diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/AdminAuthorizedServlet.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/AdminAuthorizedServlet.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/AdminAuthorizedServlet.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/AdminAuthorizedServlet.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/ClickjackingPreventionFilter.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/ClickjackingPreventionFilter.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/ClickjackingPreventionFilter.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/ClickjackingPreventionFilter.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/FilterContainer.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/FilterContainer.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/FilterContainer.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/FilterContainer.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java similarity index 96% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java index e033c10572..d3173438de 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/FilterInitializer.java @@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.http; import org.apache.hadoop.conf.Configuration; /** - * Initialize a javax.servlet.Filter. + * Initialize a javax.servlet.Filter. */ public abstract class FilterInitializer { /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java similarity index 99% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java index 60a74b73df..7f4bb83b52 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HtmlQuoting.java @@ -92,7 +92,7 @@ public class HtmlQuoting { } } } - + /** * Quote the given item to make it html-safe. * @param item the string to quote @@ -130,18 +130,18 @@ public class HtmlQuoting { public void write(byte[] data, int off, int len) throws IOException { quoteHtmlChars(out, data, off, len); } - + @Override public void write(int b) throws IOException { data[0] = (byte) b; quoteHtmlChars(out, data, 0, 1); } - + @Override public void flush() throws IOException { out.flush(); } - + @Override public void close() throws IOException { out.close(); @@ -173,7 +173,7 @@ public class HtmlQuoting { next += 5; } else if (item.startsWith("'", next)) { buffer.append('\''); - next += 6; + next += 6; } else if (item.startsWith(">", next)) { buffer.append('>'); next += 4; @@ -188,7 +188,7 @@ public class HtmlQuoting { if (end == 0) { end = len; } - throw new IllegalArgumentException("Bad HTML quoting for " + + throw new IllegalArgumentException("Bad HTML quoting for " + item.substring(next,end)); } posn = next; @@ -197,7 +197,7 @@ public class HtmlQuoting { buffer.append(item.substring(posn, len)); return buffer.toString(); } - + public static void main(String[] args) throws Exception { if (args.length == 0) { throw new IllegalArgumentException("Please provide some arguments"); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpConfig.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpConfig.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpConfig.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpConfig.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLog.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLog.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLog.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLog.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLogAppender.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLogAppender.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLogAppender.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpRequestLogAppender.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HttpServerUtil.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServerUtil.java similarity index 98% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/util/HttpServerUtil.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServerUtil.java index 59c6ad6a72..0b33fd124c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HttpServerUtil.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServerUtil.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.util; +package org.apache.hadoop.hbase.http; import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.util.security.Constraint; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java similarity index 99% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java index b5f4183b3d..5fd6514f91 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/InfoServer.java @@ -38,7 +38,7 @@ import org.apache.hadoop.conf.Configuration; */ @InterfaceAudience.Private public class InfoServer { - + private static final String HBASE_APP_DIR = "hbase-webapps"; private final org.apache.hadoop.hbase.http.HttpServer httpServer; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/NoCacheFilter.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/NoCacheFilter.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/NoCacheFilter.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/NoCacheFilter.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java similarity index 99% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java index 4ae4a2fc00..8f338a7af6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/ServerConfigurationKeys.java @@ -20,7 +20,7 @@ package org.apache.hadoop.hbase.http; import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceStability; -/** +/** * This interface contains constants for configuration keys used * in the hbase http server code. */ diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/conf/ConfServlet.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/conf/ConfServlet.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/conf/ConfServlet.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/conf/ConfServlet.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java similarity index 96% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java index 3abad3a8b6..2e43be2677 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -57,23 +57,23 @@ import org.apache.hadoop.hbase.util.JSONBean; * all hadoop metrics exposed through JMX. *

*

- * The optional get parameter is used to query an specific + * The optional get parameter is used to query an specific * attribute of a JMX bean. The format of the URL is * http://.../jmx?get=MXBeanName::AttributeName *

*

- * For example + * For example * * http://../jmx?get=Hadoop:service=NameNode,name=NameNodeInfo::ClusterId * will return the cluster id of the namenode mxbean. *

*

- * If the qry or the get parameter is not formatted - * correctly then a 400 BAD REQUEST http response code will be returned. + * If the qry or the get parameter is not formatted + * correctly then a 400 BAD REQUEST http response code will be returned. *

*

- * If a resouce such as a mbean or attribute can not be found, - * a 404 SC_NOT_FOUND http response code will be returned. + * If a resouce such as a mbean or attribute can not be found, + * a 404 SC_NOT_FOUND http response code will be returned. *

*

* The return format is JSON and in the form @@ -91,24 +91,24 @@ import org.apache.hadoop.hbase.util.JSONBean; *

* The servlet attempts to convert the the JMXBeans into JSON. Each * bean's attributes will be converted to a JSON object member. - * + * * If the attribute is a boolean, a number, a string, or an array - * it will be converted to the JSON equivalent. - * + * it will be converted to the JSON equivalent. + * * If the value is a {@link CompositeData} then it will be converted * to a JSON object with the keys as the name of the JSON member and * the value is converted following these same rules. - * + * * If the value is a {@link TabularData} then it will be converted * to an array of the {@link CompositeData} elements that it contains. - * + * * All other objects will be converted to a string and output as such. - * + * * The bean's name and modelerType will be returned for all beans. * * Optional paramater "callback" should be used to deliver JSONP response. *

- * + * */ public class JMXJsonServlet extends HttpServlet { private static final Log LOG = LogFactory.getLog(JMXJsonServlet.class); @@ -142,7 +142,7 @@ public class JMXJsonServlet extends HttpServlet { /** * Process a GET request for the specified resource. - * + * * @param request * The servlet request we are processing * @param response @@ -161,7 +161,7 @@ public class JMXJsonServlet extends HttpServlet { jsonpcb = checkCallbackName(request.getParameter(CALLBACK_PARAM)); writer = response.getWriter(); beanWriter = this.jsonBeanWriter.open(writer); - + // "callback" parameter implies JSONP outpout if (jsonpcb != null) { response.setContentType("application/javascript; charset=utf8"); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java similarity index 99% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java index 324cc2dd85..21667d779a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/package-info.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java similarity index 96% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java index bce3a07931..a1fa9f00a0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/lib/StaticUserWebFilter.java @@ -77,7 +77,7 @@ public class StaticUserWebFilter extends FilterInitializer { @Override public String toString() { return name; - } + } } @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG) @@ -99,7 +99,7 @@ public class StaticUserWebFilter extends FilterInitializer { if (httpRequest.getRemoteUser() != null) { chain.doFilter(request, response); } else { - HttpServletRequestWrapper wrapper = + HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(httpRequest) { @Override public Principal getUserPrincipal() { @@ -119,18 +119,18 @@ public class StaticUserWebFilter extends FilterInitializer { this.username = conf.getInitParameter(HBASE_HTTP_STATIC_USER); this.user = new User(username); } - + } @Override public void initFilter(FilterContainer container, Configuration conf) { HashMap options = new HashMap<>(); - + String username = getUsernameFromConf(conf); options.put(HBASE_HTTP_STATIC_USER, username); - container.addFilter("static_user_filter", - StaticUserFilter.class.getName(), + container.addFilter("static_user_filter", + StaticUserFilter.class.getName(), options); } @@ -142,7 +142,7 @@ public class StaticUserWebFilter extends FilterInitializer { if (oldStyleUgi != null) { // We can't use the normal configuration deprecation mechanism here // since we need to split out the username from the configured UGI. - LOG.warn(DEPRECATED_UGI_KEY + " should not be used. Instead, use " + + LOG.warn(DEPRECATED_UGI_KEY + " should not be used. Instead, use " + HBASE_HTTP_STATIC_USER + "."); String[] parts = oldStyleUgi.split(","); return parts[0]; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/lib/package-info.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/lib/package-info.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/lib/package-info.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/lib/package-info.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/log/LogLevel.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/http/package-info.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/package-info.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/http/package-info.java rename to hbase-http/src/main/java/org/apache/hadoop/hbase/http/package-info.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java similarity index 99% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java index 7d610e45f7..69972a2e12 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/HttpServerFunctionalTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + package org.apache.hadoop.hbase.http; import org.apache.hadoop.net.NetUtils; @@ -41,7 +41,7 @@ public class HttpServerFunctionalTest extends Assert { public static final String TEST_BUILD_WEBAPPS = "test.build.webapps"; /** expected location of the test.build.webapps dir: {@value} */ private static final String BUILD_WEBAPPS_DIR = "src/main/resources/hbase-webapps"; - + /** name of the test webapp: {@value} */ private static final String TEST = "test"; @@ -89,7 +89,7 @@ public class HttpServerFunctionalTest extends Assert { * @throws IOException if a problem occurs * @throws AssertionError if a condition was not met */ - public static HttpServer createTestServer(Configuration conf, + public static HttpServer createTestServer(Configuration conf, String[] pathSpecs) throws IOException { prepareTestWebapp(); return createServer(TEST, conf, pathSpecs); @@ -167,7 +167,7 @@ public class HttpServerFunctionalTest extends Assert { return new HttpServer.Builder().setName(webapp).addEndpoint( URI.create("http://localhost:0")); } - + /** * Create an HttpServer instance for the given webapp * @param webapp the webapp to work with diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java similarity index 99% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java index acfe9293d2..729dd06b4c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestGlobalFilter.java @@ -83,15 +83,15 @@ public class TestGlobalFilter extends HttpServerFunctionalTest { } } } - - + + /** access a url, ignoring some IOException such as the page does not exist */ static void access(String urlstring) throws IOException { LOG.warn("access " + urlstring); URL url = new URL(urlstring); URLConnection connection = url.openConnection(); connection.connect(); - + try { BufferedReader in = new BufferedReader(new InputStreamReader( connection.getInputStream())); @@ -108,7 +108,7 @@ public class TestGlobalFilter extends HttpServerFunctionalTest { @Test public void testServletFilter() throws Exception { Configuration conf = new Configuration(); - + //start a http server with CountingFilter conf.set(HttpServer.FILTER_INITIALIZERS_PROPERTY, RecordingFilter.Initializer.class.getName()); @@ -126,7 +126,7 @@ public class TestGlobalFilter extends HttpServerFunctionalTest { final String outURL = "/static/a.out"; final String logURL = "/logs/a.log"; - final String[] urls = {fsckURL, stacksURL, ajspURL, listPathsURL, + final String[] urls = {fsckURL, stacksURL, ajspURL, listPathsURL, dataURL, streamFile, rootURL, allURL, outURL, logURL}; //access the urls @@ -141,7 +141,7 @@ public class TestGlobalFilter extends HttpServerFunctionalTest { } LOG.info("RECORDS = " + RECORDS); - + //verify records for(int i = 0; i < urls.length; i++) { assertTrue(RECORDS.remove(urls[i])); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java similarity index 98% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java index 82fbe04150..5bc026c7fc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHtmlQuoting.java @@ -51,10 +51,10 @@ public class TestHtmlQuoting { } private void runRoundTrip(String str) throws Exception { - assertEquals(str, + assertEquals(str, HtmlQuoting.unquoteHtmlChars(HtmlQuoting.quoteHtmlChars(str))); } - + @Test public void testRoundtrip() throws Exception { runRoundTrip(""); runRoundTrip("<>&'\""); @@ -67,18 +67,18 @@ public class TestHtmlQuoting { } runRoundTrip(buffer.toString()); } - + @Test public void testRequestQuoting() throws Exception { HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class); HttpServer.QuotingInputFilter.RequestQuoter quoter = new HttpServer.QuotingInputFilter.RequestQuoter(mockReq); - + Mockito.doReturn("a"))); + assertEquals("a:b\nc<:d\ne:>\n", + readOutput(new URL(baseUrl, "/echo?a=b&c<=d&e=>"))); } - + /** Test the echo map servlet that uses getParameterMap. */ @Test public void testEchoMap() throws Exception { - assertEquals("a:b\nc:d\n", + assertEquals("a:b\nc:d\n", readOutput(new URL(baseUrl, "/echomap?a=b&c=d"))); - assertEquals("a:b,>\nc<:d\n", + assertEquals("a:b,>\nc<:d\n", readOutput(new URL(baseUrl, "/echomap?a=b&c<=d&a=>"))); } - /** - * Test that verifies headers can be up to 64K long. + /** + * Test that verifies headers can be up to 64K long. * The test adds a 63K header leaving 1K for other headers. * This is because the header buffer setting is for ALL headers, * names and values included. */ @@ -275,7 +275,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { * Dummy filter that mimics as an authentication filter. Obtains user identity * from the request parameter user.name. Wraps around the request so that * request.getRemoteUser() returns the user identity. - * + * */ public static class DummyServletFilter implements Filter { @Override @@ -317,7 +317,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { * Access a URL and get the corresponding return Http status code. The URL * will be accessed as the passed user, by sending user.name request * parameter. - * + * * @param urlstring * @param userName * @return @@ -352,7 +352,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { * Verify the access for /logs, /stacks, /conf, /logLevel and /metrics * servlets, when authentication filters are set, but authorization is not * enabled. - * @throws Exception + * @throws Exception */ @Test @Ignore @@ -388,7 +388,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { /** * Verify the administrator access for /logs, /stacks, /conf, /logLevel and * /metrics servlets. - * + * * @throws Exception */ @Test @@ -431,7 +431,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { } myServer.stop(); } - + @Test public void testRequestQuoterWithNull() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); @@ -534,7 +534,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { // hang onto this one for a bit more testing HttpServer myServer = checkBindAddress("localhost", 0, false); HttpServer myServer2 = null; - try { + try { int port = myServer.getConnectorAddress(0).getPort(); // it's already in use, true = expect a higher port myServer2 = checkBindAddress("localhost", port, true); @@ -551,7 +551,7 @@ public class TestHttpServer extends HttpServerFunctionalTest { } } } - + private HttpServer checkBindAddress(String host, int port, boolean findPort) throws Exception { HttpServer server = createServer(host, port); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerLifecycle.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerLifecycle.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerLifecycle.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerLifecycle.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerWebapps.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerWebapps.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerWebapps.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestHttpServerWebapps.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java similarity index 99% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java index 3c2de5391a..5eff2b4fb3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestPathFilter.java @@ -83,16 +83,16 @@ public class TestPathFilter extends HttpServerFunctionalTest { } } } - - + + /** access a url, ignoring some IOException such as the page does not exist */ static void access(String urlstring) throws IOException { LOG.warn("access " + urlstring); URL url = new URL(urlstring); - + URLConnection connection = url.openConnection(); connection.connect(); - + try { BufferedReader in = new BufferedReader(new InputStreamReader( connection.getInputStream())); @@ -109,7 +109,7 @@ public class TestPathFilter extends HttpServerFunctionalTest { @Test public void testPathSpecFilters() throws Exception { Configuration conf = new Configuration(); - + //start a http server with CountingFilter conf.set(HttpServer.FILTER_INITIALIZERS_PROPERTY, RecordingFilter.Initializer.class.getName()); @@ -125,11 +125,11 @@ public class TestPathFilter extends HttpServerFunctionalTest { final String rootURL = "/"; final String allURL = "/*"; - final String[] filteredUrls = {baseURL, baseSlashURL, addedURL, + final String[] filteredUrls = {baseURL, baseSlashURL, addedURL, addedSlashURL, longURL}; final String[] notFilteredUrls = {rootURL, allURL}; - // access the urls and verify our paths specs got added to the + // access the urls and verify our paths specs got added to the // filters final String prefix = "http://" + NetUtils.getHostPortString(http.getConnectorAddress(0)); @@ -145,7 +145,7 @@ public class TestPathFilter extends HttpServerFunctionalTest { } LOG.info("RECORDS = " + RECORDS); - + //verify records for(int i = 0; i < filteredUrls.length; i++) { assertTrue(RECORDS.remove(filteredUrls[i])); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestSSLHttpServer.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestSSLHttpServer.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestSSLHttpServer.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestSSLHttpServer.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java similarity index 91% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java index 1d24ec21a2..32bc03ed2b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestServletFilter.java @@ -35,10 +35,11 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.GenericTestUtils; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.net.NetUtils; +import org.apache.hadoop.util.StringUtils; +import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -46,7 +47,7 @@ import org.junit.experimental.categories.Category; @Category({MiscTests.class, SmallTests.class}) public class TestServletFilter extends HttpServerFunctionalTest { private static final Log LOG = LogFactory.getLog(HttpServer.class); - static volatile String uri = null; + static volatile String uri = null; /** A very simple filter which record the uri filtered. */ static public class SimpleFilter implements Filter { @@ -83,15 +84,21 @@ public class TestServletFilter extends HttpServerFunctionalTest { } } } - - + + public static void assertExceptionContains(String string, Throwable t) { + String msg = t.getMessage(); + Assert.assertTrue( + "Expected to find '" + string + "' but got unexpected exception:" + + StringUtils.stringifyException(t), msg.contains(string)); + } + /** access a url, ignoring some IOException such as the page does not exist */ static void access(String urlstring) throws IOException { LOG.warn("access " + urlstring); URL url = new URL(urlstring); URLConnection connection = url.openConnection(); connection.connect(); - + try { BufferedReader in = new BufferedReader(new InputStreamReader( connection.getInputStream())); @@ -112,7 +119,7 @@ public class TestServletFilter extends HttpServerFunctionalTest { // It's second class. Could comment it out if only failing test (as per @nkeywal – sort of) public void testServletFilter() throws Exception { Configuration conf = new Configuration(); - + //start a http server with CountingFilter conf.set(HttpServer.FILTER_INITIALIZERS_PROPERTY, SimpleFilter.Initializer.class.getName()); @@ -124,12 +131,12 @@ public class TestServletFilter extends HttpServerFunctionalTest { final String ajspURL = "/a.jsp"; final String logURL = "/logs/a.log"; final String hadooplogoURL = "/static/hadoop-logo.jpg"; - + final String[] urls = {fsckURL, stacksURL, ajspURL, logURL, hadooplogoURL}; final Random ran = new Random(); final int[] sequence = new int[50]; - //generate a random sequence and update counts + //generate a random sequence and update counts for(int i = 0; i < sequence.length; i++) { sequence[i] = ran.nextInt(urls.length); } @@ -153,7 +160,7 @@ public class TestServletFilter extends HttpServerFunctionalTest { http.stop(); } } - + static public class ErrorFilter extends SimpleFilter { @Override public void init(FilterConfig arg0) throws ServletException { @@ -183,10 +190,10 @@ public class TestServletFilter extends HttpServerFunctionalTest { http.start(); fail("expecting exception"); } catch (IOException e) { - GenericTestUtils.assertExceptionContains("Problem starting http server", e); + assertExceptionContains("Problem starting http server", e); } } - + /** * Similar to the above test case, except that it uses a different API to add the * filter. Regression test for HADOOP-8786. @@ -203,7 +210,7 @@ public class TestServletFilter extends HttpServerFunctionalTest { http.start(); fail("expecting exception"); } catch (IOException e) { - GenericTestUtils.assertExceptionContains("Unable to initialize WebAppContext", e); + assertExceptionContains("Unable to initialize WebAppContext", e); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestSpnegoHttpServer.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestSpnegoHttpServer.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/TestSpnegoHttpServer.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/TestSpnegoHttpServer.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java similarity index 98% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java index e1d9acaa27..8bd1e6d38b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java @@ -82,7 +82,7 @@ public class TestConfServlet extends TestCase { ConfServlet.writeResponse(getTestConf(), sw, "xml"); String xml = sw.toString(); - DocumentBuilderFactory docBuilderFactory + DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(xml))); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java similarity index 97% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java index d7e68d5708..484162af55 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -50,41 +50,41 @@ public class TestJMXJsonServlet extends HttpServerFunctionalTest { server.start(); baseUrl = getServerURL(server); } - + @AfterClass public static void cleanup() throws Exception { server.stop(); } - + public static void assertReFind(String re, String value) { Pattern p = Pattern.compile(re); Matcher m = p.matcher(value); assertTrue("'"+p+"' does not match "+value, m.find()); } - + @Test public void testQuery() throws Exception { String result = readOutput(new URL(baseUrl, "/jmx?qry=java.lang:type=Runtime")); LOG.info("/jmx?qry=java.lang:type=Runtime RESULT: "+result); assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Runtime\"", result); assertReFind("\"modelerType\"", result); - + result = readOutput(new URL(baseUrl, "/jmx?qry=java.lang:type=Memory")); LOG.info("/jmx?qry=java.lang:type=Memory RESULT: "+result); assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result); assertReFind("\"modelerType\"", result); - + result = readOutput(new URL(baseUrl, "/jmx")); LOG.info("/jmx RESULT: "+result); assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result); - + // test to get an attribute of a mbean - result = readOutput(new URL(baseUrl, + result = readOutput(new URL(baseUrl, "/jmx?get=java.lang:type=Memory::HeapMemoryUsage")); LOG.info("/jmx RESULT: "+result); assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result); assertReFind("\"committed\"\\s*:", result); - + // negative test to get an attribute of a mbean - result = readOutput(new URL(baseUrl, + result = readOutput(new URL(baseUrl, "/jmx?get=java.lang:type=Memory::")); LOG.info("/jmx RESULT: "+result); assertReFind("\"ERROR\"", result); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java similarity index 98% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java index 81bcbd582f..3adca50bba 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/lib/TestStaticUserWebFilter.java @@ -45,30 +45,30 @@ public class TestStaticUserWebFilter { ServerConfigurationKeys.HBASE_HTTP_STATIC_USER); return mock; } - + @Test public void testFilter() throws Exception { FilterConfig config = mockConfig("myuser"); StaticUserFilter suf = new StaticUserFilter(); suf.init(config); - + ArgumentCaptor wrapperArg = ArgumentCaptor.forClass(HttpServletRequestWrapper.class); FilterChain chain = mock(FilterChain.class); - + suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class), chain); - + Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito.anyObject()); - + HttpServletRequestWrapper wrapper = wrapperArg.getValue(); assertEquals("myuser", wrapper.getUserPrincipal().getName()); assertEquals("myuser", wrapper.getRemoteUser()); - + suf.destroy(); } - + @Test public void testOldStyleConfiguration() { Configuration conf = new Configuration(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/resource/JerseyResource.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/resource/JerseyResource.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/resource/JerseyResource.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/resource/JerseyResource.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java similarity index 99% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java rename to hbase-http/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java index 234bd7a18e..35d6236949 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/ssl/KeyStoreTestUtil.java @@ -69,8 +69,8 @@ public class KeyStoreTestUtil { * @param algorithm the signing algorithm, eg "SHA1withRSA" * @return the self-signed certificate */ - public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm) - throws CertificateEncodingException, InvalidKeyException, IllegalStateException, + public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm) + throws CertificateEncodingException, InvalidKeyException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException { Date from = new Date(); Date to = new Date(from.getTime() + days * 86400000l); @@ -127,7 +127,7 @@ public class KeyStoreTestUtil { /** * Creates a keystore with a single key and saves it to a file. - * + * * @param filename String file to save * @param password String store password to set on keystore * @param keyPassword String key password to set on key @@ -185,7 +185,7 @@ public class KeyStoreTestUtil { * SSLFactory. This includes keys, certs, keystores, truststores, the server * SSL configuration file, the client SSL configuration file, and the master * configuration file read by the SSLFactory. - * + * * @param keystoresDir String directory to save keystores * @param sslConfDir String directory to save SSL configuration files * @param conf Configuration master configuration to be used by an SSLFactory, @@ -244,7 +244,7 @@ public class KeyStoreTestUtil { /** * Creates SSL configuration for a client. - * + * * @param clientKS String client keystore file * @param password String store password, or null to avoid setting store * password @@ -262,7 +262,7 @@ public class KeyStoreTestUtil { /** * Creates SSL configuration for a server. - * + * * @param serverKS String server keystore file * @param password String store password, or null to avoid setting store * password @@ -280,7 +280,7 @@ public class KeyStoreTestUtil { /** * Creates SSL configuration. - * + * * @param mode SSLFactory.Mode mode to configure * @param keystore String keystore file * @param password String store password, or null to avoid setting store @@ -325,7 +325,7 @@ public class KeyStoreTestUtil { /** * Saves configuration to a file. - * + * * @param file File to save * @param conf Configuration contents to write to file * @throws IOException if there is an I/O error saving the file diff --git a/hbase-http/src/test/resources/log4j.properties b/hbase-http/src/test/resources/log4j.properties new file mode 100644 index 0000000000..c322699ced --- /dev/null +++ b/hbase-http/src/test/resources/log4j.properties @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Define some default values that can be overridden by system properties +hbase.root.logger=INFO,console +hbase.log.dir=. +hbase.log.file=hbase.log + +# Define the root logger to the system property "hbase.root.logger". +log4j.rootLogger=${hbase.root.logger} + +# Logging Threshold +log4j.threshold=ALL + +# +# Daily Rolling File Appender +# +log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} + +# Rollver at midnight +log4j.appender.DRFA.DatePattern=.yyyy-MM-dd + +# 30-day backup +#log4j.appender.DRFA.MaxBackupIndex=30 +log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout +# Debugging Pattern format +log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n + + +# +# console +# Add "console" to rootlogger above if you want to use this +# +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %C{2}(%L): %m%n + +# Custom Logging levels + +#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG + +log4j.logger.org.apache.hadoop=WARN +log4j.logger.org.apache.zookeeper=ERROR +log4j.logger.org.apache.hadoop.hbase=DEBUG + +#These settings are workarounds against spurious logs from the minicluster. +#See HBASE-4709 +log4j.logger.org.apache.hadoop.metrics2.impl.MetricsConfig=WARN +log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSinkAdapter=WARN +log4j.logger.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=WARN +log4j.logger.org.apache.hadoop.metrics2.util.MBeans=WARN +# Enable this to get detailed connection error/retry logging. +# log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE diff --git a/hbase-http/src/test/resources/webapps/static/test.css b/hbase-http/src/test/resources/webapps/static/test.css new file mode 100644 index 0000000000..ae4382869a --- /dev/null +++ b/hbase-http/src/test/resources/webapps/static/test.css @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Test CSS file for content type handling - empty, since we just check + * returned content type! + */ diff --git a/hbase-http/src/test/resources/webapps/test/testjsp.jsp b/hbase-http/src/test/resources/webapps/test/testjsp.jsp new file mode 100644 index 0000000000..23465da295 --- /dev/null +++ b/hbase-http/src/test/resources/webapps/test/testjsp.jsp @@ -0,0 +1,21 @@ +<%! +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +%> +<%@ page contentType="text/html; charset=UTF-8" %> +Hello world! diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServer.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServer.java index c2f6cf6a61..360ab9d5e6 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServer.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServer.java @@ -20,10 +20,8 @@ package org.apache.hadoop.hbase.rest; import java.lang.management.ManagementFactory; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.EnumSet; import java.util.concurrent.ArrayBlockingQueue; @@ -46,7 +44,7 @@ import org.apache.hadoop.hbase.rest.filter.GzipFilter; import org.apache.hadoop.hbase.rest.filter.RestCsrfPreventionFilter; import org.apache.hadoop.hbase.security.UserProvider; import org.apache.hadoop.hbase.util.DNS; -import org.apache.hadoop.hbase.util.HttpServerUtil; +import org.apache.hadoop.hbase.http.HttpServerUtil; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Strings; import org.apache.hadoop.hbase.util.VersionInfo; diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTTestingUtility.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTTestingUtility.java index 0714c7bcc8..4c977fd1f7 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTTestingUtility.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTTestingUtility.java @@ -24,7 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.security.UserProvider; -import org.apache.hadoop.hbase.util.HttpServerUtil; +import org.apache.hadoop.hbase.http.HttpServerUtil; import org.apache.hadoop.util.StringUtils; import org.eclipse.jetty.server.HttpConfiguration; @@ -99,7 +99,7 @@ public class HBaseRESTTestingUtility { // get the port testServletPort = ((ServerConnector)server.getConnectors()[0]).getLocalPort(); - LOG.info("started " + server.getClass().getName() + " on port " + + LOG.info("started " + server.getClass().getName() + " on port " + testServletPort); } diff --git a/hbase-server/pom.xml b/hbase-server/pom.xml index 3a025d1b13..ea02f26efc 100644 --- a/hbase-server/pom.xml +++ b/hbase-server/pom.xml @@ -359,6 +359,16 @@ org.apache.hbase hbase-common
+ + org.apache.hbase + hbase-http + + + org.apache.hbase + hbase-http + test-jar + test + org.glassfish.web javax.servlet.jsp - - - org.glassfish - javax.el - org.codehaus.jettison jettison diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DumpRegionServerMetrics.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DumpRegionServerMetrics.java new file mode 100644 index 0000000000..2b07a64253 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/DumpRegionServerMetrics.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver; + +import org.apache.hadoop.hbase.util.JSONBean; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.management.ManagementFactory; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + +/** + * Utility for doing JSON and MBeans. + */ +public class DumpRegionServerMetrics { + /** + * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out. + */ + public static String dumpMetrics() throws MalformedObjectNameException, IOException { + StringWriter sw = new StringWriter(1024 * 100); // Guess this size + try (PrintWriter writer = new PrintWriter(sw)) { + JSONBean dumper = new JSONBean(); + try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) { + MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); + jsonBeanWriter.write(mbeanServer, + new ObjectName("java.lang:type=Memory"), null, false); + jsonBeanWriter.write(mbeanServer, + new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"), null, false); + jsonBeanWriter.write(mbeanServer, + new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false); + jsonBeanWriter.write(mbeanServer, + new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false); + } + } + sw.close(); + return sw.toString(); + } + + public static void main(String[] args) throws IOException, MalformedObjectNameException { + String str = dumpMetrics(); + System.out.println(str); + } +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index d396b3e981..339b331d75 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -147,7 +147,6 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSTableDescriptors; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.HasThread; -import org.apache.hadoop.hbase.util.JSONBean; import org.apache.hadoop.hbase.util.JvmPauseMonitor; import org.apache.hadoop.hbase.util.NettyEventLoopGroupConfig; import org.apache.hadoop.hbase.util.Pair; @@ -2347,7 +2346,7 @@ public class HRegionServer extends HasThread implements CoprocessorHost.getLoadedCoprocessors()); // Try and dump metrics if abort -- might give clue as to how fatal came about.... try { - LOG.info("Dump of metrics as JSON on abort: " + JSONBean.dumpRegionServerMetrics()); + LOG.info("Dump of metrics as JSON on abort: " + DumpRegionServerMetrics.dumpMetrics()); } catch (MalformedObjectNameException | IOException e) { LOG.warn("Failed dumping metrics", e); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java index 2014b5b23a..08565e07af 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/GenericTestUtils.java @@ -35,7 +35,6 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.Log4JLogger; import org.apache.hadoop.fs.FileUtil; -import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.Time; import org.apache.log4j.Layout; import org.apache.log4j.Logger; @@ -70,14 +69,14 @@ public abstract class GenericTestUtils { public static int uniqueSequenceId() { return sequence.incrementAndGet(); } - + /** * Assert that a given file exists. */ public static void assertExists(File f) { Assert.assertTrue("File " + f + " should exist", f.exists()); } - + /** * List all of the files in 'dir' that match the regex 'pattern'. * Then check that this list is identical to 'expectedMatches'. @@ -85,7 +84,7 @@ public abstract class GenericTestUtils { */ public static void assertGlobEquals(File dir, String pattern, String ... expectedMatches) throws IOException { - + Set found = Sets.newTreeSet(); for (File f : FileUtil.listFiles(dir)) { if (f.getName().matches(pattern)) { @@ -98,13 +97,6 @@ public abstract class GenericTestUtils { Joiner.on(",").join(expectedSet), Joiner.on(",").join(found)); } - - public static void assertExceptionContains(String string, Throwable t) { - String msg = t.getMessage(); - Assert.assertTrue( - "Expected to find '" + string + "' but got unexpected exception:" - + StringUtils.stringifyException(t), msg.contains(string)); - } public static void waitFor(Supplier check, int checkEveryMillis, int waitForMillis) @@ -116,26 +108,26 @@ public abstract class GenericTestUtils { if (result) { return; } - + Thread.sleep(checkEveryMillis); } while (Time.now() - st < waitForMillis); - + throw new TimeoutException("Timed out waiting for condition. " + "Thread diagnostics:\n" + TimedOutTestsListener.buildThreadDiagnosticString()); } - + public static class LogCapturer { private StringWriter sw = new StringWriter(); private WriterAppender appender; private Logger logger; - + public static LogCapturer captureLogs(Log l) { Logger logger = ((Log4JLogger)l).getLogger(); LogCapturer c = new LogCapturer(logger); return c; } - + private LogCapturer(Logger logger) { this.logger = logger; @@ -143,36 +135,36 @@ public abstract class GenericTestUtils { WriterAppender wa = new WriterAppender(layout, sw); logger.addAppender(wa); } - + public String getOutput() { return sw.toString(); } - + public void stopCapturing() { logger.removeAppender(appender); } } - - + + /** * Mockito answer helper that triggers one latch as soon as the * method is called, then waits on another before continuing. */ public static class DelayAnswer implements Answer { private final Log LOG; - + private final CountDownLatch fireLatch = new CountDownLatch(1); private final CountDownLatch waitLatch = new CountDownLatch(1); private final CountDownLatch resultLatch = new CountDownLatch(1); - + private final AtomicInteger fireCounter = new AtomicInteger(0); private final AtomicInteger resultCounter = new AtomicInteger(0); - + // Result fields set after proceed() is called. private volatile Throwable thrown; private volatile Object returnValue; - + public DelayAnswer(Log log) { this.LOG = log; } @@ -183,7 +175,7 @@ public abstract class GenericTestUtils { public void waitForCall() throws InterruptedException { fireLatch.await(); } - + /** * Tell the method to proceed. * This should only be called after waitForCall() @@ -191,7 +183,7 @@ public abstract class GenericTestUtils { public void proceed() { waitLatch.countDown(); } - + @Override public Object answer(InvocationOnMock invocation) throws Throwable { LOG.info("DelayAnswer firing fireLatch"); @@ -220,7 +212,7 @@ public abstract class GenericTestUtils { resultLatch.countDown(); } } - + /** * After calling proceed(), this will wait until the call has * completed and a result has been returned to the caller. @@ -228,7 +220,7 @@ public abstract class GenericTestUtils { public void waitForResult() throws InterruptedException { resultLatch.await(); } - + /** * After the call has gone through, return any exception that * was thrown, or null if no exception was thrown. @@ -236,7 +228,7 @@ public abstract class GenericTestUtils { public Throwable getThrown() { return thrown; } - + /** * After the call has gone through, return the call's return value, * or null in case it was void or an exception was thrown. @@ -244,20 +236,20 @@ public abstract class GenericTestUtils { public Object getReturnValue() { return returnValue; } - + public int getFireCount() { return fireCounter.get(); } - + public int getResultCount() { return resultCounter.get(); } } - + /** * An Answer implementation that simply forwards all calls through * to a delegate. - * + * * This is useful as the default Answer for a mock object, to create * something like a spy on an RPC proxy. For example: * @@ -268,14 +260,14 @@ public abstract class GenericTestUtils { * ... * */ - public static class DelegateAnswer implements Answer { + public static class DelegateAnswer implements Answer { private final Object delegate; private final Log log; - + public DelegateAnswer(Object delegate) { this(null, delegate); } - + public DelegateAnswer(Log log, Object delegate) { this.log = log; this.delegate = delegate; @@ -305,11 +297,11 @@ public abstract class GenericTestUtils { public static class SleepAnswer implements Answer { private final int maxSleepTime; private static Random r = new Random(); - + public SleepAnswer(int maxSleepTime) { this.maxSleepTime = maxSleepTime; } - + @Override public Object answer(InvocationOnMock invocation) throws Throwable { boolean interrupted = false; @@ -333,11 +325,11 @@ public abstract class GenericTestUtils { " but got:\n" + output, Pattern.compile(pattern).matcher(output).find()); } - + public static void assertValueNear(long expected, long actual, long allowedError) { assertValueWithinRange(expected - allowedError, expected + allowedError, actual); } - + public static void assertValueWithinRange(long expectedMin, long expectedMax, long actual) { Assert.assertTrue("Expected " + actual + " to be in range (" + expectedMin + "," @@ -352,7 +344,7 @@ public abstract class GenericTestUtils { public static void assertNoThreadsMatching(String regex) { Pattern pattern = Pattern.compile(regex); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); - + ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20); for (ThreadInfo info : infos) { if (info == null) continue; diff --git a/hbase-shaded/hbase-shaded-mapreduce/pom.xml b/hbase-shaded/hbase-shaded-mapreduce/pom.xml index 1f2a2bf1ec..cfcc357877 100644 --- a/hbase-shaded/hbase-shaded-mapreduce/pom.xml +++ b/hbase-shaded/hbase-shaded-mapreduce/pom.xml @@ -141,6 +141,10 @@ org.glassfish.web javax.servlet.jsp + + org.glassfish.jersey.core + jersey-server + org.glassfish.jersey.containers jersey-container-servlet-core diff --git a/pom.xml b/pom.xml index d7cbca2766..c6794c3e6f 100755 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,7 @@ hbase-replication hbase-mapreduce hbase-resource-bundle + hbase-http hbase-server hbase-thrift hbase-shell @@ -1624,6 +1625,18 @@ org.apache.hbase ${project.version} + + hbase-http + org.apache.hbase + ${project.version} + + + hbase-http + org.apache.hbase + ${project.version} + test-jar + test + hbase-server org.apache.hbase @@ -1967,6 +1980,11 @@ jersey-client ${jersey.version} + + org.glassfish.jersey.core + jersey-server + ${jersey.version} + org.glassfish.web @@ -2028,6 +2046,11 @@ ${bouncycastle.version} test + + org.apache.kerby + kerb-core + ${kerby.version} + org.apache.kerby kerb-client -- 2.14.1