HBASE-21662 Add append_peer_exclude_namespaces and remove_peer_exclude_namespaces shell commands

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
meiyi 2019-01-02 14:08:22 +08:00 committed by Guanghao Zhang
parent 77ca660389
commit 90b9ed1523
5 changed files with 207 additions and 0 deletions

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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