Skip to content

Commit fa233bd

Browse files
Adding logging, fixing minor formatting and ordering issues.
1 parent 42813b4 commit fa233bd

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

launcher/src/main/java/org/apache/spark/launcher/SparkSubmitOptionParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class SparkSubmitOptionParser {
5757
protected final String REPOSITORIES = "--repositories";
5858
protected final String STATUS = "--status";
5959
protected final String TOTAL_EXECUTOR_CORES = "--total-executor-cores";
60-
protected final String PRINCIPAL = "--principal";
61-
protected final String KEYTAB = "--keytab";
6260

6361
// Options that do not take arguments.
6462
protected final String HELP = "--help";
@@ -71,8 +69,10 @@ class SparkSubmitOptionParser {
7169
// YARN-only options.
7270
protected final String ARCHIVES = "--archives";
7371
protected final String EXECUTOR_CORES = "--executor-cores";
74-
protected final String QUEUE = "--queue";
72+
protected final String KEYTAB = "--keytab";
7573
protected final String NUM_EXECUTORS = "--num-executors";
74+
protected final String PRINCIPAL = "--principal";
75+
protected final String QUEUE = "--queue";
7676

7777
/**
7878
* This is the canonical list of spark-submit options. Each entry in the array contains the
@@ -98,20 +98,20 @@ class SparkSubmitOptionParser {
9898
{ EXECUTOR_MEMORY },
9999
{ FILES },
100100
{ JARS },
101+
{ KEYTAB },
101102
{ KILL_SUBMISSION },
102103
{ MASTER },
103104
{ NAME },
104105
{ NUM_EXECUTORS },
105106
{ PACKAGES },
107+
{ PRINCIPAL },
106108
{ PROPERTIES_FILE },
107109
{ PROXY_USER },
108110
{ PY_FILES },
109111
{ QUEUE },
110112
{ REPOSITORIES },
111113
{ STATUS },
112114
{ TOTAL_EXECUTOR_CORES },
113-
{ PRINCIPAL},
114-
{ KEYTAB}
115115
};
116116

117117
/**

yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import scala.collection.JavaConversions._
2626
import scala.collection.mutable.{ArrayBuffer, HashMap, ListBuffer, Map}
2727
import scala.util.{Try, Success, Failure}
2828

29-
import com.google.common.base.{Objects, Preconditions}
29+
import com.google.common.base.Objects
3030
import org.apache.hadoop.io.DataOutputBuffer
3131
import org.apache.hadoop.conf.Configuration
3232
import org.apache.hadoop.fs._
@@ -238,6 +238,8 @@ private[spark] class Client(
238238
// If we passed in a keytab, make sure we copy the keytab to the staging directory on
239239
// HDFS, and setup the relevant environment vars, so the AM can login again.
240240
if (loginFromKeytab) {
241+
logInfo("To enable the AM to login from keytab, credentials are being copied over to the AM" +
242+
" via the YARN Secure Distributed Cache.")
241243
val localUri = new URI(args.keytab)
242244
val localPath = getQualifiedLocalPath(localUri, hadoopConf)
243245
val destinationPath = copyFileToRemote(dst, localPath, replication)
@@ -333,6 +335,7 @@ private[spark] class Client(
333335
val credentialsFile = "credentials-" + UUID.randomUUID().toString
334336
sparkConf.set(
335337
"spark.yarn.credentials.file", new Path(stagingDirPath, credentialsFile).toString)
338+
logInfo(s"Credentials file set to: $credentialsFile")
336339
}
337340

338341
// Set the environment variables to be passed on to the executors.
@@ -562,8 +565,7 @@ private[spark] class Client(
562565

563566
def setupCredentials(): Unit = {
564567
if (args.principal != null) {
565-
Preconditions.checkNotNull(
566-
args.keytab, "Keytab must be specified when principal is specified.", Array.empty[Any])
568+
require(args.keytab != null, "Keytab must be specified when principal is specified.")
567569
logInfo("Attempting to login to the Kerberos" +
568570
s" using principal: ${args.principal} and keytab: ${args.keytab}")
569571
val f = new File(args.keytab)

yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnSparkHadoopUtil.scala

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
126126
private[spark] override def scheduleLoginFromKeytab(): Unit = {
127127
sparkConf.getOption("spark.yarn.principal").foreach { principal =>
128128
val keytab = sparkConf.get("spark.yarn.keytab")
129+
130+
def scheduleRenewal(runnable: Runnable) = {
131+
val renewalInterval = (0.75 * (getLatestValidity - System.currentTimeMillis())).toLong
132+
logInfo("Scheduling login from keytab in " + renewalInterval + "millis.")
133+
delegationTokenRenewer.schedule(runnable, renewalInterval, TimeUnit.MILLISECONDS)
134+
}
135+
129136
// This thread periodically runs on the driver to update the delegation tokens on HDFS.
130137
val driverTokenRenewerRunnable =
131138
new Runnable {
@@ -139,23 +146,21 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
139146
delegationTokenRenewer.schedule(this, 1, TimeUnit.HOURS)
140147
return
141148
}
142-
delegationTokenRenewer.schedule(
143-
this, (0.75 * (getLatestValidity - System.currentTimeMillis())).toLong,
144-
TimeUnit.MILLISECONDS)
149+
scheduleRenewal(this)
145150
}
146151
}
147-
val timeToRenewal = (0.75 * (getLatestValidity - System.currentTimeMillis())).toLong
148-
delegationTokenRenewer.schedule(
149-
driverTokenRenewerRunnable, timeToRenewal, TimeUnit.MILLISECONDS)
152+
scheduleRenewal(driverTokenRenewerRunnable)
150153
}
151154
}
152155

153156
private def renewCredentials(principal: String, keytab: String): Unit = {
154157
if (!loggedInViaKeytab) {
155158
// Keytab is copied by YARN to the working directory of the AM, so full path is
156159
// not needed.
160+
logInfo(s"Attempting to login to KDC using principal: $principal")
157161
loggedInUGI = UserGroupInformation.loginUserFromKeytabAndReturnUGI(
158162
principal, keytab)
163+
logInfo("Successfully logged into KDC.")
159164
loggedInViaKeytab = true
160165
}
161166
val nns = getNameNodesToAccess(sparkConf)
@@ -167,13 +172,16 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
167172
sparkConf.get("spark.yarn.credentials.file") + "-" + nextSuffix
168173
val tokenPath = new Path(tokenPathStr)
169174
val tempTokenPath = new Path(tokenPathStr + ".tmp")
175+
logInfo("Writing out delegation tokens to " + tempTokenPath.toString)
170176
val stream = Option(remoteFs.create(tempTokenPath, true))
171177
try {
172178
stream.foreach { s =>
173179
newCredentials.writeTokenStorageToStream(s)
174180
s.hflush()
175181
s.close()
182+
logInfo(s"Delegation Tokens written out successfully. Renaming file to $tokenPathStr")
176183
remoteFs.rename(tempTokenPath, tokenPath)
184+
logInfo("Delegation token file rename complete.")
177185
}
178186
} finally {
179187
stream.foreach(_.close())
@@ -205,16 +213,23 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
205213
val credentials = credentialsStatus.getPath
206214
val suffix = credentials.getName.substring(credentials.getName.lastIndexOf("-") + 1).toInt
207215
if (suffix > lastCredentialsFileSuffix) {
216+
logInfo("Reading new delegation tokens from " + credentials.toString)
208217
val newCredentials = getCredentialsFromHDFSFile(remoteFs, credentials)
218+
lastCredentialsFileSuffix = suffix
209219
UserGroupInformation.getCurrentUser.addCredentials(newCredentials)
220+
210221
val totalValidity = getLatestValidity - credentialsStatus.getModificationTime
211222
val timeToRunRenewal =
212223
credentialsStatus.getModificationTime + (0.8 * totalValidity).toLong
213224
val timeFromNowToRenewal = timeToRunRenewal - System.currentTimeMillis()
214-
delegationTokenRenewer.schedule(executorUpdaterRunnable,
215-
timeFromNowToRenewal, TimeUnit.MILLISECONDS)
225+
logInfo("Updated delegation tokens, will check for new tokens in " +
226+
timeFromNowToRenewal + " millis")
227+
delegationTokenRenewer.schedule(
228+
executorUpdaterRunnable, timeFromNowToRenewal, TimeUnit.MILLISECONDS)
216229
} else {
217230
// Check every hour to see if new credentials arrived.
231+
logInfo("Updated delegation tokens were expected, but the driver has not updated the " +
232+
"tokens yet, will check again in an hour.")
218233
delegationTokenRenewer.schedule(executorUpdaterRunnable, 1, TimeUnit.HOURS)
219234
}
220235
}
@@ -223,8 +238,7 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
223238
// Since the file may get deleted while we are reading it, catch the Exception and come
224239
// back in an hour to try again
225240
case e: Exception =>
226-
logWarning(
227-
"Error encountered while trying to update credentials, will try again in 1 hour", e)
241+
logWarning("Error while trying to update credentials, will try again in 1 hour", e)
228242
delegationTokenRenewer.schedule(executorUpdaterRunnable, 1, TimeUnit.HOURS)
229243
}
230244
}

0 commit comments

Comments
 (0)