diff --git a/ql/pom.xml b/ql/pom.xml index 5927cc5feae6..f7a9b04d6a99 100644 --- a/ql/pom.xml +++ b/ql/pom.xml @@ -301,10 +301,6 @@ ${hadoop.version} true - - org.apache.hadoop - hadoop-yarn-registry - org.apache.hadoop hadoop-mapreduce-client-core diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 7e91d0bfb419..d12ecb01e7de 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -4136,7 +4136,7 @@ public static boolean isPerfOrAboveLogging(HiveConf conf) { } /** - * Returns the full path to the Jar containing the class. It always return a JAR. + * Returns the full path to the Jar containing the class. It always returns a JAR. * * @param klass * class. @@ -4147,11 +4147,25 @@ public static boolean isPerfOrAboveLogging(HiveConf conf) { public static String jarFinderGetJar(Class klass) { Preconditions.checkNotNull(klass, "klass"); ClassLoader loader = klass.getClassLoader(); + return jarFinderGetJar(loader, klass.getName()); + } + + /** + * Returns the full path to the Jar containing the class. + * + * @param loader + * the classloader instance to scan for jars. + * @param className + * the name of the class to look for. + * + * @return path to the Jar containing the class. + */ + public static String jarFinderGetJar(ClassLoader loader, String className) { if (loader != null) { - String class_file = klass.getName().replaceAll("\\.", "/") + ".class"; + String classFilePath = className.replace('.', '/') + ".class"; try { - for (Enumeration itr = loader.getResources(class_file); itr.hasMoreElements();) { - URL url = (URL) itr.nextElement(); + for (Enumeration itr = loader.getResources(classFilePath); itr.hasMoreElements();) { + URL url = itr.nextElement(); String path = url.getPath(); if (path.startsWith("file:")) { path = path.substring("file:".length()); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java index b89cac4e8137..a068af19edc4 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionState.java @@ -18,7 +18,6 @@ package org.apache.hadoop.hive.ql.exec.tez; import org.apache.hadoop.hive.common.JavaVersionUtils; -import org.apache.hadoop.registry.client.api.RegistryOperations; import java.io.File; import java.io.IOException; @@ -308,7 +307,11 @@ protected void openInternal(String[] additionalFilesNotFromConf, addJarLRByClass(LlapTaskSchedulerService.class, commonLocalResources); addJarLRByClass(LlapProtocolClientImpl.class, commonLocalResources); addJarLRByClass(LlapProtocolClientProxy.class, commonLocalResources); - addJarLRByClass(RegistryOperations.class, commonLocalResources); + addJarLRByClassName( + Utilities.getSessionSpecifiedClassLoader(), + "org.apache.hadoop.registry.client.api.RegistryOperations", + commonLocalResources + ); } // Create environment for AM. @@ -852,15 +855,33 @@ private String getKey(final FileStatus fileStatus) { return fileStatus.getPath() + ":" + fileStatus.getLen() + ":" + fileStatus.getModificationTime(); } + private void addJarLRByPath(String jarPath, final Map lrMap) throws IOException { + final File jar = new File(jarPath); + final String localJarPath = jar.toURI().toURL().toExternalForm(); + final LocalResource jarLr = createJarLocalResource(localJarPath); + lrMap.put(DagUtils.getBaseName(jarLr), jarLr); + } + private void addJarLRByClass(Class clazz, final Map lrMap) throws IOException { String jarPath = Utilities.jarFinderGetJar(clazz); if (jarPath == null) { throw new IOException("Can't find jar for: " + clazz); } - final File jar = new File(jarPath); - final String localJarPath = jar.toURI().toURL().toExternalForm(); - final LocalResource jarLr = createJarLocalResource(localJarPath); - lrMap.put(DagUtils.getBaseName(jarLr), jarLr); + addJarLRByPath(jarPath, lrMap); + } + + private void addJarLRByClassName( + ClassLoader loader, + String className, + final Map lrMap + ) throws IOException { + + String jarPath = Utilities.jarFinderGetJar(loader, className); + if (jarPath == null) { + throw new IOException("Can't find jar for: " + className); + } + addJarLRByPath(jarPath, lrMap); + } private String getSha(final Path localFile) throws IOException, IllegalArgumentException { diff --git a/service/pom.xml b/service/pom.xml index 5921d2350c77..602ba9ec41c9 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -176,6 +176,10 @@ + + org.apache.hadoop + hadoop-yarn-registry + org.pac4j pac4j-saml-opensamlv3