kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-5953: Register all jdbc drivers available in plugin and class paths
Date Fri, 06 Oct 2017 18:42:07 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 196bcfca0 -> 974d6fec9


KAFKA-5953: Register all jdbc drivers available in plugin and class paths

Author: Konstantine Karantasis <konstantine@confluent.io>

Reviewers: Randall Hauch <rhauch@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes #4030 from kkonstantine/KAFKA-5953-Connect-classloader-isolation-may-be-broken-for-JDBC-drivers


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

Branch: refs/heads/trunk
Commit: 974d6fec93b779cd2f9036d0ea89cf1b0917de7b
Parents: 196bcfc
Author: Konstantine Karantasis <konstantine@confluent.io>
Authored: Fri Oct 6 11:42:04 2017 -0700
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Fri Oct 6 11:42:04 2017 -0700

----------------------------------------------------------------------
 .../isolation/DelegatingClassLoader.java        | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/974d6fec/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java
----------------------------------------------------------------------
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java
b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java
index ac0530e..0c133b9 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java
@@ -35,12 +35,15 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.sql.Driver;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.SortedSet;
@@ -209,6 +212,40 @@ public class DelegatingClassLoader extends URLClassLoader {
             addPlugins(plugins.transformations(), loader);
             transformations.addAll(plugins.transformations());
         }
+
+        loadJdbcDrivers(loader);
+    }
+
+    private void loadJdbcDrivers(final ClassLoader loader) {
+        // Apply here what java.sql.DriverManager does to discover and register classes
+        // implementing the java.sql.Driver interface.
+        AccessController.doPrivileged(
+                new PrivilegedAction<Void>() {
+                    public Void run() {
+                        ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(
+                                Driver.class,
+                                loader
+                        );
+                        Iterator<Driver> driversIterator = loadedDrivers.iterator();
+                        try {
+                            while (driversIterator.hasNext()) {
+                                Driver driver = driversIterator.next();
+                                log.debug(
+                                        "Registered java.sql.Driver: {} to java.sql.DriverManager",
+                                        driver
+                                );
+                            }
+                        } catch (Throwable t) {
+                            log.debug(
+                                    "Ignoring java.sql.Driver classes listed in resources
but not"
+                                            + " present in class loader's classpath: ",
+                                    t
+                            );
+                        }
+                        return null;
+                    }
+                }
+        );
     }
 
     private PluginScanResult scanPluginPath(


Mime
View raw message