DRILL-3589: Update JDBC driver to shade and minimize dependencies. Update build process to use shading, stop using Proguard. Add simple integration test that verifies that the JDBC driver works correctly with a clean classpath.
Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/4e3b7dc0 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/4e3b7dc0 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/4e3b7dc0 Branch: refs/heads/master Commit: 4e3b7dc0333a01e72d0ea9256331ea1e1dd51181 Parents: e5f529b Author: Jacques Nadeau <[email protected]> Authored: Sun Aug 16 11:46:26 2015 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Sun Sep 13 21:58:34 2015 -0700 ---------------------------------------------------------------------- .../apache/drill/common/util/PathScanner.java | 49 ++- distribution/pom.xml | 5 + .../drill/exec/compile/QueryClassLoader.java | 2 +- .../drill/exec/server/BootStrapContext.java | 10 +- .../java/org/apache/drill/BaseTestQuery.java | 2 +- exec/jdbc-all/pom.xml | 411 +++++++++++-------- .../apache/drill/jdbc/DrillbitClassLoader.java | 106 +++++ .../org/apache/drill/jdbc/ITTestShadedJar.java | 189 +++++++++ exec/jdbc-all/src/test/resources/logback.xml | 54 +++ .../main/java/org/apache/drill/jdbc/Driver.java | 14 +- 10 files changed, 620 insertions(+), 222 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/common/src/main/java/org/apache/drill/common/util/PathScanner.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/drill/common/util/PathScanner.java b/common/src/main/java/org/apache/drill/common/util/PathScanner.java index 16537b6..a44bdf2 100644 --- a/common/src/main/java/org/apache/drill/common/util/PathScanner.java +++ b/common/src/main/java/org/apache/drill/common/util/PathScanner.java @@ -35,7 +35,6 @@ import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; import org.reflections.scanners.SubTypesScanner; import org.reflections.scanners.TypeAnnotationsScanner; -import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; import com.google.common.base.Stopwatch; @@ -143,33 +142,31 @@ public class PathScanner { resourcePathname); final Set<URL> resultUrlSet = Sets.newHashSet(); - final ClassLoader[] netLoaders = ClasspathHelper.classLoaders(classLoaders); - for (ClassLoader classLoader : netLoaders) { - try { - final Enumeration<URL> resourceUrls = - classLoader.getResources(resourcePathname); - while (resourceUrls.hasMoreElements()) { - final URL resourceUrl = resourceUrls.nextElement(); - logger.trace( "- found a(n) {} at {}.", resourcePathname, resourceUrl ); - - int index = resourceUrl.toExternalForm().lastIndexOf(resourcePathname); - if (index != -1 && returnRootPathname) { - final URL classpathRootUrl = - new URL(resourceUrl.toExternalForm().substring(0, index)); - resultUrlSet.add(classpathRootUrl); - logger.debug( "- collected resource's classpath root URL {}.", - classpathRootUrl ); - } else { - resultUrlSet.add(resourceUrl); - logger.debug( "- collected resource URL {}.", resourceUrl ); - } - } - } catch (IOException e) { - if (Reflections.log != null) { - Reflections.log.error( - "Error scanning for resources named " + resourcePathname, e); + final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + try { + final Enumeration<URL> resourceUrls = + classLoader.getResources(resourcePathname); + while (resourceUrls.hasMoreElements()) { + final URL resourceUrl = resourceUrls.nextElement(); + logger.trace("- found a(n) {} at {}.", resourcePathname, resourceUrl); + + int index = resourceUrl.toExternalForm().lastIndexOf(resourcePathname); + if (index != -1 && returnRootPathname) { + final URL classpathRootUrl = + new URL(resourceUrl.toExternalForm().substring(0, index)); + resultUrlSet.add(classpathRootUrl); + logger.debug("- collected resource's classpath root URL {}.", + classpathRootUrl); + } else { + resultUrlSet.add(resourceUrl); + logger.debug("- collected resource URL {}.", resourceUrl); } } + } catch (IOException e) { + if (Reflections.log != null) { + Reflections.log.error( + "Error scanning for resources named " + resourcePathname, e); + } } return resultUrlSet; http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/distribution/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/pom.xml b/distribution/pom.xml index c08efc7..f4a17ac 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -158,6 +158,11 @@ </exclusions> </dependency> <dependency> + <groupId>org.apache.drill.contrib</groupId> + <artifactId>drill-jdbc-storage</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.apache.drill.contrib.storage-hive</groupId> <artifactId>drill-storage-hive-core</artifactId> <version>${project.version}</version> http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java index c4eaae8..3df8f84 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/QueryClassLoader.java @@ -74,7 +74,7 @@ public class QueryClassLoader extends URLClassLoader { private ConcurrentMap<String, byte[]> customClasses = new MapMaker().concurrencyLevel(4).makeMap(); public QueryClassLoader(DrillConfig config, OptionManager sessionOptions) { - super(new URL[0]); + super(new URL[0], Thread.currentThread().getContextClassLoader()); compilerSelector = new ClassCompilerSelector(config, sessionOptions); } http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java index 120c0d0..4530dba 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java @@ -30,9 +30,9 @@ import org.apache.drill.exec.rpc.TransportCheck; import com.codahale.metrics.MetricRegistry; -// TODO: Doc. What kind of context? (For what aspects, RPC? What kind of data?) + public class BootStrapContext implements Closeable { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BootStrapContext.class); + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BootStrapContext.class); private final DrillConfig config; private final EventLoopGroup loop; @@ -70,7 +70,11 @@ public class BootStrapContext implements Closeable { @Override public void close() { - DrillMetrics.resetMetrics(); + try { + DrillMetrics.resetMetrics(); + } catch (Error | Exception e) { + logger.warn("failure resetting metrics.", e); + } loop.shutdownGracefully(); allocator.close(); } http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java index 1381949..cb137ee 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java +++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java @@ -300,7 +300,7 @@ public class BaseTestQuery extends ExecTest { QueryTestUtil.testWithListener(client, type, query, resultListener); } - protected static void testNoResult(String query, Object... args) throws Exception { + public static void testNoResult(String query, Object... args) throws Exception { testNoResult(1, query, args); } http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/jdbc-all/pom.xml ---------------------------------------------------------------------- diff --git a/exec/jdbc-all/pom.xml b/exec/jdbc-all/pom.xml index ed49cfb..5ef6e07 100644 --- a/exec/jdbc-all/pom.xml +++ b/exec/jdbc-all/pom.xml @@ -28,99 +28,29 @@ <name>JDBC JAR with all dependencies</name> <dependencies> - - <!-- start parent dependencies --> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty-handler</artifactId> - <version>4.0.27.Final</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>14.0.1</version> - <scope>provided</scope> - </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${dep.slf4j.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jul-to-slf4j</artifactId> - <version>${dep.slf4j.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>${dep.slf4j.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>log4j-over-slf4j</artifactId> - <version>${dep.slf4j.version}</version> - <scope>provided</scope> </dependency> <dependency> - <groupId>com.googlecode.jmockit</groupId> - <artifactId>jmockit</artifactId> - <version>1.3</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>${dep.junit.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>1.9.5</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <version>1.0.13</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>de.huxhorn.lilith</groupId> - <artifactId>de.huxhorn.lilith.logback.appender.multiplex-classic</artifactId> - <version>0.9.44</version> - <scope>provided</scope> - </dependency> - - <!-- end parent dependencies --> - - <dependency> - <groupId>net.hydromatic</groupId> - <artifactId>optiq-avatica</artifactId> - <version>0.9-drill-r20</version> - <scope>provided</scope> + <groupId>org.apache.drill</groupId> + <artifactId>drill-common</artifactId> + <version>${project.version}</version> + <exclusions> + <exclusion> + <artifactId>javassist</artifactId> + <groupId>javassist</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.drill.exec</groupId> <artifactId>drill-java-exec</artifactId> <version>${project.version}</version> - <scope>provided</scope> <exclusions> <exclusion> <groupId>log4j</groupId> @@ -208,7 +138,6 @@ <groupId>org.apache.drill</groupId> <artifactId>drill-common</artifactId> <version>${project.version}</version> - <scope>provided</scope> <exclusions> <exclusion> <artifactId>javassist</artifactId> @@ -220,7 +149,6 @@ <groupId>org.apache.drill.exec</groupId> <artifactId>drill-jdbc</artifactId> <version>${project.version}</version> - <scope>provided</scope> <exclusions> <exclusion> <artifactId>drill-storage-hive-core</artifactId> @@ -237,148 +165,267 @@ <groupId>org.codehaus.janino</groupId> <artifactId>janino</artifactId> <version>2.6.1</version> - <scope>provided</scope> + <scope>test</scope> </dependency> <!-- Specify xalan and xerces versions to avoid setXIncludeAware error. --> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> - <scope>provided</scope> <exclusions> - <exclusion> - <groupId>xml-apis</groupId> - <artifactId>xml-apis</artifactId> - </exclusion> + <!-- <exclusion> --> + <!-- <groupId>xml-apis</groupId> --> + <!-- <artifactId>xml-apis</artifactId> --> + <!-- </exclusion> --> </exclusions> </dependency> <dependency> <groupId>xalan</groupId> <artifactId>xalan</artifactId> - <scope>provided</scope> <exclusions> - <exclusion> - <groupId>xml-apis</groupId> - <artifactId>xml-apis</artifactId> - </exclusion> + <!-- <exclusion> --> + <!-- <groupId>xml-apis</groupId> --> + <!-- <artifactId>xml-apis</artifactId> --> + <!-- </exclusion> --> </exclusions> </dependency> + + + <!-- Test Dependencies --> <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <version>1.0.13</version> + <groupId>org.apache.drill</groupId> + <artifactId>drill-common</artifactId> + <classifier>tests</classifier> + <version>${project.version}</version> <scope>provided</scope> </dependency> <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-core</artifactId> - <version>1.0.13</version> + <groupId>org.apache.drill.exec</groupId> + <artifactId>drill-java-exec</artifactId> + <classifier>tests</classifier> + <version>${project.version}</version> <scope>provided</scope> </dependency> + </dependencies> <build> <plugins> + + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>define-classpath</id> + <phase>integration-test</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <exportAntProperties>true</exportAntProperties> + <target> + <property name="app.class.path" refid="maven.test.classpath" /> + </target> + </configuration> + </execution> + </executions> + </plugin> <plugin> - <groupId>com.github.wvengen</groupId> - <artifactId>proguard-maven-plugin</artifactId> - <version>2.0.7</version> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.18.1</version> <executions> <execution> - <phase>package</phase> <goals> - <goal>proguard</goal> + <goal>integration-test</goal> + <goal>verify</goal> </goals> </execution> </executions> - <dependencies> - <dependency> - <groupId>net.sf.proguard</groupId> - <artifactId>proguard-base</artifactId> - <version>5.0</version> - <scope>runtime</scope> - </dependency> - </dependencies> + <configuration> - <proguardVersion>5.0</proguardVersion> - <obfuscate>false</obfuscate> - <includeDependencyInjar>true</includeDependencyInjar> - <outjar>${project.build.finalName}-dirty.jar</outjar> - <outputDirectory>${project.build.directory}</outputDirectory> - <maxMemory>6g</maxMemory> - <options> - <option>-dontobfuscate</option> - <option>-dontoptimize</option> - <option>-ignorewarnings</option> - <option>-keep class org.apache.drill.exec.proto.** { *; }</option> - <option>-keep class org.apache.drill.common.types.** { *; }</option> - <option>-keep class org.apache.drill.jdbc.Driver { *; }</option> - <option>-keep class org.apache.drill.jdbc.DrillConnection { *; }</option> - <option>-keep class org.apache.drill.jdbc.DrillStatement { *; }</option> - <option>-keep class org.apache.drill.jdbc.DrillResultSet { *; }</option> - <option>-keep class org.apache.drill.jdbc.impl.DrillJdbc40Factory { *; }</option> - <option>-keep class org.apache.drill.jdbc.impl.DrillJdbc41Factory { *; }</option> - <option>-keep class org.apache.drill.jdbc.proxy.TracingProxyDriver { *; }</option> - <option>-keep class org.apache.drill.common.config.CommonConstants { *; }</option> - <option>-keep class org.apache.drill.common.config.ConfigProvider { *; }</option> - <option>-keep class org.apache.drill.common.config.DrillConfig { *; }</option> - <option>-keep class org.apache.drill.common.config.NestedConfig { *; }</option> + <argLine>-Xms512m -Xmx3g -Ddrill.exec.http.enabled=false -Djava.net.preferIPv4Stack=true + -Ddrill.exec.sys.store.provider.local.write=false + -Dorg.apache.drill.exec.server.Drillbit.system_options="org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on" + -XX:MaxPermSize=256M -XX:MaxDirectMemorySize=3072M + -XX:+CMSClassUnloadingEnabled -ea</argLine> + <additionalClasspathElements> + <additionalClasspathElements>${settings.localRepository}/junit/junit/4.11/junit-4.11.jar</additionalClasspathElements> + <additionalClasspathElements>${settings.localRepository}/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar</additionalClasspathElements> + <additionalClasspathElements>${project.build.directory}/test-classes/</additionalClasspathElements> + </additionalClasspathElements> + <classpathDependencyExcludes> + <classpathDependencyExcludes>*:*</classpathDependencyExcludes> + </classpathDependencyExcludes> - <option>-keep class ch.qos.logback.** { *; }</option> - <option>-keep class org.slf4j.** { *; }</option> - <option>-keep class * implements com.fasterxml.jackson.databind.cfg.ConfigFeature { *; }</option> - <option>-keep class * implements com.fasterxml.jackson.databind.jsontype.TypeIdResolver { *; }</option> - <!-- do not mess with enums, Java doesn't like it --> - <option>-keep enum ** { *; }</option> - </options> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - </exclusion> - <exclusion> - <groupId>net.hydromatic</groupId> - <artifactId>eigenbase-properties</artifactId> - </exclusion> - </exclusions> - <libs> - <lib>${java.home}/lib/rt.jar</lib> - <lib>${java.home}/lib/jsse.jar</lib> - </libs> + <systemPropertyVariables> + <java.io.tmpdir>${project.build.directory}</java.io.tmpdir> + <app.class.path>${app.class.path}</app.class.path> + <project.version>${project.version}</project.version> + </systemPropertyVariables> </configuration> </plugin> <plugin> - <artifactId>maven-antrun-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.4.1</version> <executions> <execution> <phase>package</phase> - <configuration> - <target> - <delete dir="${project.build.directory}/dirty"/> - <mkdir dir="${project.build.directory}/dirty"/> - <unzip src="${project.build.directory}/${project.build.finalName}-dirty.jar" dest="${project.build.directory}/dirty"> - <patternset> - <exclude name="**/*.java"/> - <exclude name="org.codehaus.commons.compiler.properties"/> <!-- This leads jad-ui to not parse classes under 'org/' --> - <exclude name="**/*.SF"/> - <exclude name="**/*.RSA"/> - <exclude name="**/*.DSA"/> - <exclude name="META-INF/services/*"/> - <exclude name="META-INF/*.SF"/> - <exclude name="META-INF/*.RSA"/> - <exclude name="META-INF/*.DSA"/> - </patternset> - </unzip> - <jar destfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/dirty"/> - <delete dir="${project.build.directory}/dirty"/> - </target> - </configuration> <goals> - <goal>run</goal> + <goal>shade</goal> </goals> </execution> </executions> + <configuration> + <shadedArtifactAttached>false</shadedArtifactAttached> + <createDependencyReducedPom>true</createDependencyReducedPom> + <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation> + <minimizeJar>false</minimizeJar> + + <artifactSet> + <includes> + <include>*:*</include> + </includes> + <excludes> + <exclude>org.slf4j:jcl-over-slf4j</exclude> + <exclude>com.dyuproject.protostuff:*</exclude> + <exclude>org.apache.calcite:*</exclude> + <exclude>org.pentaho:*</exclude> + <exclude>org.msgpack:*</exclude> + <exclude>com.googlecode.json-simple:*</exclude> + <exclude>dom4j:*</exclude> + <exclude>org.hibernate:*</exclude> + <exclude>javax.validation:*</exclude> + <exclude>antlr:*</exclude> + <exclude>org.ow2.asm:*</exclude> + <exclude>com.univocity:*</exclude> + <exclude>net.sf.jpam:*</exclude> + <exclude>com.twitter:*</exclude> + <exclude>javax.inject:*</exclude> + <exclude>com.beust:*</exclude> + <exclude>org.codehaus.jackson:*</exclude> + <exclude>jline:*</exclude> + <exclude>io.netty:netty:jar:3.7.0.Final</exclude> + <exclude>org.xerial.snappy:*</exclude> + <exclude>org.apache.avro:*</exclude> + <exclude>org.tukaani:*</exclude> + <exclude>org.apache.velocity:*</exclude> + <exclude>net.hydromatic:linq4j</exclude> + <exclude>org.codehaus.janino:*</exclude> + <exclude>org.mortbay.jetty:*</exclude> + <exclude>org.slf4j:jul-to-slf4j</exclude> + <exclude>org.slf4j:log4j-over-slf4j</exclude> + <exclude>org.hamcrest:hamcrest-core</exclude> + <exclude>org.mockito:mockito-core</exclude> + <exclude>org.objenesis:objenesis</exclude> + </excludes> + </artifactSet> + <relocations> + <!-- Relocate Drill classes to minimize classloader hell. --> + <relocation><pattern>org.apache.drill.exec.</pattern><shadedPattern>oadd.org.apache.drill.exec.</shadedPattern></relocation> + <relocation><pattern>org.apache.drill.common.</pattern><shadedPattern>oadd.org.apache.drill.common.</shadedPattern></relocation> + + <!-- Move dependencies out of path --> + <relocation><pattern>antlr.</pattern><shadedPattern>oadd.antlr.</shadedPattern></relocation> + <relocation><pattern>antlr.</pattern><shadedPattern>oadd.antlr.</shadedPattern></relocation> + <relocation><pattern>io.</pattern><shadedPattern>oadd.io.</shadedPattern></relocation> + <relocation><pattern>javacc.</pattern><shadedPattern>oadd.javacc.</shadedPattern></relocation> + <relocation><pattern>java_cup.</pattern><shadedPattern>oadd.java_cup.</shadedPattern></relocation> + <relocation><pattern>javassist.</pattern><shadedPattern>oadd.javassist.</shadedPattern></relocation> + <relocation><pattern>jline.</pattern><shadedPattern>oadd.jline.</shadedPattern></relocation> + <relocation><pattern>license.</pattern><shadedPattern>oadd.license.</shadedPattern></relocation> + <relocation><pattern>net.</pattern><shadedPattern>oadd.net.</shadedPattern></relocation> + <relocation><pattern>parquet.</pattern><shadedPattern>oadd.parquet.</shadedPattern></relocation> + <relocation><pattern>test.</pattern><shadedPattern>oadd.test.</shadedPattern></relocation> + <relocation><pattern>trax.</pattern><shadedPattern>oadd.trax.</shadedPattern></relocation> + <relocation><pattern>org.antlr.</pattern><shadedPattern>oadd.org.antlr.</shadedPattern></relocation> + <relocation><pattern>org.codehaus.</pattern><shadedPattern>oadd.org.codehaus.</shadedPattern></relocation> + <relocation><pattern>org.eigenbase.</pattern><shadedPattern>oadd.org.eigenbase.</shadedPattern></relocation> + <relocation><pattern>org.hamcrest.</pattern><shadedPattern>oadd.org.hamcrest.</shadedPattern></relocation> + <relocation><pattern>org.jboss.</pattern><shadedPattern>oadd.org.jboss.</shadedPattern></relocation> + <relocation><pattern>org.joda.</pattern><shadedPattern>oadd.org.joda.</shadedPattern></relocation> + <relocation><pattern>org.json.</pattern><shadedPattern>oadd.org.json.</shadedPattern></relocation> + <relocation><pattern>org.mockito.</pattern><shadedPattern>oadd.org.mockito.</shadedPattern></relocation> + <relocation><pattern>org.msgpack.</pattern><shadedPattern>oadd.org.msgpack.</shadedPattern></relocation> + <relocation><pattern>org.objectweb.</pattern><shadedPattern>oadd.org.objectweb.</shadedPattern></relocation> + <relocation><pattern>org.objensis.</pattern><shadedPattern>oadd.org.objensis.</shadedPattern></relocation> + <relocation><pattern>org.pentaho.</pattern><shadedPattern>oadd.org.pentaho.</shadedPattern></relocation> + <relocation><pattern>org.reflections.</pattern><shadedPattern>oadd.org.reflections.</shadedPattern></relocation> + <relocation><pattern>org.tukaani.</pattern><shadedPattern>oadd.org.tukaani.</shadedPattern></relocation> + <relocation><pattern>org.xerial.</pattern><shadedPattern>oadd.org.xerial.</shadedPattern></relocation> + <relocation><pattern>com.beust.</pattern><shadedPattern>oadd.com.beust.</shadedPattern></relocation> + <relocation><pattern>com.carrotsearch.</pattern><shadedPattern>oadd.com.carrotsearch.</shadedPattern></relocation> + <relocation><pattern>com.codahale.</pattern><shadedPattern>oadd.com.codahale.</shadedPattern></relocation> + <relocation><pattern>com.dyuproject.</pattern><shadedPattern>oadd.com.dyuproject.</shadedPattern></relocation> + <relocation><pattern>com.fasterxml.</pattern><shadedPattern>oadd.com.fasterxml.</shadedPattern></relocation> + <relocation><pattern>com.google.</pattern><shadedPattern>oadd.com.google.</shadedPattern></relocation> + <relocation><pattern>com.thoughtworks.</pattern><shadedPattern>oadd.com.thoughtworks.</shadedPattern></relocation> + <relocation><pattern>com.typesafe.</pattern><shadedPattern>oadd.com.typesafe.</shadedPattern></relocation> + <relocation><pattern>com.univocity.</pattern><shadedPattern>oadd.com.univocity.</shadedPattern></relocation> + <relocation><pattern>org.apache.avro.</pattern><shadedPattern>oadd.org.apache.avro.</shadedPattern></relocation> + <relocation><pattern>org.apache.bcel.</pattern><shadedPattern>oadd.org.apache.bcel.</shadedPattern></relocation> + <relocation><pattern>org.apache.calcite.</pattern><shadedPattern>oadd.org.apache.calcite.</shadedPattern></relocation> + <relocation><pattern>org.apache.commons.</pattern><shadedPattern>oadd.org.apache.commons.</shadedPattern></relocation> + <relocation><pattern>org.apache.curator.</pattern><shadedPattern>oadd.org.apache.curator.</shadedPattern></relocation> + <relocation><pattern>org.apache.html.</pattern><shadedPattern>oadd.org.apache.html.</shadedPattern></relocation> + <relocation><pattern>org.apache.jute.</pattern><shadedPattern>oadd.org.apache.jute.</shadedPattern></relocation> + <relocation><pattern>org.apache.log4j.</pattern><shadedPattern>oadd.org.apache.log4j.</shadedPattern></relocation> + <relocation><pattern>org.apache.regexp.</pattern><shadedPattern>oadd.org.apache.regexp.</shadedPattern></relocation> + <relocation><pattern>org.apache.velocity.</pattern><shadedPattern>oadd.org.apache.velocity.</shadedPattern></relocation> + <relocation><pattern>org.apache.wml.</pattern><shadedPattern>oadd.org.apache.wml.</shadedPattern></relocation> + <relocation><pattern>org.apache.xalan.</pattern><shadedPattern>oadd.org.apache.xalan.</shadedPattern></relocation> + <relocation><pattern>org.apache.xerces.</pattern><shadedPattern>oadd.org.apache.xerces.</shadedPattern></relocation> + <relocation><pattern>org.apache.xml.</pattern><shadedPattern>oadd.org.apache.xml.</shadedPattern></relocation> + <relocation><pattern>org.apache.xmlcommons.</pattern><shadedPattern>oadd.org.apache.xmlcommons.</shadedPattern></relocation> + <relocation><pattern>org.apache.xpath.</pattern><shadedPattern>oadd.org.apache.xpath.</shadedPattern></relocation> + <relocation><pattern>org.apache.zookeeper.</pattern><shadedPattern>oadd.org.apache.zookeeper.</shadedPattern></relocation> + </relocations> + <transformers> + <transformer + implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>drill-module.conf</resource> + </transformer> + </transformers> + <filters> + <filter> + <artifact>*:*</artifact> + <excludes> + <exclude>**/logback.xml</exclude> + <exclude>**/LICENSE.txt</exclude> + <exclude>**/*.java</exclude> + <exclude>**/META-INF/**</exclude> + <exclude>**/org.codehaus.commons.compiler.properties</exclude> + <exclude>**/*.SF</exclude> + <exclude>**/*.RSA</exclude> + <exclude>**/*.DSA</exclude> + <exclude>javax/**</exclude> + <exclude>rest/**</exclude> + <exclude>*.tokens</exclude> + <exclude>com/google/common/math</exclude> + <exclude>com/google/common/net</exclude> + <exclude>com/google/common/primitives</exclude> + <exclude>com/google/common/reflect</exclude> + <exclude>com/google/common/util</exclude> + <exclude>com/google/common/cache</exclude> + <exclude>com/google/common/collect/Tree*</exclude> + <exclude>com/google/common/collect/Standard*</exclude> + <exclude>org/apache/drill/exec/expr/annotations/**</exclude> + <exclude>org/apache/drill/exec/expr/fn/**</exclude> + <exclude>org/apache/drill/exec/proto/beans/**</exclude> + <exclude>org/apache/drill/exec/compile/**</exclude> + <exclude>org/apache/drill/exec/planner/**</exclude> + <exclude>org/apache/drill/exec/physical/**</exclude> + <exclude>org/apache/drill/exec/store/**</exclude> + <exclude>org/apache/drill/exec/server/rest/**</exclude> + <exclude>org/apache/drill/exec/rpc/data/**</exclude> + <exclude>org/apache/drill/exec/rpc/control/**</exclude> + <exclude>org/apache/drill/exec/work/**</exclude> + </excludes> + </filter> + </filters> + </configuration> </plugin> </plugins> @@ -400,11 +447,13 @@ </pluginRepositories> <profiles> - <!-- mondrian data includes 10s of MBs of JSON file - if you want to include them run maven with -Pwith-mondrian-data --> + <!-- mondrian data includes 10s of MBs of JSON file if you want to include + them run maven with -Pwith-mondrian-data --> <profile> <id>with-mondrian-data</id> - <activation><activeByDefault>false</activeByDefault></activation> + <activation> + <activeByDefault>false</activeByDefault> + </activation> <dependencies> <dependency> <groupId>net.hydromatic</groupId> http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/DrillbitClassLoader.java ---------------------------------------------------------------------- diff --git a/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/DrillbitClassLoader.java b/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/DrillbitClassLoader.java new file mode 100644 index 0000000..0ff3a99 --- /dev/null +++ b/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/DrillbitClassLoader.java @@ -0,0 +1,106 @@ +/** + * 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. + */ +package org.apache.drill.jdbc; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; + +public class DrillbitClassLoader extends URLClassLoader { + + public DrillbitClassLoader() { + super(URLS); + } + + private static final URL[] URLS; + + static { + ArrayList<URL> urlList = new ArrayList<URL>(); + final String classPath = System.getProperty("app.class.path"); + final String[] st = fracture(classPath, File.pathSeparator); + final int l = st.length; + for (int i = 0; i < l; i++) { + try { + if (st[i].length() == 0) { + st[i] = "."; + } + urlList.add(new File(st[i]).toURI().toURL()); + } catch (MalformedURLException e) { + assert false : e.toString(); + } + } + urlList.toArray(new URL[urlList.size()]); + + List<URL> urls = new ArrayList<>(); + for (URL url : urlList) { + urls.add(url); + } + URLS = urls.toArray(new URL[urls.size()]); + } + + /** + * Helper method to avoid StringTokenizer using. + * + * Taken from Apache Harmony + */ + private static String[] fracture(String str, String sep) { + if (str.length() == 0) { + return new String[0]; + } + ArrayList<String> res = new ArrayList<String>(); + int in = 0; + int curPos = 0; + int i = str.indexOf(sep); + int len = sep.length(); + while (i != -1) { + String s = str.substring(curPos, i); + res.add(s); + in++; + curPos = i + len; + i = str.indexOf(sep, curPos); + } + + len = str.length(); + if (curPos <= len) { + String s = str.substring(curPos, len); + in++; + res.add(s); + } + + return res.toArray(new String[in]); + } + + @Override + protected Class<?> findClass(String name) throws ClassNotFoundException { + return super.findClass(name); + } + + @Override + public Class<?> loadClass(String name) throws ClassNotFoundException { + return super.loadClass(name); + } + + @Override + protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { + return super.loadClass(name, resolve); + } + +} http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java ---------------------------------------------------------------------- diff --git a/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java b/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java new file mode 100644 index 0000000..97a0984 --- /dev/null +++ b/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java @@ -0,0 +1,189 @@ +/** + * 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. + */ +package org.apache.drill.jdbc; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Vector; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ITTestShadedJar { + + private static DrillbitClassLoader drillbitLoader; + private static URLClassLoader rootClassLoader; + + private static URL getJdbcUrl() throws MalformedURLException { + return new URL( + String.format("%s../../target/drill-jdbc-all-%s.jar", + ClassLoader.getSystemClassLoader().getResource("").toString(), + System.getProperty("project.version") + )); + + } + + @Test + public void executeJdbcAllQuery() throws Exception { + + // print class path for debugging + System.out.println("java.class.path:"); + System.out.println(System.getProperty("java.class.path")); + + final URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); + Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + method.setAccessible(true); + method.invoke(loader, getJdbcUrl()); + + Class<?> clazz = loader.loadClass("org.apache.drill.jdbc.Driver"); + try { + Driver driver = (Driver) clazz.newInstance(); + try (Connection c = driver.connect("jdbc:drill:drillbit=localhost:31010", null); + Statement s = c.createStatement(); + ResultSet result = s.executeQuery("select * from (VALUES 1)");) { + while (result.next()) { + System.out.println(result.getObject(1)); + } + } + } catch (Exception ex) { + throw ex; + } + + } + + + + @BeforeClass + public static void setupDefaultTestCluster() throws Exception { + drillbitLoader = new DrillbitClassLoader(); + rootClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); + try { + runWithLoader("DrillbitStartThread", drillbitLoader); + } catch (Exception e) { + printClassesLoaded("root", rootClassLoader); + throw e; + } + } + + @AfterClass + public static void closeClient() throws Exception { + runWithLoader("DrillbitStopThread", drillbitLoader); + } + + private static int getClassesLoadedCount(ClassLoader classLoader) { + try { + Field f = ClassLoader.class.getDeclaredField("classes"); + f.setAccessible(true); + Vector<Class> classes = (Vector<Class>) f.get(classLoader); + return classes.size(); + } catch (Exception e) { + System.out.println("Failure while loading class count."); + return -1; + } + } + + private static void printClassesLoaded(String prefix, ClassLoader classLoader) { + try { + Field f = ClassLoader.class.getDeclaredField("classes"); + f.setAccessible(true); + Vector<Class> classes = (Vector<Class>) f.get(classLoader); + for (Class<?> c : classes) { + System.out.println(prefix + ": " + c.getName()); + } + } catch (Exception e) { + System.out.println("Failure while printing loaded classes."); + } + } + + private static void runWithLoader(String name, ClassLoader loader) throws Exception { + Class<?> clazz = loader.loadClass(ITTestShadedJar.class.getName() + "$" + name); + Object o = clazz.getDeclaredConstructors()[0].newInstance(loader); + clazz.getMethod("go").invoke(o); + } + + public abstract static class AbstractLoaderThread extends Thread { + private Exception ex; + protected final ClassLoader loader; + + public AbstractLoaderThread(ClassLoader loader) { + this.setContextClassLoader(loader); + this.loader = loader; + } + + @Override + public final void run() { + try { + internalRun(); + } catch (Exception e) { + this.ex = e; + } + } + + protected abstract void internalRun() throws Exception; + + public void go() throws Exception { + start(); + join(); + if (ex != null) { + throw ex; + } + } + } + + public static class DrillbitStartThread extends AbstractLoaderThread { + + public DrillbitStartThread(ClassLoader loader) { + super(loader); + } + + @Override + protected void internalRun() throws Exception { + Class<?> clazz = loader.loadClass("org.apache.drill.BaseTestQuery"); + clazz.getMethod("setupDefaultTestCluster").invoke(null); + + // loader.loadClass("org.apache.drill.exec.exception.SchemaChangeException"); + + // execute a single query to make sure the drillbit is fully up + clazz.getMethod("testNoResult", String.class, new Object[] {}.getClass()) + .invoke(null, "select * from (VALUES 1)", new Object[] {}); + + } + + } + + public static class DrillbitStopThread extends AbstractLoaderThread { + + public DrillbitStopThread(ClassLoader loader) { + super(loader); + } + + @Override + protected void internalRun() throws Exception { + Class<?> clazz = loader.loadClass("org.apache.drill.BaseTestQuery"); + clazz.getMethod("setupDefaultTestCluster").invoke(null); + } + } + +} http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/jdbc-all/src/test/resources/logback.xml ---------------------------------------------------------------------- diff --git a/exec/jdbc-all/src/test/resources/logback.xml b/exec/jdbc-all/src/test/resources/logback.xml new file mode 100644 index 0000000..54ccb42 --- /dev/null +++ b/exec/jdbc-all/src/test/resources/logback.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + 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. +--> +<configuration> + <appender name="SOCKET" + class="de.huxhorn.lilith.logback.appender.ClassicMultiplexSocketAppender"> + <Compressing>true</Compressing> + <ReconnectionDelay>10000</ReconnectionDelay> + <IncludeCallerData>true</IncludeCallerData> + <RemoteHosts>${LILITH_HOSTNAME:-localhost}</RemoteHosts> + </appender> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + </pattern> + </encoder> + </appender> + + <logger name="org.apache.drill" additivity="false"> + <level value="debug" /> + <appender-ref ref="SOCKET" /> + </logger> + + <logger name="query.logger" additivity="false"> + <level value="info" /> + <appender-ref ref="SOCKET" /> + </logger> + +<!-- <logger name="io.netty" additivity="false"> --> +<!-- <level value="debug" /> --> +<!-- <appender-ref ref="SOCKET" /> --> +<!-- </logger> --> + + <root> + <level value="error" /> + <appender-ref ref="STDOUT" /> + </root> + +</configuration> http://git-wip-us.apache.org/repos/asf/drill/blob/4e3b7dc0/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java index 1ef84c4..0d0300e 100644 --- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java +++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/Driver.java @@ -26,15 +26,12 @@ import java.util.Properties; import org.apache.drill.jdbc.impl.DriverImpl; -import org.slf4j.Logger; -import static org.slf4j.LoggerFactory.getLogger; - /** * Main class of Apache Drill JDBC driver. */ public class Driver implements java.sql.Driver { - private static final Logger logger = getLogger( Driver.class ); + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Driver.class); /** Delegate for everything except registration with DriverManager. */ private final DriverImpl impl; @@ -46,13 +43,10 @@ public class Driver implements java.sql.Driver { static { // Upon loading of class, register an instance with DriverManager. - try { - DriverManager.registerDriver( new Driver() ); - } - catch ( SQLException e ) { - logger.error( "Error in registering Drill JDBC driver {}: {}", - Driver.class, e, e ); + DriverManager.registerDriver(new Driver()); + } catch (Error | SQLException e) { + logger.warn("Error in registering Drill JDBC driver {}: {}", Driver.class, e, e); } }
