You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/09/18 21:10:06 UTC
svn commit: r1387323 [1/2] - in /hbase/trunk: dev-support/
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/ hba...
Author: stack
Date: Tue Sep 18 19:10:03 2012
New Revision: 1387323
URL: http://svn.apache.org/viewvc?rev=1387323&view=rev
Log:
HBASE-6412 Move external servers to metrics2 (thrift,thrift2,rest)
Added:
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilityFactory.java
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSource.java
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSource.java
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactory.java
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceFactory.java
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceFactory.java
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSource.java
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactory.java
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactoryImpl.java
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.metrics.RESTMetricsSource
hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactory
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseMetricsSourceImplTest.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactoryImpl.java
hbase/trunk/hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactoryImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.metrics.RESTMetricsSource
hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactory
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/thrift/
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactoryImpl.java
hbase/trunk/hbase-hadoop2-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper
Removed:
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryTest.java
hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceFactoryTest.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImplTest.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImplTest.java
hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImplTest.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImplTest.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImplTest.java
hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImplTest.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTStatistics.java
Modified:
hbase/trunk/dev-support/test-patch.sh
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java
hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java
hbase/trunk/hbase-hadoop1-compat/pom.xml
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java
hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java
hbase/trunk/hbase-hadoop2-compat/pom.xml
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImpl.java
hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java
hbase/trunk/hbase-server/pom.xml
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetrics.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift/ThriftMetrics.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/rest/TestRowResource.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift/TestCallQueue.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
hbase/trunk/src/docbkx/developer.xml
Modified: hbase/trunk/dev-support/test-patch.sh
URL: http://svn.apache.org/viewvc/hbase/trunk/dev-support/test-patch.sh?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/dev-support/test-patch.sh (original)
+++ hbase/trunk/dev-support/test-patch.sh Tue Sep 18 19:10:03 2012
@@ -382,9 +382,9 @@ checkJavadocWarnings () {
echo "======================================================================"
echo ""
echo ""
- echo "$MVN clean compile javadoc:javadoc -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1"
+ echo "$MVN clean package javadoc:javadoc -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1"
export MAVEN_OPTS="${MAVEN_OPTS}"
- $MVN clean compile javadoc:javadoc -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1
+ $MVN clean package javadoc:javadoc -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1
javadocWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavadocWarnings.txt | $AWK '/Javadoc Warnings/,EOF' | $GREP warning | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
echo ""
echo ""
@@ -415,9 +415,9 @@ checkJavacWarnings () {
echo "======================================================================"
echo ""
echo ""
- echo "$MVN clean compile -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
+ echo "$MVN clean package -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
export MAVEN_OPTS="${MAVEN_OPTS}"
- $MVN clean compile -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavacWarnings.txt 2>&1
+ $MVN clean package -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavacWarnings.txt 2>&1
if [[ $? != 0 ]] ; then
JIRA_COMMENT="$JIRA_COMMENT
@@ -501,9 +501,9 @@ checkStyle () {
echo "THIS IS NOT IMPLEMENTED YET"
echo ""
echo ""
- echo "$MVN compile checkstyle:checkstyle -D${PROJECT_NAME}PatchProcess"
+ echo "$MVN package checkstyle:checkstyle -D${PROJECT_NAME}PatchProcess -DskipTests"
export MAVEN_OPTS="${MAVEN_OPTS}"
- $MVN compile checkstyle:checkstyle -D${PROJECT_NAME}PatchProcess
+ $MVN package checkstyle:checkstyle -D${PROJECT_NAME}PatchProcess -DskipTests
JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
$JIRA_COMMENT_FOOTER"
@@ -534,9 +534,9 @@ checkFindbugsWarnings () {
echo "======================================================================"
echo ""
echo ""
- echo "$MVN clean compile findbugs:findbugs -D${PROJECT_NAME}PatchProcess"
+ echo "$MVN clean package findbugs:findbugs -D${PROJECT_NAME}PatchProcess"
export MAVEN_OPTS="${MAVEN_OPTS}"
- $MVN clean compile findbugs:findbugs -D${PROJECT_NAME}PatchProcess < /dev/null
+ $MVN clean package findbugs:findbugs -D${PROJECT_NAME}PatchProcess -DskipTests < /dev/null
if [ $? != 0 ] ; then
JIRA_COMMENT="$JIRA_COMMENT
Added: hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilityFactory.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilityFactory.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilityFactory.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilityFactory.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,70 @@
+/**
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * Class that will create many instances of classes provided by the hbase-hadoop{1|2}-compat jars.
+ */
+public class CompatibilityFactory {
+
+ private static final Log LOG = LogFactory.getLog(CompatibilitySingletonFactory.class);
+ public static final String EXCEPTION_START = "Could not create ";
+ public static final String EXCEPTION_END = " Is the hadoop compatibility jar on the classpath?";
+
+ public static synchronized <T> T getInstance(Class<T> klass) {
+ T instance = null;
+ try {
+ ServiceLoader<T> loader = ServiceLoader.load(klass);
+ Iterator<T> it = loader.iterator();
+ instance = it.next();
+ if (it.hasNext()) {
+ StringBuilder msg = new StringBuilder();
+ msg.append("ServiceLoader provided more than one implementation for class: ")
+ .append(klass)
+ .append(", using implementation: ").append(instance.getClass())
+ .append(", other implementations: {");
+ while (it.hasNext()) {
+ msg.append(it.next()).append(" ");
+ }
+ msg.append("}");
+ LOG.warn(msg);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(createExceptionString(klass), e);
+ } catch (Error e) {
+ throw new RuntimeException(createExceptionString(klass), e);
+ }
+
+ // If there was nothing returned and no exception then throw an exception.
+ if (instance == null) {
+ throw new RuntimeException(createExceptionString(klass));
+ }
+ return instance;
+ }
+
+ protected static String createExceptionString(Class klass) {
+ return EXCEPTION_START + klass.toString() + EXCEPTION_END;
+ }
+}
Modified: hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java (original)
+++ hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java Tue Sep 18 19:10:03 2012
@@ -20,7 +20,6 @@ package org.apache.hadoop.hbase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.master.metrics.MasterMetricsSource;
import java.util.HashMap;
import java.util.Iterator;
@@ -28,12 +27,11 @@ import java.util.Map;
import java.util.ServiceLoader;
/**
- * Factory for classes supplied by hadoop compatibility modules.
+ * Factory for classes supplied by hadoop compatibility modules. Only one of each class will be
+ * created.
*/
-public class CompatibilitySingletonFactory {
+public class CompatibilitySingletonFactory extends CompatibilityFactory {
private static final Log LOG = LogFactory.getLog(CompatibilitySingletonFactory.class);
- public static final String EXCEPTION_START = "Could not create ";
- public static final String EXCEPTION_END = " Is the hadoop compatibility jar on the classpath?";
private static final Map<Class, Object> instances = new HashMap<Class, Object>();
@@ -75,9 +73,4 @@ public class CompatibilitySingletonFacto
}
return instance;
}
-
- private static String createExceptionString(Class klass) {
- return EXCEPTION_START + klass.toString() + EXCEPTION_END;
- }
-
}
Modified: hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java (original)
+++ hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSource.java Tue Sep 18 19:10:03 2012
@@ -24,6 +24,11 @@ package org.apache.hadoop.hbase.metrics;
public interface BaseMetricsSource {
/**
+ * Clear out the metrics and re-prepare the source.
+ */
+ public void init();
+
+ /**
* Set a gauge to a specific value.
*
* @param gaugeName the name of the gauge
Added: hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSource.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSource.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSource.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,91 @@
+/**
+ * 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.rest.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseMetricsSource;
+
+/**
+ * Interface of the Metrics Source that will export data to Hadoop's Metrics2 system.
+ */
+public interface RESTMetricsSource extends BaseMetricsSource {
+
+ public static String METRICS_NAME = "Rest";
+
+ public static String CONTEXT = "rest";
+
+ public static String JMX_CONTEXT = "Rest";
+
+ public static String METRICS_DESCRIPTION = "Metrics about the HBase REST server";
+
+ static String REQUEST_KEY = "requests";
+
+ static String SUCCESSFUL_GET_KEY = "successfulGet";
+
+ static String SUCCESSFUL_PUT_KEY = "successfulPut";
+
+ static String SUCCESSFUL_DELETE_KEY = "successfulDelete";
+
+ static String FAILED_GET_KEY = "failedGet";
+
+ static String FAILED_PUT_KEY = "failedPut";
+
+ static String FAILED_DELETE_KEY = "failedDelete";
+
+ /**
+ * Increment the number of requests
+ * @param inc Ammount to increment by
+ */
+ void incrementRequests(int inc);
+
+ /**
+ * Increment the number of successful Get requests.
+ * @param inc Number of successful get requests.
+ */
+ void incrementSucessfulGetRequests(int inc);
+
+ /**
+ * Increment the number of successful Put requests.
+ * @param inc Number of successful put requests.
+ */
+ void incrementSucessfulPutRequests(int inc);
+
+ /**
+ * Increment the number of successful Delete requests.
+ * @param inc
+ */
+ void incrementSucessfulDeleteRequests(int inc);
+
+ /**
+ * Increment the number of failed Put Requests.
+ * @param inc Number of failed Put requests.
+ */
+ void incrementFailedPutRequests(int inc);
+
+ /**
+ * Increment the number of failed Get requests.
+ * @param inc The number of failed Get Requests.
+ */
+ void incrementFailedGetRequests(int inc);
+
+ /**
+ * Increment the number of failed Delete requests.
+ * @param inc The number of failed delete requests.
+ */
+ void incrementFailedDeleteRequests(int inc);
+}
Added: hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSource.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSource.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSource.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,78 @@
+/**
+ * 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.thrift.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseMetricsSource;
+
+/**
+ * Inteface of a class that will export metrics about Thrift to hadoop's metrics2.
+ */
+public interface ThriftServerMetricsSource extends BaseMetricsSource {
+
+ public static final String BATCH_GET_KEY = "batchGet";
+ public static final String BATCH_MUTATE_KEY = "batchMutate";
+ public static final String TIME_IN_QUEUE_KEY = "timeInQueue";
+ public static final String THRIFT_CALL_KEY = "thriftCall";
+ public static final String SLOW_THRIFT_CALL_KEY = "slowThriftCall";
+ public static final String CALL_QUEUE_LEN_KEY = "callQueueLen";
+
+ /**
+ * Add how long an operation was in the queue.
+ * @param time
+ */
+ public void incTimeInQueue(long time);
+
+ /**
+ * Set the call queue length.
+ * @param len Time
+ */
+ public void setCallQueueLen(int len);
+
+ /**
+ * Add how many keys were in a batch get.
+ * @param diff Num Keys
+ */
+ public void incNumRowKeysInBatchGet(int diff);
+
+ /**
+ * Add how many keys were in a batch mutate.
+ * @param diff Num Keys
+ */
+ public void incNumRowKeysInBatchMutate(int diff);
+
+ /**
+ * Add how long a method took
+ * @param name Method name
+ * @param time Time
+ */
+ public void incMethodTime(String name, long time);
+
+ /**
+ * Add how long a call took
+ * @param time Time
+ */
+ public void incCall(long time);
+
+ /**
+ * Increment how long a slow call took.
+ * @param time Time
+ */
+ public void incSlowCall(long time);
+
+}
Added: hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactory.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactory.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactory.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactory.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.thrift.metrics;
+
+/** Factory that will be used to create metrics sources for the two diffent types of thrift servers. */
+public interface ThriftServerMetricsSourceFactory {
+
+ public static final String METRICS_NAME = "Thrift";
+ public static final String METRICS_DESCRIPTION = "Thrift Server Metrics";
+ public static final String THRIFT_ONE_METRICS_CONTEXT = "thrift-one";
+ public static final String THRIFT_ONE_JMX_CONTEXT = "Thrift,sub=ThriftOne";
+ public static final String THRIFT_TWO_METRICS_CONTEXT = "thrift-two";
+ public static final String THRIFT_TWO_JMX_CONTEXT = "Thrift,sub=ThriftTwo";
+
+ public ThriftServerMetricsSource createThriftOneSource();
+
+ public ThriftServerMetricsSource createThriftTwoSource();
+
+}
Added: hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceFactory.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceFactory.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceFactory.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceFactory.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.master.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+/**
+ * Test for the CompatibilitySingletonFactory and building MasterMetricsSource
+ */
+public class TestMasterMetricsSourceFactory {
+
+ @Test(expected=RuntimeException.class)
+ public void testGetInstanceNoHadoopCompat() throws Exception {
+ //This should throw an exception because there is no compat lib on the class path.
+ CompatibilitySingletonFactory.getInstance(MasterMetricsSource.class);
+
+ }
+}
Added: hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceFactory.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceFactory.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceFactory.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceFactory.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.replication.regionserver.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+/**
+ * Test for the CompatibilitySingletonFactory and building ReplicationMetricsSource
+ */
+public class TestReplicationMetricsSourceFactory {
+
+ @Test(expected=RuntimeException.class)
+ public void testGetInstanceNoHadoopCompat() throws Exception {
+ //This should throw an exception because there is no compat lib on the class path.
+ CompatibilitySingletonFactory.getInstance(ReplicationMetricsSource.class);
+ }
+}
Added: hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSource.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSource.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSource.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSource.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,36 @@
+/**
+ * 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.rest.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+/**
+ * Test of Rest Metrics Source interface.
+ */
+public class TestRESTMetricsSource {
+
+
+ @Test(expected=RuntimeException.class)
+ public void testGetInstanceNoHadoopCompat() throws Exception {
+ //This should throw an exception because there is no compat lib on the class path.
+ CompatibilitySingletonFactory.getInstance(RESTMetricsSource.class);
+ }
+
+}
Added: hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelper.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,48 @@
+/**
+ * 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.test;
+
+import org.apache.hadoop.hbase.metrics.BaseMetricsSource;
+
+/**
+ *
+ */
+public interface MetricsAssertHelper {
+
+ public void assertTag(String name, String expected, BaseMetricsSource source);
+
+ public void assertGauge(String name, long expected, BaseMetricsSource source);
+
+ public void assertGaugeGt(String name, long expected, BaseMetricsSource source);
+
+ public void assertGaugeLt(String name, long expected, BaseMetricsSource source);
+
+ public void assertGauge(String name, double expected, BaseMetricsSource source);
+
+ public void assertGaugeGt(String name, double expected, BaseMetricsSource source);
+
+ public void assertGaugeLt(String name, double expected, BaseMetricsSource source);
+
+ public void assertCounter(String name, long expected, BaseMetricsSource source);
+
+ public void assertCounterGt(String name, long expected, BaseMetricsSource source);
+
+ public void assertCounterLt(String name, long expected, BaseMetricsSource source);
+
+}
Added: hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactory.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactory.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactory.java (added)
+++ hbase/trunk/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactory.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,36 @@
+/**
+ * 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.thrift.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+/**
+ * Test for the interface of ThriftServerMetricsSourceFactory
+ */
+public class TestThriftServerMetricsSourceFactory {
+
+
+ @Test(expected=RuntimeException.class)
+ public void testGetInstanceNoHadoopCompat() throws RuntimeException {
+ //This should throw an exception because there is no compat lib on the class path.
+ CompatibilitySingletonFactory.getInstance(ThriftServerMetricsSourceFactory.class);
+ }
+
+}
Modified: hbase/trunk/hbase-hadoop1-compat/pom.xml
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/pom.xml?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/pom.xml (original)
+++ hbase/trunk/hbase-hadoop1-compat/pom.xml Tue Sep 18 19:10:03 2012
@@ -61,6 +61,7 @@ limitations under the License.
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-hadoop-compat</artifactId>
+ <version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Modified: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java (original)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java Tue Sep 18 19:10:03 2012
@@ -22,9 +22,16 @@ package org.apache.hadoop.hbase.master.m
* Factory to create MasterMetricsSource when given a MasterMetricsWrapper
*/
public class MasterMetricsSourceFactoryImpl implements MasterMetricsSourceFactory {
+ private static enum FactoryStorage {
+ INSTANCE;
+ MasterMetricsSource source;
+ }
@Override
- public MasterMetricsSource create(MasterMetricsWrapper beanWrapper) {
- return new MasterMetricsSourceImpl(beanWrapper);
+ public synchronized MasterMetricsSource create(MasterMetricsWrapper beanWrapper) {
+ if (FactoryStorage.INSTANCE.source == null ) {
+ FactoryStorage.INSTANCE.source = new MasterMetricsSourceImpl(beanWrapper);
+ }
+ return FactoryStorage.INSTANCE.source;
}
}
Modified: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java (original)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -26,18 +26,16 @@ import org.apache.hadoop.metrics2.Metric
import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
-/**
- * Hadoop1 implementation of MasterMetricsSource.
- */
+/** Hadoop1 implementation of MasterMetricsSource. */
public class MasterMetricsSourceImpl
- extends BaseMetricsSourceImpl implements MasterMetricsSource {
+ extends BaseMetricsSourceImpl implements MasterMetricsSource {
private static final Log LOG = LogFactory.getLog(MasterMetricsSourceImpl.class.getName());
- final MetricMutableCounterLong clusterRequestsCounter;
- final MetricMutableGaugeLong ritGauge;
- final MetricMutableGaugeLong ritCountOverThresholdGauge;
- final MetricMutableGaugeLong ritOldestAgeGauge;
+ MetricMutableCounterLong clusterRequestsCounter;
+ MetricMutableGaugeLong ritGauge;
+ MetricMutableGaugeLong ritCountOverThresholdGauge;
+ MetricMutableGaugeLong ritOldestAgeGauge;
private final MasterMetricsWrapper masterWrapper;
@@ -51,12 +49,16 @@ public class MasterMetricsSourceImpl
String metricsJmxContext,
MasterMetricsWrapper masterWrapper) {
super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
-
this.masterWrapper = masterWrapper;
- clusterRequestsCounter = metricsRegistry.newCounter("cluster_requests", "", 0l);
- ritGauge = metricsRegistry.newGauge("ritCount", "", 0l);
- ritCountOverThresholdGauge = metricsRegistry.newGauge("ritCountOverThreshold","", 0l);
- ritOldestAgeGauge = metricsRegistry.newGauge("ritOldestAge", "", 0l);
+ }
+
+ @Override
+ public void init() {
+ this.metricsRegistry.clearMetrics();
+ clusterRequestsCounter = getMetricsRegistry().getLongCounter("cluster_requests", 0);
+ ritGauge = getMetricsRegistry().getLongGauge("ritCount", 0);
+ ritCountOverThresholdGauge = getMetricsRegistry().getLongGauge("ritCountOverThreshold", 0);
+ ritOldestAgeGauge = getMetricsRegistry().getLongGauge("ritOldestAge", 0);
}
public void incRequests(final int inc) {
@@ -110,4 +112,5 @@ public class MasterMetricsSourceImpl
metricsRegistry.snapshot(metricsRecordBuilder, true);
}
+
}
Modified: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java (original)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -75,6 +75,11 @@ public class BaseMetricsSourceImpl imple
//Register this instance.
DefaultMetricsSystem.INSTANCE.registerSource(metricsJmxContext, metricsDescription, this);
+ init();
+ }
+
+ public void init() {
+ this.metricsRegistry.clearMetrics();
}
@@ -151,4 +156,12 @@ public class BaseMetricsSourceImpl imple
public void getMetrics(MetricsBuilder metricsBuilder, boolean all) {
metricsRegistry.snapshot(metricsBuilder.addRecord(metricsRegistry.name()), all);
}
+
+ /**
+ * Used to get at the DynamicMetricsRegistry.
+ * @return
+ */
+ protected DynamicMetricsRegistry getMetricsRegistry() {
+ return metricsRegistry;
+ }
}
Added: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSourceImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/rest/metrics/RESTMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,97 @@
+/**
+ * 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.rest.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl;
+import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
+
+/**
+ * Hadoop One implementation of a metrics2 source that will export metrics from the Rest server to
+ * the hadoop metrics2 subsystem.
+ */
+public class RESTMetricsSourceImpl extends BaseMetricsSourceImpl implements RESTMetricsSource {
+
+ private MetricMutableCounterLong request;
+ private MetricMutableCounterLong sucGet;
+ private MetricMutableCounterLong sucPut;
+ private MetricMutableCounterLong sucDel;
+ private MetricMutableCounterLong fGet;
+ private MetricMutableCounterLong fPut;
+ private MetricMutableCounterLong fDel;
+
+ public RESTMetricsSourceImpl() {
+ this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
+ }
+
+ public RESTMetricsSourceImpl(String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext) {
+ super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+ }
+
+ @Override
+ public void init() {
+ super.init();
+ request = getMetricsRegistry().getLongCounter(REQUEST_KEY, 0l);
+
+ sucGet = getMetricsRegistry().getLongCounter(SUCCESSFUL_GET_KEY, 0l);
+ sucPut = getMetricsRegistry().getLongCounter(SUCCESSFUL_PUT_KEY, 0l);
+ sucDel = getMetricsRegistry().getLongCounter(SUCCESSFUL_DELETE_KEY, 0l);
+
+ fGet = getMetricsRegistry().getLongCounter(FAILED_GET_KEY, 0l);
+ fPut = getMetricsRegistry().getLongCounter(FAILED_PUT_KEY, 0l);
+ fDel = getMetricsRegistry().getLongCounter(FAILED_DELETE_KEY, 0l);
+ }
+
+ @Override
+ public void incrementRequests(int inc) {
+ request.incr(inc);
+ }
+
+ @Override
+ public void incrementSucessfulGetRequests(int inc) {
+ sucGet.incr(inc);
+ }
+
+ @Override
+ public void incrementSucessfulPutRequests(int inc) {
+ sucPut.incr(inc);
+ }
+
+ @Override
+ public void incrementSucessfulDeleteRequests(int inc) {
+ sucDel.incr(inc);
+ }
+
+ @Override
+ public void incrementFailedGetRequests(int inc) {
+ fGet.incr(inc);
+ }
+
+ @Override
+ public void incrementFailedPutRequests(int inc) {
+ fPut.incr(inc);
+ }
+
+ @Override
+ public void incrementFailedDeleteRequests(int inc) {
+ fDel.incr(inc);
+ }
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactoryImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactoryImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceFactoryImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,52 @@
+/**
+ * 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.thrift.metrics;
+
+/**
+ * Class used to create metrics sources for Thrift and Thrift2 servers in hadoop 1's compat
+ * library.
+ */
+public class ThriftServerMetricsSourceFactoryImpl implements ThriftServerMetricsSourceFactory {
+
+ /**
+ * A singleton used to make sure that only one thrift metrics source per server type is ever
+ * created.
+ */
+ private static enum FactoryStorage {
+ INSTANCE;
+ ThriftServerMetricsSourceImpl thriftOne = new ThriftServerMetricsSourceImpl(METRICS_NAME,
+ METRICS_DESCRIPTION,
+ THRIFT_ONE_METRICS_CONTEXT,
+ THRIFT_ONE_JMX_CONTEXT);
+ ThriftServerMetricsSourceImpl thriftTwo = new ThriftServerMetricsSourceImpl(METRICS_NAME,
+ METRICS_DESCRIPTION,
+ THRIFT_TWO_METRICS_CONTEXT,
+ THRIFT_TWO_JMX_CONTEXT);
+ }
+
+ @Override
+ public ThriftServerMetricsSource createThriftOneSource() {
+ return FactoryStorage.INSTANCE.thriftOne;
+ }
+
+ @Override
+ public ThriftServerMetricsSource createThriftTwoSource() {
+ return FactoryStorage.INSTANCE.thriftTwo;
+ }
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/thrift/metrics/ThriftServerMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,97 @@
+/**
+ * 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.thrift.metrics;
+
+import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl;
+import org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSource;
+import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
+import org.apache.hadoop.metrics2.lib.MetricMutableStat;
+
+/**
+ * Hadoop 1 version of ThriftServerMetricsSource{@link ThriftServerMetricsSource}
+ */
+public class ThriftServerMetricsSourceImpl extends BaseMetricsSourceImpl implements
+ ThriftServerMetricsSource {
+
+
+ private MetricMutableStat batchGetStat;
+ private MetricMutableStat batchMutateStat;
+ private MetricMutableStat queueTimeStat;
+
+ private MetricMutableStat thriftCallStat;
+ private MetricMutableStat thriftSlowCallStat;
+
+ private MetricMutableGaugeLong callQueueLenGauge;
+
+ public ThriftServerMetricsSourceImpl(String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext) {
+ super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+ }
+
+
+ @Override
+ public void init() {
+ super.init();
+ batchGetStat = getMetricsRegistry().newStat(BATCH_GET_KEY, "", "Keys", "Ops");
+ batchMutateStat = getMetricsRegistry().newStat(BATCH_MUTATE_KEY, "", "Keys", "Ops");
+ queueTimeStat = getMetricsRegistry().newStat(TIME_IN_QUEUE_KEY);
+ thriftCallStat = getMetricsRegistry().newStat(THRIFT_CALL_KEY);
+ thriftSlowCallStat = getMetricsRegistry().newStat(SLOW_THRIFT_CALL_KEY);
+ callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0);
+ }
+
+ @Override
+ public void incTimeInQueue(long time) {
+ queueTimeStat.add(time);
+ }
+
+ @Override
+ public void setCallQueueLen(int len) {
+ callQueueLenGauge.set(len);
+ }
+
+ @Override
+ public void incNumRowKeysInBatchGet(int diff) {
+ batchGetStat.add(diff);
+ }
+
+ @Override
+ public void incNumRowKeysInBatchMutate(int diff) {
+ batchMutateStat.add(diff);
+ }
+
+ @Override
+ public void incMethodTime(String name, long time) {
+ MetricMutableStat s = getMetricsRegistry().newStat(name);
+ s.add(time);
+ }
+
+ @Override
+ public void incCall(long time) {
+ thriftCallStat.add(time);
+ }
+
+ @Override
+ public void incSlowCall(long time) {
+ thriftSlowCallStat.add(time);
+ }
+
+}
Modified: hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java (original)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java Tue Sep 18 19:10:03 2012
@@ -352,4 +352,8 @@ public class DynamicMetricsRegistry {
return (T) metric;
}
+
+ public void clearMetrics() {
+ metricsMap.clear();
+ }
}
Added: hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.metrics.RESTMetricsSource
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.metrics.RESTMetricsSource?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.metrics.RESTMetricsSource (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.metrics.RESTMetricsSource Tue Sep 18 19:10:03 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.rest.metrics.RESTMetricsSourceImpl
\ No newline at end of file
Added: hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactory
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactory?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactory (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactory Tue Sep 18 19:10:03 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.thrift.metrics.ThriftServerMetricsSourceFactoryImpl
\ No newline at end of file
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/master/metrics/TestMasterMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,41 @@
+/**
+ * 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.master.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for MasterMetricsSourceImpl
+ */
+public class TestMasterMetricsSourceImpl {
+
+ @Test
+ public void testGetInstance() throws Exception {
+ MasterMetricsSourceFactory masterMetricsSourceFactory = CompatibilitySingletonFactory
+ .getInstance(MasterMetricsSourceFactory.class);
+ MasterMetricsSource masterMetricsSource = masterMetricsSourceFactory.create(null);
+ assertTrue(masterMetricsSource instanceof MasterMetricsSourceImpl);
+ assertSame(masterMetricsSourceFactory, CompatibilitySingletonFactory.getInstance(MasterMetricsSourceFactory.class));
+ }
+
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseMetricsSourceImplTest.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseMetricsSourceImplTest.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseMetricsSourceImplTest.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseMetricsSourceImplTest.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,97 @@
+/**
+ * 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.metrics;
+
+import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
+import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+/**
+ * Test of the default BaseMetricsSource implementation for hadoop 1
+ */
+public class TestBaseMetricsSourceImplTest {
+
+ private static BaseMetricsSourceImpl bmsi;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ bmsi = new BaseMetricsSourceImpl("TestName", "test description", "testcontext", "TestContext");
+ }
+
+ @Test
+ public void testSetGauge() throws Exception {
+ String key = "testset";
+ bmsi.setGauge(key, 100);
+ MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
+ assertEquals(key, g.name);
+ bmsi.setGauge(key, 110);
+ assertSame(g, bmsi.metricsRegistry.get(key));
+
+ }
+
+ @Test
+ public void testIncGauge() throws Exception {
+ String key = "testincgauge";
+ bmsi.incGauge(key, 100);
+ MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
+ assertEquals(key, g.name);
+ bmsi.incGauge(key, 10);
+ assertSame(g, bmsi.metricsRegistry.get(key));
+ }
+
+ @Test
+ public void testDecGauge() throws Exception {
+ String key = "testdec";
+ bmsi.decGauge(key, 100);
+ MetricMutableGaugeLong g = (MetricMutableGaugeLong) bmsi.metricsRegistry.get(key);
+ assertEquals(key, g.name);
+ bmsi.decGauge(key, 100);
+ assertSame(g, bmsi.metricsRegistry.get(key));
+ }
+
+ @Test
+ public void testIncCounters() throws Exception {
+ String key = "testinccounter";
+ bmsi.incCounters(key, 100);
+ MetricMutableCounterLong c = (MetricMutableCounterLong) bmsi.metricsRegistry.get(key);
+ assertEquals(key, c.name);
+ bmsi.incCounters(key, 100);
+ assertSame(c, bmsi.metricsRegistry.get(key));
+ }
+
+ @Test
+ public void testRemoveGauge() throws Exception {
+ bmsi.setGauge("testrm", 100);
+ bmsi.removeGauge("testrm");
+ assertNull(bmsi.metricsRegistry.get("testrm"));
+
+ }
+
+ @Test
+ public void testRemoveCounter() throws Exception {
+ bmsi.incCounters("testrm", 100);
+ bmsi.removeCounter("testrm");
+ assertNull(bmsi.metricsRegistry.get("testrm"));
+ }
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/metrics/TestReplicationMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,37 @@
+/**
+ * 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.replication.regionserver.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test to make sure that ReplicationMetricsSourceImpl is hooked up to ServiceLoader
+ */
+public class TestReplicationMetricsSourceImpl {
+
+ @Test
+ public void testGetInstance() throws Exception {
+ ReplicationMetricsSource rms = CompatibilitySingletonFactory
+ .getInstance(ReplicationMetricsSource.class);
+ assertTrue(rms instanceof ReplicationMetricsSourceImpl);
+ }
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSourceImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/rest/metrics/TestRESTMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.rest.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for hadoop1's version of RESTMetricsSource
+ */
+public class TestRESTMetricsSourceImpl {
+
+ @Test
+ public void ensureCompatRegistered() throws Exception {
+ assertNotNull(CompatibilitySingletonFactory.getInstance(RESTMetricsSource.class));
+ assertTrue(CompatibilitySingletonFactory.getInstance(RESTMetricsSource.class) instanceof RESTMetricsSourceImpl);
+ }
+
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,214 @@
+/**
+ * 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.test;
+
+import org.apache.hadoop.hbase.metrics.BaseMetricsSource;
+import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl;
+import org.apache.hadoop.metrics2.Metric;
+import org.apache.hadoop.metrics2.MetricsBuilder;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.MetricsTag;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * A helper class that will allow tests to get into hadoop1's metrics2 values.
+ */
+public class MetricsAssertHelperImpl implements MetricsAssertHelper {
+
+ private Map<String, String> tags = new HashMap<String, String>();
+ private Map<String, Number> gauges = new HashMap<String, Number>();
+ private Map<String, Long> counters = new HashMap<String, Long>();
+
+ public class MockMetricsBuilder implements MetricsBuilder {
+
+ @Override
+ public MetricsRecordBuilder addRecord(String s) {
+ return new MockRecordBuilder();
+ }
+ }
+
+ public class MockRecordBuilder extends MetricsRecordBuilder {
+
+ @Override
+ public MetricsRecordBuilder tag(String s, String s1, String s2) {
+ tags.put(canonicalizeMetricName(s), s2);
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder add(MetricsTag metricsTag) {
+ tags.put(canonicalizeMetricName(metricsTag.name()), metricsTag.value());
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder setContext(String s) {
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder addCounter(String s, String s1, int i) {
+ counters.put(canonicalizeMetricName(s), Long.valueOf(i));
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder addCounter(String s, String s1, long l) {
+ counters.put(canonicalizeMetricName(s), Long.valueOf(l));
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder addGauge(String s, String s1, int i) {
+ gauges.put(canonicalizeMetricName(s), Long.valueOf(i));
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder addGauge(String s, String s1, long l) {
+ gauges.put(canonicalizeMetricName(s), Long.valueOf(l));
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder addGauge(String s, String s1, float v) {
+ gauges.put(canonicalizeMetricName(s), Double.valueOf(v));
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder addGauge(String s, String s1, double v) {
+ gauges.put(canonicalizeMetricName(s), Double.valueOf(v));
+ return this;
+ }
+
+ @Override
+ public MetricsRecordBuilder add(Metric metric) {
+ gauges.put(canonicalizeMetricName(metric.name()), metric.value());
+ return this;
+ }
+ }
+
+ @Override
+ public void assertTag(String name, String expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertEquals("Tags should be equal", expected, tags.get(cName));
+ }
+
+ @Override
+ public void assertGauge(String name, long expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertEquals("Metrics Should be equal", Long.valueOf(expected), gauges.get(cName));
+ }
+
+ @Override
+ public void assertGaugeGt(String name, long expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertNotNull(gauges.get(cName));
+ long found = gauges.get(cName).longValue();
+ assertTrue(name + " (" + found + ") should be greater than " + expected, found > expected);
+ }
+
+ @Override
+ public void assertGaugeLt(String name, long expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertNotNull(gauges.get(cName));
+ long found = gauges.get(cName).longValue();
+ assertTrue(name + "(" + found + ") should be less than " + expected, found < expected);
+ }
+
+ @Override
+ public void assertGauge(String name, double expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertEquals("Metrics Should be equal", Double.valueOf(expected), gauges.get(cName));
+ }
+
+ @Override
+ public void assertGaugeGt(String name, double expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertNotNull(gauges.get(cName));
+ double found = gauges.get(cName).doubleValue();
+ assertTrue(name + "(" + found + ") should be greater than " + expected, found > expected);
+ }
+
+ @Override
+ public void assertGaugeLt(String name, double expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertNotNull(gauges.get(cName));
+ double found = gauges.get(cName).doubleValue();
+ assertTrue(name + "(" + found + ") should be less than " + expected, found < expected);
+ }
+
+ @Override
+ public void assertCounter(String name, long expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertEquals("Metrics Counters should be equal", Long.valueOf(expected), counters.get(cName));
+ }
+
+ @Override
+ public void assertCounterGt(String name, long expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertNotNull(counters.get(cName));
+ long found = counters.get(cName).longValue();
+ assertTrue(name + " (" + found + ") should be greater than " + expected, found > expected);
+ }
+
+ @Override
+ public void assertCounterLt(String name, long expected, BaseMetricsSource source) {
+ getMetrics(source);
+ String cName = canonicalizeMetricName(name);
+ assertNotNull(counters.get(cName));
+ long found = counters.get(cName).longValue();
+ assertTrue(name + "(" + found + ") should be less than " + expected, found < expected);
+ }
+
+ private void reset() {
+ tags.clear();
+ gauges.clear();
+ counters.clear();
+ }
+
+ private void getMetrics(BaseMetricsSource source) {
+ reset();
+ if (!(source instanceof BaseMetricsSourceImpl)) {
+ assertTrue(false);
+ }
+ BaseMetricsSourceImpl impl = (BaseMetricsSourceImpl) source;
+
+ impl.getMetrics(new MockMetricsBuilder(), true);
+
+ }
+
+ private String canonicalizeMetricName(String in) {
+ return in.toLowerCase().replaceAll("[^A-Za-z0-9 ]", "");
+ }
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactoryImpl.java?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactoryImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/metrics/TestThriftServerMetricsSourceFactoryImpl.java Tue Sep 18 19:10:03 2012
@@ -0,0 +1,53 @@
+/**
+ * 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.thrift.metrics;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test the hadoop 1 version of ThriftServerMetricsSourceFactory
+ */
+public class TestThriftServerMetricsSourceFactoryImpl {
+
+ @Test
+ public void testCompatabilityRegistered() throws Exception {
+ assertNotNull(CompatibilitySingletonFactory.getInstance(ThriftServerMetricsSourceFactory.class));
+ assertTrue(CompatibilitySingletonFactory.getInstance(ThriftServerMetricsSourceFactory.class) instanceof ThriftServerMetricsSourceFactoryImpl);
+ }
+
+ @Test
+ public void testCreateThriftOneSource() throws Exception {
+ //Make sure that the factory gives back a singleton.
+ assertSame(new ThriftServerMetricsSourceFactoryImpl().createThriftOneSource(),
+ new ThriftServerMetricsSourceFactoryImpl().createThriftOneSource());
+
+ }
+
+ @Test
+ public void testCreateThriftTwoSource() throws Exception {
+ //Make sure that the factory gives back a singleton.
+ assertSame(new ThriftServerMetricsSourceFactoryImpl().createThriftTwoSource(),
+ new ThriftServerMetricsSourceFactoryImpl().createThriftTwoSource());
+ }
+}
Added: hbase/trunk/hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper?rev=1387323&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.test.MetricsAssertHelper Tue Sep 18 19:10:03 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.test.MetricsAssertHelperImpl
Modified: hbase/trunk/hbase-hadoop2-compat/pom.xml
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/pom.xml?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/pom.xml (original)
+++ hbase/trunk/hbase-hadoop2-compat/pom.xml Tue Sep 18 19:10:03 2012
@@ -115,6 +115,7 @@ limitations under the License.
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-hadoop-compat</artifactId>
+ <version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
@@ -128,6 +129,11 @@ limitations under the License.
<artifactId>hadoop-annotations</artifactId>
<version>${hadoop-two.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <version>${hadoop-two.version}</version>
+ </dependency>
<!-- This was marked as test dep in earlier pom, but was scoped compile. Where
do we actually need it? -->
<dependency>
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceFactoryImpl.java Tue Sep 18 19:10:03 2012
@@ -22,9 +22,16 @@ package org.apache.hadoop.hbase.master.m
* Factory to create MasterMetricsSource when given a MasterMetricsWrapper
*/
public class MasterMetricsSourceFactoryImpl implements MasterMetricsSourceFactory {
+ private static enum FactoryStorage {
+ INSTANCE;
+ MasterMetricsSource source;
+ }
@Override
- public MasterMetricsSource create(MasterMetricsWrapper beanWrapper) {
- return new MasterMetricsSourceImpl(beanWrapper);
+ public synchronized MasterMetricsSource create(MasterMetricsWrapper beanWrapper) {
+ if (FactoryStorage.INSTANCE.source == null ) {
+ FactoryStorage.INSTANCE.source = new MasterMetricsSourceImpl(beanWrapper);
+ }
+ return FactoryStorage.INSTANCE.source;
}
}
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -50,11 +50,15 @@ public class MasterMetricsSourceImpl
MasterMetricsWrapper masterWrapper) {
super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
this.masterWrapper = masterWrapper;
+ }
- clusterRequestsCounter = metricsRegistry.newCounter("cluster_requests", "", 0l);
- ritGauge = metricsRegistry.newGauge("ritCount", "", 0l);
- ritCountOverThresholdGauge = metricsRegistry.newGauge("ritCountOverThreshold", "" , 0l);
- ritOldestAgeGauge = metricsRegistry.newGauge("ritOldestAge", "", 0l);
+ @Override
+ public void init() {
+ super.init();
+ clusterRequestsCounter = getMetricsRegistry().getLongCounter("cluster_requests", 0);
+ ritGauge = getMetricsRegistry().getLongGauge("ritCount", 0);
+ ritCountOverThresholdGauge = getMetricsRegistry().getLongGauge("ritCountOverThreshold", 0);
+ ritOldestAgeGauge = getMetricsRegistry().getLongGauge("ritOldestAge", 0);
}
public void incRequests(final int inc) {
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -58,12 +58,18 @@ public class BaseMetricsSourceImpl imple
if (!defaultMetricsSystemInited) {
//Not too worried about mutlithread here as all it does is spam the logs.
defaultMetricsSystemInited = true;
+
DefaultMetricsSystem.initialize(HBASE_METRICS_SYSTEM_NAME);
jvmMetricsSource = JvmMetrics.create(metricsName, "", DefaultMetricsSystem.instance());
}
DefaultMetricsSystem.instance().register(metricsJmxContext, metricsDescription, this);
+ init();
+
+ }
+ public void init() {
+ this.metricsRegistry.clearMetrics();
}
/**
@@ -129,8 +135,14 @@ public class BaseMetricsSourceImpl imple
metricsRegistry.removeMetric(key);
}
+ protected DynamicMetricsRegistry getMetricsRegistry() {
+ return metricsRegistry;
+ }
+
@Override
public void getMetrics(MetricsCollector metricsCollector, boolean all) {
metricsRegistry.snapshot(metricsCollector.addRecord(metricsRegistry.info()), all);
}
+
+
}
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImpl.java?rev=1387323&r1=1387322&r2=1387323&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImpl.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/metrics/ReplicationMetricsSourceImpl.java Tue Sep 18 19:10:03 2012
@@ -19,7 +19,6 @@
package org.apache.hadoop.hbase.replication.regionserver.metrics;
import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl;
-import org.apache.hadoop.metrics2.MetricsSource;
/**
* Hadoop2 implementation of ReplicationMetricsSource. This provides access to metrics gauges and