Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4B8A4200BC1 for ; Tue, 1 Nov 2016 20:47:44 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4A558160B0D; Tue, 1 Nov 2016 19:47:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 82631160B07 for ; Tue, 1 Nov 2016 20:47:43 +0100 (CET) Received: (qmail 42961 invoked by uid 500); 1 Nov 2016 19:47:40 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 42320 invoked by uid 99); 1 Nov 2016 19:47:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Nov 2016 19:47:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DD484EF9A4; Tue, 1 Nov 2016 19:47:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: larsh@apache.org To: commits@hbase.apache.org Date: Tue, 01 Nov 2016 19:47:50 -0000 Message-Id: <53518f0babb34834ad03098ee86b3f8b@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [12/50] hbase git commit: HBASE-16379 [replication] Minor improvement to replication/copy_tables_desc.rb archived-at: Tue, 01 Nov 2016 19:47:44 -0000 HBASE-16379 [replication] Minor improvement to replication/copy_tables_desc.rb Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c2830638 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c2830638 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c2830638 Branch: refs/heads/0.98 Commit: c2830638709897fd53baece55f7a22848a932b93 Parents: 62690df Author: Esteban Gutierrez Authored: Mon Aug 8 16:10:29 2016 -0700 Committer: Andrew Purtell Committed: Wed Aug 24 17:54:36 2016 -0700 ---------------------------------------------------------------------- bin/replication/copy_tables_desc.rb | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/c2830638/bin/replication/copy_tables_desc.rb ---------------------------------------------------------------------- diff --git a/bin/replication/copy_tables_desc.rb b/bin/replication/copy_tables_desc.rb index bc70031..07b17a8 100644 --- a/bin/replication/copy_tables_desc.rb +++ b/bin/replication/copy_tables_desc.rb @@ -27,7 +27,6 @@ include Java import org.apache.commons.logging.LogFactory import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.HConstants -import org.apache.hadoop.hbase.EmptyWatcher import org.apache.hadoop.hbase.client.HBaseAdmin import org.apache.hadoop.hbase.HTableDescriptor import org.apache.hadoop.conf.Configuration @@ -37,11 +36,32 @@ NAME = "copy_tables_desc" # Print usage for this script def usage - puts 'Usage: %s.rb master_zookeeper.quorum.peers:clientport:znode_parent slave_zookeeper.quorum.peers:clientport:znode_parent' % NAME + puts 'Usage: %s.rb master_zookeeper.quorum.peers:clientport:znode_parent slave_zookeeper.quorum.peers:clientport:znode_parent [table1,table2,table3,...]' % NAME exit! end -if ARGV.size != 2 +def copy (src, dst, table) + # verify if table exists in source cluster + begin + t = src.getTableDescriptor(table.to_java_bytes) + rescue org.apache.hadoop.hbase.TableNotFoundException + puts "Source table \"%s\" doesn't exist, skipping." % table + return + end + + # verify if table *doesn't* exists in the target cluster + begin + dst.createTable(t) + rescue org.apache.hadoop.hbase.TableExistsException + puts "Destination table \"%s\" exists in remote cluster, skipping." % table + return + end + + puts "Schema for table \"%s\" was succesfully copied to remote cluster." % table +end + + +if ARGV.size < 2 || ARGV.size > 3 usage end @@ -51,6 +71,8 @@ parts1 = ARGV[0].split(":") parts2 = ARGV[1].split(":") +parts3 = ARGV[2].split(",") unless ARGV[2].nil? + c1 = HBaseConfiguration.create() c1.set(HConstants::ZOOKEEPER_QUORUM, parts1[0]) c1.set("hbase.zookeeper.property.clientPort", parts1[1]) @@ -65,9 +87,12 @@ c2.set(HConstants::ZOOKEEPER_ZNODE_PARENT, parts2[2]) admin2 = HBaseAdmin.new(c2) -for t in admin1.listTables() - admin2.createTable(t) +if parts3.nil? + admin1.listTableNames().each do |t| + copy(admin1, admin2, t.nameAsString()) + end +else + parts3.each do |t| + copy(admin1, admin2, t) + end end - - -puts "All descriptions were copied"