You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by re...@apache.org on 2020/04/22 06:21:59 UTC

[hbase] branch branch-1 updated: HBASE-24196 [Shell] Add rename rsgroup command in hbase shell (#1555)

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

reidchan pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1 by this push:
     new 5213d20  HBASE-24196 [Shell] Add rename rsgroup command in hbase shell (#1555)
5213d20 is described below

commit 5213d20ae8789774c4bc5b517b0eb58fe25a05d5
Author: Reid Chan <re...@apache.org>
AuthorDate: Wed Apr 22 14:21:49 2020 +0800

    HBASE-24196 [Shell] Add rename rsgroup command in hbase shell (#1555)
    
    Signed-off-by: Viraj Jasani <vj...@apache.org>
    Signed-off-by: Jan Hentschel <ja...@ultratendency.com>
---
 hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb   |  6 ++++
 hbase-shell/src/main/ruby/shell.rb                 |  3 +-
 .../src/main/ruby/shell/commands/rename_rsgroup.rb | 33 ++++++++++++++++++++++
 .../src/test/ruby/shell/rsgroup_shell_test.rb      | 13 +++++++++
 4 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb b/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
index f5f4e62..dbfd6380 100644
--- a/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
@@ -171,5 +171,11 @@ module Hbase
       end
       @admin.removeServers(servers)
     end
+
+    #--------------------------------------------------------------------------
+    # rename rsgroup
+    def rename_rsgroup(oldname, newname)
+      @admin.renameRSGroup(oldname, newname)
+    end
   end
 end
diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb
index 5cf2320..d955d90 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -105,7 +105,7 @@ module Shell
     def hbase_visibility_labels_admin
       @hbase_visibility_labels_admin ||= hbase.visibility_labels_admin()
     end
-    
+
     def hbase_quotas_admin
       @hbase_quotas_admin ||= hbase.quotas_admin()
     end
@@ -472,5 +472,6 @@ Shell.load_command_group(
     get_server_rsgroup
     get_table_rsgroup
     remove_servers_rsgroup
+    rename_rsgroup
   ]
 )
diff --git a/hbase-shell/src/main/ruby/shell/commands/rename_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/rename_rsgroup.rb
new file mode 100644
index 0000000..496b3a7
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/rename_rsgroup.rb
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+module Shell
+  module Commands
+    class RenameRsgroup < Command
+      def help
+        <<-EOF
+Rename a RegionServer group.
+  hbase> rename_rsgroup 'old_rsgroup_name', 'new_rsgroup_name'
+        EOF
+      end
+
+      def command(oldname, newname)
+        rsgroup_admin.rename_rsgroup(oldname, newname)
+      end
+    end
+  end
+end
diff --git a/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb b/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
index 7542e6e..cb3b8f8 100644
--- a/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
+++ b/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
@@ -92,5 +92,18 @@ module Hbase
         @hbase.rsgroup_admin.get_rsgroup_of_table('foobar')
       end
     end
+
+    define_test 'Test rsgroup rename' do
+      old_rs_group_name = 'test_group'
+      new_rs_group_name = 'renamed_test_group'
+      table_name = 'test_table'
+
+      @hbase.rsgroup_admin.rename_rsgroup(old_rs_group_name, new_rs_group_name)
+      assert_not_nil(@rsgroup_admin.getRSGroupInfo(new_rs_group_name))
+      assert_nil(@rsgroup_admin.getRSGroupInfo(old_rs_group_name))
+      assert_equal(1, @rsgroup_admin.getRSGroupInfo(new_rs_group_name).getServers.count)
+      assert_equal(1, @rsgroup_admin.getRSGroupInfo(new_rs_group_name).getTables.count)
+      assert_equal(table_name, @rsgroup_admin.getRSGroupInfo(new_rs_group_name).getTables.iterator.next.toString)
+    end
   end
 end