You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2012/11/07 00:22:09 UTC
svn commit: r1406396 [3/6] - 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/master/
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/met...
Modified: 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=1406396&r1=1406395&r2=1406396&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java (original)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/test/MetricsAssertHelperImpl.java Tue Nov 6 23:22:01 2012
@@ -18,8 +18,8 @@
package org.apache.hadoop.hbase.test;
-import org.apache.hadoop.hbase.metrics.BaseMetricsSource;
-import org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl;
+import org.apache.hadoop.hbase.metrics.BaseSource;
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.metrics2.Metric;
import org.apache.hadoop.metrics2.MetricsBuilder;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
@@ -110,68 +110,68 @@ public class MetricsAssertHelperImpl imp
}
@Override
- public void assertTag(String name, String expected, BaseMetricsSource source) {
+ public void assertTag(String name, String expected, BaseSource 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) {
+ public void assertGauge(String name, long expected, BaseSource source) {
long found = getGaugeLong(name, source);
assertEquals("Metrics Should be equal", (long) Long.valueOf(expected), found);
}
@Override
- public void assertGaugeGt(String name, long expected, BaseMetricsSource source) {
+ public void assertGaugeGt(String name, long expected, BaseSource source) {
double found = getGaugeDouble(name, source);
assertTrue(name + " (" + found + ") should be greater than " + expected, found > expected);
}
@Override
- public void assertGaugeLt(String name, long expected, BaseMetricsSource source) {
+ public void assertGaugeLt(String name, long expected, BaseSource source) {
double found = getGaugeDouble(name, source);
assertTrue(name + "(" + found + ") should be less than " + expected, found < expected);
}
@Override
- public void assertGauge(String name, double expected, BaseMetricsSource source) {
+ public void assertGauge(String name, double expected, BaseSource source) {
double found = getGaugeDouble(name, source);
- assertEquals("Metrics Should be equal", (double) Double.valueOf(expected), found);
+ assertEquals("Metrics Should be equal", (double) Double.valueOf(expected), found, 0.01);
}
@Override
- public void assertGaugeGt(String name, double expected, BaseMetricsSource source) {
+ public void assertGaugeGt(String name, double expected, BaseSource source) {
double found = getGaugeDouble(name, source);
assertTrue(name + "(" + found + ") should be greater than " + expected, found > expected);
}
@Override
- public void assertGaugeLt(String name, double expected, BaseMetricsSource source) {
+ public void assertGaugeLt(String name, double expected, BaseSource source) {
double found = getGaugeDouble(name, source);
assertTrue(name + "(" + found + ") should be less than " + expected, found < expected);
}
@Override
- public void assertCounter(String name, long expected, BaseMetricsSource source) {
+ public void assertCounter(String name, long expected, BaseSource source) {
long found = getCounter(name, source);
assertEquals("Metrics Counters should be equal", (long) Long.valueOf(expected), found);
}
@Override
- public void assertCounterGt(String name, long expected, BaseMetricsSource source) {
+ public void assertCounterGt(String name, long expected, BaseSource source) {
long found = getCounter(name, source);
assertTrue(name + " (" + found + ") should be greater than " + expected, found > expected);
}
@Override
- public void assertCounterLt(String name, long expected, BaseMetricsSource source) {
+ public void assertCounterLt(String name, long expected, BaseSource source) {
long found = getCounter(name, source);
assertTrue(name + "(" + found + ") should be less than " + expected, found < expected);
}
@Override
- public long getCounter(String name, BaseMetricsSource source) {
+ public long getCounter(String name, BaseSource source) {
getMetrics(source);
String cName = canonicalizeMetricName(name);
assertNotNull(counters.get(cName));
@@ -179,7 +179,7 @@ public class MetricsAssertHelperImpl imp
}
@Override
- public double getGaugeDouble(String name, BaseMetricsSource source) {
+ public double getGaugeDouble(String name, BaseSource source) {
getMetrics(source);
String cName = canonicalizeMetricName(name);
assertNotNull(gauges.get(cName));
@@ -187,7 +187,7 @@ public class MetricsAssertHelperImpl imp
}
@Override
- public long getGaugeLong(String name, BaseMetricsSource source) {
+ public long getGaugeLong(String name, BaseSource source) {
getMetrics(source);
String cName = canonicalizeMetricName(name);
assertNotNull(gauges.get(cName));
@@ -200,12 +200,12 @@ public class MetricsAssertHelperImpl imp
counters.clear();
}
- private void getMetrics(BaseMetricsSource source) {
+ private void getMetrics(BaseSource source) {
reset();
- if (!(source instanceof BaseMetricsSourceImpl)) {
+ if (!(source instanceof BaseSourceImpl)) {
assertTrue(false);
}
- BaseMetricsSourceImpl impl = (BaseMetricsSourceImpl) source;
+ BaseSourceImpl impl = (BaseSourceImpl) source;
impl.getMetrics(new MockMetricsBuilder(), true);
Added: hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerMetricsSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerMetricsSourceFactoryImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerMetricsSourceFactoryImpl.java (added)
+++ hbase/trunk/hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServerMetricsSourceFactoryImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,55 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactory;
+import org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactoryImpl;
+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 MetricsThriftServerSourceFactory
+ */
+public class TestThriftServerMetricsSourceFactoryImpl {
+
+ @Test
+ public void testCompatabilityRegistered() throws Exception {
+ assertNotNull(CompatibilitySingletonFactory.getInstance(MetricsThriftServerSourceFactory.class));
+ assertTrue(CompatibilitySingletonFactory.getInstance(MetricsThriftServerSourceFactory.class) instanceof MetricsThriftServerSourceFactoryImpl);
+ }
+
+ @Test
+ public void testCreateThriftOneSource() throws Exception {
+ //Make sure that the factory gives back a singleton.
+ assertSame(new MetricsThriftServerSourceFactoryImpl().createThriftOneSource(),
+ new MetricsThriftServerSourceFactoryImpl().createThriftOneSource());
+
+ }
+
+ @Test
+ public void testCreateThriftTwoSource() throws Exception {
+ //Make sure that the factory gives back a singleton.
+ assertSame(new MetricsThriftServerSourceFactoryImpl().createThriftTwoSource(),
+ new MetricsThriftServerSourceFactoryImpl().createThriftTwoSource());
+ }
+}
Modified: hbase/trunk/hbase-hadoop2-compat/pom.xml
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/pom.xml?rev=1406396&r1=1406395&r2=1406396&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/pom.xml (original)
+++ hbase/trunk/hbase-hadoop2-compat/pom.xml Tue Nov 6 23:22:01 2012
@@ -138,6 +138,10 @@ limitations under the License.
<groupId>com.yammer.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
<!-- This was marked as test dep in earlier pom, but was scoped compile. Where
do we actually need it? -->
<dependency>
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceFactoryImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceFactoryImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceFactoryImpl.java Tue Nov 6 23:22:01 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.master;
+
+/**
+ * Factory to create MetricsMasterSource when given a MetricsMasterWrapper
+ */
+public class MetricsMasterSourceFactoryImpl implements MetricsMasterSourceFactory {
+ private static enum FactoryStorage {
+ INSTANCE;
+ MetricsMasterSource masterSource;
+ }
+
+ @Override
+ public synchronized MetricsMasterSource create(MetricsMasterWrapper masterWrapper) {
+ if (FactoryStorage.INSTANCE.masterSource == null) {
+ FactoryStorage.INSTANCE.masterSource = new MetricsMasterSourceImpl(masterWrapper);
+ }
+ return FactoryStorage.INSTANCE.masterSource;
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,130 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.lib.Interns;
+import org.apache.hadoop.metrics2.lib.MutableCounterLong;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
+import org.apache.hadoop.metrics2.lib.MutableHistogram;
+
+/**
+ * Hadoop2 implementation of MetricsMasterSource.
+ */
+public class MetricsMasterSourceImpl
+ extends BaseSourceImpl implements MetricsMasterSource {
+
+ private final MetricsMasterWrapper masterWrapper;
+ private MutableCounterLong clusterRequestsCounter;
+ private MutableGaugeLong ritGauge;
+ private MutableGaugeLong ritCountOverThresholdGauge;
+ private MutableGaugeLong ritOldestAgeGauge;
+ private MutableHistogram splitTimeHisto;
+ private MutableHistogram splitSizeHisto;
+
+ public MetricsMasterSourceImpl(MetricsMasterWrapper masterWrapper) {
+ this(METRICS_NAME,
+ METRICS_DESCRIPTION,
+ METRICS_CONTEXT,
+ METRICS_JMX_CONTEXT,
+ masterWrapper);
+ }
+
+ public MetricsMasterSourceImpl(String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext,
+ MetricsMasterWrapper masterWrapper) {
+ super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+ this.masterWrapper = masterWrapper;
+
+ }
+
+ @Override
+ public void init() {
+ super.init();
+ clusterRequestsCounter = metricsRegistry.newCounter(CLUSTER_REQUESTS_NAME, "", 0l);
+ ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, "", 0l);
+ ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, "", 0l);
+ ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, "", 0l);
+ splitTimeHisto = metricsRegistry.newHistogram(SPLIT_SIZE_NAME, SPLIT_SIZE_DESC);
+ splitSizeHisto = metricsRegistry.newHistogram(SPLIT_TIME_NAME, SPLIT_TIME_DESC);
+ }
+
+ public void incRequests(final int inc) {
+ this.clusterRequestsCounter.incr(inc);
+ }
+
+ public void setRIT(int ritCount) {
+ ritGauge.set(ritCount);
+ }
+
+ public void setRITCountOverThreshold(int ritCount) {
+ ritCountOverThresholdGauge.set(ritCount);
+ }
+
+ public void setRITOldestAge(long ritCount) {
+ ritOldestAgeGauge.set(ritCount);
+ }
+
+ @Override
+ public void updateSplitTime(long time) {
+ splitTimeHisto.add(time);
+ }
+
+ @Override
+ public void updateSplitSize(long size) {
+ splitSizeHisto.add(size);
+ }
+
+ @Override
+ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
+
+ MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName)
+ .setContext(metricsContext);
+
+ // masterWrapper can be null because this function is called inside of init.
+ if (masterWrapper != null) {
+ metricsRecordBuilder
+ .addGauge(Interns.info(MASTER_ACTIVE_TIME_NAME,
+ MASTER_ACTIVE_TIME_DESC), masterWrapper.getActiveTime())
+ .addGauge(Interns.info(MASTER_START_TIME_NAME,
+ MASTER_START_TIME_DESC), masterWrapper.getStartTime())
+ .addGauge(Interns.info(AVERAGE_LOAD_NAME, AVERAGE_LOAD_DESC),
+ masterWrapper.getAverageLoad())
+ .addGauge(Interns.info(NUM_REGION_SERVERS_NAME,
+ NUMBER_OF_REGION_SERVERS_DESC), masterWrapper.getRegionServers())
+ .addGauge(Interns.info(NUM_DEAD_REGION_SERVERS_NAME,
+ NUMBER_OF_DEAD_REGION_SERVERS_DESC),
+ masterWrapper.getDeadRegionServers())
+ .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
+ masterWrapper.getZookeeperQuorum())
+ .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), masterWrapper.getServerName())
+ .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), masterWrapper.getClusterId())
+ .tag(Interns.info(IS_ACTIVE_MASTER_NAME,
+ IS_ACTIVE_MASTER_DESC),
+ String.valueOf(masterWrapper.getIsActiveMaster()));
+ }
+
+ metricsRegistry.snapshot(metricsRecordBuilder, all);
+ }
+
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/BaseSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,158 @@
+/**
+ * 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.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.impl.JmxCacheBuster;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
+import org.apache.hadoop.metrics2.lib.MetricMutableQuantiles;
+import org.apache.hadoop.metrics2.lib.MutableCounterLong;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
+import org.apache.hadoop.metrics2.lib.MutableHistogram;
+import org.apache.hadoop.metrics2.source.JvmMetrics;
+
+/**
+ * Hadoop 2 implementation of BaseSource (using metrics2 framework)
+ */
+public class BaseSourceImpl implements BaseSource, MetricsSource {
+
+ private static enum DefaultMetricsSystemInitializer {
+ INSTANCE;
+ private boolean inited = false;
+ private JvmMetrics jvmMetricsSource;
+
+ synchronized void init(String name) {
+ if (inited) return;
+ inited = true;
+ DefaultMetricsSystem.initialize(HBASE_METRICS_SYSTEM_NAME);
+ jvmMetricsSource = JvmMetrics.create(name, "", DefaultMetricsSystem.instance());
+
+ }
+ }
+
+ protected final DynamicMetricsRegistry metricsRegistry;
+ protected final String metricsName;
+ protected final String metricsDescription;
+ protected final String metricsContext;
+ protected final String metricsJmxContext;
+
+ public BaseSourceImpl(
+ String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext) {
+
+ this.metricsName = metricsName;
+ this.metricsDescription = metricsDescription;
+ this.metricsContext = metricsContext;
+ this.metricsJmxContext = metricsJmxContext;
+
+ metricsRegistry = new DynamicMetricsRegistry(metricsName).setContext(metricsContext);
+ DefaultMetricsSystemInitializer.INSTANCE.init(metricsName);
+
+ //Register this instance.
+ DefaultMetricsSystem.instance().register(metricsJmxContext, metricsDescription, this);
+ init();
+
+ }
+
+ public void init() {
+ this.metricsRegistry.clearMetrics();
+ }
+
+ /**
+ * Set a single gauge to a value.
+ *
+ * @param gaugeName gauge name
+ * @param value the new value of the gauge.
+ */
+ public void setGauge(String gaugeName, long value) {
+ MutableGaugeLong gaugeInt = metricsRegistry.getLongGauge(gaugeName, value);
+ gaugeInt.set(value);
+ }
+
+ /**
+ * Add some amount to a gauge.
+ *
+ * @param gaugeName The name of the gauge to increment.
+ * @param delta The amount to increment the gauge by.
+ */
+ public void incGauge(String gaugeName, long delta) {
+ MutableGaugeLong gaugeInt = metricsRegistry.getLongGauge(gaugeName, 0l);
+ gaugeInt.incr(delta);
+ }
+
+ /**
+ * Decrease the value of a named gauge.
+ *
+ * @param gaugeName The name of the gauge.
+ * @param delta the ammount to subtract from a gauge value.
+ */
+ public void decGauge(String gaugeName, long delta) {
+ MutableGaugeLong gaugeInt = metricsRegistry.getLongGauge(gaugeName, 0l);
+ gaugeInt.decr(delta);
+ }
+
+ /**
+ * Increment a named counter by some value.
+ *
+ * @param key the name of the counter
+ * @param delta the ammount to increment
+ */
+ public void incCounters(String key, long delta) {
+ MutableCounterLong counter = metricsRegistry.getLongCounter(key, 0l);
+ counter.incr(delta);
+
+ }
+
+ @Override
+ public void updateHistogram(String name, long value) {
+ MutableHistogram histo = metricsRegistry.getHistogram(name);
+ histo.add(value);
+ }
+
+ @Override
+ public void updateQuantile(String name, long value) {
+ MetricMutableQuantiles histo = metricsRegistry.getQuantile(name);
+ histo.add(value);
+ }
+
+ /**
+ * Remove a named gauge.
+ *
+ * @param key
+ */
+ public void removeMetric(String key) {
+ metricsRegistry.removeMetric(key);
+ JmxCacheBuster.clearJmxCache();
+ }
+
+ public DynamicMetricsRegistry getMetricsRegistry() {
+ return metricsRegistry;
+ }
+
+ @Override
+ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
+ metricsRegistry.snapshot(metricsCollector.addRecord(metricsRegistry.info()), all);
+ }
+
+
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionAggregateSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionAggregateSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionAggregateSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionAggregateSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,82 @@
+/**
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+
+import java.util.TreeSet;
+
+public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
+ implements MetricsRegionAggregateSource {
+
+ private final Log LOG = LogFactory.getLog(this.getClass());
+
+ private final TreeSet<MetricsRegionSourceImpl> regionSources =
+ new TreeSet<MetricsRegionSourceImpl>();
+
+ public MetricsRegionAggregateSourceImpl() {
+ this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
+ }
+
+
+ public MetricsRegionAggregateSourceImpl(String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext) {
+ super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+ }
+
+ @Override
+ public void register(MetricsRegionSource source) {
+ regionSources.add((MetricsRegionSourceImpl) source);
+ }
+
+ @Override
+ public void deregister(MetricsRegionSource source) {
+ regionSources.remove(source);
+ }
+
+ /**
+ * Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all
+ * expectations of java programmers. Instead of returning anything Hadoop metrics expects
+ * getMetrics to push the metrics into the collector.
+ *
+ * @param collector the collector
+ * @param all get all the metrics regardless of when they last changed.
+ */
+ @Override
+ public void getMetrics(MetricsCollector collector, boolean all) {
+
+
+ MetricsRecordBuilder mrb = collector.addRecord(metricsName)
+ .setContext(metricsContext);
+
+ if (regionSources != null) {
+ for (MetricsRegionSourceImpl regionMetricSource : regionSources) {
+ regionMetricSource.snapshot(mrb, all);
+ }
+ }
+
+ metricsRegistry.snapshot(mrb, all);
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java Tue Nov 6 23:22:01 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.regionserver;
+
+/**
+ * Factory to create MetricsRegionServerSource when given a MetricsRegionServerWrapper
+ */
+public class MetricsRegionServerSourceFactoryImpl implements MetricsRegionServerSourceFactory {
+ private static enum FactoryStorage {
+ INSTANCE;
+ private MetricsRegionServerSource serverSource;
+ private MetricsRegionAggregateSourceImpl aggImpl;
+ }
+
+ private synchronized MetricsRegionAggregateSourceImpl getAggregate() {
+ if (FactoryStorage.INSTANCE.aggImpl == null) {
+ FactoryStorage.INSTANCE.aggImpl = new MetricsRegionAggregateSourceImpl();
+ }
+ return FactoryStorage.INSTANCE.aggImpl;
+ }
+
+
+ @Override
+ public synchronized MetricsRegionServerSource createServer(MetricsRegionServerWrapper regionServerWrapper) {
+ if (FactoryStorage.INSTANCE.serverSource == null) {
+ FactoryStorage.INSTANCE.serverSource = new MetricsRegionServerSourceImpl(
+ regionServerWrapper);
+ }
+ return FactoryStorage.INSTANCE.serverSource;
+ }
+
+ @Override
+ public MetricsRegionSource createRegion(MetricsRegionWrapper wrapper) {
+ return new MetricsRegionSourceImpl(wrapper, getAggregate());
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,164 @@
+/**
+ * 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.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.MetricHistogram;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.lib.Interns;
+
+/**
+ * Hadoop1 implementation of MetricsRegionServerSource.
+ */
+public class MetricsRegionServerSourceImpl
+ extends BaseSourceImpl implements MetricsRegionServerSource {
+
+ final MetricsRegionServerWrapper rsWrap;
+ private final MetricHistogram putHisto;
+ private final MetricHistogram deleteHisto;
+ private final MetricHistogram getHisto;
+ private final MetricHistogram incrementHisto;
+ private final MetricHistogram appendHisto;
+
+ public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
+ this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
+ }
+
+ public MetricsRegionServerSourceImpl(String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext,
+ MetricsRegionServerWrapper rsWrap) {
+ super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+ this.rsWrap = rsWrap;
+
+ putHisto = getMetricsRegistry().getHistogram(PUT_KEY);
+ deleteHisto = getMetricsRegistry().getHistogram(DELETE_KEY);
+ getHisto = getMetricsRegistry().getHistogram(GET_KEY);
+ incrementHisto = getMetricsRegistry().getHistogram(INCREMENT_KEY);
+ appendHisto = getMetricsRegistry().getHistogram(APPEND_KEY);
+ }
+
+ @Override
+ public void init() {
+ super.init();
+ }
+
+ @Override
+ public void updatePut(long t) {
+ putHisto.add(t);
+ }
+
+ @Override
+ public void updateDelete(long t) {
+ deleteHisto.add(t);
+ }
+
+ @Override
+ public void updateGet(long t) {
+ getHisto.add(t);
+ }
+
+ @Override
+ public void updateIncrement(long t) {
+ incrementHisto.add(t);
+ }
+
+ @Override
+ public void updateAppend(long t) {
+ appendHisto.add(t);
+ }
+
+ /**
+ * Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all
+ * expectations of java programmers. Instead of returning anything Hadoop metrics expects
+ * getMetrics to push the metrics into the collector.
+ *
+ * @param metricsCollector Collector to accept metrics
+ * @param all push all or only changed?
+ */
+ @Override
+ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
+
+ MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName)
+ .setContext(metricsContext);
+
+ // rsWrap can be null because this function is called inside of init.
+ if (rsWrap != null) {
+ mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
+ .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
+ .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
+ .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemstoreSize())
+ .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
+ .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC),
+ rsWrap.getStartCode())
+ .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
+ rsWrap.getTotalRequestCount())
+ .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
+ rsWrap.getReadRequestsCount())
+ .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
+ rsWrap.getWriteRequestsCount())
+ .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
+ rsWrap.getCheckAndMutateChecksFailed())
+ .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
+ rsWrap.getCheckAndMutateChecksPassed())
+ .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
+ rsWrap.getStoreFileIndexSize())
+ .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
+ rsWrap.getTotalStaticIndexSize())
+ .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
+ rsWrap.getTotalStaticBloomSize())
+ .addGauge(Interns.info(NUMBER_OF_PUTS_WITHOUT_WAL, NUMBER_OF_PUTS_WITHOUT_WAL_DESC),
+ rsWrap.getNumPutsWithoutWAL())
+ .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
+ rsWrap.getDataInMemoryWithoutWAL())
+ .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
+ rsWrap.getPercentFileLocal())
+ .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
+ rsWrap.getCompactionQueueSize())
+ .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
+ rsWrap.getFlushQueueSize())
+ .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
+ rsWrap.getBlockCacheFreeSize())
+ .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
+ rsWrap.getBlockCacheCount())
+ .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC),
+ rsWrap.getBlockCacheSize())
+ .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
+ rsWrap.getBlockCacheHitCount())
+ .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
+ rsWrap.getBlockCacheMissCount())
+ .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
+ rsWrap.getBlockCacheEvictedCount())
+ .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
+ rsWrap.getBlockCacheHitPercent())
+ .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
+ BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
+ .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
+ rsWrap.getUpdatesBlockedTime())
+ .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
+ rsWrap.getZookeeperQuorum())
+ .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
+ .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
+ }
+
+ metricsRegistry.snapshot(mrb, all);
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,158 @@
+/**
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.impl.JmxCacheBuster;
+import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
+import org.apache.hadoop.metrics2.lib.Interns;
+import org.apache.hadoop.metrics2.lib.MutableCounterLong;
+
+public class MetricsRegionSourceImpl implements MetricsRegionSource {
+
+ private final MetricsRegionWrapper regionWrapper;
+ private boolean closed = false;
+ private MetricsRegionAggregateSourceImpl agg;
+ private DynamicMetricsRegistry registry;
+ private static final Log LOG = LogFactory.getLog(MetricsRegionSourceImpl.class);
+
+ private String regionNamePrefix;
+ private String regionPutKey;
+ private String regionDeleteKey;
+ private String regionGetKey;
+ private String regionIncrementKey;
+ private String regionAppendKey;
+ private MutableCounterLong regionPut;
+ private MutableCounterLong regionDelete;
+ private MutableCounterLong regionGet;
+ private MutableCounterLong regionIncrement;
+ private MutableCounterLong regionAppend;
+
+
+ public MetricsRegionSourceImpl(MetricsRegionWrapper regionWrapper,
+ MetricsRegionAggregateSourceImpl aggregate) {
+ this.regionWrapper = regionWrapper;
+ agg = aggregate;
+ agg.register(this);
+
+ LOG.debug("Creating new MetricsRegionSourceImpl for table " +
+ regionWrapper.getTableName() +
+ " " +
+ regionWrapper.getRegionName());
+
+ registry = agg.getMetricsRegistry();
+
+ regionNamePrefix = "table." + regionWrapper.getTableName() + "."
+ + "region." + regionWrapper.getRegionName() + ".";
+
+ String suffix = "Count";
+
+ regionPutKey = regionNamePrefix + MetricsRegionServerSource.PUT_KEY + suffix;
+ regionPut = registry.getLongCounter(regionPutKey, 0l);
+
+ regionDeleteKey = regionNamePrefix + MetricsRegionServerSource.DELETE_KEY + suffix;
+ regionDelete = registry.getLongCounter(regionDeleteKey, 0l);
+
+ regionGetKey = regionNamePrefix + MetricsRegionServerSource.GET_KEY + suffix;
+ regionGet = registry.getLongCounter(regionGetKey, 0l);
+
+ regionIncrementKey = regionNamePrefix + MetricsRegionServerSource.INCREMENT_KEY + suffix;
+ regionIncrement = registry.getLongCounter(regionIncrementKey, 0l);
+
+ regionAppendKey = regionNamePrefix + MetricsRegionServerSource.APPEND_KEY + suffix;
+ regionAppend = registry.getLongCounter(regionAppendKey, 0l);
+ }
+
+ @Override
+ public void close() {
+ closed = true;
+ agg.deregister(this);
+
+ LOG.trace("Removing region Metrics: " + regionWrapper.getRegionName());
+ registry.removeMetric(regionPutKey);
+ registry.removeMetric(regionDeleteKey);
+ registry.removeMetric(regionGetKey);
+ registry.removeMetric(regionIncrementKey);
+
+ registry.removeMetric(regionAppendKey);
+
+ JmxCacheBuster.clearJmxCache();
+ }
+
+ @Override
+ public void updatePut() {
+ regionPut.incr();
+ }
+
+ @Override
+ public void updateDelete() {
+ regionDelete.incr();
+ }
+
+ @Override
+ public void updateGet() {
+ regionGet.incr();
+ }
+
+ @Override
+ public void updateIncrement() {
+ regionIncrement.incr();
+ }
+
+ @Override
+ public void updateAppend() {
+ regionAppend.incr();
+ }
+
+ @Override
+ public MetricsRegionAggregateSource getAggregateSource() {
+ return agg;
+ }
+
+ @Override
+ public int compareTo(MetricsRegionSource source) {
+
+ if (!(source instanceof MetricsRegionSourceImpl))
+ return -1;
+
+ MetricsRegionSourceImpl impl = (MetricsRegionSourceImpl) source;
+ return this.regionWrapper.getRegionName()
+ .compareTo(impl.regionWrapper.getRegionName());
+ }
+
+ void snapshot(MetricsRecordBuilder mrb, boolean ignored) {
+ if (closed) return;
+
+ mrb.addGauge(
+ Interns.info(regionNamePrefix + MetricsRegionServerSource.STORE_COUNT,
+ MetricsRegionServerSource.STORE_COUNT_DESC),
+ this.regionWrapper.getNumStores());
+ mrb.addGauge(Interns.info(regionNamePrefix + MetricsRegionServerSource.STOREFILE_COUNT,
+ MetricsRegionServerSource.STOREFILE_COUNT_DESC),
+ this.regionWrapper.getNumStoreFiles());
+ mrb.addGauge(Interns.info(regionNamePrefix + MetricsRegionServerSource.MEMSTORE_SIZE,
+ MetricsRegionServerSource.MEMSTORE_SIZE_DESC),
+ this.regionWrapper.getMemstoreSize());
+ mrb.addGauge(Interns.info(regionNamePrefix + MetricsRegionServerSource.STOREFILE_SIZE,
+ MetricsRegionServerSource.STOREFILE_SIZE_DESC),
+ this.regionWrapper.getStoreFileSize());
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/MetricsReplicationSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/MetricsReplicationSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/MetricsReplicationSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/replication/regionserver/MetricsReplicationSourceImpl.java Tue Nov 6 23:22:01 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.replication.regionserver;
+
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+
+/**
+ * Hadoop2 implementation of MetricsReplicationSource. This provides access to metrics gauges and
+ * counters.
+ */
+public class MetricsReplicationSourceImpl extends BaseSourceImpl implements
+ MetricsReplicationSource {
+
+
+ public MetricsReplicationSourceImpl() {
+ this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
+ }
+
+ MetricsReplicationSourceImpl(String metricsName,
+ String metricsDescription,
+ String metricsContext,
+ String metricsJmxContext) {
+ super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/MetricsRESTSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/MetricsRESTSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/MetricsRESTSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/rest/MetricsRESTSourceImpl.java Tue Nov 6 23:22:01 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;
+
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.lib.MutableCounterLong;
+
+/**
+ * Hadoop Two implementation of a metrics2 source that will export metrics from the Rest server to
+ * the hadoop metrics2 subsystem.
+ */
+public class MetricsRESTSourceImpl extends BaseSourceImpl implements MetricsRESTSource {
+
+ private MutableCounterLong request;
+ private MutableCounterLong sucGet;
+ private MutableCounterLong sucPut;
+ private MutableCounterLong sucDel;
+ private MutableCounterLong fGet;
+ private MutableCounterLong fPut;
+ private MutableCounterLong fDel;
+
+ public MetricsRESTSourceImpl() {
+ this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
+ }
+
+ public MetricsRESTSourceImpl(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-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,51 @@
+/**
+ * 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;
+
+/**
+ * Class used to create metrics sources for Thrift and Thrift2 servers.
+ */
+public class MetricsThriftServerSourceFactoryImpl implements MetricsThriftServerSourceFactory {
+
+ /**
+ * A singleton used to make sure that only one thrift metrics source per server type is ever
+ * created.
+ */
+ private static enum FactoryStorage {
+ INSTANCE;
+ MetricsThriftServerSourceImpl thriftOne = new MetricsThriftServerSourceImpl(METRICS_NAME,
+ METRICS_DESCRIPTION,
+ THRIFT_ONE_METRICS_CONTEXT,
+ THRIFT_ONE_JMX_CONTEXT);
+ MetricsThriftServerSourceImpl thriftTwo = new MetricsThriftServerSourceImpl(METRICS_NAME,
+ METRICS_DESCRIPTION,
+ THRIFT_TWO_METRICS_CONTEXT,
+ THRIFT_TWO_JMX_CONTEXT);
+ }
+
+ @Override
+ public MetricsThriftServerSource createThriftOneSource() {
+ return FactoryStorage.INSTANCE.thriftOne;
+ }
+
+ @Override
+ public MetricsThriftServerSource createThriftTwoSource() {
+ return FactoryStorage.INSTANCE.thriftTwo;
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceImpl.java Tue Nov 6 23:22:01 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;
+
+import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
+import org.apache.hadoop.metrics2.lib.MutableStat;
+
+/**
+ * Hadoop 2 version of MetricsThriftServerSource{@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource}
+ */
+public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
+ MetricsThriftServerSource {
+
+ private MutableStat batchGetStat;
+ private MutableStat batchMutateStat;
+ private MutableStat queueTimeStat;
+
+ private MutableStat thriftCallStat;
+ private MutableStat thriftSlowCallStat;
+
+ private MutableGaugeLong callQueueLenGauge;
+
+ public MetricsThriftServerSourceImpl(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().newRate(TIME_IN_QUEUE_KEY);
+
+ thriftCallStat = getMetricsRegistry().newRate(THRIFT_CALL_KEY);
+ thriftSlowCallStat = getMetricsRegistry().newRate(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) {
+ MutableStat s = getMetricsRegistry().newRate(name);
+ s.add(time);
+ }
+
+ @Override
+ public void incCall(long time) {
+ thriftCallStat.add(time);
+ }
+
+ @Override
+ public void incSlowCall(long time) {
+ thriftSlowCallStat.add(time);
+ }
+
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,54 @@
+/**
+ * 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.metrics2.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * JMX caches the beans that have been exported; even after the values are removed from hadoop's
+ * metrics system the keys and old values will still remain. This class stops and restarts the
+ * Hadoop metrics system, forcing JMX to clear the cache of exported metrics.
+ *
+ * This class need to be in the o.a.h.metrics2.impl namespace as many of the variables/calls used
+ * are package private.
+ */
+public class JmxCacheBuster {
+ private static final Log LOG = LogFactory.getLog(JmxCacheBuster.class);
+
+ /**
+ * For JMX to forget about all previously exported metrics.
+ */
+ public static void clearJmxCache() {
+ LOG.trace("Clearing JMX mbean cache.");
+
+ // This is pretty extreme but it's the best way that
+ // I could find to get metrics to be removed.
+ try {
+ if (DefaultMetricsSystem.instance() != null ) {
+ DefaultMetricsSystem.instance().stop();
+ DefaultMetricsSystem.instance().start();
+ }
+
+ } catch (Exception exception ) {
+ LOG.debug("error clearing the jmx it appears the metrics system hasn't been started", exception);
+ }
+ }
+}
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java?rev=1406396&r1=1406395&r2=1406396&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/DynamicMetricsRegistry.java Tue Nov 6 23:22:01 2012
@@ -528,6 +528,7 @@ public class DynamicMetricsRegistry {
return returnExistingWithCast(metric, metricClass, name);
}
+ @SuppressWarnings("unchecked")
private<T> T returnExistingWithCast(MutableMetric metric,
Class<T> metricClass, String name) {
if (!metricClass.isAssignableFrom(metric.getClass())) {
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableQuantiles.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableQuantiles.java?rev=1406396&r1=1406395&r2=1406396&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableQuantiles.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricMutableQuantiles.java Tue Nov 6 23:22:01 2012
@@ -22,8 +22,8 @@ import com.google.common.annotations.Vis
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.hadoop.metrics.MetricHistogram;
-import org.apache.hadoop.metrics.MetricsExecutor;
+import org.apache.hadoop.metrics2.MetricHistogram;
+import org.apache.hadoop.metrics2.MetricsExecutor;
import org.apache.hadoop.metrics2.MetricsInfo;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.metrics2.util.MetricQuantile;
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricsExecutorImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricsExecutorImpl.java?rev=1406396&r1=1406395&r2=1406396&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricsExecutorImpl.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MetricsExecutorImpl.java Tue Nov 6 23:22:01 2012
@@ -18,7 +18,7 @@
package org.apache.hadoop.metrics2.lib;
-import org.apache.hadoop.metrics.MetricsExecutor;
+import org.apache.hadoop.metrics2.MetricsExecutor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
Modified: hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java?rev=1406396&r1=1406395&r2=1406396&view=diff
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java (original)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java Tue Nov 6 23:22:01 2012
@@ -22,7 +22,7 @@ import com.yammer.metrics.stats.Exponent
import com.yammer.metrics.stats.Sample;
import com.yammer.metrics.stats.Snapshot;
import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.metrics.MetricHistogram;
+import org.apache.hadoop.metrics2.MetricHistogram;
import org.apache.hadoop.metrics2.MetricsInfo;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
Added: hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsMasterSourceFactory
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsMasterSourceFactory?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsMasterSourceFactory (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.master.MetricsMasterSourceFactory Tue Nov 6 23:22:01 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.master.MetricsMasterSourceFactoryImpl
\ No newline at end of file
Added: hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactory Tue Nov 6 23:22:01 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.regionserver.MetricsRegionServerSourceFactoryImpl
Added: hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSource
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSource?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSource (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSource Tue Nov 6 23:22:01 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceImpl
\ No newline at end of file
Added: hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.MetricsRESTSource
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.MetricsRESTSource?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.MetricsRESTSource (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.rest.MetricsRESTSource Tue Nov 6 23:22:01 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.rest.MetricsRESTSourceImpl
\ No newline at end of file
Added: hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactory
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactory?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactory (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactory Tue Nov 6 23:22:01 2012
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.thrift.MetricsThriftServerSourceFactoryImpl
\ No newline at end of file
Added: hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.metrics2.MetricsExecutor
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.metrics2.MetricsExecutor?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.metrics2.MetricsExecutor (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.metrics2.MetricsExecutor Tue Nov 6 23:22:01 2012
@@ -0,0 +1 @@
+org.apache.hadoop.metrics2.lib.MetricsExecutorImpl
Added: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsMasterSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsMasterSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsMasterSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/master/TestMetricsMasterSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,44 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.apache.hadoop.hbase.master.MetricsMasterSource;
+import org.apache.hadoop.hbase.master.MetricsMasterSourceFactory;
+import org.apache.hadoop.hbase.master.MetricsMasterSourceImpl;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for MetricsMasterSourceImpl
+ */
+public class TestMetricsMasterSourceImpl {
+
+ @Test
+ public void testGetInstance() throws Exception {
+ MetricsMasterSourceFactory metricsMasterSourceFactory = CompatibilitySingletonFactory
+ .getInstance(MetricsMasterSourceFactory.class);
+ MetricsMasterSource masterSource = metricsMasterSourceFactory.create(null);
+ assertTrue(masterSource instanceof MetricsMasterSourceImpl);
+ assertSame(metricsMasterSourceFactory, CompatibilitySingletonFactory.getInstance(MetricsMasterSourceFactory.class));
+ }
+
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/TestBaseSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,84 @@
+/**
+ * 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.MutableCounterLong;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test of default BaseSource for hadoop 2
+ */
+public class TestBaseSourceImpl {
+
+ private static BaseSourceImpl bmsi;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ bmsi = new BaseSourceImpl("TestName", "test description", "testcontext", "TestContext");
+ }
+
+ @Test
+ public void testSetGauge() throws Exception {
+ bmsi.setGauge("testset", 100);
+ assertEquals(100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testset")).value());
+ bmsi.setGauge("testset", 300);
+ assertEquals(300, ((MutableGaugeLong) bmsi.metricsRegistry.get("testset")).value());
+
+ }
+
+ @Test
+ public void testIncGauge() throws Exception {
+ bmsi.incGauge("testincgauge", 100);
+ assertEquals(100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testincgauge")).value());
+ bmsi.incGauge("testincgauge", 100);
+ assertEquals(200, ((MutableGaugeLong) bmsi.metricsRegistry.get("testincgauge")).value());
+
+ }
+
+ @Test
+ public void testDecGauge() throws Exception {
+ bmsi.decGauge("testdec", 100);
+ assertEquals(-100, ((MutableGaugeLong) bmsi.metricsRegistry.get("testdec")).value());
+ bmsi.decGauge("testdec", 100);
+ assertEquals(-200, ((MutableGaugeLong) bmsi.metricsRegistry.get("testdec")).value());
+
+ }
+
+ @Test
+ public void testIncCounters() throws Exception {
+ bmsi.incCounters("testinccounter", 100);
+ assertEquals(100, ((MutableCounterLong) bmsi.metricsRegistry.get("testinccounter")).value());
+ bmsi.incCounters("testinccounter", 100);
+ assertEquals(200, ((MutableCounterLong) bmsi.metricsRegistry.get("testinccounter")).value());
+
+ }
+
+ @Test
+ public void testRemoveMetric() throws Exception {
+ bmsi.setGauge("testrmgauge", 100);
+ bmsi.removeMetric("testrmgauge");
+ assertNull(bmsi.metricsRegistry.get("testrmgauge"));
+ }
+
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServerSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServerSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServerSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServerSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,50 @@
+/**
+ * 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.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for MetricsRegionServerSourceImpl
+ */
+public class TestMetricsRegionServerSourceImpl {
+
+ @Test
+ public void testGetInstance() throws Exception {
+ MetricsRegionServerSourceFactory metricsRegionServerSourceFactory =
+ CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
+ MetricsRegionServerSource serverSource =
+ metricsRegionServerSourceFactory.createServer(null);
+ assertTrue(serverSource instanceof MetricsRegionServerSourceImpl);
+ assertSame(metricsRegionServerSourceFactory,
+ CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class));
+ }
+
+
+ @Test(expected = RuntimeException.class)
+ public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
+ // This should throw an exception because MetricsRegionServerSourceImpl should only
+ // be created by a factory.
+ CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceImpl.class);
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,101 @@
+/**
+ * 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.CompatibilitySingletonFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class TestMetricsRegionSourceImpl {
+
+ @Test
+ public void testCompareTo() throws Exception {
+ MetricsRegionServerSourceFactory fact = CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class);
+
+ MetricsRegionSource one = fact.createRegion(new RegionWrapperStub("TEST"));
+ MetricsRegionSource oneClone = fact.createRegion(new RegionWrapperStub("TEST"));
+ MetricsRegionSource two = fact.createRegion(new RegionWrapperStub("TWO"));
+
+ assertEquals(0, one.compareTo(oneClone));
+
+ assertTrue( one.compareTo(two) < 0);
+ assertTrue( two.compareTo(one) > 0);
+ }
+
+
+ @Test(expected = RuntimeException.class)
+ public void testNoGetRegionServerMetricsSourceImpl() throws Exception {
+ // This should throw an exception because MetricsRegionSourceImpl should only
+ // be created by a factory.
+ CompatibilitySingletonFactory.getInstance(MetricsRegionSource.class);
+ }
+
+ class RegionWrapperStub implements MetricsRegionWrapper {
+
+ private String regionName;
+
+ public RegionWrapperStub(String regionName) {
+
+
+ this.regionName = regionName;
+ }
+
+ @Override
+ public String getTableName() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public String getRegionName() {
+ return this.regionName;
+ }
+
+ @Override
+ public long getNumStores() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public long getNumStoreFiles() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public long getMemstoreSize() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public long getStoreFileSize() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public long getReadRequestCount() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public long getWriteRequestCount() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetricsReplicationSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetricsReplicationSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetricsReplicationSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestMetricsReplicationSourceImpl.java Tue Nov 6 23:22:01 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;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSource;
+import org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceImpl;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/** Test for MetricsReplicationSourceImpl */
+public class TestMetricsReplicationSourceImpl {
+
+ @Test
+ public void testGetInstance() throws Exception {
+ MetricsReplicationSource rms = CompatibilitySingletonFactory
+ .getInstance(MetricsReplicationSource.class);
+ assertTrue(rms instanceof MetricsReplicationSourceImpl);
+ }
+}
Added: hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/TestMetricsRESTSourceImpl.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/TestMetricsRESTSourceImpl.java?rev=1406396&view=auto
==============================================================================
--- hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/TestMetricsRESTSourceImpl.java (added)
+++ hbase/trunk/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/rest/TestMetricsRESTSourceImpl.java Tue Nov 6 23:22:01 2012
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
+import org.apache.hadoop.hbase.rest.MetricsRESTSource;
+import org.apache.hadoop.hbase.rest.MetricsRESTSourceImpl;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for hadoop 2's version of MetricsRESTSource
+ */
+public class TestMetricsRESTSourceImpl {
+
+ @Test
+ public void ensureCompatRegistered() throws Exception {
+ assertNotNull(CompatibilitySingletonFactory.getInstance(MetricsRESTSource.class));
+ assertTrue(CompatibilitySingletonFactory.getInstance(MetricsRESTSource.class) instanceof MetricsRESTSourceImpl);
+ }
+
+}