kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: KAFKA-3112; Warn instead of error on unresolvable bootstrap server
Date Sat, 07 May 2016 08:06:01 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 717eea835 -> c4bbf3424


KAFKA-3112; Warn instead of error on unresolvable bootstrap server

so that unresolvable DNS names are ignored and only throw an error if no other bootstrap servers
are resolvable.

Author: Jonathan Bond <jbond@netflix.com>

Reviewers: Ewen Cheslack-Postava <me@ewencp.org>, Grant Henke <granthenke@gmail.com>,
Ismael Juma <ismael@juma.me.uk>

Closes #792 from bondj/KAFKA-3112


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/c4bbf342
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/c4bbf342
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/c4bbf342

Branch: refs/heads/trunk
Commit: c4bbf342432291220242ad4177fd72a959ddcb94
Parents: 717eea8
Author: Jonathan Bond <jbond@netflix.com>
Authored: Sat May 7 09:05:55 2016 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Sat May 7 09:05:55 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/kafka/clients/ClientUtils.java | 10 ++++++----
 .../org/apache/kafka/clients/ClientUtilsTest.java  | 17 +++++++++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/c4bbf342/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java b/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java
index ad9c5d0..0c12ea1 100644
--- a/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java
+++ b/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java
@@ -45,16 +45,18 @@ public class ClientUtils {
                     throw new ConfigException("Invalid url in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG
+ ": " + url);
                 try {
                     InetSocketAddress address = new InetSocketAddress(host, port);
-                    if (address.isUnresolved())
-                        throw new ConfigException("DNS resolution failed for url in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG
+ ": " + url);
-                    addresses.add(address);
+                    if (address.isUnresolved()) {
+                        log.warn("Removing server from " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG
+ " as DNS resolution failed: " + url);
+                    } else {
+                        addresses.add(address);
+                    }
                 } catch (NumberFormatException e) {
                     throw new ConfigException("Invalid port in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG
+ ": " + url);
                 }
             }
         }
         if (addresses.size() < 1)
-            throw new ConfigException("No bootstrap urls given in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
+            throw new ConfigException("No resolvable bootstrap urls given in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
         return addresses;
     }
 

http://git-wip-us.apache.org/repos/asf/kafka/blob/c4bbf342/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java b/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
index d6a4019..2c1db44 100644
--- a/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
+++ b/clients/src/test/java/org/apache/kafka/clients/ClientUtilsTest.java
@@ -18,8 +18,11 @@ package org.apache.kafka.clients;
 
 import org.apache.kafka.common.config.ConfigException;
 import org.junit.Test;
+import static org.junit.Assert.assertEquals;
 
+import java.net.InetSocketAddress;
 import java.util.Arrays;
+import java.util.List;
 
 public class ClientUtilsTest {
 
@@ -29,14 +32,24 @@ public class ClientUtilsTest {
         check("mydomain.com:8080");
         check("[::1]:8000");
         check("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:1234", "mydomain.com:10000");
+        List<InetSocketAddress> validatedAddresses = check("some.invalid.hostname.foo.bar:9999",
"mydomain.com:10000");
+        assertEquals(1, validatedAddresses.size());
+        InetSocketAddress onlyAddress = validatedAddresses.get(0);
+        assertEquals("mydomain.com", onlyAddress.getHostName());
+        assertEquals(10000, onlyAddress.getPort());
     }
 
     @Test(expected = ConfigException.class)
     public void testNoPort() {
         check("127.0.0.1");
     }
+    
+    @Test(expected = ConfigException.class)
+    public void testOnlyBadHostname() {
+        check("some.invalid.hostname.foo.bar:9999");
+    }
 
-    private void check(String... url) {
-        ClientUtils.parseAndValidateAddresses(Arrays.asList(url));
+    private List<InetSocketAddress> check(String... url) {
+        return ClientUtils.parseAndValidateAddresses(Arrays.asList(url));
     }
 }


Mime
View raw message