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:
parent
2b1b79f08b
commit
65caa08edc
|
@ -51,28 +51,29 @@ optparse.parse!
|
|||
def getServers(admin)
|
||||
serverInfos = admin.getClusterStatus.getServers
|
||||
servers = []
|
||||
for server in serverInfos
|
||||
serverInfos.each do |server|
|
||||
servers << server.getServerName
|
||||
end
|
||||
servers
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def getServerNames(hostOrServers, config)
|
||||
ret = []
|
||||
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
|
||||
parts = hostOrServer.split(',')
|
||||
parts = host_or_server.split(',')
|
||||
if parts.size == 3
|
||||
ret << hostOrServer
|
||||
ret << host_or_server
|
||||
else
|
||||
admin = connection.getAdmin unless admin
|
||||
admin ||= connection.getAdmin
|
||||
servers = getServers(admin)
|
||||
|
||||
hostOrServer = hostOrServer.tr(':', ',')
|
||||
for server in servers
|
||||
ret << server if server.start_with?(hostOrServer)
|
||||
host_or_server = host_or_server.tr(':', ',')
|
||||
servers.each do |server|
|
||||
ret << server if server.start_with?(host_or_server)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -90,7 +91,7 @@ def addServers(_options, hostOrServers)
|
|||
|
||||
begin
|
||||
parentZnode = zkw.getZNodePaths.drainingZNode
|
||||
for server in servers
|
||||
servers.each do |server|
|
||||
node = ZNodePaths.joinZNode(parentZnode, server)
|
||||
ZKUtil.createAndFailSilent(zkw, node)
|
||||
end
|
||||
|
@ -107,7 +108,7 @@ def removeServers(_options, hostOrServers)
|
|||
|
||||
begin
|
||||
parentZnode = zkw.getZNodePaths.drainingZNode
|
||||
for server in servers
|
||||
servers.each do |server|
|
||||
node = ZNodePaths.joinZNode(parentZnode, server)
|
||||
ZKUtil.deleteNodeFailSilent(zkw, node)
|
||||
end
|
||||
|
@ -115,6 +116,7 @@ def removeServers(_options, hostOrServers)
|
|||
zkw.close
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
# list servers in draining mode
|
||||
def listServers(_options)
|
||||
|
|
|
@ -82,7 +82,7 @@ log_level = org.apache.log4j.Level::ERROR
|
|||
@shell_debug = false
|
||||
interactive = true
|
||||
_configuration = nil
|
||||
D_ARG = '-D'
|
||||
D_ARG = '-D'.freeze
|
||||
while (arg = ARGV.shift)
|
||||
if arg == '-h' || arg == '--help'
|
||||
puts cmdline_help
|
||||
|
@ -248,7 +248,7 @@ else
|
|||
# exception unwrapping in shell means we'll have to handle Java exceptions
|
||||
# as a special case in order to format them properly.
|
||||
if exception.is_a? java.lang.Exception
|
||||
$stderr.puts 'java exception'
|
||||
warn 'java exception'
|
||||
message = exception.get_message
|
||||
end
|
||||
# Include the 'ERROR' string to try to make transition easier for scripts that
|
||||
|
|
|
@ -116,6 +116,7 @@ while iter.hasNext
|
|||
# Gone too far, break
|
||||
break
|
||||
end
|
||||
|
||||
region = MetaTableAccessor.getHRegionInfo(result)
|
||||
unless region.isOffline
|
||||
# only include regions that should be online
|
||||
|
|
|
@ -28,24 +28,24 @@ java_import org.apache.hadoop.hbase.client.HBaseAdmin
|
|||
java_import org.apache.hadoop.hbase.client.ConnectionFactory
|
||||
|
||||
def usage(msg = nil)
|
||||
$stderr.puts 'Usage: shutdown_regionserver.rb <host:port>..'
|
||||
$stderr.puts
|
||||
$stderr.puts 'Stops the specified regionservers via RPC'
|
||||
$stderr.puts format('Error: %s', msg) if msg
|
||||
warn 'Usage: shutdown_regionserver.rb <host:port>..'
|
||||
warn
|
||||
warn 'Stops the specified regionservers via RPC'
|
||||
warn format('Error: %<msg>s') if msg
|
||||
abort
|
||||
end
|
||||
|
||||
usage if ARGV.empty?
|
||||
|
||||
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
|
||||
|
||||
config = HBaseConfiguration.create
|
||||
connection = ConnectionFactory.createConnection(config)
|
||||
begin
|
||||
admin = connection.getAdmin
|
||||
rescue
|
||||
rescue StandardError
|
||||
abort "Error: Couldn't instantiate HBaseAdmin"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue