hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject [hbase] branch branch-2 updated: HBASE-21812 Address ruby static analysis for shell/bin modules [2nd pass]
Date Sun, 03 Feb 2019 15:55:11 GMT
This is an automated email from the ASF dual-hosted git repository.

busbey pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 789d9df  HBASE-21812 Address ruby static analysis for shell/bin modules [2nd pass]
789d9df is described below

commit 789d9df1700d917de219fffa9ec43e0562379005
Author: Sakthi <sakthivel.azhaku@gmail.com>
AuthorDate: Fri Feb 1 11:21:49 2019 -0800

    HBASE-21812 Address ruby static analysis for shell/bin modules [2nd pass]
    
    Signed-off-by: Sean Busbey <busbey@apache.org>
    (cherry picked from commit 65caa08edc2be1d3db4e321c1228c1cddb73b88b)
---
 bin/draining_servers.rb      | 22 ++++++++++++----------
 bin/hirb.rb                  |  4 ++--
 bin/region_status.rb         |  1 +
 bin/shutdown_regionserver.rb | 12 ++++++------
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/bin/draining_servers.rb b/bin/draining_servers.rb
index a8e20f0..12f0ba4 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 e857db7..fcbec78 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 abd19dd..f8c203b 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 fd1af30..a131776 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 <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
 


Mime
View raw message