HBASE-15849 Simplify the way we handle runtime of commands.

Functions format_simple_command and format_and_return_simple_command are used to print runtimes right now. They are called from within every single command and use Ruby's 'yield' magic.  Instead, we can simplify it using 'command_safe' function. Since command_safe wraps all commands, we can simply time before and after we call individual command.
If a command only wants to time a part of its logic, it can set instance variables start_time and end_time accordingly which is far more simpler to understand and work with than 'yield'.

Change-Id: Ibfacf3593175af22fc4f7d80896dd2f6d7c5dde3
This commit is contained in:
Apekshit Sharma 2016-06-03 14:13:45 -07:00
parent de1b5ff776
commit 70762faa98
95 changed files with 177 additions and 353 deletions

View File

@ -81,8 +81,9 @@ module Shell
self.interactive = interactive
end
def hbase_admin
@hbase_admin ||= hbase.admin()
# Returns Admin class from admin.rb
def admin
@admin ||= hbase.admin()
end
def hbase_taskmonitor
@ -143,7 +144,7 @@ module Shell
# method_name - name of the method on the command to call. Defaults to just 'command'
# args - to be passed to the named method
def internal_command(command, method_name= :command, *args)
command_instance(command).command_safe(self.debug,method_name, *args)
command_instance(command).command_safe(self.debug, method_name, *args)
end
def print_banner

View File

@ -29,9 +29,12 @@ module Shell
# cmd - command name to execute
# args - arguments to pass to the command
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
#(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) }
rescue => e
rootCause = e
while rootCause != nil && rootCause.respond_to?(:cause) && rootCause.cause != nil
@ -48,13 +51,16 @@ module Shell
else
raise rootCause
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
# Convenience functions to get different admins
# Returns HBase::Admin ruby class.
def admin
@shell.hbase_admin
@shell.admin
end
def taskmonitor
@ -91,21 +97,6 @@ module Shell
@formatter ||= ::Shell::Formatter::Console.new
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)
yield
rescue => e

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,14 +35,14 @@ t to table 't1', the corresponding command would be:
EOF
end
def command(table, row, column, value, args={})
append(table(table), row, column, value, args)
def command(table_name, row, column, value, args={})
table = table(table_name)
@start_time = Time.now
append(table, row, column, value, args)
end
def append(table, row, column, value, args={})
format_simple_command do
table._append_internal(row, column, value, args)
end
table._append_internal(row, column, value, args)
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,9 +32,7 @@ EOF
end
def command(snapshot_name, table)
format_simple_command do
admin.clone_snapshot(snapshot_name, table)
end
admin.clone_snapshot(snapshot_name, table)
end
def handle_exceptions(cause, *args)

View File

@ -51,9 +51,7 @@ EOF
end
def command(region_name, server = nil)
format_simple_command do
admin.close_region(region_name, server)
end
admin.close_region(region_name, server)
end
end
end

View File

@ -44,9 +44,7 @@ module Shell
end
def command(table_or_region_name, family = nil, type = "NORMAL")
format_simple_command do
admin.compact(table_or_region_name, family, type)
end
admin.compact(table_or_region_name, family, type)
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

@ -40,16 +40,15 @@ t to table 't1', the corresponding command would be:
EOF
end
def command(table, row, column,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
def command(table, row, column,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
delete(table(table), row, column, timestamp, args)
end
def delete(table, row, column,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
format_simple_command do
table._delete_internal(row, column, timestamp, args)
end
def delete(table, row, column,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
@start_time = Time.now
table._delete_internal(row, column, timestamp, args)
end
end
end

View File

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

View File

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

View File

@ -51,16 +51,15 @@ 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
return unless answer =~ /y.*/i
format_simple_command do
list.each do |deleteSnapshot|
begin
admin.delete_snapshot(deleteSnapshot.getName)
puts "Successfully deleted snapshot: #{deleteSnapshot.getName}"
puts "\n"
rescue RuntimeError
puts "Failed to delete snapshot: #{deleteSnapshot.getName}, due to below exception,\n" + $!
puts "\n"
end
@start_time = Time.now
list.each do |deleteSnapshot|
begin
admin.delete_snapshot(deleteSnapshot.getName)
puts "Successfully deleted snapshot: #{deleteSnapshot.getName}"
puts "\n"
rescue RuntimeError
puts "Failed to delete snapshot: #{deleteSnapshot.getName}, due to below exception,\n" + $!
puts "\n"
end
end
end

View File

@ -48,9 +48,8 @@ EOF
def deleteall(table, row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
format_simple_command do
table._deleteall_internal(row, column, timestamp, args)
end
@start_time = Time.now
table._deleteall_internal(row, column, timestamp, args)
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -49,13 +49,11 @@ EOF
end
def incr(table, row, column, value = nil, args={})
format_simple_command do
if cnt = table._incr_internal(row, column, value, args)
puts "COUNTER VALUE = #{cnt}"
else
puts "No counter found at specified coordinates"
end
end
if cnt = table._incr_internal(row, column, value, args)
puts "COUNTER VALUE = #{cnt}"
else
puts "No counter found at specified coordinates"
end
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,16 +25,14 @@ module Shell
end
def command
format_simple_command do
peer_configs = replication_admin.list_peer_configs
unless peer_configs.nil?
peer_configs.each do |peer_config_entry|
peer_id = peer_config_entry[0]
peer_config = peer_config_entry[1]
formatter.row(["PeerId", peer_id])
GetPeerConfig.new(@shell).format_peer_config(peer_config)
formatter.row([" "])
end
peer_configs = replication_admin.list_peer_configs
unless peer_configs.nil?
peer_configs.each do |peer_config_entry|
peer_id = peer_config_entry[0]
peer_config = peer_config_entry[1]
formatter.row(["PeerId", peer_id])
GetPeerConfig.new(@shell).format_peer_config(peer_config)
formatter.row([" "])
end
end
end

View File

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

View File

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

View File

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

View File

@ -31,8 +31,6 @@ EOF
end
def command(regex = ".*")
now = Time.now
formatter.header([ "TABLE:COLUMNFAMILY", "ReplicationType" ], [ 32 ])
list = replication_admin.list_replicated_tables(regex)
list.each do |e|
@ -43,7 +41,7 @@ EOF
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])
end
formatter.footer(now)
formatter.footer()
end
end
end

View File

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

View File

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

View File

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

View File

@ -44,9 +44,7 @@ module Shell
end
def command(table_or_region_name, family = nil, type = "NORMAL")
format_simple_command do
admin.major_compact(table_or_region_name, family, type)
end
admin.majorCompact(table_or_region_name, family, type)
end
end
end

View File

@ -40,9 +40,7 @@ EOF
end
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)
end
admin.merge_region(encoded_region_a_name, encoded_region_b_name, force)
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

@ -45,9 +45,8 @@ EOF
end
def put(table, row, column, value, timestamp = nil, args = {})
format_simple_command do
table._put_internal(row, column, value, timestamp, args)
end
@start_time = Time.now
table._put_internal(row, column, value, timestamp, args)
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,9 +41,7 @@ module Shell
end
def command(id, peer_table_cfs = nil)
format_simple_command do
replication_admin.set_peer_tableCFs(id, peer_table_cfs)
end
replication_admin.set_peer_tableCFs(id, peer_table_cfs)
end
end
end

View File

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

View File

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

View File

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

View File

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

View File

@ -30,11 +30,9 @@ EOF
end
def command(switch_type)
format_simple_command do
formatter.row(
[admin.splitormerge_enabled(switch_type) ? 'true' : 'false']
)
end
formatter.row(
[admin.splitormerge_enabled(switch_type) ? 'true' : 'false']
)
end
end
end

View File

@ -32,11 +32,9 @@ EOF
end
def command(switch_type, enabled)
format_simple_command do
formatter.row(
[admin.splitormerge_switch(switch_type, enabled) ? 'true' : 'false']
)
end
formatter.row(
[admin.splitormerge_switch(switch_type, enabled) ? 'true' : 'false']
)
end
end
end

View File

@ -48,9 +48,7 @@ EOF
end
def command(startstop="status", spanname="HBaseShell")
format_and_return_simple_command do
trace(startstop, spanname)
end
trace(startstop, spanname)
end
def trace(startstop, spanname)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,12 +26,12 @@ class ShellTest < Test::Unit::TestCase
@shell = Shell::Shell.new(@hbase)
end
define_test "Shell::Shell#hbase_admin should return an admin instance" do
assert_kind_of(Hbase::Admin, @shell.hbase_admin)
define_test "Shell::Shell#admin should return an admin instance" do
assert_kind_of(Hbase::Admin, @shell.admin)
end
define_test "Shell::Shell#hbase_admin should cache admin instances" do
assert_same(@shell.hbase_admin, @shell.hbase_admin)
define_test "Shell::Shell#admin should cache admin instances" do
assert_same(@shell.admin, @shell.admin)
end
#-------------------------------------------------------------------------------
@ -44,6 +44,10 @@ class ShellTest < Test::Unit::TestCase
assert_not_same(@shell.hbase_table('hbase:meta'), @shell.hbase_table('hbase:meta'))
end
define_test "Shell::Shell#hbase attribute is a HBase instance" do
assert_kind_of(Hbase::Hbase, @shell.hbase)
end
#-------------------------------------------------------------------------------
define_test "Shell::Shell#export_commands should export command methods to specified object" do

View File

@ -55,7 +55,7 @@ module Hbase
end
def admin
@shell.hbase_admin
@shell.admin
end
def taskmonitor