hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r1513704 [1/3] - in /hbase/branches/0.95: hbase-client/src/main/java/org/apache/hadoop/hbase/client/ hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/ hbase...
Date Wed, 14 Aug 2013 00:56:02 GMT
Author: apurtell
Date: Wed Aug 14 00:56:01 2013
New Revision: 1513704

URL: http://svn.apache.org/r1513704
Log:
HBASE-9182. Allow non-admin users to list all table names

Modified:
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionWrapper.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
    hbase/branches/0.95/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/MasterAdminProtos.java
    hbase/branches/0.95/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/MasterMonitorProtos.java
    hbase/branches/0.95/hbase-protocol/src/main/protobuf/MasterAdmin.proto
    hbase/branches/0.95/hbase-protocol/src/main/protobuf/MasterMonitor.proto
    hbase/branches/0.95/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
    hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterServices.java
    hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java
    hbase/branches/0.95/hbase-server/src/main/ruby/hbase/admin.rb
    hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNamespace.java
    hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitor.java

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1513704&r1=1513703&r2=1513704&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
Wed Aug 14 00:56:01 2013
@@ -321,6 +321,52 @@ public class HBaseAdmin implements Abort
     return listTables(Pattern.compile(regex));
   }
 
+  /**
+   * List all of the names of userspace tables.
+   * @return String[] table names
+   * @throws IOException if a remote or network exception occurs
+   */
+  @Deprecated
+  public String[] getTableNames() throws IOException {
+    return this.connection.getTableNames();
+  }
+
+  /**
+   * List all of the names of userspace tables matching the given regular expression.
+   * @param pattern The regular expression to match against
+   * @return String[] table names
+   * @throws IOException if a remote or network exception occurs
+   */
+  @Deprecated
+  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 regular expression.
+   * @param regex The regular expression to match against
+   * @return String[] table names
+   * @throws IOException if a remote or network exception occurs
+   */
+  @Deprecated
+  public String[] getTableNames(String regex) throws IOException {
+    return getTableNames(Pattern.compile(regex));
+  }
+
+  /**
+   * List all of the names of userspace tables.
+   * @return TableName[] table names
+   * @throws IOException if a remote or network exception occurs
+   */
+  public TableName[] listTableNames() throws IOException {
+    return this.connection.listTableNames();
+  }
 
   /**
    * Method for getting the tableDescriptor
@@ -2155,14 +2201,14 @@ public class HBaseAdmin implements Abort
    * @return A descriptor
    * @throws IOException
    */
-  public HTableDescriptor[] getTableDescriptorsByNamespace(final String name) throws IOException
{
+  public HTableDescriptor[] listTableDescriptorsByNamespace(final String name) throws IOException
{
     return
         executeCallable(new MasterAdminCallable<HTableDescriptor[]>(getConnection())
{
           @Override
           public HTableDescriptor[] call() throws Exception {
             List<TableSchema> list =
-                masterAdmin.getTableDescriptorsByNamespace(null,
-                    MasterAdminProtos.GetTableDescriptorsByNamespaceRequest.newBuilder()
+                masterAdmin.listTableDescriptorsByNamespace(null,
+                    MasterAdminProtos.ListTableDescriptorsByNamespaceRequest.newBuilder()
                         .setNamespaceName(name).build())
                             .getTableSchemaList();
             HTableDescriptor[] res = new HTableDescriptor[list.size()];
@@ -2176,6 +2222,31 @@ public class HBaseAdmin implements Abort
   }
 
   /**
+   * Get list of table names by namespace
+   * @param name namespace name
+   * @return The list of table names in the namespace
+   * @throws IOException
+   */
+  public TableName[] listTableNamesByNamespace(final String name) throws IOException {
+    return
+        executeCallable(new MasterAdminCallable<TableName[]>(getConnection()) {
+          @Override
+          public TableName[] call() throws Exception {
+            List<HBaseProtos.TableName> tableNames =
+                masterAdmin.listTableNamesByNamespace(null,
+                    MasterAdminProtos.ListTableNamesByNamespaceRequest.newBuilder()
+                        .setNamespaceName(name).build())
+                .getTableNameList();
+            TableName[] result = new TableName[tableNames.size()];
+            for (int i = 0; i < tableNames.size(); i++) {
+              result[i] = ProtobufUtil.toTableName(tableNames.get(i));
+            }
+            return result;
+          }
+        });
+  }
+
+  /**
    * Check to see if HBase is running. Throw an exception if not.
    * We consider that HBase is running if ZooKeeper and Master are running.
    *
@@ -2283,7 +2354,6 @@ public class HBaseAdmin implements Abort
     return getTableDescriptorsByTableName(tableNames);
   }
 
-
   /**
    * Roll the log writer. That is, start writing log messages to a new file.
    *

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java?rev=1513704&r1=1513703&r2=1513704&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
Wed Aug 14 00:56:01 2013
@@ -220,6 +220,15 @@ public interface HConnection extends Abo
    */
   HTableDescriptor[] listTables() throws IOException;
 
+  // This is a bit ugly - We call this getTableNames in 0.94 and the
+  // successor function, returning TableName, listTableNames in later versions
+  // because Java polymorphism doesn't consider return value types
+
+  @Deprecated
+  String[] getTableNames() throws IOException;
+
+  TableName[] listTableNames() throws IOException;
+
   /**
    * @param tableName table name
    * @return table metadata

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1513704&r1=1513703&r2=1513704&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Wed Aug 14 00:56:01 2013
@@ -86,9 +86,13 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos
     .ListNamespaceDescriptorsRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos
-    .GetTableDescriptorsByNamespaceResponse;
+    .ListTableDescriptorsByNamespaceResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos
-    .GetTableDescriptorsByNamespaceRequest;
+    .ListTableDescriptorsByNamespaceRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos
+    .ListTableNamesByNamespaceResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos
+    .ListTableNamesByNamespaceRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AddColumnRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AddColumnResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterAdminProtos.AssignRegionRequest;
@@ -148,6 +152,8 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetSchemaAlterStatusResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableDescriptorsResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableNamesRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.GetTableNamesResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterMonitorProtos.MasterMonitorService;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
@@ -2114,8 +2120,14 @@ public class HConnectionManager {
         }
 
         @Override
-        public GetTableDescriptorsByNamespaceResponse getTableDescriptorsByNamespace(RpcController
controller, GetTableDescriptorsByNamespaceRequest request) throws ServiceException {
-          return stub.getTableDescriptorsByNamespace(controller, request);
+        public ListTableDescriptorsByNamespaceResponse listTableDescriptorsByNamespace(RpcController
controller, ListTableDescriptorsByNamespaceRequest request) throws ServiceException {
+          return stub.listTableDescriptorsByNamespace(controller, request);
+        }
+
+        @Override
+        public ListTableNamesByNamespaceResponse listTableNamesByNamespace(RpcController
controller,
+              ListTableNamesByNamespaceRequest request) throws ServiceException {
+          return stub.listTableNamesByNamespace(controller, request);
         }
 
         @Override
@@ -2160,6 +2172,13 @@ public class HConnectionManager {
         }
 
         @Override
+        public GetTableNamesResponse getTableNames(
+            RpcController controller, GetTableNamesRequest request)
+            throws ServiceException {
+          return stub.getTableNames(controller, request);
+        }
+
+        @Override
         public GetClusterStatusResponse getClusterStatus(
             RpcController controller, GetClusterStatusRequest request)
             throws ServiceException {
@@ -2620,6 +2639,30 @@ public class HConnectionManager {
     }
 
     @Override
+    public String[] getTableNames() throws IOException {
+      TableName[] tableNames = listTableNames();
+      String result[] = new String[tableNames.length];
+      for (int i = 0; i < tableNames.length; i++) {
+        result[i] = tableNames[i].getNameAsString();
+      }
+      return result;
+    }
+
+    @Override
+    public TableName[] listTableNames() throws IOException {
+      MasterMonitorKeepAliveConnection master = getKeepAliveMasterMonitorService();
+      try {
+        return ProtobufUtil.getTableNameArray(master.getTableNames(null,
+            GetTableNamesRequest.newBuilder().build())
+          .getTableNamesList());
+      } catch (ServiceException se) {
+        throw ProtobufUtil.getRemoteException(se);
+      } finally {
+        master.close();
+      }
+    }
+
+    @Override
     public HTableDescriptor[] getHTableDescriptorsByTableName(
         List<TableName> tableNames) throws IOException {
       if (tableNames == null || tableNames.isEmpty()) return new HTableDescriptor[0];

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionWrapper.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionWrapper.java?rev=1513704&r1=1513703&r2=1513704&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionWrapper.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionWrapper.java
Wed Aug 14 00:56:01 2013
@@ -164,6 +164,16 @@ public class HConnectionWrapper implemen
   }
 
   @Override
+  public String[] getTableNames() throws IOException {
+    return hconnection.getTableNames();
+  }
+
+  @Override
+  public TableName[] listTableNames() throws IOException {
+    return hconnection.listTableNames();
+  }
+
+  @Override
   public HTableDescriptor getHTableDescriptor(TableName tableName) throws IOException {
     return hconnection.getHTableDescriptor(tableName);
   }

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java?rev=1513704&r1=1513703&r2=1513704&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
Wed Aug 14 00:56:01 2013
@@ -2251,4 +2251,16 @@ public final class ProtobufUtil {
         .setNamespace(ByteString.copyFrom(tableName.getNamespace()))
         .setQualifier(ByteString.copyFrom(tableName.getQualifier())).build();
   }
+
+  public static TableName[] getTableNameArray(List<HBaseProtos.TableName> tableNamesList)
{
+    if (tableNamesList == null) {
+      return new TableName[0];
+    }
+    TableName[] tableNames = new TableName[tableNamesList.size()];
+    for (int i = 0; i < tableNamesList.size(); i++) {
+      tableNames[i] = toTableName(tableNamesList.get(i));
+    }
+    return tableNames;
+  }
+
 }



Mime
View raw message