From 9772e38a3a013710eaff2c15ba3aa43e0d5f1e92 Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Mon, 19 Jan 2015 18:49:51 -0600 Subject: [PATCH] HBASE-12867 Add command 'add_custom_peer' to hbase shell to support custom endpoint replication --- .../hbase/client/replication/ReplicationAdmin.java | 20 +++++++++++ .../src/main/ruby/hbase/replication_admin.rb | 6 ++++ hbase-shell/src/main/ruby/shell.rb | 1 + .../main/ruby/shell/commands/add_custom_peer.rb | 41 ++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 hbase-shell/src/main/ruby/shell/commands/add_custom_peer.rb diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java index 2d5c5e9..97d3926 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java @@ -48,6 +48,7 @@ import org.apache.hadoop.hbase.replication.ReplicationFactory; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.replication.ReplicationPeers; import org.apache.hadoop.hbase.replication.ReplicationQueuesClient; +import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import com.google.common.annotations.VisibleForTesting; @@ -166,6 +167,25 @@ public class ReplicationAdmin implements Closeable { } /** + * Add a new replication endpoint to replicate to. + * @param id a short name that identifies the replication endpoint + * @param replicationEndpointImpl a custom replication endpoint class that + * implements org.apache.hadoop.hbase.replication.ReplicationEndpoint + * @param tableCFs the table and column-family list which will be replicated for this peer. + * @throws IllegalStateException if there's already one slave since + * multi-slave isn't supported yet. + */ + public void addCustomPeer(String id, String replicationEndpointImpl, String tableCFs) + throws ReplicationException { + // Get the cluster key from the cluster configuration since custom + // replication endpoint doesn't communicate with an external cluster + String clusterKey = ZKUtil.getZooKeeperClusterKey(connection.getConfiguration()); + this.replicationPeers.addPeer(id, + new ReplicationPeerConfig().setClusterKey(clusterKey) + .setReplicationEndpointImpl(replicationEndpointImpl), tableCFs); + } + + /** * Add a new remote slave cluster for replication. * @param id a short name that identifies the cluster * @param peerConfig configuration for the replication slave cluster diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index 6dedb2e..606992a 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -37,6 +37,12 @@ module Hbase end #---------------------------------------------------------------------------------------------- + # Add a new peer cluster to replicate to + def add_custom_peer(id, replicationEndpointImpl, peer_tableCFs = nil) + @replication_admin.addCustomPeer(id, replicationEndpointImpl, peer_tableCFs) + end + + #---------------------------------------------------------------------------------------------- # Remove a peer cluster, stops the replication def remove_peer(id) @replication_admin.removePeer(id) diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 5db2776..65c92a4 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -339,6 +339,7 @@ Shell.load_command_group( :full_name => 'CLUSTER REPLICATION TOOLS', :comment => "In order to use these tools, hbase.replication must be true.", :commands => %w[ + add_custom_peer add_peer remove_peer list_peers diff --git a/hbase-shell/src/main/ruby/shell/commands/add_custom_peer.rb b/hbase-shell/src/main/ruby/shell/commands/add_custom_peer.rb new file mode 100644 index 0000000..5086d3d --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/add_custom_peer.rb @@ -0,0 +1,41 @@ +# +# +# 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 AddCustomPeer< Command + def help + return <<-EOF +Add a custom replication endpoint peer to replicate to. The id must be a short. The +replicationEndpointImpl must be the classname of a class that implements ReplicationEndpoint. +Examples: + + hbase> add_custom_peer '1', "com.example.hbase.MyCustomEndpoint" + hbase> add_custom_peer '2', "com.example.hbase.MyCustomEndpoint", "tab1; tab2:cf1; tab3:cf2,cf3" +EOF + end + + def command(id, replicationEndpointImpl, peer_tableCFs = nil) + format_simple_command do + replication_admin.add_custom_peer(id, replicationEndpointImpl, peer_tableCFs) + end + end + end + end +end -- 2.2.2