HBASE-12940 Expose listPeerConfigs and getPeerConfig to the HBase shell (Geoffrey Jacoby)
This commit is contained in:
parent
ac1a7a4a78
commit
448ac5b37c
|
@ -170,5 +170,13 @@ module Hbase
|
||||||
tableName = TableName.valueOf(table_name)
|
tableName = TableName.valueOf(table_name)
|
||||||
@replication_admin.disableTableRep(tableName)
|
@replication_admin.disableTableRep(tableName)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list_peer_configs
|
||||||
|
@replication_admin.list_peer_configs
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_peer_config(id)
|
||||||
|
@replication_admin.get_peer_config(id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -363,6 +363,8 @@ Shell.load_command_group(
|
||||||
remove_peer_tableCFs
|
remove_peer_tableCFs
|
||||||
enable_table_replication
|
enable_table_replication
|
||||||
disable_table_replication
|
disable_table_replication
|
||||||
|
get_peer_config
|
||||||
|
list_peer_configs
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
# 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 GetPeerConfig < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
Outputs the cluster key, replication endpoint class (if present), and any replication configuration parameters
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(id)
|
||||||
|
peer_config = replication_admin.get_peer_config(id)
|
||||||
|
format_simple_command do
|
||||||
|
format_peer_config(peer_config)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_peer_config(peer_config)
|
||||||
|
cluster_key = peer_config.get_cluster_key
|
||||||
|
endpoint = peer_config.get_replication_endpoint_impl
|
||||||
|
|
||||||
|
unless cluster_key.nil?
|
||||||
|
formatter.row(["Cluster Key", cluster_key])
|
||||||
|
end
|
||||||
|
unless endpoint.nil?
|
||||||
|
formatter.row(["Replication Endpoint", endpoint])
|
||||||
|
end
|
||||||
|
unless peer_config.get_configuration.nil?
|
||||||
|
peer_config.get_configuration.each do |config_entry|
|
||||||
|
formatter.row(config_entry)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,43 @@
|
||||||
|
# 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 ListPeerConfigs < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
No-argument method that outputs the replication peer configuration for each peer defined on this cluster.
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command
|
||||||
|
format_simple_command do
|
||||||
|
peer_configs = replication_admin.list_peer_configs
|
||||||
|
unless peer_configs.nil?
|
||||||
|
peer_configs.each do |peer_config_entry|
|
||||||
|
peer_id = peer_config_entry[0]
|
||||||
|
peer_config = peer_config_entry[1]
|
||||||
|
formatter.row(["PeerId", peer_id])
|
||||||
|
GetPeerConfig.new(@shell).format_peer_config(peer_config)
|
||||||
|
formatter.row([" "])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -172,6 +172,49 @@ module Hbase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_test "get_peer_config: works with simple clusterKey peer" do
|
||||||
|
cluster_key = "localhost:2181:/hbase-test"
|
||||||
|
args = { CLUSTER_KEY => cluster_key }
|
||||||
|
replication_admin.add_peer(@peer_id, args)
|
||||||
|
peer_config = replication_admin.get_peer_config(@peer_id)
|
||||||
|
assert_equal(cluster_key, peer_config.get_cluster_key)
|
||||||
|
#cleanup
|
||||||
|
replication_admin.remove_peer(@peer_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
define_test "get_peer_config: works with replicationendpointimpl peer and config params" do
|
||||||
|
repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest"
|
||||||
|
config_params = { "config1" => "value1", "config2" => "value2" }
|
||||||
|
args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params}
|
||||||
|
replication_admin.add_peer(@peer_id, args)
|
||||||
|
peer_config = replication_admin.get_peer_config(@peer_id)
|
||||||
|
assert_equal(repl_impl, peer_config.get_replication_endpoint_impl)
|
||||||
|
assert_equal(2, peer_config.get_configuration.size)
|
||||||
|
assert_equal("value1", peer_config.get_configuration.get("config1"))
|
||||||
|
#cleanup
|
||||||
|
replication_admin.remove_peer(@peer_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
define_test "list_peer_configs: returns all peers' ReplicationPeerConfig objects" do
|
||||||
|
cluster_key = "localhost:2181:/hbase-test"
|
||||||
|
args = { CLUSTER_KEY => cluster_key }
|
||||||
|
peer_id_second = '2'
|
||||||
|
replication_admin.add_peer(@peer_id, args)
|
||||||
|
|
||||||
|
repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest"
|
||||||
|
config_params = { "config1" => "value1", "config2" => "value2" }
|
||||||
|
args2 = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params}
|
||||||
|
replication_admin.add_peer(peer_id_second, args2)
|
||||||
|
|
||||||
|
peer_configs = replication_admin.list_peer_configs
|
||||||
|
assert_equal(2, peer_configs.size)
|
||||||
|
assert_equal(cluster_key, peer_configs.get(@peer_id).get_cluster_key)
|
||||||
|
assert_equal(repl_impl, peer_configs.get(peer_id_second).get_replication_endpoint_impl)
|
||||||
|
#cleanup
|
||||||
|
replication_admin.remove_peer(@peer_id)
|
||||||
|
replication_admin.remove_peer(peer_id_second)
|
||||||
|
end
|
||||||
|
|
||||||
# assert_raise fails on native exceptions - https://jira.codehaus.org/browse/JRUBY-5279
|
# 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.
|
# 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
|
# define_test "add_peer: adding a second peer with same id should error" do
|
||||||
|
|
Loading…
Reference in New Issue