Repository: hbase Updated Branches: refs/heads/branch-2 11ea19a10 -> 7ff1feeb8
HBASE-19590 Remove the duplicate code in deprecated ReplicationAdmin Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3a210d51 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3a210d51 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3a210d51 Branch: refs/heads/branch-2 Commit: 3a210d514c6027e3623f420fdf464feea4cdd99b Parents: 11ea19a Author: Guanghao Zhang <zg...@apache.org> Authored: Fri Dec 22 12:02:19 2017 +0800 Committer: Guanghao Zhang <zg...@apache.org> Committed: Fri Dec 22 18:36:28 2017 +0800 ---------------------------------------------------------------------- .../client/replication/ReplicationAdmin.java | 103 +------------------ .../replication/TestReplicationAdmin.java | 2 +- 2 files changed, 3 insertions(+), 102 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/3a210d51/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java ---------------------------------------------------------------------- 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 index a5081cb..78d4fbb 100644 --- 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 @@ -23,10 +23,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import java.util.regex.Pattern; @@ -44,7 +42,6 @@ import org.apache.hadoop.hbase.replication.ReplicationException; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; /** * <p> @@ -131,8 +128,6 @@ public class ReplicationAdmin implements Closeable { @Deprecated public void addPeer(String id, ReplicationPeerConfig peerConfig) throws ReplicationException, IOException { - checkNamespacesAndTableCfsConfigConflict(peerConfig.getNamespaces(), - peerConfig.getTableCFsMap()); this.admin.addReplicationPeer(id, peerConfig); } @@ -256,36 +251,7 @@ public class ReplicationAdmin implements Closeable { @Deprecated public void appendPeerTableCFs(String id, Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException, IOException { - if (tableCfs == null) { - throw new ReplicationException("tableCfs is null"); - } - ReplicationPeerConfig peerConfig = admin.getReplicationPeerConfig(id); - Map<TableName, List<String>> preTableCfs = peerConfig.getTableCFsMap(); - if (preTableCfs == null) { - setPeerTableCFs(id, tableCfs); - return; - } - for (Map.Entry<TableName, ? extends Collection<String>> entry : tableCfs.entrySet()) { - TableName table = entry.getKey(); - Collection<String> appendCfs = entry.getValue(); - if (preTableCfs.containsKey(table)) { - List<String> cfs = preTableCfs.get(table); - if (cfs == null || appendCfs == null || appendCfs.isEmpty()) { - preTableCfs.put(table, null); - } else { - Set<String> cfSet = new HashSet<>(cfs); - cfSet.addAll(appendCfs); - preTableCfs.put(table, Lists.newArrayList(cfSet)); - } - } else { - if (appendCfs == null || appendCfs.isEmpty()) { - preTableCfs.put(table, null); - } else { - preTableCfs.put(table, Lists.newArrayList(appendCfs)); - } - } - } - updatePeerConfig(id, peerConfig); + this.admin.appendReplicationPeerTableCFs(id, tableCfs); } /** @@ -313,42 +279,7 @@ public class ReplicationAdmin implements Closeable { @Deprecated public void removePeerTableCFs(String id, Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException, IOException { - if (tableCfs == null) { - throw new ReplicationException("tableCfs is null"); - } - ReplicationPeerConfig peerConfig = admin.getReplicationPeerConfig(id); - Map<TableName, List<String>> preTableCfs = peerConfig.getTableCFsMap(); - if (preTableCfs == null) { - throw new ReplicationException("Table-Cfs for peer" + id + " is null"); - } - for (Map.Entry<TableName, ? extends Collection<String>> entry: tableCfs.entrySet()) { - - TableName table = entry.getKey(); - Collection<String> removeCfs = entry.getValue(); - if (preTableCfs.containsKey(table)) { - List<String> cfs = preTableCfs.get(table); - if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) { - preTableCfs.remove(table); - } else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) { - Set<String> cfSet = new HashSet<>(cfs); - cfSet.removeAll(removeCfs); - if (cfSet.isEmpty()) { - preTableCfs.remove(table); - } else { - preTableCfs.put(table, Lists.newArrayList(cfSet)); - } - } else if (cfs == null && (removeCfs != null && !removeCfs.isEmpty())) { - throw new ReplicationException("Cannot remove cf of table: " + table - + " which doesn't specify cfs from table-cfs config in peer: " + id); - } else if (cfs != null && (removeCfs == null || removeCfs.isEmpty())) { - throw new ReplicationException("Cannot remove table: " + table - + " which has specified cfs from table-cfs config in peer: " + id); - } - } else { - throw new ReplicationException("No table: " + table + " in table-cfs config of peer: " + id); - } - } - updatePeerConfig(id, peerConfig); + this.admin.removeReplicationPeerTableCFs(id, tableCfs); } /** @@ -455,34 +386,4 @@ public class ReplicationAdmin implements Closeable { List<ReplicationPeerDescription> listReplicationPeers() throws IOException { return admin.listReplicationPeers(); } - - /** - * Set a namespace in the peer config means that all tables in this namespace - * will be replicated to the peer cluster. - * - * 1. If you already have set a namespace in the peer config, then you can't set any table - * of this namespace to the peer config. - * 2. If you already have set a table in the peer config, then you can't set this table's - * namespace to the peer config. - * - * @param namespaces - * @param tableCfs - * @throws ReplicationException - */ - private void checkNamespacesAndTableCfsConfigConflict(Set<String> namespaces, - Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException { - if (namespaces == null || namespaces.isEmpty()) { - return; - } - if (tableCfs == null || tableCfs.isEmpty()) { - return; - } - for (Map.Entry<TableName, ? extends Collection<String>> entry : tableCfs.entrySet()) { - TableName table = entry.getKey(); - if (namespaces.contains(table.getNamespaceAsString())) { - throw new ReplicationException( - "Table-cfs config conflict with namespaces config in peer"); - } - } - } } http://git-wip-us.apache.org/repos/asf/hbase/blob/3a210d51/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java index 67c635b..8770299 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java @@ -748,4 +748,4 @@ public class TestReplicationAdmin { assertEquals(2097152, admin.getPeerConfig(ID_ONE).getBandwidth()); admin.removePeer(ID_ONE); } -} +} \ No newline at end of file