Revert HBASE-15965 and HBASE-15849.

While it's fine to introduce these format changes in minor version, reverting it from branch-1 after discussion on HBASE-16044.
This commit is contained in:
Apekshit Sharma 2016-06-28 17:30:23 -07:00
parent 7a78d871d0
commit 48492ec7fd
102 changed files with 564 additions and 423 deletions

View File

@ -423,26 +423,25 @@ module Hbase
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Truncates table (deletes all records by recreating the table) # Truncates table (deletes all records by recreating the table)
def truncate(table_name_str) def truncate(table_name, conf = @conf)
puts "Truncating '#{table_name_str}' table (it may take a while):" table_description = @admin.getTableDescriptor(TableName.valueOf(table_name))
table_name = TableName.valueOf(table_name_str)
table_description = @admin.getTableDescriptor(table_name)
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)
puts 'Disabling table...' yield 'Disabling table...' if block_given?
@admin.disableTable(table_name) @admin.disableTable(table_name)
begin begin
puts 'Truncating table...' yield 'Truncating table...' if block_given?
@admin.truncateTable(table_name, false) @admin.truncateTable(org.apache.hadoop.hbase.TableName.valueOf(table_name), false)
rescue => e rescue => e
# 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
raise e unless e.respond_to?(:cause) && e.cause != nil raise e unless e.respond_to?(:cause) && e.cause != nil
rootCause = e.cause rootCause = e.cause
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
puts 'Dropping table...' yield 'Dropping table...' if block_given?
@admin.deleteTable(table_name) @admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name))
puts 'Creating table...' yield 'Creating table...' if block_given?
@admin.createTable(table_description) @admin.createTable(table_description)
else else
raise e raise e
@ -452,10 +451,9 @@ 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_str) def truncate_preserve(table_name, conf = @conf)
puts "Truncating '#{table_name_str}' table (it may take a while):" h_table = @connection.getTable(TableName.valueOf(table_name))
table_name = TableName.valueOf(table_name_str) locator = @connection.getRegionLocator(TableName.valueOf(table_name))
locator = @connection.getRegionLocator(table_name)
begin begin
splits = locator.getAllRegionLocations(). splits = locator.getAllRegionLocations().
map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}. map{|i| Bytes.toString(i.getRegionInfo().getStartKey)}.
@ -464,23 +462,23 @@ module Hbase
locator.close() locator.close()
end end
table_description = @admin.getTableDescriptor(table_name) table_description = @admin.getTableDescriptor(TableName.valueOf(table_name))
puts 'Disabling table...' yield 'Disabling table...' if block_given?
disable(table_name) disable(table_name)
begin begin
puts 'Truncating table...' yield 'Truncating table...' if block_given?
@admin.truncateTable(table_name, true) @admin.truncateTable(org.apache.hadoop.hbase.TableName.valueOf(table_name), true)
rescue => e rescue => e
# 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
raise e unless e.respond_to?(:cause) && e.cause != nil raise e unless e.respond_to?(:cause) && e.cause != nil
rootCause = e.cause rootCause = e.cause
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
puts 'Dropping table...' yield 'Dropping table...' if block_given?
@admin.deleteTable(table_name) @admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name))
puts 'Creating table with region boundaries...' yield 'Creating table with region boundaries...' if block_given?
@admin.createTable(table_description, splits) @admin.createTable(table_description, splits)
else else
raise e raise e

View File

@ -710,7 +710,6 @@ EOF
map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}.delete_if{|k| k == ""} map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}.delete_if{|k| k == ""}
locator.close() locator.close()
puts("Total number of splits = %s" % [splits.size + 1]) puts("Total number of splits = %s" % [splits.size + 1])
puts splits
return splits return splits
end end
end end

View File

@ -81,9 +81,8 @@ module Shell
self.interactive = interactive self.interactive = interactive
end end
# Returns Admin class from admin.rb def hbase_admin
def admin @hbase_admin ||= hbase.admin()
@admin ||= hbase.admin()
end end
def hbase_taskmonitor def hbase_taskmonitor
@ -131,16 +130,8 @@ module Shell
end end
#call the method 'command' on the specified command #call the method 'command' on the specified command
# If interactive is enabled, then we suppress the return value. The command should have
# printed relevant output.
# Return value is only useful in non-interactive mode, for e.g. tests.
def command(command, *args) def command(command, *args)
ret = internal_command(command, :command, *args) internal_command(command, :command, *args)
if self.interactive
return nil
else
return ret
end
end end
# call a specific internal method in the command instance # call a specific internal method in the command instance

View File

@ -17,8 +17,6 @@
# limitations under the License. # limitations under the License.
# #
require 'shell/formatter'
module Shell module Shell
module Commands module Commands
class Command class Command
@ -31,9 +29,6 @@ module Shell
# cmd - command name to execute # cmd - command name to execute
# args - arguments to pass to the command # args - arguments to pass to the command
def command_safe(debug, cmd = :command, *args) def command_safe(debug, cmd = :command, *args)
# Commands can overwrite start_time to skip time used in some kind of setup.
# See count.rb for example.
@start_time = Time.now
# send is internal ruby method to call 'cmd' with *args # send is internal ruby method to call 'cmd' with *args
#(everything is a message, so this is just the formal semantics to support that idiom) #(everything is a message, so this is just the formal semantics to support that idiom)
translate_hbase_exceptions(*args) { send(cmd,*args) } translate_hbase_exceptions(*args) { send(cmd,*args) }
@ -53,16 +48,13 @@ module Shell
else else
raise rootCause raise rootCause
end end
ensure
# If end_time is not already set by the command, use current time.
@end_time ||= Time.now
formatter.output_str("Took %.4f seconds" % [@end_time - @start_time])
end end
# Convenience functions to get different admins # Convenience functions to get different admins
# Returns HBase::Admin ruby class. # Returns HBase::Admin ruby class.
def admin def admin
@shell.admin @shell.hbase_admin
end end
def taskmonitor def taskmonitor
@ -95,6 +87,21 @@ module Shell
@formatter ||= ::Shell::Formatter::Console.new @formatter ||= ::Shell::Formatter::Console.new
end end
def format_simple_command
now = Time.now
yield
formatter.header
formatter.footer(now)
end
def format_and_return_simple_command
now = Time.now
ret = yield
formatter.header
formatter.footer(now)
return ret
end
def translate_hbase_exceptions(*args) def translate_hbase_exceptions(*args)
yield yield
rescue => e rescue => e

View File

@ -40,7 +40,11 @@ EOF
end end
def command(proc_id, may_interrupt_if_running=nil) def command(proc_id, may_interrupt_if_running=nil)
formatter.row([admin.abort_procedure?(proc_id, may_interrupt_if_running).to_s]) format_simple_command do
formatter.row([
admin.abort_procedure?(proc_id, may_interrupt_if_running).to_s
])
end
end end
end end
end end

View File

@ -31,8 +31,10 @@ EOF
end end
def command(*args) def command(*args)
format_simple_command do
visibility_labels_admin.add_labels(args) visibility_labels_admin.add_labels(args)
end end
end end
end end
end end
end

View File

@ -58,8 +58,10 @@ EOF
end end
def command(id, args = {}, peer_tableCFs = nil) def command(id, args = {}, peer_tableCFs = nil)
format_simple_command do
replication_admin.add_peer(id, args, peer_tableCFs) replication_admin.add_peer(id, args, peer_tableCFs)
end end
end end
end end
end end
end

View File

@ -92,8 +92,10 @@ EOF
end end
def command(table, *args) def command(table, *args)
format_simple_command do
admin.alter(table, true, *args) admin.alter(table, true, *args)
end end
end end
end end
end end
end

View File

@ -56,8 +56,10 @@ EOF
end end
def command(table, *args) def command(table, *args)
format_simple_command do
admin.alter(table, false, *args) admin.alter(table, false, *args)
end end
end end
end end
end end
end

View File

@ -35,8 +35,10 @@ EOF
end end
def command(namespace, *args) def command(namespace, *args)
format_simple_command do
admin.alter_namespace(namespace, *args) admin.alter_namespace(namespace, *args)
end end
end end
end end
end end
end

View File

@ -35,18 +35,18 @@ t to table 't1', the corresponding command would be:
EOF EOF
end end
def command(table_name, row, column, value, args={}) def command(table, row, column, value, args={})
table = table(table_name) append(table(table), row, column, value, args)
@start_time = Time.now
append(table, row, column, value, args)
end end
def append(table, row, column, value, args={}) def append(table, row, column, value, args={})
format_simple_command do
table._append_internal(row, column, value, args) table._append_internal(row, column, value, args)
end end
end end
end end
end end
end
#add incr comamnd to Table #add incr comamnd to Table
::Hbase::Table.add_shell_command("append") ::Hbase::Table.add_shell_command("append")

View File

@ -32,8 +32,10 @@ EOF
end end
def command(id, table_cfs) def command(id, table_cfs)
format_simple_command do
replication_admin.append_peer_tableCFs(id, table_cfs) replication_admin.append_peer_tableCFs(id, table_cfs)
end end
end end
end end
end end
end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(region_name) def command(region_name)
format_simple_command do
admin.assign(region_name) admin.assign(region_name)
end end
end end
end end
end end
end

View File

@ -31,7 +31,11 @@ EOF
end end
def command(enableDisable) def command(enableDisable)
formatter.row([admin.balance_switch(enableDisable)? "true" : "false"]) format_simple_command do
formatter.row([
admin.balance_switch(enableDisable)? "true" : "false"
])
end
end end
end end
end end

View File

@ -38,13 +38,15 @@ EOF
end end
def command(force=nil) def command(force=nil)
force_balancer = 'false' format_simple_command do
if force == 'force' formatter.row([
force_balancer = 'true' if force.nil?
elsif !force.nil? admin.balancer("false")? "true": "false"
raise ArgumentError, "Invalid argument #{force}." elsif force == "force"
admin.balancer("true")? "true": "false"
end
])
end end
formatter.row([admin.balancer(force_balancer)? "true": "false"])
end end
end end
end end

View File

@ -30,7 +30,11 @@ EOF
end end
def command() def command()
formatter.row([admin.balancer_enabled?.to_s]) format_simple_command do
formatter.row([
admin.balancer_enabled?.to_s
])
end
end end
end end
end end

View File

@ -29,7 +29,11 @@ EOF
end end
def command() def command()
formatter.row([admin.catalogjanitor_enabled()? "true" : "false"]) format_simple_command do
formatter.row([
admin.catalogjanitor_enabled()? "true" : "false"
])
end
end end
end end
end end

View File

@ -28,8 +28,10 @@ Catalog janitor command to run the (garbage collection) scan from command line.
EOF EOF
end end
def command() def command()
format_simple_command do
admin.catalogjanitor_run() admin.catalogjanitor_run()
end end
end end
end end
end end
end

View File

@ -30,7 +30,11 @@ EOF
end end
def command(enableDisable) def command(enableDisable)
formatter.row([admin.catalogjanitor_switch(enableDisable)? "true" : "false"]) format_simple_command do
formatter.row([
admin.catalogjanitor_switch(enableDisable)? "true" : "false"
])
end
end end
end end
end end

View File

@ -31,8 +31,10 @@ EOF
end end
def command(user, *args) def command(user, *args)
format_simple_command do
visibility_labels_admin.clear_auths(user, args) visibility_labels_admin.clear_auths(user, args)
end end
end end
end end
end end
end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(snapshot_name, table) def command(snapshot_name, table)
format_simple_command do
admin.clone_snapshot(snapshot_name, table) admin.clone_snapshot(snapshot_name, table)
end end
end
def handle_exceptions(cause, *args) def handle_exceptions(cause, *args)
if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then

View File

@ -52,8 +52,10 @@ EOF
end end
def command(region_name, server = nil) def command(region_name, server = nil)
format_simple_command do
admin.close_region(region_name, server) admin.close_region(region_name, server)
end end
end end
end end
end end
end

View File

@ -39,8 +39,10 @@ module Shell
end end
def command(table_or_region_name, family = nil) def command(table_or_region_name, family = nil)
format_simple_command do
admin.compact(table_or_region_name, family) admin.compact(table_or_region_name, family)
end end
end end
end end
end end
end

View File

@ -34,7 +34,9 @@ module Shell
end end
def command(regionserver, major = false) def command(regionserver, major = false)
admin.compactRegionserver(regionserver, major) format_simple_command do
admin.compact_regionserver(regionserver, major)
end
end end
end end
end end

View File

@ -61,12 +61,12 @@ EOF
}.merge(params) }.merge(params)
# Call the counter method # Call the counter method
@start_time = Time.now now = Time.now
formatter.header formatter.header
count = table._count_internal(params['INTERVAL'].to_i, params['CACHE'].to_i) do |cnt, row| count = table._count_internal(params['INTERVAL'].to_i, params['CACHE'].to_i) do |cnt, row|
formatter.row([ "Current count: #{cnt}, row: #{row}" ]) formatter.row([ "Current count: #{cnt}, row: #{row}" ])
end end
formatter.footer(count) formatter.footer(now, count)
return count return count
end end
end end

View File

@ -62,11 +62,10 @@ EOF
end end
def command(table, *args) def command(table, *args)
admin.create(table, *args) format_simple_command do
@end_time = Time.now ret = admin.create(table, *args)
puts "Created table " + table.to_s end
#and then return the table you just created
#and then return the table just created
table(table) table(table)
end end
end end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(namespace, *args) def command(namespace, *args)
format_simple_command do
admin.create_namespace(namespace, *args) admin.create_namespace(namespace, *args)
end end
end end
end end
end end
end

View File

@ -47,12 +47,13 @@ EOF
def delete(table, row, column, def delete(table, row, column,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
@start_time = Time.now format_simple_command do
table._delete_internal(row, column, timestamp, args) table._delete_internal(row, column, timestamp, args)
end end
end end
end end
end end
end
#Add the method table.delete that calls delete.delete #Add the method table.delete that calls delete.delete
::Hbase::Table.add_shell_command("delete") ::Hbase::Table.add_shell_command("delete")

View File

@ -41,9 +41,9 @@ EOF
answer = gets.chomp unless count == 0 answer = gets.chomp unless count == 0
puts "No snapshots matched the regex #{regex.to_s}" if count == 0 puts "No snapshots matched the regex #{regex.to_s}" if count == 0
return unless answer =~ /y.*/i return unless answer =~ /y.*/i
@start_time = Time.now format_simple_command do
admin.delete_all_snapshot(regex) admin.delete_all_snapshot(regex)
@end_time = Time.now end
list = admin.list_snapshot(regex) list = admin.list_snapshot(regex)
leftOverSnapshotCount = list.size leftOverSnapshotCount = list.size
successfullyDeleted = count - leftOverSnapshotCount successfullyDeleted = count - leftOverSnapshotCount

View File

@ -28,8 +28,10 @@ EOF
end end
def command(snapshot_name) def command(snapshot_name)
format_simple_command do
admin.delete_snapshot(snapshot_name) admin.delete_snapshot(snapshot_name)
end end
end end
end end
end end
end

View File

@ -51,7 +51,7 @@ EOF
puts "No snapshots matched the table name regular expression #{tableNameregex.to_s} and the snapshot name regular expression #{snapshotNameRegex.to_s}" if count == 0 puts "No snapshots matched the table name regular expression #{tableNameregex.to_s} and the snapshot name regular expression #{snapshotNameRegex.to_s}" if count == 0
return unless answer =~ /y.*/i return unless answer =~ /y.*/i
@start_time = Time.now format_simple_command do
list.each do |deleteSnapshot| list.each do |deleteSnapshot|
begin begin
admin.delete_snapshot(deleteSnapshot.getName) admin.delete_snapshot(deleteSnapshot.getName)
@ -66,3 +66,4 @@ EOF
end end
end end
end end
end

View File

@ -48,12 +48,13 @@ EOF
def deleteall(table, row, column = nil, def deleteall(table, row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
@start_time = Time.now format_simple_command do
table._deleteall_internal(row, column, timestamp, args) table._deleteall_internal(row, column, timestamp, args)
end end
end end
end end
end end
end
#Add the method table.deleteall that calls deleteall.deleteall #Add the method table.deleteall that calls deleteall.deleteall
::Hbase::Table.add_shell_command("deleteall") ::Hbase::Table.add_shell_command("deleteall")

View File

@ -33,6 +33,8 @@ EOF
end end
def command(table) def command(table)
now = Time.now
column_families = admin.get_column_families(table) column_families = admin.get_column_families(table)
formatter.header(["Table " + table.to_s + " is " + if admin.enabled?(table) then "ENABLED" else "DISABLED" end]) formatter.header(["Table " + table.to_s + " is " + if admin.enabled?(table) then "ENABLED" else "DISABLED" end])
@ -41,7 +43,7 @@ EOF
column_families.each do |column_family| column_families.each do |column_family|
formatter.row([ column_family.to_s ], true) formatter.row([ column_family.to_s ], true)
end end
formatter.footer() formatter.footer(now)
end end
end end
end end

View File

@ -28,10 +28,13 @@ EOF
end end
def command(namespace) def command(namespace)
now = Time.now
desc = admin.describe_namespace(namespace) desc = admin.describe_namespace(namespace)
formatter.header([ "DESCRIPTION" ], [ 64 ]) formatter.header([ "DESCRIPTION" ], [ 64 ])
formatter.row([ desc ], true, [ 64 ]) formatter.row([ desc ], true, [ 64 ])
formatter.footer(now)
end end
end end
end end

View File

@ -29,8 +29,10 @@ EOF
end end
def command(table) def command(table)
format_simple_command do
admin.disable(table) admin.disable(table)
end end
end end
end end
end end
end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(id) def command(id)
format_simple_command do
replication_admin.disable_peer(id) replication_admin.disable_peer(id)
end end
end end
end end
end end
end

View File

@ -30,8 +30,10 @@ EOF
end end
def command(table_name) def command(table_name)
format_simple_command do
replication_admin.disable_tablerep(table_name) replication_admin.disable_tablerep(table_name)
puts "Replication of table '#{table_name}' successfully disabled." end
puts "The replication swith of table '#{table_name}' successfully disabled"
end end
end end
end end

View File

@ -29,8 +29,10 @@ EOF
end end
def command(table) def command(table)
format_simple_command do
admin.drop(table) admin.drop(table)
end end
end end
end end
end end
end

View File

@ -27,8 +27,10 @@ EOF
end end
def command(namespace) def command(namespace)
format_simple_command do
admin.drop_namespace(namespace) admin.drop_namespace(namespace)
end end
end end
end end
end end
end

View File

@ -29,8 +29,10 @@ EOF
end end
def command(table) def command(table)
format_simple_command do
admin.enable(table) admin.enable(table)
end end
end end
end end
end end
end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(id) def command(id)
format_simple_command do
replication_admin.enable_peer(id) replication_admin.enable_peer(id)
end end
end end
end end
end end
end

View File

@ -30,8 +30,10 @@ EOF
end end
def command(table_name) def command(table_name)
format_simple_command do
replication_admin.enable_tablerep(table_name) replication_admin.enable_tablerep(table_name)
puts "The replication of table '#{table_name}' successfully enabled" end
puts "The replication swith of table '#{table_name}' successfully enabled"
end end
end end
end end

View File

@ -29,11 +29,11 @@ EOF
end end
def command(table) def command(table)
exists = admin.exists?(table.to_s) format_simple_command do
formatter.row([ formatter.row([
"Table #{table} " + (exists ? "does exist" : "does not exist") "Table #{table} " + (admin.exists?(table.to_s) ? "does exist" : "does not exist")
]) ])
exists end
end end
end end
end end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(table_or_region_name) def command(table_or_region_name)
format_simple_command do
admin.flush(table_or_region_name) admin.flush(table_or_region_name)
end end
end end
end end
end end
end

View File

@ -81,14 +81,14 @@ EOF
end end
def get(table, row, *args) def get(table, row, *args)
@start_time = Time.now now = Time.now
formatter.header(["COLUMN", "CELL"]) formatter.header(["COLUMN", "CELL"])
count, is_stale = table._get_internal(row, *args) do |column, value| count, is_stale = table._get_internal(row, *args) do |column, value|
formatter.row([ column, value ]) formatter.row([ column, value ])
end end
formatter.footer(count, is_stale) formatter.footer(now, count, is_stale)
end end
end end
end end

View File

@ -31,11 +31,12 @@ EOF
end end
def command(user) def command(user)
format_simple_command do
list = visibility_labels_admin.get_auths(user) list = visibility_labels_admin.get_auths(user)
list.each do |auths| list.each do |auths|
formatter.row([org.apache.hadoop.hbase.util.Bytes::toStringBinary(auths.toByteArray)]) formatter.row([org.apache.hadoop.hbase.util.Bytes::toStringBinary(auths.toByteArray)])
end end
list end
end end
end end
end end

View File

@ -26,9 +26,9 @@ module Shell
def command(id) def command(id)
peer_config = replication_admin.get_peer_config(id) peer_config = replication_admin.get_peer_config(id)
@start_time = Time.now format_simple_command do
format_peer_config(peer_config) format_peer_config(peer_config)
peer_config end
end end
def format_peer_config(peer_config) def format_peer_config(peer_config)

View File

@ -38,8 +38,10 @@ EOF
end end
def command(table, *args) def command(table, *args)
format_and_return_simple_command do
table(table) table(table)
end end
end end
end end
end end
end

View File

@ -74,8 +74,9 @@ EOF
end end
end end
end end
@start_time = Time.now format_simple_command do
security_admin.grant(user, permissions, table_name, family, qualifier) security_admin.grant(user, permissions, table_name, family, qualifier)
end
elsif args[1].kind_of?(Hash) elsif args[1].kind_of?(Hash)
@ -91,7 +92,7 @@ EOF
raise(ArgumentError, "Scanner specification is not a Hash") unless scan.kind_of?(Hash) raise(ArgumentError, "Scanner specification is not a Hash") unless scan.kind_of?(Hash)
t = table(table_name) t = table(table_name)
@start_time = Time.now now = Time.now
scanner = t._get_scanner(scan) scanner = t._get_scanner(scan)
count = 0 count = 0
iter = scanner.iterator iter = scanner.iterator
@ -105,7 +106,7 @@ EOF
end end
count += 1 count += 1
end end
formatter.footer(count) formatter.footer(now, count)
else else
raise(ArgumentError, "Second argument should be a String or Hash") raise(ArgumentError, "Second argument should be a String or Hash")

View File

@ -49,6 +49,7 @@ EOF
end end
def incr(table, row, column, value = nil, args={}) def incr(table, row, column, value = nil, args={})
format_simple_command do
if cnt = table._incr_internal(row, column, value, args) if cnt = table._incr_internal(row, column, value, args)
puts "COUNTER VALUE = #{cnt}" puts "COUNTER VALUE = #{cnt}"
else else
@ -58,6 +59,7 @@ EOF
end end
end end
end end
end
#add incr comamnd to Table #add incr comamnd to Table
::Hbase::Table.add_shell_command("incr") ::Hbase::Table.add_shell_command("incr")

View File

@ -29,7 +29,11 @@ EOF
end end
def command(table) def command(table)
formatter.row([admin.disabled?(table)? "true" : "false"]) format_simple_command do
formatter.row([
admin.disabled?(table)? "true" : "false"
])
end
end end
end end
end end

View File

@ -29,9 +29,11 @@ EOF
end end
def command(table) def command(table)
enabled = admin.enabled?(table) format_simple_command do
formatter.row([enabled ? "true" : "false"]) formatter.row([
enabled admin.enabled?(table)? "true" : "false"
])
end
end end
end end
end end

View File

@ -33,6 +33,7 @@ EOF
end end
def command(regex = ".*") def command(regex = ".*")
now = Time.now
formatter.header([ "TABLE" ]) formatter.header([ "TABLE" ])
list = admin.list(regex) list = admin.list(regex)
@ -40,7 +41,7 @@ EOF
formatter.row([ table ]) formatter.row([ table ])
end end
formatter.footer(list.size) formatter.footer(now, list.size)
return list return list
end end
end end

View File

@ -32,6 +32,7 @@ EOF
end end
def command(regex = ".*") def command(regex = ".*")
format_simple_command do
list = visibility_labels_admin.list_labels(regex) list = visibility_labels_admin.list_labels(regex)
list.each do |label| list.each do |label|
formatter.row([org.apache.hadoop.hbase.util.Bytes::toStringBinary(label.toByteArray)]) formatter.row([org.apache.hadoop.hbase.util.Bytes::toStringBinary(label.toByteArray)])
@ -40,3 +41,4 @@ EOF
end end
end end
end end
end

View File

@ -31,6 +31,7 @@ EOF
end end
def command(regex = ".*") def command(regex = ".*")
now = Time.now
formatter.header([ "NAMESPACE" ]) formatter.header([ "NAMESPACE" ])
list = admin.list_namespace(regex) list = admin.list_namespace(regex)
@ -38,7 +39,7 @@ EOF
formatter.row([ table ]) formatter.row([ table ])
end end
formatter.footer(list.size) formatter.footer(now, list.size)
end end
end end
end end

View File

@ -30,6 +30,7 @@ EOF
end end
def command(namespace) def command(namespace)
now = Time.now
formatter.header([ "TABLE" ]) formatter.header([ "TABLE" ])
list = admin.list_namespace_tables(namespace) list = admin.list_namespace_tables(namespace)
@ -37,8 +38,7 @@ EOF
formatter.row([ table ]) formatter.row([ table ])
end end
formatter.footer(list.size) formatter.footer(now, list.size)
list
end end
end end
end end

View File

@ -25,6 +25,7 @@ module Shell
end end
def command def command
format_simple_command do
peer_configs = replication_admin.list_peer_configs peer_configs = replication_admin.list_peer_configs
unless peer_configs.nil? unless peer_configs.nil?
peer_configs.each do |peer_config_entry| peer_configs.each do |peer_config_entry|
@ -35,7 +36,7 @@ module Shell
formatter.row([" "]) formatter.row([" "])
end end
end end
peer_configs end
end end
end end
end end

View File

@ -30,6 +30,7 @@ EOF
end end
def command() def command()
now = Time.now
peers = replication_admin.list_peers peers = replication_admin.list_peers
formatter.header(["PEER_ID", "CLUSTER_KEY", "STATE", "TABLE_CFS"]) formatter.header(["PEER_ID", "CLUSTER_KEY", "STATE", "TABLE_CFS"])
@ -40,8 +41,7 @@ EOF
formatter.row([ e.key, e.value, state, tableCFs ]) formatter.row([ e.key, e.value, state, tableCFs ])
end end
formatter.footer() formatter.footer(now)
peers
end end
end end
end end

View File

@ -29,6 +29,7 @@ EOF
end end
def command() def command()
now = Time.now
formatter.header([ "Id", "Name", "State", "Start_Time", "Last_Update" ]) formatter.header([ "Id", "Name", "State", "Start_Time", "Last_Update" ])
list = admin.list_procedures() list = admin.list_procedures()
@ -38,7 +39,7 @@ EOF
formatter.row([ proc.getProcId, proc.getProcName, proc.getProcState, start_time, last_update ]) formatter.row([ proc.getProcId, proc.getProcName, proc.getProcState, start_time, last_update ])
end end
formatter.footer(list.size) formatter.footer(now, list.size)
end end
end end
end end

View File

@ -37,6 +37,7 @@ EOF
end end
def command(args = {}) def command(args = {})
now = Time.now
formatter.header(["OWNER", "QUOTAS"]) formatter.header(["OWNER", "QUOTAS"])
#actually do the scanning #actually do the scanning
@ -44,7 +45,7 @@ EOF
formatter.row([ row, cells ]) formatter.row([ row, cells ])
end end
formatter.footer(count) formatter.footer(now, count)
end end
end end
end end

View File

@ -31,6 +31,8 @@ EOF
end end
def command(regex = ".*") def command(regex = ".*")
now = Time.now
formatter.header([ "TABLE:COLUMNFAMILY", "ReplicationType" ], [ 32 ]) formatter.header([ "TABLE:COLUMNFAMILY", "ReplicationType" ], [ 32 ])
list = replication_admin.list_replicated_tables(regex) list = replication_admin.list_replicated_tables(regex)
list.each do |e| list.each do |e|
@ -41,7 +43,7 @@ EOF
end end
formatter.row([e.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::TNAME) + ":" + e.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::CFNAME), replicateType], true, [32]) formatter.row([e.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::TNAME) + ":" + e.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::CFNAME), replicateType], true, [32])
end end
formatter.footer() formatter.footer(now)
end end
end end
end end

View File

@ -34,6 +34,7 @@ EOF
end end
def command(regex = ".*") def command(regex = ".*")
now = Time.now
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"]) formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
list = admin.list_snapshot(regex) list = admin.list_snapshot(regex)
@ -42,7 +43,7 @@ EOF
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ]) formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
end end
formatter.footer(list.size) formatter.footer(now, list.size)
return list.map { |s| s.getName() } return list.map { |s| s.getName() }
end end
end end

View File

@ -39,6 +39,7 @@ EOF
end end
def command(tableNameRegex, snapshotNameRegex = ".*") def command(tableNameRegex, snapshotNameRegex = ".*")
now = Time.now
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"]) formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
list = admin.list_table_snapshots(tableNameRegex, snapshotNameRegex) list = admin.list_table_snapshots(tableNameRegex, snapshotNameRegex)
@ -47,7 +48,7 @@ EOF
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ]) formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
end end
formatter.footer(list.size) formatter.footer(now, list.size)
return list.map { |s| s.getName() } return list.map { |s| s.getName() }
end end
end end

View File

@ -30,13 +30,14 @@ EOF
end end
def command(table, row_key) def command(table, row_key)
now = Time.now
region_location = admin.locate_region(table, row_key) region_location = admin.locate_region(table, row_key)
hri = region_location.getRegionInfo() hri = region_location.getRegionInfo()
formatter.header([ "HOST", "REGION" ]) formatter.header([ "HOST", "REGION" ])
formatter.row([region_location.getHostnamePort(), hri.toString()]) formatter.row([region_location.getHostnamePort(), hri.toString()])
formatter.footer(1) formatter.footer(now, 1)
region_location
end end
end end
end end

View File

@ -40,8 +40,10 @@ module Shell
end end
def command(table_or_region_name, family = nil) def command(table_or_region_name, family = nil)
format_simple_command do
admin.major_compact(table_or_region_name, family) admin.major_compact(table_or_region_name, family)
end end
end end
end end
end end
end

View File

@ -40,8 +40,10 @@ EOF
end end
def command(encoded_region_a_name, encoded_region_b_name, force = 'false') def command(encoded_region_a_name, encoded_region_b_name, force = 'false')
format_simple_command do
admin.merge_region(encoded_region_a_name, encoded_region_b_name, force) admin.merge_region(encoded_region_a_name, encoded_region_b_name, force)
end end
end end
end end
end end
end

View File

@ -38,8 +38,10 @@ EOF
end end
def command(encoded_region_name, server_name = nil) def command(encoded_region_name, server_name = nil)
format_simple_command do
admin.move(encoded_region_name, server_name) admin.move(encoded_region_name, server_name)
end end
end end
end end
end end
end

View File

@ -33,7 +33,11 @@ EOF
end end
def command() def command()
formatter.row([admin.normalize()? "true": "false"]) format_simple_command do
formatter.row([
admin.normalize()? "true": "false"
])
end
end end
end end
end end

View File

@ -30,7 +30,11 @@ EOF
end end
def command() def command()
formatter.row([admin.normalizer_enabled?.to_s]) format_simple_command do
formatter.row([
admin.normalizer_enabled?.to_s
])
end
end end
end end
end end

View File

@ -32,7 +32,11 @@ EOF
end end
def command(enableDisable) def command(enableDisable)
formatter.row([admin.normalizer_switch(enableDisable)? "true" : "false"]) format_simple_command do
formatter.row([
admin.normalizer_switch(enableDisable)? "true" : "false"
])
end
end end
end end
end end

View File

@ -45,12 +45,13 @@ EOF
end end
def put(table, row, column, value, timestamp = nil, args = {}) def put(table, row, column, value, timestamp = nil, args = {})
@start_time = Time.now format_simple_command do
table._put_internal(row, column, value, timestamp, args) table._put_internal(row, column, value, timestamp, args)
end end
end end
end end
end end
end
#Add the method table.put that calls Put.put #Add the method table.put that calls Put.put
::Hbase::Table.add_shell_command("put") ::Hbase::Table.add_shell_command("put")

View File

@ -30,8 +30,10 @@ EOF
end end
def command(id) def command(id)
format_simple_command do
replication_admin.remove_peer(id) replication_admin.remove_peer(id)
end end
end end
end end
end end
end

View File

@ -33,8 +33,10 @@ EOF
end end
def command(id, table_cfs) def command(id, table_cfs)
format_simple_command do
replication_admin.remove_peer_tableCFs(id, table_cfs) replication_admin.remove_peer_tableCFs(id, table_cfs)
end end
end end
end end
end end
end

View File

@ -32,8 +32,10 @@ EOF
end end
def command(snapshot_name) def command(snapshot_name)
format_simple_command do
admin.restore_snapshot(snapshot_name) admin.restore_snapshot(snapshot_name)
end end
end end
end end
end end
end

View File

@ -39,8 +39,10 @@ EOF
end end
def command(user, table_name=nil, family=nil, qualifier=nil) def command(user, table_name=nil, family=nil, qualifier=nil)
format_simple_command do
security_admin.revoke(user, table_name, family, qualifier) security_admin.revoke(user, table_name, family, qualifier)
end end
end end
end end
end end
end

View File

@ -104,17 +104,16 @@ EOF
#internal command that actually does the scanning #internal command that actually does the scanning
def scan(table, args = {}) def scan(table, args = {})
now = Time.now
formatter.header(["ROW", "COLUMN+CELL"]) formatter.header(["ROW", "COLUMN+CELL"])
scan = table._hash_to_scan(args) scan = table._hash_to_scan(args)
#actually do the scanning #actually do the scanning
@start_time = Time.now
count, is_stale = table._scan_internal(args, scan) do |row, cells| count, is_stale = table._scan_internal(args, scan) do |row, cells|
formatter.row([ row, cells ]) formatter.row([ row, cells ])
end end
@end_time = Time.now
formatter.footer(count, is_stale) formatter.footer(now, count, is_stale)
# if scan metrics were enabled, print them after the results # if scan metrics were enabled, print them after the results
if (scan != nil && scan.isScanMetricsEnabled()) if (scan != nil && scan.isScanMetricsEnabled())
formatter.scan_metrics(scan.getScanMetrics(), args["METRICS"]) formatter.scan_metrics(scan.getScanMetrics(), args["METRICS"])

View File

@ -31,8 +31,10 @@ EOF
end end
def command(user, *args) def command(user, *args)
format_simple_command do
visibility_labels_admin.set_auths(user, args) visibility_labels_admin.set_auths(user, args)
end end
end end
end end
end end
end

View File

@ -38,8 +38,10 @@ module Shell
end end
def command(id, peer_table_cfs = nil) def command(id, peer_table_cfs = nil)
format_simple_command do
replication_admin.set_peer_tableCFs(id, peer_table_cfs) replication_admin.set_peer_tableCFs(id, peer_table_cfs)
end end
end end
end end
end end
end

View File

@ -51,7 +51,7 @@ EOF
def command(table, visibility, scan) def command(table, visibility, scan)
t = table(table) t = table(table)
@start_time = Time.now now = Time.now
scanner = t._get_scanner(scan) scanner = t._get_scanner(scan)
count = 0 count = 0
iter = scanner.iterator iter = scanner.iterator
@ -65,7 +65,7 @@ EOF
end end
count += 1 count += 1
end end
formatter.footer(count) formatter.footer(now, count)
end end
end end

View File

@ -36,6 +36,7 @@ EOF
end end
def command( ) def command( )
now = Time.now
parseFilter = ParseFilter.new parseFilter = ParseFilter.new
supportedFilters = parseFilter.getSupportedFilters supportedFilters = parseFilter.getSupportedFilters

View File

@ -30,9 +30,7 @@ module Shell
end end
def command(id) def command(id)
peer_table_cfs = replication_admin.show_peer_tableCFs(id) puts replication_admin.show_peer_tableCFs(id)
puts peer_table_cfs
peer_table_cfs
end end
end end
end end

View File

@ -29,8 +29,10 @@ EOF
end end
def command(table, snapshot_name, *args) def command(table, snapshot_name, *args)
format_simple_command do
admin.snapshot(table, snapshot_name, *args) admin.snapshot(table, snapshot_name, *args)
end end
end end
end end
end end
end

View File

@ -34,8 +34,10 @@ EOF
end end
def command(table_or_region_name, split_point = nil) def command(table_or_region_name, split_point = nil)
format_simple_command do
admin.split(table_or_region_name, split_point) admin.split(table_or_region_name, split_point)
end end
end end
end end
end end
end

View File

@ -30,6 +30,7 @@ EOF
end end
def command(switch_type) def command(switch_type)
format_simple_command do
formatter.row( formatter.row(
[admin.splitormerge_enabled(switch_type) ? 'true' : 'false'] [admin.splitormerge_enabled(switch_type) ? 'true' : 'false']
) )
@ -37,3 +38,4 @@ EOF
end end
end end
end end
end

View File

@ -32,6 +32,7 @@ EOF
end end
def command(switch_type, enabled) def command(switch_type, enabled)
format_simple_command do
formatter.row( formatter.row(
[admin.splitormerge_switch(switch_type, enabled) ? 'true' : 'false'] [admin.splitormerge_switch(switch_type, enabled) ? 'true' : 'false']
) )
@ -39,3 +40,4 @@ EOF
end end
end end
end end
end

View File

@ -48,8 +48,10 @@ EOF
end end
def command(startstop="status", spanname="HBaseShell") def command(startstop="status", spanname="HBaseShell")
format_and_return_simple_command do
trace(startstop, spanname) trace(startstop, spanname)
end end
end
def trace(startstop, spanname) def trace(startstop, spanname)
@@receiver ||= SpanReceiverHost.getInstance(@shell.hbase.configuration) @@receiver ||= SpanReceiverHost.getInstance(@shell.hbase.configuration)

View File

@ -27,7 +27,10 @@ EOF
end end
def command(table) def command(table)
admin.truncate(table) format_simple_command do
puts "Truncating '#{table}' table (it may take a while):"
admin.truncate(table) { |log| puts " - #{log}" }
end
end end
end end

View File

@ -27,7 +27,10 @@ EOF
end end
def command(table) def command(table)
admin.truncate_preserve(table) format_simple_command do
puts "Truncating '#{table}' table (it may take a while):"
admin.truncate_preserve(table) { |log| puts " - #{log}" }
end
end end
end end

View File

@ -36,8 +36,10 @@ EOF
end end
def command(region_name, force = 'false') def command(region_name, force = 'false')
format_simple_command do
admin.unassign(region_name, force) admin.unassign(region_name, force)
end end
end end
end end
end end
end

View File

@ -30,8 +30,10 @@ EOF
end end
def command() def command()
format_simple_command do
admin.update_all_config() admin.update_all_config()
end end
end end
end end
end end
end

View File

@ -31,8 +31,10 @@ EOF
end end
def command(serverName) def command(serverName)
format_simple_command do
admin.update_config(serverName) admin.update_config(serverName)
end end
end end
end end
end end
end

View File

@ -40,8 +40,10 @@ To update TABLE_CFs, see the append_peer_tableCFs and remove_peer_tableCFs comma
end end
def command(id, args = {}) def command(id, args = {})
format_simple_command do
replication_admin.update_peer_config(id, args) replication_admin.update_peer_config(id, args)
end end
end end
end end
end end
end

View File

@ -40,14 +40,16 @@ EOF
end end
def command(table_regex=nil) def command(table_regex=nil)
#format_simple_command do
#admin.user_permission(table_regex) #admin.user_permission(table_regex)
now = Time.now
formatter.header(["User", "Namespace,Table,Family,Qualifier:Permission"]) formatter.header(["User", "Namespace,Table,Family,Qualifier:Permission"])
count = security_admin.user_permission(table_regex) do |user, permission| count = security_admin.user_permission(table_regex) do |user, permission|
formatter.row([ user, permission]) formatter.row([ user, permission])
end end
formatter.footer(count) formatter.footer(now, count)
end end
end end
end end

View File

@ -30,10 +30,11 @@ EOF
end end
def command(server_name) def command(server_name)
format_simple_command do
admin.wal_roll(server_name) admin.wal_roll(server_name)
end end
end end
end
#TODO remove old HLog version #TODO remove old HLog version
class HlogRoll < WalRoll class HlogRoll < WalRoll
end end

View File

@ -64,7 +64,7 @@ module Shell
# Print a string # Print a string
if args.is_a?(String) if args.is_a?(String)
output_str(args) output(args)
@out.puts @out.puts
return return
end end
@ -162,7 +162,7 @@ module Shell
return str return str
end end
def output_str(str) def output(str)
output(@max_width, str) output(@max_width, str)
end end
@ -177,12 +177,15 @@ module Shell
end end
end end
def footer(row_count = nil, is_stale = false) def footer(start_time = nil, row_count = nil, is_stale = false)
return unless start_time
row_count ||= @row_count row_count ||= @row_count
# Only output elapsed time and row count if startTime passed # Only output elapsed time and row count if startTime passed
@out.puts("%d row(s)" % [row_count]) @out.print("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time])
if is_stale == true if is_stale == true
@out.puts(" (possible stale results) ") @out.puts(" (possible stale results) ")
else
@out.puts("")
end end
end end
end end

View File

@ -28,7 +28,7 @@ import org.junit.experimental.categories.Category;
@Category({ ClientTests.class, LargeTests.class }) @Category({ ClientTests.class, LargeTests.class })
public class TestReplicationShell extends AbstractTestShell { public class TestReplicationShell extends AbstractTestShell {
@Test @Ignore ("Disabled because hangs on occasion.. about 10% of the time") @Test
public void testRunShellTests() throws IOException { public void testRunShellTests() throws IOException {
System.setProperty("shell.test.include", "replication_admin_test.rb"); System.setProperty("shell.test.include", "replication_admin_test.rb");
// Start all ruby tests // Start all ruby tests

View File

@ -41,21 +41,21 @@ module Hbase
end end
define_test "exists? should return true when a table exists" do define_test "exists? should return true when a table exists" do
assert(command(:exists, 'hbase:meta')) assert(admin.exists?('hbase:meta'))
end end
define_test "exists? should return false when a table exists" do define_test "exists? should return false when a table exists" do
assert(!command(:exists, 'NOT.EXISTS')) assert(!admin.exists?('NOT.EXISTS'))
end end
define_test "enabled? should return true for enabled tables" do define_test "enabled? should return true for enabled tables" do
command(:enable, @test_name) admin.enable(@test_name)
assert(command(:is_enabled, @test_name)) assert(admin.enabled?(@test_name))
end end
define_test "enabled? should return false for disabled tables" do define_test "enabled? should return false for disabled tables" do
command(:disable, @test_name) admin.disable(@test_name)
assert(!command(:is_enabled, @test_name)) assert(!admin.enabled?(@test_name))
end end
end end
@ -78,67 +78,63 @@ module Hbase
end end
define_test "list should return a list of tables" do define_test "list should return a list of tables" do
list = command(:list) assert(admin.list.member?(@test_name))
assert(list.member?(@test_name))
end end
define_test "list should not return meta tables" do define_test "list should not return meta tables" do
list = command(:list) assert(!admin.list.member?('hbase:meta'))
assert(!list.member?('hbase:meta'))
end end
define_test "list_namespace_tables for the system namespace should return a list of tables" do define_test "list_namespace_tables for the system namespace should return a list of tables" do
list = command(:list_namespace_tables, 'hbase') assert(admin.list_namespace_tables('hbase').count > 0)
assert(list.count > 0)
end end
define_test "list_namespace_tables for the default namespace should return a list of tables" do define_test "list_namespace_tables for the default namespace should return a list of tables" do
list = command(:list_namespace_tables, 'default') assert(admin.list_namespace_tables('default').count > 0)
assert(list.count > 0)
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "flush should work" do define_test "flush should work" do
command(:flush, 'hbase:meta') admin.flush('hbase:meta')
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "compact should work" do define_test "compact should work" do
command(:compact, 'hbase:meta') admin.compact('hbase:meta')
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "major_compact should work" do define_test "major_compact should work" do
command(:major_compact, 'hbase:meta') admin.major_compact('hbase:meta')
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "split should work" do define_test "split should work" do
command(:split, 'hbase:meta', nil) admin.split('hbase:meta', nil)
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "drop should fail on non-existent tables" do define_test "drop should fail on non-existent tables" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:drop, 'NOT.EXISTS') admin.drop('NOT.EXISTS')
end end
end end
define_test "drop should fail on enabled tables" do define_test "drop should fail on enabled tables" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:drop, @test_name) admin.drop(@test_name)
end end
end end
define_test "drop should drop tables" do define_test "drop should drop tables" do
command(:disable, @test_name) admin.disable(@test_name)
command(:drop, @test_name) admin.drop(@test_name)
assert(!command(:exists, @test_name)) assert(!admin.exists?(@test_name))
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -151,46 +147,45 @@ module Hbase
define_test "create should fail with non-string table names" do define_test "create should fail with non-string table names" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:create, 123, 'xxx') admin.create(123, 'xxx')
end end
end end
define_test "create should fail with non-string/non-hash column args" do define_test "create should fail with non-string/non-hash column args" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:create, @create_test_name, 123) admin.create(@create_test_name, 123)
end end
end end
define_test "create should fail without columns" do define_test "create should fail without columns" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:create, @create_test_name) admin.create(@create_test_name)
end end
end end
define_test "create should fail without columns when called with options" do define_test "create should fail without columns when called with options" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:create, @create_test_name, { OWNER => 'a' }) admin.create(@create_test_name, { OWNER => 'a' })
end end
end end
define_test "create should work with string column args" do define_test "create should work with string column args" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
command(:create, @create_test_name, 'a', 'b') admin.create(@create_test_name, 'a', 'b')
assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort) assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
end end
define_test "create should work with hash column args" do define_test "create should work with hash column args" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
command(:create, @create_test_name, { NAME => 'a'}, { NAME => 'b'}) admin.create(@create_test_name, { NAME => 'a'}, { NAME => 'b'})
assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort) assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
end end
define_test "create should be able to set table options" do define_test "create should be able to set table options" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
command(:create, @create_test_name, 'a', 'b', 'MAX_FILESIZE' => 12345678, admin.create(@create_test_name, 'a', 'b', 'MAX_FILESIZE' => 12345678, OWNER => '987654321')
OWNER => '987654321')
assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort) assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
assert_match(/12345678/, admin.describe(@create_test_name)) assert_match(/12345678/, admin.describe(@create_test_name))
assert_match(/987654321/, admin.describe(@create_test_name)) assert_match(/987654321/, admin.describe(@create_test_name))
@ -198,15 +193,14 @@ module Hbase
define_test "create should ignore table_att" do define_test "create should ignore table_att" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
command(:create, @create_test_name, 'a', 'b', METHOD => 'table_att', OWNER => '987654321') admin.create(@create_test_name, 'a', 'b', METHOD => 'table_att', OWNER => '987654321')
assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort) assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
assert_match(/987654321/, admin.describe(@create_test_name)) assert_match(/987654321/, admin.describe(@create_test_name))
end end
define_test "create should work with SPLITALGO" do define_test "create should work with SPLITALGO" do
drop_test_table(@create_test_name) drop_test_table(@create_test_name)
command(:create, @create_test_name, 'a', 'b', admin.create(@create_test_name, 'a', 'b', {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'})
{NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'})
assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort) assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
end end
@ -229,13 +223,17 @@ module Hbase
table(@test_name).put(2, "x:a", 2) table(@test_name).put(2, "x:a", 2)
assert_equal(2, table(@test_name)._count_internal) assert_equal(2, table(@test_name)._count_internal)
# This is hacky. Need to get the configuration into admin instance # This is hacky. Need to get the configuration into admin instance
command(:truncate, @test_name) admin.truncate(@test_name, $TEST_CLUSTER.getConfiguration)
assert_equal(0, table(@test_name)._count_internal) assert_equal(0, table(@test_name)._count_internal)
end end
define_test "truncate should yield log records" do define_test "truncate should yield log records" do
output = capture_stdout { command(:truncate, @test_name) } logs = []
assert(!output.empty?) admin.truncate(@test_name, $TEST_CLUSTER.getConfiguration) do |log|
assert_kind_of(String, log)
logs << log
end
assert(!logs.empty?)
end end
end end
@ -259,68 +257,77 @@ module Hbase
define_test "alter should fail with non-string table names" do define_test "alter should fail with non-string table names" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:alter, 123, METHOD => 'delete', NAME => 'y') admin.alter(123, true, METHOD => 'delete', NAME => 'y')
end end
end end
define_test "alter should fail with non-existing tables" do define_test "alter should fail with non-existing tables" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:alter, 'NOT.EXISTS', METHOD => 'delete', NAME => 'y') admin.alter('NOT.EXISTS', true, METHOD => 'delete', NAME => 'y')
end end
end end
define_test "alter should not fail with enabled tables" do define_test "alter should not fail with enabled tables" do
command(:enable, @test_name) admin.enable(@test_name)
command(:alter, @test_name, METHOD => 'delete', NAME => 'y') admin.alter(@test_name, true, METHOD => 'delete', NAME => 'y')
end end
define_test "alter should be able to delete column families" do define_test "alter should be able to delete column families" do
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
command(:alter, @test_name, METHOD => 'delete', NAME => 'y') admin.alter(@test_name, true, METHOD => 'delete', NAME => 'y')
command(:enable, @test_name) admin.enable(@test_name)
assert_equal(['x:'], table(@test_name).get_all_columns.sort) assert_equal(['x:'], table(@test_name).get_all_columns.sort)
end end
define_test "alter should be able to add column families" do define_test "alter should be able to add column families" do
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
command(:alter, @test_name, NAME => 'z') admin.alter(@test_name, true, NAME => 'z')
command(:enable, @test_name) admin.enable(@test_name)
assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort)
end end
define_test "alter should be able to add column families (name-only alter spec)" do define_test "alter should be able to add column families (name-only alter spec)" do
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
command(:alter, @test_name, 'z') admin.alter(@test_name, true, 'z')
command(:enable, @test_name) admin.enable(@test_name)
assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort)
end end
define_test "alter should support more than one alteration in one call" do define_test "alter should support more than one alteration in one call" do
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
alterOutput = capture_stdout { alterOutput = capture_stdout { admin.alter(@test_name, true, { NAME => 'z' },
command(:alter, @test_name, { NAME => 'z' }, { METHOD => 'delete', NAME => 'y' }, { METHOD => 'delete', NAME => 'y' }, 'MAX_FILESIZE' => 12345678) }
'MAX_FILESIZE' => 12345678) } admin.enable(@test_name)
command(:enable, @test_name)
assert_equal(1, /Updating all regions/.match(alterOutput).size, assert_equal(1, /Updating all regions/.match(alterOutput).size,
"HBASE-15641 - Should only perform one table modification per alter.") "HBASE-15641 - Should only perform one table modification per alter.")
assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort)
assert_match(/12345678/, admin.describe(@test_name)) assert_match(/12345678/, admin.describe(@test_name))
end end
def capture_stdout
begin
old_stdout = $stdout
$stdout = StringIO.new('','w')
yield
$stdout.string
ensure
$stdout = old_stdout
end
end
define_test 'alter should support shortcut DELETE alter specs' do define_test 'alter should support shortcut DELETE alter specs' do
assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
command(:alter, @test_name, 'delete' => 'y') admin.alter(@test_name, true, 'delete' => 'y')
assert_equal(['x:'], table(@test_name).get_all_columns.sort) assert_equal(['x:'], table(@test_name).get_all_columns.sort)
end end
define_test "alter should be able to change table options" do define_test "alter should be able to change table options" do
command(:alter, @test_name, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678) admin.alter(@test_name, true, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678)
assert_match(/12345678/, admin.describe(@test_name)) assert_match(/12345678/, admin.describe(@test_name))
end end
define_test "alter should be able to change table options w/o table_att" do define_test "alter should be able to change table options w/o table_att" do
command(:alter, @test_name, 'MAX_FILESIZE' => 12345678) admin.alter(@test_name, true, 'MAX_FILESIZE' => 12345678)
assert_match(/12345678/, admin.describe(@test_name)) assert_match(/12345678/, admin.describe(@test_name))
end end
@ -336,7 +343,7 @@ module Hbase
# eval() is used to convert a string to regex # eval() is used to convert a string to regex
assert_no_match(eval("/" + class_name + "/"), admin.describe(@test_name)) assert_no_match(eval("/" + class_name + "/"), admin.describe(@test_name))
assert_no_match(eval("/" + cp_key + "/"), admin.describe(@test_name)) assert_no_match(eval("/" + cp_key + "/"), admin.describe(@test_name))
command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value) admin.alter(@test_name, true, 'METHOD' => 'table_att', cp_key => cp_value)
assert_match(eval("/" + class_name + "/"), admin.describe(@test_name)) assert_match(eval("/" + class_name + "/"), admin.describe(@test_name))
assert_match(eval("/" + cp_key + "\\$(\\d+)/"), admin.describe(@test_name)) assert_match(eval("/" + cp_key + "\\$(\\d+)/"), admin.describe(@test_name))
end end
@ -346,12 +353,12 @@ module Hbase
create_test_table(@test_name) create_test_table(@test_name)
key = "MAX_FILESIZE" key = "MAX_FILESIZE"
command(:alter, @test_name, 'METHOD' => 'table_att', key => 12345678) admin.alter(@test_name, true, 'METHOD' => 'table_att', key => 12345678)
# eval() is used to convert a string to regex # eval() is used to convert a string to regex
assert_match(eval("/" + key + "/"), admin.describe(@test_name)) assert_match(eval("/" + key + "/"), admin.describe(@test_name))
command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => key) admin.alter(@test_name, true, 'METHOD' => 'table_att_unset', 'NAME' => key)
assert_no_match(eval("/" + key + "/"), admin.describe(@test_name)) assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
end end
@ -360,13 +367,13 @@ module Hbase
key_1 = "TestAttr1" key_1 = "TestAttr1"
key_2 = "TestAttr2" key_2 = "TestAttr2"
command(:create, @test_name, { NAME => 'i'}, METADATA => { key_1 => 1, key_2 => 2 }) admin.create(@test_name, { NAME => 'i'}, METADATA => { key_1 => 1, key_2 => 2 })
# eval() is used to convert a string to regex # eval() is used to convert a string to regex
assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name))
assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name))
command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => [ key_1, key_2 ]) admin.alter(@test_name, true, 'METHOD' => 'table_att_unset', 'NAME' => [ key_1, key_2 ])
assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name))
assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name))
end end
@ -414,66 +421,66 @@ module Hbase
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "Snapshot should fail with non-string snapshot name" do define_test "Snapshot should fail with non-string snapshot name" do
assert_raise(NoMethodError) do assert_raise(NoMethodError) do
command(:snapshot, @create_test_snapshot, 123) admin.snapshot(123, 'xxx')
end end
end end
define_test "Snapshot should fail with non-string table name" do define_test "Snapshot should fail with non-string table name" do
assert_raise(NoMethodError) do assert_raise(NoMethodError) do
command(:snapshot, 123, 'xxx') admin.snapshot(@create_test_snapshot, 123)
end end
end end
define_test "Snapshot should fail without table name" do define_test "Snapshot should fail without table name" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:snapshot, "hbase_create_test_snapshot") admin.snapshot("hbase_create_test_snapshot")
end end
end end
define_test "Snapshot should work with string args" do define_test "Snapshot should work with string args" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, @create_test_snapshot) admin.snapshot(@test_name, @create_test_snapshot)
list = command(:list_snapshots, @create_test_snapshot) list = admin.list_snapshot(@create_test_snapshot)
assert_equal(1, list.size) assert_equal(1, list.size)
end end
define_test "Snapshot should work when SKIP_FLUSH args" do define_test "Snapshot should work when SKIP_FLUSH args" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, @create_test_snapshot, {SKIP_FLUSH => true}) admin.snapshot(@test_name, @create_test_snapshot, {SKIP_FLUSH => true})
list = command(:list_snapshots, @create_test_snapshot) list = admin.list_snapshot(@create_test_snapshot)
assert_equal(1, list.size) assert_equal(1, list.size)
end end
define_test "List snapshot without any args" do define_test "List snapshot without any args" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, @create_test_snapshot) admin.snapshot(@test_name, @create_test_snapshot)
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(1, list.size) assert_equal(1, list.size)
end end
define_test "List snapshot for a non-existing snapshot" do define_test "List snapshot for a non-existing snapshot" do
list = command(:list_snapshots, "xyz") list = admin.list_snapshot("xyz")
assert_equal(0, list.size) assert_equal(0, list.size)
end end
define_test "Restore snapshot without any args" do define_test "Restore snapshot without any args" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:restore_snapshot) admin.restore_snapshot()
end end
end end
define_test "Restore snapshot should work" do define_test "Restore snapshot should work" do
drop_test_snapshot() drop_test_snapshot()
restore_table = "test_restore_snapshot_table" restore_table = "test_restore_snapshot_table"
command(:create, restore_table, 'f1', 'f2') admin.create(restore_table, 'f1', 'f2')
assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table)) assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table))
assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table)) assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table))
command(:snapshot, restore_table, @create_test_snapshot) admin.snapshot(restore_table, @create_test_snapshot)
command(:alter, restore_table, METHOD => 'delete', NAME => 'f1') admin.alter(restore_table, true, METHOD => 'delete', NAME => 'f1')
assert_no_match(eval("/" + "f1" + "/"), admin.describe(restore_table)) assert_no_match(eval("/" + "f1" + "/"), admin.describe(restore_table))
assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table)) assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table))
drop_test_table(restore_table) drop_test_table(restore_table)
command(:restore_snapshot, @create_test_snapshot) admin.restore_snapshot(@create_test_snapshot)
assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table)) assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table))
assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table)) assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table))
drop_test_table(restore_table) drop_test_table(restore_table)
@ -481,13 +488,13 @@ module Hbase
define_test "Clone snapshot without any args" do define_test "Clone snapshot without any args" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:restore_snapshot) admin.restore_snapshot()
end end
end end
define_test "Clone snapshot without table name args" do define_test "Clone snapshot without table name args" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:clone_snapshot, @create_test_snapshot) admin.clone_snapshot(@create_test_snapshot)
end end
end end
@ -496,8 +503,8 @@ module Hbase
clone_table = "test_clone_snapshot_table" clone_table = "test_clone_snapshot_table"
assert_match(eval("/" + "x" + "/"), admin.describe(@test_name)) assert_match(eval("/" + "x" + "/"), admin.describe(@test_name))
assert_match(eval("/" + "y" + "/"), admin.describe(@test_name)) assert_match(eval("/" + "y" + "/"), admin.describe(@test_name))
command(:snapshot, @test_name, @create_test_snapshot) admin.snapshot(@test_name, @create_test_snapshot)
command(:clone_snapshot, @create_test_snapshot, clone_table) admin.clone_snapshot(@create_test_snapshot, clone_table)
assert_match(eval("/" + "x" + "/"), admin.describe(clone_table)) assert_match(eval("/" + "x" + "/"), admin.describe(clone_table))
assert_match(eval("/" + "y" + "/"), admin.describe(clone_table)) assert_match(eval("/" + "y" + "/"), admin.describe(clone_table))
drop_test_table(clone_table) drop_test_table(clone_table)
@ -511,11 +518,11 @@ module Hbase
define_test "Delete snapshot should work" do define_test "Delete snapshot should work" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, @create_test_snapshot) admin.snapshot(@test_name, @create_test_snapshot)
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(1, list.size) assert_equal(1, list.size)
admin.delete_snapshot(@create_test_snapshot) admin.delete_snapshot(@create_test_snapshot)
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(0, list.size) assert_equal(0, list.size)
end end
@ -527,17 +534,17 @@ module Hbase
define_test "Delete all snapshots should work" do define_test "Delete all snapshots should work" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, "delete_all_snapshot1") admin.snapshot(@test_name, "delete_all_snapshot1")
command(:snapshot, @test_name, "delete_all_snapshot2") admin.snapshot(@test_name, "delete_all_snapshot2")
command(:snapshot, @test_name, "snapshot_delete_all_1") admin.snapshot(@test_name, "snapshot_delete_all_1")
command(:snapshot, @test_name, "snapshot_delete_all_2") admin.snapshot(@test_name, "snapshot_delete_all_2")
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(4, list.size) assert_equal(4, list.size)
admin.delete_all_snapshot("d.*") admin.delete_all_snapshot("d.*")
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(2, list.size) assert_equal(2, list.size)
admin.delete_all_snapshot(".*") admin.delete_all_snapshot(".*")
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(0, list.size) assert_equal(0, list.size)
end end
@ -549,48 +556,48 @@ module Hbase
define_test "Delete table snapshots should work" do define_test "Delete table snapshots should work" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, "delete_table_snapshot1") admin.snapshot(@test_name, "delete_table_snapshot1")
command(:snapshot, @test_name, "delete_table_snapshot2") admin.snapshot(@test_name, "delete_table_snapshot2")
command(:snapshot, @test_name, "snapshot_delete_table1") admin.snapshot(@test_name, "snapshot_delete_table1")
new_table = "test_delete_table_snapshots_table" new_table = "test_delete_table_snapshots_table"
command(:create, new_table, 'f1') admin.create(new_table, 'f1')
command(:snapshot, new_table, "delete_table_snapshot3") admin.snapshot(new_table, "delete_table_snapshot3")
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(4, list.size) assert_equal(4, list.size)
admin.delete_table_snapshots(@test_name, "d.*") admin.delete_table_snapshots(@test_name, "d.*")
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(2, list.size) assert_equal(2, list.size)
admin.delete_table_snapshots(@test_name) admin.delete_table_snapshots(@test_name)
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(1, list.size) assert_equal(1, list.size)
admin.delete_table_snapshots(".*", "d.*") admin.delete_table_snapshots(".*", "d.*")
list = command(:list_snapshots) list = admin.list_snapshot()
assert_equal(0, list.size) assert_equal(0, list.size)
drop_test_table(new_table) drop_test_table(new_table)
end end
define_test "List table snapshots without any args" do define_test "List table snapshots without any args" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:list_table_snapshots) admin.list_table_snapshots()
end end
end end
define_test "List table snapshots should work" do define_test "List table snapshots should work" do
drop_test_snapshot() drop_test_snapshot()
command(:snapshot, @test_name, "delete_table_snapshot1") admin.snapshot(@test_name, "delete_table_snapshot1")
command(:snapshot, @test_name, "delete_table_snapshot2") admin.snapshot(@test_name, "delete_table_snapshot2")
command(:snapshot, @test_name, "snapshot_delete_table1") admin.snapshot(@test_name, "snapshot_delete_table1")
new_table = "test_list_table_snapshots_table" new_table = "test_list_table_snapshots_table"
command(:create, new_table, 'f1') admin.create(new_table, 'f1')
command(:snapshot, new_table, "delete_table_snapshot3") admin.snapshot(new_table, "delete_table_snapshot3")
list = command(:list_table_snapshots, ".*") list = admin.list_table_snapshots(".*")
assert_equal(4, list.size) assert_equal(4, list.size)
list = command(:list_table_snapshots, @test_name, "d.*") list = admin.list_table_snapshots(@test_name, "d.*")
assert_equal(2, list.size) assert_equal(2, list.size)
list = command(:list_table_snapshots, @test_name) list = admin.list_table_snapshots(@test_name)
assert_equal(3, list.size) assert_equal(3, list.size)
admin.delete_table_snapshots(".*") admin.delete_table_snapshots(".*")
list = command(:list_table_snapshots, ".*", ".*") list = admin.list_table_snapshots(".*", ".*")
assert_equal(0, list.size) assert_equal(0, list.size)
drop_test_table(new_table) drop_test_table(new_table)
end end

View File

@ -33,25 +33,25 @@ module Hbase
setup_hbase setup_hbase
assert_equal(0, command(:list_peers).length) assert_equal(0, replication_admin.list_peers.length)
end end
def teardown def teardown
assert_equal(0, command(:list_peers).length) assert_equal(0, replication_admin.list_peers.length)
shutdown shutdown
end end
define_test "add_peer: should fail when args isn't specified" do define_test "add_peer: should fail when args isn't specified" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:add_peer, @peer_id, nil) replication_admin.add_peer(@peer_id, nil)
end end
end end
define_test "add_peer: fail when neither CLUSTER_KEY nor ENDPOINT_CLASSNAME are specified" do define_test "add_peer: fail when neither CLUSTER_KEY nor ENDPOINT_CLASSNAME are specified" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
args = {} args = {}
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
end end
end end
@ -59,86 +59,86 @@ module Hbase
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
args = { CLUSTER_KEY => 'zk1,zk2,zk3:2182:/hbase-prod', args = { CLUSTER_KEY => 'zk1,zk2,zk3:2182:/hbase-prod',
ENDPOINT_CLASSNAME => 'org.apache.hadoop.hbase.MyReplicationEndpoint' } ENDPOINT_CLASSNAME => 'org.apache.hadoop.hbase.MyReplicationEndpoint' }
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
end end
end end
define_test "add_peer: args must be a string or number" do define_test "add_peer: args must be a string or number" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:add_peer, @peer_id, 1) replication_admin.add_peer(@peer_id, 1)
end end
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
command(:add_peer, @peer_id, ['test']) replication_admin.add_peer(@peer_id, ['test'])
end end
end end
define_test "add_peer: single zk cluster key" do define_test "add_peer: single zk cluster key" do
cluster_key = "server1.cie.com:2181:/hbase" cluster_key = "server1.cie.com:2181:/hbase"
command(:add_peer, @peer_id, cluster_key) replication_admin.add_peer(@peer_id, cluster_key)
assert_equal(1, command(:list_peers).length) assert_equal(1, replication_admin.list_peers.length)
assert(command(:list_peers).key?(@peer_id)) assert(replication_admin.list_peers.key?(@peer_id))
assert_equal(cluster_key, command(:list_peers).fetch(@peer_id)) assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id))
# cleanup for future tests # cleanup for future tests
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "add_peer: multiple zk cluster key" do define_test "add_peer: multiple zk cluster key" do
cluster_key = "zk1,zk2,zk3:2182:/hbase-prod" cluster_key = "zk1,zk2,zk3:2182:/hbase-prod"
command(:add_peer, @peer_id, cluster_key) replication_admin.add_peer(@peer_id, cluster_key)
assert_equal(1, command(:list_peers).length) assert_equal(1, replication_admin.list_peers.length)
assert(command(:list_peers).key?(@peer_id)) assert(replication_admin.list_peers.key?(@peer_id))
assert_equal(cluster_key, command(:list_peers).fetch(@peer_id)) assert_equal(replication_admin.list_peers.fetch(@peer_id), cluster_key)
# cleanup for future tests # cleanup for future tests
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "add_peer: multiple zk cluster key and table_cfs" do define_test "add_peer: multiple zk cluster key and table_cfs" do
cluster_key = "zk4,zk5,zk6:11000:/hbase-test" cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
table_cfs_str = "table1;table2:cf1;table3:cf2,cf3" table_cfs_str = "table1;table2:cf1;table3:cf2,cf3"
command(:add_peer, @peer_id, cluster_key, table_cfs_str) replication_admin.add_peer(@peer_id, cluster_key, table_cfs_str)
assert_equal(1, command(:list_peers).length) assert_equal(1, replication_admin.list_peers.length)
assert(command(:list_peers).key?(@peer_id)) assert(replication_admin.list_peers.key?(@peer_id))
assert_equal(cluster_key, command(:list_peers).fetch(@peer_id)) assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id))
assert_equal(table_cfs_str, command(:show_peer_tableCFs, @peer_id)) assert_equal(table_cfs_str, replication_admin.show_peer_tableCFs(@peer_id))
# cleanup for future tests # cleanup for future tests
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "add_peer: single zk cluster key - peer config" do define_test "add_peer: single zk cluster key - peer config" do
cluster_key = "server1.cie.com:2181:/hbase" cluster_key = "server1.cie.com:2181:/hbase"
args = { CLUSTER_KEY => cluster_key } args = { CLUSTER_KEY => cluster_key }
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
assert_equal(1, command(:list_peers).length) assert_equal(1, replication_admin.list_peers.length)
assert(command(:list_peers).key?(@peer_id)) assert(replication_admin.list_peers.key?(@peer_id))
assert_equal(cluster_key, command(:list_peers).fetch(@peer_id)) assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id))
# cleanup for future tests # cleanup for future tests
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "add_peer: multiple zk cluster key - peer config" do define_test "add_peer: multiple zk cluster key - peer config" do
cluster_key = "zk1,zk2,zk3:2182:/hbase-prod" cluster_key = "zk1,zk2,zk3:2182:/hbase-prod"
args = { CLUSTER_KEY => cluster_key } args = { CLUSTER_KEY => cluster_key }
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
assert_equal(1, command(:list_peers).length) assert_equal(1, replication_admin.list_peers.length)
assert(command(:list_peers).key?(@peer_id)) assert(replication_admin.list_peers.key?(@peer_id))
assert_equal(cluster_key, command(:list_peers).fetch(@peer_id)) assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id))
# cleanup for future tests # cleanup for future tests
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "add_peer: multiple zk cluster key and table_cfs - peer config" do define_test "add_peer: multiple zk cluster key and table_cfs - peer config" do
@ -147,15 +147,15 @@ module Hbase
table_cfs_str = "table1;table2:cf1;table3:cf1,cf2" table_cfs_str = "table1;table2:cf1;table3:cf1,cf2"
args = { CLUSTER_KEY => cluster_key, TABLE_CFS => table_cfs } args = { CLUSTER_KEY => cluster_key, TABLE_CFS => table_cfs }
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
assert_equal(1, command(:list_peers).length) assert_equal(1, replication_admin.list_peers.length)
assert(command(:list_peers).key?(@peer_id)) assert(replication_admin.list_peers.key?(@peer_id))
assert_equal(cluster_key, command(:list_peers).fetch(@peer_id)) assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id))
assert_equal(table_cfs_str, command(:show_peer_tableCFs, @peer_id)) assert_equal(table_cfs_str, replication_admin.show_peer_tableCFs(@peer_id))
# cleanup for future tests # cleanup for future tests
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "add_peer: should fail when args is a hash and peer_tableCFs provided" do define_test "add_peer: should fail when args is a hash and peer_tableCFs provided" do
@ -164,51 +164,51 @@ module Hbase
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
args = { CLUSTER_KEY => cluster_key } args = { CLUSTER_KEY => cluster_key }
command(:add_peer, @peer_id, args, table_cfs_str) replication_admin.add_peer(@peer_id, args, table_cfs_str)
end end
end end
define_test "get_peer_config: works with simple clusterKey peer" do define_test "get_peer_config: works with simple clusterKey peer" do
cluster_key = "localhost:2181:/hbase-test" cluster_key = "localhost:2181:/hbase-test"
args = { CLUSTER_KEY => cluster_key } args = { CLUSTER_KEY => cluster_key }
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
peer_config = command(:get_peer_config, @peer_id) peer_config = replication_admin.get_peer_config(@peer_id)
assert_equal(cluster_key, peer_config.get_cluster_key) assert_equal(cluster_key, peer_config.get_cluster_key)
#cleanup #cleanup
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "get_peer_config: works with replicationendpointimpl peer and config params" do define_test "get_peer_config: works with replicationendpointimpl peer and config params" do
repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest" repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest"
config_params = { "config1" => "value1", "config2" => "value2" } config_params = { "config1" => "value1", "config2" => "value2" }
args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params} args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params}
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
peer_config = command(:get_peer_config, @peer_id) peer_config = replication_admin.get_peer_config(@peer_id)
assert_equal(repl_impl, peer_config.get_replication_endpoint_impl) assert_equal(repl_impl, peer_config.get_replication_endpoint_impl)
assert_equal(2, peer_config.get_configuration.size) assert_equal(2, peer_config.get_configuration.size)
assert_equal("value1", peer_config.get_configuration.get("config1")) assert_equal("value1", peer_config.get_configuration.get("config1"))
#cleanup #cleanup
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
end end
define_test "list_peer_configs: returns all peers' ReplicationPeerConfig objects" do define_test "list_peer_configs: returns all peers' ReplicationPeerConfig objects" do
cluster_key = "localhost:2181:/hbase-test" cluster_key = "localhost:2181:/hbase-test"
args = { CLUSTER_KEY => cluster_key } args = { CLUSTER_KEY => cluster_key }
peer_id_second = '2' peer_id_second = '2'
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest" repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest"
config_params = { "config1" => "value1", "config2" => "value2" } config_params = { "config1" => "value1", "config2" => "value2" }
args2 = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params} args2 = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params}
command(:add_peer, peer_id_second, args2) replication_admin.add_peer(peer_id_second, args2)
peer_configs = command(:list_peer_configs) peer_configs = replication_admin.list_peer_configs
assert_equal(2, peer_configs.size) assert_equal(2, peer_configs.size)
assert_equal(cluster_key, peer_configs.get(@peer_id).get_cluster_key) assert_equal(cluster_key, peer_configs.get(@peer_id).get_cluster_key)
assert_equal(repl_impl, peer_configs.get(peer_id_second).get_replication_endpoint_impl) assert_equal(repl_impl, peer_configs.get(peer_id_second).get_replication_endpoint_impl)
#cleanup #cleanup
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
command(:remove_peer, peer_id_second) replication_admin.remove_peer(peer_id_second)
end end
define_test "update_peer_config: can update peer config and data" do define_test "update_peer_config: can update peer config and data" do
@ -216,7 +216,7 @@ module Hbase
config_params = { "config1" => "value1", "config2" => "value2" } config_params = { "config1" => "value1", "config2" => "value2" }
data_params = {"data1" => "value1", "data2" => "value2"} data_params = {"data1" => "value1", "data2" => "value2"}
args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params, DATA => data_params} args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params, DATA => data_params}
command(:add_peer, @peer_id, args) replication_admin.add_peer(@peer_id, args)
#Normally the ReplicationSourceManager will call ReplicationPeer#peer_added, but here we have to do it ourselves #Normally the ReplicationSourceManager will call ReplicationPeer#peer_added, but here we have to do it ourselves
replication_admin.peer_added(@peer_id) replication_admin.peer_added(@peer_id)
@ -224,12 +224,12 @@ module Hbase
new_config_params = { "config1" => "new_value1" } new_config_params = { "config1" => "new_value1" }
new_data_params = {"data1" => "new_value1"} new_data_params = {"data1" => "new_value1"}
new_args = {CONFIG => new_config_params, DATA => new_data_params} new_args = {CONFIG => new_config_params, DATA => new_data_params}
command(:update_peer_config, @peer_id, new_args) replication_admin.update_peer_config(@peer_id, new_args)
#Make sure the updated key/value pairs in config and data were successfully updated, and that those we didn't #Make sure the updated key/value pairs in config and data were successfully updated, and that those we didn't
#update are still there and unchanged #update are still there and unchanged
peer_config = command(:get_peer_config, @peer_id) peer_config = replication_admin.get_peer_config(@peer_id)
command(:remove_peer, @peer_id) replication_admin.remove_peer(@peer_id)
assert_equal("new_value1", peer_config.get_configuration.get("config1")) assert_equal("new_value1", peer_config.get_configuration.get("config1"))
assert_equal("value2", peer_config.get_configuration.get("config2")) assert_equal("value2", peer_config.get_configuration.get("config2"))
assert_equal("new_value1", Bytes.to_string(peer_config.get_peer_data.get(Bytes.toBytes("data1")))) assert_equal("new_value1", Bytes.to_string(peer_config.get_peer_data.get(Bytes.toBytes("data1"))))
@ -239,17 +239,17 @@ module Hbase
# assert_raise fails on native exceptions - https://jira.codehaus.org/browse/JRUBY-5279 # assert_raise fails on native exceptions - https://jira.codehaus.org/browse/JRUBY-5279
# Can't catch native Java exception with assert_raise in JRuby 1.6.8 as in the test below. # Can't catch native Java exception with assert_raise in JRuby 1.6.8 as in the test below.
# define_test "add_peer: adding a second peer with same id should error" do # define_test "add_peer: adding a second peer with same id should error" do
# command(:add_peer, @peer_id, '') # replication_admin.add_peer(@peer_id, '')
# assert_equal(1, command(:list_peers).length) # assert_equal(1, replication_admin.list_peers.length)
# #
# assert_raise(java.lang.IllegalArgumentException) do # assert_raise(java.lang.IllegalArgumentException) do
# command(:add_peer, @peer_id, '') # replication_admin.add_peer(@peer_id, '')
# end # end
# #
# assert_equal(1, command(:list_peers).length, 1) # assert_equal(1, replication_admin.list_peers.length, 1)
# #
# # cleanup for future tests # # cleanup for future tests
# command(:remove_peer, @peer_id) # replication_admin.remove_peer(@peer_id)
# end # end
end end
end end

View File

@ -45,37 +45,37 @@ module Hbase
define_test "Labels should be created as specified" do define_test "Labels should be created as specified" do
label = 'TEST_LABELS' label = 'TEST_LABELS'
count = table('hbase:labels')._count_internal count = table('hbase:labels')._count_internal
command(:add_labels, 'test_label') visibility_admin.add_labels('test_label')
assert_equal(count + 1, table('hbase:labels')._count_internal) assert_equal(count + 1, table('hbase:labels')._count_internal)
end end
define_test "The set/clear methods should work with authorizations" do define_test "The set/clear methods should work with authorizations" do
label = 'TEST_AUTHS' label = 'TEST_AUTHS'
user = org.apache.hadoop.hbase.security.User.getCurrent().getName(); user = org.apache.hadoop.hbase.security.User.getCurrent().getName();
command(:add_labels, label) visibility_admin.add_labels(label)
$TEST_CLUSTER.waitLabelAvailable(10000, label) $TEST_CLUSTER.waitLabelAvailable(10000, label)
count = command(:get_auths, user).length count = visibility_admin.get_auths(user).length
# verifying the set functionality # verifying the set functionality
command(:set_auths, user, label) visibility_admin.set_auths(user, label)
assert_equal(count + 1, command(:get_auths, user).length) assert_equal(count + 1, visibility_admin.get_auths(user).length)
assert_block do assert_block do
command(:get_auths, user).any? { visibility_admin.get_auths(user).any? {
|auth| org.apache.hadoop.hbase.util.Bytes::toStringBinary(auth.toByteArray) == label |auth| org.apache.hadoop.hbase.util.Bytes::toStringBinary(auth.toByteArray) == label
} }
end end
# verifying the clear functionality # verifying the clear functionality
command(:clear_auths, user, label) visibility_admin.clear_auths(user, label)
assert_equal(count, command(:get_auths, user).length) assert_equal(count, visibility_admin.get_auths(user).length)
end end
define_test "The get/put methods should work for data written with Visibility" do define_test "The get/put methods should work for data written with Visibility" do
label = 'TEST_VISIBILITY' label = 'TEST_VISIBILITY'
user = org.apache.hadoop.hbase.security.User.getCurrent().getName(); user = org.apache.hadoop.hbase.security.User.getCurrent().getName();
command(:add_labels, label) visibility_admin.add_labels(label)
$TEST_CLUSTER.waitLabelAvailable(10000, label) $TEST_CLUSTER.waitLabelAvailable(10000, label)
command(:set_auths, user, label) visibility_admin.set_auths(user, label)
# verifying put functionality # verifying put functionality
@test_table.put(1, "x:a", 31, {VISIBILITY=>label}) @test_table.put(1, "x:a", 31, {VISIBILITY=>label})

View File

@ -63,6 +63,6 @@ class ShellFormatterTest < Test::Unit::TestCase
end end
define_test "Froematter#footer should work" do define_test "Froematter#footer should work" do
formatter.footer() formatter.footer(Time.now - 5)
end end
end end

Some files were not shown because too many files have changed in this diff Show More