hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zg...@apache.org
Subject hbase git commit: HBASE-19336 Improve rsgroup to allow assign all tables within a specified namespace by only writing namespace
Date Sat, 02 Dec 2017 01:27:51 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 835d15bf9 -> 5e0d00f88


HBASE-19336 Improve rsgroup to allow assign all tables within a specified namespace by only
writing namespace

Signed-off-by: Guanghao Zhang <zghao@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/5e0d00f8
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5e0d00f8
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5e0d00f8

Branch: refs/heads/master
Commit: 5e0d00f88493788cd78974b0c48efb36a10596fc
Parents: 835d15b
Author: libisthanks <libisthanks@gmail.com>
Authored: Fri Dec 1 21:49:37 2017 +0800
Committer: Guanghao Zhang <zghao@apache.org>
Committed: Sat Dec 2 09:27:29 2017 +0800

----------------------------------------------------------------------
 .../src/main/ruby/hbase/rsgroup_admin.rb        | 59 ++++++++++++++++++--
 hbase-shell/src/main/ruby/shell.rb              |  2 +
 .../shell/commands/move_namespaces_rsgroup.rb   | 37 ++++++++++++
 .../commands/move_servers_namespaces_rsgroup.rb | 37 ++++++++++++
 .../src/test/ruby/shell/rsgroup_shell_test.rb   | 42 ++++++++++++++
 5 files changed, 172 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5e0d00f8/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb b/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
index 1d3ca7c..4e32ea4 100644
--- a/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/rsgroup_admin.rb
@@ -26,7 +26,9 @@ module Hbase
     include HBaseConstants
 
     def initialize(connection)
+      @connection = connection
       @admin = org.apache.hadoop.hbase.rsgroup.RSGroupAdminClient.new(connection)
+      @hb_admin = @connection.getAdmin
     end
 
     def close
@@ -76,7 +78,7 @@ module Hbase
     end
 
     #--------------------------------------------------------------------------
-    # move server to a group
+    # move tables to a group
     def move_tables(dest, *args)
       tables = java.util.HashSet.new
       args[0].each do |s|
@@ -86,6 +88,13 @@ module Hbase
     end
 
     #--------------------------------------------------------------------------
+    # move namespaces to a group
+    def move_namespaces(dest, *args)
+      tables = get_tables(args[0])
+      @admin.moveTables(tables, dest)
+    end
+
+    #--------------------------------------------------------------------------
     # get group of server
     def get_rsgroup_of_server(server)
       res = @admin.getRSGroupOfServer(
@@ -108,11 +117,8 @@ module Hbase
     #--------------------------------------------------------------------------
     # move server and table to a group
     def move_servers_tables(dest, *args)
-      servers = java.util.HashSet.new
+      servers = get_servers(args[0])
       tables = java.util.HashSet.new
-      args[0].each do |s|
-        servers.add(org.apache.hadoop.hbase.net.Address.fromString(s))
-      end
       args[1].each do |t|
         tables.add(org.apache.hadoop.hbase.TableName.valueOf(t))
       end
@@ -120,6 +126,49 @@ module Hbase
     end
 
     #--------------------------------------------------------------------------
+    # move server and namespace to a group
+    def move_servers_namespaces(dest, *args)
+      servers = get_servers(args[0])
+      tables = get_tables(args[1])
+      @admin.moveServersAndTables(servers, tables, dest)
+    end
+
+    def get_servers(servers)
+      server_set = java.util.HashSet.new
+      servers.each do |s|
+        server_set.add(org.apache.hadoop.hbase.net.Address.fromString(s))
+      end
+      server_set
+    end
+
+    def get_tables(namespaces)
+      table_set = java.util.HashSet.new
+      error = "Can't find a namespace: "
+      namespaces.each do |ns|
+        raise(ArgumentError, "#{error}#{ns}") unless namespace_exists?(ns)
+        table_set.addAll(get_tables_by_namespace(ns))
+      end
+      table_set
+    end
+
+    # Get tables by namespace
+    def get_tables_by_namespace(ns)
+      tables = java.util.HashSet.new
+      tablelist = @hb_admin.listTableNamesByNamespace(ns).map(&:getNameAsString)
+      tablelist.each do |table|
+        tables.add(org.apache.hadoop.hbase.TableName.valueOf(table))
+      end
+      tables
+    end
+
+    # Does Namespace exist
+    def namespace_exists?(ns)
+      return !@hb_admin.getNamespaceDescriptor(ns).nil?
+    rescue org.apache.hadoop.hbase.NamespaceNotFoundException
+      return false
+    end
+
+    #--------------------------------------------------------------------------
     # remove decommissioned server from rsgroup
     def remove_servers(*args)
       # Flatten params array

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e0d00f8/hbase-shell/src/main/ruby/shell.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb
index 7852625..58886fc 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -480,7 +480,9 @@ Shell.load_command_group(
     balance_rsgroup
     move_servers_rsgroup
     move_tables_rsgroup
+    move_namespaces_rsgroup
     move_servers_tables_rsgroup
+    move_servers_namespaces_rsgroup
     get_server_rsgroup
     get_table_rsgroup
     remove_servers_rsgroup

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e0d00f8/hbase-shell/src/main/ruby/shell/commands/move_namespaces_rsgroup.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/move_namespaces_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/move_namespaces_rsgroup.rb
new file mode 100644
index 0000000..0151f7a
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/move_namespaces_rsgroup.rb
@@ -0,0 +1,37 @@
+# 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
+    # Reassign tables of specified namespaces
+    # from one RegionServer group to another.
+    class MoveNamespacesRsgroup < Command
+      def help
+        <<-CMD
+
+  Example:
+  hbase> move_namespaces_rsgroup 'dest',['ns1','ns2']
+
+CMD
+      end
+
+      def command(dest, namespaces)
+        rsgroup_admin.move_namespaces(dest, namespaces)
+      end
+    end
+  end
+end

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e0d00f8/hbase-shell/src/main/ruby/shell/commands/move_servers_namespaces_rsgroup.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/move_servers_namespaces_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/move_servers_namespaces_rsgroup.rb
new file mode 100644
index 0000000..16b1ce9
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/move_servers_namespaces_rsgroup.rb
@@ -0,0 +1,37 @@
+# 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
+    # Reassign RegionServers and Tables of
+    # specified namespaces from one group to another.
+    class MoveServersNamespacesRsgroup < Command
+      def help
+        <<-CMD
+
+  Example:
+  hbase> move_servers_namespaces_rsgroup 'dest',['server1:port','server2:port'],['ns1','ns2']
+
+CMD
+      end
+
+      def command(dest, servers, namespaces)
+        rsgroup_admin.move_servers_namespaces(dest, servers, namespaces)
+      end
+    end
+  end
+end

http://git-wip-us.apache.org/repos/asf/hbase/blob/5e0d00f8/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
----------------------------------------------------------------------
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 8c33459..ab7ba0d 100644
--- a/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
+++ b/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
@@ -75,6 +75,48 @@ module Hbase
       @hbase.rsgroup_admin.balance_rs_group(group_name)
     end
 
+    define_test 'Test RSGroup Move Namespace RSGroup Commands' do
+      group_name = 'test_group'
+      namespace_name = 'test_namespace'
+      ns_table_name = 'test_namespace:test_ns_table'
+
+      @shell.command('create_namespace', namespace_name)
+      @shell.command('create', ns_table_name, 'f')
+
+      @shell.command('move_namespaces_rsgroup',
+                     group_name,
+                     [namespace_name])
+      assert_equal(2, @rsgroup_admin.getRSGroupInfo(group_name).getTables.count)
+
+      group = @hbase.rsgroup_admin.get_rsgroup(group_name)
+      assert_not_nil(group)
+      assert_equal(ns_table_name, group.getTables.iterator.next.toString)
+    end
+
+    define_test 'Test RSGroup Move Server Namespace RSGroup Commands' do
+      ns_group_name = 'test_ns_group'
+      namespace_name = 'test_namespace'
+      ns_table_name = 'test_namespace:test_ns_table'
+
+      @shell.command('add_rsgroup', ns_group_name)
+      assert_not_nil(@rsgroup_admin.getRSGroupInfo(ns_group_name))
+
+      @shell.command('move_tables_rsgroup',
+                     'default',
+                     [ns_table_name])
+
+      group_servers = @rsgroup_admin.getRSGroupInfo('default').getServers
+      hostport_str = group_servers.iterator.next.toString
+      @shell.command('move_servers_namespaces_rsgroup',
+                     ns_group_name,
+                     [hostport_str],
+                     [namespace_name])
+      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)
+    end
+
     # we test exceptions that could be thrown by the ruby wrappers
     define_test 'Test bogus arguments' do
       assert_raise(ArgumentError) do


Mime
View raw message