@@ -24,7 +24,7 @@ import java.nio.file.Files
2424
2525import scala .collection .JavaConversions ._
2626import scala .collection .mutable .{ArrayBuffer , HashMap , ListBuffer , Map }
27- import scala .util .{Try , Success , Failure }
27+ import scala .util .{Random , Try , Success , Failure }
2828
2929import com .google .common .base .Objects
3030
@@ -69,6 +69,9 @@ private[spark] class Client(
6969 private val distCacheMgr = new ClientDistributedCacheManager ()
7070 private val isClusterMode = args.isClusterMode
7171
72+ private var loginFromKeytab = false
73+ private var kerberosFileName : String = null
74+
7275
7376 def stop (): Unit = yarnClient.stop()
7477
@@ -86,6 +89,7 @@ private[spark] class Client(
8689 * available in the alpha API.
8790 */
8891 def submitApplication (): ApplicationId = {
92+ setupCredentials()
8993 yarnClient.init(yarnConf)
9094 yarnClient.start()
9195
@@ -380,7 +384,6 @@ private[spark] class Client(
380384 private def createContainerLaunchContext (newAppResponse : GetNewApplicationResponse )
381385 : ContainerLaunchContext = {
382386 logInfo(" Setting up container launch context for our AM" )
383-
384387 val appId = newAppResponse.getApplicationId
385388 val appStagingDir = getAppStagingDir(appId)
386389 val localResources = prepareLocalResources(appStagingDir)
@@ -547,16 +550,19 @@ private[spark] class Client(
547550 case Some (principal) =>
548551 Option (args.keytab) match {
549552 case Some (keytabPath) =>
550- File principalFile = Files .createTempF
553+ // Generate a file name that can be used for the keytab file, that does not conflict
554+ // with any user file.
555+ val f = new File (keytabPath)
556+ kerberosFileName = f.getName + " -" + System .currentTimeMillis()
551557 val ugi = UserGroupInformation .loginUserFromKeytabAndReturnUGI(principal, keytabPath)
552558 credentials = ugi.getCredentials
559+ loginFromKeytab = true
553560 case None =>
561+ throw new SparkException (" Keytab must be specified when principal is specified." )
554562 }
555563 case None =>
556564 credentials = UserGroupInformation .getCurrentUser.getCredentials
557-
558565 }
559-
560566 }
561567
562568 /**
0 commit comments