You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2016/03/17 02:44:17 UTC
hbase git commit: HBASE-12940 Expose listPeerConfigs and
getPeerConfig to the HBase shell (Geoffrey Jacoby)
Repository: hbase
Updated Branches:
refs/heads/master ac1a7a4a7 -> 448ac5b37
HBASE-12940 Expose listPeerConfigs and getPeerConfig to the HBase shell (Geoffrey Jacoby)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/448ac5b3
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/448ac5b3
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/448ac5b3
Branch: refs/heads/master
Commit: 448ac5b37c5430c12df722f06580d44f4dd89da5
Parents: ac1a7a4
Author: tedyu <yu...@gmail.com>
Authored: Wed Mar 16 18:42:52 2016 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Wed Mar 16 18:42:52 2016 -0700
----------------------------------------------------------------------
.../src/main/ruby/hbase/replication_admin.rb | 8 +++
hbase-shell/src/main/ruby/shell.rb | 2 +
.../main/ruby/shell/commands/get_peer_config.rb | 53 ++++++++++++++++++++
.../ruby/shell/commands/list_peer_configs.rb | 43 ++++++++++++++++
.../test/ruby/hbase/replication_admin_test.rb | 43 ++++++++++++++++
5 files changed, 149 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/448ac5b3/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 2a24829..1c64f09 100644
--- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb
@@ -170,5 +170,13 @@ module Hbase
tableName = TableName.valueOf(table_name)
@replication_admin.disableTableRep(tableName)
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
http://git-wip-us.apache.org/repos/asf/hbase/blob/448ac5b3/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 ed7dd76..e5c9a31 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -363,6 +363,8 @@ Shell.load_command_group(
remove_peer_tableCFs
enable_table_replication
disable_table_replication
+ get_peer_config
+ list_peer_configs
]
)
http://git-wip-us.apache.org/repos/asf/hbase/blob/448ac5b3/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb b/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
new file mode 100644
index 0000000..ee02229
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
@@ -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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hbase/blob/448ac5b3/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb b/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
new file mode 100644
index 0000000..fc6e4a7
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
@@ -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
http://git-wip-us.apache.org/repos/asf/hbase/blob/448ac5b3/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 648efa7..4923560 100644
--- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
@@ -172,6 +172,49 @@ module Hbase
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
# 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