From c66db70072ec10d4964391413bfcb29c486c661d Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 27 Feb 2015 16:59:15 +0530 Subject: [PATCH] HBASE-13058 Hbase shell command 'scan' for non existent table shows unnecessary info for one unrelated existent table. --- hbase-shell/src/main/ruby/shell/commands.rb | 22 ++++++++-------------- .../src/main/ruby/shell/commands/clone_snapshot.rb | 7 +++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 4602db6..db4768c 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -99,12 +99,15 @@ module Shell yield rescue => e raise e unless e.respond_to?(:cause) && e.cause != nil - # Get the special java exception which will be handled cause = e.cause + # let individual command handle exceptions first + if self.respond_to?(:handle_exceptions) + self.handle_exceptions(cause, *args) + end + # Global HBase exception handling below if not handled by respective command above if cause.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then - first_arg = args.first - raise "Unknown table #{first_arg}!" + raise "Unknown table #{args.first}!" end if cause.kind_of?(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) then exceptions = cause.getCauses @@ -114,21 +117,12 @@ module Shell raise "Unknown column family! Valid column names: #{valid_cols.join(", ")}" end if exception.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then - first_arg = args.first - raise "Unknown table #{first_arg}!" + raise "Unknown table #{args.first}!" end end end if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then - str = java.lang.String.new("#{cause}") - strs = str.split("\n") - if strs.size > 0 then - s = strs[0].split(' '); - if(s.size > 1) - raise "Table already exists: #{s[1]}!" - end - raise "Table already exists: #{strs[0]}!" - end + 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. 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 8c193bb..aa17948 100644 --- a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb @@ -36,6 +36,13 @@ EOF admin.clone_snapshot(snapshot_name, table) end end + + def handle_exceptions(cause, *args) + if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then + tableName = args[1] + raise "Table already exists: #{tableName}!" + end + end end end end -- 1.8.4.msysgit.0