Revert "HBASE-12495 Use interfaces in the shell scripts (Solomon Duskis)"

This reverts commit 929bb34181.
This commit is contained in:
stack 2014-11-18 18:14:52 -08:00
parent 5f391efda1
commit 6f0138d695
6 changed files with 24 additions and 29 deletions

View File

@ -18,8 +18,8 @@
# #
# HBase ruby classes. # HBase ruby classes.
# Has wrapper classes for org.apache.hadoop.hbase.client.Admin # Has wrapper classes for org.apache.hadoop.hbase.client.HBaseAdmin
# and for org.apache.hadoop.hbase.client.Table. Classes take # and for org.apache.hadoop.hbase.client.HTable. Classes take
# Formatters on construction and outputs any results using # Formatters on construction and outputs any results using
# Formatter methods. These classes are only really for use by # Formatter methods. These classes are only really for use by
# the hirb.rb HBase Shell script; they don't make much sense elsewhere. # the hirb.rb HBase Shell script; they don't make much sense elsewhere.

View File

@ -24,22 +24,19 @@ java_import org.apache.hadoop.hbase.util.RegionSplitter
java_import org.apache.hadoop.hbase.util.Bytes java_import org.apache.hadoop.hbase.util.Bytes
java_import org.apache.hadoop.hbase.ServerName java_import org.apache.hadoop.hbase.ServerName
java_import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos::SnapshotDescription 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.Admin # Wrapper for org.apache.hadoop.hbase.client.HBaseAdmin
module Hbase module Hbase
class Admin class Admin
include HBaseConstants include HBaseConstants
def initialize(configuration, formatter) def initialize(configuration, formatter)
@connection = ConnectionFactory.createConnection(configuration) @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration)
@admin = @connection.getAdmin(); connection = @admin.getConnection()
@conf = configuration @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 = @zk_wrapper.getRecoverableZooKeeper().getZooKeeper()
@zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk) @zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk)
@formatter = formatter @formatter = formatter
@ -186,7 +183,7 @@ module Hbase
tableExists(table_name) tableExists(table_name)
raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name) raise ArgumentError, "Table #{table_name} is enabled. Disable it first.'" if enabled?(table_name)
@admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) @admin.deleteTable(table_name)
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
@ -356,7 +353,8 @@ module Hbase
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Truncates table (deletes all records by recreating the table) # Truncates table (deletes all records by recreating the table)
def truncate(table_name, conf = @conf) def truncate(table_name, conf = @conf)
table_description = @admin.getTableDescriptor(table_name.to_java_bytes) h_table = org.apache.hadoop.hbase.client.HTable.new(conf, table_name)
table_description = h_table.getTableDescriptor()
raise ArgumentError, "Table #{table_name} is not enabled. Enable it first.'" unless enabled?(table_name) raise ArgumentError, "Table #{table_name} is not enabled. Enable it first.'" unless enabled?(table_name)
yield 'Disabling table...' if block_given? yield 'Disabling table...' if block_given?
@admin.disableTable(table_name) @admin.disableTable(table_name)
@ -371,7 +369,7 @@ module Hbase
if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then
# Handle the compatibility case, where the truncate method doesn't exists on the Master # Handle the compatibility case, where the truncate method doesn't exists on the Master
yield 'Dropping table...' if block_given? yield 'Dropping table...' if block_given?
@admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) @admin.deleteTable(table_name)
yield 'Creating table...' if block_given? yield 'Creating table...' if block_given?
@admin.createTable(table_description) @admin.createTable(table_description)
@ -384,7 +382,7 @@ module Hbase
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Truncates table while maintaing region boundaries (deletes all records by recreating the table) # Truncates table while maintaing region boundaries (deletes all records by recreating the table)
def truncate_preserve(table_name, conf = @conf) def truncate_preserve(table_name, conf = @conf)
h_table = @connection.getTable(table_name) h_table = org.apache.hadoop.hbase.client.HTable.new(conf, table_name)
splits = h_table.getRegionLocations().keys().map{|i| Bytes.toString(i.getStartKey)}.delete_if{|k| k == ""}.to_java :String 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) splits = org.apache.hadoop.hbase.util.Bytes.toByteArrays(splits)
table_description = h_table.getTableDescriptor() table_description = h_table.getTableDescriptor()
@ -401,7 +399,7 @@ module Hbase
if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then
# Handle the compatibility case, where the truncate method doesn't exists on the Master # Handle the compatibility case, where the truncate method doesn't exists on the Master
yield 'Dropping table...' if block_given? yield 'Dropping table...' if block_given?
@admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) @admin.deleteTable(table_name)
yield 'Creating table with region boundaries...' if block_given? yield 'Creating table with region boundaries...' if block_given?
@admin.createTable(table_description, splits) @admin.createTable(table_description, splits)
@ -716,7 +714,8 @@ module Hbase
# Enables/disables a region by name # Enables/disables a region by name
def online(region_name, on_off) def online(region_name, on_off)
# Open meta table # Open meta table
meta = connection.getTable(org.apache.hadoop.hbase.TableName::META_TABLE_NAME) meta = org.apache.hadoop.hbase.client.HTable.new(
org.apache.hadoop.hbase.TableName::META_TABLE_NAME)
# Read region info # Read region info
# FIXME: fail gracefully if can't find the region # FIXME: fail gracefully if can't find the region

View File

@ -36,8 +36,7 @@ module Hbase
class QuotasAdmin class QuotasAdmin
def initialize(configuration, formatter) def initialize(configuration, formatter)
@config = configuration @config = configuration
@connection = org.apache.hadoop.hbase.client.ConnectionFactor.createConnection(Configuration) @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration)
@admin = connection.getAdmin()
@formatter = formatter @formatter = formatter
end end

View File

@ -26,8 +26,7 @@ module Hbase
def initialize(configuration, formatter) def initialize(configuration, formatter)
@config = configuration @config = configuration
@connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(@config) @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration)
@admin = @connection.getAdmin()
@formatter = formatter @formatter = formatter
end end
@ -38,7 +37,7 @@ module Hbase
# TODO: need to validate user name # TODO: need to validate user name
begin begin
meta_table = @connection.getTable( meta_table = org.apache.hadoop.hbase.client.HTable.new(@config,
org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME) org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME)
service = meta_table.coprocessorService( service = meta_table.coprocessorService(
org.apache.hadoop.hbase.HConstants::EMPTY_START_ROW) org.apache.hadoop.hbase.HConstants::EMPTY_START_ROW)
@ -102,7 +101,7 @@ module Hbase
# TODO: need to validate user name # TODO: need to validate user name
begin begin
meta_table = @connection.getTable( meta_table = org.apache.hadoop.hbase.client.HTable.new(@config,
org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME) org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME)
service = meta_table.coprocessorService( service = meta_table.coprocessorService(
org.apache.hadoop.hbase.HConstants::EMPTY_START_ROW) org.apache.hadoop.hbase.HConstants::EMPTY_START_ROW)

View File

@ -19,7 +19,7 @@
include Java include Java
# Wrapper for org.apache.hadoop.hbase.client.Table # Wrapper for org.apache.hadoop.hbase.client.HTable
module Hbase module Hbase
class Table class Table
@ -113,12 +113,11 @@ EOF
def initialize(configuration, table_name, shell) def initialize(configuration, table_name, shell)
if @@thread_pool then if @@thread_pool then
@connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(configuration, @@thread_pool) @table = org.apache.hadoop.hbase.client.HTable.new(configuration, table_name.to_java_bytes, @@thread_pool)
else else
@connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(configuration) @table = org.apache.hadoop.hbase.client.HTable.new(configuration, table_name)
@@thread_pool = @connection.getBatchPool() @@thread_pool = @table.getPool()
end end
@table = @connection.getTable(table_name)
@name = table_name @name = table_name
@shell = shell @shell = shell
@converters = Hash.new() @converters = Hash.new()

View File

@ -27,8 +27,7 @@ module Hbase
def initialize(configuration, formatter) def initialize(configuration, formatter)
@config = configuration @config = configuration
@formatter = formatter @formatter = formatter
@connection = org.apache.hadoop.hbase.client.ConnectionFactory(configuration) @admin = org.apache.hadoop.hbase.client.HBaseAdmin.new(configuration)
@admin = @connection.getAdmin()
end end
def add_labels(*args) def add_labels(*args)