Repository: hbase Updated Branches: refs/heads/branch-2 77ca66038 -> 90b9ed152
HBASE-21662 Add append_peer_exclude_namespaces and remove_peer_exclude_namespaces shell commands Signed-off-by: Guanghao Zhang <zg...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/90b9ed15 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/90b9ed15 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/90b9ed15 Branch: refs/heads/branch-2 Commit: 90b9ed15231c01f979c76620f5201bdcd4975ac9 Parents: 77ca660 Author: meiyi <myime...@gamil.com> Authored: Wed Jan 2 14:08:22 2019 +0800 Committer: Guanghao Zhang <zg...@apache.org> Committed: Thu Jan 3 10:35:30 2019 +0800 ---------------------------------------------------------------------- .../src/main/ruby/hbase/replication_admin.rb | 39 +++++++++++ hbase-shell/src/main/ruby/shell.rb | 2 + .../commands/append_peer_exclude_namespaces.rb | 47 +++++++++++++ .../commands/remove_peer_exclude_namespaces.rb | 45 ++++++++++++ .../test/ruby/hbase/replication_admin_test.rb | 74 ++++++++++++++++++++ 5 files changed, 207 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/90b9ed15/hbase-shell/src/main/ruby/hbase/replication_admin.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index d46b468..af2b071 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -282,6 +282,45 @@ module Hbase end end + # Append exclude namespaces config for the specified peer + def append_peer_exclude_namespaces(id, namespaces) + unless namespaces.nil? + rpc = get_peer_config(id) + unless rpc.nil? + if rpc.getExcludeNamespaces.nil? + ns_set = java.util.HashSet.new + else + ns_set = java.util.HashSet.new(rpc.getExcludeNamespaces) + end + namespaces.each do |n| + ns_set.add(n) + end + builder = ReplicationPeerConfig.newBuilder(rpc) + builder.setExcludeNamespaces(ns_set) + @admin.updateReplicationPeerConfig(id, builder.build) + end + end + end + + # Remove exclude namespaces config for the specified peer + def remove_peer_exclude_namespaces(id, namespaces) + unless namespaces.nil? + rpc = get_peer_config(id) + unless rpc.nil? + ns_set = rpc.getExcludeNamespaces + unless ns_set.nil? + ns_set = java.util.HashSet.new(ns_set) + namespaces.each do |n| + ns_set.remove(n) + end + end + builder = ReplicationPeerConfig.newBuilder(rpc) + builder.setExcludeNamespaces(ns_set) + @admin.updateReplicationPeerConfig(id, builder.build) + end + end + end + def set_peer_replicate_all(id, replicate_all) rpc = get_peer_config(id) return if rpc.nil? http://git-wip-us.apache.org/repos/asf/hbase/blob/90b9ed15/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 9aada3a..0ed2623 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -384,6 +384,8 @@ Shell.load_command_group( append_peer_namespaces remove_peer_namespaces set_peer_exclude_namespaces + append_peer_exclude_namespaces + remove_peer_exclude_namespaces show_peer_tableCFs set_peer_tableCFs set_peer_exclude_tableCFs http://git-wip-us.apache.org/repos/asf/hbase/blob/90b9ed15/hbase-shell/src/main/ruby/shell/commands/append_peer_exclude_namespaces.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/append_peer_exclude_namespaces.rb b/hbase-shell/src/main/ruby/shell/commands/append_peer_exclude_namespaces.rb new file mode 100644 index 0000000..4f500c8 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/append_peer_exclude_namespaces.rb @@ -0,0 +1,47 @@ +# +# +# 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 AppendPeerExcludeNamespaces < Command + def help + <<-EOF +Append the namespaces which not replicated for the specified peer. + +Note: + 1. The replicate_all flag need to be true when append exclude namespaces. + 2. Append a exclude namespace in the peer config means that all tables in this + namespace will not be replicated to the peer cluster. If peer config + already has a exclude table, then not allow append this table's namespace + as a exclude namespace. + +Examples: + + # append ns1,ns2 to be not replicable for peer '2'. + hbase> append_peer_exclude_namespaces '2', ["ns1", "ns2"] + + EOF + end + + def command(id, namespaces) + replication_admin.append_peer_exclude_namespaces(id, namespaces) + end + end + end +end http://git-wip-us.apache.org/repos/asf/hbase/blob/90b9ed15/hbase-shell/src/main/ruby/shell/commands/remove_peer_exclude_namespaces.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/remove_peer_exclude_namespaces.rb b/hbase-shell/src/main/ruby/shell/commands/remove_peer_exclude_namespaces.rb new file mode 100644 index 0000000..0298ce9 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/remove_peer_exclude_namespaces.rb @@ -0,0 +1,45 @@ +# +# +# 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 RemovePeerExcludeNamespaces < Command + def help + <<-EOF +Remove the namespaces which not replicated for the specified peer. + +Note: + 1. The replicate_all flag need to be true when remove exclude namespaces. + 2. Remove a exclude namespace in the peer config means that all tables in this + namespace will be replicated to the peer cluster. + +Examples: + + # remove ns1 from the not replicable namespaces for peer '2'. + hbase> remove_peer_exclude_namespaces '2', ["ns1", "ns2"] + + EOF + end + + def command(id, namespaces) + replication_admin.remove_peer_exclude_namespaces(id, namespaces) + end + end + end +end http://git-wip-us.apache.org/repos/asf/hbase/blob/90b9ed15/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb index 072aab2..5e2dbea 100644 --- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb @@ -587,6 +587,80 @@ module Hbase assert_equal("value2", Bytes.to_string(peer_config.get_peer_data.get(Bytes.toBytes("data2")))) end + define_test "append_peer_exclude_namespaces: works with namespaces array" do + cluster_key = "zk4,zk5,zk6:11000:/hbase-test" + args = {CLUSTER_KEY => cluster_key} + command(:add_peer, @peer_id, args) + command(:set_peer_replicate_all, @peer_id, true) + + namespaces = ["ns1", "ns2"] + namespaces_str = "!ns1;ns2" + command(:append_peer_exclude_namespaces, @peer_id, namespaces) + assert_equal(1, command(:list_peers).length) + assert_equal(@peer_id, command(:list_peers).get(0).getPeerId) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(namespaces_str, + replication_admin.show_peer_exclude_namespaces(peer_config)) + + namespaces = ["ns3"] + namespaces_str = "!ns1;ns2;ns3" + command(:append_peer_exclude_namespaces, @peer_id, namespaces) + assert_equal(1, command(:list_peers).length) + assert_equal(@peer_id, command(:list_peers).get(0).getPeerId) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(namespaces_str, + replication_admin.show_peer_exclude_namespaces(peer_config)) + + # append a namespace which is already excluded in the peer config + command(:append_peer_exclude_namespaces, @peer_id, namespaces) + assert_equal(1, command(:list_peers).length) + assert_equal(@peer_id, command(:list_peers).get(0).getPeerId) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(namespaces_str, + replication_admin.show_peer_exclude_namespaces(peer_config)) + + # cleanup for future tests + command(:remove_peer, @peer_id) + end + + define_test "remove_peer_exclude_namespaces: works with namespaces array" do + cluster_key = "zk4,zk5,zk6:11000:/hbase-test" + args = {CLUSTER_KEY => cluster_key} + command(:add_peer, @peer_id, args) + + namespaces = ["ns1", "ns2", "ns3"] + command(:set_peer_exclude_namespaces, @peer_id, namespaces) + + namespaces = ["ns1", "ns2"] + namespaces_str = "!ns3" + command(:remove_peer_exclude_namespaces, @peer_id, namespaces) + assert_equal(1, command(:list_peers).length) + assert_equal(@peer_id, command(:list_peers).get(0).getPeerId) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(namespaces_str, + replication_admin.show_peer_exclude_namespaces(peer_config)) + + namespaces = ["ns3"] + namespaces_str = nil + command(:remove_peer_exclude_namespaces, @peer_id, namespaces) + assert_equal(1, command(:list_peers).length) + assert_equal(@peer_id, command(:list_peers).get(0).getPeerId) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(namespaces_str, + replication_admin.show_peer_exclude_namespaces(peer_config)) + + # remove a namespace which is not in peer config + command(:remove_peer_namespaces, @peer_id, namespaces) + assert_equal(1, command(:list_peers).length) + assert_equal(@peer_id, command(:list_peers).get(0).getPeerId) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(namespaces_str, + replication_admin.show_peer_exclude_namespaces(peer_config)) + + # cleanup for future tests + command(:remove_peer, @peer_id) + end + # assert_raise fails on native exceptions - https://jira.codehaus.org/browse/JRUBY-5279 # Can't catch native Java exception with assert_raise in JRuby 1.6.8 as in the test below. # define_test "add_peer: adding a second peer with same id should error" do