Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import scala.util.control.NonFatal

import org.apache.commons.lang.SerializationUtils
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.security.UserGroupInformation
import org.apache.hadoop.fs.Path
import org.apache.hadoop.io.{ArrayWritable, BooleanWritable, BytesWritable, DoubleWritable,
FloatWritable, IntWritable, LongWritable, NullWritable, Text, Writable}
Expand Down Expand Up @@ -440,6 +441,16 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli

_conf.set("spark.externalBlockStore.folderName", externalBlockStoreFolderName)

var principal: String = null
var keytab: String = null

if (master.startsWith("yarn")) {
if (_conf.contains("spark.yarn.principal") && _conf.contains("spark.yarn.keytab")) {
principal = _conf.get("spark.yarn.principal")
keytab = _conf.get("spark.yarn.keytab")
}
}

if (master == "yarn-client") System.setProperty("SPARK_YARN_MODE", "true")

// "_jobProgressListener" should be set up before creating SparkEnv because when creating
Expand Down Expand Up @@ -569,6 +580,11 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
}
_cleaner.foreach(_.start())

if (null != principal && UserGroupInformation.isSecurityEnabled) {
UserGroupInformation.loginUserFromKeytab(principal, keytab)
logInfo("Successfully logged into the KDC in SparkContext.")
}

setupAndStartListenerBus()
postEnvironmentUpdate()
postApplicationStart()
Expand Down