From 305fc182c02d1b159ee77125395e167749c45577 Mon Sep 17 00:00:00 2001 From: Geoffrey Date: Wed, 7 Sep 2016 14:48:33 -0700 Subject: [PATCH] HBASE-16576 - Shell add_peer doesn't allow setting cluster_key for custom endpoints --- hbase-shell/src/main/ruby/hbase/replication_admin.rb | 2 -- hbase-shell/src/main/ruby/shell/commands/add_peer.rb | 6 +++++- .../src/test/ruby/hbase/replication_admin_test.rb | 17 +++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index 7eae7af..4de3962 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -51,8 +51,6 @@ module Hbase # or neither are provided if endpoint_classname.nil? and cluster_key.nil? raise(ArgumentError, "Either ENDPOINT_CLASSNAME or CLUSTER_KEY must be specified.") - elsif !endpoint_classname.nil? and !cluster_key.nil? - raise(ArgumentError, "ENDPOINT_CLASSNAME and CLUSTER_KEY cannot both be specified.") end # Cluster Key is required for ReplicationPeerConfig for a custom replication endpoint diff --git a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb index 558e86d..e9431cf 100644 --- a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb @@ -52,8 +52,12 @@ the key TABLE_CFS. hbase> add_peer '11', ENDPOINT_CLASSNAME => 'org.apache.hadoop.hbase.MyReplicationEndpoint', DATA => { "key1" => 1 }, CONFIG => { "config1" => "value1", "config2" => "value2" }, TABLE_CFS => { "table1" => [], "ns2:table2" => ["cf1"], "ns3:table3" => ["cf1", "cf2"] } + hbase> add_peer '12', ENDPOINT_CLASSNAME => 'org.apache.hadoop.hbase.MyReplicationEndpoint', + CLUSTER_KEY => "server2.cie.com:2181:/hbase" + +Note: Either CLUSTER_KEY or ENDPOINT_CLASSNAME must be specified. If ENDPOINT_CLASSNAME is specified, CLUSTER_KEY is +optional and should only be specified if a particular custom endpoint requires it. -Note: Either CLUSTER_KEY or ENDPOINT_CLASSNAME must be specified but not both. EOF end 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 cf6eac2..272eb6e 100644 --- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb @@ -55,14 +55,6 @@ module Hbase end end - define_test "add_peer: fail when both CLUSTER_KEY and ENDPOINT_CLASSNAME are specified" do - assert_raise(ArgumentError) do - args = { CLUSTER_KEY => 'zk1,zk2,zk3:2182:/hbase-prod', - ENDPOINT_CLASSNAME => 'org.apache.hadoop.hbase.MyReplicationEndpoint' } - command(:add_peer, @peer_id, args) - end - end - define_test "add_peer: args must be a hash" do assert_raise(ArgumentError) do command(:add_peer, @peer_id, 1) @@ -140,7 +132,10 @@ module Hbase assert_equal(1, command(:list_peers).length) assert(command(:list_peers).key?(@peer_id)) assert_equal(cluster_key, command(:list_peers).fetch(@peer_id).get_cluster_key) - assert_equal(table_cfs_str, command(:show_peer_tableCFs, @peer_id)) + + #Note: below assertion is dependent on the sort order of an unordered map and hence flaky depending on JVM + #Commenting out until HBASE-16274 is worked. + #assert_equal(table_cfs_str, command(:show_peer_tableCFs, @peer_id)) # cleanup for future tests command(:remove_peer, @peer_id) @@ -167,11 +162,13 @@ module Hbase end define_test "get_peer_config: works with replicationendpointimpl peer and config params" do + cluster_key = "localhost:2181:/hbase-test" repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest" config_params = { "config1" => "value1", "config2" => "value2" } - args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params} + args = { CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params} command(:add_peer, @peer_id, args) peer_config = command(:get_peer_config, @peer_id) + assert_equal(cluster_key, peer_config.get_cluster_key) 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")) -- 2.9.0