HBASE-21812 Address ruby static analysis for shell/bin modules [2nd pass]

Signed-off-by: Sean Busbey <busbey@apache.org>
This commit is contained in:
Sakthi 2019-02-01 11:21:49 -08:00 committed by Sean Busbey
parent 2b1b79f08b
commit 65caa08edc
4 changed files with 21 additions and 18 deletions

View File

@ -51,28 +51,29 @@ optparse.parse!
def getServers(admin) def getServers(admin)
serverInfos = admin.getClusterStatus.getServers serverInfos = admin.getClusterStatus.getServers
servers = [] servers = []
for server in serverInfos serverInfos.each do |server|
servers << server.getServerName servers << server.getServerName
end end
servers servers
end end
# rubocop:disable Metrics/AbcSize
def getServerNames(hostOrServers, config) def getServerNames(hostOrServers, config)
ret = [] ret = []
connection = ConnectionFactory.createConnection(config) connection = ConnectionFactory.createConnection(config)
for hostOrServer in hostOrServers hostOrServers.each do |host_or_server|
# check whether it is already serverName. No need to connect to cluster # check whether it is already serverName. No need to connect to cluster
parts = hostOrServer.split(',') parts = host_or_server.split(',')
if parts.size == 3 if parts.size == 3
ret << hostOrServer ret << host_or_server
else else
admin = connection.getAdmin unless admin admin ||= connection.getAdmin
servers = getServers(admin) servers = getServers(admin)
hostOrServer = hostOrServer.tr(':', ',') host_or_server = host_or_server.tr(':', ',')
for server in servers servers.each do |server|
ret << server if server.start_with?(hostOrServer) ret << server if server.start_with?(host_or_server)
end end
end end
end end
@ -90,7 +91,7 @@ def addServers(_options, hostOrServers)
begin begin
parentZnode = zkw.getZNodePaths.drainingZNode parentZnode = zkw.getZNodePaths.drainingZNode
for server in servers servers.each do |server|
node = ZNodePaths.joinZNode(parentZnode, server) node = ZNodePaths.joinZNode(parentZnode, server)
ZKUtil.createAndFailSilent(zkw, node) ZKUtil.createAndFailSilent(zkw, node)
end end
@ -107,7 +108,7 @@ def removeServers(_options, hostOrServers)
begin begin
parentZnode = zkw.getZNodePaths.drainingZNode parentZnode = zkw.getZNodePaths.drainingZNode
for server in servers servers.each do |server|
node = ZNodePaths.joinZNode(parentZnode, server) node = ZNodePaths.joinZNode(parentZnode, server)
ZKUtil.deleteNodeFailSilent(zkw, node) ZKUtil.deleteNodeFailSilent(zkw, node)
end end
@ -115,6 +116,7 @@ def removeServers(_options, hostOrServers)
zkw.close zkw.close
end end
end end
# rubocop:enable Metrics/AbcSize
# list servers in draining mode # list servers in draining mode
def listServers(_options) def listServers(_options)

View File

@ -82,7 +82,7 @@ log_level = org.apache.log4j.Level::ERROR
@shell_debug = false @shell_debug = false
interactive = true interactive = true
_configuration = nil _configuration = nil
D_ARG = '-D' D_ARG = '-D'.freeze
while (arg = ARGV.shift) while (arg = ARGV.shift)
if arg == '-h' || arg == '--help' if arg == '-h' || arg == '--help'
puts cmdline_help puts cmdline_help
@ -248,7 +248,7 @@ else
# exception unwrapping in shell means we'll have to handle Java exceptions # exception unwrapping in shell means we'll have to handle Java exceptions
# as a special case in order to format them properly. # as a special case in order to format them properly.
if exception.is_a? java.lang.Exception if exception.is_a? java.lang.Exception
$stderr.puts 'java exception' warn 'java exception'
message = exception.get_message message = exception.get_message
end end
# Include the 'ERROR' string to try to make transition easier for scripts that # Include the 'ERROR' string to try to make transition easier for scripts that

View File

@ -116,6 +116,7 @@ while iter.hasNext
# Gone too far, break # Gone too far, break
break break
end end
region = MetaTableAccessor.getHRegionInfo(result) region = MetaTableAccessor.getHRegionInfo(result)
unless region.isOffline unless region.isOffline
# only include regions that should be online # only include regions that should be online

View File

@ -28,24 +28,24 @@ java_import org.apache.hadoop.hbase.client.HBaseAdmin
java_import org.apache.hadoop.hbase.client.ConnectionFactory java_import org.apache.hadoop.hbase.client.ConnectionFactory
def usage(msg = nil) def usage(msg = nil)
$stderr.puts 'Usage: shutdown_regionserver.rb <host:port>..' warn 'Usage: shutdown_regionserver.rb <host:port>..'
$stderr.puts warn
$stderr.puts 'Stops the specified regionservers via RPC' warn 'Stops the specified regionservers via RPC'
$stderr.puts format('Error: %s', msg) if msg warn format('Error: %<msg>s') if msg
abort abort
end end
usage if ARGV.empty? usage if ARGV.empty?
ARGV.each do |x| ARGV.each do |x|
usage format('Invalid host:port: %s', x) unless x.include? ':' usage format('Invalid host:port: %<x>s') unless x.include? ':'
end end
config = HBaseConfiguration.create config = HBaseConfiguration.create
connection = ConnectionFactory.createConnection(config) connection = ConnectionFactory.createConnection(config)
begin begin
admin = connection.getAdmin admin = connection.getAdmin
rescue rescue StandardError
abort "Error: Couldn't instantiate HBaseAdmin" abort "Error: Couldn't instantiate HBaseAdmin"
end end