Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit d5c4a5d

Browse files
jerryshaoMarcelo Vanzin
authored andcommitted
[SPARK-18840][YARN] Avoid throw exception when getting token renewal interval in non HDFS security environment
## What changes were proposed in this pull request? Fix `java.util.NoSuchElementException` when running Spark in non-hdfs security environment. In the current code, we assume `HDFS_DELEGATION_KIND` token will be found in Credentials. But in some cloud environments, HDFS is not required, so we should avoid this exception. ## How was this patch tested? Manually verified in local environment. Author: jerryshao <[email protected]> Closes apache#16265 from jerryshao/SPARK-18840. (cherry picked from commit 43298d1) Signed-off-by: Marcelo Vanzin <[email protected]>
1 parent 207107b commit d5c4a5d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

yarn/src/main/scala/org/apache/spark/deploy/yarn/security/HDFSCredentialProvider.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,22 @@ private[security] class HDFSCredentialProvider extends ServiceCredentialProvider
7272
// We cannot use the tokens generated with renewer yarn. Trying to renew
7373
// those will fail with an access control issue. So create new tokens with the logged in
7474
// user as renewer.
75-
sparkConf.get(PRINCIPAL).map { renewer =>
75+
sparkConf.get(PRINCIPAL).flatMap { renewer =>
7676
val creds = new Credentials()
7777
nnsToAccess(hadoopConf, sparkConf).foreach { dst =>
7878
val dstFs = dst.getFileSystem(hadoopConf)
7979
dstFs.addDelegationTokens(renewer, creds)
8080
}
81-
val t = creds.getAllTokens.asScala
82-
.filter(_.getKind == DelegationTokenIdentifier.HDFS_DELEGATION_KIND)
83-
.head
84-
val newExpiration = t.renew(hadoopConf)
85-
val identifier = new DelegationTokenIdentifier()
86-
identifier.readFields(new DataInputStream(new ByteArrayInputStream(t.getIdentifier)))
87-
val interval = newExpiration - identifier.getIssueDate
88-
logInfo(s"Renewal Interval is $interval")
89-
interval
81+
val hdfsToken = creds.getAllTokens.asScala
82+
.find(_.getKind == DelegationTokenIdentifier.HDFS_DELEGATION_KIND)
83+
hdfsToken.map { t =>
84+
val newExpiration = t.renew(hadoopConf)
85+
val identifier = new DelegationTokenIdentifier()
86+
identifier.readFields(new DataInputStream(new ByteArrayInputStream(t.getIdentifier)))
87+
val interval = newExpiration - identifier.getIssueDate
88+
logInfo(s"Renewal Interval is $interval")
89+
interval
90+
}
9091
}
9192
}
9293

0 commit comments

Comments
 (0)