diff --git hbase-shell/src/main/ruby/hbase.rb hbase-shell/src/main/ruby/hbase.rb index c48a1c8..5928e7b 100644 --- hbase-shell/src/main/ruby/hbase.rb +++ hbase-shell/src/main/ruby/hbase.rb @@ -18,8 +18,8 @@ # # HBase ruby classes. -# Has wrapper classes for org.apache.hadoop.hbase.client.HBaseAdmin -# and for org.apache.hadoop.hbase.client.HTable. Classes take +# Has wrapper classes for org.apache.hadoop.hbase.client.Admin +# and for org.apache.hadoop.hbase.client.Table. Classes take # Formatters on construction and outputs any results using # Formatter methods. These classes are only really for use by # the hirb.rb HBase Shell script; they don't make much sense elsewhere. diff --git hbase-shell/src/main/ruby/hbase/admin.rb hbase-shell/src/main/ruby/hbase/admin.rb index 971df06..0dd3c9b 100644 --- hbase-shell/src/main/ruby/hbase/admin.rb +++ hbase-shell/src/main/ruby/hbase/admin.rb @@ -24,19 +24,22 @@ java_import org.apache.hadoop.hbase.util.RegionSplitter java_import org.apache.hadoop.hbase.util.Bytes java_import org.apache.hadoop.hbase.ServerName java_import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos::SnapshotDescription +java_import org.apache.hadoop.hbase.client.Admin +java_import org.apache.hadoop.hbase.client.Connection +java_import org.apache.hadoop.hbase.client.ConnectionFactory +java_import org.apache.hadoop.hbase.client.Table -# Wrapper for org.apache.hadoop.hbase.client.HBaseAdmin +# Wrapper for org.apache.hadoop.hbase.client.Admin module Hbase class Admin include HBaseConstants def initialize(configuration, formatter) - @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration) - connection = @admin.getConnection() + @connection = ConnectionFactory.createConnection(configuration) + @admin = @connection.getAdmin(); @conf = configuration - @zk_wrapper = org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.new(configuration, - "admin", nil) + @zk_wrapper = org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.new(configuration, "admin", nil) zk = @zk_wrapper.getRecoverableZooKeeper().getZooKeeper() @zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk) @formatter = formatter @@ -181,7 +184,7 @@ module Hbase tableExists(table_name) raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name) - @admin.deleteTable(table_name) + @admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) end #---------------------------------------------------------------------------------------------- @@ -351,8 +354,7 @@ module Hbase #---------------------------------------------------------------------------------------------- # Truncates table (deletes all records by recreating the table) def truncate(table_name, conf = @conf) - h_table = org.apache.hadoop.hbase.client.HTable.new(conf, table_name) - table_description = h_table.getTableDescriptor() + table_description = @admin.getTableDescriptor(table_name.to_java_bytes) raise ArgumentError, "Table #{table_name} is not enabled. Enable it first.'" unless enabled?(table_name) yield 'Disabling table...' if block_given? @admin.disableTable(table_name) @@ -367,7 +369,7 @@ module Hbase if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then # Handle the compatibility case, where the truncate method doesn't exists on the Master yield 'Dropping table...' if block_given? - @admin.deleteTable(table_name) + @admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) yield 'Creating table...' if block_given? @admin.createTable(table_description) @@ -380,7 +382,7 @@ module Hbase #---------------------------------------------------------------------------------------------- # Truncates table while maintaing region boundaries (deletes all records by recreating the table) def truncate_preserve(table_name, conf = @conf) - h_table = org.apache.hadoop.hbase.client.HTable.new(conf, table_name) + h_table = @connection.getTable(table_name) splits = h_table.getRegionLocations().keys().map{|i| Bytes.toString(i.getStartKey)}.delete_if{|k| k == ""}.to_java :String splits = org.apache.hadoop.hbase.util.Bytes.toByteArrays(splits) table_description = h_table.getTableDescriptor() @@ -397,7 +399,7 @@ module Hbase if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then # Handle the compatibility case, where the truncate method doesn't exists on the Master yield 'Dropping table...' if block_given? - @admin.deleteTable(table_name) + @admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) yield 'Creating table with region boundaries...' if block_given? @admin.createTable(table_description, splits) @@ -712,8 +714,7 @@ module Hbase # Enables/disables a region by name def online(region_name, on_off) # Open meta table - meta = org.apache.hadoop.hbase.client.HTable.new( - org.apache.hadoop.hbase.TableName::META_TABLE_NAME) + meta = connection.getTable(org.apache.hadoop.hbase.TableName::META_TABLE_NAME) # Read region info # FIXME: fail gracefully if can't find the region diff --git hbase-shell/src/main/ruby/hbase/quotas.rb hbase-shell/src/main/ruby/hbase/quotas.rb index 3bcba26..3427b44 100644 --- hbase-shell/src/main/ruby/hbase/quotas.rb +++ hbase-shell/src/main/ruby/hbase/quotas.rb @@ -36,7 +36,8 @@ module Hbase class QuotasAdmin def initialize(configuration, formatter) @config = configuration - @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration) + @connection = org.apache.hadoop.hbase.client.ConnectionFactor.createConnection(Configuration) + @admin = connection.getAdmin() @formatter = formatter end diff --git hbase-shell/src/main/ruby/hbase/security.rb hbase-shell/src/main/ruby/hbase/security.rb index 154c5ca..1bd025c 100644 --- hbase-shell/src/main/ruby/hbase/security.rb +++ hbase-shell/src/main/ruby/hbase/security.rb @@ -26,7 +26,8 @@ module Hbase def initialize(configuration, formatter) @config = configuration - @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration) + @connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(@config) + @admin = @connection.getAdmin() @formatter = formatter end @@ -37,7 +38,7 @@ module Hbase # TODO: need to validate user name begin - meta_table = org.apache.hadoop.hbase.client.HTable.new(@config, + meta_table = @connection.getTable( org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME) service = meta_table.coprocessorService( org.apache.hadoop.hbase.HConstants::EMPTY_START_ROW) @@ -101,7 +102,7 @@ module Hbase # TODO: need to validate user name begin - meta_table = org.apache.hadoop.hbase.client.HTable.new(@config, + meta_table = @connection.getTable( org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME) service = meta_table.coprocessorService( org.apache.hadoop.hbase.HConstants::EMPTY_START_ROW) diff --git hbase-shell/src/main/ruby/hbase/table.rb hbase-shell/src/main/ruby/hbase/table.rb index f02ba81..dbde160 100644 --- hbase-shell/src/main/ruby/hbase/table.rb +++ hbase-shell/src/main/ruby/hbase/table.rb @@ -19,7 +19,7 @@ include Java -# Wrapper for org.apache.hadoop.hbase.client.HTable +# Wrapper for org.apache.hadoop.hbase.client.Table module Hbase class Table @@ -113,11 +113,12 @@ EOF def initialize(configuration, table_name, shell) if @@thread_pool then - @table = org.apache.hadoop.hbase.client.HTable.new(configuration, table_name.to_java_bytes, @@thread_pool) + @connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(configuration, @@thread_pool) else - @table = org.apache.hadoop.hbase.client.HTable.new(configuration, table_name) - @@thread_pool = @table.getPool() + @connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(configuration) + @@thread_pool = @connection.getBatchPool() end + @table = @connection.getTable(table_name) @name = table_name @shell = shell @converters = Hash.new() diff --git hbase-shell/src/main/ruby/hbase/visibility_labels.rb hbase-shell/src/main/ruby/hbase/visibility_labels.rb index 73e1d9e..0528f26 100644 --- hbase-shell/src/main/ruby/hbase/visibility_labels.rb +++ hbase-shell/src/main/ruby/hbase/visibility_labels.rb @@ -27,7 +27,8 @@ module Hbase def initialize(configuration, formatter) @config = configuration @formatter = formatter - @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration) + @connection = org.apache.hadoop.hbase.client.ConnectionFactory(configuration) + @admin = @connection.getAdmin() end def add_labels(*args)