diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java deleted file mode 100644 index 722dc2aadb60..000000000000 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java +++ /dev/null @@ -1,396 +0,0 @@ -/** - * - * 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.client.replication; - -import java.io.Closeable; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.regex.Pattern; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.ReplicationPeerNotFoundException; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Admin; -import org.apache.hadoop.hbase.client.Connection; -import org.apache.hadoop.hbase.client.ConnectionFactory; -import org.apache.hadoop.hbase.replication.ReplicationException; -import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; -import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; -import org.apache.yetus.audience.InterfaceAudience; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; -import org.apache.hbase.thirdparty.com.google.common.collect.Lists; - -/** - *
- * This class provides the administrative interface to HBase cluster - * replication. - *
- *- * Adding a new peer results in creating new outbound connections from every - * region server to a subset of region servers on the slave cluster. Each - * new stream of replication will start replicating from the beginning of the - * current WAL, meaning that edits from that past will be replicated. - *
- *- * Removing a peer is a destructive and irreversible operation that stops - * all the replication streams for the given cluster and deletes the metadata - * used to keep track of the replication state. - *
- *
- * To see which commands are available in the shell, type
- * replication
.
- *
* Create two new Tables with colfamilies enabled for replication then run - * ReplicationAdmin.listReplicated(). Finally verify the table:colfamilies. Note: - * TestReplicationAdmin is a better place for this testing but it would need mocks. + * {@link Admin#listReplicatedTableCFs()}. Finally verify the table:colfamilies. */ @Test public void testVerifyListReplicatedTable() throws Exception { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java index 8c5299e90271..8b6e12167670 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java @@ -48,7 +48,6 @@ import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Table; -import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; import org.apache.hadoop.hbase.codec.KeyValueCodecWithTags; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.coprocessor.ObserverContext; @@ -81,7 +80,7 @@ public class TestReplicationWithTags { private static Configuration conf1 = HBaseConfiguration.create(); private static Configuration conf2; - private static ReplicationAdmin replicationAdmin; + private static Admin replicationAdmin; private static Connection connection1; private static Connection connection2; @@ -121,7 +120,7 @@ public static void setUpBeforeClass() throws Exception { // Have to reget conf1 in case zk cluster location different // than default conf1 = utility1.getConfiguration(); - replicationAdmin = new ReplicationAdmin(conf1); + replicationAdmin = ConnectionFactory.createConnection(conf1).getAdmin(); LOG.info("Setup first Zk"); // Base conf2 on conf1 so it gets the right zk cluster. @@ -143,7 +142,7 @@ public static void setUpBeforeClass() throws Exception { ReplicationPeerConfig rpc = new ReplicationPeerConfig(); rpc.setClusterKey(utility2.getClusterKey()); - replicationAdmin.addPeer("2", rpc, null); + replicationAdmin.addReplicationPeer("2", rpc); HTableDescriptor table = new HTableDescriptor(TABLE_NAME); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java index 6078f55e1a0c..a5349cf4474f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalReplicationThrottler.java @@ -28,12 +28,13 @@ import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTestConst; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; -import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; @@ -98,17 +99,17 @@ public static void setUpBeforeClass() throws Exception { utility2.setZkCluster(miniZK); new ZKWatcher(conf2, "cluster2", null, true); - ReplicationAdmin admin1 = new ReplicationAdmin(conf1); + Admin admin1 = ConnectionFactory.createConnection(conf1).getAdmin(); ReplicationPeerConfig rpc = new ReplicationPeerConfig(); rpc.setClusterKey(utility2.getClusterKey()); utility1.startMiniCluster(); utility2.startMiniCluster(); - admin1.addPeer("peer1", rpc, null); - admin1.addPeer("peer2", rpc, null); - admin1.addPeer("peer3", rpc, null); - numOfPeer = admin1.getPeersCount(); + admin1.addReplicationPeer("peer1", rpc); + admin1.addReplicationPeer("peer2", rpc); + admin1.addReplicationPeer("peer3", rpc); + numOfPeer = admin1.listReplicationPeers().size(); } @AfterClass diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java index 669e3d2a1242..9fa2aca703e7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestRegionReplicaReplicationEndpoint.java @@ -42,12 +42,12 @@ import org.apache.hadoop.hbase.ReplicationPeerNotFoundException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; +import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.client.Table; -import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.regionserver.Region; @@ -124,18 +124,18 @@ public static void afterClass() throws Exception { public void testRegionReplicaReplicationPeerIsCreated() throws IOException, ReplicationException { // create a table with region replicas. Check whether the replication peer is created // and replication started. - ReplicationAdmin admin = new ReplicationAdmin(HTU.getConfiguration()); + Admin admin = ConnectionFactory.createConnection(HTU.getConfiguration()).getAdmin(); String peerId = "region_replica_replication"; ReplicationPeerConfig peerConfig = null; try { - peerConfig = admin.getPeerConfig(peerId); + peerConfig = admin.getReplicationPeerConfig(peerId); } catch (ReplicationPeerNotFoundException e) { LOG.warn("Region replica replication peer id=" + peerId + " not exist", e); } if (peerConfig != null) { - admin.removePeer(peerId); + admin.removeReplicationPeer(peerId); peerConfig = null; } @@ -143,7 +143,7 @@ public void testRegionReplicaReplicationPeerIsCreated() throws IOException, Repl "testReplicationPeerIsCreated_no_region_replicas"); HTU.getAdmin().createTable(htd); try { - peerConfig = admin.getPeerConfig(peerId); + peerConfig = admin.getReplicationPeerConfig(peerId); fail("Should throw ReplicationException, because replication peer id=" + peerId + " not exist"); } catch (ReplicationPeerNotFoundException e) { @@ -155,7 +155,7 @@ public void testRegionReplicaReplicationPeerIsCreated() throws IOException, Repl HTU.getAdmin().createTable(htd); // assert peer configuration is correct - peerConfig = admin.getPeerConfig(peerId); + peerConfig = admin.getReplicationPeerConfig(peerId); assertNotNull(peerConfig); assertEquals(peerConfig.getClusterKey(), ZKConfig.getZooKeeperClusterKey( HTU.getConfiguration())); @@ -168,18 +168,18 @@ public void testRegionReplicaReplicationPeerIsCreated() throws IOException, Repl public void testRegionReplicaReplicationPeerIsCreatedForModifyTable() throws Exception { // modify a table by adding region replicas. Check whether the replication peer is created // and replication started. - ReplicationAdmin admin = new ReplicationAdmin(HTU.getConfiguration()); + Admin admin = ConnectionFactory.createConnection(HTU.getConfiguration()).getAdmin(); String peerId = "region_replica_replication"; ReplicationPeerConfig peerConfig = null; try { - peerConfig = admin.getPeerConfig(peerId); + peerConfig = admin.getReplicationPeerConfig(peerId); } catch (ReplicationPeerNotFoundException e) { LOG.warn("Region replica replication peer id=" + peerId + " not exist", e); } if (peerConfig != null) { - admin.removePeer(peerId); + admin.removeReplicationPeer(peerId); peerConfig = null; } @@ -189,7 +189,7 @@ public void testRegionReplicaReplicationPeerIsCreatedForModifyTable() throws Exc // assert that replication peer is not created yet try { - peerConfig = admin.getPeerConfig(peerId); + peerConfig = admin.getReplicationPeerConfig(peerId); fail("Should throw ReplicationException, because replication peer id=" + peerId + " not exist"); } catch (ReplicationPeerNotFoundException e) { @@ -202,7 +202,7 @@ public void testRegionReplicaReplicationPeerIsCreatedForModifyTable() throws Exc HTU.getAdmin().enableTable(htd.getTableName()); // assert peer configuration is correct - peerConfig = admin.getPeerConfig(peerId); + peerConfig = admin.getReplicationPeerConfig(peerId); assertNotNull(peerConfig); assertEquals(peerConfig.getClusterKey(), ZKConfig.getZooKeeperClusterKey( HTU.getConfiguration())); @@ -405,8 +405,8 @@ public void testRegionReplicaReplicationIgnores(boolean dropTable, boolean disab HTU.getAdmin().createTable(htd); // both tables are created, now pause replication - ReplicationAdmin admin = new ReplicationAdmin(HTU.getConfiguration()); - admin.disablePeer(ServerRegionReplicaUtil.getReplicationPeerId()); + Admin admin = ConnectionFactory.createConnection(HTU.getConfiguration()).getAdmin(); + admin.disableReplicationPeer(ServerRegionReplicaUtil.getReplicationPeerId()); // now that the replication is disabled, write to the table to be dropped, then drop the table. @@ -465,7 +465,7 @@ public void testRegionReplicaReplicationIgnores(boolean dropTable, boolean disab HTU.loadNumericRows(table, HBaseTestingUtility.fam1, 0, 1000); // now enable the replication - admin.enablePeer(ServerRegionReplicaUtil.getReplicationPeerId()); + admin.enableReplicationPeer(ServerRegionReplicaUtil.getReplicationPeerId()); verifyReplication(tableName, regionReplication, 0, 1000); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java index bff363f986e0..099fbc38b280 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicator.java @@ -70,10 +70,9 @@ public void testReplicatorBatching() throws Exception { truncateTable(UTIL2, tableName); // Replace the peer set up for us by the base class with a wrapper for this test - admin.addPeer("testReplicatorBatching", + hbaseAdmin.addReplicationPeer("testReplicatorBatching", new ReplicationPeerConfig().setClusterKey(UTIL2.getClusterKey()) - .setReplicationEndpointImpl(ReplicationEndpointForTest.class.getName()), - null); + .setReplicationEndpointImpl(ReplicationEndpointForTest.class.getName())); ReplicationEndpointForTest.setBatchCount(0); ReplicationEndpointForTest.setEntriesCount(0); @@ -109,7 +108,7 @@ public String explainFailure() throws Exception { ReplicationEndpointForTest.getBatchCount()); assertEquals("We did not replicate enough rows", NUM_ROWS, UTIL2.countRows(htable2)); } finally { - admin.removePeer("testReplicatorBatching"); + hbaseAdmin.removeReplicationPeer("testReplicatorBatching"); } } @@ -120,10 +119,9 @@ public void testReplicatorWithErrors() throws Exception { truncateTable(UTIL2, tableName); // Replace the peer set up for us by the base class with a wrapper for this test - admin.addPeer("testReplicatorWithErrors", + hbaseAdmin.addReplicationPeer("testReplicatorWithErrors", new ReplicationPeerConfig().setClusterKey(UTIL2.getClusterKey()) - .setReplicationEndpointImpl(FailureInjectingReplicationEndpointForTest.class.getName()), - null); + .setReplicationEndpointImpl(FailureInjectingReplicationEndpointForTest.class.getName())); FailureInjectingReplicationEndpointForTest.setBatchCount(0); FailureInjectingReplicationEndpointForTest.setEntriesCount(0); @@ -157,7 +155,7 @@ public String explainFailure() throws Exception { assertEquals("We did not replicate enough rows", NUM_ROWS, UTIL2.countRows(htable2)); } finally { - admin.removePeer("testReplicatorWithErrors"); + hbaseAdmin.removeReplicationPeer("testReplicatorWithErrors"); } }