Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1E3CA10F97 for ; Wed, 14 Aug 2013 06:24:19 +0000 (UTC) Received: (qmail 47200 invoked by uid 500); 14 Aug 2013 06:24:19 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 47170 invoked by uid 500); 14 Aug 2013 06:24:18 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 47162 invoked by uid 99); 14 Aug 2013 06:24:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Aug 2013 06:24:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Aug 2013 06:24:15 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CCD9323888E4; Wed, 14 Aug 2013 06:23:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1513738 - in /hbase/branches/0.94/src/main: java/org/apache/hadoop/hbase/client/ java/org/apache/hadoop/hbase/ipc/ java/org/apache/hadoop/hbase/master/ ruby/hbase/ Date: Wed, 14 Aug 2013 06:23:53 -0000 To: commits@hbase.apache.org From: apurtell@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130814062353.CCD9323888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: apurtell Date: Wed Aug 14 06:23:53 2013 New Revision: 1513738 URL: http://svn.apache.org/r1513738 Log: HBASE-9182. Allow non-admin users to list all table names Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnection.java hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java hbase/branches/0.94/src/main/ruby/hbase/admin.rb Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1513738&r1=1513737&r2=1513738&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Wed Aug 14 06:23:53 2013 @@ -78,8 +78,6 @@ import org.apache.hadoop.hbase.util.Pair import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.util.StringUtils; -import com.google.protobuf.ServiceException; - /** * Provides an interface to manage HBase database table metadata + general * administrative functions. Use HBaseAdmin to create, drop, list, enable and @@ -313,6 +311,40 @@ public class HBaseAdmin implements Abort return listTables(Pattern.compile(regex)); } + /** + * List all of the names of userspace tables. + * @return the list of table names + * @throws IOException if a remote or network exception occurs + */ + public String[] getTableNames() throws IOException { + return this.connection.getTableNames(); + } + + /** + * List all of the names of userspace tables matching the given pattern + * @param pattern The compiled regular expression to match against + * @return the list of table names + * @throws IOException if a remote or network exception occurs + */ + public String[] getTableNames(Pattern pattern) throws IOException { + List matched = new ArrayList(); + for (String name : this.connection.getTableNames()) { + if (pattern.matcher(name).matches()) { + matched.add(name); + } + } + return matched.toArray(new String[matched.size()]); + } + + /** + * List all of the names of userspace tables matching the given regex + * @param regex The regular expression to match against + * @return the list of table names + * @throws IOException if a remote or network exception occurs + */ + public String[] getTableNames(String regex) throws IOException { + return getTableNames(Pattern.compile(regex)); + } /** * Method for getting the tableDescriptor Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnection.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnection.java?rev=1513738&r1=1513737&r2=1513738&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnection.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnection.java Wed Aug 14 06:23:53 2013 @@ -452,6 +452,12 @@ public interface HConnection extends Abo throws IOException; /** + * @return string[] table names + * @throws IOException if a remote or network exception occurs + */ + public String[] getTableNames() throws IOException; + + /** * @return true if this connection is closed */ public boolean isClosed(); Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1513738&r1=1513737&r2=1513738&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java Wed Aug 14 06:23:53 2013 @@ -1987,6 +1987,14 @@ public class HConnectionManager { return master.getHTableDescriptors(tableNames); } + @Override + public String[] getTableNames() throws IOException { + if (this.master == null) { + this.master = getMaster(); + } + return master.getTableNames(); + } + public HTableDescriptor getHTableDescriptor(final byte[] tableName) throws IOException { if (tableName == null || tableName.length == 0) return null; Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java?rev=1513738&r1=1513737&r2=1513738&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java Wed Aug 14 06:23:53 2013 @@ -318,4 +318,11 @@ public interface HMasterInterface extend public boolean isRestoreSnapshotDone(final HSnapshotDescription request) throws IOException; + + /** + * Return all table names. + * @return the list of table names + * @throws IOException if an error occurred while getting the list of tables + */ + public String[] getTableNames() throws IOException; } Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1513738&r1=1513737&r2=1513738&view=diff ============================================================================== --- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original) +++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Wed Aug 14 06:23:53 2013 @@ -26,9 +26,11 @@ import java.lang.reflect.Method; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -2242,5 +2244,23 @@ Server { public boolean isRestoreSnapshotDone(final HSnapshotDescription request) throws IOException { return snapshotManager.isRestoreDone(request.getProto()); } -} + /** + * Return all table names. + * @return the list of table names + * @throws IOException if an error occurred while getting the list of tables + */ + @Override + public String[] getTableNames() throws IOException { + // Anyone is allowed to see the names of tables, so there is no coprocessor + // hook nor AccessController interception necessary + Collection descriptors = tableDescriptors.getAll().values(); + Iterator iter = descriptors.iterator(); + String names[] = new String[descriptors.size()]; + int i = 0; + while (iter.hasNext()) { + names[i++] = iter.next().getNameAsString(); + } + return names; + } +} Modified: hbase/branches/0.94/src/main/ruby/hbase/admin.rb URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/ruby/hbase/admin.rb?rev=1513738&r1=1513737&r2=1513738&view=diff ============================================================================== --- hbase/branches/0.94/src/main/ruby/hbase/admin.rb (original) +++ hbase/branches/0.94/src/main/ruby/hbase/admin.rb Wed Aug 14 06:23:53 2013 @@ -40,8 +40,8 @@ module Hbase #---------------------------------------------------------------------------------------------- # Returns a list of tables in hbase - def list - @admin.listTables.map { |t| t.getNameAsString } + def list(regex = ".*") + @admin.getTableNames(regex) end #----------------------------------------------------------------------------------------------