Index: hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java
===================================================================
--- hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java (revision 0)
+++ hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java (revision 0)
@@ -0,0 +1,106 @@
+/**
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.MediumTests;
+import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.metrics.MetricsAsserts;
+import org.apache.hadoop.hbase.metrics.MutableCounterLong;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
+import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.util.Threads;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(MediumTests.class)
+public class TestMasterMetrics {
+ private static final Log LOG = LogFactory.getLog(TestMasterMetrics.class);
+
+ static {
+ Logger.getLogger("org.apache.hadoop.hbase").setLevel(Level.DEBUG);
+ }
+
+ private MiniHBaseCluster cluster;
+ private HMaster master;
+ private Configuration conf;
+ private HBaseTestingUtility TEST_UTIL;
+
+ private void startCluster() throws Exception{
+ LOG.info("Starting cluster");
+ conf = HBaseConfiguration.create();
+ conf.getLong("hbase.splitlog.max.resubmit", 0);
+ // Make the failure test faster
+ conf.setInt("zookeeper.recovery.retry", 0);
+ conf.setInt(HConstants.REGIONSERVER_INFO_PORT, -1);
+ conf.setFloat(HConstants.LOAD_BALANCER_SLOP_KEY, (float) 100.0); // no load balancing
+ conf.setBoolean(HConstants.DISTRIBUTED_LOG_SPLITTING_KEY, true);
+ TEST_UTIL = new HBaseTestingUtility(conf);
+ TEST_UTIL.startMiniCluster(1, 1);
+ cluster = TEST_UTIL.getHBaseCluster();
+ LOG.info("Waiting for active/ready master");
+ cluster.waitForActiveAndReadyMaster();
+ master = cluster.getMaster();
+
+ while (cluster.getLiveRegionServerThreads().size() < 1) {
+ Threads.sleep(1);
+ }
+ }
+
+ @After
+ public void after() throws Exception {
+ if (TEST_UTIL != null) {
+ TEST_UTIL.shutdownMiniCluster();
+ }
+ }
+
+ @Test(timeout=300000)
+ public void testClusterRequests() throws Exception {
+ MetricsAsserts.getInstance();
+
+ startCluster();
+
+ MutableCounterLong metric = master.getMetrics().getClusterRequests();
+ long val = MetricsAsserts.getInstance().getValue(metric);
+
+ // sending fake request to master to see how metric value has changed
+ RegionServerStatusProtos.RegionServerReportRequest.Builder request =
+ RegionServerStatusProtos.RegionServerReportRequest.newBuilder();
+ HRegionServer rs = cluster.getRegionServer(0);
+ request.setServer(ProtobufUtil.toServerName(rs.getServerName()));
+
+ HBaseProtos.ServerLoad sl = HBaseProtos.ServerLoad.newBuilder()
+ .setTotalNumberOfRequests(10)
+ .build();
+ request.setLoad(sl);
+ master.regionServerReport(null, request.build());
+
+ MetricsAsserts.getInstance().assertCounter("cluster_requests", val + 10, master.getMetrics());
+ master.stopMaster();
+ }
+}
Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
===================================================================
--- hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision 1363357)
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (working copy)
@@ -79,6 +79,8 @@
import org.apache.hadoop.hbase.MasterMonitorProtocol;
import org.apache.hadoop.hbase.MasterAdminProtocol;
import org.apache.hadoop.hbase.RegionServerStatusProtocol;
+import org.apache.hadoop.hbase.master.metrics.MasterMetrics2;
+import org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.RequestConverter;
import org.apache.hadoop.hbase.ipc.ProtocolSignature;
@@ -229,6 +231,9 @@
// Metrics for the HMaster
private final MasterMetrics metrics;
+
+ private final MasterMetrics2 myMetrics;
+
// file system manager for the master FS operations
private MasterFileSystem fileSystemManager;
@@ -354,6 +359,11 @@
this.zooKeeper = new ZooKeeperWatcher(conf, MASTER + ":" + isa.getPort(), this, true);
this.rpcServer.startThreads();
this.metrics = new MasterMetrics(getServerName().toString());
+
+ DefaultMetricsSystemFactory.getInstance().initialize("HMaster");
+ // TODO: move to where HMaster starts?
+ this.myMetrics = MasterMetrics2.create(conf, getServerName().toString());
+
// metrics interval: using the same property as region server.
this.msgInterval = conf.getInt("hbase.regionserver.msginterval", 3 * 1000);
@@ -964,6 +974,10 @@
return this.zooKeeper;
}
+ MasterMetrics2 getMetrics() {
+ return myMetrics;
+ }
+
/*
* Start up all services. If any of these threads gets an unhandled exception
* then they just die with a logged message. This should be fine because
@@ -1127,6 +1141,10 @@
// Up our metrics.
this.metrics.incrementRequests(sl.getTotalNumberOfRequests());
}
+ if (sl != null && this.myMetrics != null) {
+ // Up our metrics.
+ this.myMetrics.incClusterRequests(sl.getTotalNumberOfRequests());
+ }
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics2.java
===================================================================
--- hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics2.java (revision 0)
+++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/metrics/MasterMetrics2.java (revision 0)
@@ -0,0 +1,83 @@
+/**
+ * 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.conf.Configuration;
+import org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory;
+import org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory;
+import org.apache.hadoop.hbase.metrics.MetricsRegistry;
+import org.apache.hadoop.hbase.metrics.MetricsRegistryFactory;
+import org.apache.hadoop.hbase.metrics.MetricsSource;
+import org.apache.hadoop.hbase.metrics.MutableCounterLong;
+
+/**
+ *
+ * This class is for maintaining the various HMaster statistics
+ * and publishing them through the metrics interfaces.
+ * This also registers the JMX MBean for RPC.
+ *
+ * This class has a number of metrics variables that are publicly accessible;
+ * these variables (objects) have methods to update their values;
+ * for example:
+ *
{@link #clusterRequests#incr()}
+ *
+ */
+public class MasterMetrics2 implements MetricsSource {
+ final String name;
+ final MetricsRegistry registry = MetricsRegistryFactory.getInstance().create("hmaster");
+
+ final MutableCounterLong clusterRequests =
+ registry.newCounter("cluster_requests", "", 0);
+
+ public MasterMetrics2(final String name, final String sessionId) {
+ this.name = name;
+ JvmMetricsSourceFactory.getInstance().create("HMaster", sessionId);
+ registry.setContext(name).tag("sessionId", "", sessionId);
+ }
+
+ public static MasterMetrics2 create(Configuration conf,
+ String masterName
+ ) {
+ String name = "hmaster-" + masterName;
+ String sessionId = conf.get("session.id");
+
+ return DefaultMetricsSystemFactory.getInstance().register("HMaster", "HMaster metrics",
+ new MasterMetrics2(name, sessionId));
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void incClusterRequests() {
+ clusterRequests.inc();
+ }
+
+ public void incClusterRequests(int delta) {
+ clusterRequests.inc(delta);
+ }
+
+ public MutableCounterLong getClusterRequests() {
+ return clusterRequests;
+ }
+
+ @Override
+ public MetricsRegistry getRegistry() {
+ return registry;
+ }
+}
Index: hbase-server/pom.xml
===================================================================
--- hbase-server/pom.xml (revision 1363357)
+++ hbase-server/pom.xml (working copy)
@@ -497,6 +497,22 @@
jettison
test
+
+ org.apache.hbase
+ hbase-hadoop-compat
+ ${project.version}
+ test-jar
+ true
+ test
+
+
+ org.apache.hbase
+ ${compat.module}
+ ${project.version}
+ test-jar
+ true
+ test
+
Index: hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAssertsImpl.java
===================================================================
--- hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAssertsImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAssertsImpl.java (revision 0)
@@ -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.metrics;
+
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * TODO
+ */
+public class MetricsAssertsImpl extends MetricsAsserts {
+ @Override
+ public void assertCounter(String name, long value, MetricsSource ms) {
+ MetricsSourceWrapper msw = new MetricsSourceWrapper(ms);
+ org.apache.hadoop.test.MetricsAsserts.assertCounter(name, value, msw);
+ }
+
+ @Override
+ public long getValue(MutableCounterLong counter) {
+ // This looks ugly, but this is is the only usable way I found
+ // to get metrics value in hadoop 1.0...
+ final long[] value = new long[1];
+ MetricsRecordBuilder mrb = Mockito.mock(MetricsRecordBuilder.class, new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ value[0] = (Long) args[2]; // args are: name, description, value
+ return invocation.getMock();
+ }
+ });
+ ((MutableCounterLongImpl) counter).getCounter().snapshot(mrb);
+
+ return value[0];
+ }
+}
Index: hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsAsserts
===================================================================
--- hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsAsserts (revision 0)
+++ hbase-hadoop1-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsAsserts (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.MetricsAssertsImpl
\ No newline at end of file
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryImpl.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryImpl.java (revision 0)
@@ -0,0 +1,62 @@
+/**
+ * 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.MetricsBuilder;
+
+/**
+ * TODO
+ */
+public class MetricsRegistryImpl implements MetricsRegistry {
+ private final org.apache.hadoop.metrics2.lib.MetricsRegistry registry;
+
+ public MetricsRegistryImpl(String name) {
+ this.registry = new org.apache.hadoop.metrics2.lib.MetricsRegistry(name);
+ }
+
+ @Override
+ public MetricsRegistry setContext(String name) {
+ registry.setContext(name);
+ return this;
+ }
+
+ @Override
+ public MetricsRegistry tag(String name, String description, String value) {
+ registry.tag(name, description, value);
+ return this;
+ }
+
+ @Override
+ public MutableCounterLong newCounter(String name, String desc, long iVal) {
+ MutableCounterLongImpl counter =
+ new MutableCounterLongImpl(registry.newCounter(name, desc, iVal));
+ return counter;
+ }
+
+ @Override
+ public MutableGaugeLong newGauge(String name, String desc, long iVal) {
+ MutableGaugeLongImpl gauge =
+ new MutableGaugeLongImpl(registry.newGauge(name, desc, iVal));
+ return gauge;
+ }
+
+ public void getMetrics(MetricsBuilder builder, boolean all) {
+ registry.snapshot(builder.addRecord(registry.name()), all);
+ }
+}
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLongImpl.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLongImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLongImpl.java (revision 0)
@@ -0,0 +1,32 @@
+/**
+ * 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.MetricMutableGaugeLong;
+
+/**
+ * TODO
+ */
+public class MutableGaugeLongImpl implements MutableGaugeLong {
+ private final MetricMutableGaugeLong gauge;
+
+ public MutableGaugeLongImpl(MetricMutableGaugeLong gauge) {
+ this.gauge = gauge;
+ }
+}
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSourceWrapper.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSourceWrapper.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSourceWrapper.java (revision 0)
@@ -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.metrics;
+
+import org.apache.hadoop.metrics2.MetricsBuilder;
+
+/**
+ * TODO
+ */
+public class MetricsSourceWrapper implements org.apache.hadoop.metrics2.MetricsSource {
+ private final MetricsSource ms;
+
+ public MetricsSourceWrapper(MetricsSource ms) {
+ this.ms = ms;
+ }
+
+ @Override
+ public void getMetrics(MetricsBuilder builder, boolean all) {
+ ((MetricsRegistryImpl) ms.getRegistry()).getMetrics(builder, all);
+ }
+}
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactoryImpl.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactoryImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactoryImpl.java (revision 0)
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public class MetricsRegistryFactoryImpl extends MetricsRegistryFactory {
+ @Override
+ public MetricsRegistry create(String name) {
+ return new MetricsRegistryImpl(name);
+ }
+}
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactoryImpl.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactoryImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactoryImpl.java (revision 0)
@@ -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.metrics;
+
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * TODO
+ */
+public class DefaultMetricsSystemFactoryImpl extends DefaultMetricsSystemFactory {
+ @Override
+ public T register(String name, String desc, T source) {
+ MetricsSourceWrapper msw = new MetricsSourceWrapper(source);
+ DefaultMetricsSystem.INSTANCE.register(name, desc, msw);
+ return source;
+ }
+
+ @Override
+ public void initialize(String prefix) {
+ DefaultMetricsSystem.initialize(prefix);
+ }
+}
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLongImpl.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLongImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLongImpl.java (revision 0)
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public class MutableCounterLongImpl implements MutableCounterLong {
+ private final MetricMutableCounterLong counter;
+
+ public MutableCounterLongImpl(MetricMutableCounterLong counter) {
+ this.counter = counter;
+ }
+
+ public MetricMutableCounterLong getCounter() {
+ return counter;
+ }
+
+ @Override
+ public void inc() {
+ counter.incr();
+ }
+
+ @Override
+ public void inc(long delta) {
+ counter.incr(delta);
+ }
+}
Index: hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactoryImpl.java
===================================================================
--- hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactoryImpl.java (revision 0)
+++ hbase-hadoop1-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactoryImpl.java (revision 0)
@@ -0,0 +1,31 @@
+/**
+ * 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.source.JvmMetricsSource;
+
+/**
+ * TODO
+ */
+public class JvmMetricsSourceFactoryImpl extends JvmMetricsSourceFactory {
+ @Override
+ public void create(String processName, String sessionId) {
+ JvmMetricsSource.create(processName, sessionId);
+ }
+}
Index: hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory
===================================================================
--- hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory (revision 0)
+++ hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactoryImpl
\ No newline at end of file
Index: hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsRegistryFactory
===================================================================
--- hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsRegistryFactory (revision 0)
+++ hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsRegistryFactory (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.MetricsRegistryFactoryImpl
\ No newline at end of file
Index: hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory
===================================================================
--- hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory (revision 0)
+++ hbase-hadoop1-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactoryImpl
Index: hbase-hadoop1-compat/pom.xml
===================================================================
--- hbase-hadoop1-compat/pom.xml (revision 1363357)
+++ hbase-hadoop1-compat/pom.xml (working copy)
@@ -93,5 +93,13 @@
true
test
+
+ org.apache.hbase
+ hbase-hadoop-compat
+ ${project.version}
+ test-jar
+ true
+ test
+
Index: hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAssertsImpl.java
===================================================================
--- hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAssertsImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAssertsImpl.java (revision 0)
@@ -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.metrics;
+
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * TODO
+ */
+public class MetricsAssertsImpl extends MetricsAsserts {
+ @Override
+ public void assertCounter(String name, long value, MetricsSource ms) {
+ MetricsSourceWrapper msw = new MetricsSourceWrapper(ms);
+ org.apache.hadoop.test.MetricsAsserts.assertCounter(name, value, msw);
+ }
+
+ @Override
+ public long getValue(MutableCounterLong counter) {
+ return ((MutableCounterLongImpl) counter).getCounter().value();
+ }
+}
Index: hbase-hadoop2-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsAsserts
===================================================================
--- hbase-hadoop2-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsAsserts (revision 0)
+++ hbase-hadoop2-compat/src/test/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsAsserts (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.MetricsAssertsImpl
\ No newline at end of file
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryImpl.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryImpl.java (revision 0)
@@ -0,0 +1,62 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public class MetricsRegistryImpl implements MetricsRegistry {
+ private final org.apache.hadoop.metrics2.lib.MetricsRegistry registry;
+
+ public MetricsRegistryImpl(String name) {
+ this.registry = new org.apache.hadoop.metrics2.lib.MetricsRegistry(name);
+ }
+
+ @Override
+ public MetricsRegistry setContext(String name) {
+ registry.setContext(name);
+ return this;
+ }
+
+ @Override
+ public MetricsRegistry tag(String name, String description, String value) {
+ registry.tag(name, description, value);
+ return this;
+ }
+
+ @Override
+ public MutableCounterLong newCounter(String name, String desc, long iVal) {
+ MutableCounterLongImpl counter =
+ new MutableCounterLongImpl(registry.newCounter(name, desc, iVal));
+ return counter;
+ }
+
+ @Override
+ public MutableGaugeLong newGauge(String name, String desc, long iVal) {
+ MutableGaugeLongImpl gauge =
+ new MutableGaugeLongImpl(registry.newGauge(name, desc, iVal));
+ return gauge;
+ }
+
+ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
+ registry.snapshot(metricsCollector.addRecord(registry.info()), all);
+ }
+}
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLongImpl.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLongImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLongImpl.java (revision 0)
@@ -0,0 +1,32 @@
+/**
+ * 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.MutableGaugeLong;
+
+/**
+ * TODO
+ */
+public class MutableGaugeLongImpl implements org.apache.hadoop.hbase.metrics.MutableGaugeLong {
+ private final MutableGaugeLong gauge;
+
+ public MutableGaugeLongImpl(MutableGaugeLong gauge) {
+ this.gauge = gauge;
+ }
+}
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSourceWrapper.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSourceWrapper.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSourceWrapper.java (revision 0)
@@ -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.metrics;
+
+import org.apache.hadoop.metrics2.MetricsCollector;
+
+/**
+ * TODO
+ */
+public class MetricsSourceWrapper implements org.apache.hadoop.metrics2.MetricsSource {
+ private final MetricsSource ms;
+
+ public MetricsSourceWrapper(MetricsSource ms) {
+ this.ms = ms;
+ }
+
+ @Override
+ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
+ ((MetricsRegistryImpl) ms.getRegistry()).getMetrics(metricsCollector, all);
+ }
+}
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactoryImpl.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactoryImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactoryImpl.java (revision 0)
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public class MetricsRegistryFactoryImpl extends MetricsRegistryFactory {
+ @Override
+ public MetricsRegistry create(String name) {
+ return new MetricsRegistryImpl(name);
+ }
+}
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactoryImpl.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactoryImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactoryImpl.java (revision 0)
@@ -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.metrics;
+
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * TODO
+ */
+public class DefaultMetricsSystemFactoryImpl extends DefaultMetricsSystemFactory {
+ @Override
+ public T register(String name, String desc, T source) {
+ MetricsSourceWrapper msw = new MetricsSourceWrapper(source);
+ DefaultMetricsSystem.instance().register(name, desc, msw);
+ return source;
+ }
+
+ @Override
+ public void initialize(String prefix) {
+ DefaultMetricsSystem.initialize(prefix);
+ }
+}
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLongImpl.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLongImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLongImpl.java (revision 0)
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public class MutableCounterLongImpl implements org.apache.hadoop.hbase.metrics.MutableCounterLong {
+ private final MutableCounterLong counter;
+
+ public MutableCounterLongImpl(MutableCounterLong counter) {
+ this.counter = counter;
+ }
+
+ public MutableCounterLong getCounter() {
+ return counter;
+ }
+
+ @Override
+ public void inc() {
+ counter.incr();
+ }
+
+ @Override
+ public void inc(long delta) {
+ counter.incr(delta);
+ }
+}
Index: hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactoryImpl.java
===================================================================
--- hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactoryImpl.java (revision 0)
+++ hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactoryImpl.java (revision 0)
@@ -0,0 +1,32 @@
+/**
+ * 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.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.source.JvmMetrics;
+
+/**
+ * TODO
+ */
+public class JvmMetricsSourceFactoryImpl extends JvmMetricsSourceFactory {
+ @Override
+ public void create(String processName, String sessionId) {
+ JvmMetrics.create(processName, sessionId, DefaultMetricsSystem.instance());
+ }
+}
Index: hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory
===================================================================
--- hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory (revision 0)
+++ hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactory (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.JvmMetricsSourceFactoryImpl
\ No newline at end of file
Index: hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsRegistryFactory
===================================================================
--- hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsRegistryFactory (revision 0)
+++ hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.MetricsRegistryFactory (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.MetricsRegistryFactoryImpl
\ No newline at end of file
Index: hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory
===================================================================
--- hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory (revision 0)
+++ hbase-hadoop2-compat/src/main/resources/META-INF/services/org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactory (revision 0)
@@ -0,0 +1 @@
+org.apache.hadoop.hbase.metrics.DefaultMetricsSystemFactoryImpl
Index: hbase-hadoop2-compat/pom.xml
===================================================================
--- hbase-hadoop2-compat/pom.xml (revision 1363357)
+++ hbase-hadoop2-compat/pom.xml (working copy)
@@ -129,5 +129,13 @@
hadoop-minicluster
${hadoop-two.version}
+
+ org.apache.hbase
+ hbase-hadoop-compat
+ ${project.version}
+ test-jar
+ true
+ test
+
Index: hbase-common/hbase-common.iml
===================================================================
--- hbase-common/hbase-common.iml (revision 0)
+++ hbase-common/hbase-common.iml (revision 0)
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAsserts.java
===================================================================
--- hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAsserts.java (revision 0)
+++ hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/metrics/MetricsAsserts.java (revision 0)
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.metrics;
+
+import java.util.ServiceLoader;
+
+/**
+ * Class to load MetricsAsserts from the class path. Will only return a singleton
+ * instance.
+ */
+public abstract class MetricsAsserts {
+
+ private static MetricsAsserts factory = null;
+ public static final String EXCEPTION_STRING = "Could not create a MetricsAsserts metrics source. " +
+ "Is the hadoop compatibility jar on the classpath?";
+
+
+ public abstract void assertCounter(String name, long value, MetricsSource ms);
+
+ public abstract long getValue(MutableCounterLong counter);
+
+ /**
+ * Get the singleton instance of ReplicationMetricsSource
+ *
+ * @return the singleton
+ */
+ public static synchronized MetricsAsserts getInstance() {
+ if (factory == null) {
+ try {
+ factory = ServiceLoader.load(MetricsAsserts.class).iterator().next();
+ } catch (Exception e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ } catch (Error e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ }
+
+ // If there was nothing returned and no exception then throw an exception.
+ if (factory == null) {
+ throw new RuntimeException(EXCEPTION_STRING);
+ }
+ }
+ return factory;
+ }
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistry.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistry.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistry.java (revision 0)
@@ -0,0 +1,63 @@
+/**
+ * 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;
+
+/**
+ * Metrics registry class for creating and maintaining a
+ * collection of MetricsMutables, making writing metrics source easier.
+ *
+ * This is similar to org.apache.hadoop.metrics2.lib.MetricsRegistry, but
+ * allows removing metrics. After HADOOP-8313 is implemented, this can be
+ * substituted with org.apache.hadoop.metrics2.lib.MetricsRegistry.
+ */
+public interface MetricsRegistry {
+ /**
+ * Set the metrics context tag
+ * @param name of the context
+ * @return the registry itself as a convenience
+ */
+ MetricsRegistry setContext(String name);
+
+ /**
+ * Add a tag to the metrics
+ * @param name of the tag
+ * @param description of the tag
+ * @param value of the tag
+ * @return the registry (for keep adding tags)
+ */
+ MetricsRegistry tag(String name, String description, String value);
+
+ /**
+ * Create a mutable long integer counter
+ * @param name of the metric
+ * @param desc metric description
+ * @param iVal initial value
+ * @return a new counter object
+ */
+ MutableCounterLong newCounter(String name, String desc, long iVal);
+
+ /**
+ * Create a mutable long integer gauge
+ * @param name of the metric
+ * @param desc metric description
+ * @param iVal initial value
+ * @return a new gauge object
+ */
+ MutableGaugeLong newGauge(String name, String desc, long iVal);
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLong.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLong.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableGaugeLong.java (revision 0)
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public interface MutableGaugeLong {
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSource.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSource.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsSource.java (revision 0)
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public interface MetricsSource {
+ MetricsRegistry getRegistry();
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactory.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactory.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MetricsRegistryFactory.java (revision 0)
@@ -0,0 +1,59 @@
+/**
+ * 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 java.util.ServiceLoader;
+
+import org.apache.hadoop.hbase.replication.regionserver.metrics.ReplicationMetricsSource;
+
+/**
+ * Class to load MetricsRegistryFactory from the class path. Will only return a singleton
+ * instance.
+ */
+public abstract class MetricsRegistryFactory {
+
+ private static MetricsRegistryFactory factory = null;
+ public static final String EXCEPTION_STRING = "Could not create a MetricsRegistryFactory metrics source. " +
+ "Is the hadoop compatibility jar on the classpath?";
+
+ public abstract MetricsRegistry create(String name);
+
+ /**
+ * Get the singleton instance of ReplicationMetricsSource
+ *
+ * @return the singleton
+ */
+ public static synchronized MetricsRegistryFactory getInstance() {
+ if (factory == null) {
+ try {
+ factory = ServiceLoader.load(MetricsRegistryFactory.class).iterator().next();
+ } catch (Exception e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ } catch (Error e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ }
+
+ // If there was nothing returned and no exception then throw an exception.
+ if (factory == null) {
+ throw new RuntimeException(EXCEPTION_STRING);
+ }
+ }
+ return factory;
+ }
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactory.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactory.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/DefaultMetricsSystemFactory.java (revision 0)
@@ -0,0 +1,74 @@
+/**
+ * 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 java.util.ServiceLoader;
+
+/**
+ * Class to load DefaultMetricsSystemFactory from the class path. Will only return a singleton
+ * instance.
+ */
+public abstract class DefaultMetricsSystemFactory {
+
+ private static DefaultMetricsSystemFactory factory = null;
+ public static final String EXCEPTION_STRING = "Could not create a JvmMetricsSourceFactory metrics source. " +
+ "Is the hadoop compatibility jar on the classpath?";
+
+ /**
+ * Register a metrics source
+ * @param the actual type of the source object
+ * @param source object to register
+ * @param name of the source. Must be unique or null (then extracted from
+ * the annotations of the source object.)
+ * @param desc the description of the source (or null. See above.)
+ * @return the source object
+ */
+ public abstract T register(String name, String desc, T source);
+
+
+ /**
+ * Common static convenience method to initialize the metrics system
+ * @param prefix for configuration
+ * @return the metrics system instance
+ */
+ public abstract void initialize(String prefix);
+
+ /**
+ * Get the singleton instance of ReplicationMetricsSource
+ *
+ * @return the singleton
+ */
+ public static synchronized DefaultMetricsSystemFactory getInstance() {
+ if (factory == null) {
+ try {
+ factory = ServiceLoader.load(DefaultMetricsSystemFactory.class).iterator().next();
+ } catch (Exception e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ } catch (Error e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ }
+
+ // If there was nothing returned and no exception then throw an exception.
+ if (factory == null) {
+ throw new RuntimeException(EXCEPTION_STRING);
+ }
+ }
+ return factory;
+ }
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLong.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLong.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/MutableCounterLong.java (revision 0)
@@ -0,0 +1,27 @@
+/**
+ * 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;
+
+/**
+ * TODO
+ */
+public interface MutableCounterLong {
+ void inc();
+ void inc(long delta);
+}
Index: hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactory.java
===================================================================
--- hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactory.java (revision 0)
+++ hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/JvmMetricsSourceFactory.java (revision 0)
@@ -0,0 +1,57 @@
+/**
+ * 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 java.util.ServiceLoader;
+
+/**
+ * Class to load JvmMetricsSourceFactory from the class path. Will only return a singleton
+ * instance.
+ */
+public abstract class JvmMetricsSourceFactory {
+
+ private static JvmMetricsSourceFactory factory = null;
+ public static final String EXCEPTION_STRING = "Could not create a JvmMetricsSourceFactory metrics source. " +
+ "Is the hadoop compatibility jar on the classpath?";
+
+ public abstract void create(String processName, String sessionId);
+
+ /**
+ * Get the singleton instance of ReplicationMetricsSource
+ *
+ * @return the singleton
+ */
+ public static synchronized JvmMetricsSourceFactory getInstance() {
+ if (factory == null) {
+ try {
+ factory = ServiceLoader.load(JvmMetricsSourceFactory.class).iterator().next();
+ } catch (Exception e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ } catch (Error e) {
+ throw new RuntimeException(EXCEPTION_STRING, e);
+ }
+
+ // If there was nothing returned and no exception then throw an exception.
+ if (factory == null) {
+ throw new RuntimeException(EXCEPTION_STRING);
+ }
+ }
+ return factory;
+ }
+}