HBASE-18239 rubocop autocorrect for shell

Signed-off-by: Michael Stack <stack@apache.org>
This commit is contained in:
Mike Drob 2017-06-20 15:24:29 -05:00 committed by Michael Stack
parent 90fee695b4
commit 2115d4b50e
140 changed files with 1448 additions and 1526 deletions

File diff suppressed because it is too large Load Diff

View File

@ -39,22 +39,22 @@ module Hbase
else
self.configuration = HBaseConfiguration.create
# Turn off retries in hbase and ipc. Human doesn't want to wait on N retries.
configuration.setInt("hbase.client.retries.number", 7)
configuration.setInt("hbase.ipc.client.connect.max.retries", 3)
configuration.setInt('hbase.client.retries.number', 7)
configuration.setInt('hbase.ipc.client.connect.max.retries', 3)
end
@connection = ConnectionFactory.createConnection(self.configuration)
@connection = ConnectionFactory.createConnection(configuration)
end
# Returns ruby's Admin class from admin.rb
def admin()
def admin
::Hbase::Admin.new(@connection)
end
def rsgroup_admin()
def rsgroup_admin
::Hbase::RSGroupAdmin.new(@connection)
end
def taskmonitor()
def taskmonitor
::Hbase::TaskMonitor.new(configuration)
end
@ -63,19 +63,19 @@ module Hbase
::Hbase::Table.new(@connection.getTable(TableName.valueOf(table)), shell)
end
def replication_admin()
def replication_admin
::Hbase::RepAdmin.new(configuration)
end
def security_admin()
def security_admin
::Hbase::SecurityAdmin.new(@connection.getAdmin)
end
def visibility_labels_admin()
def visibility_labels_admin
::Hbase::VisibilityLabelsAdmin.new(@connection.getAdmin)
end
def quotas_admin()
def quotas_admin
::Hbase::QuotasAdmin.new(@connection.getAdmin)
end

View File

@ -30,18 +30,18 @@ java_import org.apache.hadoop.hbase.quotas.SpaceViolationPolicy
module HBaseQuotasConstants
# RPC Quota constants
GLOBAL_BYPASS = 'GLOBAL_BYPASS'
THROTTLE_TYPE = 'THROTTLE_TYPE'
THROTTLE = 'THROTTLE'
REQUEST = 'REQUEST'
WRITE = 'WRITE'
READ = 'READ'
GLOBAL_BYPASS = 'GLOBAL_BYPASS'.freeze
THROTTLE_TYPE = 'THROTTLE_TYPE'.freeze
THROTTLE = 'THROTTLE'.freeze
REQUEST = 'REQUEST'.freeze
WRITE = 'WRITE'.freeze
READ = 'READ'.freeze
# Space quota constants
SPACE = 'SPACE'
NO_INSERTS = 'NO_INSERTS'
NO_WRITES = 'NO_WRITES'
NO_WRITES_COMPACTIONS = 'NO_WRITES_COMPACTIONS'
DISABLE = 'DISABLE'
SPACE = 'SPACE'.freeze
NO_INSERTS = 'NO_INSERTS'.freeze
NO_WRITES = 'NO_WRITES'.freeze
NO_WRITES_COMPACTIONS = 'NO_WRITES_COMPACTIONS'.freeze
DISABLE = 'DISABLE'.freeze
end
module Hbase
@ -55,88 +55,88 @@ module Hbase
end
def throttle(args)
raise(ArgumentError, "Arguments should be a Hash") unless args.kind_of?(Hash)
raise(ArgumentError, 'Arguments should be a Hash') unless args.is_a?(Hash)
type = args.fetch(THROTTLE_TYPE, REQUEST)
args.delete(THROTTLE_TYPE)
type, limit, time_unit = _parse_limit(args.delete(LIMIT), ThrottleType, type)
if args.has_key?(USER)
if args.key?(USER)
user = args.delete(USER)
if args.has_key?(TABLE)
if args.key?(TABLE)
table = TableName.valueOf(args.delete(TABLE))
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.throttleUser(user, table, type, limit, time_unit)
elsif args.has_key?(NAMESPACE)
elsif args.key?(NAMESPACE)
namespace = args.delete(NAMESPACE)
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.throttleUser(user, namespace, type, limit, time_unit)
else
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.throttleUser(user, type, limit, time_unit)
end
elsif args.has_key?(TABLE)
elsif args.key?(TABLE)
table = TableName.valueOf(args.delete(TABLE))
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.throttleTable(table, type, limit, time_unit)
elsif args.has_key?(NAMESPACE)
elsif args.key?(NAMESPACE)
namespace = args.delete(NAMESPACE)
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.throttleNamespace(namespace, type, limit, time_unit)
else
raise "One of USER, TABLE or NAMESPACE must be specified"
raise 'One of USER, TABLE or NAMESPACE must be specified'
end
@admin.setQuota(settings)
end
def unthrottle(args)
raise(ArgumentError, "Arguments should be a Hash") unless args.kind_of?(Hash)
if args.has_key?(USER)
raise(ArgumentError, 'Arguments should be a Hash') unless args.is_a?(Hash)
if args.key?(USER)
user = args.delete(USER)
if args.has_key?(TABLE)
if args.key?(TABLE)
table = TableName.valueOf(args.delete(TABLE))
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.unthrottleUser(user, table)
elsif args.has_key?(NAMESPACE)
elsif args.key?(NAMESPACE)
namespace = args.delete(NAMESPACE)
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.unthrottleUser(user, namespace)
else
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.unthrottleUser(user)
end
elsif args.has_key?(TABLE)
elsif args.key?(TABLE)
table = TableName.valueOf(args.delete(TABLE))
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.unthrottleTable(table)
elsif args.has_key?(NAMESPACE)
elsif args.key?(NAMESPACE)
namespace = args.delete(NAMESPACE)
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.unthrottleNamespace(namespace)
else
raise "One of USER, TABLE or NAMESPACE must be specified"
raise 'One of USER, TABLE or NAMESPACE must be specified'
end
@admin.setQuota(settings)
end
def limit_space(args)
raise(ArgumentError, 'Argument should be a Hash') unless (not args.nil? and args.kind_of?(Hash))
raise(ArgumentError, 'Argument should be a Hash') unless !args.nil? && args.is_a?(Hash)
# Let the user provide a raw number
if args[LIMIT].is_a?(Numeric)
limit = args[LIMIT]
limit = if args[LIMIT].is_a?(Numeric)
args[LIMIT]
else
# Parse a string a 1K, 2G, etc.
limit = _parse_size(args[LIMIT])
_parse_size(args[LIMIT])
end
# Extract the policy, failing if something bogus was provided
policy = SpaceViolationPolicy.valueOf(args[POLICY])
# Create a table or namespace quota
if args.key?(TABLE)
if args.key?(NAMESPACE)
raise(ArgumentError, "Only one of TABLE or NAMESPACE can be specified.")
raise(ArgumentError, 'Only one of TABLE or NAMESPACE can be specified.')
end
settings = QuotaSettingsFactory.limitTableSpace(TableName.valueOf(args.delete(TABLE)), limit, policy)
elsif args.key?(NAMESPACE)
if args.key?(TABLE)
raise(ArgumentError, "Only one of TABLE or NAMESPACE can be specified.")
raise(ArgumentError, 'Only one of TABLE or NAMESPACE can be specified.')
end
settings = QuotaSettingsFactory.limitNamespaceSpace(args.delete(NAMESPACE), limit, policy)
else
@ -147,16 +147,16 @@ module Hbase
end
def remove_space_limit(args)
raise(ArgumentError, 'Argument should be a Hash') unless (not args.nil? and args.kind_of?(Hash))
raise(ArgumentError, 'Argument should be a Hash') unless !args.nil? && args.is_a?(Hash)
if args.key?(TABLE)
if args.key?(NAMESPACE)
raise(ArgumentError, "Only one of TABLE or NAMESPACE can be specified.")
raise(ArgumentError, 'Only one of TABLE or NAMESPACE can be specified.')
end
table = TableName.valueOf(args.delete(TABLE))
settings = QuotaSettingsFactory.removeTableSpaceLimit(table)
elsif args.key?(NAMESPACE)
if args.key?(TABLE)
raise(ArgumentError, "Only one of TABLE or NAMESPACE can be specified.")
raise(ArgumentError, 'Only one of TABLE or NAMESPACE can be specified.')
end
settings = QuotaSettingsFactory.removeNamespaceSpaceLimit(args.delete(NAMESPACE))
else
@ -165,8 +165,8 @@ module Hbase
@admin.setQuota(settings)
end
def get_master_table_sizes()
QuotaTableUtil.getMasterReportedTableSizes(@admin.getConnection())
def get_master_table_sizes
QuotaTableUtil.getMasterReportedTableSizes(@admin.getConnection)
end
def get_quota_snapshots(regionserver = nil)
@ -176,41 +176,41 @@ module Hbase
get_quota_snapshots_from_table
end
def get_quota_snapshots_from_table()
def get_quota_snapshots_from_table
# Reads the snapshots from the hbase:quota table
QuotaTableUtil.getSnapshots(@admin.getConnection())
QuotaTableUtil.getSnapshots(@admin.getConnection)
end
def get_rs_quota_snapshots(rs)
# Reads the snapshots from a specific regionserver
QuotaTableUtil.getRegionServerQuotaSnapshots(@admin.getConnection(),
QuotaTableUtil.getRegionServerQuotaSnapshots(@admin.getConnection,
ServerName.valueOf(rs))
end
def set_global_bypass(bypass, args)
raise(ArgumentError, "Arguments should be a Hash") unless args.kind_of?(Hash)
raise(ArgumentError, 'Arguments should be a Hash') unless args.is_a?(Hash)
if args.has_key?(USER)
if args.key?(USER)
user = args.delete(USER)
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
settings = QuotaSettingsFactory.bypassGlobals(user, bypass)
else
raise "Expected USER"
raise 'Expected USER'
end
@admin.setQuota(settings)
end
def list_quotas(args = {})
raise(ArgumentError, "Arguments should be a Hash") unless args.kind_of?(Hash)
raise(ArgumentError, 'Arguments should be a Hash') unless args.is_a?(Hash)
limit = args.delete("LIMIT") || -1
limit = args.delete('LIMIT') || -1
count = 0
filter = QuotaFilter.new()
filter.setUserFilter(args.delete(USER)) if args.has_key?(USER)
filter.setTableFilter(args.delete(TABLE)) if args.has_key?(TABLE)
filter.setNamespaceFilter(args.delete(NAMESPACE)) if args.has_key?(NAMESPACE)
raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty?
filter = QuotaFilter.new
filter.setUserFilter(args.delete(USER)) if args.key?(USER)
filter.setTableFilter(args.delete(TABLE)) if args.key?(TABLE)
filter.setNamespaceFilter(args.delete(NAMESPACE)) if args.key?(NAMESPACE)
raise(ArgumentError, 'Unexpected arguments: ' + args.inspect) unless args.empty?
# Start the scanner
scanner = @admin.getQuotaRetriever(filter)
@ -219,30 +219,28 @@ module Hbase
# Iterate results
while iter.hasNext
if limit > 0 && count >= limit
break
end
break if limit > 0 && count >= limit
settings = iter.next
owner = {
USER => settings.getUserName(),
TABLE => settings.getTableName(),
NAMESPACE => settings.getNamespace(),
}.delete_if { |k, v| v.nil? }.map {|k, v| k.to_s + " => " + v.to_s} * ', '
USER => settings.getUserName,
TABLE => settings.getTableName,
NAMESPACE => settings.getNamespace
}.delete_if { |_k, v| v.nil? }.map { |k, v| k.to_s + ' => ' + v.to_s } * ', '
yield owner, settings.to_s
count += 1
end
ensure
scanner.close()
scanner.close
end
return count
count
end
def list_snapshot_sizes()
QuotaTableUtil.getObservedSnapshotSizes(@admin.getConnection())
def list_snapshot_sizes
QuotaTableUtil.getObservedSnapshotSizes(@admin.getConnection)
end
def _parse_size(str_limit)
@ -255,7 +253,7 @@ module Hbase
return _size_from_str(match[1].to_i, match[2])
end
else
raise(ArgumentError, "Invalid size limit syntax")
raise(ArgumentError, 'Invalid size limit syntax')
end
end
@ -265,14 +263,14 @@ module Hbase
if match
if match[2] == 'req'
limit = match[1].to_i
type = type_cls.valueOf(type + "_NUMBER")
type = type_cls.valueOf(type + '_NUMBER')
else
limit = _size_from_str(match[1].to_i, match[2])
type = type_cls.valueOf(type + "_SIZE")
type = type_cls.valueOf(type + '_SIZE')
end
if limit <= 0
raise(ArgumentError, "Invalid throttle limit, must be greater then 0")
raise(ArgumentError, 'Invalid throttle limit, must be greater then 0')
end
case match[3]
@ -284,7 +282,7 @@ module Hbase
return type, limit, time_unit
else
raise(ArgumentError, "Invalid throttle limit syntax")
raise(ArgumentError, 'Invalid throttle limit syntax')
end
end
@ -296,7 +294,7 @@ module Hbase
when 't' then value <<= 40
when 'p' then value <<= 50
end
return value
value
end
end
end

View File

@ -43,7 +43,7 @@ module Hbase
def add_peer(id, args = {}, peer_tableCFs = nil)
if args.is_a?(Hash)
unless peer_tableCFs.nil?
raise(ArgumentError, "peer_tableCFs should be specified as TABLE_CFS in args")
raise(ArgumentError, 'peer_tableCFs should be specified as TABLE_CFS in args')
end
endpoint_classname = args.fetch(ENDPOINT_CLASSNAME, nil)
@ -51,12 +51,12 @@ module Hbase
# Handle cases where custom replication endpoint and cluster key are either both provided
# or neither are provided
if endpoint_classname.nil? and cluster_key.nil?
raise(ArgumentError, "Either ENDPOINT_CLASSNAME or CLUSTER_KEY must be specified.")
if endpoint_classname.nil? && cluster_key.nil?
raise(ArgumentError, 'Either ENDPOINT_CLASSNAME or CLUSTER_KEY must be specified.')
end
# Cluster Key is required for ReplicationPeerConfig for a custom replication endpoint
if !endpoint_classname.nil? and cluster_key.nil?
if !endpoint_classname.nil? && cluster_key.nil?
cluster_key = ZKConfig.getZooKeeperClusterKey(@configuration)
end
@ -81,9 +81,9 @@ module Hbase
unless data.nil?
# Convert Strings to Bytes for peer_data
peer_data = replication_peer_config.get_peer_data
data.each{|key, val|
data.each do |key, val|
peer_data.put(Bytes.to_bytes(key), Bytes.to_bytes(val))
}
end
end
unless namespaces.nil?
@ -97,14 +97,14 @@ module Hbase
unless table_cfs.nil?
# convert table_cfs to TableName
map = java.util.HashMap.new
table_cfs.each{|key, val|
table_cfs.each do |key, val|
map.put(org.apache.hadoop.hbase.TableName.valueOf(key), val)
}
end
replication_peer_config.set_table_cfs_map(map)
end
@admin.addReplicationPeer(id, replication_peer_config)
else
raise(ArgumentError, "args must be a Hash")
raise(ArgumentError, 'args must be a Hash')
end
end
@ -116,10 +116,10 @@ module Hbase
#---------------------------------------------------------------------------------------------
# Show replcated tables/column families, and their ReplicationType
def list_replicated_tables(regex = ".*")
def list_replicated_tables(regex = '.*')
pattern = java.util.regex.Pattern.compile(regex)
list = @admin.listReplicatedTableCFs()
list.select {|t| pattern.match(t.getTable().getNameAsString())}
list = @admin.listReplicatedTableCFs
list.select { |t| pattern.match(t.getTable.getNameAsString) }
end
#----------------------------------------------------------------------------------------------
@ -144,7 +144,7 @@ module Hbase
# Show the current tableCFs config for the specified peer
def show_peer_tableCFs(id)
rpc = @admin.getReplicationPeerConfig(id)
ReplicationSerDeHelper.convertToString(rpc.getTableCFsMap())
ReplicationSerDeHelper.convertToString(rpc.getTableCFsMap)
end
#----------------------------------------------------------------------------------------------
@ -153,9 +153,9 @@ module Hbase
unless tableCFs.nil?
# convert tableCFs to TableName
map = java.util.HashMap.new
tableCFs.each{|key, val|
tableCFs.each do |key, val|
map.put(org.apache.hadoop.hbase.TableName.valueOf(key), val)
}
end
rpc = get_peer_config(id)
unless rpc.nil?
rpc.setTableCFsMap(map)
@ -170,9 +170,9 @@ module Hbase
unless tableCFs.nil?
# convert tableCFs to TableName
map = java.util.HashMap.new
tableCFs.each{|key, val|
tableCFs.each do |key, val|
map.put(org.apache.hadoop.hbase.TableName.valueOf(key), val)
}
end
end
@admin.appendReplicationPeerTableCFs(id, map)
end
@ -183,9 +183,9 @@ module Hbase
unless tableCFs.nil?
# convert tableCFs to TableName
map = java.util.HashMap.new
tableCFs.each{|key, val|
tableCFs.each do |key, val|
map.put(org.apache.hadoop.hbase.TableName.valueOf(key), val)
}
end
end
@admin.removeReplicationPeerTableCFs(id, map)
end
@ -210,10 +210,8 @@ module Hbase
unless namespaces.nil?
rpc = get_peer_config(id)
unless rpc.nil?
ns_set = rpc.getNamespaces()
if ns_set.nil?
ns_set = java.util.HashSet.new
end
ns_set = rpc.getNamespaces
ns_set = java.util.HashSet.new if ns_set.nil?
namespaces.each do |n|
ns_set.add(n)
end
@ -228,7 +226,7 @@ module Hbase
unless namespaces.nil?
rpc = get_peer_config(id)
unless rpc.nil?
ns_set = rpc.getNamespaces()
ns_set = rpc.getNamespaces
unless ns_set.nil?
namespaces.each do |n|
ns_set.remove(n)
@ -281,7 +279,7 @@ module Hbase
peers.each do |peer|
map.put(peer.getPeerId, peer.getPeerConfig)
end
return map
map
end
def get_peer_config(id)
@ -302,9 +300,9 @@ module Hbase
unless data.nil?
# Convert Strings to Bytes for peer_data
peer_data = replication_peer_config.get_peer_data
data.each{|key, val|
data.each do |key, val|
peer_data.put(Bytes.to_bytes(key), Bytes.to_bytes(val))
}
end
end
@admin.updateReplicationPeerConfig(id, replication_peer_config)

View File

@ -36,21 +36,17 @@ module Hbase
#--------------------------------------------------------------------------
# Returns a list of groups in hbase
def list_rs_groups
@admin.listRSGroups.map { |g| g.getName }
@admin.listRSGroups.map(&:getName)
end
#--------------------------------------------------------------------------
# get a group's information
def get_rsgroup(group_name)
group = @admin.getRSGroupInfo(group_name)
if group.nil?
raise(ArgumentError, 'Group does not exist: ' + group_name)
end
raise(ArgumentError, 'Group does not exist: ' + group_name) if group.nil?
res = {}
if block_given?
yield('Servers:')
end
yield('Servers:') if block_given?
servers = []
group.getServers.each do |v|
@ -63,9 +59,7 @@ module Hbase
res[:servers] = servers
tables = []
if block_given?
yield('Tables:')
end
yield('Tables:') if block_given?
group.getTables.each do |v|
if block_given?
yield(v.toString)
@ -75,11 +69,7 @@ module Hbase
end
res[:tables] = tables
if !block_given?
res
else
nil
end
res unless block_given?
end
#--------------------------------------------------------------------------
@ -113,7 +103,7 @@ module Hbase
#--------------------------------------------------------------------------
# move server to a group
def move_tables(dest, *args)
tables = java.util.HashSet.new;
tables = java.util.HashSet.new
args[0].each do |s|
tables.add(org.apache.hadoop.hbase.TableName.valueOf(s))
end
@ -124,10 +114,9 @@ module Hbase
# get group of server
def get_rsgroup_of_server(server)
res = @admin.getRSGroupOfServer(
org.apache.hadoop.hbase.net.Address.fromString(server))
if res.nil?
raise(ArgumentError,'Server has no group: ' + server)
end
org.apache.hadoop.hbase.net.Address.fromString(server)
)
raise(ArgumentError, 'Server has no group: ' + server) if res.nil?
res
end
@ -135,10 +124,9 @@ module Hbase
# get group of table
def get_rsgroup_of_table(table)
res = @admin.getRSGroupInfoOfTable(
org.apache.hadoop.hbase.TableName.valueOf(table))
if res.nil?
raise(ArgumentError,'Table has no group: ' + table)
end
org.apache.hadoop.hbase.TableName.valueOf(table)
)
raise(ArgumentError, 'Table has no group: ' + table) if res.nil?
res
end
@ -146,7 +134,7 @@ module Hbase
# move server and table to a group
def move_servers_tables(dest, *args)
servers = java.util.HashSet.new
tables = java.util.HashSet.new;
tables = java.util.HashSet.new
args[0].each do |s|
servers.add(org.apache.hadoop.hbase.net.Address.fromString(s))
end
@ -155,6 +143,5 @@ module Hbase
end
@admin.moveServersAndTables(servers, tables, dest)
end
end
end

View File

@ -26,7 +26,7 @@ module Hbase
def initialize(admin)
@admin = admin
@connection = @admin.getConnection()
@connection = @admin.getConnection
end
def close
@ -41,24 +41,26 @@ module Hbase
begin
# Verify that the specified permission is valid
if (permissions == nil || permissions.length == 0)
raise(ArgumentError, "Invalid permission: no actions associated with user")
if permissions.nil? || permissions.empty?
raise(ArgumentError, 'Invalid permission: no actions associated with user')
end
perm = org.apache.hadoop.hbase.security.access.Permission.new(
permissions.to_java_bytes)
permissions.to_java_bytes
)
if (table_name != nil)
if !table_name.nil?
tablebytes = table_name.to_java_bytes
# check if the tablename passed is actually a namespace
if (isNamespace?(table_name))
if isNamespace?(table_name)
# Namespace should exist first.
namespace_name = table_name[1...table_name.length]
raise(ArgumentError, "Can't find a namespace: #{namespace_name}") unless
namespace_exists?(namespace_name)
org.apache.hadoop.hbase.security.access.AccessControlClient.grant(
@connection, namespace_name, user, perm.getActions())
@connection, namespace_name, user, perm.getActions
)
else
# Table should exist
raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)
@ -66,20 +68,22 @@ module Hbase
tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name)
htd = @admin.getTableDescriptor(tableName)
if (family != nil)
unless family.nil?
raise(ArgumentError, "Can't find a family: #{family}") unless htd.hasFamily(family.to_java_bytes)
end
fambytes = family.to_java_bytes if (family != nil)
qualbytes = qualifier.to_java_bytes if (qualifier != nil)
fambytes = family.to_java_bytes unless family.nil?
qualbytes = qualifier.to_java_bytes unless qualifier.nil?
org.apache.hadoop.hbase.security.access.AccessControlClient.grant(
@connection, tableName, user, fambytes, qualbytes, perm.getActions())
@connection, tableName, user, fambytes, qualbytes, perm.getActions
)
end
else
# invoke cp endpoint to perform access controls
org.apache.hadoop.hbase.security.access.AccessControlClient.grant(
@connection, user, perm.getActions())
@connection, user, perm.getActions
)
end
end
end
@ -91,16 +95,17 @@ module Hbase
# TODO: need to validate user name
begin
if (table_name != nil)
if !table_name.nil?
# check if the tablename passed is actually a namespace
if (isNamespace?(table_name))
if isNamespace?(table_name)
# Namespace should exist first.
namespace_name = table_name[1...table_name.length]
raise(ArgumentError, "Can't find a namespace: #{namespace_name}") unless namespace_exists?(namespace_name)
tablebytes = table_name.to_java_bytes
org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(
@connection, namespace_name, user)
@connection, namespace_name, user
)
else
# Table should exist
raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)
@ -108,20 +113,22 @@ module Hbase
tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name)
htd = @admin.getTableDescriptor(tableName)
if (family != nil)
unless family.nil?
raise(ArgumentError, "Can't find a family: #{family}") unless htd.hasFamily(family.to_java_bytes)
end
fambytes = family.to_java_bytes if (family != nil)
qualbytes = qualifier.to_java_bytes if (qualifier != nil)
fambytes = family.to_java_bytes unless family.nil?
qualbytes = qualifier.to_java_bytes unless qualifier.nil?
org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(
@connection, tableName, user, fambytes, qualbytes)
@connection, tableName, user, fambytes, qualbytes
)
end
else
perm = org.apache.hadoop.hbase.security.access.Permission.new(''.to_java_bytes)
org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(
@connection, user, perm.getActions())
@connection, user, perm.getActions
)
end
end
end
@ -130,28 +137,29 @@ module Hbase
def user_permission(table_regex = nil)
security_available?
all_perms = org.apache.hadoop.hbase.security.access.AccessControlClient.getUserPermissions(
@connection,table_regex)
@connection, table_regex
)
res = {}
count = 0
all_perms.each do |value|
user_name = String.from_java_bytes(value.getUser)
if (table_regex != nil && isNamespace?(table_regex))
namespace = value.getNamespace()
if !table_regex.nil? && isNamespace?(table_regex)
namespace = value.getNamespace
else
namespace = (value.getTableName != nil) ? value.getTableName.getNamespaceAsString() : value.getNamespace()
namespace = !value.getTableName.nil? ? value.getTableName.getNamespaceAsString : value.getNamespace
end
table = (value.getTableName != nil) ? value.getTableName.getNameAsString() : ''
family = (value.getFamily != nil) ?
org.apache.hadoop.hbase.util.Bytes::toStringBinary(value.getFamily) :
table = !value.getTableName.nil? ? value.getTableName.getNameAsString : ''
family = !value.getFamily.nil? ?
org.apache.hadoop.hbase.util.Bytes.toStringBinary(value.getFamily) :
''
qualifier = (value.getQualifier != nil) ?
org.apache.hadoop.hbase.util.Bytes::toStringBinary(value.getQualifier) :
qualifier = !value.getQualifier.nil? ?
org.apache.hadoop.hbase.util.Bytes.toStringBinary(value.getQualifier) :
''
action = org.apache.hadoop.hbase.security.access.Permission.new value.getActions
if block_given?
yield(user_name, "#{namespace},#{table},#{family},#{qualifier}: #{action.to_s}")
yield(user_name, "#{namespace},#{table},#{family},#{qualifier}: #{action}")
else
res[user_name] ||= {}
res[user_name]["#{family}:#{qualifier}"] = action
@ -159,7 +167,7 @@ module Hbase
count += 1
end
return ((block_given?) ? count : res)
(block_given? ? count : res)
end
# Does table exist?
@ -173,13 +181,13 @@ module Hbase
# Does Namespace exist
def namespace_exists?(namespace_name)
return @admin.getNamespaceDescriptor(namespace_name) != nil
return !@admin.getNamespaceDescriptor(namespace_name).nil?
rescue org.apache.hadoop.hbase.NamespaceNotFoundException => e
return false
end
# Make sure that security features are available
def security_available?()
def security_available?
caps = []
begin
# Try the getSecurityCapabilities API where supported.
@ -189,11 +197,11 @@ module Hbase
rescue
# If we are unable to use getSecurityCapabilities, fall back with a check for
# deployment of the ACL table
raise(ArgumentError, "DISABLED: Security features are not available") unless \
raise(ArgumentError, 'DISABLED: Security features are not available') unless \
exists?(org.apache.hadoop.hbase.security.access.AccessControlLists::ACL_TABLE_NAME)
return
end
raise(ArgumentError, "DISABLED: Security features are not available") unless \
raise(ArgumentError, 'DISABLED: Security features are not available') unless \
caps.include? org.apache.hadoop.hbase.client.security.SecurityCapability::AUTHORIZATION
end
end

View File

@ -32,7 +32,7 @@ module Hbase
#
# e.g. name = scan, adds table.scan which calls Scan.scan
def self.add_shell_command(name)
self.add_command(name, name, name)
add_command(name, name, name)
end
# add a named command to the table instance
@ -43,7 +43,7 @@ module Hbase
# internal_method_name - name of the method in the shell command to forward the call
def self.add_command(name, shell_command, internal_method_name)
method = name.to_sym
self.class_eval do
class_eval do
define_method method do |*args|
@shell.internal_command(shell_command, internal_method_name, self, *args)
end
@ -53,7 +53,7 @@ module Hbase
# General help for the table
# class level so we can call it from anywhere
def self.help
return <<-EOF
<<-EOF
Help for table-reference commands.
You can either create a table via 'create' and then manipulate the table via commands like 'put', 'get', etc.
@ -113,13 +113,13 @@ EOF
def initialize(table, shell)
@table = table
@name = @table.getName().getNameAsString()
@name = @table.getName.getNameAsString
@shell = shell
@converters = Hash.new()
@converters = {}
end
def close()
@table.close()
def close
@table.close
end
# Note the below methods are prefixed with '_' to hide them from the average user, as
@ -139,13 +139,13 @@ EOF
set_op_ttl(p, ttl) if ttl
end
# Case where attributes are specified without timestamp
if timestamp.kind_of?(Hash)
if timestamp.is_a?(Hash)
timestamp.each do |k, v|
if k == 'ATTRIBUTES'
set_attributes(p, v)
elsif k == 'VISIBILITY'
set_cell_visibility(p, v)
elsif k == "TTL"
elsif k == 'TTL'
set_op_ttl(p, v)
end
end
@ -164,13 +164,13 @@ EOF
def _createdelete_internal(row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
temptimestamp = timestamp
if temptimestamp.kind_of?(Hash)
if temptimestamp.is_a?(Hash)
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP
end
d = org.apache.hadoop.hbase.client.Delete.new(row.to_s.to_java_bytes, timestamp)
if temptimestamp.kind_of?(Hash)
temptimestamp.each do |k, v|
if v.kind_of?(String)
if temptimestamp.is_a?(Hash)
temptimestamp.each do |_k, v|
if v.is_a?(String)
set_cell_visibility(d, v) if v
end
end
@ -183,15 +183,15 @@ EOF
family, qualifier = parse_column_name(column)
d.addColumns(family, qualifier, timestamp)
end
return d
d
end
#----------------------------------------------------------------------------------------------
# Delete rows using prefix
def _deleterows_internal(row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
cache = row["CACHE"] ? row["CACHE"] : 100
prefix = row["ROWPREFIXFILTER"]
cache = row['CACHE'] ? row['CACHE'] : 100
prefix = row['ROWPREFIXFILTER']
# create scan to get table names using prefix
scan = org.apache.hadoop.hbase.client.Scan.new
@ -204,7 +204,7 @@ EOF
iter = scanner.iterator
while iter.hasNext
row = iter.next
key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow)
key = org.apache.hadoop.hbase.util.Bytes.toStringBinary(row.getRow)
d = _createdelete_internal(key, column, timestamp, args)
list.add(d)
if list.size >= cache
@ -229,9 +229,9 @@ EOF
# delete operation doesn't need read permission. Retaining the read check for
# meta table as a part of HBASE-5837.
if is_meta_table?
raise ArgumentError, "Row Not Found" if _get_internal(row).nil?
raise ArgumentError, 'Row Not Found' if _get_internal(row).nil?
end
if row.kind_of?(Hash)
if row.is_a?(Hash)
_deleterows_internal(row, column, timestamp, args)
else
d = _createdelete_internal(row, column, timestamp, args)
@ -242,14 +242,12 @@ EOF
#----------------------------------------------------------------------------------------------
# Increment a counter atomically
def _incr_internal(row, column, value = nil, args = {})
if value.kind_of?(Hash)
value = 1
end
value = 1 if value.is_a?(Hash)
value ||= 1
incr = org.apache.hadoop.hbase.client.Increment.new(row.to_s.to_java_bytes)
family, qualifier = parse_column_name(column)
if qualifier.nil?
raise ArgumentError, "Failed to provide both column family and column qualifier for incr"
raise ArgumentError, 'Failed to provide both column family and column qualifier for incr'
end
if args.any?
attributes = args[ATTRIBUTES]
@ -265,7 +263,7 @@ EOF
# Fetch cell value
cell = result.listCells[0]
org.apache.hadoop.hbase.util.Bytes::toLong(cell.getValueArray,
org.apache.hadoop.hbase.util.Bytes.toLong(cell.getValueArray,
cell.getValueOffset, cell.getValueLength)
end
@ -275,7 +273,7 @@ EOF
append = org.apache.hadoop.hbase.client.Append.new(row.to_s.to_java_bytes)
family, qualifier = parse_column_name(column)
if qualifier.nil?
raise ArgumentError, "Failed to provide both column family and column qualifier for append"
raise ArgumentError, 'Failed to provide both column family and column qualifier for append'
end
if args.any?
attributes = args[ATTRIBUTES]
@ -291,31 +289,30 @@ EOF
# Fetch cell value
cell = result.listCells[0]
org.apache.hadoop.hbase.util.Bytes::toStringBinary(cell.getValueArray,
org.apache.hadoop.hbase.util.Bytes.toStringBinary(cell.getValueArray,
cell.getValueOffset, cell.getValueLength)
end
#----------------------------------------------------------------------------------------------
# Count rows in a table
def _count_internal(interval = 1000, scan = nil)
raise(ArgumentError, "Scan argument should be org.apache.hadoop.hbase.client.Scan") \
unless scan == nil || scan.kind_of?(org.apache.hadoop.hbase.client.Scan)
raise(ArgumentError, 'Scan argument should be org.apache.hadoop.hbase.client.Scan') \
unless scan.nil? || scan.is_a?(org.apache.hadoop.hbase.client.Scan)
# We can safely set scanner caching with the first key only filter
if scan == nil
if scan.nil?
scan = org.apache.hadoop.hbase.client.Scan.new
scan.setCacheBlocks(false)
scan.setCaching(10)
scan.setFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter.new)
else
scan.setCacheBlocks(false)
filter = scan.getFilter()
filter = scan.getFilter
firstKeyOnlyFilter = org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter.new
if filter == nil
if filter.nil?
scan.setFilter(firstKeyOnlyFilter)
else
firstKeyOnlyFilter.setReversed(filter.isReversed())
firstKeyOnlyFilter.setReversed(filter.isReversed)
scan.setFilter(org.apache.hadoop.hbase.filter.FilterList.new(filter, firstKeyOnlyFilter))
end
end
@ -329,15 +326,15 @@ EOF
while iter.hasNext
row = iter.next
count += 1
next unless (block_given? && count % interval == 0)
next unless block_given? && count % interval == 0
# Allow command modules to visualize counting process
yield(count,
org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow))
org.apache.hadoop.hbase.util.Bytes.toStringBinary(row.getRow))
end
scanner.close()
scanner.close
# Return the counter
return count
count
end
#----------------------------------------------------------------------------------------------
@ -346,11 +343,11 @@ EOF
get = org.apache.hadoop.hbase.client.Get.new(row.to_s.to_java_bytes)
maxlength = -1
count = 0
@converters.clear()
@converters.clear
# Normalize args
args = args.first if args.first.kind_of?(Hash)
if args.kind_of?(String) || args.kind_of?(Array)
args = args.first if args.first.is_a?(Hash)
if args.is_a?(String) || args.is_a?(Array)
columns = [args].flatten.compact
args = { COLUMNS => columns }
end
@ -358,7 +355,7 @@ EOF
#
# Parse arguments
#
unless args.kind_of?(Hash)
unless args.is_a?(Hash)
raise ArgumentError, "Failed parse of #{args.inspect}, #{args.class}"
end
@ -373,17 +370,17 @@ EOF
converter_class = args.delete(FORMATTER_CLASS) || 'org.apache.hadoop.hbase.util.Bytes'
unless args.empty?
columns = args[COLUMN] || args[COLUMNS]
if args[VERSIONS]
vers = args[VERSIONS]
vers = if args[VERSIONS]
args[VERSIONS]
else
vers = 1
1
end
if columns
# Normalize types, convert string to an array of strings
columns = [columns] if columns.is_a?(String)
# At this point it is either an array or some unsupported stuff
unless columns.kind_of?(Array)
unless columns.is_a?(Array)
raise ArgumentError, "Failed parse column argument type #{args.inspect}, #{args.class}"
end
@ -422,11 +419,12 @@ EOF
set_authorizations(get, authorizations) if authorizations
end
unless filter.class == String
get.setFilter(filter)
else
if filter.class == String
get.setFilter(
org.apache.hadoop.hbase.filter.ParseFilter.new.parseFilterString(filter.to_java_bytes))
org.apache.hadoop.hbase.filter.ParseFilter.new.parseFilterString(filter.to_java_bytes)
)
else
get.setFilter(filter)
end
get.setConsistency(org.apache.hadoop.hbase.client.Consistency.valueOf(consistency)) if consistency
@ -459,7 +457,7 @@ EOF
end
# If block given, we've yielded all the results, otherwise just return them
return ((block_given?) ? [count, is_stale]: res)
(block_given? ? [count, is_stale] : res)
end
#----------------------------------------------------------------------------------------------
@ -477,35 +475,35 @@ EOF
# Fetch cell value
cell = result.listCells[0]
org.apache.hadoop.hbase.util.Bytes::toLong(cell.getValueArray,
org.apache.hadoop.hbase.util.Bytes.toLong(cell.getValueArray,
cell.getValueOffset, cell.getValueLength)
end
def _hash_to_scan(args)
if args.any?
enablemetrics = args["ALL_METRICS"].nil? ? false : args["ALL_METRICS"]
enablemetrics = enablemetrics || !args["METRICS"].nil?
filter = args["FILTER"]
startrow = args["STARTROW"] || ''
stoprow = args["STOPROW"]
rowprefixfilter = args["ROWPREFIXFILTER"]
timestamp = args["TIMESTAMP"]
columns = args["COLUMNS"] || args["COLUMN"] || []
enablemetrics = args['ALL_METRICS'].nil? ? false : args['ALL_METRICS']
enablemetrics ||= !args['METRICS'].nil?
filter = args['FILTER']
startrow = args['STARTROW'] || ''
stoprow = args['STOPROW']
rowprefixfilter = args['ROWPREFIXFILTER']
timestamp = args['TIMESTAMP']
columns = args['COLUMNS'] || args['COLUMN'] || []
# If CACHE_BLOCKS not set, then default 'true'.
cache_blocks = args["CACHE_BLOCKS"].nil? ? true: args["CACHE_BLOCKS"]
cache = args["CACHE"] || 0
reversed = args["REVERSED"] || false
versions = args["VERSIONS"] || 1
cache_blocks = args['CACHE_BLOCKS'].nil? ? true : args['CACHE_BLOCKS']
cache = args['CACHE'] || 0
reversed = args['REVERSED'] || false
versions = args['VERSIONS'] || 1
timerange = args[TIMERANGE]
raw = args["RAW"] || false
raw = args['RAW'] || false
attributes = args[ATTRIBUTES]
authorizations = args[AUTHORIZATIONS]
consistency = args[CONSISTENCY]
# Normalize column names
columns = [columns] if columns.class == String
limit = args["LIMIT"] || -1
unless columns.kind_of?(Array)
raise ArgumentError.new("COLUMNS must be specified as a String or an Array")
limit = args['LIMIT'] || -1
unless columns.is_a?(Array)
raise ArgumentError, 'COLUMNS must be specified as a String or an Array'
end
scan = if stoprow
@ -518,7 +516,7 @@ EOF
scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter
# Clear converters from last scan.
@converters.clear()
@converters.clear
columns.each do |c|
family, qualifier = parse_column_name(c.to_s)
@ -529,11 +527,12 @@ EOF
end
end
unless filter.class == String
scan.setFilter(filter)
else
if filter.class == String
scan.setFilter(
org.apache.hadoop.hbase.filter.ParseFilter.new.parseFilterString(filter.to_java_bytes))
org.apache.hadoop.hbase.filter.ParseFilter.new.parseFilterString(filter.to_java_bytes)
)
else
scan.setFilter(filter)
end
scan.setScanMetricsEnabled(enablemetrics) if enablemetrics
@ -562,19 +561,19 @@ EOF
#----------------------------------------------------------------------------------------------
# Scans whole table or a range of keys and returns rows matching specific criteria
def _scan_internal(args = {}, scan = nil)
raise(ArgumentError, "Args should be a Hash") unless args.kind_of?(Hash)
raise(ArgumentError, "Scan argument should be org.apache.hadoop.hbase.client.Scan") \
unless scan == nil || scan.kind_of?(org.apache.hadoop.hbase.client.Scan)
raise(ArgumentError, 'Args should be a Hash') unless args.is_a?(Hash)
raise(ArgumentError, 'Scan argument should be org.apache.hadoop.hbase.client.Scan') \
unless scan.nil? || scan.is_a?(org.apache.hadoop.hbase.client.Scan)
limit = args["LIMIT"] || -1
maxlength = args.delete("MAXLENGTH") || -1
limit = args['LIMIT'] || -1
maxlength = args.delete('MAXLENGTH') || -1
converter = args.delete(FORMATTER) || nil
converter_class = args.delete(FORMATTER_CLASS) || 'org.apache.hadoop.hbase.util.Bytes'
count = 0
res = {}
# Start the scanner
scan = scan == nil ? _hash_to_scan(args) : scan
scan = scan.nil? ? _hash_to_scan(args) : scan
scanner = @table.getScanner(scan)
iter = scanner.iterator
@ -609,13 +608,13 @@ EOF
end
end
scanner.close()
return ((block_given?) ? [count, is_stale] : res)
scanner.close
(block_given? ? [count, is_stale] : res)
end
# Apply OperationAttributes to puts/scans/gets
def set_attributes(oprattr, attributes)
raise(ArgumentError, "Attributes must be a Hash type") unless attributes.kind_of?(Hash)
raise(ArgumentError, 'Attributes must be a Hash type') unless attributes.is_a?(Hash)
for k, v in attributes
v = v.to_s unless v.nil?
oprattr.setAttribute(k.to_s, v.to_java_bytes)
@ -623,11 +622,12 @@ EOF
end
def set_cell_permissions(op, permissions)
raise(ArgumentError, "Permissions must be a Hash type") unless permissions.kind_of?(Hash)
raise(ArgumentError, 'Permissions must be a Hash type') unless permissions.is_a?(Hash)
map = java.util.HashMap.new
permissions.each do |user, perms|
map.put(user.to_s, org.apache.hadoop.hbase.security.access.Permission.new(
perms.to_java_bytes))
perms.to_java_bytes
))
end
op.setACL(map)
end
@ -635,15 +635,19 @@ EOF
def set_cell_visibility(oprattr, visibility)
oprattr.setCellVisibility(
org.apache.hadoop.hbase.security.visibility.CellVisibility.new(
visibility.to_s))
visibility.to_s
)
)
end
def set_authorizations(oprattr, authorizations)
raise(ArgumentError, "Authorizations must be a Array type") unless authorizations.kind_of?(Array)
raise(ArgumentError, 'Authorizations must be a Array type') unless authorizations.is_a?(Array)
auths = [authorizations].flatten.compact
oprattr.setAuthorizations(
org.apache.hadoop.hbase.security.visibility.Authorizations.new(
auths.to_java(:string)))
auths.to_java(:string)
)
)
end
def set_op_ttl(op, ttl)
@ -680,13 +684,13 @@ EOF
return nil
end
end
return @shell.help('table_help')
@shell.help('table_help')
end
# Table to string
def to_s
cl = self.class()
return "#{cl} - #{@name}"
cl = self.class
"#{cl} - #{@name}"
end
# Standard ruby call to get the return value for an object
@ -707,24 +711,24 @@ EOF
# Checks if current table is one of the 'meta' tables
def is_meta_table?
org.apache.hadoop.hbase.TableName::META_TABLE_NAME.equals(@table.getName())
org.apache.hadoop.hbase.TableName::META_TABLE_NAME.equals(@table.getName)
end
# Returns family and (when has it) qualifier for a column name
def parse_column_name(column)
split = org.apache.hadoop.hbase.KeyValue.parseColumn(column.to_java_bytes)
set_converter(split) if split.length > 1
return split[0], (split.length > 1) ? split[1] : nil
[split[0], split.length > 1 ? split[1] : nil]
end
# Make a String of the passed kv
# Intercept cells whose format we know such as the info:regioninfo in hbase:meta
def to_string(column, kv, maxlength = -1, converter_class = nil, converter = nil)
if is_meta_table?
if column == 'info:regioninfo' or column == 'info:splitA' or column == 'info:splitB'
if column == 'info:regioninfo' || column == 'info:splitA' || column == 'info:splitB'
hri = org.apache.hadoop.hbase.HRegionInfo.parseFromOrNull(kv.getValueArray,
kv.getValueOffset, kv.getValueLength)
return "timestamp=%d, value=%s" % [kv.getTimestamp, hri.toString]
return format('timestamp=%d, value=%s', kv.getTimestamp, hri.toString)
end
if column == 'info:serverstartcode'
if kv.getValueLength > 0
@ -734,16 +738,16 @@ EOF
str_val = org.apache.hadoop.hbase.util.Bytes.toStringBinary(kv.getValueArray,
kv.getValueOffset, kv.getValueLength)
end
return "timestamp=%d, value=%s" % [kv.getTimestamp, str_val]
return format('timestamp=%d, value=%s', kv.getTimestamp, str_val)
end
end
if kv.isDelete
val = "timestamp=#{kv.getTimestamp}, type=#{org.apache.hadoop.hbase.KeyValue::Type::codeToType(kv.getType)}"
val = "timestamp=#{kv.getTimestamp}, type=#{org.apache.hadoop.hbase.KeyValue::Type.codeToType(kv.getType)}"
else
val = "timestamp=#{kv.getTimestamp}, value=#{convert(column, kv, converter_class, converter)}"
end
(maxlength != -1) ? val[0, maxlength] : val
maxlength != -1 ? val[0, maxlength] : val
end
def convert(column, kv, converter_class = 'org.apache.hadoop.hbase.util.Bytes', converter = 'toStringBinary')
@ -751,7 +755,7 @@ EOF
converter_class = 'org.apache.hadoop.hbase.util.Bytes' unless converter_class
# use org.apache.hadoop.hbase.util.Bytes::toStringBinary as the default convertor
converter = 'toStringBinary' unless converter
if @converters.has_key?(column)
if @converters.key?(column)
# lookup the CONVERTER for certain column - "cf:qualifier"
matches = /c\((.+)\)\.(.+)/.match(@converters[column])
if matches.nil?
@ -792,14 +796,14 @@ EOF
#----------------------------------------------------------------------------------------------
# Get the split points for the table
def _get_splits_internal()
locator = @table.getRegionLocator()
splits = locator.getAllRegionLocations().
map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}.delete_if{|k| k == ""}
locator.close()
puts("Total number of splits = %s" % [splits.size + 1])
def _get_splits_internal
locator = @table.getRegionLocator
splits = locator.getAllRegionLocations
.map { |i| Bytes.toStringBinary(i.getRegionInfo.getStartKey) }.delete_if { |k| k == '' }
locator.close
puts(format('Total number of splits = %s', splits.size + 1))
puts splits
return splits
splits
end
end
end

View File

@ -21,8 +21,8 @@
include Java
# Add the $HBASE_HOME/lib directory to the ruby load_path to load jackson
if File.exists?(File.join(File.dirname(__FILE__), "..", "lib"))
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
if File.exist?(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
end
module Hbase
@ -32,34 +32,29 @@ module Hbase
#---------------------------------------------------------------------------------------------
# Represents information reported by a server on a single MonitoredTask
class Task
def initialize(taskMap, host)
taskMap.each_pair do |k, v|
case k
when "statustimems"
when 'statustimems'
@statustime = Time.at(v / 1000)
when "status"
when 'status'
@status = v
when "starttimems"
when 'starttimems'
@starttime = Time.at(v / 1000)
when "description"
when 'description'
@description = v
when "state"
when 'state'
@state = v
end
end
@host = host
end
def statustime
# waiting IPC handlers often have statustime = -1, in this case return starttime
if @statustime > Time.at(-1)
return @statustime
end
return @starttime
return @statustime if @statustime > Time.at(-1)
@starttime
end
attr_reader :host
@ -67,24 +62,21 @@ module Hbase
attr_reader :starttime
attr_reader :description
attr_reader :state
end
def initialize(configuration)
@conf = configuration
@conn = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(@conf)
@admin = @conn.getAdmin()
@admin = @conn.getAdmin
end
#---------------------------------------------------------------------------------------------------
# Returns a filtered list of tasks on the given host
def tasksOnHost(filter, host)
java_import 'java.net.URL'
java_import 'org.codehaus.jackson.map.ObjectMapper'
infoport = @admin.getClusterStatus().getLoad(host).getInfoServerPort().to_s
infoport = @admin.getClusterStatus.getLoad(host).getInfoServerPort.to_s
# Note: This condition use constants from hbase-server
# if (!@admin.getConfiguration().getBoolean(org.apache.hadoop.hbase.http.ServerConfigurationKeys::HBASE_SSL_ENABLED_KEY,
@ -93,8 +85,8 @@ module Hbase
# else
# schema = "https://"
# end
schema = "http://"
url = schema + host.hostname + ":" + infoport + "/rs-status?format=json&filter=" + filter
schema = 'http://'
url = schema + host.hostname + ':' + infoport + '/rs-status?format=json&filter=' + filter
json = URL.new(url)
mapper = ObjectMapper.new
@ -103,29 +95,27 @@ module Hbase
tasksArrayList = mapper.readValue(json, java.lang.Object.java_class)
# convert to an array of TaskMonitor::Task instances
tasks = Array.new
tasks = []
tasksArrayList.each do |t|
tasks.unshift Task.new(t, host)
end
return tasks
tasks
end
#---------------------------------------------------------------------------------------------------
# Prints a table of filtered tasks on requested hosts
def tasks(filter, hosts)
# put all tasks on all requested hosts in the same list
tasks = []
hosts.each do |host|
tasks.concat(tasksOnHost(filter, host))
end
puts("%d tasks as of: %s" % [tasks.size,Time.now.strftime("%Y-%m-%d %H:%M:%S")])
puts(format('%d tasks as of: %s', tasks.size, Time.now.strftime('%Y-%m-%d %H:%M:%S')))
if tasks.size() == 0
puts("No " + filter + " tasks currently running.")
if tasks.empty?
puts('No ' + filter + ' tasks currently running.')
else
# determine table width
@ -143,44 +133,40 @@ module Hbase
descriptionWidth = [32, longestDescriptionWidth].min
statusWidth = [36, longestStatusWidth + 27].min
rowSeparator = "+" + "-" * (hostWidth + 2) +
"+" + "-" * (startTimeWidth + 2) +
"+" + "-" * (stateWidth + 2) +
"+" + "-" * (descriptionWidth + 2) +
"+" + "-" * (statusWidth + 2) + "+"
rowSeparator = '+' + '-' * (hostWidth + 2) +
'+' + '-' * (startTimeWidth + 2) +
'+' + '-' * (stateWidth + 2) +
'+' + '-' * (descriptionWidth + 2) +
'+' + '-' * (statusWidth + 2) + '+'
# print table header
cells = [setCellWidth("Host",hostWidth),
setCellWidth("Start Time",startTimeWidth),
setCellWidth("State",stateWidth),
setCellWidth("Description",descriptionWidth),
setCellWidth("Status",statusWidth)]
cells = [setCellWidth('Host', hostWidth),
setCellWidth('Start Time', startTimeWidth),
setCellWidth('State', stateWidth),
setCellWidth('Description', descriptionWidth),
setCellWidth('Status', statusWidth)]
line = "| %s | %s | %s | %s | %s |" % cells
line = format('| %s | %s | %s | %s | %s |', cells)
puts(rowSeparator)
puts(line)
# print table content
tasks.each do |t|
cells = [setCellWidth(t.host.hostname, hostWidth),
setCellWidth(t.starttime.strftime("%Y-%m-%d %H:%M:%S"),startTimeWidth),
setCellWidth(t.starttime.strftime('%Y-%m-%d %H:%M:%S'), startTimeWidth),
setCellWidth(t.state, stateWidth),
setCellWidth(t.description, descriptionWidth),
setCellWidth("%s (since %d seconds ago)" %
[t.status,Time.now - t.statustime], statusWidth)]
setCellWidth(format('%s (since %d seconds ago)', t.status, Time.now - t.statustime), statusWidth)]
line = "| %s | %s | %s | %s | %s |" % cells
line = format('| %s | %s | %s | %s | %s |', cells)
puts(rowSeparator)
puts(line)
end
puts(rowSeparator)
end
end
#---------------------------------------------------------------------------------------------------
@ -193,12 +179,11 @@ module Hbase
numCharsTooShort = width - cellContent.length
if numCharsTooShort < 0
# cellContent is too long, so truncate
return cellContent[0,[width-3,0].max] + "." * [3,width].min
return cellContent[0, [width - 3, 0].max] + '.' * [3, width].min
else
# cellContent is requested width or too short, so right-pad with zero or more spaces
return cellContent + " " * numCharsTooShort
return cellContent + ' ' * numCharsTooShort
end
end
end
end

View File

@ -23,10 +23,9 @@ java_import org.apache.hadoop.hbase.util.Bytes
module Hbase
class VisibilityLabelsAdmin
def initialize(admin)
@admin = admin
@connection = @admin.getConnection()
@connection = @admin.getConnection
end
def close
@ -36,53 +35,43 @@ module Hbase
def add_labels(*args)
visibility_feature_available?
# Normalize args
if args.kind_of?(Array)
labels = [ args ].flatten.compact
end
if labels.size() == 0
raise(ArgumentError, "Arguments cannot be null")
end
labels = [args].flatten.compact if args.is_a?(Array)
raise(ArgumentError, 'Arguments cannot be null') if labels.empty?
begin
response = VisibilityClient.addLabels(@connection, labels.to_java(:string))
if response.nil?
raise(ArgumentError, "DISABLED: Visibility labels feature is not available")
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available')
end
labelsWithException = ""
list = response.getResultList()
labelsWithException = ''
list = response.getResultList
list.each do |result|
if result.hasException()
labelsWithException += Bytes.toString(result.getException().getValue().toByteArray())
if result.hasException
labelsWithException += Bytes.toString(result.getException.getValue.toByteArray)
end
end
if labelsWithException.length > 0
raise(ArgumentError, labelsWithException)
end
raise(ArgumentError, labelsWithException) unless labelsWithException.empty?
end
end
def set_auths(user, *args)
visibility_feature_available?
# Normalize args
if args.kind_of?(Array)
auths = [ args ].flatten.compact
end
auths = [args].flatten.compact if args.is_a?(Array)
begin
response = VisibilityClient.setAuths(@connection, auths.to_java(:string), user)
if response.nil?
raise(ArgumentError, "DISABLED: Visibility labels feature is not available")
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available')
end
labelsWithException = ""
list = response.getResultList()
labelsWithException = ''
list = response.getResultList
list.each do |result|
if result.hasException()
labelsWithException += Bytes.toString(result.getException().getValue().toByteArray())
if result.hasException
labelsWithException += Bytes.toString(result.getException.getValue.toByteArray)
end
end
if labelsWithException.length > 0
raise(ArgumentError, labelsWithException)
end
raise(ArgumentError, labelsWithException) unless labelsWithException.empty?
end
end
@ -91,18 +80,18 @@ module Hbase
begin
response = VisibilityClient.getAuths(@connection, user)
if response.nil?
raise(ArgumentError, "DISABLED: Visibility labels feature is not available")
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available')
end
return response.getAuthList
end
end
def list_labels(regex = ".*")
def list_labels(regex = '.*')
visibility_feature_available?
begin
response = VisibilityClient.listLabels(@connection, regex)
if response.nil?
raise(ArgumentError, "DISABLED: Visibility labels feature is not available")
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available')
end
return response.getLabelList
end
@ -111,30 +100,26 @@ module Hbase
def clear_auths(user, *args)
visibility_feature_available?
# Normalize args
if args.kind_of?(Array)
auths = [ args ].flatten.compact
end
auths = [args].flatten.compact if args.is_a?(Array)
begin
response = VisibilityClient.clearAuths(@connection, auths.to_java(:string), user)
if response.nil?
raise(ArgumentError, "DISABLED: Visibility labels feature is not available")
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available')
end
labelsWithException = ""
list = response.getResultList()
labelsWithException = ''
list = response.getResultList
list.each do |result|
if result.hasException()
labelsWithException += Bytes.toString(result.getException().getValue().toByteArray())
if result.hasException
labelsWithException += Bytes.toString(result.getException.getValue.toByteArray)
end
end
if labelsWithException.length > 0
raise(ArgumentError, labelsWithException)
end
raise(ArgumentError, labelsWithException) unless labelsWithException.empty?
end
end
# Make sure that lables table is available
def visibility_feature_available?()
def visibility_feature_available?
caps = []
begin
# Try the getSecurityCapabilities API where supported.
@ -142,11 +127,11 @@ module Hbase
rescue
# If we are unable to use getSecurityCapabilities, fall back with a check for
# deployment of the labels table
raise(ArgumentError, "DISABLED: Visibility labels feature is not available") unless \
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available') unless \
exists?(VisibilityConstants::LABELS_TABLE_NAME)
return
end
raise(ArgumentError, "DISABLED: Visibility labels feature is not available") unless \
raise(ArgumentError, 'DISABLED: Visibility labels feature is not available') unless \
caps.include? org.apache.hadoop.hbase.client.security.SecurityCapability::CELL_VISIBILITY
end

View File

@ -32,62 +32,62 @@ java_import('java.lang.Long') { |_package, name| "J#{name}" }
java_import('java.lang.Boolean') { |_package, name| "J#{name}" }
module HBaseConstants
COLUMN = "COLUMN"
COLUMNS = "COLUMNS"
TIMESTAMP = "TIMESTAMP"
TIMERANGE = "TIMERANGE"
COLUMN = 'COLUMN'.freeze
COLUMNS = 'COLUMNS'.freeze
TIMESTAMP = 'TIMESTAMP'.freeze
TIMERANGE = 'TIMERANGE'.freeze
NAME = org.apache.hadoop.hbase.HConstants::NAME
VERSIONS = org.apache.hadoop.hbase.HConstants::VERSIONS
IN_MEMORY = org.apache.hadoop.hbase.HConstants::IN_MEMORY
IN_MEMORY_COMPACTION = org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY_COMPACTION
METADATA = org.apache.hadoop.hbase.HConstants::METADATA
STOPROW = "STOPROW"
STARTROW = "STARTROW"
ROWPREFIXFILTER = "ROWPREFIXFILTER"
STOPROW = 'STOPROW'.freeze
STARTROW = 'STARTROW'.freeze
ROWPREFIXFILTER = 'ROWPREFIXFILTER'.freeze
ENDROW = STOPROW
RAW = "RAW"
LIMIT = "LIMIT"
METHOD = "METHOD"
MAXLENGTH = "MAXLENGTH"
CACHE_BLOCKS = "CACHE_BLOCKS"
ALL_METRICS = "ALL_METRICS"
METRICS = "METRICS"
REVERSED = "REVERSED"
REPLICATION_SCOPE = "REPLICATION_SCOPE"
INTERVAL = 'INTERVAL'
CACHE = 'CACHE'
FILTER = 'FILTER'
SPLITS = 'SPLITS'
SPLITS_FILE = 'SPLITS_FILE'
SPLITALGO = 'SPLITALGO'
NUMREGIONS = 'NUMREGIONS'
REGION_REPLICATION = 'REGION_REPLICATION'
REGION_REPLICA_ID = 'REGION_REPLICA_ID'
RAW = 'RAW'.freeze
LIMIT = 'LIMIT'.freeze
METHOD = 'METHOD'.freeze
MAXLENGTH = 'MAXLENGTH'.freeze
CACHE_BLOCKS = 'CACHE_BLOCKS'.freeze
ALL_METRICS = 'ALL_METRICS'.freeze
METRICS = 'METRICS'.freeze
REVERSED = 'REVERSED'.freeze
REPLICATION_SCOPE = 'REPLICATION_SCOPE'.freeze
INTERVAL = 'INTERVAL'.freeze
CACHE = 'CACHE'.freeze
FILTER = 'FILTER'.freeze
SPLITS = 'SPLITS'.freeze
SPLITS_FILE = 'SPLITS_FILE'.freeze
SPLITALGO = 'SPLITALGO'.freeze
NUMREGIONS = 'NUMREGIONS'.freeze
REGION_REPLICATION = 'REGION_REPLICATION'.freeze
REGION_REPLICA_ID = 'REGION_REPLICA_ID'.freeze
CONFIGURATION = org.apache.hadoop.hbase.HConstants::CONFIGURATION
ATTRIBUTES="ATTRIBUTES"
VISIBILITY="VISIBILITY"
AUTHORIZATIONS = "AUTHORIZATIONS"
SKIP_FLUSH = 'SKIP_FLUSH'
CONSISTENCY = "CONSISTENCY"
USER = 'USER'
TABLE = 'TABLE'
NAMESPACE = 'NAMESPACE'
TYPE = 'TYPE'
NONE = 'NONE'
VALUE = 'VALUE'
ENDPOINT_CLASSNAME = 'ENDPOINT_CLASSNAME'
CLUSTER_KEY = 'CLUSTER_KEY'
TABLE_CFS = 'TABLE_CFS'
NAMESPACES = 'NAMESPACES'
CONFIG = 'CONFIG'
DATA = 'DATA'
SERVER_NAME = 'SERVER_NAME'
LOCALITY_THRESHOLD = 'LOCALITY_THRESHOLD'
RESTORE_ACL = 'RESTORE_ACL'
FORMATTER = 'FORMATTER'
FORMATTER_CLASS = 'FORMATTER_CLASS'
POLICY = 'POLICY'
REGIONSERVER = 'REGIONSERVER'
ATTRIBUTES = 'ATTRIBUTES'.freeze
VISIBILITY = 'VISIBILITY'.freeze
AUTHORIZATIONS = 'AUTHORIZATIONS'.freeze
SKIP_FLUSH = 'SKIP_FLUSH'.freeze
CONSISTENCY = 'CONSISTENCY'.freeze
USER = 'USER'.freeze
TABLE = 'TABLE'.freeze
NAMESPACE = 'NAMESPACE'.freeze
TYPE = 'TYPE'.freeze
NONE = 'NONE'.freeze
VALUE = 'VALUE'.freeze
ENDPOINT_CLASSNAME = 'ENDPOINT_CLASSNAME'.freeze
CLUSTER_KEY = 'CLUSTER_KEY'.freeze
TABLE_CFS = 'TABLE_CFS'.freeze
NAMESPACES = 'NAMESPACES'.freeze
CONFIG = 'CONFIG'.freeze
DATA = 'DATA'.freeze
SERVER_NAME = 'SERVER_NAME'.freeze
LOCALITY_THRESHOLD = 'LOCALITY_THRESHOLD'.freeze
RESTORE_ACL = 'RESTORE_ACL'.freeze
FORMATTER = 'FORMATTER'.freeze
FORMATTER_CLASS = 'FORMATTER_CLASS'.freeze
POLICY = 'POLICY'.freeze
REGIONSERVER = 'REGIONSERVER'.freeze
# Load constants from hbase java API
def self.promote_constants(constants)

View File

@ -32,28 +32,25 @@ module IRB
# down in IRB didn't seem to work. I think the worst thing that can
# happen is the shell exiting because of failed IRB construction with
# no error (though we're not blanking STDERR)
begin
# Map the '/dev/null' according to the runing platform
# Under Windows platform the 'dev/null' is not fully compliant with unix,
# and the 'NUL' object need to be use instead.
devnull = "/dev/null"
devnull = "NUL" if WINDOZE
f = File.open(devnull, "w")
devnull = '/dev/null'
devnull = 'NUL' if WINDOZE
f = File.open(devnull, 'w')
$stdout = f
super
ensure
f.close()
f.close
$stdout = STDOUT
end
end
def output_value
# Suppress output if last_value is 'nil'
# Otherwise, when user types help, get ugly 'nil'
# after all output.
if @context.last_value != nil
super
end
super unless @context.last_value.nil?
end
end
end

View File

@ -39,7 +39,7 @@ module Shell
# Load command
begin
require "shell/commands/#{name}"
klass_name = name.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } # camelize
klass_name = name.to_s.gsub(/(?:^|_)(.)/) { Regexp.last_match(1).upcase } # camelize
commands[name] = eval("Commands::#{klass_name}")
aliases.each do |an_alias|
commands[an_alias] = commands[name]
@ -53,10 +53,10 @@ module Shell
raise ArgumentError, "No :commands for group #{group}" unless opts[:commands]
command_groups[group] = {
:commands => [],
:command_names => opts[:commands],
:full_name => opts[:full_name] || group,
:comment => opts[:comment]
commands: [],
command_names: opts[:commands],
full_name: opts[:full_name] || group,
comment: opts[:comment]
}
all_aliases = opts[:aliases] || {}
@ -83,11 +83,11 @@ module Shell
# Returns Admin class from admin.rb
def admin
@admin ||= hbase.admin()
@admin ||= hbase.admin
end
def hbase_taskmonitor
@hbase_taskmonitor ||= hbase.taskmonitor()
@hbase_taskmonitor ||= hbase.taskmonitor
end
def hbase_table(name)
@ -95,23 +95,23 @@ module Shell
end
def hbase_replication_admin
@hbase_replication_admin ||= hbase.replication_admin()
@hbase_replication_admin ||= hbase.replication_admin
end
def hbase_security_admin
@hbase_security_admin ||= hbase.security_admin()
@hbase_security_admin ||= hbase.security_admin
end
def hbase_visibility_labels_admin
@hbase_visibility_labels_admin ||= hbase.visibility_labels_admin()
@hbase_visibility_labels_admin ||= hbase.visibility_labels_admin
end
def hbase_quotas_admin
@hbase_quotas_admin ||= hbase.quotas_admin()
@hbase_quotas_admin ||= hbase.quotas_admin
end
def hbase_rsgroup_admin
@rsgroup_admin ||= hbase.rsgroup_admin()
@rsgroup_admin ||= hbase.rsgroup_admin
end
def export_commands(where)
@ -140,7 +140,7 @@ module Shell
# Return value is only useful in non-interactive mode, for e.g. tests.
def command(command, *args)
ret = internal_command(command, :command, *args)
if self.interactive
if interactive
return nil
else
return ret
@ -152,7 +152,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(debug, method_name, *args)
end
def print_banner
@ -168,12 +168,12 @@ module Shell
puts "Command: #{command}"
puts command_instance(command).help
puts
return nil
nil
end
def help_command(command)
puts command_instance(command).help
return nil
nil
end
def help_group(group_name)
@ -185,7 +185,7 @@ module Shell
puts group[:comment]
puts
end
return nil
nil
end
def help(command = nil)
@ -200,22 +200,22 @@ module Shell
puts
puts 'COMMAND GROUPS:'
::Shell.command_groups.each do |name, group|
puts " Group name: " + name
puts " Commands: " + group[:command_names].sort.join(', ')
puts ' Group name: ' + name
puts ' Commands: ' + group[:command_names].sort.join(', ')
puts
end
unless command
puts 'SHELL USAGE:'
help_footer
end
return nil
nil
end
def help_header
return "HBase Shell, version #{org.apache.hadoop.hbase.util.VersionInfo.getVersion()}, " +
"r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision()}, " +
"#{org.apache.hadoop.hbase.util.VersionInfo.getDate()}" + "\n" +
"Type 'help \"COMMAND\"', (e.g. 'help \"get\"' -- the quotes are necessary) for help on a specific command.\n" +
"HBase Shell, version #{org.apache.hadoop.hbase.util.VersionInfo.getVersion}, " \
"r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision}, " \
"#{org.apache.hadoop.hbase.util.VersionInfo.getDate}" + "\n" \
"Type 'help \"COMMAND\"', (e.g. 'help \"get\"' -- the quotes are necessary) for help on a specific command.\n" \
"Commands are grouped. Type 'help \"COMMAND_GROUP\"', (e.g. 'help \"general\"') for help on a command group."
end
@ -253,8 +253,8 @@ require 'shell/commands'
# Load all commands
Shell.load_command_group(
'general',
:full_name => 'GENERAL HBASE SHELL COMMANDS',
:commands => %w[
full_name: 'GENERAL HBASE SHELL COMMANDS',
commands: %w[
status
version
table_help
@ -265,8 +265,8 @@ Shell.load_command_group(
Shell.load_command_group(
'ddl',
:full_name => 'TABLES MANAGEMENT COMMANDS',
:commands => %w[
full_name: 'TABLES MANAGEMENT COMMANDS',
commands: %w[
alter
create
describe
@ -287,15 +287,15 @@ Shell.load_command_group(
locate_region
list_regions
],
:aliases => {
aliases: {
'describe' => ['desc']
}
)
Shell.load_command_group(
'namespace',
:full_name => 'NAMESPACE MANAGEMENT COMMANDS',
:commands => %w[
full_name: 'NAMESPACE MANAGEMENT COMMANDS',
commands: %w[
create_namespace
drop_namespace
alter_namespace
@ -307,8 +307,8 @@ Shell.load_command_group(
Shell.load_command_group(
'dml',
:full_name => 'DATA MANIPULATION COMMANDS',
:commands => %w[
full_name: 'DATA MANIPULATION COMMANDS',
commands: %w[
count
delete
deleteall
@ -326,9 +326,9 @@ Shell.load_command_group(
Shell.load_command_group(
'tools',
:full_name => 'HBASE SURGERY TOOLS',
:comment => "WARNING: Above commands are for 'experts'-only as misuse can damage an install",
:commands => %w[
full_name: 'HBASE SURGERY TOOLS',
comment: "WARNING: Above commands are for 'experts'-only as misuse can damage an install",
commands: %w[
assign
balancer
balance_switch
@ -359,16 +359,16 @@ Shell.load_command_group(
splitormerge_enabled
clear_compaction_queues
],
# TODO remove older hlog_roll command
:aliases => {
# TODO: remove older hlog_roll command
aliases: {
'wal_roll' => ['hlog_roll']
}
)
Shell.load_command_group(
'replication',
:full_name => 'CLUSTER REPLICATION TOOLS',
:commands => %w[
full_name: 'CLUSTER REPLICATION TOOLS',
commands: %w[
add_peer
remove_peer
list_peers
@ -393,8 +393,8 @@ Shell.load_command_group(
Shell.load_command_group(
'snapshots',
:full_name => 'CLUSTER SNAPSHOT TOOLS',
:commands => %w[
full_name: 'CLUSTER SNAPSHOT TOOLS',
commands: %w[
snapshot
clone_snapshot
restore_snapshot
@ -408,8 +408,8 @@ Shell.load_command_group(
Shell.load_command_group(
'configuration',
:full_name => 'ONLINE CONFIGURATION TOOLS',
:commands => %w[
full_name: 'ONLINE CONFIGURATION TOOLS',
commands: %w[
update_config
update_all_config
]
@ -417,8 +417,8 @@ Shell.load_command_group(
Shell.load_command_group(
'quotas',
:full_name => 'CLUSTER QUOTAS TOOLS',
:commands => %w[
full_name: 'CLUSTER QUOTAS TOOLS',
commands: %w[
set_quota
list_quotas
list_quota_table_sizes
@ -429,9 +429,9 @@ Shell.load_command_group(
Shell.load_command_group(
'security',
:full_name => 'SECURITY TOOLS',
:comment => "NOTE: Above commands are only applicable if running with the AccessController coprocessor",
:commands => %w[
full_name: 'SECURITY TOOLS',
comment: 'NOTE: Above commands are only applicable if running with the AccessController coprocessor',
commands: %w[
list_security_capabilities
grant
revoke
@ -441,8 +441,8 @@ Shell.load_command_group(
Shell.load_command_group(
'procedures',
:full_name => 'PROCEDURES & LOCKS MANAGEMENT',
:commands => %w[
full_name: 'PROCEDURES & LOCKS MANAGEMENT',
commands: %w[
abort_procedure
list_procedures
list_locks
@ -451,9 +451,9 @@ Shell.load_command_group(
Shell.load_command_group(
'visibility labels',
:full_name => 'VISIBILITY LABEL TOOLS',
:comment => "NOTE: Above commands are only applicable if running with the VisibilityController coprocessor",
:commands => %w[
full_name: 'VISIBILITY LABEL TOOLS',
comment: 'NOTE: Above commands are only applicable if running with the VisibilityController coprocessor',
commands: %w[
add_labels
list_labels
set_auths
@ -465,10 +465,10 @@ Shell.load_command_group(
Shell.load_command_group(
'rsgroup',
:full_name => 'RSGroups',
:comment => "NOTE: The rsgroup Coprocessor Endpoint must be enabled on the Master else commands fail with:
full_name: 'RSGroups',
comment: "NOTE: The rsgroup Coprocessor Endpoint must be enabled on the Master else commands fail with:
UnknownProtocolException: No registered Master Coprocessor Endpoint found for RSGroupAdminService",
:commands => %w[
commands: %w[
list_rsgroups
get_rsgroup
add_rsgroup

View File

@ -22,7 +22,6 @@ require 'shell/formatter'
module Shell
module Commands
class Command
def initialize(shell)
@shell = shell
end
@ -57,7 +56,7 @@ module Shell
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])
formatter.output_str(format('Took %.4f seconds', @end_time - @start_time))
end
# Convenience functions to get different admins
@ -109,44 +108,40 @@ module Shell
yield
rescue => cause
# let individual command handle exceptions first
if self.respond_to?(:handle_exceptions)
self.handle_exceptions(cause, *args)
end
handle_exceptions(cause, *args) if respond_to?(:handle_exceptions)
# Global HBase exception handling below if not handled by respective command above
if cause.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then
if cause.is_a?(org.apache.hadoop.hbase.TableNotFoundException)
raise "Unknown table #{args.first}!"
end
if cause.kind_of?(org.apache.hadoop.hbase.UnknownRegionException) then
if cause.is_a?(org.apache.hadoop.hbase.UnknownRegionException)
raise "Unknown region #{args.first}!"
end
if cause.kind_of?(org.apache.hadoop.hbase.NamespaceNotFoundException) then
if cause.is_a?(org.apache.hadoop.hbase.NamespaceNotFoundException)
raise "Unknown namespace #{args.first}!"
end
if cause.kind_of?(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException) then
if cause.is_a?(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)
raise "Unknown snapshot #{args.first}!"
end
if cause.kind_of?(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) then
if cause.is_a?(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)
exceptions = cause.getCauses
exceptions.each do |exception|
if exception.kind_of?(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) then
if exception.is_a?(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)
valid_cols = table(args.first).get_all_columns.map { |c| c + '*' }
raise "Unknown column family! Valid column names: #{valid_cols.join(", ")}"
raise "Unknown column family! Valid column names: #{valid_cols.join(', ')}"
end
end
end
if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then
if cause.is_a?(org.apache.hadoop.hbase.TableExistsException)
raise "Table already exists: #{args.first}!"
end
# To be safe, here only AccessDeniedException is considered. In future
# we might support more in more generic approach when possible.
if cause.kind_of?(org.apache.hadoop.hbase.security.AccessDeniedException) then
str = java.lang.String.new("#{cause}")
if cause.is_a?(org.apache.hadoop.hbase.security.AccessDeniedException)
str = java.lang.String.new(cause.to_s)
# Error message is merged with stack trace, reference StringUtils.stringifyException
# This is to parse and get the error message from the whole.
strs = str.split("\n")
if strs.size > 0 then
raise "#{strs[0]}"
end
raise (strs[0]).to_s unless strs.empty?
end
# Throw the other exception which hasn't been handled above

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class AbortProcedure < Command
def help
return <<-EOF
<<-EOF
Given a procedure Id (and optional boolean may_interrupt_if_running parameter,
default is true), abort a procedure in hbase. Use with caution. Some procedures
might not be abortable. For experts only.

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class AddLabels < Command
def help
return <<-EOF
<<-EOF
Add a set of visibility labels.
Syntax : add_labels [label1, label2]

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class AddPeer < Command
def help
return <<-EOF
<<-EOF
A peer can either be another HBase cluster or a custom replication endpoint. In either case an id
must be specified to identify the peer.

View File

@ -22,7 +22,7 @@ module Shell
module Commands
class AddRsgroup < Command
def help
return <<-EOF
<<-EOF
Create a new RegionServer group.
Example:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Alter < Command
def help
return <<-EOF
<<-EOF
Alter a table. Tables can be altered without disabling them first.
Altering enabled tables has caused problems
in the past, so use caution and test it before using in production.

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class AlterAsync < Command
def help
return <<-EOF
<<-EOF
Alter column family schema, does not wait for all regions to receive the
schema changes. Pass table name and a dictionary specifying new column
family schema. Dictionaries are described on the main help command output.

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class AlterNamespace < Command
def help
return <<-EOF
<<-EOF
Alter namespace properties.
To add/modify a property:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class AlterStatus < Command
def help
return <<-EOF
<<-EOF
Get the status of the alter command. Indicates the number of regions of the
table that have received the updated schema
Pass table name.
@ -30,6 +30,7 @@ hbase> alter_status 't1'
hbase> alter_status 'ns1:t1'
EOF
end
def command(table)
admin.alter_status(table)
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Append < Command
def help
return <<-EOF
<<-EOF
Appends a cell 'value' at specified table/row/column coordinates.
hbase> append 't1', 'r1', 'c1', 'value', ATTRIBUTES=>{'mykey'=>'myvalue'}
@ -51,4 +51,4 @@ EOF
end
# add incr comamnd to Table
::Hbase::Table.add_shell_command("append")
::Hbase::Table.add_shell_command('append')

View File

@ -22,7 +22,7 @@ module Shell
module Commands
class AppendPeerNamespaces < Command
def help
return <<-EOF
<<-EOF
Append some namespaces to be replicable for the specified peer.
Set a namespace in the peer config means that all tables in this

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class AppendPeerTableCFs < Command
def help
return <<-EOF
<<-EOF
Append a replicable table-cf config for the specified peer
Examples:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Assign < Command
def help
return <<-EOF
<<-EOF
Assign a region. Use with caution. If region already assigned,
this command will do a force reassign. For experts only.
Examples:

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class BalanceRsgroup < Command
def help
return <<-EOF
<<-EOF
Balance a RegionServer group
Example:
@ -33,7 +33,7 @@ EOF
# Returns true if balancer was run, otherwise false.
ret = rsgroup_admin.balance_rs_group(group_name)
if ret
puts "Ran the balancer."
puts 'Ran the balancer.'
else
puts "Couldn't run the balancer."
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class BalanceSwitch < Command
def help
return <<-EOF
<<-EOF
Enable/Disable balancer. Returns previous balancer state.
Examples:
@ -31,7 +31,7 @@ EOF
end
def command(enableDisable)
prev_state = admin.balance_switch(enableDisable)? "true" : "false"
prev_state = admin.balance_switch(enableDisable) ? 'true' : 'false'
formatter.row(["Previous balancer state : #{prev_state}"])
prev_state
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Balancer < Command
def help
return <<-EOF
<<-EOF
Trigger the cluster balancer. Returns true if balancer ran and was able to
tell the region servers to unassign all the regions to balance (the re-assignment itself is async).
Otherwise false (Will not run if regions in transition).
@ -44,7 +44,7 @@ EOF
elsif !force.nil?
raise ArgumentError, "Invalid argument #{force}."
end
formatter.row([admin.balancer(force_balancer)? "true": "false"])
formatter.row([admin.balancer(force_balancer) ? 'true' : 'false'])
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class BalancerEnabled < Command
def help
return <<-EOF
<<-EOF
Query the balancer's state.
Examples:
@ -29,7 +29,7 @@ Examples:
EOF
end
def command()
def command
state = admin.balancer_enabled?
formatter.row([state.to_s])
state

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class CatalogjanitorEnabled < Command
def help
return <<-EOF
<<-EOF
Query for the CatalogJanitor state (enabled/disabled?)
Examples:
@ -28,8 +28,8 @@ Examples:
EOF
end
def command()
formatter.row([admin.catalogjanitor_enabled()? "true" : "false"])
def command
formatter.row([admin.catalogjanitor_enabled ? 'true' : 'false'])
end
end
end

View File

@ -20,15 +20,16 @@ module Shell
module Commands
class CatalogjanitorRun < Command
def help
return <<-EOF
<<-EOF
Catalog janitor command to run the (garbage collection) scan from command line.
hbase> catalogjanitor_run
EOF
end
def command()
admin.catalogjanitor_run()
def command
admin.catalogjanitor_run
end
end
end

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class CatalogjanitorSwitch < Command
def help
return <<-EOF
<<-EOF
Enable/Disable CatalogJanitor. Returns previous CatalogJanitor state.
Examples:
@ -30,7 +30,7 @@ EOF
end
def command(enableDisable)
formatter.row([admin.catalogjanitor_switch(enableDisable)? "true" : "false"])
formatter.row([admin.catalogjanitor_switch(enableDisable) ? 'true' : 'false'])
end
end
end

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class CleanerChoreEnabled < Command
def help
return <<-EOF
<<-EOF
Query for the Cleaner chore state (enabled/disabled?).
Examples:
@ -28,8 +28,8 @@ Examples:
EOF
end
def command()
formatter.row([admin.cleaner_chore_enabled()? "true" : "false"])
def command
formatter.row([admin.cleaner_chore_enabled ? 'true' : 'false'])
end
end
end

View File

@ -20,15 +20,16 @@ module Shell
module Commands
class CleanerChoreRun < Command
def help
return <<-EOF
<<-EOF
Cleaner chore command for garbage collection of HFiles and WAL files.
hbase> cleaner_chore_run
EOF
end
def command()
admin.cleaner_chore_run()
def command
admin.cleaner_chore_run
end
end
end

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class CleanerChoreSwitch < Command
def help
return <<-EOF
<<-EOF
Enable/Disable Cleaner chore. Returns previous Cleaner chore state.
Examples:
@ -30,7 +30,7 @@ EOF
end
def command(enableDisable)
formatter.row([admin.cleaner_chore_switch(enableDisable)? "true" : "false"])
formatter.row([admin.cleaner_chore_switch(enableDisable) ? 'true' : 'false'])
end
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class ClearAuths < Command
def help
return <<-EOF
<<-EOF
Clear visibility labels from a user or group
Syntax : clear_auths 'user',[label1, label2]

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class ClearCompactionQueues < Command
def help
return <<-EOF
<<-EOF
Clear compacting queues on a regionserver.
The queue_name contains short and long.
short is shortCompactions's queue,long is longCompactions's queue.

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class CloneSnapshot < Command
def help
return <<-EOF
<<-EOF
Create a new table by cloning the snapshot content.
There're no copies of data involved.
And writing on the newly created table will not influence the snapshot data.
@ -37,13 +37,13 @@ EOF
end
def command(snapshot_name, table, args = {})
raise(ArgumentError, "Arguments should be a Hash") unless args.kind_of?(Hash)
raise(ArgumentError, 'Arguments should be a Hash') unless args.is_a?(Hash)
restore_acl = args.delete(RESTORE_ACL) || false
admin.clone_snapshot(snapshot_name, table, restore_acl)
end
def handle_exceptions(cause, *args)
if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then
if cause.is_a?(org.apache.hadoop.hbase.TableExistsException)
tableName = args[1]
raise "Table already exists: #{tableName}!"
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class CloseRegion < Command
def help
return <<-EOF
<<-EOF
Close a single region. Ask the master to close a region out on the cluster
or if 'SERVER_NAME' is supplied, ask the designated hosting regionserver to
close the region directly. Closing a region, the master expects 'REGIONNAME'

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Compact < Command
def help
return <<-EOF
<<-EOF
Compact all regions in passed table or pass a region row
to compact an individual region. You can also compact a single column
family within a region.
@ -43,7 +43,7 @@ module Shell
EOF
end
def command(table_or_region_name, family = nil, type = "NORMAL")
def command(table_or_region_name, family = nil, type = 'NORMAL')
admin.compact(table_or_region_name, family, type)
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class CompactRs < Command
def help
return <<-EOF
<<-EOF
Compact all regions on passed regionserver.
Examples:
Compact all regions on a regionserver:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class CompactionState < Command
def help
return <<-EOF
<<-EOF
Gets compaction status for a table:
hbase> compaction_state 'ns1:t1'
hbase> compaction_state 't1'

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Count < Command
def help
return <<-EOF
<<-EOF
Count the number of rows in a table. Return value is the number of rows.
This operation may take a LONG time (Run '$HADOOP_HOME/bin/hadoop jar
hbase.jar rowcount' to run a counting mapreduce job). Current count is shown
@ -58,7 +58,7 @@ EOF
def count(table, params = {})
# If the second parameter is an integer, then it is the old command syntax
params = { 'INTERVAL' => params } if params.kind_of?(Fixnum)
params = { 'INTERVAL' => params } if params.is_a?(Integer)
# Merge params with defaults
params = {
@ -74,11 +74,11 @@ EOF
formatter.row(["Current count: #{cnt}, row: #{row}"])
end
formatter.footer(count)
return count
count
end
end
end
end
# Add the method table.count that calls count.count
::Hbase::Table.add_shell_command("count")
::Hbase::Table.add_shell_command('count')

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Create < Command
def help
return <<-EOF
<<-EOF
Creates a table. Pass a table name, and a set of column family
specifications (at least one), and, optionally, table configuration.
Column specification can be a simple string (name), or a dictionary
@ -65,7 +65,7 @@ EOF
def command(table, *args)
admin.create(table, *args)
@end_time = Time.now
puts "Created table " + table.to_s
puts 'Created table ' + table.to_s
# and then return the table just created
table(table)

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class CreateNamespace < Command
def help
return <<-EOF
<<-EOF
Create namespace; pass namespace name,
and optionally a dictionary of namespace configuration.
Examples:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Delete < Command
def help
return <<-EOF
<<-EOF
Put a delete cell value at specified table/row/column and optionally
timestamp coordinates. Deletes must match the deleted cell's
coordinates exactly. When scanning, a delete cell suppresses older
@ -55,4 +55,4 @@ EOF
end
# Add the method table.delete that calls delete.delete
::Hbase::Table.add_shell_command("delete")
::Hbase::Table.add_shell_command('delete')

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class DeleteAllSnapshot < Command
def help
return <<-EOF
<<-EOF
Delete all of the snapshots matching the given regex. Examples:
hbase> delete_all_snapshot 's.*'
@ -29,17 +29,17 @@ EOF
end
def command(regex)
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME'])
list = admin.list_snapshot(regex)
count = list.size
list.each do |snapshot|
creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
creation_time = Time.at(snapshot.getCreationTime / 1000).to_s
formatter.row([snapshot.getName, snapshot.getTable + ' (' + creation_time + ')'])
end
puts "\nDelete the above #{count} snapshots (y/n)?" unless count == 0
answer = 'n'
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}" if count == 0
return unless answer =~ /y.*/i
@start_time = Time.now
admin.delete_all_snapshot(regex)
@ -50,10 +50,10 @@ EOF
puts "#{successfullyDeleted} snapshots successfully deleted." unless successfullyDeleted == 0
return if leftOverSnapshotCount == 0
puts "\nFailed to delete the below #{leftOverSnapshotCount} snapshots."
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME'])
list.each do |snapshot|
creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
creation_time = Time.at(snapshot.getCreationTime / 1000).to_s
formatter.row([snapshot.getName, snapshot.getTable + ' (' + creation_time + ')'])
end
end
end

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class DeleteSnapshot < Command
def help
return <<-EOF
<<-EOF
Delete a specified snapshot. Examples:
hbase> delete_snapshot 'snapshotName',

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class DeleteTableSnapshots < Command
def help
return <<-EOF
<<-EOF
Delete all of the snapshots matching the given table name regular expression
and snapshot name regular expression.
By default snapshot name regular expression will delete all the snapshots of the
@ -37,18 +37,18 @@ Examples:
EOF
end
def command(tableNameregex, snapshotNameRegex = ".*")
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
def command(tableNameregex, snapshotNameRegex = '.*')
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME'])
list = admin.list_table_snapshots(tableNameregex, snapshotNameRegex)
count = list.size
list.each do |snapshot|
creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
creation_time = Time.at(snapshot.getCreationTime / 1000).to_s
formatter.row([snapshot.getName, snapshot.getTable + ' (' + creation_time + ')'])
end
puts "\nDelete the above #{count} snapshots (y/n)?" unless count == 0
answer = 'n'
answer = gets.chomp unless 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
puts "No snapshots matched the table name regular expression #{tableNameregex} and the snapshot name regular expression #{snapshotNameRegex}" if count == 0
return unless answer =~ /y.*/i
@start_time = Time.now
@ -58,7 +58,7 @@ EOF
puts "Successfully deleted snapshot: #{deleteSnapshot.getName}"
puts "\n"
rescue RuntimeError
puts "Failed to delete snapshot: #{deleteSnapshot.getName}, due to below exception,\n" + $!
puts "Failed to delete snapshot: #{deleteSnapshot.getName}, due to below exception,\n" + $ERROR_INFO
puts "\n"
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Deleteall < Command
def help
return <<-EOF
<<-EOF
Delete all cells in a given row; pass a table name, row, and optionally
a column and timestamp. Deleteall also support deleting a row range using a
row key prefix. Examples:
@ -65,4 +65,4 @@ EOF
end
# Add the method table.deleteall that calls deleteall.deleteall
::Hbase::Table.add_shell_command("deleteall")
::Hbase::Table.add_shell_command('deleteall')

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Describe < Command
def help
return <<-EOF
<<-EOF
Describe the named table. For example:
hbase> describe 't1'
hbase> describe 'ns1:t1'
@ -35,13 +35,13 @@ EOF
def command(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 ' + (admin.enabled?(table) ? 'ENABLED' : 'DISABLED')])
formatter.row([table.to_s + admin.get_table_attributes(table)], true)
formatter.header(["COLUMN FAMILIES DESCRIPTION"])
formatter.header(['COLUMN FAMILIES DESCRIPTION'])
column_families.each do |column_family|
formatter.row([column_family.to_s], true)
end
formatter.footer()
formatter.footer
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class DescribeNamespace < Command
def help
return <<-EOF
<<-EOF
Describe the named namespace. For example:
hbase> describe_namespace 'ns1'
EOF
@ -30,7 +30,7 @@ EOF
def command(namespace)
desc = admin.describe_namespace(namespace)
formatter.header([ "DESCRIPTION" ], [ 64 ])
formatter.header(['DESCRIPTION'], [64])
formatter.row([desc], true, [64])
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Disable < Command
def help
return <<-EOF
<<-EOF
Start disable of named table:
hbase> disable 't1'
hbase> disable 'ns1:t1'

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class DisableAll < Command
def help
return <<-EOF
<<-EOF
Disable all of tables matching the given regex:
hbase> disable_all 't.*'
@ -39,11 +39,11 @@ EOF
puts "\nDisable the above #{count} tables (y/n)?" unless count == 0
answer = 'n'
answer = gets.chomp unless count == 0
puts "No tables matched the regex #{regex.to_s}" if count == 0
puts "No tables matched the regex #{regex}" if count == 0
return unless answer =~ /y.*/i
failed = admin.disable_all(regex)
puts "#{count - failed.size} tables successfully disabled"
puts "#{failed.size} tables not disabled due to an exception: #{failed.join ','}" unless failed.size == 0
puts "#{failed.size} tables not disabled due to an exception: #{failed.join ','}" unless failed.empty?
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class DisablePeer < Command
def help
return <<-EOF
<<-EOF
Stops the replication stream to the specified cluster, but still
keeps track of new edits to replicate.

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class DisableTableReplication < Command
def help
return <<-EOF
<<-EOF
Disable a table's replication switch.
Examples:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Drop < Command
def help
return <<-EOF
<<-EOF
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class DropAll < Command
def help
return <<-EOF
<<-EOF
Drop all of the tables matching the given regex:
hbase> drop_all 't.*'
@ -39,11 +39,11 @@ EOF
puts "\nDrop the above #{count} tables (y/n)?" unless count == 0
answer = 'n'
answer = gets.chomp unless count == 0
puts "No tables matched the regex #{regex.to_s}" if count == 0
puts "No tables matched the regex #{regex}" if count == 0
return unless answer =~ /y.*/i
failed = admin.drop_all(regex)
puts "#{count - failed.size} tables successfully dropped"
puts "#{failed.size} tables not dropped due to an exception: #{failed.join ','}" unless failed.size == 0
puts "#{failed.size} tables not dropped due to an exception: #{failed.join ','}" unless failed.empty?
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class DropNamespace < Command
def help
return <<-EOF
<<-EOF
Drop the named namespace. The namespace must be empty.
EOF
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Enable < Command
def help
return <<-EOF
<<-EOF
Start enable of named table:
hbase> enable 't1'
hbase> enable 'ns1:t1'

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class EnableAll < Command
def help
return <<-EOF
<<-EOF
Enable all of the tables matching the given regex:
hbase> enable_all 't.*'
@ -39,11 +39,11 @@ EOF
puts "\nEnable the above #{count} tables (y/n)?" unless count == 0
answer = 'n'
answer = gets.chomp unless count == 0
puts "No tables matched the regex #{regex.to_s}" if count == 0
puts "No tables matched the regex #{regex}" if count == 0
return unless answer =~ /y.*/i
failed = admin.enable_all(regex)
puts "#{count - failed.size} tables successfully enabled"
puts "#{failed.size} tables not enabled due to an exception: #{failed.join ','}" unless failed.size == 0
puts "#{failed.size} tables not enabled due to an exception: #{failed.join ','}" unless failed.empty?
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class EnablePeer < Command
def help
return <<-EOF
<<-EOF
Restarts the replication to the specified peer cluster,
continuing from where it was disabled.

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class EnableTableReplication < Command
def help
return <<-EOF
<<-EOF
Enable a table's replication switch.
Examples:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Exists < Command
def help
return <<-EOF
<<-EOF
Does the named table exist?
hbase> exists 't1'
hbase> exists 'ns1:t1'
@ -31,7 +31,7 @@ EOF
def command(table)
exists = admin.exists?(table.to_s)
formatter.row([
"Table #{table} " + (exists ? "does exist" : "does not exist")
"Table #{table} " + (exists ? 'does exist' : 'does not exist')
])
exists
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Flush < Command
def help
return <<-EOF
<<-EOF
Flush all regions in passed table or pass a region row to
flush an individual region. For example:

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Get < Command
def help
return <<-EOF
<<-EOF
Get row or cell contents; pass table name, row, and optionally
a dictionary of column(s), timestamp, timerange and versions. Examples:
@ -87,7 +87,7 @@ EOF
def get(table, row, *args)
@start_time = Time.now
formatter.header(["COLUMN", "CELL"])
formatter.header(%w[COLUMN CELL])
count, is_stale = table._get_internal(row, *args) do |column, value|
formatter.row([column, value])

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class GetAuths < Command
def help
return <<-EOF
<<-EOF
Get the visibility labels set for a particular user or group
Syntax : get_auths 'user'
@ -33,7 +33,7 @@ EOF
def command(user)
list = visibility_labels_admin.get_auths(user)
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
list
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class GetCounter < Command
def help
return <<-EOF
<<-EOF
Return a counter cell value at specified table/row/column coordinates.
A counter cell should be managed with atomic increment functions on HBase
and the data should be binary encoded (as long value). Example:
@ -44,7 +44,7 @@ EOF
if cnt = table._get_counter_internal(row, column)
puts "COUNTER VALUE = #{cnt}"
else
puts "No counter found at specified coordinates"
puts 'No counter found at specified coordinates'
end
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class GetPeerConfig < Command
def help
return <<-EOF
<<-EOF
Outputs the cluster key, replication endpoint class (if present), and any replication configuration parameters
EOF
end
@ -35,18 +35,13 @@ module Shell
cluster_key = peer_config.get_cluster_key
endpoint = peer_config.get_replication_endpoint_impl
unless cluster_key.nil?
formatter.row(["Cluster Key", cluster_key])
end
unless endpoint.nil?
formatter.row(["Replication Endpoint", endpoint])
end
formatter.row(['Cluster Key', cluster_key]) unless cluster_key.nil?
formatter.row(['Replication Endpoint', endpoint]) unless endpoint.nil?
unless peer_config.get_configuration.nil?
peer_config.get_configuration.each do |config_entry|
formatter.row(config_entry)
end
end
end
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class GetRsgroup < Command
def help
return <<-EOF
<<-EOF
Get a RegionServer group's information.
Example:
@ -34,7 +34,7 @@ EOF
rsgroup_admin.get_rsgroup(group_name) do |s|
formatter.row([s])
end
formatter.footer()
formatter.footer
end
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class GetServerRsgroup < Command
def help
return <<-EOF
<<-EOF
Get the group name the given RegionServer is a member of.
Example:

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class GetSplits < Command
def help
return <<-EOF
<<-EOF
Get the splits of the named table:
hbase> get_splits 't1'
hbase> get_splits 'ns1:t1'
@ -37,10 +37,10 @@ EOF
end
def get_splits(table)
table._get_splits_internal()
table._get_splits_internal
end
end
end
end
::Hbase::Table.add_shell_command("get_splits")
::Hbase::Table.add_shell_command('get_splits')

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class GetTable < Command
def help
return <<-EOF
<<-EOF
Get the given table name and return it as an actual object to
be manipulated by the user. See table.help for more information
on how to use the table.
@ -37,7 +37,7 @@ which will then print the help for that table.
EOF
end
def command(table, *args)
def command(table, *_args)
table(table)
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class GetTableRsgroup < Command
def help
return <<-EOF
<<-EOF
Get the RegionServer group name the given table is a member of.
Example:

View File

@ -20,7 +20,7 @@ module Shell
module Commands
class Grant < Command
def help
return <<-EOF
<<-EOF
Grant users specific rights.
Syntax : grant <user>, <permissions> [, <@namespace> [, <table> [, <column family> [, <column qualifier>]]]
@ -42,12 +42,11 @@ EOF
end
def command(*args)
# command form is ambiguous at first argument
table_name = user = args[0]
raise(ArgumentError, "First argument should be a String") unless user.kind_of?(String)
raise(ArgumentError, 'First argument should be a String') unless user.is_a?(String)
if args[1].kind_of?(String)
if args[1].is_a?(String)
# Original form of the command
# user in args[0]
@ -57,27 +56,30 @@ EOF
# qualifier in args[4] or nil
permissions = args[1]
raise(ArgumentError, "Permissions are not of String type") unless permissions.kind_of?(
String)
raise(ArgumentError, 'Permissions are not of String type') unless permissions.is_a?(
String
)
table_name = family = qualifier = nil
table_name = args[2] # will be nil if unset
if not table_name.nil?
raise(ArgumentError, "Table name is not of String type") unless table_name.kind_of?(
String)
unless table_name.nil?
raise(ArgumentError, 'Table name is not of String type') unless table_name.is_a?(
String
)
family = args[3] # will be nil if unset
if not family.nil?
raise(ArgumentError, "Family is not of String type") unless family.kind_of?(String)
unless family.nil?
raise(ArgumentError, 'Family is not of String type') unless family.is_a?(String)
qualifier = args[4] # will be nil if unset
if not qualifier.nil?
raise(ArgumentError, "Qualifier is not of String type") unless qualifier.kind_of?(
String)
unless qualifier.nil?
raise(ArgumentError, 'Qualifier is not of String type') unless qualifier.is_a?(
String
)
end
end
end
@start_time = Time.now
security_admin.grant(user, permissions, table_name, family, qualifier)
elsif args[1].kind_of?(Hash)
elsif args[1].is_a?(Hash)
# New form of the command, a cell ACL update
# table_name in args[0], a string
@ -86,9 +88,9 @@ EOF
# Useful for feature testing and debugging.
permissions = args[1]
raise(ArgumentError, "Permissions are not of Hash type") unless permissions.kind_of?(Hash)
raise(ArgumentError, 'Permissions are not of Hash type') unless permissions.is_a?(Hash)
scan = args[2]
raise(ArgumentError, "Scanner specification is not a Hash") unless scan.kind_of?(Hash)
raise(ArgumentError, 'Scanner specification is not a Hash') unless scan.is_a?(Hash)
t = table(table_name)
@start_time = Time.now
@ -108,9 +110,8 @@ EOF
formatter.footer(count)
else
raise(ArgumentError, "Second argument should be a String or Hash")
end
raise(ArgumentError, 'Second argument should be a String or Hash')
end
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Incr < Command
def help
return <<-EOF
<<-EOF
Increments a cell 'value' at specified table/row/column coordinates.
To increment a cell value in table 'ns1:t1' or 't1' at row 'r1' under column
'c1' by 1 (can be omitted) or 10 do:
@ -52,7 +52,7 @@ EOF
if cnt = table._incr_internal(row, column, value, args)
puts "COUNTER VALUE = #{cnt}"
else
puts "No counter found at specified coordinates"
puts 'No counter found at specified coordinates'
end
end
end
@ -60,4 +60,4 @@ EOF
end
# add incr comamnd to Table
::Hbase::Table.add_shell_command("incr")
::Hbase::Table.add_shell_command('incr')

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class IsDisabled < Command
def help
return <<-EOF
<<-EOF
Is named table disabled? For example:
hbase> is_disabled 't1'
hbase> is_disabled 'ns1:t1'
@ -29,7 +29,7 @@ EOF
end
def command(table)
formatter.row([admin.disabled?(table)? "true" : "false"])
formatter.row([admin.disabled?(table) ? 'true' : 'false'])
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class IsEnabled < Command
def help
return <<-EOF
<<-EOF
Is named table enabled? For example:
hbase> is_enabled 't1'
hbase> is_enabled 'ns1:t1'
@ -30,7 +30,7 @@ EOF
def command(table)
enabled = admin.enabled?(table)
formatter.row([enabled ? "true" : "false"])
formatter.row([enabled ? 'true' : 'false'])
enabled
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class List < Command
def help
return <<-EOF
<<-EOF
List all user tables in hbase. Optional regular expression parameter could
be used to filter the output. Examples:
@ -32,8 +32,8 @@ be used to filter the output. Examples:
EOF
end
def command(regex = ".*")
formatter.header([ "TABLE" ])
def command(regex = '.*')
formatter.header(['TABLE'])
list = admin.list(regex)
list.each do |table|
@ -41,7 +41,7 @@ EOF
end
formatter.footer(list.size)
return list
list
end
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class ListLabels < Command
def help
return <<-EOF
<<-EOF
List the visibility labels defined in the system.
Optional regular expression parameter could be used to filter the labels being returned.
Syntax : list_labels
@ -31,10 +31,10 @@ For example:
EOF
end
def command(regex = ".*")
def command(regex = '.*')
list = visibility_labels_admin.list_labels(regex)
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)])
end
end
end

View File

@ -21,15 +21,15 @@ module Shell
module Commands
class ListLocks < Command
def help
return <<-EOF
<<-EOF
List all locks in hbase. Examples:
hbase> list_locks
EOF
end
def command()
list = admin.list_locks()
def command
list = admin.list_locks
list.each do |lock|
formatter.output_strln("#{lock.resourceType}(#{lock.resourceName})")
@ -42,17 +42,17 @@ EOF
end
if lock.waitingProcedures.any?
formatter.output_strln("Waiting procedures:")
formatter.header([ "Lock type", "Procedure Id" ])
formatter.output_strln('Waiting procedures:')
formatter.header(['Lock type', 'Procedure Id'])
lock.waitingProcedures.each do |waitingProcedure|
formatter.row([ waitingProcedure.lockType.to_s, waitingProcedure.procedure.procId.to_s ]);
formatter.row([waitingProcedure.lockType.to_s, waitingProcedure.procedure.procId.to_s])
end
formatter.footer(lock.waitingProcedures.size)
end
formatter.output_strln("");
formatter.output_strln('')
end
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class ListNamespace < Command
def help
return <<-EOF
<<-EOF
List all namespaces in hbase. Optional regular expression parameter could
be used to filter the output. Examples:
@ -30,8 +30,8 @@ be used to filter the output. Examples:
EOF
end
def command(regex = ".*")
formatter.header([ "NAMESPACE" ])
def command(regex = '.*')
formatter.header(['NAMESPACE'])
list = admin.list_namespace(regex)
list.each do |table|

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class ListNamespaceTables < Command
def help
return <<-EOF
<<-EOF
List all tables that are members of the namespace.
Examples:
@ -30,7 +30,7 @@ EOF
end
def command(namespace)
formatter.header([ "TABLE" ])
formatter.header(['TABLE'])
list = admin.list_namespace_tables(namespace)
list.each do |table|

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class ListPeerConfigs < Command
def help
return <<-EOF
<<-EOF
No-argument method that outputs the replication peer configuration for each peer defined on this cluster.
EOF
end
@ -30,9 +30,9 @@ module Shell
peer_configs.each do |peer_config_entry|
peer_id = peer_config_entry[0]
peer_config = peer_config_entry[1]
formatter.row(["PeerId", peer_id])
formatter.row(['PeerId', peer_id])
GetPeerConfig.new(@shell).format_peer_config(peer_config)
formatter.row([" "])
formatter.row([' '])
end
end
peer_configs

View File

@ -22,22 +22,22 @@ module Shell
module Commands
class ListPeers < Command
def help
return <<-EOF
<<-EOF
List all replication peer clusters.
hbase> list_peers
EOF
end
def command()
def command
peers = replication_admin.list_peers
formatter.header(["PEER_ID", "CLUSTER_KEY", "ENDPOINT_CLASSNAME",
"STATE", "NAMESPACES", "TABLE_CFS", "BANDWIDTH"])
formatter.header(%w[PEER_ID CLUSTER_KEY ENDPOINT_CLASSNAME
STATE NAMESPACES TABLE_CFS BANDWIDTH])
peers.each do |peer|
id = peer.getPeerId
state = peer.isEnabled ? "ENABLED" : "DISABLED"
state = peer.isEnabled ? 'ENABLED' : 'DISABLED'
config = peer.getPeerConfig
namespaces = replication_admin.show_peer_namespaces(config)
tableCFs = replication_admin.show_peer_tableCFs(id)
@ -46,7 +46,7 @@ EOF
config.getBandwidth])
end
formatter.footer()
formatter.footer
peers
end
end

View File

@ -21,17 +21,17 @@ module Shell
module Commands
class ListProcedures < Command
def help
return <<-EOF
<<-EOF
List all procedures in hbase. For example:
hbase> list_procedures
EOF
end
def command()
formatter.header([ "Id", "Name", "State", "Submitted_Time", "Last_Update" ])
def command
formatter.header(%w[Id Name State Submitted_Time Last_Update])
list = admin.list_procedures()
list = admin.list_procedures
list.each do |proc|
submitted_time = Time.at(proc.getSubmittedTime / 1000).to_s
last_update = Time.at(proc.getLastUpdate / 1000).to_s

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class ListQuotaSnapshots < Command
def help
return <<-EOF
<<-EOF
Lists the current space quota snapshots with optional selection criteria.
Snapshots encapsulate relevant information to space quotas such as space
use, configured limits, and quota violation details. This command is
@ -48,15 +48,15 @@ EOF
desired_table = args[TABLE]
desired_namespace = args[NAMESPACE]
desired_regionserver = args[REGIONSERVER]
formatter.header(["TABLE", "USAGE", "LIMIT", "IN_VIOLATION", "POLICY"])
formatter.header(%w[TABLE USAGE LIMIT IN_VIOLATION POLICY])
count = 0
quotas_admin.get_quota_snapshots(desired_regionserver).each do |table_name, snapshot|
# Skip this snapshot if it's for a table/namespace the user did not ask for
next unless accept? table_name, desired_table, desired_namespace
status = snapshot.getQuotaStatus()
status = snapshot.getQuotaStatus
policy = get_policy(status)
formatter.row([table_name.to_s, snapshot.getUsage().to_s, snapshot.getLimit().to_s,
status.isInViolation().to_s, policy])
formatter.row([table_name.to_s, snapshot.getUsage.to_s, snapshot.getLimit.to_s,
status.isInViolation.to_s, policy])
count += 1
end
formatter.footer(count)
@ -64,20 +64,20 @@ EOF
def get_policy(status)
# Unwrap the violation policy if it exists
if status.isInViolation()
status.getPolicy().name()
if status.isInViolation
status.getPolicy.name
else
"None"
'None'
end
end
def accept?(table_name, desired_table = nil, desired_namespace = nil)
# Check the table name if given one
if desired_table and table_name.getQualifierAsString() != desired_table
if desired_table && table_name.getQualifierAsString != desired_table
return false
end
# Check the namespace if given one
if desired_namespace and table_name.getNamespaceAsString() != desired_namespace
if desired_namespace && table_name.getNamespaceAsString != desired_namespace
return false
end
true

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class ListQuotaTableSizes < Command
def help
return <<-EOF
<<-EOF
Lists the computed size of each table in the cluster as computed by
all RegionServers. This is the raw information that the Master uses to
make decisions about space quotas. Most times, using `list_quota_snapshots`
@ -33,10 +33,10 @@ For example:
EOF
end
def command(args = {})
formatter.header(["TABLE", "SIZE"])
def command(_args = {})
formatter.header(%w[TABLE SIZE])
count = 0
quotas_admin.get_master_table_sizes().each do |tableName,size|
quotas_admin.get_master_table_sizes.each do |tableName, size|
formatter.row([tableName.to_s, size.to_s])
count += 1
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class ListQuotas < Command
def help
return <<-EOF
<<-EOF
List the quota settings added to the system.
You can filter the result based on USER, TABLE, or NAMESPACE.
@ -37,7 +37,7 @@ EOF
end
def command(args = {})
formatter.header(["OWNER", "QUOTAS"])
formatter.header(%w[OWNER QUOTAS])
# actually do the scanning
count = quotas_admin.list_quotas(args) do |row, cells|

View File

@ -21,7 +21,6 @@ module Shell
module Commands
class ListRegions < Command
def help
return <<EOF
List all regions for a particular table as an array and also filter them by server name (optional) as prefix
and maximum locality (optional). By default, it will return all the regions for the table with any locality.
@ -39,37 +38,37 @@ module Shell
hbase> list_regions 'table_name', '', ['SERVER_NAME', 'start_key']
EOF
return
nil
end
def command(table_name, options = nil, cols = nil)
if options.nil?
options = {}
elsif not options.is_a? Hash
elsif !options.is_a? Hash
# When options isn't a hash, assume it's the server name
# and create the hash internally
options = { SERVER_NAME => options }
end
size_hash = Hash.new
size_hash = {}
if cols.nil?
size_hash = { "SERVER_NAME" => 12, "REGION_NAME" => 12, "START_KEY" => 10, "END_KEY" => 10, "SIZE" => 5, "REQ" => 5, "LOCALITY" => 10 }
size_hash = { 'SERVER_NAME' => 12, 'REGION_NAME' => 12, 'START_KEY' => 10, 'END_KEY' => 10, 'SIZE' => 5, 'REQ' => 5, 'LOCALITY' => 10 }
elsif cols.is_a?(Array)
cols.each do |col|
if col.upcase.eql?("SERVER_NAME")
size_hash.store("SERVER_NAME", 12)
elsif col.upcase.eql?("REGION_NAME")
size_hash.store("REGION_NAME", 12)
elsif col.upcase.eql?("START_KEY")
size_hash.store("START_KEY", 10)
elsif col.upcase.eql?("END_KEY")
size_hash.store("END_KEY", 10)
elsif col.upcase.eql?("SIZE")
size_hash.store("SIZE", 5)
elsif col.upcase.eql?("REQ")
size_hash.store("REQ", 5)
elsif col.upcase.eql?("LOCALITY")
size_hash.store("LOCALITY", 10)
if col.casecmp('SERVER_NAME').zero?
size_hash.store('SERVER_NAME', 12)
elsif col.casecmp('REGION_NAME').zero?
size_hash.store('REGION_NAME', 12)
elsif col.casecmp('START_KEY').zero?
size_hash.store('START_KEY', 10)
elsif col.casecmp('END_KEY').zero?
size_hash.store('END_KEY', 10)
elsif col.casecmp('SIZE').zero?
size_hash.store('SIZE', 5)
elsif col.casecmp('REQ').zero?
size_hash.store('REQ', 5)
elsif col.casecmp('LOCALITY').zero?
size_hash.store('LOCALITY', 10)
else
raise "#{col} is not a valid column. Possible values are SERVER_NAME, REGION_NAME, START_KEY, END_KEY, SIZE, REQ, LOCALITY."
end
@ -78,12 +77,12 @@ EOF
raise "#{cols} must be an array of strings. Possible values are SERVER_NAME, REGION_NAME, START_KEY, END_KEY, SIZE, REQ, LOCALITY."
end
admin_instance = admin.instance_variable_get("@admin")
conn_instance = admin_instance.getConnection()
cluster_status = admin_instance.getClusterStatus()
admin_instance = admin.instance_variable_get('@admin')
conn_instance = admin_instance.getConnection
cluster_status = admin_instance.getClusterStatus
hregion_locator_instance = conn_instance.getRegionLocator(TableName.valueOf(table_name))
hregion_locator_list = hregion_locator_instance.getAllRegionLocations().to_a
results = Array.new
hregion_locator_list = hregion_locator_instance.getAllRegionLocations.to_a
results = []
desired_server_name = options[SERVER_NAME]
begin
@ -92,7 +91,7 @@ EOF
# A locality threshold of "1.0" would be all regions (cannot have greater than 1 locality)
# Regions which have a `dataLocality` less-than-or-equal to this value are accepted
locality_threshold = 1.0
if options.has_key? LOCALITY_THRESHOLD
if options.key? LOCALITY_THRESHOLD
value = options[LOCALITY_THRESHOLD]
# Value validation. Must be a Float, and must be between [0, 1.0]
raise "#{LOCALITY_THRESHOLD} must be a float value" unless value.is_a? Float
@ -101,60 +100,59 @@ EOF
end
regions.each do |hregion|
hregion_info = hregion.getRegionInfo()
server_name = hregion.getServerName()
region_load_map = cluster_status.getLoad(server_name).getRegionsLoad()
region_load = region_load_map.get(hregion_info.getRegionName())
hregion_info = hregion.getRegionInfo
server_name = hregion.getServerName
region_load_map = cluster_status.getLoad(server_name).getRegionsLoad
region_load = region_load_map.get(hregion_info.getRegionName)
# Ignore regions which exceed our locality threshold
if accept_region_for_locality? region_load.getDataLocality(), locality_threshold
result_hash = Hash.new
next unless accept_region_for_locality? region_load.getDataLocality, locality_threshold
result_hash = {}
if size_hash.key?("SERVER_NAME")
result_hash.store("SERVER_NAME", server_name.toString().strip)
size_hash["SERVER_NAME"] = [size_hash["SERVER_NAME"], server_name.toString().strip.length].max
if size_hash.key?('SERVER_NAME')
result_hash.store('SERVER_NAME', server_name.toString.strip)
size_hash['SERVER_NAME'] = [size_hash['SERVER_NAME'], server_name.toString.strip.length].max
end
if size_hash.key?("REGION_NAME")
result_hash.store("REGION_NAME", hregion_info.getRegionNameAsString().strip)
size_hash["REGION_NAME"] = [size_hash["REGION_NAME"], hregion_info.getRegionNameAsString().length].max
if size_hash.key?('REGION_NAME')
result_hash.store('REGION_NAME', hregion_info.getRegionNameAsString.strip)
size_hash['REGION_NAME'] = [size_hash['REGION_NAME'], hregion_info.getRegionNameAsString.length].max
end
if size_hash.key?("START_KEY")
startKey = Bytes.toStringBinary(hregion_info.getStartKey()).strip
result_hash.store("START_KEY", startKey)
size_hash["START_KEY"] = [size_hash["START_KEY"], startKey.length].max
if size_hash.key?('START_KEY')
startKey = Bytes.toStringBinary(hregion_info.getStartKey).strip
result_hash.store('START_KEY', startKey)
size_hash['START_KEY'] = [size_hash['START_KEY'], startKey.length].max
end
if size_hash.key?("END_KEY")
endKey = Bytes.toStringBinary(hregion_info.getEndKey()).strip
result_hash.store("END_KEY", endKey)
size_hash["END_KEY"] = [size_hash["END_KEY"], endKey.length].max
if size_hash.key?('END_KEY')
endKey = Bytes.toStringBinary(hregion_info.getEndKey).strip
result_hash.store('END_KEY', endKey)
size_hash['END_KEY'] = [size_hash['END_KEY'], endKey.length].max
end
if size_hash.key?("SIZE")
region_store_file_size = region_load.getStorefileSizeMB().to_s.strip
result_hash.store("SIZE", region_store_file_size)
size_hash["SIZE"] = [size_hash["SIZE"], region_store_file_size.length].max
if size_hash.key?('SIZE')
region_store_file_size = region_load.getStorefileSizeMB.to_s.strip
result_hash.store('SIZE', region_store_file_size)
size_hash['SIZE'] = [size_hash['SIZE'], region_store_file_size.length].max
end
if size_hash.key?("REQ")
region_requests = region_load.getRequestsCount().to_s.strip
result_hash.store("REQ", region_requests)
size_hash["REQ"] = [size_hash["REQ"], region_requests.length].max
if size_hash.key?('REQ')
region_requests = region_load.getRequestsCount.to_s.strip
result_hash.store('REQ', region_requests)
size_hash['REQ'] = [size_hash['REQ'], region_requests.length].max
end
if size_hash.key?("LOCALITY")
locality = region_load.getDataLocality().to_s.strip
result_hash.store("LOCALITY", locality)
size_hash["LOCALITY"] = [size_hash["LOCALITY"], locality.length].max
if size_hash.key?('LOCALITY')
locality = region_load.getDataLocality.to_s.strip
result_hash.store('LOCALITY', locality)
size_hash['LOCALITY'] = [size_hash['LOCALITY'], locality.length].max
end
results << result_hash
end
end
ensure
hregion_locator_instance.close()
hregion_locator_instance.close
end
@end_time = Time.now
@ -164,8 +162,8 @@ EOF
end
printf("\n")
size_hash.each do | param, length |
str = "-" * length
size_hash.each do |_param, length|
str = '-' * length
printf(" %#{length}s |", str)
end
printf("\n")
@ -178,11 +176,10 @@ EOF
end
printf(" %d rows\n", results.size)
end
def valid_locality_threshold?(value)
value >= 0 and value <= 1.0
value >= 0 && value <= 1.0
end
def get_regions_for_table_and_server(table_name, conn, server_name)
@ -191,16 +188,16 @@ EOF
def get_regions_for_server(regions_for_table, server_name)
regions_for_table.select do |hregion|
accept_server_name? server_name, hregion.getServerName().toString()
accept_server_name? server_name, hregion.getServerName.toString
end
end
def get_regions_for_table(table_name, conn)
conn.getRegionLocator(TableName.valueOf(table_name)).getAllRegionLocations().to_a
conn.getRegionLocator(TableName.valueOf(table_name)).getAllRegionLocations.to_a
end
def accept_server_name?(desired_server_name, actual_server_name)
desired_server_name.nil? or actual_server_name.start_with? desired_server_name
desired_server_name.nil? || actual_server_name.start_with?(desired_server_name)
end
def accept_region_for_locality?(actual_locality, locality_threshold)

View File

@ -22,7 +22,7 @@ module Shell
module Commands
class ListReplicatedTables < Command
def help
return <<-EOF
<<-EOF
List all the tables and column families replicated from this cluster
hbase> list_replicated_tables
@ -30,25 +30,25 @@ List all the tables and column families replicated from this cluster
EOF
end
def command(regex = ".*")
formatter.header([ "TABLE:COLUMNFAMILY", "ReplicationType" ], [ 32 ])
def command(regex = '.*')
formatter.header(['TABLE:COLUMNFAMILY', 'ReplicationType'], [32])
list = replication_admin.list_replicated_tables(regex)
list.each do |e|
map = e.getColumnFamilyMap()
map = e.getColumnFamilyMap
map.each do |cf|
if cf[1] == org.apache.hadoop.hbase.HConstants::REPLICATION_SCOPE_LOCAL
replicateType = "LOCAL"
replicateType = 'LOCAL'
elsif cf[1] == org.apache.hadoop.hbase.HConstants::REPLICATION_SCOPE_GLOBAL
replicateType = "GLOBAL"
replicateType = 'GLOBAL'
elsif cf[1] == org.apache.hadoop.hbase.HConstants::REPLICATION_SCOPE_SERIAL
replicateType = "SERIAL"
replicateType = 'SERIAL'
else
replicateType = "UNKNOWN"
replicateType = 'UNKNOWN'
end
formatter.row([e.getTable().getNameAsString() + ":" + cf[0], replicateType], true, [32])
formatter.row([e.getTable.getNameAsString + ':' + cf[0], replicateType], true, [32])
end
end
formatter.footer()
formatter.footer
end
end
end

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class ListRsgroups < Command
def help
return <<-EOF
<<-EOF
List all RegionServer groups. Optional regular expression parameter can
be used to filter the output.

View File

@ -19,7 +19,7 @@ module Shell
module Commands
class ListSecurityCapabilities < Command
def help
return <<-EOF
<<-EOF
List supported security capabilities
Example:
@ -27,16 +27,15 @@ Example:
EOF
end
def command()
begin
def command
list = admin.get_security_capabilities
list.each do |s|
puts s.getName
end
return list.map { |s| s.getName() }
return list.map(&:getName)
rescue Exception => e
if e.to_s.include? "UnsupportedOperationException"
puts "ERROR: Master does not support getSecurityCapabilities"
if e.to_s.include? 'UnsupportedOperationException'
puts 'ERROR: Master does not support getSecurityCapabilities'
return []
end
raise e
@ -44,4 +43,3 @@ EOF
end
end
end
end

View File

@ -21,17 +21,17 @@ module Shell
module Commands
class ListSnapshotSizes < Command
def help
return <<-EOF
<<-EOF
Lists the size of every HBase snapshot given the space quota size computation
algorithms. An HBase snapshot only "owns" the size of a file when the table
from which the snapshot was created no longer refers to that file.
EOF
end
def command(args = {})
formatter.header(["SNAPSHOT", "SIZE"])
def command(_args = {})
formatter.header(%w[SNAPSHOT SIZE])
count = 0
quotas_admin.list_snapshot_sizes().each do |snapshot,size|
quotas_admin.list_snapshot_sizes.each do |snapshot, size|
formatter.row([snapshot.to_s, size.to_s])
count += 1
end

View File

@ -22,7 +22,7 @@ module Shell
module Commands
class ListSnapshots < Command
def help
return <<-EOF
<<-EOF
List all snapshots taken (by printing the names and relative information).
Optional regular expression parameter could be used to filter the output
by snapshot name.
@ -33,17 +33,17 @@ Examples:
EOF
end
def command(regex = ".*")
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
def command(regex = '.*')
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME'])
list = admin.list_snapshot(regex)
list.each do |snapshot|
creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
creation_time = Time.at(snapshot.getCreationTime / 1000).to_s
formatter.row([snapshot.getName, snapshot.getTable + ' (' + creation_time + ')'])
end
formatter.footer(list.size)
return list.map { |s| s.getName() }
list.map(&:getName)
end
end
end

View File

@ -22,7 +22,7 @@ module Shell
module Commands
class ListTableSnapshots < Command
def help
return <<-EOF
<<-EOF
List all completed snapshots matching the table name regular expression and the
snapshot name regular expression (by printing the names and relative information).
Optional snapshot name regular expression parameter could be used to filter the output
@ -38,17 +38,17 @@ Examples:
EOF
end
def command(tableNameRegex, snapshotNameRegex = ".*")
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
def command(tableNameRegex, snapshotNameRegex = '.*')
formatter.header(['SNAPSHOT', 'TABLE + CREATION TIME'])
list = admin.list_table_snapshots(tableNameRegex, snapshotNameRegex)
list.each do |snapshot|
creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
creation_time = Time.at(snapshot.getCreationTime / 1000).to_s
formatter.row([snapshot.getName, snapshot.getTable + ' (' + creation_time + ')'])
end
formatter.footer(list.size)
return list.map { |s| s.getName() }
list.map(&:getName)
end
end
end

View File

@ -22,7 +22,7 @@ module Shell
module Commands
class LocateRegion < Command
def help
return <<-EOF
<<-EOF
Locate the region given a table name and a row-key
hbase> locate_region 'tableName', 'key0'
@ -31,10 +31,10 @@ EOF
def command(table, row_key)
region_location = admin.locate_region(table, row_key)
hri = region_location.getRegionInfo()
hri = region_location.getRegionInfo
formatter.header([ "HOST", "REGION" ])
formatter.row([region_location.getHostnamePort(), hri.toString()])
formatter.header(%w[HOST REGION])
formatter.row([region_location.getHostnamePort, hri.toString])
formatter.footer(1)
region_location
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class MajorCompact < Command
def help
return <<-EOF
<<-EOF
Run major compaction on passed table or pass a region row
to major compact an individual region. To compact a single
column family within a region specify the region name
@ -43,7 +43,7 @@ module Shell
EOF
end
def command(table_or_region_name, family = nil, type = "NORMAL")
def command(table_or_region_name, family = nil, type = 'NORMAL')
admin.major_compact(table_or_region_name, family, type)
end
end

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class MergeRegion < Command
def help
return <<-EOF
<<-EOF
Merge two regions. Passing 'true' as the optional third parameter will force
a merge ('force' merges regardless else merge will fail unless passed
adjacent regions. 'force' is for expert use only).

View File

@ -21,7 +21,7 @@ module Shell
module Commands
class Move < Command
def help
return <<-EOF
<<-EOF
Move a region. Optionally specify target regionserver else we choose one
at random. NOTE: You pass the encoded region name, not the region name so
this command is a little different to the others. The encoded region name

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