Skip to content

Commit 8766d37

Browse files
committed
Heavily add documentation to Client* classes + various clean-ups
1 parent 6c94d79 commit 8766d37

File tree

6 files changed

+234
-200
lines changed

6 files changed

+234
-200
lines changed

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ private[spark] class Client(
4848

4949
val yarnConf: YarnConfiguration = new YarnConfiguration(hadoopConf)
5050

51+
/* ------------------------------------------------------------------------------------- *
52+
| The following methods have much in common in the stable and alpha versions of Client, |
53+
| but cannot be implemented in the parent trait due to subtle API differences across |
54+
| hadoop versions. |
55+
* ------------------------------------------------------------------------------------- */
56+
5157
/** Submit an application running our ApplicationMaster to the ResourceManager. */
5258
override def submitApplication(): ApplicationId = {
53-
// Initialize and start the client service.
5459
init(yarnConf)
5560
start()
5661

@@ -64,10 +69,8 @@ private[spark] class Client(
6469
// Verify whether the cluster has enough resources for our AM.
6570
verifyClusterResources(newAppResponse)
6671

67-
// Set up ContainerLaunchContext to launch our AM container.
72+
// Set up the appropriate contexts to launch our AM.
6873
val containerContext = createContainerLaunchContext(newAppResponse)
69-
70-
// Set up ApplicationSubmissionContext to submit our AM.
7174
val appContext = createApplicationSubmissionContext(appId, containerContext)
7275

7376
// Finally, submit and monitor the application.
@@ -77,7 +80,9 @@ private[spark] class Client(
7780
}
7881

7982
/**
80-
*
83+
* Set up a context for launching our ApplicationMaster container.
84+
* In the Yarn alpha API, the memory requirements of this container must be set in
85+
* the ContainerLaunchContext instead of the ApplicationSubmissionContext.
8186
*/
8287
override def createContainerLaunchContext(newAppResponse: GetNewApplicationResponse)
8388
: ContainerLaunchContext = {
@@ -88,9 +93,7 @@ private[spark] class Client(
8893
containerContext
8994
}
9095

91-
/**
92-
*
93-
*/
96+
/** Set up the context for submitting our ApplicationMaster. */
9497
def createApplicationSubmissionContext(
9598
appId: ApplicationId,
9699
containerContext: ContainerLaunchContext): ApplicationSubmissionContext = {
@@ -104,25 +107,30 @@ private[spark] class Client(
104107
}
105108

106109
/**
107-
*
110+
* Set up security tokens for launching our ApplicationMaster container.
111+
* ContainerLaunchContext#setContainerTokens is renamed `setTokens` in the stable API.
108112
*/
109-
override def getAMMemory(newApp: GetNewApplicationResponse): Int = {
110-
val minResMemory = newApp.getMinimumResourceCapability().getMemory()
111-
val amMemory = ((args.amMemory / minResMemory) * minResMemory) +
112-
((if ((args.amMemory % minResMemory) == 0) 0 else minResMemory) - memoryOverhead)
113-
amMemory
114-
}
115-
116-
/** */
117113
override def setupSecurityToken(amContainer: ContainerLaunchContext): Unit = {
118114
val dob = new DataOutputBuffer()
119115
credentials.writeTokenStorageToStream(dob)
120116
amContainer.setContainerTokens(ByteBuffer.wrap(dob.getData()))
121117
}
122118

119+
/**
120+
* Return the amount of memory for launching the ApplicationMaster container (MB).
121+
* GetNewApplicationResponse#getMinimumResourceCapability does not exist in the stable API.
122+
*/
123+
override def getAMMemory(newAppResponse: GetNewApplicationResponse): Int = {
124+
val minResMemory = newAppResponse.getMinimumResourceCapability().getMemory()
125+
val amMemory = ((args.amMemory / minResMemory) * minResMemory) +
126+
((if ((args.amMemory % minResMemory) == 0) 0 else minResMemory) - memoryOverhead)
127+
amMemory
128+
}
129+
123130
/**
124131
* Return the security token used by this client to communicate with the ApplicationMaster.
125132
* If no security is enabled, the token returned by the report is null.
133+
* ApplicationReport#getClientToken is renamed `getClientToAMToken` in the stable API.
126134
*/
127135
override def getClientToken(report: ApplicationReport): String =
128136
Option(report.getClientToken).getOrElse("")

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ClientArguments.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.apache.spark.util.{Utils, IntParam, MemoryParam}
2424

2525

2626
// TODO: Add code and support for ensuring that yarn resource 'tasks' are location aware !
27-
private[spark] class ClientArguments(val args: Array[String], val sparkConf: SparkConf) {
27+
private[spark] class ClientArguments(args: Array[String], sparkConf: SparkConf) {
2828
var addJars: String = null
2929
var files: String = null
3030
var archives: String = null
@@ -47,6 +47,7 @@ private[spark] class ClientArguments(val args: Array[String], val sparkConf: Spa
4747
loadDefaultArgs()
4848
validateArgs()
4949

50+
/** Load any default arguments provided through environment variables and Spark properties. */
5051
private def loadDefaultArgs(): Unit = {
5152
// For backward compatibility, SPARK_YARN_DIST_{ARCHIVES/FILES} should be resolved to hdfs://,
5253
// while spark.yarn.dist.{archives/files} should be resolved to file:// (SPARK-2051).
@@ -62,6 +63,10 @@ private[spark] class ClientArguments(val args: Array[String], val sparkConf: Spa
6263
.orNull
6364
}
6465

66+
/**
67+
* Fail fast if any arguments provided are invalid.
68+
* This is intended to be called only after the provided arguments have been parsed.
69+
*/
6570
private def validateArgs(): Unit = {
6671
Map[Boolean, String](
6772
(numExecutors <= 0) -> "You must specify at least 1 executor!",

0 commit comments

Comments
 (0)