diff --git a/bin/draining_servers.rb b/bin/draining_servers.rb index a8e20f036f4..12f0ba4e174 100644 --- a/bin/draining_servers.rb +++ b/bin/draining_servers.rb @@ -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) diff --git a/bin/hirb.rb b/bin/hirb.rb index e857db788fc..fcbec7809c9 100644 --- a/bin/hirb.rb +++ b/bin/hirb.rb @@ -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 diff --git a/bin/region_status.rb b/bin/region_status.rb index abd19ddb078..f8c203b3926 100644 --- a/bin/region_status.rb +++ b/bin/region_status.rb @@ -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 diff --git a/bin/shutdown_regionserver.rb b/bin/shutdown_regionserver.rb index fd1af30c8c3..a131776e32a 100644 --- a/bin/shutdown_regionserver.rb +++ b/bin/shutdown_regionserver.rb @@ -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 ..' - $stderr.puts - $stderr.puts 'Stops the specified regionservers via RPC' - $stderr.puts format('Error: %s', msg) if msg + warn 'Usage: shutdown_regionserver.rb ..' + warn + warn 'Stops the specified regionservers via RPC' + warn format('Error: %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: %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