You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2020/08/22 03:47:23 UTC

[hbase] branch master updated: HBASE-24890 The command regioninfo is not available (#2263)

This is an automated email from the ASF dual-hosted git repository.

stack pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new 4021f45  HBASE-24890 The command regioninfo is not available (#2263)
4021f45 is described below

commit 4021f4577cd53d81f4d6e5a9302021f73397994a
Author: bsglz <18...@qq.com>
AuthorDate: Sat Aug 22 11:47:03 2020 +0800

    HBASE-24890 The command regioninfo is not available (#2263)
    
    * HBASE-24890 The command regioninfo is not available
    
    * add ut for command regioninfo
---
 .../src/main/ruby/shell/commands/regioninfo.rb     | 25 ++++++++++---
 hbase-shell/src/test/ruby/hbase/admin2_test.rb     | 42 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb b/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb
index 725dd65..4facbf8 100644
--- a/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/regioninfo.rb
@@ -16,6 +16,13 @@
 # limitations under the License.
 #
 
+include Java
+java_import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil
+java_import org.apache.hadoop.hbase.util.FutureUtils
+java_import org.apache.hadoop.hbase.client.ConnectionFactory
+java_import org.apache.hadoop.hbase.security.UserProvider
+java_import org.apache.hadoop.hbase.client.ClusterConnectionFactory
+
 module Shell
   module Commands
     class Regioninfo < Command
@@ -35,12 +42,20 @@ Below we pass first encoded region name and then full region name.
 EOF
       end
 
-      def command(regionname)
-        connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection()
-        admin = connection.getAdmin()
+      def command(region_name)
+        admin = @shell.hbase.connection.getAdmin()
         sn = admin.getMaster()
-        puts org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.getRegionInfo(nil,
-          connection.getAdmin(sn), regionname.to_java_bytes)
+
+        conf = @shell.hbase.configuration
+        user = UserProvider.instantiate(conf).getCurrent()
+        clusterConnection = ClusterConnectionFactory.createAsyncClusterConnection(conf, nil, user)
+        regionInfo = ProtobufUtil.toRegionInfo(FutureUtils.get(
+          clusterConnection.getRegionServerAdmin(sn).getRegionInfo(
+            ProtobufUtil.getGetRegionInfoRequest(region_name.to_java_bytes))).getRegionInfo())
+        if clusterConnection != nil
+          clusterConnection.close()
+        end
+        puts regionInfo
       end
     end
   end
diff --git a/hbase-shell/src/test/ruby/hbase/admin2_test.rb b/hbase-shell/src/test/ruby/hbase/admin2_test.rb
index e420c74..9d3834e 100644
--- a/hbase-shell/src/test/ruby/hbase/admin2_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/admin2_test.rb
@@ -435,5 +435,47 @@ class CommissioningTest < Test::Unit::TestCase
       end
     end
   end
+
+  # Tests for the `regioninfo` shell command
+  class RegionInfoTest < Test::Unit::TestCase
+    include TestHelpers
+    include HBaseConstants
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_regioninfo_test"
+      drop_test_table(@test_name)
+      create_test_table(@test_name)
+    end
+
+    def teardown
+      shutdown
+    end
+
+    define_test "Get region info without any args" do
+      assert_raise(ArgumentError) do
+        command(:regioninfo)
+      end
+    end
+
+    define_test 'Get region info with encoded region name' do
+      region = command(:locate_region, @test_name, '')
+      encodedRegionName = region.getRegion.getEncodedName
+      output = capture_stdout { command(:regioninfo, encodedRegionName) }
+      puts "Region info output:\n#{output}"
+      assert output.include? 'ENCODED'
+      assert output.include? 'STARTKEY'
+    end
+
+    define_test 'Get region info with region name' do
+      region = command(:locate_region, @test_name, '')
+      regionName = region.getRegion.getRegionNameAsString
+      output = capture_stdout { command(:regioninfo, regionName) }
+      puts "Region info output:\n#{output}"
+      assert output.include? 'ENCODED'
+      assert output.include? 'STARTKEY'
+    end
+  end
   # rubocop:enable ClassLength
 end