hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
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 GMT
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<String> matched = new ArrayList<String>();
+    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<HTableDescriptor> descriptors = tableDescriptors.getAll().values();
+    Iterator<HTableDescriptor> 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
 
     #----------------------------------------------------------------------------------------------



Mime
View raw message