Skip to content

Commit

Permalink
HBASE-24196 [Shell] Add rename rsgroup command in hbase shell (apache…
Browse files Browse the repository at this point in the history
…#1555)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
  • Loading branch information
Reidddddd committed Apr 22, 2020
1 parent be2a8c4 commit a0a87e4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,11 @@ def remove_servers(*args)
end
@admin.removeServers(servers)
end

#--------------------------------------------------------------------------
# rename rsgroup
def rename_rsgroup(oldname, newname)
@admin.renameRSGroup(oldname, newname)
end
end
end
3 changes: 2 additions & 1 deletion hbase-shell/src/main/ruby/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def hbase_security_admin
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
Expand Down Expand Up @@ -468,5 +468,6 @@ def help_footer
get_server_rsgroup
get_table_rsgroup
remove_servers_rsgroup
rename_rsgroup
]
)
33 changes: 33 additions & 0 deletions hbase-shell/src/main/ruby/shell/commands/rename_rsgroup.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,18 @@ def setup
@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

0 comments on commit a0a87e4

Please sign in to comment.