Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4688#discussion_r25978772
  
    --- Diff: 
yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnSparkHadoopUtil.scala ---
    @@ -82,6 +100,179 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
         if (credentials != null) credentials.getSecretKey(new Text(key)) else 
null
       }
     
    +  private[spark] override def scheduleLoginFromKeytab(): Unit = {
    +    sparkConf.getOption("spark.yarn.principal").foreach { principal =>
    +      val keytab = sparkConf.get("spark.yarn.keytab")
    +      val delegationTokenRenewerRunnable =
    +        new Runnable {
    +          override def run(): Unit = {
    +            renewCredentials(principal, keytab)
    +            delegationTokenRenewer.schedule(
    +              this, (0.75 * (getLatestValidity - 
System.currentTimeMillis())).toLong,
    +              TimeUnit.MILLISECONDS)
    +          }
    +        }
    +      val timeToRenewal = (0.75 * (getLatestValidity - 
System.currentTimeMillis())).toLong
    +      delegationTokenRenewer.schedule(
    +        delegationTokenRenewerRunnable, timeToRenewal, 
TimeUnit.MILLISECONDS)
    +    }
    +  }
    +
    +  private def renewCredentials(principal: String, keytab: String): Unit = {
    +    if (!loggedInViaKeytab) {
    +      // Keytab is copied by YARN to the working directory of the AM, so 
full path is
    +      // not needed.
    +      loggedInUGI = UserGroupInformation.loginUserFromKeytabAndReturnUGI(
    +        principal, keytab)
    +      loggedInViaKeytab = true
    +    }
    +    val nns = getNameNodesToAccess(sparkConf)
    +    val newCredentials = loggedInUGI.getCredentials
    +    obtainTokensForNamenodes(nns, conf, newCredentials)
    +    val remoteFs = FileSystem.get(conf)
    +    val nextSuffix = lastCredentialsFileSuffix + 1
    +    val tokenPathStr =
    +      sparkConf.get("spark.yarn.credentials.file") + "-" + nextSuffix
    +    val tokenPath = new Path(tokenPathStr)
    +    val tempTokenPath = new Path(tokenPathStr + ".tmp")
    +    val stream = Option(remoteFs.create(tempTokenPath, true))
    +    try {
    +      stream.foreach { s =>
    +        newCredentials.writeTokenStorageToStream(s)
    +        s.hflush()
    +        s.close()
    +        remoteFs.rename(tempTokenPath, tokenPath)
    +      }
    +    } catch {
    +      case e: Exception =>
    +    } finally {
    +      stream.foreach(_.close())
    +    }
    +
    +    lastCredentialsFileSuffix = nextSuffix
    +  }
    +
    +  override def updateCredentialsIfRequired(): Unit = {
    +    try {
    +      sparkConf.getOption("spark.yarn.credentials.file").foreach { 
credentialsFile =>
    +        val credentialsFilePath = new Path(credentialsFile)
    +        val remoteFs = FileSystem.get(conf)
    +        val stagingDirPath = new Path(remoteFs.getHomeDirectory, 
credentialsFilePath.getParent)
    +        val fileStatuses =
    +          remoteFs.listStatus(stagingDirPath,
    +            new PathFilter {
    +              override def accept(path: Path): Boolean = {
    +                val name = path.getName
    +                name.startsWith(credentialsFilePath.getName) && 
!name.endsWith(".tmp")
    +              }
    +            })
    +        util.Arrays.sort(fileStatuses, new Comparator[FileStatus] {
    +          override def compare(o1: FileStatus, o2: FileStatus): Int = {
    +            // can't return this directly, as it might cause int to 
overflow
    --- End diff --
    
    
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/primitives/Longs.html#compare%28long,%20long%29


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to