Return-Path: X-Original-To: apmail-zookeeper-commits-archive@www.apache.org Delivered-To: apmail-zookeeper-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E54A18588 for ; Sun, 18 Oct 2015 17:00:50 +0000 (UTC) Received: (qmail 71348 invoked by uid 500); 18 Oct 2015 17:00:50 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 71319 invoked by uid 500); 18 Oct 2015 17:00:50 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 71302 invoked by uid 99); 18 Oct 2015 17:00:49 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Oct 2015 17:00:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 7F3331A093D for ; Sun, 18 Oct 2015 17:00:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id pS_9Xil6c7ty for ; Sun, 18 Oct 2015 17:00:42 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id BB5C22118F for ; Sun, 18 Oct 2015 17:00:41 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4E4BDE049C for ; Sun, 18 Oct 2015 17:00:41 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 4B4283A06F5 for ; Sun, 18 Oct 2015 17:00:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1709293 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java Date: Sun, 18 Oct 2015 17:00:41 -0000 To: commits@zookeeper.apache.org From: cnauroth@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151018170041.4B4283A06F5@svn01-us-west.apache.org> Author: cnauroth Date: Sun Oct 18 17:00:41 2015 New Revision: 1709293 URL: http://svn.apache.org/viewvc?rev=1709293&view=rev Log: ZOOKEEPER-1460: IPv6 literal address not supported for quorum members (Joseph Walton via cnauroth) Modified: zookeeper/trunk/CHANGES.txt zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java Modified: zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1709293&r1=1709292&r2=1709293&view=diff ============================================================================== --- zookeeper/trunk/CHANGES.txt (original) +++ zookeeper/trunk/CHANGES.txt Sun Oct 18 17:00:41 2015 @@ -187,6 +187,9 @@ BUGFIXES: ZOOKEEPER-2281: ZK Server startup fails if there are spaces in the JAVA_HOME path (Neha Bathra via cnauroth) + ZOOKEEPER-1460: IPv6 literal address not supported for quorum members + (Joseph Walton via cnauroth) + IMPROVEMENTS: ZOOKEEPER-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex) Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=1709293&r1=1709292&r2=1709293&view=diff ============================================================================== --- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java (original) +++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java Sun Oct 18 17:00:41 2015 @@ -173,17 +173,38 @@ public class QuorumPeer extends ZooKeepe type = LearnerType.PARTICIPANT; } else { throw new ConfigException("Unrecognised peertype: " + s); - } - } + } + } + + private static String[] splitWithLeadingHostname(String s) + throws ConfigException + { + /* Does it start with an IPv6 literal? */ + if (s.startsWith("[")) { + int i = s.indexOf("]:"); + if (i < 0) { + throw new ConfigException(s + " starts with '[' but has no matching ']:'"); + } + + String[] sa = s.substring(i + 2).split(":"); + String[] nsa = new String[sa.length + 1]; + nsa[0] = s.substring(1, i); + System.arraycopy(sa, 0, nsa, 1, sa.length); + + return nsa; + } else { + return s.split(":"); + } + } - private static final String wrongFormat = " does not have the form server_cofig or server_config;client_config"+ + private static final String wrongFormat = " does not have the form server_config or server_config;client_config"+ " where server_config is host:port:port or host:port:port:type and client_config is port or host:port"; - + public QuorumServer(long sid, String addressStr) throws ConfigException { // LOG.warn("sid = " + sid + " addressStr = " + addressStr); this.id = sid; String serverClientParts[] = addressStr.split(";"); - String serverParts[] = serverClientParts[0].split(":"); + String serverParts[] = splitWithLeadingHostname(serverClientParts[0]); if ((serverClientParts.length > 2) || (serverParts.length < 3) || (serverParts.length > 4)) { throw new ConfigException(addressStr + wrongFormat); @@ -191,7 +212,7 @@ public class QuorumPeer extends ZooKeepe if (serverClientParts.length == 2) { //LOG.warn("ClientParts: " + serverClientParts[1]); - String clientParts[] = serverClientParts[1].split(":"); + String clientParts[] = splitWithLeadingHostname(serverClientParts[1]); if (clientParts.length > 2) { throw new ConfigException(addressStr + wrongFormat); } @@ -252,11 +273,21 @@ public class QuorumPeer extends ZooKeepe this.myAddrs = excludedSpecialAddresses(this.myAddrs); } + private static String delimitedHostString(InetSocketAddress addr) + { + String host = addr.getHostString(); + if (host.contains(":")) { + return "[" + host + "]"; + } else { + return host; + } + } + public String toString(){ - StringWriter sw = new StringWriter(); + StringWriter sw = new StringWriter(); //addr should never be null, but just to make sure - if (addr !=null) { - sw.append(addr.getHostString()); + if (addr !=null) { + sw.append(delimitedHostString(addr)); sw.append(":"); sw.append(String.valueOf(addr.getPort())); } @@ -268,7 +299,7 @@ public class QuorumPeer extends ZooKeepe else if (type == LearnerType.PARTICIPANT) sw.append(":participant"); if (clientAddr!=null){ sw.append(";"); - sw.append(clientAddr.getHostString()); + sw.append(delimitedHostString(clientAddr)); sw.append(":"); sw.append(String.valueOf(clientAddr.getPort())); } Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java?rev=1709293&r1=1709292&r2=1709293&view=diff ============================================================================== --- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java (original) +++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java Sun Oct 18 17:00:41 2015 @@ -16,6 +16,8 @@ */ package org.apache.zookeeper.server.quorum; +import static org.junit.Assert.assertEquals; + import org.apache.zookeeper.ZKTestCase; import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; @@ -57,4 +59,28 @@ public class QuorumServerTest extends ZK qs = new QuorumServer(0, config); Assert.assertEquals("Use hostname", expected, qs.toString()); } + + @Test + public void constructionUnderstandsIpv6LiteralsInServerConfig() throws ConfigException { + String config = "[::1]:1234:1236:participant"; + QuorumServer qs = new QuorumServer(0, config); + assertEquals("[0:0:0:0:0:0:0:1]:1234:1236:participant", qs.toString()); + } + + @Test + public void constructionUnderstandsIpv6LiteralsInClientConfig() throws ConfigException { + String config = "127.0.0.1:1234:1236:participant;[::1]:1237"; + QuorumServer qs = new QuorumServer(0, config); + assertEquals("127.0.0.1:1234:1236:participant;[0:0:0:0:0:0:0:1]:1237", qs.toString()); + } + + @Test(expected = ConfigException.class) + public void unbalancedIpv6LiteralsInServerConfigFailToBeParsed() throws ConfigException { + new QuorumServer(0, "[::1:1234:1236:participant"); + } + + @Test(expected = ConfigException.class) + public void unbalancedIpv6LiteralsInClientConfigFailToBeParsed() throws ConfigException { + new QuorumServer(0, "127.0.0.1:1234:1236:participant;[::1:1237"); + } }