Skip to content

Commit c622a87

Browse files
jerryshaoMarcelo Vanzin
authored andcommitted
[SPARK-20059][YARN] Use the correct classloader for HBaseCredentialProvider
## What changes were proposed in this pull request? Currently we use system classloader to find HBase jars, if it is specified by `--jars`, then it will be failed with ClassNotFound issue. So here changing to use child classloader. Also putting added jars and main jar into classpath of submitted application in yarn cluster mode, otherwise HBase jars specified with `--jars` will never be honored in cluster mode, and fetching tokens in client side will always be failed. ## How was this patch tested? Unit test and local verification. Author: jerryshao <[email protected]> Closes #17388 from jerryshao/SPARK-20059.
1 parent b56ad2b commit c622a87

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

core/src/main/scala/org/apache/spark/deploy/SparkSubmit.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,17 @@ object SparkSubmit extends CommandLineUtils {
485485

486486
// In client mode, launch the application main class directly
487487
// In addition, add the main application jar and any added jars (if any) to the classpath
488-
if (deployMode == CLIENT) {
488+
// Also add the main application jar and any added jars to classpath in case YARN client
489+
// requires these jars.
490+
if (deployMode == CLIENT || isYarnCluster) {
489491
childMainClass = args.mainClass
490492
if (isUserJar(args.primaryResource)) {
491493
childClasspath += args.primaryResource
492494
}
493495
if (args.jars != null) { childClasspath ++= args.jars.split(",") }
496+
}
497+
498+
if (deployMode == CLIENT) {
494499
if (args.childArgs != null) { childArgs ++= args.childArgs }
495500
}
496501

core/src/test/scala/org/apache/spark/deploy/SparkSubmitSuite.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ class SparkSubmitSuite
213213
childArgsStr should include ("--arg arg1 --arg arg2")
214214
childArgsStr should include regex ("--jar .*thejar.jar")
215215
mainClass should be ("org.apache.spark.deploy.yarn.Client")
216-
classpath should have length (0)
216+
217+
// In yarn cluster mode, also adding jars to classpath
218+
classpath(0) should endWith ("thejar.jar")
219+
classpath(1) should endWith ("one.jar")
220+
classpath(2) should endWith ("two.jar")
221+
classpath(3) should endWith ("three.jar")
217222

218223
sysProps("spark.executor.memory") should be ("5g")
219224
sysProps("spark.driver.memory") should be ("4g")

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/security/HBaseCredentialProvider.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.apache.hadoop.security.token.{Token, TokenIdentifier}
2626

2727
import org.apache.spark.SparkConf
2828
import org.apache.spark.internal.Logging
29+
import org.apache.spark.util.Utils
2930

3031
private[security] class HBaseCredentialProvider extends ServiceCredentialProvider with Logging {
3132

@@ -36,7 +37,7 @@ private[security] class HBaseCredentialProvider extends ServiceCredentialProvide
3637
sparkConf: SparkConf,
3738
creds: Credentials): Option[Long] = {
3839
try {
39-
val mirror = universe.runtimeMirror(getClass.getClassLoader)
40+
val mirror = universe.runtimeMirror(Utils.getContextOrSparkClassLoader)
4041
val obtainToken = mirror.classLoader.
4142
loadClass("org.apache.hadoop.hbase.security.token.TokenUtil").
4243
getMethod("obtainToken", classOf[Configuration])
@@ -60,7 +61,7 @@ private[security] class HBaseCredentialProvider extends ServiceCredentialProvide
6061

6162
private def hbaseConf(conf: Configuration): Configuration = {
6263
try {
63-
val mirror = universe.runtimeMirror(getClass.getClassLoader)
64+
val mirror = universe.runtimeMirror(Utils.getContextOrSparkClassLoader)
6465
val confCreate = mirror.classLoader.
6566
loadClass("org.apache.hadoop.hbase.HBaseConfiguration").
6667
getMethod("create", classOf[Configuration])

0 commit comments

Comments
 (0)