aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/running-on-yarn.md9
-rw-r--r--yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala26
2 files changed, 34 insertions, 1 deletions
diff --git a/docs/running-on-yarn.md b/docs/running-on-yarn.md
index db6bfa69ee..925a1e0ba6 100644
--- a/docs/running-on-yarn.md
+++ b/docs/running-on-yarn.md
@@ -327,6 +327,15 @@ If you need a reference to the proper location to put log files in the YARN so t
</td>
</tr>
<tr>
+ <td><code>spark.yarn.am.nodeLabelExpression</code></td>
+ <td>(none)</td>
+ <td>
+ A YARN node label expression that restricts the set of nodes AM will be scheduled on.
+ Only versions of YARN greater than or equal to 2.6 support node label expressions, so when
+ running against earlier versions, this property will be ignored.
+ </td>
+</tr>
+<tr>
<td><code>spark.yarn.executor.nodeLabelExpression</code></td>
<td>(none)</td>
<td>
diff --git a/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala b/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
index ba799884f5..a77a3e2420 100644
--- a/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
+++ b/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
@@ -225,7 +225,31 @@ private[spark] class Client(
val capability = Records.newRecord(classOf[Resource])
capability.setMemory(args.amMemory + amMemoryOverhead)
capability.setVirtualCores(args.amCores)
- appContext.setResource(capability)
+
+ if (sparkConf.contains("spark.yarn.am.nodeLabelExpression")) {
+ try {
+ val amRequest = Records.newRecord(classOf[ResourceRequest])
+ amRequest.setResourceName(ResourceRequest.ANY)
+ amRequest.setPriority(Priority.newInstance(0))
+ amRequest.setCapability(capability)
+ amRequest.setNumContainers(1)
+ val amLabelExpression = sparkConf.get("spark.yarn.am.nodeLabelExpression")
+ val method = amRequest.getClass.getMethod("setNodeLabelExpression", classOf[String])
+ method.invoke(amRequest, amLabelExpression)
+
+ val setResourceRequestMethod =
+ appContext.getClass.getMethod("setAMContainerResourceRequest", classOf[ResourceRequest])
+ setResourceRequestMethod.invoke(appContext, amRequest)
+ } catch {
+ case e: NoSuchMethodException =>
+ logWarning("Ignoring spark.yarn.am.nodeLabelExpression because the version " +
+ "of YARN does not support it")
+ appContext.setResource(capability)
+ }
+ } else {
+ appContext.setResource(capability)
+ }
+
appContext
}