HBASE-23807 Make rsgroup related shell command to use the new admin methods (#1148)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Duo Zhang 2020-02-09 10:33:32 +08:00 committed by Duo Zhang
parent 7386369fec
commit 37e87aeca7
5 changed files with 39 additions and 41 deletions

View File

@ -27,8 +27,7 @@ module Hbase
def initialize(connection)
@connection = connection
@admin = org.apache.hadoop.hbase.rsgroup.RSGroupAdminClient.new(connection)
@hb_admin = @connection.getAdmin
@admin = @connection.getAdmin
end
def close
@ -44,7 +43,7 @@ module Hbase
#--------------------------------------------------------------------------
# get a group's information
def get_rsgroup(group_name)
group = @admin.getRSGroupInfo(group_name)
group = @admin.getRSGroup(group_name)
raise(ArgumentError, 'Group does not exist: ' + group_name) if group.nil?
group
end
@ -74,7 +73,7 @@ module Hbase
args[0].each do |s|
servers.add(org.apache.hadoop.hbase.net.Address.fromString(s))
end
@admin.moveServers(servers, dest)
@admin.moveServersToRSGroup(servers, dest)
end
#--------------------------------------------------------------------------
@ -84,20 +83,20 @@ module Hbase
args[0].each do |s|
tables.add(org.apache.hadoop.hbase.TableName.valueOf(s))
end
@admin.moveTables(tables, dest)
@admin.setRSGroup(tables, dest)
end
#--------------------------------------------------------------------------
# move namespaces to a group
def move_namespaces(dest, *args)
tables = get_tables(args[0])
@admin.moveTables(tables, dest)
@admin.setRSGroup(tables, dest)
end
#--------------------------------------------------------------------------
# get group of server
def get_rsgroup_of_server(server)
res = @admin.getRSGroupOfServer(
res = @admin.getRSGroup(
org.apache.hadoop.hbase.net.Address.fromString(server)
)
raise(ArgumentError, 'Server has no group: ' + server) if res.nil?
@ -107,7 +106,7 @@ module Hbase
#--------------------------------------------------------------------------
# get group of table
def get_rsgroup_of_table(table)
res = @admin.getRSGroupInfoOfTable(
res = @admin.getRSGroup(
org.apache.hadoop.hbase.TableName.valueOf(table)
)
raise(ArgumentError, 'Table has no group: ' + table) if res.nil?
@ -122,7 +121,8 @@ module Hbase
args[1].each do |t|
tables.add(org.apache.hadoop.hbase.TableName.valueOf(t))
end
@admin.moveServersAndTables(servers, tables, dest)
@admin.moveServersToRSGroup(servers, dest)
@admin.setRSGroup(tables, dest)
end
#--------------------------------------------------------------------------
@ -130,7 +130,8 @@ module Hbase
def move_servers_namespaces(dest, *args)
servers = get_servers(args[0])
tables = get_tables(args[1])
@admin.moveServersAndTables(servers, tables, dest)
@admin.moveServersToRSGroup(servers, dest)
@admin.setRSGroup(tables, dest)
end
def get_servers(servers)
@ -154,7 +155,7 @@ module Hbase
# Get tables by namespace
def get_tables_by_namespace(ns)
tables = java.util.HashSet.new
tablelist = @hb_admin.listTableNamesByNamespace(ns).map(&:getNameAsString)
tablelist = @admin.listTableNamesByNamespace(ns).map(&:getNameAsString)
tablelist.each do |table|
tables.add(org.apache.hadoop.hbase.TableName.valueOf(table))
end
@ -163,7 +164,7 @@ module Hbase
# Does Namespace exist
def namespace_exists?(ns)
return !@hb_admin.getNamespaceDescriptor(ns).nil?
return !@admin.getNamespaceDescriptor(ns).nil?
rescue org.apache.hadoop.hbase.NamespaceNotFoundException
return false
end
@ -177,7 +178,12 @@ module Hbase
args.each do |s|
servers.add(org.apache.hadoop.hbase.net.Address.fromString(s))
end
@admin.removeServers(servers)
@admin.removeServersFromRSGroup(servers)
end
# get tables in rs group
def list_tables_in_rs_group(group_name)
@admin.listTablesInRSGroup(group_name)
end
end
end

View File

@ -39,7 +39,8 @@ EOF
formatter.footer
formatter.header(['TABLES'])
group.getTables.each do |table|
tables = rsgroup_admin.list_tables_in_rs_group(group_name)
tables.each do |table|
formatter.row([table.getNameAsString])
end
formatter.footer

View File

@ -54,8 +54,8 @@ EOF
formatter.row([group_name, 'server ' + server.toString])
end
group.getTables.each do |table|
tables = rsgroup_admin.list_tables_in_rs_group(group.getName)
tables.each do |table|
if group_name_printed
group_name = ''
else

View File

@ -19,10 +19,7 @@ package org.apache.hadoop.hbase.client;
import java.io.IOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint;
import org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.jruby.embed.PathType;
@ -43,11 +40,7 @@ public class TestRSGroupShell extends AbstractTestShell {
setUpConfig();
// enable rs group
TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
TEST_UTIL.getConfiguration().get(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY) + "," +
RSGroupAdminEndpoint.class.getName());
TEST_UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS,
RSGroupBasedLoadBalancer.class.getName());
TEST_UTIL.getConfiguration().setBoolean(RSGroupInfoManager.RS_GROUP_ENABLED, true);
TEST_UTIL.startMiniCluster(3);

View File

@ -26,8 +26,7 @@ module Hbase
@hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
@shell = Shell::Shell.new(@hbase)
connection = $TEST_CLUSTER.getConnection
@rsgroup_admin =
org.apache.hadoop.hbase.rsgroup.RSGroupAdminClient.new(connection)
@admin = connection.getAdmin
end
define_test 'Test Basic RSGroup Commands' do
@ -37,37 +36,36 @@ module Hbase
@shell.command('create', table_name, 'f')
@shell.command('add_rsgroup', group_name)
assert_not_nil(@rsgroup_admin.getRSGroupInfo(group_name))
assert_not_nil(@admin.getRSGroup(group_name))
@shell.command('remove_rsgroup', group_name)
assert_nil(@rsgroup_admin.getRSGroupInfo(group_name))
assert_nil(@admin.getRSGroup(group_name))
@shell.command('add_rsgroup', group_name)
group = @rsgroup_admin.getRSGroupInfo(group_name)
group = @admin.getRSGroup(group_name)
assert_not_nil(group)
assert_equal(0, group.getServers.count)
hostport = @rsgroup_admin.getRSGroupInfo('default').getServers.iterator.next
hostport = @admin.getRSGroup('default').getServers.iterator.next
@shell.command('get_rsgroup', 'default')
hostPortStr = hostport.toString
@shell.command('get_server_rsgroup', hostPortStr)
@shell.command('move_servers_rsgroup',
group_name,
[hostPortStr])
assert_equal(1, @rsgroup_admin.getRSGroupInfo(group_name).getServers.count)
assert_equal(group_name, @rsgroup_admin.getRSGroupOfServer(hostport).getName)
assert_equal(1, @admin.getRSGroup(group_name).getServers.count)
assert_equal(group_name, @admin.getRSGroup(hostport).getName)
@shell.command('move_tables_rsgroup',
group_name,
[table_name])
assert_equal(1, @rsgroup_admin.getRSGroupInfo(group_name).getTables.count)
assert_equal(1, @admin.listTablesInRSGroup(group_name).count)
group = @hbase.rsgroup_admin.get_rsgroup(group_name)
assert_not_nil(group)
assert_equal(1, group.getServers.count)
assert_equal(1, group.getTables.count)
assert_equal(hostPortStr, group.getServers.iterator.next.toString)
assert_equal(table_name, group.getTables.iterator.next.toString)
assert_equal(table_name, @admin.listTablesInRSGroup(group_name).iterator.next.toString)
assert_equal(2, @hbase.rsgroup_admin.list_rs_groups.count)
@ -86,11 +84,11 @@ module Hbase
@shell.command('move_namespaces_rsgroup',
group_name,
[namespace_name])
assert_equal(2, @rsgroup_admin.getRSGroupInfo(group_name).getTables.count)
assert_equal(2, @admin.listTablesInRSGroup(group_name).count)
group = @hbase.rsgroup_admin.get_rsgroup(group_name)
assert_not_nil(group)
assert_equal(ns_table_name, group.getTables.iterator.next.toString)
assert_true(@admin.listTablesInRSGroup(group_name).contains(org.apache.hadoop.hbase.TableName.valueOf(ns_table_name)))
end
define_test 'Test RSGroup Move Server Namespace RSGroup Commands' do
@ -99,13 +97,13 @@ module Hbase
ns_table_name = 'test_namespace:test_ns_table'
@shell.command('add_rsgroup', ns_group_name)
assert_not_nil(@rsgroup_admin.getRSGroupInfo(ns_group_name))
assert_not_nil(@admin.getRSGroup(ns_group_name))
@shell.command('move_tables_rsgroup',
'default',
[ns_table_name])
group_servers = @rsgroup_admin.getRSGroupInfo('default').getServers
group_servers = @admin.getRSGroup('default').getServers
hostport_str = group_servers.iterator.next.toString
@shell.command('move_servers_namespaces_rsgroup',
ns_group_name,
@ -114,7 +112,7 @@ module Hbase
ns_group = @hbase.rsgroup_admin.get_rsgroup(ns_group_name)
assert_not_nil(ns_group)
assert_equal(hostport_str, ns_group.getServers.iterator.next.toString)
assert_equal(ns_table_name, ns_group.getTables.iterator.next.toString)
assert_equal(ns_table_name, @admin.listTablesInRSGroup(ns_group_name).iterator.next.toString)
end
# we test exceptions that could be thrown by the ruby wrappers