hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject hbase git commit: HBASE-12940 Expose listPeerConfigs and getPeerConfig to the HBase shell (Geoffrey Jacoby)
Date Fri, 18 Mar 2016 00:49:04 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 a68458a4d -> deaf0f3d0


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/deaf0f3d
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/deaf0f3d
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/deaf0f3d

Branch: refs/heads/0.98
Commit: deaf0f3d01cacb4917e67f0db726cd5a4194e3f0
Parents: a68458a
Author: tedyu <yuzhihong@gmail.com>
Authored: Wed Mar 16 19:52:25 2016 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Thu Mar 17 17:42:06 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/deaf0f3d/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 c4061b6..3c39bdf 100644
--- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb
@@ -160,5 +160,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/deaf0f3d/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 f56499c..2398aaa 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -343,6 +343,8 @@ Shell.load_command_group(
     list_replicated_tables
     enable_table_replication
     disable_table_replication
+    get_peer_config
+    list_peer_configs
   ]
 )
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/deaf0f3d/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/deaf0f3d/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/deaf0f3d/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 ba2bcc9..14f4a0b 100644
--- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
@@ -168,6 +168,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


Mime
View raw message