From 6dbe09c310ecbda6bd0ad365c09cd79c7ff52ee7 Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Thu, 12 Mar 2015 19:32:38 +0530 Subject: [PATCH] HBASE-13220 set_quota should fail for non-existing table and namespace --- hbase-shell/src/main/ruby/hbase/quotas.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hbase-shell/src/main/ruby/hbase/quotas.rb b/hbase-shell/src/main/ruby/hbase/quotas.rb index fa076a5..6732241 100644 --- a/hbase-shell/src/main/ruby/hbase/quotas.rb +++ b/hbase-shell/src/main/ruby/hbase/quotas.rb @@ -52,10 +52,15 @@ module Hbase if args.has_key?(TABLE) table = TableName.valueOf(args.delete(TABLE)) raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty? + # Table should exist first. + raise(ArgumentError, "Can't find a table: #{table}") unless exists?(table) settings = QuotaSettingsFactory.throttleUser(user, table, type, limit, time_unit) elsif args.has_key?(NAMESPACE) namespace = args.delete(NAMESPACE) raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty? + # Namespace should exist first. + raise(ArgumentError, "Can't find a namespace: #{namespace}") unless + namespace_exists?(namespace) settings = QuotaSettingsFactory.throttleUser(user, namespace, type, limit, time_unit) else raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty? @@ -82,10 +87,15 @@ module Hbase if args.has_key?(TABLE) table = TableName.valueOf(args.delete(TABLE)) raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty? + # Table should exist first. + raise(ArgumentError, "Can't find a table: #{table}") unless exists?(table) settings = QuotaSettingsFactory.unthrottleUser(user, table) elsif args.has_key?(NAMESPACE) namespace = args.delete(NAMESPACE) raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty? + # Namespace should exist first. + raise(ArgumentError, "Can't find a namespace: #{namespace}") unless + namespace_exists?(namespace) settings = QuotaSettingsFactory.unthrottleUser(user, namespace) else raise(ArgumentError, "Unexpected arguments: " + args.inspect) unless args.empty? @@ -212,5 +222,20 @@ module Hbase end return value end + + # Does table exist? + def exists?(table_name) + @admin.tableExists(table_name) + end + + # Does Namespace exist + def namespace_exists?(namespace_name) + namespaceDesc = @admin.getNamespaceDescriptor(namespace_name) + if(namespaceDesc == nil) + return false + else + return true + end + end end end \ No newline at end of file -- 1.9.2.msysgit.0