diff --git a/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java b/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
index b4efc3f..3085b33 100644
--- a/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
+++ b/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
@@ -22,6 +22,9 @@ package org.apache.hadoop.hbase.client.replication;
import java.io.Closeable;
import java.io.IOException;
import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.LinkedList;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
@@ -30,6 +33,8 @@ import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.replication.ReplicationZookeeper;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.zookeeper.KeeperException;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.HColumnDescriptor;
/**
*
@@ -199,4 +204,41 @@ public class ReplicationAdmin implements Closeable {
this.connection.close();
}
}
+
+ /**
+ * Find all column families that are replicated from this cluster, match them with the peers
+ * (target cluster)
+ * @param none
+ * @return the full list of the replicated column families of this cluster as: table name, column
+ * family name, target cluster name, and target cluster state
+ */
+ public List listReplicated() throws IOException {
+
+ List replicatedColFams = new ArrayList();
+
+ HTableDescriptor[] tables;
+
+ tables = this.connection.listTables();
+
+ Map peers = listPeers();
+
+ for (HTableDescriptor table : tables) {
+ HColumnDescriptor[] columns = table.getColumnFamilies();
+ String tableName = table.getNameAsString();
+ for (HColumnDescriptor column : columns) {
+ if (column.getScope()!=0) {
+ // At this moment, the columfam is replicated to all peers
+ for (Map.Entry peer : peers.entrySet()) {
+ String[] replicatedEntry = new String[4];
+ replicatedEntry[0] = tableName;
+ replicatedEntry[1] = column.getNameAsString();
+ replicatedEntry[2] = peer.getValue();
+ replicatedEntry[3] = getPeerState(peer.getKey());
+ replicatedColFams.add(replicatedEntry);
+ }
+ }
+ }
+ }
+ return replicatedColFams;
+ }
}
diff --git a/src/main/ruby/hbase/replication_admin.rb b/src/main/ruby/hbase/replication_admin.rb
index f694f5f..a5f48a8 100644
--- a/src/main/ruby/hbase/replication_admin.rb
+++ b/src/main/ruby/hbase/replication_admin.rb
@@ -78,5 +78,12 @@ module Hbase
def stop_replication
@replication_admin.setReplicating(false)
end
+
+ #----------------------------------------------------------------------------------------------
+ # Show replcated tables/column families, and their target clusers
+ def list_replicated_tables
+ @replication_admin.listReplicated()
+ end
+
end
end
diff --git a/src/main/ruby/shell.rb b/src/main/ruby/shell.rb
index 128a0a2..814f739 100644
--- a/src/main/ruby/shell.rb
+++ b/src/main/ruby/shell.rb
@@ -286,6 +286,7 @@ Shell.load_command_group(
disable_peer
start_replication
stop_replication
+ list_replicated_tables
]
)
diff --git a/src/main/ruby/shell/commands/list_replicated_tables.rb b/src/main/ruby/shell/commands/list_replicated_tables.rb
new file mode 100644
index 0000000..983a588
--- /dev/null
+++ b/src/main/ruby/shell/commands/list_replicated_tables.rb
@@ -0,0 +1,47 @@
+#
+# Copyright The Apache Software Foundation
+#
+# 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.
+#
+
+module Shell
+ module Commands
+ class ListReplicatedTables< Command
+ def help
+ return <<-EOF
+List all the tables and column families replicated from this cluster
+
+ hbase> list_replicated_tables
+ hbase> list_replicated_tables 'abc.*'
+EOF
+ end
+
+ def command(regex = ".*")
+ now = Time.now
+
+ formatter.header([ "TABLE:COLUMNFAMILY", "TARGET_CLUSTER + STATE" ], [ 32 ])
+ regex = /#{regex}/ unless regex.is_a?(Regexp)
+ list = replication_admin.list_replicated_tables
+ list = list.select {|s| regex.match(s[0])}
+ list.each do |e|
+ formatter.row([ e[0] + ":" + e[1], e[2]+ " + " + e[3] ], true, [ 32 ])
+ end
+ formatter.footer(now)
+ end
+ end
+ end
+end