From 2115d4b50ecf7a17028d88c9bccef076e516a3e2 Mon Sep 17 00:00:00 2001 From: Mike Drob Date: Tue, 20 Jun 2017 15:24:29 -0500 Subject: [PATCH] HBASE-18239 rubocop autocorrect for shell Signed-off-by: Michael Stack --- hbase-shell/src/main/ruby/hbase/admin.rb | 620 +++++++++--------- hbase-shell/src/main/ruby/hbase/hbase.rb | 20 +- hbase-shell/src/main/ruby/hbase/quotas.rb | 180 +++-- .../src/main/ruby/hbase/replication_admin.rb | 54 +- .../src/main/ruby/hbase/rsgroup_admin.rb | 39 +- hbase-shell/src/main/ruby/hbase/security.rb | 134 ++-- hbase-shell/src/main/ruby/hbase/table.rb | 332 +++++----- .../src/main/ruby/hbase/taskmonitor.rb | 131 ++-- .../src/main/ruby/hbase/visibility_labels.rb | 81 +-- hbase-shell/src/main/ruby/hbase_constants.rb | 98 +-- hbase-shell/src/main/ruby/irb/hirb.rb | 29 +- hbase-shell/src/main/ruby/shell.rb | 122 ++-- hbase-shell/src/main/ruby/shell/commands.rb | 35 +- .../ruby/shell/commands/abort_procedure.rb | 6 +- .../main/ruby/shell/commands/add_labels.rb | 2 +- .../src/main/ruby/shell/commands/add_peer.rb | 4 +- .../main/ruby/shell/commands/add_rsgroup.rb | 2 +- .../src/main/ruby/shell/commands/alter.rb | 2 +- .../main/ruby/shell/commands/alter_async.rb | 2 +- .../ruby/shell/commands/alter_namespace.rb | 2 +- .../main/ruby/shell/commands/alter_status.rb | 3 +- .../src/main/ruby/shell/commands/append.rb | 10 +- .../shell/commands/append_peer_namespaces.rb | 4 +- .../shell/commands/append_peer_tableCFs.rb | 4 +- .../src/main/ruby/shell/commands/assign.rb | 2 +- .../ruby/shell/commands/balance_rsgroup.rb | 4 +- .../ruby/shell/commands/balance_switch.rb | 4 +- .../src/main/ruby/shell/commands/balancer.rb | 8 +- .../ruby/shell/commands/balancer_enabled.rb | 4 +- .../shell/commands/catalogjanitor_enabled.rb | 6 +- .../ruby/shell/commands/catalogjanitor_run.rb | 7 +- .../shell/commands/catalogjanitor_switch.rb | 4 +- .../shell/commands/cleaner_chore_enabled.rb | 8 +- .../ruby/shell/commands/cleaner_chore_run.rb | 9 +- .../shell/commands/cleaner_chore_switch.rb | 6 +- .../main/ruby/shell/commands/clear_auths.rb | 2 +- .../shell/commands/clear_compaction_queues.rb | 4 +- .../ruby/shell/commands/clone_snapshot.rb | 8 +- .../main/ruby/shell/commands/close_region.rb | 6 +- .../src/main/ruby/shell/commands/compact.rb | 4 +- .../main/ruby/shell/commands/compact_rs.rb | 2 +- .../ruby/shell/commands/compaction_state.rb | 2 +- .../src/main/ruby/shell/commands/count.rb | 12 +- .../src/main/ruby/shell/commands/create.rb | 6 +- .../ruby/shell/commands/create_namespace.rb | 2 +- .../src/main/ruby/shell/commands/delete.rb | 6 +- .../shell/commands/delete_all_snapshot.rb | 16 +- .../ruby/shell/commands/delete_snapshot.rb | 2 +- .../shell/commands/delete_table_snapshots.rb | 14 +- .../src/main/ruby/shell/commands/deleteall.rb | 6 +- .../src/main/ruby/shell/commands/describe.rb | 10 +- .../ruby/shell/commands/describe_namespace.rb | 6 +- .../src/main/ruby/shell/commands/disable.rb | 2 +- .../main/ruby/shell/commands/disable_all.rb | 8 +- .../main/ruby/shell/commands/disable_peer.rb | 4 +- .../commands/disable_table_replication.rb | 4 +- .../src/main/ruby/shell/commands/drop.rb | 2 +- .../src/main/ruby/shell/commands/drop_all.rb | 8 +- .../ruby/shell/commands/drop_namespace.rb | 2 +- .../src/main/ruby/shell/commands/enable.rb | 2 +- .../main/ruby/shell/commands/enable_all.rb | 8 +- .../main/ruby/shell/commands/enable_peer.rb | 4 +- .../commands/enable_table_replication.rb | 4 +- .../src/main/ruby/shell/commands/exists.rb | 6 +- .../src/main/ruby/shell/commands/flush.rb | 2 +- .../src/main/ruby/shell/commands/get.rb | 16 +- .../src/main/ruby/shell/commands/get_auths.rb | 4 +- .../main/ruby/shell/commands/get_counter.rb | 4 +- .../ruby/shell/commands/get_peer_config.rb | 13 +- .../main/ruby/shell/commands/get_rsgroup.rb | 4 +- .../ruby/shell/commands/get_server_rsgroup.rb | 2 +- .../main/ruby/shell/commands/get_splits.rb | 6 +- .../src/main/ruby/shell/commands/get_table.rb | 4 +- .../ruby/shell/commands/get_table_rsgroup.rb | 4 +- .../src/main/ruby/shell/commands/grant.rb | 47 +- .../src/main/ruby/shell/commands/incr.rb | 10 +- .../main/ruby/shell/commands/is_disabled.rb | 4 +- .../main/ruby/shell/commands/is_enabled.rb | 4 +- .../src/main/ruby/shell/commands/list.rb | 10 +- .../main/ruby/shell/commands/list_labels.rb | 6 +- .../main/ruby/shell/commands/list_locks.rb | 14 +- .../ruby/shell/commands/list_namespace.rb | 8 +- .../shell/commands/list_namespace_tables.rb | 6 +- .../ruby/shell/commands/list_peer_configs.rb | 6 +- .../main/ruby/shell/commands/list_peers.rb | 20 +- .../ruby/shell/commands/list_procedures.rb | 10 +- .../shell/commands/list_quota_snapshots.rb | 24 +- .../shell/commands/list_quota_table_sizes.rb | 8 +- .../main/ruby/shell/commands/list_quotas.rb | 8 +- .../main/ruby/shell/commands/list_regions.rb | 167 +++-- .../shell/commands/list_replicated_tables.rb | 22 +- .../main/ruby/shell/commands/list_rsgroups.rb | 2 +- .../commands/list_security_capabilities.rb | 26 +- .../shell/commands/list_snapshot_sizes.rb | 8 +- .../ruby/shell/commands/list_snapshots.rb | 12 +- .../shell/commands/list_table_snapshots.rb | 12 +- .../main/ruby/shell/commands/locate_region.rb | 8 +- .../main/ruby/shell/commands/major_compact.rb | 4 +- .../main/ruby/shell/commands/merge_region.rb | 2 +- .../src/main/ruby/shell/commands/move.rb | 2 +- .../shell/commands/move_servers_rsgroup.rb | 2 +- .../commands/move_servers_tables_rsgroup.rb | 2 +- .../shell/commands/move_tables_rsgroup.rb | 2 +- .../src/main/ruby/shell/commands/normalize.rb | 7 +- .../ruby/shell/commands/normalizer_enabled.rb | 4 +- .../ruby/shell/commands/normalizer_switch.rb | 4 +- .../main/ruby/shell/commands/processlist.rb | 19 +- .../src/main/ruby/shell/commands/put.rb | 8 +- .../main/ruby/shell/commands/remove_peer.rb | 4 +- .../shell/commands/remove_peer_namespaces.rb | 4 +- .../shell/commands/remove_peer_tableCFs.rb | 2 +- .../ruby/shell/commands/remove_rsgroup.rb | 2 +- .../ruby/shell/commands/restore_snapshot.rb | 4 +- .../src/main/ruby/shell/commands/revoke.rb | 8 +- .../src/main/ruby/shell/commands/scan.rb | 28 +- .../src/main/ruby/shell/commands/set_auths.rb | 2 +- .../ruby/shell/commands/set_peer_bandwidth.rb | 4 +- .../shell/commands/set_peer_namespaces.rb | 4 +- .../ruby/shell/commands/set_peer_tableCFs.rb | 4 +- .../src/main/ruby/shell/commands/set_quota.rb | 44 +- .../ruby/shell/commands/set_visibility.rb | 3 +- .../main/ruby/shell/commands/show_filters.rb | 4 +- .../ruby/shell/commands/show_peer_tableCFs.rb | 4 +- .../src/main/ruby/shell/commands/snapshot.rb | 2 +- .../src/main/ruby/shell/commands/split.rb | 6 +- .../src/main/ruby/shell/commands/status.rb | 4 +- .../main/ruby/shell/commands/table_help.rb | 4 +- .../src/main/ruby/shell/commands/trace.rb | 19 +- .../src/main/ruby/shell/commands/truncate.rb | 3 +- .../ruby/shell/commands/truncate_preserve.rb | 3 +- .../src/main/ruby/shell/commands/unassign.rb | 2 +- .../ruby/shell/commands/update_all_config.rb | 6 +- .../main/ruby/shell/commands/update_config.rb | 2 +- .../ruby/shell/commands/update_peer_config.rb | 4 +- .../ruby/shell/commands/user_permission.rb | 10 +- .../src/main/ruby/shell/commands/version.rb | 8 +- .../src/main/ruby/shell/commands/wal_roll.rb | 4 +- .../src/main/ruby/shell/commands/whoami.rb | 12 +- .../src/main/ruby/shell/commands/zk_dump.rb | 2 +- hbase-shell/src/main/ruby/shell/formatter.rb | 65 +- 140 files changed, 1448 insertions(+), 1526 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 634ad3bf485..5eee26cd04d 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -44,35 +44,31 @@ module Hbase #---------------------------------------------------------------------------------------------- # Returns a list of tables in hbase - def list(regex = ".*") - @admin.listTableNames(regex).map { |t| t.getNameAsString } + def list(regex = '.*') + @admin.listTableNames(regex).map(&:getNameAsString) end #---------------------------------------------------------------------------------------------- # Requests a table or region flush def flush(table_or_region_name) - begin - @admin.flushRegion(table_or_region_name.to_java_bytes); - rescue java.lang.IllegalArgumentException => e - # Unknown region. Try table. - @admin.flush(TableName.valueOf(table_or_region_name)); - end + @admin.flushRegion(table_or_region_name.to_java_bytes) + rescue java.lang.IllegalArgumentException => e + # Unknown region. Try table. + @admin.flush(TableName.valueOf(table_or_region_name)) end #---------------------------------------------------------------------------------------------- # Requests a table or region or column family compaction - def compact(table_or_region_name, family = nil, type = "NORMAL") + def compact(table_or_region_name, family = nil, type = 'NORMAL') family_bytes = nil - unless family.nil? - family_bytes = family.to_java_bytes - end + family_bytes = family.to_java_bytes unless family.nil? compact_type = nil - if type == "NORMAL" + if type == 'NORMAL' compact_type = org.apache.hadoop.hbase.client.CompactType::NORMAL - elsif type == "MOB" + elsif type == 'MOB' compact_type = org.apache.hadoop.hbase.client.CompactType::MOB else - raise ArgumentError, "only NORMAL or MOB accepted for type!" + raise ArgumentError, 'only NORMAL or MOB accepted for type!' end begin @@ -85,7 +81,7 @@ module Hbase #---------------------------------------------------------------------------------------------- # Gets compaction state for specified table def getCompactionState(table_name) - @admin.getCompactionState(TableName.valueOf(table_name)).name() + @admin.getCompactionState(TableName.valueOf(table_name)).name end # Requests to compact all regions on the regionserver @@ -95,18 +91,16 @@ module Hbase #---------------------------------------------------------------------------------------------- # Requests a table or region or column family major compaction - def major_compact(table_or_region_name, family = nil, type = "NORMAL") + def major_compact(table_or_region_name, family = nil, type = 'NORMAL') family_bytes = nil - unless family.nil? - family_bytes = family.to_java_bytes - end + family_bytes = family.to_java_bytes unless family.nil? compact_type = nil - if type == "NORMAL" + if type == 'NORMAL' compact_type = org.apache.hadoop.hbase.client.CompactType::NORMAL - elsif type == "MOB" + elsif type == 'MOB' compact_type = org.apache.hadoop.hbase.client.CompactType::MOB else - raise ArgumentError, "only NORMAL or MOB accepted for type!" + raise ArgumentError, 'only NORMAL or MOB accepted for type!' end begin @@ -121,16 +115,14 @@ module Hbase def wal_roll(server_name) @admin.rollWALWriter(ServerName.valueOf(server_name)) end - # TODO remove older hlog_roll version - alias :hlog_roll :wal_roll + # TODO: remove older hlog_roll version + alias hlog_roll wal_roll #---------------------------------------------------------------------------------------------- # Requests a table or region split def split(table_or_region_name, split_point = nil) split_point_bytes = nil - unless split_point.nil? - split_point_bytes = split_point.to_java_bytes - end + split_point_bytes = split_point.to_java_bytes unless split_point.nil? begin @admin.splitRegion(table_or_region_name.to_java_bytes, split_point_bytes) rescue java.lang.IllegalArgumentException => e @@ -152,7 +144,8 @@ module Hbase end @admin.setSplitOrMergeEnabled( java.lang.Boolean.valueOf(enabled), java.lang.Boolean.valueOf(false), - switch_type)[0] + switch_type + )[0] end #---------------------------------------------------------------------------------------------- @@ -175,7 +168,7 @@ module Hbase begin return locator.getRegionLocation(Bytes.toBytesBinary(row_key)) ensure - locator.close() + locator.close end end @@ -183,7 +176,7 @@ module Hbase # Requests a cluster balance # Returns true if balancer ran def balancer(force) - @admin.balancer(java.lang.Boolean::valueOf(force)) + @admin.balancer(java.lang.Boolean.valueOf(force)) end #---------------------------------------------------------------------------------------------- @@ -191,76 +184,77 @@ module Hbase # Returns previous balancer switch setting. def balance_switch(enableDisable) @admin.setBalancerRunning( - java.lang.Boolean::valueOf(enableDisable), java.lang.Boolean::valueOf(false)) + java.lang.Boolean.valueOf(enableDisable), java.lang.Boolean.valueOf(false) + ) end #---------------------------------------------------------------------------------------------- # Query the current state of the LoadBalancer. # Returns the balancer's state (true is enabled). - def balancer_enabled?() - @admin.isBalancerEnabled() + def balancer_enabled? + @admin.isBalancerEnabled end #---------------------------------------------------------------------------------------------- # Requests region normalization for all configured tables in the cluster # Returns true if normalizer ran successfully - def normalize() - @admin.normalize() + def normalize + @admin.normalize end #---------------------------------------------------------------------------------------------- # Enable/disable region normalizer # Returns previous normalizer switch setting. def normalizer_switch(enableDisable) - @admin.setNormalizerRunning(java.lang.Boolean::valueOf(enableDisable)) + @admin.setNormalizerRunning(java.lang.Boolean.valueOf(enableDisable)) end #---------------------------------------------------------------------------------------------- # Query the current state of region normalizer. # Returns the state of region normalizer (true is enabled). - def normalizer_enabled?() - @admin.isNormalizerEnabled() + def normalizer_enabled? + @admin.isNormalizerEnabled end #---------------------------------------------------------------------------------------------- # Request a scan of the catalog table (for garbage collection) # Returns an int signifying the number of entries cleaned - def catalogjanitor_run() - @admin.runCatalogScan() + def catalogjanitor_run + @admin.runCatalogScan end #---------------------------------------------------------------------------------------------- # Enable/disable the catalog janitor # Returns previous catalog janitor switch setting. def catalogjanitor_switch(enableDisable) - @admin.enableCatalogJanitor(java.lang.Boolean::valueOf(enableDisable)) + @admin.enableCatalogJanitor(java.lang.Boolean.valueOf(enableDisable)) end #---------------------------------------------------------------------------------------------- # Query on the catalog janitor state (enabled/disabled?) # Returns catalog janitor state (true signifies enabled). - def catalogjanitor_enabled() - @admin.isCatalogJanitorEnabled() + def catalogjanitor_enabled + @admin.isCatalogJanitorEnabled end #---------------------------------------------------------------------------------------------- # Request cleaner chore to run (for garbage collection of HFiles and WAL files) - def cleaner_chore_run() - @admin.runCleanerChore() + def cleaner_chore_run + @admin.runCleanerChore end #---------------------------------------------------------------------------------------------- # Enable/disable the cleaner chore # Returns previous cleaner switch setting. def cleaner_chore_switch(enableDisable) - @admin.setCleanerChoreRunning(java.lang.Boolean::valueOf(enableDisable)) + @admin.setCleanerChoreRunning(java.lang.Boolean.valueOf(enableDisable)) end #---------------------------------------------------------------------------------------------- # Query on the cleaner chore state (enabled/disabled?) # Returns cleaner state (true signifies enabled). - def cleaner_chore_enabled() - @admin.isCleanerChoreEnabled() + def cleaner_chore_enabled + @admin.isCleanerChoreEnabled end #---------------------------------------------------------------------------------------------- @@ -290,7 +284,7 @@ module Hbase # Disables all tables matching the given regex def disable_all(regex) regex = regex.to_s - @admin.disableTables(regex).map { |t| t.getTableName().getNameAsString } + @admin.disableTables(regex).map { |t| t.getTableName.getNameAsString } end #--------------------------------------------------------------------------------------------- @@ -310,7 +304,8 @@ module Hbase def drop(table_name) tableExists(table_name) raise ArgumentError, "Table #{table_name} is enabled. Disable it first." if enabled?( - table_name) + table_name + ) @admin.deleteTable(org.apache.hadoop.hbase.TableName.valueOf(table_name)) end @@ -319,27 +314,28 @@ module Hbase # Drops a table def drop_all(regex) regex = regex.to_s - failed = @admin.deleteTables(regex).map { |t| t.getTableName().getNameAsString } - return failed + failed = @admin.deleteTables(regex).map { |t| t.getTableName.getNameAsString } + failed end #---------------------------------------------------------------------------------------------- # Returns ZooKeeper status dump def zk_dump @zk_wrapper = org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.new( - @admin.getConfiguration(), - "admin", - nil) - zk = @zk_wrapper.getRecoverableZooKeeper().getZooKeeper() + @admin.getConfiguration, + 'admin', + nil + ) + zk = @zk_wrapper.getRecoverableZooKeeper.getZooKeeper @zk_main = org.apache.zookeeper.ZooKeeperMain.new(zk) - org.apache.hadoop.hbase.zookeeper.ZKUtil::dump(@zk_wrapper) + org.apache.hadoop.hbase.zookeeper.ZKUtil.dump(@zk_wrapper) end #---------------------------------------------------------------------------------------------- # Creates a table def create(table_name, *args) # Fail if table name is not a string - raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String) + raise(ArgumentError, 'Table name must be of type String') unless table_name.is_a?(String) # Flatten params array args = args.flatten.compact @@ -351,18 +347,18 @@ module Hbase # Args are either columns or splits, add them to the table definition # TODO: add table options support args.each do |arg| - unless arg.kind_of?(String) || arg.kind_of?(Hash) + unless arg.is_a?(String) || arg.is_a?(Hash) raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type") end # First, handle all the cases where arg is a column family. - if arg.kind_of?(String) or arg.has_key?(NAME) + if arg.is_a?(String) || arg.key?(NAME) # If the arg is a string, default action is to add a column to the table. # If arg has a name, it must also be a column descriptor. - descriptor = hcd(arg, htd); + descriptor = hcd(arg, htd) # Warn if duplicate columns are added if htd.hasFamily(descriptor.getName) - puts "Family '" + descriptor.getNameAsString() + "' already exists, the old one will be replaced" + puts "Family '" + descriptor.getNameAsString + "' already exists, the old one will be replaced" htd.modifyFamily(descriptor) else htd.addFamily(descriptor) @@ -370,7 +366,7 @@ module Hbase has_columns = true next end - if arg.has_key?(REGION_REPLICATION) + if arg.key?(REGION_REPLICATION) region_replication = JInteger.valueOf(arg.delete(REGION_REPLICATION)) htd.setRegionReplication(region_replication) end @@ -378,35 +374,35 @@ module Hbase # Get rid of the "METHOD", which is deprecated for create. # We'll do whatever it used to do below if it's table_att. if (method = arg.delete(METHOD)) - raise(ArgumentError, "table_att is currently the only supported method") unless method == 'table_att' + raise(ArgumentError, 'table_att is currently the only supported method') unless method == 'table_att' end # The hash is not a column family. Figure out what's in it. # First, handle splits. - if arg.has_key?(SPLITS_FILE) + if arg.key?(SPLITS_FILE) splits_file = arg.delete(SPLITS_FILE) unless File.exist?(splits_file) raise(ArgumentError, "Splits file #{splits_file} doesn't exist") end arg[SPLITS] = [] File.foreach(splits_file) do |line| - arg[SPLITS].push(line.strip()) + arg[SPLITS].push(line.strip) end htd.setValue(SPLITS_FILE, arg[SPLITS_FILE]) end - if arg.has_key?(SPLITS) + if arg.key?(SPLITS) splits = Java::byte[][arg[SPLITS].size].new idx = 0 arg.delete(SPLITS).each do |split| splits[idx] = org.apache.hadoop.hbase.util.Bytes.toBytesBinary(split) - idx = idx + 1 + idx += 1 end - elsif arg.has_key?(NUMREGIONS) or arg.has_key?(SPLITALGO) + elsif arg.key?(NUMREGIONS) || arg.key?(SPLITALGO) # deprecated region pre-split API; if one of the above is specified, will be ignored. - raise(ArgumentError, "Number of regions must be specified") unless arg.has_key?(NUMREGIONS) - raise(ArgumentError, "Split algorithm must be specified") unless arg.has_key?(SPLITALGO) - raise(ArgumentError, "Number of regions must be greater than 1") unless arg[NUMREGIONS] > 1 + raise(ArgumentError, 'Number of regions must be specified') unless arg.key?(NUMREGIONS) + raise(ArgumentError, 'Split algorithm must be specified') unless arg.key?(SPLITALGO) + raise(ArgumentError, 'Number of regions must be greater than 1') unless arg[NUMREGIONS] > 1 num_regions = arg.delete(NUMREGIONS) split_algo = RegionSplitter.newSplitAlgoInstance(@conf, arg.delete(SPLITALGO)) splits = split_algo.split(JInteger.valueOf(num_regions)) @@ -416,12 +412,12 @@ module Hbase update_htd_from_arg(htd, arg) arg.each_key do |ignored_key| - puts("An argument ignored (unknown or overridden): %s" % [ ignored_key ]) + puts(format('An argument ignored (unknown or overridden): %s', ignored_key)) end end # Fail if no column families defined - raise(ArgumentError, "Table must have at least one column family") if !has_columns + raise(ArgumentError, 'Table must have at least one column family') unless has_columns if splits.nil? # Perform the create table call @@ -437,7 +433,7 @@ module Hbase # If server name is nil, we presume region_name is full region name (HRegionInfo.getRegionName). # If server name is not nil, we presume it is the region's encoded name (HRegionInfo.getEncodedName) def close_region(region_name, server) - if (region_name.end_with? ".") + if region_name.end_with? '.' @admin.closeRegion(region_name, server) else closeEncodedRegion?(region_name, server) @@ -454,19 +450,19 @@ module Hbase #---------------------------------------------------------------------------------------------- # Unassign a region def unassign(region_name, force) - @admin.unassign(region_name.to_java_bytes, java.lang.Boolean::valueOf(force)) + @admin.unassign(region_name.to_java_bytes, java.lang.Boolean.valueOf(force)) end #---------------------------------------------------------------------------------------------- # Move a region def move(encoded_region_name, server = nil) - @admin.move(encoded_region_name.to_java_bytes, server ? server.to_java_bytes: nil) + @admin.move(encoded_region_name.to_java_bytes, server ? server.to_java_bytes : nil) end #---------------------------------------------------------------------------------------------- # Merge two regions def merge_region(encoded_region_a_name, encoded_region_b_name, force) - @admin.mergeRegions(encoded_region_a_name.to_java_bytes, encoded_region_b_name.to_java_bytes, java.lang.Boolean::valueOf(force)) + @admin.mergeRegions(encoded_region_a_name.to_java_bytes, encoded_region_b_name.to_java_bytes, java.lang.Boolean.valueOf(force)) end #---------------------------------------------------------------------------------------------- @@ -478,7 +474,7 @@ module Hbase def get_column_families(table_name) tableExists(table_name) - @admin.getTableDescriptor(TableName.valueOf(table_name)).getColumnFamilies() + @admin.getTableDescriptor(TableName.valueOf(table_name)).getColumnFamilies end def get_table_attributes(table_name) @@ -502,9 +498,9 @@ module Hbase @admin.truncateTable(table_name, false) rescue => e # Handle the compatibility case, where the truncate method doesn't exists on the Master - raise e unless e.respond_to?(:cause) && e.cause != nil + raise e unless e.respond_to?(:cause) && !e.cause.nil? rootCause = e.cause - if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then + if rootCause.is_a?(org.apache.hadoop.hbase.DoNotRetryIOException) # Handle the compatibility case, where the truncate method doesn't exists on the Master puts 'Dropping table...' @admin.deleteTable(table_name) @@ -524,12 +520,12 @@ module Hbase table_name = TableName.valueOf(table_name_str) locator = @connection.getRegionLocator(table_name) begin - splits = locator.getAllRegionLocations(). - map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}. - delete_if{|k| k == ""}.to_java :String + splits = locator.getAllRegionLocations + .map { |i| Bytes.toStringBinary(i.getRegionInfo.getStartKey) } + .delete_if { |k| k == '' }.to_java :String splits = org.apache.hadoop.hbase.util.Bytes.toBinaryByteArrays(splits) ensure - locator.close() + locator.close end table_description = @admin.getTableDescriptor(table_name) @@ -538,16 +534,16 @@ module Hbase begin puts 'Truncating table...' - #just for test - unless conf.getBoolean("hbase.client.truncatetable.support", true) - raise UnsupportedMethodException.new('truncateTable') + # just for test + unless conf.getBoolean('hbase.client.truncatetable.support', true) + raise UnsupportedMethodException, 'truncateTable' end @admin.truncateTable(table_name, true) rescue => e # Handle the compatibility case, where the truncate method doesn't exists on the Master - raise e unless e.respond_to?(:cause) && e.cause != nil + raise e unless e.respond_to?(:cause) && !e.cause.nil? rootCause = e.cause - if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then + if rootCause.is_a?(org.apache.hadoop.hbase.DoNotRetryIOException) # Handle the compatibility case, where the truncate method doesn't exists on the Master puts 'Dropping table...' @admin.deleteTable(table_name) @@ -566,7 +562,7 @@ module Hbase end def cause - return org.apache.hadoop.hbase.DoNotRetryIOException.new("#@method_name is not support") + org.apache.hadoop.hbase.DoNotRetryIOException.new("#{@method_name} is not support") end end @@ -574,36 +570,36 @@ module Hbase # Check the status of alter command (number of regions reopened) def alter_status(table_name) # Table name should be a string - raise(ArgumentError, "Table name must be of type String") unless table_name.kind_of?(String) + raise(ArgumentError, 'Table name must be of type String') unless table_name.is_a?(String) # Table should exist raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name) - status = Pair.new() + status = Pair.new begin status = @admin.getAlterStatus(org.apache.hadoop.hbase.TableName.valueOf(table_name)) - if status.getSecond() != 0 - puts "#{status.getSecond() - status.getFirst()}/#{status.getSecond()} regions updated." + if status.getSecond != 0 + puts "#{status.getSecond - status.getFirst}/#{status.getSecond} regions updated." else - puts "All regions updated." + puts 'All regions updated.' end - sleep 1 - end while status != nil && status.getFirst() != 0 - puts "Done." + sleep 1 + end while !status.nil? && status.getFirst != 0 + puts 'Done.' end #---------------------------------------------------------------------------------------------- # Change table structure or table options def alter(table_name_str, wait = true, *args) # Table name should be a string - raise(ArgumentError, "Table name must be of type String") unless - table_name_str.kind_of?(String) + raise(ArgumentError, 'Table name must be of type String') unless + table_name_str.is_a?(String) # Table should exist raise(ArgumentError, "Can't find a table: #{table_name_str}") unless exists?(table_name_str) # There should be at least one argument - raise(ArgumentError, "There should be at least one argument but the table name") if args.empty? + raise(ArgumentError, 'There should be at least one argument but the table name') if args.empty? table_name = TableName.valueOf(table_name_str) @@ -613,10 +609,8 @@ module Hbase # Process all args args.each do |arg| - - # Normalize args to support column name only alter specs - arg = { NAME => arg } if arg.kind_of?(String) + arg = { NAME => arg } if arg.is_a?(String) # Normalize args to support shortcut delete syntax arg = { METHOD => 'delete', NAME => arg['delete'] } if arg['delete'] @@ -624,7 +618,7 @@ module Hbase # There are 3 possible options. # 1) Column family spec. Distinguished by having a NAME and no METHOD. method = arg.delete(METHOD) - if method == nil and arg.has_key?(NAME) + if method.nil? && arg.key?(NAME) descriptor = hcd(arg, htd) column_name = descriptor.getNameAsString @@ -640,24 +634,24 @@ module Hbase # 2) Method other than table_att, with some args. name = arg.delete(NAME) - if method != nil and method != "table_att" + if !method.nil? && method != 'table_att' # Delete column family - if method == "delete" - raise(ArgumentError, "NAME parameter missing for delete method") unless name + if method == 'delete' + raise(ArgumentError, 'NAME parameter missing for delete method') unless name htd.removeFamily(name.to_java_bytes) hasTableUpdate = true # Unset table attributes - elsif method == "table_att_unset" - raise(ArgumentError, "NAME parameter missing for table_att_unset method") unless name - if name.kind_of?(Array) + elsif method == 'table_att_unset' + raise(ArgumentError, 'NAME parameter missing for table_att_unset method') unless name + if name.is_a?(Array) name.each do |key| - if (htd.getValue(key) == nil) + if htd.getValue(key).nil? raise ArgumentError, "Could not find attribute: #{key}" end htd.remove(key) end else - if (htd.getValue(name) == nil) + if htd.getValue(name).nil? raise ArgumentError, "Could not find attribute: #{name}" end htd.remove(name) @@ -669,7 +663,7 @@ module Hbase end arg.each_key do |unknown_key| - puts("Unknown argument ignored: %s" % [unknown_key]) + puts(format('Unknown argument ignored: %s', unknown_key)) end next @@ -680,31 +674,29 @@ module Hbase # set a coprocessor attribute valid_coproc_keys = [] - if arg.kind_of?(Hash) - arg.each do |key, value| - k = String.new(key) # prepare to strip - k.strip! + next unless arg.is_a?(Hash) + arg.each do |key, value| + k = String.new(key) # prepare to strip + k.strip! - if (k =~ /coprocessor/i) - v = String.new(value) - v.strip! - htd.addCoprocessorWithSpec(v) - valid_coproc_keys << key - end - end - - valid_coproc_keys.each do |key| - arg.delete(key) - end - - hasTableUpdate = true - - arg.each_key do |unknown_key| - puts("Unknown argument ignored: %s" % [unknown_key]) - end - - next + next unless k =~ /coprocessor/i + v = String.new(value) + v.strip! + htd.addCoprocessorWithSpec(v) + valid_coproc_keys << key end + + valid_coproc_keys.each do |key| + arg.delete(key) + end + + hasTableUpdate = true + + arg.each_key do |unknown_key| + puts(format('Unknown argument ignored: %s', unknown_key)) + end + + next end # Bulk apply all table modifications. @@ -712,107 +704,102 @@ module Hbase @admin.modifyTable(table_name, htd) if wait == true - puts "Updating all regions with the new schema..." + puts 'Updating all regions with the new schema...' alter_status(table_name_str) end end end def status(format, type) - status = @admin.getClusterStatus() - if format == "detailed" - puts("version %s" % [ status.getHBaseVersion() ]) + status = @admin.getClusterStatus + if format == 'detailed' + puts(format('version %s', status.getHBaseVersion)) # Put regions in transition first because usually empty - puts("%d regionsInTransition" % status.getRegionsInTransition().size()) - for v in status.getRegionsInTransition() - puts(" %s" % [v]) + puts(format('%d regionsInTransition', status.getRegionsInTransition.size)) + for v in status.getRegionsInTransition + puts(format(' %s', v)) end - master = status.getMaster() - puts("active master: %s:%d %d" % [master.getHostname(), master.getPort(), master.getStartcode()]) - puts("%d backup masters" % [ status.getBackupMastersSize() ]) - for server in status.getBackupMasters() - puts(" %s:%d %d" % \ - [ server.getHostname(), server.getPort(), server.getStartcode() ]) + master = status.getMaster + puts(format('active master: %s:%d %d', master.getHostname, master.getPort, master.getStartcode)) + puts(format('%d backup masters', status.getBackupMastersSize)) + for server in status.getBackupMasters + puts(format(' %s:%d %d', server.getHostname, server.getPort, server.getStartcode)) end - master_coprocs = java.util.Arrays.toString(@admin.getMasterCoprocessors()) - if master_coprocs != nil - puts("master coprocessors: %s" % master_coprocs) + master_coprocs = java.util.Arrays.toString(@admin.getMasterCoprocessors) + unless master_coprocs.nil? + puts(format('master coprocessors: %s', master_coprocs)) end - puts("%d live servers" % [ status.getServersSize() ]) - for server in status.getServers() - puts(" %s:%d %d" % \ - [ server.getHostname(), server.getPort(), server.getStartcode() ]) - puts(" %s" % [ status.getLoad(server).toString() ]) - for name, region in status.getLoad(server).getRegionsLoad() - puts(" %s" % [ region.getNameAsString().dump ]) - puts(" %s" % [ region.toString() ]) + puts(format('%d live servers', status.getServersSize)) + for server in status.getServers + puts(format(' %s:%d %d', server.getHostname, server.getPort, server.getStartcode)) + puts(format(' %s', status.getLoad(server).toString)) + for name, region in status.getLoad(server).getRegionsLoad + puts(format(' %s', region.getNameAsString.dump)) + puts(format(' %s', region.toString)) end end - puts("%d dead servers" % [ status.getDeadServersSize() ]) - for server in status.getDeadServerNames() - puts(" %s" % [ server ]) + puts(format('%d dead servers', status.getDeadServersSize)) + for server in status.getDeadServerNames + puts(format(' %s', server)) end - elsif format == "replication" - puts("version %s" % [ status.getHBaseVersion() ]) - puts("%d live servers" % [ status.getServersSize() ]) - for server in status.getServers() + elsif format == 'replication' + puts(format('version %s', status.getHBaseVersion)) + puts(format('%d live servers', status.getServersSize)) + for server in status.getServers sl = status.getLoad(server) - rSinkString = " SINK :" - rSourceString = " SOURCE:" - rLoadSink = sl.getReplicationLoadSink() - next if rLoadSink == nil - rSinkString << " AgeOfLastAppliedOp=" + rLoadSink.getAgeOfLastAppliedOp().to_s - rSinkString << ", TimeStampsOfLastAppliedOp=" + - (java.util.Date.new(rLoadSink.getTimeStampsOfLastAppliedOp())).toString() - rLoadSourceList = sl.getReplicationLoadSourceList() + rSinkString = ' SINK :' + rSourceString = ' SOURCE:' + rLoadSink = sl.getReplicationLoadSink + next if rLoadSink.nil? + rSinkString << ' AgeOfLastAppliedOp=' + rLoadSink.getAgeOfLastAppliedOp.to_s + rSinkString << ', TimeStampsOfLastAppliedOp=' + + java.util.Date.new(rLoadSink.getTimeStampsOfLastAppliedOp).toString + rLoadSourceList = sl.getReplicationLoadSourceList index = 0 - while index < rLoadSourceList.size() + while index < rLoadSourceList.size rLoadSource = rLoadSourceList.get(index) - rSourceString << " PeerID=" + rLoadSource.getPeerID() - rSourceString << ", AgeOfLastShippedOp=" + rLoadSource.getAgeOfLastShippedOp().to_s - rSourceString << ", SizeOfLogQueue=" + rLoadSource.getSizeOfLogQueue().to_s - rSourceString << ", TimeStampsOfLastShippedOp=" + - (java.util.Date.new(rLoadSource.getTimeStampOfLastShippedOp())).toString() - rSourceString << ", Replication Lag=" + rLoadSource.getReplicationLag().to_s - index = index + 1 + rSourceString << ' PeerID=' + rLoadSource.getPeerID + rSourceString << ', AgeOfLastShippedOp=' + rLoadSource.getAgeOfLastShippedOp.to_s + rSourceString << ', SizeOfLogQueue=' + rLoadSource.getSizeOfLogQueue.to_s + rSourceString << ', TimeStampsOfLastShippedOp=' + + java.util.Date.new(rLoadSource.getTimeStampOfLastShippedOp).toString + rSourceString << ', Replication Lag=' + rLoadSource.getReplicationLag.to_s + index += 1 end - puts(" %s:" % - [ server.getHostname() ]) - if type.casecmp("SOURCE") == 0 - puts("%s" % rSourceString) - elsif type.casecmp("SINK") == 0 - puts("%s" % rSinkString) + puts(format(' %s:', server.getHostname)) + if type.casecmp('SOURCE') == 0 + puts(format('%s', rSourceString)) + elsif type.casecmp('SINK') == 0 + puts(format('%s', rSinkString)) else - puts("%s" % rSourceString) - puts("%s" % rSinkString) + puts(format('%s', rSourceString)) + puts(format('%s', rSinkString)) end end - elsif format == "simple" + elsif format == 'simple' load = 0 regions = 0 - master = status.getMaster() - puts("active master: %s:%d %d" % [master.getHostname(), master.getPort(), master.getStartcode()]) - puts("%d backup masters" % [ status.getBackupMastersSize() ]) - for server in status.getBackupMasters() - puts(" %s:%d %d" % \ - [ server.getHostname(), server.getPort(), server.getStartcode() ]) + master = status.getMaster + puts(format('active master: %s:%d %d', master.getHostname, master.getPort, master.getStartcode)) + puts(format('%d backup masters', status.getBackupMastersSize)) + for server in status.getBackupMasters + puts(format(' %s:%d %d', server.getHostname, server.getPort, server.getStartcode)) end - puts("%d live servers" % [ status.getServersSize() ]) - for server in status.getServers() - puts(" %s:%d %d" % \ - [ server.getHostname(), server.getPort(), server.getStartcode() ]) - puts(" %s" % [ status.getLoad(server).toString() ]) - load += status.getLoad(server).getNumberOfRequests() - regions += status.getLoad(server).getNumberOfRegions() + puts(format('%d live servers', status.getServersSize)) + for server in status.getServers + puts(format(' %s:%d %d', server.getHostname, server.getPort, server.getStartcode)) + puts(format(' %s', status.getLoad(server).toString)) + load += status.getLoad(server).getNumberOfRequests + regions += status.getLoad(server).getNumberOfRegions end - puts("%d dead servers" % [ status.getDeadServers() ]) - for server in status.getDeadServerNames() - puts(" %s" % [ server ]) + puts(format('%d dead servers', status.getDeadServers)) + for server in status.getDeadServerNames + puts(format(' %s', server)) end - puts("Aggregate load: %d, regions: %d" % [ load , regions ] ) + puts(format('Aggregate load: %d, regions: %d', load, regions)) else - puts "1 active master, #{status.getBackupMastersSize} backup masters, #{status.getServersSize} servers, #{status.getDeadServers} dead, #{'%.4f' % status.getAverageLoad} average load" + puts "1 active master, #{status.getBackupMastersSize} backup masters, #{status.getServersSize} servers, #{status.getDeadServers} dead, #{format('%.4f', status.getAverageLoad)} average load" end end @@ -833,16 +820,16 @@ module Hbase end #---------------------------------------------------------------------------------------------- - #Is supplied region name is encoded region name + # Is supplied region name is encoded region name def closeEncodedRegion?(region_name, server) - @admin.closeRegionWithEncodedRegionName(region_name, server) + @admin.closeRegionWithEncodedRegionName(region_name, server) end #---------------------------------------------------------------------------------------------- # Return a new HColumnDescriptor made of passed args def hcd(arg, htd) # String arg, single parameter constructor - return org.apache.hadoop.hbase.HColumnDescriptor.new(arg) if arg.kind_of?(String) + return org.apache.hadoop.hbase.HColumnDescriptor.new(arg) if arg.is_a?(String) raise(ArgumentError, "Column family #{arg} must have a name") unless name = arg.delete(NAME) @@ -858,8 +845,11 @@ module Hbase family.setEvictBlocksOnClose(JBoolean.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::EVICT_BLOCKS_ON_CLOSE))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::EVICT_BLOCKS_ON_CLOSE) family.setCacheDataInL1(JBoolean.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::CACHE_DATA_IN_L1))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::CACHE_DATA_IN_L1) family.setInMemory(JBoolean.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY) - family.setInMemoryCompaction( - org.apache.hadoop.hbase.MemoryCompactionPolicy.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY_COMPACTION))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY_COMPACTION) + if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY_COMPACTION) + family.setInMemoryCompaction( + org.apache.hadoop.hbase.MemoryCompactionPolicy.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::IN_MEMORY_COMPACTION)) + ) + end family.setTimeToLive(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::TTL)) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::TTL) family.setDataBlockEncoding(org.apache.hadoop.hbase.io.encoding.DataBlockEncoding.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::DATA_BLOCK_ENCODING))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::DATA_BLOCK_ENCODING) family.setBlocksize(JInteger.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::BLOCKSIZE))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::BLOCKSIZE) @@ -872,18 +862,18 @@ module Hbase family.setMobThreshold(JLong.valueOf(arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::MOB_THRESHOLD))) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::MOB_THRESHOLD) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::BLOOMFILTER) bloomtype = arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::BLOOMFILTER).upcase.to_sym - unless org.apache.hadoop.hbase.regionserver.BloomType.constants.include?(bloomtype) - raise(ArgumentError, "BloomFilter type #{bloomtype} is not supported. Use one of " + org.apache.hadoop.hbase.regionserver.StoreFile::BloomType.constants.join(" ")) - else + if org.apache.hadoop.hbase.regionserver.BloomType.constants.include?(bloomtype) family.setBloomFilterType(org.apache.hadoop.hbase.regionserver.BloomType.valueOf(bloomtype)) + else + raise(ArgumentError, "BloomFilter type #{bloomtype} is not supported. Use one of " + org.apache.hadoop.hbase.regionserver.StoreFile::BloomType.constants.join(' ')) end end if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::COMPRESSION) compression = arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::COMPRESSION).upcase.to_sym - unless org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.include?(compression) - raise(ArgumentError, "Compression #{compression} is not supported. Use one of " + org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.join(" ")) - else + if org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.include?(compression) family.setCompressionType(org.apache.hadoop.hbase.io.compress.Compression::Algorithm.valueOf(compression)) + else + raise(ArgumentError, "Compression #{compression} is not supported. Use one of " + org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.join(' ')) end end if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::ENCRYPTION) @@ -891,44 +881,46 @@ module Hbase family.setEncryptionType(algorithm) if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::ENCRYPTION_KEY) key = org.apache.hadoop.hbase.io.crypto.Encryption.pbkdf128( - arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::ENCRYPTION_KEY)) + arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::ENCRYPTION_KEY) + ) family.setEncryptionKey(org.apache.hadoop.hbase.security.EncryptionUtil.wrapKey(@conf, key, - algorithm)) + algorithm)) end end if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::COMPRESSION_COMPACT) compression = arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::COMPRESSION_COMPACT).upcase.to_sym - unless org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.include?(compression) - raise(ArgumentError, "Compression #{compression} is not supported. Use one of " + org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.join(" ")) - else + if org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.include?(compression) family.setCompactionCompressionType(org.apache.hadoop.hbase.io.compress.Compression::Algorithm.valueOf(compression)) + else + raise(ArgumentError, "Compression #{compression} is not supported. Use one of " + org.apache.hadoop.hbase.io.compress.Compression::Algorithm.constants.join(' ')) end end if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::STORAGE_POLICY) - storage_policy = arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::STORAGE_POLICY).upcase - family.setStoragePolicy(storage_policy) + storage_policy = arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::STORAGE_POLICY).upcase + family.setStoragePolicy(storage_policy) end if arg.include?(org.apache.hadoop.hbase.HColumnDescriptor::MOB_COMPACT_PARTITION_POLICY) mob_partition_policy = arg.delete(org.apache.hadoop.hbase.HColumnDescriptor::MOB_COMPACT_PARTITION_POLICY).upcase.to_sym - unless org.apache.hadoop.hbase.client.MobCompactPartitionPolicy.constants.include?(mob_partition_policy) - raise(ArgumentError, "MOB_COMPACT_PARTITION_POLICY #{mob_partition_policy} is not supported. Use one of " + org.apache.hadoop.hbase.client.MobCompactPartitionPolicy.constants.join(" ")) - else + if org.apache.hadoop.hbase.client.MobCompactPartitionPolicy.constants.include?(mob_partition_policy) family.setMobCompactPartitionPolicy(org.apache.hadoop.hbase.client.MobCompactPartitionPolicy.valueOf(mob_partition_policy)) + else + raise(ArgumentError, "MOB_COMPACT_PARTITION_POLICY #{mob_partition_policy} is not supported. Use one of " + org.apache.hadoop.hbase.client.MobCompactPartitionPolicy.constants.join(' ')) end end - set_user_metadata(family, arg.delete(METADATA)) if arg[METADATA] set_descriptor_config(family, arg.delete(CONFIGURATION)) if arg[CONFIGURATION] - family.setDFSReplication(JInteger.valueOf(arg.delete(org.apache.hadoop.hbase. - HColumnDescriptor::DFS_REPLICATION))) if arg.include?(org.apache.hadoop.hbase. - HColumnDescriptor::DFS_REPLICATION) - - arg.each_key do |unknown_key| - puts("Unknown argument ignored for column family %s: %s" % [name, unknown_key]) + if arg.include?(org.apache.hadoop.hbase + .HColumnDescriptor::DFS_REPLICATION) + family.setDFSReplication(JInteger.valueOf(arg.delete(org.apache.hadoop.hbase + .HColumnDescriptor::DFS_REPLICATION))) end - return family + arg.each_key do |unknown_key| + puts(format('Unknown argument ignored for column family %s: %s', name, unknown_key)) + end + + family end #---------------------------------------------------------------------------------------------- @@ -951,41 +943,42 @@ module Hbase # Write it back put = org.apache.hadoop.hbase.client.Put.new(region_bytes) put.addColumn(org.apache.hadoop.hbase.HConstants::CATALOG_FAMILY, - org.apache.hadoop.hbase.HConstants::REGIONINFO_QUALIFIER, - org.apache.hadoop.hbase.util.Writables.getBytes(hri)) + org.apache.hadoop.hbase.HConstants::REGIONINFO_QUALIFIER, + org.apache.hadoop.hbase.util.Writables.getBytes(hri)) meta.put(put) end + # Apply user metadata to table/column descriptor def set_user_metadata(descriptor, metadata) - raise(ArgumentError, "#{METADATA} must be a Hash type") unless metadata.kind_of?(Hash) - for k,v in metadata - v = v.to_s unless v.nil? - descriptor.setValue(k, v) - end + raise(ArgumentError, "#{METADATA} must be a Hash type") unless metadata.is_a?(Hash) + for k, v in metadata + v = v.to_s unless v.nil? + descriptor.setValue(k, v) + end end #---------------------------------------------------------------------------------------------- # Take a snapshot of specified table def snapshot(table, snapshot_name, *args) # Table name should be a string - raise(ArgumentError, "Table name must be of type String") unless table.kind_of?(String) + raise(ArgumentError, 'Table name must be of type String') unless table.is_a?(String) # Snapshot name should be a string - raise(ArgumentError, "Snapshot name must be of type String") unless - snapshot_name.kind_of?(String) + raise(ArgumentError, 'Snapshot name must be of type String') unless + snapshot_name.is_a?(String) table_name = TableName.valueOf(table) if args.empty? - @admin.snapshot(snapshot_name, table_name) + @admin.snapshot(snapshot_name, table_name) else - args.each do |arg| - if arg[SKIP_FLUSH] == true - @admin.snapshot(snapshot_name, table_name, - org.apache.hadoop.hbase.client.SnapshotType::SKIPFLUSH) - else - @admin.snapshot(snapshot_name, table_name) - end - end + args.each do |arg| + if arg[SKIP_FLUSH] == true + @admin.snapshot(snapshot_name, table_name, + org.apache.hadoop.hbase.client.SnapshotType::SKIPFLUSH) + else + @admin.snapshot(snapshot_name, table_name) + end + end end end @@ -993,7 +986,7 @@ module Hbase # Restore specified snapshot def restore_snapshot(snapshot_name, restore_acl = false) conf = @connection.getConfiguration - take_fail_safe_snapshot = conf.getBoolean("hbase.snapshot.restore.take.failsafe.snapshot", false) + take_fail_safe_snapshot = conf.getBoolean('hbase.snapshot.restore.take.failsafe.snapshot', false) @admin.restoreSnapshot(snapshot_name, take_fail_safe_snapshot, restore_acl) end @@ -1017,51 +1010,51 @@ module Hbase #---------------------------------------------------------------------------------------------- # Deletes the table snapshots matching the given regex - def delete_table_snapshots(tableNameRegex, snapshotNameRegex = ".*") + def delete_table_snapshots(tableNameRegex, snapshotNameRegex = '.*') @admin.deleteTableSnapshots(tableNameRegex, snapshotNameRegex).to_a end #---------------------------------------------------------------------------------------------- # Returns a list of snapshots - def list_snapshot(regex = ".*") + def list_snapshot(regex = '.*') @admin.listSnapshots(regex).to_a end #---------------------------------------------------------------------------------------------- # Returns a list of table snapshots - def list_table_snapshots(tableNameRegex, snapshotNameRegex = ".*") + def list_table_snapshots(tableNameRegex, snapshotNameRegex = '.*') @admin.listTableSnapshots(tableNameRegex, snapshotNameRegex).to_a end #---------------------------------------------------------------------------------------------- # Returns a list of regionservers - def getRegionServers() - return @admin.getClusterStatus.getServers.map { |serverName| serverName } + def getRegionServers + @admin.getClusterStatus.getServers.map { |serverName| serverName } end #---------------------------------------------------------------------------------------------- # Returns a list of servernames def getServerNames(servers) - regionservers = getRegionServers() + regionservers = getRegionServers servernames = [] - if servers.length == 0 + if servers.empty? # if no servers were specified as arguments, get a list of all servers servernames = regionservers else # Strings replace with ServerName objects in servers array i = 0 - while (i < servers.length) + while i < servers.length server = servers[i] if ServerName.isFullServerName(server) servernames.push(ServerName.valueOf(server)) else - name_list = server.split(",") + name_list = server.split(',') j = 0 - while (j < regionservers.length) + while j < regionservers.length sn = regionservers[j] - if name_list[0] == sn.hostname and (name_list[1] == nil ? true : (name_list[1] == sn.port.to_s) ) + if name_list[0] == sn.hostname && (name_list[1].nil? ? true : (name_list[1] == sn.port.to_s)) servernames.push(sn) end j += 1 @@ -1071,28 +1064,28 @@ module Hbase end end - return servernames - end + servernames + end # Apply config specific to a table/column to its descriptor def set_descriptor_config(descriptor, config) - raise(ArgumentError, "#{CONFIGURATION} must be a Hash type") unless config.kind_of?(Hash) - for k,v in config - v = v.to_s unless v.nil? - descriptor.setConfiguration(k, v) - end + raise(ArgumentError, "#{CONFIGURATION} must be a Hash type") unless config.is_a?(Hash) + for k, v in config + v = v.to_s unless v.nil? + descriptor.setConfiguration(k, v) + end end #---------------------------------------------------------------------------------------------- # Updates the configuration of one regionserver. def update_config(serverName) - @admin.updateConfiguration(ServerName.valueOf(serverName)); + @admin.updateConfiguration(ServerName.valueOf(serverName)) end #---------------------------------------------------------------------------------------------- # Updates the configuration of all the regionservers. - def update_all_config() - @admin.updateConfiguration(); + def update_all_config + @admin.updateConfiguration end #---------------------------------------------------------------------------------------------- @@ -1100,26 +1093,24 @@ module Hbase def describe_namespace(namespace_name) namespace = @admin.getNamespaceDescriptor(namespace_name) - unless namespace.nil? - return namespace.to_s - end + return namespace.to_s unless namespace.nil? raise(ArgumentError, "Failed to find namespace named #{namespace_name}") end #---------------------------------------------------------------------------------------------- # Returns a list of namespaces in hbase - def list_namespace(regex = ".*") + def list_namespace(regex = '.*') pattern = java.util.regex.Pattern.compile(regex) - list = @admin.listNamespaceDescriptors.map { |ns| ns.getName } - list.select {|s| pattern.match(s) } + list = @admin.listNamespaceDescriptors.map(&:getName) + list.select { |s| pattern.match(s) } end #---------------------------------------------------------------------------------------------- # Returns a list of tables in namespace def list_namespace_tables(namespace_name) unless namespace_name.nil? - return @admin.listTableNamesByNamespace(namespace_name).map { |t| t.getQualifierAsString() } + return @admin.listTableNamesByNamespace(namespace_name).map(&:getQualifierAsString) end raise(ArgumentError, "Failed to find namespace named #{namespace_name}") @@ -1129,52 +1120,50 @@ module Hbase # Creates a namespace def create_namespace(namespace_name, *args) # Fail if table name is not a string - raise(ArgumentError, "Namespace name must be of type String") unless namespace_name.kind_of?(String) + raise(ArgumentError, 'Namespace name must be of type String') unless namespace_name.is_a?(String) # Flatten params array args = args.flatten.compact # Start defining the table - nsb = org.apache.hadoop.hbase.NamespaceDescriptor::create(namespace_name) + nsb = org.apache.hadoop.hbase.NamespaceDescriptor.create(namespace_name) args.each do |arg| - unless arg.kind_of?(Hash) + unless arg.is_a?(Hash) raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash or String type") end - for k,v in arg + for k, v in arg v = v.to_s unless v.nil? nsb.addConfiguration(k, v) end end - @admin.createNamespace(nsb.build()); + @admin.createNamespace(nsb.build) end #---------------------------------------------------------------------------------------------- # modify a namespace def alter_namespace(namespace_name, *args) # Fail if table name is not a string - raise(ArgumentError, "Namespace name must be of type String") unless namespace_name.kind_of?(String) + raise(ArgumentError, 'Namespace name must be of type String') unless namespace_name.is_a?(String) nsd = @admin.getNamespaceDescriptor(namespace_name) - unless nsd - raise(ArgumentError, "Namespace does not exist") - end - nsb = org.apache.hadoop.hbase.NamespaceDescriptor::create(nsd) + raise(ArgumentError, 'Namespace does not exist') unless nsd + nsb = org.apache.hadoop.hbase.NamespaceDescriptor.create(nsd) # Flatten params array args = args.flatten.compact # Start defining the table args.each do |arg| - unless arg.kind_of?(Hash) + unless arg.is_a?(Hash) raise(ArgumentError, "#{arg.class} of #{arg.inspect} is not of Hash type") end method = arg[METHOD] - if method == "unset" + if method == 'unset' nsb.removeConfiguration(arg[NAME]) - elsif method == "set" + elsif method == 'set' arg.delete(METHOD) - for k,v in arg + for k, v in arg v = v.to_s unless v.nil? nsb.addConfiguration(k, v) @@ -1183,10 +1172,9 @@ module Hbase raise(ArgumentError, "Unknown method #{method}") end end - @admin.modifyNamespace(nsb.build()); + @admin.modifyNamespace(nsb.build) end - #---------------------------------------------------------------------------------------------- # Drops a table def drop_namespace(namespace_name) @@ -1200,7 +1188,7 @@ module Hbase end # Abort a procedure - def abort_procedure?(proc_id, may_interrupt_if_running=nil) + def abort_procedure?(proc_id, may_interrupt_if_running = nil) if may_interrupt_if_running.nil? @admin.abortProcedure(proc_id, true) else @@ -1209,13 +1197,13 @@ module Hbase end # List all procedures - def list_procedures() - @admin.listProcedures() + def list_procedures + @admin.listProcedures end # List all locks - def list_locks() - @admin.listLocks(); + def list_locks + @admin.listLocks end # Parse arguments and update HTableDescriptor accordingly @@ -1239,20 +1227,20 @@ module Hbase #---------------------------------------------------------------------------------------------- # clear compaction queues def clear_compaction_queues(server_name, queue_name = nil) - names = ['long', 'short'] + names = %w[long short] queues = java.util.HashSet.new if queue_name.nil? queues.add('long') queues.add('short') - elsif queue_name.kind_of?(String) + elsif queue_name.is_a?(String) queues.add(queue_name) - if !(names.include?(queue_name)) + unless names.include?(queue_name) raise(ArgumentError, "Unknown queue name #{queue_name}") end - elsif queue_name.kind_of?(Array) + elsif queue_name.is_a?(Array) queue_name.each do |s| queues.add(s) - if !(names.include?(s)) + unless names.include?(s) raise(ArgumentError, "Unknown queue name #{s}") end end diff --git a/hbase-shell/src/main/ruby/hbase/hbase.rb b/hbase-shell/src/main/ruby/hbase/hbase.rb index bc5a31dc571..1f37f992723 100644 --- a/hbase-shell/src/main/ruby/hbase/hbase.rb +++ b/hbase-shell/src/main/ruby/hbase/hbase.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/hbase/quotas.rb b/hbase-shell/src/main/ruby/hbase/quotas.rb index a8a8e6ba80b..1ea8d28ad97 100644 --- a/hbase-shell/src/main/ruby/hbase/quotas.rb +++ b/hbase-shell/src/main/ruby/hbase/quotas.rb @@ -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] - else - # Parse a string a 1K, 2G, etc. - limit = _parse_size(args[LIMIT]) - end + limit = if args[LIMIT].is_a?(Numeric) + args[LIMIT] + else + # Parse a string a 1K, 2G, etc. + _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,52 +165,52 @@ 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) + def get_quota_snapshots(regionserver = nil) # Ask a regionserver if we were given one return get_rs_quota_snapshots(regionserver) if regionserver # Otherwise, read from the quota table 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(), - ServerName.valueOf(rs)) + 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,38 +263,38 @@ 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] - when 'sec' then time_unit = TimeUnit::SECONDS - when 'min' then time_unit = TimeUnit::MINUTES - when 'hour' then time_unit = TimeUnit::HOURS - when 'day' then time_unit = TimeUnit::DAYS + when 'sec' then time_unit = TimeUnit::SECONDS + when 'min' then time_unit = TimeUnit::MINUTES + when 'hour' then time_unit = TimeUnit::HOURS + when 'day' then time_unit = TimeUnit::DAYS end return type, limit, time_unit else - raise(ArgumentError, "Invalid throttle limit syntax") + raise(ArgumentError, 'Invalid throttle limit syntax') end end def _size_from_str(value, suffix) case suffix - when 'k' then value <<= 10 - when 'm' then value <<= 20 - when 'g' then value <<= 30 - when 't' then value <<= 40 - when 'p' then value <<= 50 + when 'k' then value <<= 10 + when 'm' then value <<= 20 + when 'g' then value <<= 30 + when 't' then value <<= 40 + when 'p' then value <<= 50 end - return value + value end end end diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index b9df821a52e..049f0c63a5b 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -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,14 +279,14 @@ module Hbase peers.each do |peer| map.put(peer.getPeerId, peer.getPeerConfig) end - return map + map end def get_peer_config(id) @admin.getReplicationPeerConfig(id) end - def update_peer_config(id, args={}) + def update_peer_config(id, args = {}) # Optional parameters config = args.fetch(CONFIG, nil) data = args.fetch(DATA, nil) @@ -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) diff --git a/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb b/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb index 3b71062d7a7..c8ef3e9e9f2 100644 --- a/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/hbase/security.rb b/hbase-shell/src/main/ruby/hbase/security.rb index 6dd1fe0efcf..63243fae9d3 100644 --- a/hbase-shell/src/main/ruby/hbase/security.rb +++ b/hbase-shell/src/main/ruby/hbase/security.rb @@ -26,7 +26,7 @@ module Hbase def initialize(admin) @admin = admin - @connection = @admin.getConnection() + @connection = @admin.getConnection end def close @@ -34,31 +34,33 @@ module Hbase end #---------------------------------------------------------------------------------------------- - def grant(user, permissions, table_name=nil, family=nil, qualifier=nil) + def grant(user, permissions, table_name = nil, family = nil, qualifier = nil) security_available? # TODO: need to validate user name 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) - tablebytes=table_name.to_java_bytes - #check if the tablename passed is actually a namespace - if (isNamespace?(table_name)) + if !table_name.nil? + tablebytes = table_name.to_java_bytes + # check if the tablename passed is actually a namespace + 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,100 +68,106 @@ module Hbase tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name) htd = @admin.getTableDescriptor(tableName) - if (family != nil) - raise(ArgumentError, "Can't find a family: #{family}") unless htd.hasFamily(family.to_java_bytes) + 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 #---------------------------------------------------------------------------------------------- - def revoke(user, table_name=nil, family=nil, qualifier=nil) + def revoke(user, table_name = nil, family = nil, qualifier = nil) security_available? # TODO: need to validate user name begin - if (table_name != nil) - #check if the tablename passed is actually a namespace - if (isNamespace?(table_name)) + if !table_name.nil? + # check if the tablename passed is actually a namespace + 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 + 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) + # Table should exist + raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name) - tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name) - htd = @admin.getTableDescriptor(tableName) + tableName = org.apache.hadoop.hbase.TableName.valueOf(table_name) + htd = @admin.getTableDescriptor(tableName) - if (family != nil) - raise(ArgumentError, "Can't find a family: #{family}") unless htd.hasFamily(family.to_java_bytes) - end + 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 #---------------------------------------------------------------------------------------------- - def user_permission(table_regex=nil) + 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 + 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() - else - 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) : - '' - qualifier = (value.getQualifier != nil) ? - org.apache.hadoop.hbase.util.Bytes::toStringBinary(value.getQualifier) : - '' + user_name = String.from_java_bytes(value.getUser) + if !table_regex.nil? && isNamespace?(table_regex) + namespace = value.getNamespace + else + 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) : + '' + qualifier = !value.getQualifier.nil? ? + org.apache.hadoop.hbase.util.Bytes.toStringBinary(value.getQualifier) : + '' - action = org.apache.hadoop.hbase.security.access.Permission.new value.getActions + action = org.apache.hadoop.hbase.security.access.Permission.new value.getActions - if block_given? - yield(user_name, "#{namespace},#{table},#{family},#{qualifier}: #{action.to_s}") - else - res[user_name] ||= {} - res[user_name]["#{family}:#{qualifier}"] = action - end - count += 1 + if block_given? + yield(user_name, "#{namespace},#{table},#{family},#{qualifier}: #{action}") + else + res[user_name] ||= {} + res[user_name]["#{family}:#{qualifier}"] = action + end + count += 1 end - return ((block_given?) ? count : res) + (block_given? ? count : res) end # Does table exist? @@ -171,15 +179,15 @@ module Hbase table_name.start_with?('@') end - # Does Namespace exist + # 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 diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index 0dda27a2a8d..b297f58d7ff 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -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 @@ -42,18 +42,18 @@ module Hbase # shell_command - name of the command in the shell # 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 + method = name.to_sym + class_eval do define_method method do |*args| - @shell.internal_command(shell_command, internal_method_name, self, *args) - end + @shell.internal_command(shell_command, internal_method_name, self, *args) + end end end # 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 @@ -131,21 +131,21 @@ EOF p = org.apache.hadoop.hbase.client.Put.new(row.to_s.to_java_bytes) family, qualifier = parse_column_name(column) if args.any? - attributes = args[ATTRIBUTES] - set_attributes(p, attributes) if attributes - visibility = args[VISIBILITY] - set_cell_visibility(p, visibility) if visibility - ttl = args[TTL] - set_op_ttl(p, ttl) if ttl + attributes = args[ATTRIBUTES] + set_attributes(p, attributes) if attributes + visibility = args[VISIBILITY] + set_cell_visibility(p, visibility) if visibility + ttl = args[TTL] + set_op_ttl(p, ttl) if ttl end - #Case where attributes are specified without timestamp - if timestamp.kind_of?(Hash) - timestamp.each do |k, v| + # Case where attributes are specified without timestamp + 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 @@ -162,36 +162,36 @@ EOF #---------------------------------------------------------------------------------------------- # Create a Delete mutation def _createdelete_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + 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 end if args.any? - visibility = args[VISIBILITY] - set_cell_visibility(d, visibility) if visibility + visibility = args[VISIBILITY] + set_cell_visibility(d, visibility) if visibility end if column 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"] + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + 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 @@ -218,20 +218,20 @@ EOF #---------------------------------------------------------------------------------------------- # Delete a cell def _delete_internal(row, column, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) _deleteall_internal(row, column, timestamp, args) end #---------------------------------------------------------------------------------------------- # Delete a row def _deleteall_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) # 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) @@ -241,19 +241,17 @@ EOF #---------------------------------------------------------------------------------------------- # Increment a counter atomically - def _incr_internal(row, column, value = nil, args={}) - if value.kind_of?(Hash) - value = 1 - end + def _incr_internal(row, column, value = nil, args = {}) + 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] - visibility = args[VISIBILITY] + attributes = args[ATTRIBUTES] + visibility = args[VISIBILITY] set_attributes(incr, attributes) if attributes set_cell_visibility(incr, visibility) if visibility ttl = args[TTL] @@ -265,21 +263,21 @@ EOF # Fetch cell value cell = result.listCells[0] - org.apache.hadoop.hbase.util.Bytes::toLong(cell.getValueArray, - cell.getValueOffset, cell.getValueLength) + org.apache.hadoop.hbase.util.Bytes.toLong(cell.getValueArray, + cell.getValueOffset, cell.getValueLength) end #---------------------------------------------------------------------------------------------- # appends the value atomically - def _append_internal(row, column, value, args={}) + def _append_internal(row, column, value, args = {}) 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] - visibility = args[VISIBILITY] + attributes = args[ATTRIBUTES] + visibility = args[VISIBILITY] set_attributes(append, attributes) if attributes set_cell_visibility(append, visibility) if visibility ttl = args[TTL] @@ -291,31 +289,30 @@ EOF # Fetch cell value cell = result.listCells[0] - org.apache.hadoop.hbase.util.Bytes::toStringBinary(cell.getValueArray, - cell.getValueOffset, cell.getValueLength) + 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,19 +343,19 @@ 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) - columns = [ args ].flatten.compact + 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 # # 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] - else - vers = 1 - end + vers = if args[VERSIONS] + args[VERSIONS] + else + 1 + end if columns # Normalize types, convert string to an array of strings - columns = [ columns ] if columns.is_a?(String) + 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 @@ -403,14 +400,14 @@ EOF get.setTimeRange(args[TIMERANGE][0], args[TIMERANGE][1]) if args[TIMERANGE] else if attributes - set_attributes(get, attributes) + set_attributes(get, attributes) elsif authorizations - set_authorizations(get, authorizations) + set_authorizations(get, authorizations) else - # May have passed TIMESTAMP and row only; wants all columns from ts. - unless ts = args[TIMESTAMP] || tr = args[TIMERANGE] - raise ArgumentError, "Failed parse of #{args.inspect}, #{args.class}" - end + # May have passed TIMESTAMP and row only; wants all columns from ts. + unless ts = args[TIMESTAMP] || tr = args[TIMERANGE] + raise ArgumentError, "Failed parse of #{args.inspect}, #{args.class}" + end end get.setMaxVersions(vers) @@ -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 @@ -444,9 +442,9 @@ EOF res = {} result.listCells.each do |c| family = convert_bytes_with_position(c.getFamilyArray, - c.getFamilyOffset, c.getFamilyLength, converter_class, converter) + c.getFamilyOffset, c.getFamilyLength, converter_class, converter) qualifier = convert_bytes_with_position(c.getQualifierArray, - c.getQualifierOffset, c.getQualifierLength, converter_class, converter) + c.getQualifierOffset, c.getQualifierLength, converter_class, converter) column = "#{family}:#{qualifier}" value = to_string(column, c, maxlength, converter_class, converter) @@ -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,48 +475,48 @@ EOF # Fetch cell value cell = result.listCells[0] - org.apache.hadoop.hbase.util.Bytes::toLong(cell.getValueArray, - cell.getValueOffset, cell.getValueLength) + 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 - org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes) - else - org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes) + org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes) + else + org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes) end # This will overwrite any startrow/stoprow settings 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 @@ -586,9 +585,9 @@ EOF row.listCells.each do |c| family = convert_bytes_with_position(c.getFamilyArray, - c.getFamilyOffset, c.getFamilyLength, converter_class, converter) + c.getFamilyOffset, c.getFamilyLength, converter_class, converter) qualifier = convert_bytes_with_position(c.getQualifierArray, - c.getQualifierOffset, c.getQualifierLength, converter_class, converter) + c.getQualifierOffset, c.getQualifierLength, converter_class, converter) column = "#{family}:#{qualifier}" cell = to_string(column, c, maxlength, converter_class, converter) @@ -609,25 +608,26 @@ 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 + # Apply OperationAttributes to puts/scans/gets def set_attributes(oprattr, attributes) - raise(ArgumentError, "Attributes must be a Hash type") unless attributes.kind_of?(Hash) - for k,v in attributes + 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) end 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| + 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) - auths = [ authorizations ].flatten.compact + 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) @@ -664,14 +668,14 @@ EOF end end - #Add the following admin utilities to the table + # Add the following admin utilities to the table add_admin_utils :enable, :disable, :flush, :drop, :describe, :snapshot #---------------------------- - #give the general help for the table + # give the general help for the table # or the named command - def help (command = nil) - #if there is a command, get the per-command help from the shell + def help(command = nil) + # if there is a command, get the per-command help from the shell if command begin return @shell.help_command(command) @@ -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,51 +711,51 @@ 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) + 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] + kv.getValueOffset, kv.getValueLength) + return format('timestamp=%d, value=%s', kv.getTimestamp, hri.toString) end if column == 'info:serverstartcode' if kv.getValueLength > 0 - str_val = org.apache.hadoop.hbase.util.Bytes.toLong(kv.getValueArray, - kv.getValueOffset, kv.getValueLength) + str_val = org.apache.hadoop.hbase.util.Bytes.toLong(kv.getValueArray, + kv.getValueOffset, kv.getValueLength) else str_val = org.apache.hadoop.hbase.util.Bytes.toStringBinary(kv.getValueArray, - kv.getValueOffset, kv.getValueLength) + 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') - #use org.apache.hadoop.hbase.util.Bytes as the default class + def convert(column, kv, converter_class = 'org.apache.hadoop.hbase.util.Bytes', converter = 'toStringBinary') + # use org.apache.hadoop.hbase.util.Bytes as the default class converter_class = 'org.apache.hadoop.hbase.util.Bytes' unless converter_class - #use org.apache.hadoop.hbase.util.Bytes::toStringBinary as the default convertor + # 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? @@ -767,7 +771,7 @@ EOF convert_bytes(org.apache.hadoop.hbase.CellUtil.cloneValue(kv), klazz_name, converter) end - def convert_bytes(bytes, converter_class=nil, converter_method=nil) + def convert_bytes(bytes, converter_class = nil, converter_method = nil) convert_bytes_with_position(bytes, 0, bytes.length, converter_class, converter_method) end @@ -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 diff --git a/hbase-shell/src/main/ruby/hbase/taskmonitor.rb b/hbase-shell/src/main/ruby/hbase/taskmonitor.rb index d312558a35d..849752b6af2 100644 --- a/hbase-shell/src/main/ruby/hbase/taskmonitor.rb +++ b/hbase-shell/src/main/ruby/hbase/taskmonitor.rb @@ -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| + def initialize(taskMap, host) + taskMap.each_pair do |k, v| case k - when "statustimems" - @statustime = Time.at(v/1000) - when "status" - @status = v - when "starttimems" - @starttime = Time.at(v/1000) - when "description" - @description = v - when "state" - @state = v + when 'statustimems' + @statustime = Time.at(v / 1000) + when 'status' + @status = v + when 'starttimems' + @starttime = Time.at(v / 1000) + when 'description' + @description = v + 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,120 +62,111 @@ 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) - + 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, + # if (!@admin.getConfiguration().getBoolean(org.apache.hadoop.hbase.http.ServerConfigurationKeys::HBASE_SSL_ENABLED_KEY, # org.apache.hadoop.hbase.http.ServerConfigurationKeys::HBASE_SSL_ENABLED_DEFAULT)) # schema = "http://" - #else + # else # schema = "https://" - #end - schema = "http://" - url = schema + host.hostname + ":" + infoport + "/rs-status?format=json&filter=" + filter + # end + schema = 'http://' + url = schema + host.hostname + ':' + infoport + '/rs-status?format=json&filter=' + filter json = URL.new(url) mapper = ObjectMapper.new # read and parse JSON - tasksArrayList = mapper.readValue(json,java.lang.Object.java_class) + 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) + tasks.unshift Task.new(t, host) end - return tasks - + tasks end #--------------------------------------------------------------------------------------------------- # Prints a table of filtered tasks on requested hosts - def tasks(filter,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)) + 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 longestStatusWidth = 0 longestDescriptionWidth = 0 tasks.each do |t| - longestStatusWidth = [longestStatusWidth,t.status.length].max - longestDescriptionWidth = [longestDescriptionWidth,t.description.length].max + longestStatusWidth = [longestStatusWidth, t.status.length].max + longestDescriptionWidth = [longestDescriptionWidth, t.description.length].max end # set the maximum character width of each column, without padding hostWidth = 15 startTimeWidth = 19 stateWidth = 8 - descriptionWidth = [32,longestDescriptionWidth].min - statusWidth = [36,longestStatusWidth + 27].min + 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.state, stateWidth), + setCellWidth(t.description, descriptionWidth), + setCellWidth(format('%s (since %d seconds ago)', t.status, Time.now - t.statustime), statusWidth)] - cells = [setCellWidth(t.host.hostname,hostWidth), - 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)] - - line = "| %s | %s | %s | %s | %s |" % cells + line = format('| %s | %s | %s | %s | %s |', cells) puts(rowSeparator) puts(line) - end puts(rowSeparator) end - end #--------------------------------------------------------------------------------------------------- @@ -189,16 +175,15 @@ module Hbase # # right-pad with spaces or truncate with ellipses to match passed width - def setCellWidth(cellContent,width) - numCharsTooShort = width-cellContent.length + def setCellWidth(cellContent, width) + 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 diff --git a/hbase-shell/src/main/ruby/hbase/visibility_labels.rb b/hbase-shell/src/main/ruby/hbase/visibility_labels.rb index 8e6c93c2a00..e2ae2cad35c 100644 --- a/hbase-shell/src/main/ruby/hbase/visibility_labels.rb +++ b/hbase-shell/src/main/ruby/hbase/visibility_labels.rb @@ -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()) - end - end - if labelsWithException.length > 0 - raise(ArgumentError, labelsWithException) - end + if result.hasException + labelsWithException += Bytes.toString(result.getException.getValue.toByteArray) + end + 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()) - end - end - if labelsWithException.length > 0 - raise(ArgumentError, labelsWithException) + if result.hasException + labelsWithException += Bytes.toString(result.getException.getValue.toByteArray) + end 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()) - end - end - if labelsWithException.length > 0 - raise(ArgumentError, labelsWithException) + if result.hasException + labelsWithException += Bytes.toString(result.getException.getValue.toByteArray) + end 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 diff --git a/hbase-shell/src/main/ruby/hbase_constants.rb b/hbase-shell/src/main/ruby/hbase_constants.rb index 55806cf4f72..ebaae78e9bb 100644 --- a/hbase-shell/src/main/ruby/hbase_constants.rb +++ b/hbase-shell/src/main/ruby/hbase_constants.rb @@ -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) diff --git a/hbase-shell/src/main/ruby/irb/hirb.rb b/hbase-shell/src/main/ruby/irb/hirb.rb index 4d6d2771728..904a0001019 100644 --- a/hbase-shell/src/main/ruby/irb/hirb.rb +++ b/hbase-shell/src/main/ruby/irb/hirb.rb @@ -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") - $stdout = f - super - ensure - f.close() - $stdout = STDOUT - end + + # 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') + $stdout = f + super + ensure + f.close + $stdout = STDOUT 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 diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index ab4d5149d5c..469505fb245 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -29,7 +29,7 @@ module Shell @@command_groups end - def self.load_command(name, group, aliases=[]) + def self.load_command(name, group, aliases = []) return if commands[name] # Register command in the group @@ -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] || {} @@ -76,18 +76,18 @@ module Shell @debug = false attr_accessor :debug - def initialize(hbase, interactive=true) + def initialize(hbase, interactive = true) self.hbase = hbase self.interactive = interactive end # 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 @@ -151,8 +151,8 @@ module Shell # command - name of the command to call # 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) + def internal_command(command, method_name = :command, *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,23 +200,23 @@ 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" + - "Commands are grouped. Type 'help \"COMMAND_GROUP\"', (e.g. 'help \"general\"') for help on a command group." + "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 def help_footer @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 5f7a2e621f2..94b5667395c 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -22,12 +22,11 @@ require 'shell/formatter' module Shell module Commands class Command - def initialize(shell) @shell = shell end - #wrap an execution of cmd to catch hbase exceptions + # wrap an execution of cmd to catch hbase exceptions # cmd - command name to execute # args - arguments to pass to the command def command_safe(debug, cmd = :command, *args) @@ -35,7 +34,7 @@ module Shell # See count.rb for example. @start_time = Time.now # send is internal ruby method to call 'cmd' with *args - #(everything is a message, so this is just the formal semantics to support that idiom) + # (everything is a message, so this is just the formal semantics to support that idiom) translate_hbase_exceptions(*args) { send(cmd, *args) } rescue => e rootCause = e @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/abort_procedure.rb b/hbase-shell/src/main/ruby/shell/commands/abort_procedure.rb index e69e1339c4a..28c7d8525d6 100644 --- a/hbase-shell/src/main/ruby/shell/commands/abort_procedure.rb +++ b/hbase-shell/src/main/ruby/shell/commands/abort_procedure.rb @@ -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. @@ -39,9 +39,9 @@ Examples: EOF end - def command(proc_id, may_interrupt_if_running=nil) + def command(proc_id, may_interrupt_if_running = nil) formatter.row([admin.abort_procedure?(proc_id, may_interrupt_if_running).to_s]) end end end -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell/commands/add_labels.rb b/hbase-shell/src/main/ruby/shell/commands/add_labels.rb index 7bde5fb1c50..b021b927855 100644 --- a/hbase-shell/src/main/ruby/shell/commands/add_labels.rb +++ b/hbase-shell/src/main/ruby/shell/commands/add_labels.rb @@ -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] diff --git a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb index 077bd69ea92..edaa386fb25 100644 --- a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb @@ -19,9 +19,9 @@ module Shell module Commands - class AddPeer< Command + 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. diff --git a/hbase-shell/src/main/ruby/shell/commands/add_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/add_rsgroup.rb index 9a97f694bbf..ab32d056913 100644 --- a/hbase-shell/src/main/ruby/shell/commands/add_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/add_rsgroup.rb @@ -22,7 +22,7 @@ module Shell module Commands class AddRsgroup < Command def help - return <<-EOF + <<-EOF Create a new RegionServer group. Example: diff --git a/hbase-shell/src/main/ruby/shell/commands/alter.rb b/hbase-shell/src/main/ruby/shell/commands/alter.rb index 8d6b6ca2a9f..2207111d8d7 100644 --- a/hbase-shell/src/main/ruby/shell/commands/alter.rb +++ b/hbase-shell/src/main/ruby/shell/commands/alter.rb @@ -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. diff --git a/hbase-shell/src/main/ruby/shell/commands/alter_async.rb b/hbase-shell/src/main/ruby/shell/commands/alter_async.rb index 05335fb101c..824de1082b5 100644 --- a/hbase-shell/src/main/ruby/shell/commands/alter_async.rb +++ b/hbase-shell/src/main/ruby/shell/commands/alter_async.rb @@ -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. diff --git a/hbase-shell/src/main/ruby/shell/commands/alter_namespace.rb b/hbase-shell/src/main/ruby/shell/commands/alter_namespace.rb index 0051c7f11ef..602ac6fb384 100644 --- a/hbase-shell/src/main/ruby/shell/commands/alter_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/alter_namespace.rb @@ -21,7 +21,7 @@ module Shell module Commands class AlterNamespace < Command def help - return <<-EOF + <<-EOF Alter namespace properties. To add/modify a property: diff --git a/hbase-shell/src/main/ruby/shell/commands/alter_status.rb b/hbase-shell/src/main/ruby/shell/commands/alter_status.rb index 72f044dbbaa..828482585cb 100644 --- a/hbase-shell/src/main/ruby/shell/commands/alter_status.rb +++ b/hbase-shell/src/main/ruby/shell/commands/alter_status.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/append.rb b/hbase-shell/src/main/ruby/shell/commands/append.rb index c2fb9c19abb..a7273ca4edf 100644 --- a/hbase-shell/src/main/ruby/shell/commands/append.rb +++ b/hbase-shell/src/main/ruby/shell/commands/append.rb @@ -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'} @@ -35,13 +35,13 @@ t to table 't1', the corresponding command would be: EOF end - def command(table_name, row, column, value, args={}) + def command(table_name, row, column, value, args = {}) table = table(table_name) @start_time = Time.now append(table, row, column, value, args) end - def append(table, row, column, value, args={}) + def append(table, row, column, value, args = {}) if current_value = table._append_internal(row, column, value, args) puts "CURRENT VALUE = #{current_value}" end @@ -50,5 +50,5 @@ EOF end end -#add incr comamnd to Table -::Hbase::Table.add_shell_command("append") +# add incr comamnd to Table +::Hbase::Table.add_shell_command('append') diff --git a/hbase-shell/src/main/ruby/shell/commands/append_peer_namespaces.rb b/hbase-shell/src/main/ruby/shell/commands/append_peer_namespaces.rb index 25857548883..f48cd46b7ef 100644 --- a/hbase-shell/src/main/ruby/shell/commands/append_peer_namespaces.rb +++ b/hbase-shell/src/main/ruby/shell/commands/append_peer_namespaces.rb @@ -20,9 +20,9 @@ module Shell module Commands - class AppendPeerNamespaces< Command + 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb index fe34c5c73e2..0dbf2d72dd0 100644 --- a/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/append_peer_tableCFs.rb @@ -19,9 +19,9 @@ module Shell module Commands - class AppendPeerTableCFs< Command + class AppendPeerTableCFs < Command def help - return <<-EOF + <<-EOF Append a replicable table-cf config for the specified peer Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/assign.rb b/hbase-shell/src/main/ruby/shell/commands/assign.rb index 1220bf1e060..da4fc69f68f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/assign.rb +++ b/hbase-shell/src/main/ruby/shell/commands/assign.rb @@ -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: diff --git a/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb index 5f7e561fcc0..a223e055bbf 100644 --- a/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/balance_switch.rb b/hbase-shell/src/main/ruby/shell/commands/balance_switch.rb index 4076cf61e93..332ac3b0559 100644 --- a/hbase-shell/src/main/ruby/shell/commands/balance_switch.rb +++ b/hbase-shell/src/main/ruby/shell/commands/balance_switch.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/balancer.rb b/hbase-shell/src/main/ruby/shell/commands/balancer.rb index a7490a51c65..276a0a69743 100644 --- a/hbase-shell/src/main/ruby/shell/commands/balancer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/balancer.rb @@ -21,9 +21,9 @@ 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). +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). Parameter tells master whether we should force balance even if there is region in transition. @@ -37,14 +37,14 @@ Examples: EOF end - def command(force=nil) + def command(force = nil) force_balancer = 'false' if force == 'force' force_balancer = 'true' 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb index c3d7a2b404b..a2884c4c5f9 100644 --- a/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb +++ b/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_enabled.rb index fdeb67e857f..22e26e96e38 100644 --- a/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_enabled.rb +++ b/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_enabled.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_run.rb b/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_run.rb index 638a18f4d51..32f9f6a6204 100644 --- a/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_run.rb +++ b/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_run.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_switch.rb b/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_switch.rb index d2d8e58696c..48fedc36095 100644 --- a/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_switch.rb +++ b/hbase-shell/src/main/ruby/shell/commands/catalogjanitor_switch.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_enabled.rb index 6ae4a245cf7..9fad7a01783 100644 --- a/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_enabled.rb +++ b/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_enabled.rb @@ -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,9 +28,9 @@ 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 -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_run.rb b/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_run.rb index 9ade9c99ed5..210f3889bb9 100644 --- a/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_run.rb +++ b/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_run.rb @@ -20,16 +20,17 @@ 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 -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_switch.rb b/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_switch.rb index 20241ec0c29..609978d2932 100644 --- a/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_switch.rb +++ b/hbase-shell/src/main/ruby/shell/commands/cleaner_chore_switch.rb @@ -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,8 +30,8 @@ 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 -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell/commands/clear_auths.rb b/hbase-shell/src/main/ruby/shell/commands/clear_auths.rb index be56d5d1095..9cd0a2b328b 100644 --- a/hbase-shell/src/main/ruby/shell/commands/clear_auths.rb +++ b/hbase-shell/src/main/ruby/shell/commands/clear_auths.rb @@ -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] diff --git a/hbase-shell/src/main/ruby/shell/commands/clear_compaction_queues.rb b/hbase-shell/src/main/ruby/shell/commands/clear_compaction_queues.rb index 21668d39d4d..7a5c374b965 100644 --- a/hbase-shell/src/main/ruby/shell/commands/clear_compaction_queues.rb +++ b/hbase-shell/src/main/ruby/shell/commands/clear_compaction_queues.rb @@ -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. @@ -38,4 +38,4 @@ module Shell end end end -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb index f95c6524a26..6d9c5ded2e4 100644 --- a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb @@ -20,8 +20,8 @@ module Shell module Commands class CloneSnapshot < Command def help - return <<-EOF -Create a new table by cloning the snapshot content. + <<-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 diff --git a/hbase-shell/src/main/ruby/shell/commands/close_region.rb b/hbase-shell/src/main/ruby/shell/commands/close_region.rb index 3d019113e59..e33dd7948d7 100644 --- a/hbase-shell/src/main/ruby/shell/commands/close_region.rb +++ b/hbase-shell/src/main/ruby/shell/commands/close_region.rb @@ -21,20 +21,20 @@ 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' to be a fully qualified region name. When asking the hosting regionserver to directly close a region, you pass the regions' encoded name only. A region name looks like this: - + TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396. or Namespace:TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396. The trailing period is part of the regionserver name. A region's encoded name -is the hash at the end of a region name; e.g. 527db22f95c8a9e0116f0cc13c680396 +is the hash at the end of a region name; e.g. 527db22f95c8a9e0116f0cc13c680396 (without the period). A 'SERVER_NAME' is its host, port plus startcode. For example: host187.example.com,60020,1289493121758 (find servername in master ui or when you do detailed status in shell). This command will end up running diff --git a/hbase-shell/src/main/ruby/shell/commands/compact.rb b/hbase-shell/src/main/ruby/shell/commands/compact.rb index 160753643b9..a1c44c3b604 100644 --- a/hbase-shell/src/main/ruby/shell/commands/compact.rb +++ b/hbase-shell/src/main/ruby/shell/commands/compact.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/compact_rs.rb b/hbase-shell/src/main/ruby/shell/commands/compact_rs.rb index 5f0294479a3..f10230af8b8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/compact_rs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/compact_rs.rb @@ -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: diff --git a/hbase-shell/src/main/ruby/shell/commands/compaction_state.rb b/hbase-shell/src/main/ruby/shell/commands/compaction_state.rb index fbcdc7edbe0..91bd79d1880 100644 --- a/hbase-shell/src/main/ruby/shell/commands/compaction_state.rb +++ b/hbase-shell/src/main/ruby/shell/commands/compaction_state.rb @@ -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' diff --git a/hbase-shell/src/main/ruby/shell/commands/count.rb b/hbase-shell/src/main/ruby/shell/commands/count.rb index 2f2562bf23b..03840d0a0d6 100644 --- a/hbase-shell/src/main/ruby/shell/commands/count.rb +++ b/hbase-shell/src/main/ruby/shell/commands/count.rb @@ -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 = { @@ -71,14 +71,14 @@ EOF @start_time = Time.now formatter.header count = table._count_internal(params['INTERVAL'].to_i, scan) do |cnt, row| - formatter.row([ "Current count: #{cnt}, row: #{row}" ]) + 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") +# Add the method table.count that calls count.count +::Hbase::Table.add_shell_command('count') diff --git a/hbase-shell/src/main/ruby/shell/commands/create.rb b/hbase-shell/src/main/ruby/shell/commands/create.rb index 4812048062b..14a3942196f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/create.rb +++ b/hbase-shell/src/main/ruby/shell/commands/create.rb @@ -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,9 +65,9 @@ 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 + # and then return the table just created table(table) end end diff --git a/hbase-shell/src/main/ruby/shell/commands/create_namespace.rb b/hbase-shell/src/main/ruby/shell/commands/create_namespace.rb index d478fc1665d..62a3bc21c2f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/create_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/create_namespace.rb @@ -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: diff --git a/hbase-shell/src/main/ruby/shell/commands/delete.rb b/hbase-shell/src/main/ruby/shell/commands/delete.rb index bce66255317..3e4447c6b2c 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete.rb @@ -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 @@ -54,5 +54,5 @@ EOF end end -#Add the method table.delete that calls delete.delete -::Hbase::Table.add_shell_command("delete") +# Add the method table.delete that calls delete.delete +::Hbase::Table.add_shell_command('delete') diff --git a/hbase-shell/src/main/ruby/shell/commands/delete_all_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/delete_all_snapshot.rb index 5a77f7398ab..52276fc9c79 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete_all_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete_all_snapshot.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb index 48059b0d3e0..85c73fb3f73 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb @@ -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', diff --git a/hbase-shell/src/main/ruby/shell/commands/delete_table_snapshots.rb b/hbase-shell/src/main/ruby/shell/commands/delete_table_snapshots.rb index 89936f18cdd..a7875f10234 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete_table_snapshots.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete_table_snapshots.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb index 033ec6745df..f5444aef1ed 100644 --- a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb +++ b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb @@ -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: @@ -64,5 +64,5 @@ EOF end end -#Add the method table.deleteall that calls deleteall.deleteall -::Hbase::Table.add_shell_command("deleteall") +# Add the method table.deleteall that calls deleteall.deleteall +::Hbase::Table.add_shell_command('deleteall') diff --git a/hbase-shell/src/main/ruby/shell/commands/describe.rb b/hbase-shell/src/main/ruby/shell/commands/describe.rb index 37938a7c89a..3268b2f7228 100644 --- a/hbase-shell/src/main/ruby/shell/commands/describe.rb +++ b/hbase-shell/src/main/ruby/shell/commands/describe.rb @@ -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) + formatter.row([column_family.to_s], true) end - formatter.footer() + formatter.footer end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/describe_namespace.rb b/hbase-shell/src/main/ruby/shell/commands/describe_namespace.rb index ebd9bd2a593..55261d6bdc2 100644 --- a/hbase-shell/src/main/ruby/shell/commands/describe_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/describe_namespace.rb @@ -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,8 +30,8 @@ EOF def command(namespace) desc = admin.describe_namespace(namespace) - formatter.header([ "DESCRIPTION" ], [ 64 ]) - formatter.row([ desc ], true, [ 64 ]) + formatter.header(['DESCRIPTION'], [64]) + formatter.row([desc], true, [64]) end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/disable.rb b/hbase-shell/src/main/ruby/shell/commands/disable.rb index 66950020085..79be0a21dfa 100644 --- a/hbase-shell/src/main/ruby/shell/commands/disable.rb +++ b/hbase-shell/src/main/ruby/shell/commands/disable.rb @@ -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' diff --git a/hbase-shell/src/main/ruby/shell/commands/disable_all.rb b/hbase-shell/src/main/ruby/shell/commands/disable_all.rb index 212db249a8a..b4c5a39f407 100644 --- a/hbase-shell/src/main/ruby/shell/commands/disable_all.rb +++ b/hbase-shell/src/main/ruby/shell/commands/disable_all.rb @@ -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.*' @@ -34,16 +34,16 @@ EOF list = admin.list(regex) count = list.size list.each do |table| - formatter.row([ table ]) + formatter.row([table]) end 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/disable_peer.rb b/hbase-shell/src/main/ruby/shell/commands/disable_peer.rb index c193f13864a..102731667ca 100644 --- a/hbase-shell/src/main/ruby/shell/commands/disable_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/disable_peer.rb @@ -19,9 +19,9 @@ module Shell module Commands - class DisablePeer< Command + 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. diff --git a/hbase-shell/src/main/ruby/shell/commands/disable_table_replication.rb b/hbase-shell/src/main/ruby/shell/commands/disable_table_replication.rb index a020d81a30e..0e903ac8f76 100644 --- a/hbase-shell/src/main/ruby/shell/commands/disable_table_replication.rb +++ b/hbase-shell/src/main/ruby/shell/commands/disable_table_replication.rb @@ -18,9 +18,9 @@ module Shell module Commands - class DisableTableReplication< Command + class DisableTableReplication < Command def help - return <<-EOF + <<-EOF Disable a table's replication switch. Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/drop.rb b/hbase-shell/src/main/ruby/shell/commands/drop.rb index 3f7332c59cc..063eb32773e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/drop.rb +++ b/hbase-shell/src/main/ruby/shell/commands/drop.rb @@ -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' diff --git a/hbase-shell/src/main/ruby/shell/commands/drop_all.rb b/hbase-shell/src/main/ruby/shell/commands/drop_all.rb index 73398fbf6e5..5c40dfd134a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/drop_all.rb +++ b/hbase-shell/src/main/ruby/shell/commands/drop_all.rb @@ -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.*' @@ -34,16 +34,16 @@ EOF list = admin.list(regex) count = list.size list.each do |table| - formatter.row([ table ]) + formatter.row([table]) end 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/drop_namespace.rb b/hbase-shell/src/main/ruby/shell/commands/drop_namespace.rb index 392f24789b9..e667c2ae219 100644 --- a/hbase-shell/src/main/ruby/shell/commands/drop_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/drop_namespace.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/enable.rb b/hbase-shell/src/main/ruby/shell/commands/enable.rb index 5d21219c85b..13598ecdf54 100644 --- a/hbase-shell/src/main/ruby/shell/commands/enable.rb +++ b/hbase-shell/src/main/ruby/shell/commands/enable.rb @@ -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' diff --git a/hbase-shell/src/main/ruby/shell/commands/enable_all.rb b/hbase-shell/src/main/ruby/shell/commands/enable_all.rb index 2b899f2ac07..a58f1187a52 100644 --- a/hbase-shell/src/main/ruby/shell/commands/enable_all.rb +++ b/hbase-shell/src/main/ruby/shell/commands/enable_all.rb @@ -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.*' @@ -34,16 +34,16 @@ EOF list = admin.list(regex) count = list.size list.each do |table| - formatter.row([ table ]) + formatter.row([table]) end 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/enable_peer.rb b/hbase-shell/src/main/ruby/shell/commands/enable_peer.rb index 5f1a7273737..19cf7af26f2 100644 --- a/hbase-shell/src/main/ruby/shell/commands/enable_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/enable_peer.rb @@ -19,9 +19,9 @@ module Shell module Commands - class EnablePeer< Command + class EnablePeer < Command def help - return <<-EOF + <<-EOF Restarts the replication to the specified peer cluster, continuing from where it was disabled. diff --git a/hbase-shell/src/main/ruby/shell/commands/enable_table_replication.rb b/hbase-shell/src/main/ruby/shell/commands/enable_table_replication.rb index e4e2fc1fbbe..47eb649de8a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/enable_table_replication.rb +++ b/hbase-shell/src/main/ruby/shell/commands/enable_table_replication.rb @@ -18,9 +18,9 @@ module Shell module Commands - class EnableTableReplication< Command + class EnableTableReplication < Command def help - return <<-EOF + <<-EOF Enable a table's replication switch. Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/exists.rb b/hbase-shell/src/main/ruby/shell/commands/exists.rb index 4eb13a47044..1471d4aa65f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/exists.rb +++ b/hbase-shell/src/main/ruby/shell/commands/exists.rb @@ -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,8 +31,8 @@ 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 end diff --git a/hbase-shell/src/main/ruby/shell/commands/flush.rb b/hbase-shell/src/main/ruby/shell/commands/flush.rb index 13963e19d1c..4165b84e385 100644 --- a/hbase-shell/src/main/ruby/shell/commands/flush.rb +++ b/hbase-shell/src/main/ruby/shell/commands/flush.rb @@ -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: diff --git a/hbase-shell/src/main/ruby/shell/commands/get.rb b/hbase-shell/src/main/ruby/shell/commands/get.rb index 6b9ad424fa5..cdf429996b8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get.rb @@ -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: @@ -44,14 +44,14 @@ a dictionary of column(s), timestamp, timerange and versions. Examples: Besides the default 'toStringBinary' format, 'get' also supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in the get -specification. The FORMATTER can be stipulated: +specification. The FORMATTER can be stipulated: 1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString) 2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'. -Example formatting cf:qualifier1 and cf:qualifier2 both as Integers: +Example formatting cf:qualifier1 and cf:qualifier2 both as Integers: hbase> get 't1', 'r1' {COLUMN => ['cf:qualifier1:toInt', - 'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] } + 'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] } Note that you can specify a FORMATTER by column only (cf:qualifier). You can set a formatter for all columns (including, all key parts) using the "FORMATTER" @@ -60,7 +60,7 @@ and "FORMATTER_CLASS" options. The default "FORMATTER_CLASS" is hbase> get 't1', 'r1', {FORMATTER => 'toString'} hbase> get 't1', 'r1', {FORMATTER_CLASS => 'org.apache.hadoop.hbase.util.Bytes', FORMATTER => 'toString'} - + The same commands also can be run on a reference to a table (obtained via get_table or create_table). Suppose you had a reference t to table 't1', the corresponding commands would be: @@ -87,10 +87,10 @@ 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 ]) + formatter.row([column, value]) end formatter.footer(count, is_stale) @@ -99,5 +99,5 @@ EOF end end -#add get command to table +# add get command to table ::Hbase::Table.add_shell_command('get') diff --git a/hbase-shell/src/main/ruby/shell/commands/get_auths.rb b/hbase-shell/src/main/ruby/shell/commands/get_auths.rb index 4ea1b2ec13d..80e7aeb128d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_auths.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_auths.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/get_counter.rb b/hbase-shell/src/main/ruby/shell/commands/get_counter.rb index 6708c6a5d31..12ab4b2f2bb 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_counter.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_counter.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb b/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb index 6417980b909..81f738ebcb9 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb @@ -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,19 +35,14 @@ 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 -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell/commands/get_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/get_rsgroup.rb index 15a363bf86e..a18083f6bed 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_rsgroup.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/get_server_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/get_server_rsgroup.rb index 61c13a2c117..042af2d19d3 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_server_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_server_rsgroup.rb @@ -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: diff --git a/hbase-shell/src/main/ruby/shell/commands/get_splits.rb b/hbase-shell/src/main/ruby/shell/commands/get_splits.rb index 8b6ae825834..91307c2026f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_splits.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_splits.rb @@ -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") \ No newline at end of file +::Hbase::Table.add_shell_command('get_splits') diff --git a/hbase-shell/src/main/ruby/shell/commands/get_table.rb b/hbase-shell/src/main/ruby/shell/commands/get_table.rb index 2270f43f958..6ad4f33e3e1 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_table.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_table.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/get_table_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/get_table_rsgroup.rb index c03af1fa856..dd48ca93c1c 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_table_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_table_rsgroup.rb @@ -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: @@ -31,7 +31,7 @@ EOF def command(table) group_name = - rsgroup_admin.get_rsgroup_of_table(table).getName + rsgroup_admin.get_rsgroup_of_table(table).getName formatter.row([group_name]) formatter.footer(1) end diff --git a/hbase-shell/src/main/ruby/shell/commands/grant.rb b/hbase-shell/src/main/ruby/shell/commands/grant.rb index d6f848b4237..956489a65bf 100644 --- a/hbase-shell/src/main/ruby/shell/commands/grant.rb +++ b/hbase-shell/src/main/ruby/shell/commands/grant.rb @@ -20,15 +20,15 @@ module Shell module Commands class Grant < Command def help - return <<-EOF + <<-EOF Grant users specific rights. Syntax : grant , [, <@namespace> [, [, [, ]]] permissions is either zero or more letters from the set "RWXCA". READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A') -Note: Groups and users are granted access in the same way, but groups are prefixed with an '@' - character. In the same way, tables and namespaces are specified, but namespaces are +Note: Groups and users are granted access in the same way, but groups are prefixed with an '@' + character. In the same way, tables and namespaces are specified, but namespaces are prefixed with an '@' character. For example: @@ -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) - 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) - 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 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 + unless family.nil? + raise(ArgumentError, 'Family is not of String type') unless family.is_a?(String) + qualifier = args[4] # will be nil if unset + 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") + raise(ArgumentError, 'Second argument should be a String or Hash') end - end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/incr.rb b/hbase-shell/src/main/ruby/shell/commands/incr.rb index 318fac3e722..f1c31210af8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/incr.rb +++ b/hbase-shell/src/main/ruby/shell/commands/incr.rb @@ -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: @@ -48,16 +48,16 @@ EOF incr(table(table), row, column, value, args) end - def incr(table, row, column, value = nil, args={}) + def incr(table, row, column, value = nil, args = {}) 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 end end -#add incr comamnd to Table -::Hbase::Table.add_shell_command("incr") +# add incr comamnd to Table +::Hbase::Table.add_shell_command('incr') diff --git a/hbase-shell/src/main/ruby/shell/commands/is_disabled.rb b/hbase-shell/src/main/ruby/shell/commands/is_disabled.rb index 6a914e36929..20af00c152b 100644 --- a/hbase-shell/src/main/ruby/shell/commands/is_disabled.rb +++ b/hbase-shell/src/main/ruby/shell/commands/is_disabled.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb index da9c5667bfb..fa122db374d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb +++ b/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list.rb b/hbase-shell/src/main/ruby/shell/commands/list.rb index dc3d1687ee7..676b5bfd227 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list.rb @@ -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,16 +32,16 @@ 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| - formatter.row([ table ]) + formatter.row([table]) end formatter.footer(list.size) - return list + list end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/list_labels.rb b/hbase-shell/src/main/ruby/shell/commands/list_labels.rb index 6b730b2c03a..8619642351a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_labels.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_labels.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_locks.rb b/hbase-shell/src/main/ruby/shell/commands/list_locks.rb index fca411bbd0d..a7f7b7344a5 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_locks.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_locks.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb b/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb index 63aeac1de96..131337f4821 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb @@ -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,12 +30,12 @@ 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| - formatter.row([ table ]) + formatter.row([table]) end formatter.footer(list.size) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb b/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb index 30d4db00318..ff08568ee4e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb @@ -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,11 +30,11 @@ EOF end def command(namespace) - formatter.header([ "TABLE" ]) + formatter.header(['TABLE']) list = admin.list_namespace_tables(namespace) list.each do |table| - formatter.row([ table ]) + formatter.row([table]) end formatter.footer(list.size) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb b/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb index 8946e39b30e..12fb301862e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_peers.rb b/hbase-shell/src/main/ruby/shell/commands/list_peers.rb index 2dd848375ad..04453c24ed9 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_peers.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_peers.rb @@ -20,33 +20,33 @@ module Shell module Commands - class ListPeers< Command + 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) - formatter.row([ id, config.getClusterKey, - config.getReplicationEndpointImpl, state, namespaces, tableCFs, - config.getBandwidth ]) + formatter.row([id, config.getClusterKey, + config.getReplicationEndpointImpl, state, namespaces, tableCFs, + config.getBandwidth]) end - formatter.footer() + formatter.footer peers end end diff --git a/hbase-shell/src/main/ruby/shell/commands/list_procedures.rb b/hbase-shell/src/main/ruby/shell/commands/list_procedures.rb index 64a3388b04a..a2bec3750be 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_procedures.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_procedures.rb @@ -21,21 +21,21 @@ 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 - formatter.row([ proc.getProcId, proc.getProcName, proc.getProcState, submitted_time, last_update ]) + formatter.row([proc.getProcId, proc.getProcName, proc.getProcState, submitted_time, last_update]) end formatter.footer(list.size) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb b/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb index bec7f02ed48..ff9d4f259d2 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb @@ -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| + 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) + 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb b/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb index 53395436a5b..ef7505e8c1e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_quotas.rb b/hbase-shell/src/main/ruby/shell/commands/list_quotas.rb index 604d833374f..b20aae6762b 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_quotas.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_quotas.rb @@ -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,11 +37,11 @@ EOF end def command(args = {}) - formatter.header(["OWNER", "QUOTAS"]) + formatter.header(%w[OWNER QUOTAS]) - #actually do the scanning + # actually do the scanning count = quotas_admin.list_quotas(args) do |row, cells| - formatter.row([ row, cells ]) + formatter.row([row, cells]) end formatter.footer(count) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb index f2d4b41cc13..5feb9261403 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_regions.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_regions.rb @@ -21,8 +21,7 @@ module Shell module Commands class ListRegions < Command def help - - return< 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} + 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,88 +100,86 @@ 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 - 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 - 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 - 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 - 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 - 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 - 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 - end - - results << 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 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 + 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 + 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 + 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 + 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 + 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 + end + + results << result_hash end ensure - hregion_locator_instance.close() + hregion_locator_instance.close end @end_time = Time.now - size_hash.each do | param, length | + size_hash.each do |param, length| printf(" %#{length}s |", param) 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") - results.each do | result | - size_hash.each do | param, length | + results.each do |result| + size_hash.each do |param, length| printf(" %#{length}s |", result[param]) end printf("\n") 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) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb b/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb index 4200cae62a9..1fc6e765175 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb @@ -20,9 +20,9 @@ module Shell module Commands - class ListReplicatedTables< Command + 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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_rsgroups.rb b/hbase-shell/src/main/ruby/shell/commands/list_rsgroups.rb index 7a07b53961d..ef22aa9ea32 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_rsgroups.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_rsgroups.rb @@ -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. diff --git a/hbase-shell/src/main/ruby/shell/commands/list_security_capabilities.rb b/hbase-shell/src/main/ruby/shell/commands/list_security_capabilities.rb index 922ad11a36b..873a1f5af9f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_security_capabilities.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_security_capabilities.rb @@ -19,7 +19,7 @@ module Shell module Commands class ListSecurityCapabilities < Command def help - return <<-EOF + <<-EOF List supported security capabilities Example: @@ -27,20 +27,18 @@ Example: EOF end - def command() - begin - list = admin.get_security_capabilities - list.each do |s| - puts s.getName - end - return list.map { |s| s.getName() } - rescue Exception => e - if e.to_s.include? "UnsupportedOperationException" - puts "ERROR: Master does not support getSecurityCapabilities" - return [] - end - raise e + def command + list = admin.get_security_capabilities + list.each do |s| + puts s.getName end + return list.map(&:getName) + rescue Exception => e + if e.to_s.include? 'UnsupportedOperationException' + puts 'ERROR: Master does not support getSecurityCapabilities' + return [] + end + raise e end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/list_snapshot_sizes.rb b/hbase-shell/src/main/ruby/shell/commands/list_snapshot_sizes.rb index 4ab8db98175..c00007c9d32 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_snapshot_sizes.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_snapshot_sizes.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb b/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb index bc917375a86..1b3b8f26c3f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/list_table_snapshots.rb b/hbase-shell/src/main/ruby/shell/commands/list_table_snapshots.rb index 1efcc1776c1..558fda8dedf 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_table_snapshots.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_table_snapshots.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/locate_region.rb b/hbase-shell/src/main/ruby/shell/commands/locate_region.rb index e2487c1639b..9afbbec4cd8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/locate_region.rb +++ b/hbase-shell/src/main/ruby/shell/commands/locate_region.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/major_compact.rb b/hbase-shell/src/main/ruby/shell/commands/major_compact.rb index 9b0573c71f0..9ff26c16eb8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/major_compact.rb +++ b/hbase-shell/src/main/ruby/shell/commands/major_compact.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/merge_region.rb b/hbase-shell/src/main/ruby/shell/commands/merge_region.rb index 63f7159e968..9c667707648 100644 --- a/hbase-shell/src/main/ruby/shell/commands/merge_region.rb +++ b/hbase-shell/src/main/ruby/shell/commands/merge_region.rb @@ -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). diff --git a/hbase-shell/src/main/ruby/shell/commands/move.rb b/hbase-shell/src/main/ruby/shell/commands/move.rb index 24816f3aa62..3bb2ebc1608 100644 --- a/hbase-shell/src/main/ruby/shell/commands/move.rb +++ b/hbase-shell/src/main/ruby/shell/commands/move.rb @@ -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 diff --git a/hbase-shell/src/main/ruby/shell/commands/move_servers_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/move_servers_rsgroup.rb index 61fcd02447f..e2d89233d18 100644 --- a/hbase-shell/src/main/ruby/shell/commands/move_servers_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/move_servers_rsgroup.rb @@ -19,7 +19,7 @@ module Shell module Commands class MoveServersRsgroup < Command def help - return <<-EOF + <<-EOF Reassign RegionServers from one group to another. Example: diff --git a/hbase-shell/src/main/ruby/shell/commands/move_servers_tables_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/move_servers_tables_rsgroup.rb index 533714184ae..1789a3579e7 100644 --- a/hbase-shell/src/main/ruby/shell/commands/move_servers_tables_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/move_servers_tables_rsgroup.rb @@ -19,7 +19,7 @@ module Shell module Commands class MoveServersTablesRsgroup < Command def help - return <<-EOF + <<-EOF Reassign RegionServers and Tables from one group to another. Example: diff --git a/hbase-shell/src/main/ruby/shell/commands/move_tables_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/move_tables_rsgroup.rb index c6853eafcce..ff644d1cb46 100644 --- a/hbase-shell/src/main/ruby/shell/commands/move_tables_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/move_tables_rsgroup.rb @@ -19,7 +19,7 @@ module Shell module Commands class MoveTablesRsgroup < Command def help - return <<-EOF + <<-EOF Reassign tables from one RegionServer group to another. Example: diff --git a/hbase-shell/src/main/ruby/shell/commands/normalize.rb b/hbase-shell/src/main/ruby/shell/commands/normalize.rb index 0a612273f4d..0d97ec8ae9d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/normalize.rb +++ b/hbase-shell/src/main/ruby/shell/commands/normalize.rb @@ -21,7 +21,7 @@ module Shell module Commands class Normalize < Command def help - return <<-EOF + <<-EOF Trigger region normalizer for all tables which have NORMALIZATION_ENABLED flag set. Returns true if normalizer ran successfully, false otherwise. Note that this command has no effect if region normalizer is disabled (make sure it's turned on using 'normalizer_switch' command). @@ -32,10 +32,9 @@ Trigger region normalizer for all tables which have NORMALIZATION_ENABLED flag s EOF end - def command() - formatter.row([admin.normalize()? "true": "false"]) + def command + formatter.row([admin.normalize ? 'true' : 'false']) end end end end - diff --git a/hbase-shell/src/main/ruby/shell/commands/normalizer_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/normalizer_enabled.rb index d39b7772d92..aed476e879b 100644 --- a/hbase-shell/src/main/ruby/shell/commands/normalizer_enabled.rb +++ b/hbase-shell/src/main/ruby/shell/commands/normalizer_enabled.rb @@ -21,7 +21,7 @@ module Shell module Commands class NormalizerEnabled < Command def help - return <<-EOF + <<-EOF Query the state of region normalizer. Examples: @@ -29,7 +29,7 @@ Examples: EOF end - def command() + def command formatter.row([admin.normalizer_enabled?.to_s]) end end diff --git a/hbase-shell/src/main/ruby/shell/commands/normalizer_switch.rb b/hbase-shell/src/main/ruby/shell/commands/normalizer_switch.rb index 7a12b71d9bc..03d8d5aa631 100644 --- a/hbase-shell/src/main/ruby/shell/commands/normalizer_switch.rb +++ b/hbase-shell/src/main/ruby/shell/commands/normalizer_switch.rb @@ -21,7 +21,7 @@ module Shell module Commands class NormalizerSwitch < Command def help - return <<-EOF + <<-EOF Enable/Disable region normalizer. Returns previous normalizer state. When normalizer is enabled, it handles all tables with 'NORMALIZATION_ENABLED' => true. Examples: @@ -32,7 +32,7 @@ EOF end def command(enableDisable) - formatter.row([admin.normalizer_switch(enableDisable)? "true" : "false"]) + formatter.row([admin.normalizer_switch(enableDisable) ? 'true' : 'false']) end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/processlist.rb b/hbase-shell/src/main/ruby/shell/commands/processlist.rb index 5715f4b36e4..1a69ba7b7db 100644 --- a/hbase-shell/src/main/ruby/shell/commands/processlist.rb +++ b/hbase-shell/src/main/ruby/shell/commands/processlist.rb @@ -22,7 +22,7 @@ module Shell module Commands class Processlist < Command def help - return <<-EOF + <<-EOF Show regionserver task list. hbase> processlist @@ -32,34 +32,31 @@ Show regionserver task list. hbase> processlist 'rpc' hbase> processlist 'operation' hbase> processlist 'all','host187.example.com' - hbase> processlist 'all','host187.example.com,16020' + hbase> processlist 'all','host187.example.com,16020' hbase> processlist 'all','host187.example.com,16020,1289493121758' EOF end def command(*args) - - if ['all','general','handler','rpc','operation'].include? args[0] + if %w[all general handler rpc operation].include? args[0] # if the first argument is a valid filter specifier, use it as such filter = args[0] - hosts = args[1,args.length] + hosts = args[1, args.length] else # otherwise, treat all arguments as host addresses by default filter = 'general' hosts = args end - + hosts = admin.getServerNames(hosts) - if hosts == nil - puts "No regionservers available." + if hosts.nil? + puts 'No regionservers available.' else - taskmonitor.tasks(filter,hosts) + taskmonitor.tasks(filter, hosts) end - end - end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/put.rb b/hbase-shell/src/main/ruby/shell/commands/put.rb index 39f9feab332..118902a400d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/put.rb +++ b/hbase-shell/src/main/ruby/shell/commands/put.rb @@ -21,7 +21,7 @@ module Shell module Commands class Put < Command def help - return <<-EOF + <<-EOF Put a cell 'value' at specified table/row/column and optionally timestamp coordinates. To put a cell value into table 'ns1:t1' or 't1' at row 'r1' under column 'c1' marked with the time 'ts1', do: @@ -40,7 +40,7 @@ t to table 't1', the corresponding command would be: EOF end - def command(table, row, column, value, timestamp=nil, args = {}) + def command(table, row, column, value, timestamp = nil, args = {}) put table(table), row, column, value, timestamp, args end @@ -52,5 +52,5 @@ EOF end end -#Add the method table.put that calls Put.put -::Hbase::Table.add_shell_command("put") +# Add the method table.put that calls Put.put +::Hbase::Table.add_shell_command('put') diff --git a/hbase-shell/src/main/ruby/shell/commands/remove_peer.rb b/hbase-shell/src/main/ruby/shell/commands/remove_peer.rb index bc9d6ab984e..26da40887ae 100644 --- a/hbase-shell/src/main/ruby/shell/commands/remove_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/remove_peer.rb @@ -19,9 +19,9 @@ module Shell module Commands - class RemovePeer< Command + class RemovePeer < Command def help - return <<-EOF + <<-EOF Stops the specified replication stream and deletes all the meta information kept about it. Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/remove_peer_namespaces.rb b/hbase-shell/src/main/ruby/shell/commands/remove_peer_namespaces.rb index 0b668e5b249..79b56d90cd9 100644 --- a/hbase-shell/src/main/ruby/shell/commands/remove_peer_namespaces.rb +++ b/hbase-shell/src/main/ruby/shell/commands/remove_peer_namespaces.rb @@ -20,9 +20,9 @@ module Shell module Commands - class RemovePeerNamespaces< Command + class RemovePeerNamespaces < Command def help - return <<-EOF + <<-EOF Remove some namespaces from the namespaces config for the specified peer. Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb index adfb85d4e14..d50b40546fd 100644 --- a/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/remove_peer_tableCFs.rb @@ -21,7 +21,7 @@ module Shell module Commands class RemovePeerTableCFs < Command def help - return <<-EOF + <<-EOF Remove a table / table-cf from the table-cfs config for the specified peer Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/remove_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/remove_rsgroup.rb index f200ff8334d..9d39aac9f53 100644 --- a/hbase-shell/src/main/ruby/shell/commands/remove_rsgroup.rb +++ b/hbase-shell/src/main/ruby/shell/commands/remove_rsgroup.rb @@ -19,7 +19,7 @@ module Shell module Commands class RemoveRsgroup < Command def help - return <<-EOF + <<-EOF Remove a RegionServer group. hbase> remove_rsgroup 'my_group' diff --git a/hbase-shell/src/main/ruby/shell/commands/restore_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/restore_snapshot.rb index 85a30a16a3a..be6ee3ca827 100644 --- a/hbase-shell/src/main/ruby/shell/commands/restore_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/restore_snapshot.rb @@ -20,7 +20,7 @@ module Shell module Commands class RestoreSnapshot < Command def help - return <<-EOF + <<-EOF Restore a specified snapshot. The restore will replace the content of the original table, bringing back the content to the snapshot state. @@ -36,7 +36,7 @@ EOF end def command(snapshot_name, 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.restore_snapshot(snapshot_name, restore_acl) end diff --git a/hbase-shell/src/main/ruby/shell/commands/revoke.rb b/hbase-shell/src/main/ruby/shell/commands/revoke.rb index bcf60e9f964..3f4963d1d42 100644 --- a/hbase-shell/src/main/ruby/shell/commands/revoke.rb +++ b/hbase-shell/src/main/ruby/shell/commands/revoke.rb @@ -20,12 +20,12 @@ module Shell module Commands class Revoke < Command def help - return <<-EOF + <<-EOF Revoke a user's access rights. Syntax : revoke [, <@namespace> [,
[, [, ]]]] -Note: Groups and users access are revoked in the same way, but groups are prefixed with an '@' - character. In the same way, tables and namespaces are specified, but namespaces are +Note: Groups and users access are revoked in the same way, but groups are prefixed with an '@' + character. In the same way, tables and namespaces are specified, but namespaces are prefixed with an '@' character. For example: @@ -38,7 +38,7 @@ For example: EOF end - def command(user, table_name=nil, family=nil, qualifier=nil) + def command(user, table_name = nil, family = nil, qualifier = nil) security_admin.revoke(user, table_name, family, qualifier) end end diff --git a/hbase-shell/src/main/ruby/shell/commands/scan.rb b/hbase-shell/src/main/ruby/shell/commands/scan.rb index dda98990487..96382f3195f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/scan.rb +++ b/hbase-shell/src/main/ruby/shell/commands/scan.rb @@ -21,7 +21,7 @@ module Shell module Commands class Scan < Command def help - return <<-EOF + <<-EOF Scan a table; pass table name and optionally a dictionary of scanner specifications. Scanner specifications may include one or more of: TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, ROWPREFIXFILTER, TIMESTAMP, @@ -38,7 +38,7 @@ Filter Language document attached to the HBASE-4176 JIRA If you wish to see metrics regarding the execution of the scan, the ALL_METRICS boolean should be set to true. Alternatively, if you would -prefer to see only a subset of the metrics, the METRICS array can be +prefer to see only a subset of the metrics, the METRICS array can be defined to include the names of only the metrics you care about. Some examples: @@ -56,7 +56,7 @@ Some examples: hbase> scan 't1', {FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)} hbase> scan 't1', {CONSISTENCY => 'TIMELINE'} -For setting the Operation Attributes +For setting the Operation Attributes hbase> scan 't1', { COLUMNS => ['c1', 'c2'], ATTRIBUTES => {'mykey' => 'myvalue'}} hbase> scan 't1', { COLUMNS => ['c1', 'c2'], AUTHORIZATIONS => ['PRIVATE','SECRET']} For experts, there is an additional option -- CACHE_BLOCKS -- which @@ -74,14 +74,14 @@ Disabled by default. Example: Besides the default 'toStringBinary' format, 'scan' supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in -the scan specification. The FORMATTER can be stipulated: +the scan specification. The FORMATTER can be stipulated: 1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString) 2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'. -Example formatting cf:qualifier1 and cf:qualifier2 both as Integers: +Example formatting cf:qualifier1 and cf:qualifier2 both as Integers: hbase> scan 't1', {COLUMNS => ['cf:qualifier1:toInt', - 'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] } + 'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] } Note that you can specify a FORMATTER by column only (cf:qualifier). You can set a formatter for all columns (including, all key parts) using the "FORMATTER" @@ -107,27 +107,27 @@ EOF scan(table(table), args) end - #internal command that actually does the scanning + # internal command that actually does the scanning def scan(table, args = {}) - formatter.header(["ROW", "COLUMN+CELL"]) + formatter.header(['ROW', 'COLUMN+CELL']) scan = table._hash_to_scan(args) - #actually do the scanning + # actually do the scanning @start_time = Time.now count, is_stale = table._scan_internal(args, scan) do |row, cells| - formatter.row([ row, cells ]) + formatter.row([row, cells]) end @end_time = Time.now formatter.footer(count, is_stale) # if scan metrics were enabled, print them after the results - if (scan != nil && scan.isScanMetricsEnabled()) - formatter.scan_metrics(scan.getScanMetrics(), args["METRICS"]) + if !scan.nil? && scan.isScanMetricsEnabled + formatter.scan_metrics(scan.getScanMetrics, args['METRICS']) end end end end end -#Add the method table.scan that calls Scan.scan -::Hbase::Table.add_shell_command("scan") +# Add the method table.scan that calls Scan.scan +::Hbase::Table.add_shell_command('scan') diff --git a/hbase-shell/src/main/ruby/shell/commands/set_auths.rb b/hbase-shell/src/main/ruby/shell/commands/set_auths.rb index 5663ec384f7..ddd04aa6dfc 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_auths.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_auths.rb @@ -19,7 +19,7 @@ module Shell module Commands class SetAuths < Command def help - return <<-EOF + <<-EOF Add a set of visibility labels for a user or group Syntax : set_auths 'user',[label1, label2] diff --git a/hbase-shell/src/main/ruby/shell/commands/set_peer_bandwidth.rb b/hbase-shell/src/main/ruby/shell/commands/set_peer_bandwidth.rb index d9495af7d4b..e932b9367df 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_peer_bandwidth.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_peer_bandwidth.rb @@ -20,9 +20,9 @@ module Shell module Commands - class SetPeerBandwidth< Command + class SetPeerBandwidth < Command def help - return <<-EOF + <<-EOF Set the replication source per node bandwidth for the specified peer. Examples: diff --git a/hbase-shell/src/main/ruby/shell/commands/set_peer_namespaces.rb b/hbase-shell/src/main/ruby/shell/commands/set_peer_namespaces.rb index 75b3d115a03..6d14c1ce18d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_peer_namespaces.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_peer_namespaces.rb @@ -20,9 +20,9 @@ module Shell module Commands - class SetPeerNamespaces< Command + class SetPeerNamespaces < Command def help - return <<-EOF + <<-EOF Set the replicable namespaces config for the specified peer. Set a namespace in the peer config means that all tables in this diff --git a/hbase-shell/src/main/ruby/shell/commands/set_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/set_peer_tableCFs.rb index 4d3c3ec6c37..6da2f11bafa 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_peer_tableCFs.rb @@ -20,9 +20,9 @@ module Shell module Commands - class SetPeerTableCFs< Command + class SetPeerTableCFs < Command def help - return <<-EOF + <<-EOF Set the replicable table-cf config for the specified peer. Can't set a table to table-cfs config if it's namespace already was in diff --git a/hbase-shell/src/main/ruby/shell/commands/set_quota.rb b/hbase-shell/src/main/ruby/shell/commands/set_quota.rb index 06ed0baff40..ed593b65d11 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_quota.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_quota.rb @@ -21,7 +21,7 @@ module Shell module Commands class SetQuota < Command def help - return <<-EOF + <<-EOF Set a quota for a user, table, or namespace. Syntax : set_quota TYPE => , @@ -87,33 +87,33 @@ EOF end def command(args = {}) - if args.has_key?(TYPE) + if args.key?(TYPE) qtype = args.delete(TYPE) case qtype - when THROTTLE - if args[LIMIT].eql? NONE - args.delete(LIMIT) - quotas_admin.unthrottle(args) - else - quotas_admin.throttle(args) - end - when SPACE - if args[LIMIT].eql? NONE - args.delete(LIMIT) - # Table/Namespace argument is verified in remove_space_limit - quotas_admin.remove_space_limit(args) - else - raise(ArgumentError, 'Expected a LIMIT to be provided') unless args.key?(LIMIT) - raise(ArgumentError, 'Expected a POLICY to be provided') unless args.key?(POLICY) - quotas_admin.limit_space(args) - end + when THROTTLE + if args[LIMIT].eql? NONE + args.delete(LIMIT) + quotas_admin.unthrottle(args) else - raise "Invalid TYPE argument. got " + qtype + quotas_admin.throttle(args) + end + when SPACE + if args[LIMIT].eql? NONE + args.delete(LIMIT) + # Table/Namespace argument is verified in remove_space_limit + quotas_admin.remove_space_limit(args) + else + raise(ArgumentError, 'Expected a LIMIT to be provided') unless args.key?(LIMIT) + raise(ArgumentError, 'Expected a POLICY to be provided') unless args.key?(POLICY) + quotas_admin.limit_space(args) + end + else + raise 'Invalid TYPE argument. got ' + qtype end - elsif args.has_key?(GLOBAL_BYPASS) + elsif args.key?(GLOBAL_BYPASS) quotas_admin.set_global_bypass(args.delete(GLOBAL_BYPASS), args) else - raise "Expected TYPE argument" + raise 'Expected TYPE argument' end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb b/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb index 058ccf2bd42..5c57d9c528e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb @@ -19,7 +19,7 @@ module Shell module Commands class SetVisibility < Command def help - return <<-EOF + <<-EOF Set the visibility expression on one or more existing cells. Pass table name, visibility expression, and a dictionary containing @@ -67,7 +67,6 @@ EOF end formatter.footer(count) end - end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/show_filters.rb b/hbase-shell/src/main/ruby/shell/commands/show_filters.rb index 5ff0be4828d..0017ed0e26d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/show_filters.rb +++ b/hbase-shell/src/main/ruby/shell/commands/show_filters.rb @@ -23,7 +23,7 @@ module Shell module Commands class ShowFilters < Command def help - return <<-EOF + <<-EOF Show all the filters in hbase. Example: hbase> show_filters @@ -35,7 +35,7 @@ Show all the filters in hbase. Example: EOF end - def command( ) + def command parseFilter = ParseFilter.new supportedFilters = parseFilter.getSupportedFilters diff --git a/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb index b6b69565200..0f3e78dde7e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb +++ b/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb @@ -20,9 +20,9 @@ module Shell module Commands - class ShowPeerTableCFs< Command + class ShowPeerTableCFs < Command def help - return <<-EOF + <<-EOF Show replicable table-cf config for the specified peer. hbase> show_peer_tableCFs diff --git a/hbase-shell/src/main/ruby/shell/commands/snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/snapshot.rb index fd37d07291b..c591e12b5df 100644 --- a/hbase-shell/src/main/ruby/shell/commands/snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/snapshot.rb @@ -20,7 +20,7 @@ module Shell module Commands class Snapshot < Command def help - return <<-EOF + <<-EOF Take a snapshot of specified table. Examples: hbase> snapshot 'sourceTable', 'snapshotName' diff --git a/hbase-shell/src/main/ruby/shell/commands/split.rb b/hbase-shell/src/main/ruby/shell/commands/split.rb index 9e6ec6a55cd..c7a1e2938ff 100644 --- a/hbase-shell/src/main/ruby/shell/commands/split.rb +++ b/hbase-shell/src/main/ruby/shell/commands/split.rb @@ -21,9 +21,9 @@ module Shell module Commands class Split < Command def help - return <<-EOF -Split entire table or pass a region to split individual region. With the -second parameter, you can specify an explicit split key for the region. + <<-EOF +Split entire table or pass a region to split individual region. With the +second parameter, you can specify an explicit split key for the region. Examples: split 'tableName' split 'namespace:tableName' diff --git a/hbase-shell/src/main/ruby/shell/commands/status.rb b/hbase-shell/src/main/ruby/shell/commands/status.rb index b22b2723987..af71f6cb096 100644 --- a/hbase-shell/src/main/ruby/shell/commands/status.rb +++ b/hbase-shell/src/main/ruby/shell/commands/status.rb @@ -21,7 +21,7 @@ module Shell module Commands class Status < Command def help - return <<-EOF + <<-EOF Show cluster status. Can be 'summary', 'simple', 'detailed', or 'replication'. The default is 'summary'. Examples: @@ -35,7 +35,7 @@ default is 'summary'. Examples: EOF end - def command(format = 'summary',type = 'both') + def command(format = 'summary', type = 'both') admin.status(format, type) end end diff --git a/hbase-shell/src/main/ruby/shell/commands/table_help.rb b/hbase-shell/src/main/ruby/shell/commands/table_help.rb index e5a1858a92c..0ffed753abe 100644 --- a/hbase-shell/src/main/ruby/shell/commands/table_help.rb +++ b/hbase-shell/src/main/ruby/shell/commands/table_help.rb @@ -20,10 +20,10 @@ module Shell module Commands class TableHelp < Command def help - return Hbase::Table.help + Hbase::Table.help end - #just print the help + # just print the help def command # call the shell to get the nice formatting there @shell.help_command 'table_help' diff --git a/hbase-shell/src/main/ruby/shell/commands/trace.rb b/hbase-shell/src/main/ruby/shell/commands/trace.rb index d8389798309..5ecd28cd0d4 100644 --- a/hbase-shell/src/main/ruby/shell/commands/trace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/trace.rb @@ -24,7 +24,7 @@ module Shell module Commands class Trace < Command def help - return <<-EOF + <<-EOF Start or Stop tracing using HTrace. Always returns true if tracing is running, otherwise false. If the first argument is 'start', new span is started. @@ -47,28 +47,25 @@ Examples: EOF end - def command(startstop="status", spanname="HBaseShell") + def command(startstop = 'status', spanname = 'HBaseShell') trace(startstop, spanname) end def trace(startstop, spanname) @@receiver ||= SpanReceiverHost.getInstance(@shell.hbase.configuration) - if startstop == "start" - if not tracing? + if startstop == 'start' + unless tracing? @@tracescope = HTrace.startSpan(spanname, Sampler.ALWAYS) end - elsif startstop == "stop" - if tracing? - @@tracescope.close() - end + elsif startstop == 'stop' + @@tracescope.close if tracing? end tracing? end - def tracing?() - HTrace.isTracing() + def tracing? + HTrace.isTracing end - end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/truncate.rb b/hbase-shell/src/main/ruby/shell/commands/truncate.rb index aff51ac16aa..8c9f30e8e29 100644 --- a/hbase-shell/src/main/ruby/shell/commands/truncate.rb +++ b/hbase-shell/src/main/ruby/shell/commands/truncate.rb @@ -21,7 +21,7 @@ module Shell module Commands class Truncate < Command def help - return <<-EOF + <<-EOF Disables, drops and recreates the specified table. EOF end @@ -29,7 +29,6 @@ EOF def command(table) admin.truncate(table) end - end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb b/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb index 8bb3131a925..59be7d6193a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb +++ b/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb @@ -21,7 +21,7 @@ module Shell module Commands class TruncatePreserve < Command def help - return <<-EOF + <<-EOF Disables, drops and recreates the specified table while still maintaing the previous region boundaries. EOF end @@ -29,7 +29,6 @@ EOF def command(table) admin.truncate_preserve(table) end - end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/unassign.rb b/hbase-shell/src/main/ruby/shell/commands/unassign.rb index b69971fbafc..e13e72e0754 100644 --- a/hbase-shell/src/main/ruby/shell/commands/unassign.rb +++ b/hbase-shell/src/main/ruby/shell/commands/unassign.rb @@ -21,7 +21,7 @@ module Shell module Commands class Unassign < Command def help - return <<-EOF + <<-EOF Unassign a region. Unassign will close region in current location and then reopen it again. Pass 'true' to force the unassignment ('force' will clear all in-memory state in master before the reassign. If results in diff --git a/hbase-shell/src/main/ruby/shell/commands/update_all_config.rb b/hbase-shell/src/main/ruby/shell/commands/update_all_config.rb index cb6852f662f..4ad96742b4e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/update_all_config.rb +++ b/hbase-shell/src/main/ruby/shell/commands/update_all_config.rb @@ -21,7 +21,7 @@ module Shell module Commands class UpdateAllConfig < Command def help - return <<-EOF + <<-EOF Reload a subset of configuration on all servers in the cluster. See http://hbase.apache.org/book.html?dyn_config for more details. Here is how you would run the command in the hbase shell: @@ -29,8 +29,8 @@ you would run the command in the hbase shell: EOF end - def command() - admin.update_all_config() + def command + admin.update_all_config end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/update_config.rb b/hbase-shell/src/main/ruby/shell/commands/update_config.rb index 3617bb3e24c..2ed262b1a97 100644 --- a/hbase-shell/src/main/ruby/shell/commands/update_config.rb +++ b/hbase-shell/src/main/ruby/shell/commands/update_config.rb @@ -21,7 +21,7 @@ module Shell module Commands class UpdateConfig < Command def help - return <<-EOF + <<-EOF Reload a subset of configuration on server 'servername' where servername is host, port plus startcode. For example: host187.example.com,60020,1289493121758 See http://hbase.apache.org/book.html?dyn_config for more details. Here is how diff --git a/hbase-shell/src/main/ruby/shell/commands/update_peer_config.rb b/hbase-shell/src/main/ruby/shell/commands/update_peer_config.rb index c09acc28385..cdded82b0cd 100644 --- a/hbase-shell/src/main/ruby/shell/commands/update_peer_config.rb +++ b/hbase-shell/src/main/ruby/shell/commands/update_peer_config.rb @@ -19,9 +19,9 @@ module Shell module Commands - class UpdatePeerConfig< Command + class UpdatePeerConfig < 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. This command does not interrupt processing on an enabled replication peer. diff --git a/hbase-shell/src/main/ruby/shell/commands/user_permission.rb b/hbase-shell/src/main/ruby/shell/commands/user_permission.rb index 4b5d3ffa378..ba40c6c23d1 100644 --- a/hbase-shell/src/main/ruby/shell/commands/user_permission.rb +++ b/hbase-shell/src/main/ruby/shell/commands/user_permission.rb @@ -20,7 +20,7 @@ module Shell module Commands class UserPermission < Command def help - return <<-EOF + <<-EOF Show all permissions for the particular user. Syntax : user_permission
@@ -39,12 +39,12 @@ For example: EOF end - def command(table_regex=nil) - #admin.user_permission(table_regex) - formatter.header(["User", "Namespace,Table,Family,Qualifier:Permission"]) + def command(table_regex = nil) + # admin.user_permission(table_regex) + formatter.header(['User', 'Namespace,Table,Family,Qualifier:Permission']) count = security_admin.user_permission(table_regex) do |user, permission| - formatter.row([ user, permission]) + formatter.row([user, permission]) end formatter.footer(count) diff --git a/hbase-shell/src/main/ruby/shell/commands/version.rb b/hbase-shell/src/main/ruby/shell/commands/version.rb index 63e9712a52d..788501a55a4 100644 --- a/hbase-shell/src/main/ruby/shell/commands/version.rb +++ b/hbase-shell/src/main/ruby/shell/commands/version.rb @@ -21,16 +21,16 @@ module Shell module Commands class Version < Command def help - return <<-EOF + <<-EOF Output this HBase version EOF end def command # Output version. - puts "#{org.apache.hadoop.hbase.util.VersionInfo.getVersion()}, " + - "r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision()}, " + - "#{org.apache.hadoop.hbase.util.VersionInfo.getDate()}" + puts "#{org.apache.hadoop.hbase.util.VersionInfo.getVersion}, " \ + "r#{org.apache.hadoop.hbase.util.VersionInfo.getRevision}, " \ + "#{org.apache.hadoop.hbase.util.VersionInfo.getDate}" end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/wal_roll.rb b/hbase-shell/src/main/ruby/shell/commands/wal_roll.rb index a94e9e1056e..8ee1abc436c 100644 --- a/hbase-shell/src/main/ruby/shell/commands/wal_roll.rb +++ b/hbase-shell/src/main/ruby/shell/commands/wal_roll.rb @@ -20,7 +20,7 @@ module Shell module Commands class WalRoll < Command def help - return <<-EOF + <<-EOF Roll the log writer. That is, start writing log messages to a new file. The name of the regionserver should be given as the parameter. A 'server_name' is the host, port plus startcode of a regionserver. For @@ -34,7 +34,7 @@ EOF end end - #TODO remove old HLog version + # TODO: remove old HLog version class HlogRoll < WalRoll end end diff --git a/hbase-shell/src/main/ruby/shell/commands/whoami.rb b/hbase-shell/src/main/ruby/shell/commands/whoami.rb index 3b6b32d2576..aac4e3bae93 100644 --- a/hbase-shell/src/main/ruby/shell/commands/whoami.rb +++ b/hbase-shell/src/main/ruby/shell/commands/whoami.rb @@ -20,7 +20,7 @@ module Shell module Commands class Whoami < Command def help - return <<-EOF + <<-EOF Show the current hbase user. Syntax : whoami For example: @@ -29,11 +29,11 @@ For example: EOF end - def command() - user = org.apache.hadoop.hbase.security.User.getCurrent() - puts "#{user.toString()}" - groups = user.getGroupNames().to_a - if not groups.nil? and groups.length > 0 + def command + user = org.apache.hadoop.hbase.security.User.getCurrent + puts user.toString.to_s + groups = user.getGroupNames.to_a + if !groups.nil? && !groups.empty? puts " groups: #{groups.join(', ')}" end end diff --git a/hbase-shell/src/main/ruby/shell/commands/zk_dump.rb b/hbase-shell/src/main/ruby/shell/commands/zk_dump.rb index c0b509a3c6e..fe89014a970 100644 --- a/hbase-shell/src/main/ruby/shell/commands/zk_dump.rb +++ b/hbase-shell/src/main/ruby/shell/commands/zk_dump.rb @@ -21,7 +21,7 @@ module Shell module Commands class ZkDump < Command def help - return <<-EOF + <<-EOF Dump status of HBase cluster as seen by ZooKeeper. EOF end diff --git a/hbase-shell/src/main/ruby/shell/formatter.rb b/hbase-shell/src/main/ruby/shell/formatter.rb index fb481e0ff1a..30402f31786 100644 --- a/hbase-shell/src/main/ruby/shell/formatter.rb +++ b/hbase-shell/src/main/ruby/shell/formatter.rb @@ -30,11 +30,11 @@ module Shell obj.instance_of?(IO) || obj.instance_of?(StringIO) || obj == Kernel end - def refresh_width() + def refresh_width @max_width = 0 if $stdout.tty? begin - @max_width = Java::jline.TerminalFactory.get.getWidth + @max_width = Java.jline.TerminalFactory.get.getWidth rescue NameError => e # nocommit debug log and ignore end @@ -44,7 +44,7 @@ module Shell # Takes an output stream and a print width. def initialize(opts = {}) options = { - :output_stream => Kernel, + output_stream: Kernel }.merge(opts) @out = options[:output_stream] @@ -57,7 +57,7 @@ module Shell def header(args = [], widths = []) refresh_width - row(args, false, widths) if args.length > 0 + row(args, false, widths) unless args.empty? @row_count = 0 end @@ -85,20 +85,20 @@ module Shell if @max_width == 0 col1width = col2width = 0 else - col1width = (not widths or widths.length == 0) ? @max_width / 4 : @max_width * widths[0] / 100 - col2width = (not widths or widths.length < 2) ? @max_width - col1width - 2 : @max_width * widths[1] / 100 - 2 + col1width = !widths || widths.empty? ? @max_width / 4 : @max_width * widths[0] / 100 + col2width = !widths || widths.length < 2 ? @max_width - col1width - 2 : @max_width * widths[1] / 100 - 2 end splits1 = split(col1width, dump(args[0])) splits2 = split(col2width, dump(args[1])) - biggest = (splits2.length > splits1.length)? splits2.length: splits1.length + biggest = splits2.length > splits1.length ? splits2.length : splits1.length index = 0 while index < biggest # Inset by one space if inset is set. - @out.print(" ") if inset + @out.print(' ') if inset output(col1width, splits1[index]) # Add extra space so second column lines up w/ second column output - @out.print(" ") unless inset - @out.print(" ") + @out.print(' ') unless inset + @out.print(' ') output(col2width, splits2[index]) index += 1 @out.puts @@ -108,7 +108,7 @@ module Shell print ' ' first = true for e in args - @out.print " " unless first + @out.print ' ' unless first first = false @out.print e end @@ -120,41 +120,40 @@ module Shell # Output the scan metrics. Can be filtered to output only those metrics whose keys exists # in the metric_filter def scan_metrics(scan_metrics = nil, metric_filter = []) - return if scan_metrics == nil - raise(ArgumentError, \ - "Argument should be org.apache.hadoop.hbase.client.metrics.ScanMetrics") \ - unless scan_metrics.kind_of?(org.apache.hadoop.hbase.client.metrics.ScanMetrics) + return if scan_metrics.nil? + unless scan_metrics.is_a?(org.apache.hadoop.hbase.client.metrics.ScanMetrics) + raise(ArgumentError, \ + 'Argument should be org.apache.hadoop.hbase.client.metrics.ScanMetrics') + end # prefix output with empty line @out.puts # save row count to restore after printing metrics # (metrics should not count towards row count) saved_row_count = @row_count - iter = scan_metrics.getMetricsMap().entrySet().iterator() - metric_hash = Hash.new() + iter = scan_metrics.getMetricsMap.entrySet.iterator + metric_hash = {} # put keys in hash so they can be sorted easily while iter.hasNext metric = iter.next metric_hash[metric.getKey.to_s] = metric.getValue.to_s end # print in alphabetical order - row(["METRIC", "VALUE"], false) + row(%w[METRIC VALUE], false) metric_hash.sort.map do |key, value| - if (not metric_filter or metric_filter.length == 0 or metric_filter.include?(key)) + if !metric_filter || metric_filter.empty? || metric_filter.include?(key) row([key, value]) end end @row_count = saved_row_count - return + nil end def split(width, str) - if width == 0 - return [str] - end + return [str] if width == 0 result = [] index = 0 - while index < str.length do + while index < str.length result << str.slice(index, width) index += width end @@ -162,9 +161,9 @@ module Shell end def dump(str) - return if str.instance_of?(Fixnum) + return if str.instance_of?(Integer) # Remove double-quotes added by 'dump'. - return str + str end def output_str(str) @@ -177,10 +176,8 @@ module Shell end def output(width, str) - if str == nil - str = '' - end - if not width or width == str.length + str = '' if str.nil? + if !width || width == str.length @out.print(str) else @out.printf('%-*s', width, str) @@ -190,14 +187,11 @@ module Shell def footer(row_count = nil, is_stale = false) row_count ||= @row_count # Only output elapsed time and row count if startTime passed - @out.puts("%d row(s)" % [row_count]) - if is_stale == true - @out.puts(" (possible stale results) ") - end + @out.puts(format('%d row(s)', row_count)) + @out.puts(' (possible stale results) ') if is_stale == true end end - class Console < Base end @@ -210,4 +204,3 @@ module Shell end end end -