From 4d0df5d6f7db528dfbef3afa415b2a5f152ab0c2 Mon Sep 17 00:00:00 2001 From: Sakthi Date: Tue, 22 Jan 2019 00:07:48 -0800 Subject: [PATCH] HBASE-21689: Make table/namespace specific current quota info available in shell(describe_namespace & describe) --- .../src/main/ruby/shell/commands/describe.rb | 9 +++ .../ruby/shell/commands/describe_namespace.rb | 10 +++ hbase-shell/src/test/ruby/hbase/admin_test.rb | 63 +++++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/hbase-shell/src/main/ruby/shell/commands/describe.rb b/hbase-shell/src/main/ruby/shell/commands/describe.rb index 3268b2f7228abb4cfae6fced2298234f313b228d..5ef02a03a84d56c471adff2fa19a82d2c81b34de 100644 --- a/hbase-shell/src/main/ruby/shell/commands/describe.rb +++ b/hbase-shell/src/main/ruby/shell/commands/describe.rb @@ -32,6 +32,7 @@ Alternatively, you can use the abbreviated 'desc' for the same thing. EOF end + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength def command(table) column_families = admin.get_column_families(table) @@ -40,9 +41,17 @@ EOF formatter.header(['COLUMN FAMILIES DESCRIPTION']) column_families.each do |column_family| formatter.row([column_family.to_s], true) + puts end formatter.footer + puts + formatter.header(%w[QUOTAS]) + count = quotas_admin.list_quotas(TABLE => table.to_s) do |_, quota| + formatter.row([quota]) + end + formatter.footer(count) end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength 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 55261d6bdc23737c12261fcb99183a932bf0147e..4252ad6022dfaecdbdc077bdcd2851e91ffd7fa8 100644 --- a/hbase-shell/src/main/ruby/shell/commands/describe_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/describe_namespace.rb @@ -27,12 +27,22 @@ Describe the named namespace. For example: EOF end + # rubocop:disable Metrics/AbcSize def command(namespace) desc = admin.describe_namespace(namespace) formatter.header(['DESCRIPTION'], [64]) formatter.row([desc], true, [64]) + + puts + formatter.header(%w[QUOTAS]) + ns = namespace.to_s + count = quotas_admin.list_quotas(NAMESPACE => ns) do |_, quota| + formatter.row([quota]) + end + formatter.footer(count) end + # rubocop:enable Metrics/AbcSize end end end diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb index 9fafea4afcc9413e869f19521ad393a2c17d9bfd..3bd3961f106114051e96ec2900a50934e3107798 100644 --- a/hbase-shell/src/test/ruby/hbase/admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb @@ -59,7 +59,8 @@ module Hbase end end - # Simple administration methods tests + # Simple administration methods tests + # rubocop:disable Metrics/ClassLength class AdminMethodsTest < Test::Unit::TestCase include TestHelpers @@ -193,7 +194,7 @@ module Hbase drop_test_table(@create_test_name) command(:create, @create_test_name, 'a', 'b') assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort) - end + end define_test "create should work with hash column args" do drop_test_table(@create_test_name) @@ -267,8 +268,61 @@ module Hbase end end - define_test "describe should return a description" do - assert_not_nil admin.describe(@test_name) + define_test 'describe should return a description and quotas' do + drop_test_table(@create_test_name) + command(:create, @create_test_name, 'cf1', 'cf2') + command(:set_quota, + TYPE => SPACE, + LIMIT => '1G', + POLICY => NO_INSERTS, + TABLE => @create_test_name) + output = capture_stdout { command(:describe, @create_test_name) } + + assert(output.include?("Table #{@create_test_name} is ENABLED")) + assert(output.include?('COLUMN FAMILIES DESCRIPTION')) + assert(output.include?("NAME => 'cf1'")) + assert(output.include?("NAME => 'cf2'")) + assert(output.include?('2 row(s)')) + + assert(output.include?('QUOTAS')) + assert(output.include?('LIMIT => 1G')) + assert(output.include?('VIOLATION_POLICY => NO_INSERTS')) + assert(output.include?('TYPE => SPACE')) + assert(output.include?('1 row(s)')) + + command(:set_quota, + TYPE => SPACE, + LIMIT => NONE, + TABLE => @create_test_name) + output = capture_stdout { command(:describe, @create_test_name) } + assert(output.include?('0 row(s)')) + end + + define_test 'describe_namespace should return a description and quotas' do + ns = @create_test_name + command(:create_namespace, ns) + command(:set_quota, + TYPE => SPACE, + LIMIT => '1G', + POLICY => NO_INSERTS, + NAMESPACE => ns) + output = capture_stdout { command(:describe_namespace, ns) } + + assert(output.include?('DESCRIPTION')) + assert(output.include?("NAME => '#{ns}'")) + + assert(output.include?('QUOTAS')) + assert(output.include?('LIMIT => 1G')) + assert(output.include?('VIOLATION_POLICY => NO_INSERTS')) + assert(output.include?('TYPE => SPACE')) + assert(output.include?('1 row(s)')) + + command(:set_quota, + TYPE => SPACE, + LIMIT => NONE, + NAMESPACE => ns) + output = capture_stdout { command(:describe_namespace, ns) } + assert(output.include?('0 row(s)')) end #------------------------------------------------------------------------------- @@ -332,6 +386,7 @@ module Hbase end end end + # rubocop:enable Metrics/ClassLength # Simple administration methods tests class AdminCloneTableSchemaTest < Test::Unit::TestCase -- 2.17.2 (Apple Git-113)