Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private[spark] class CoarseGrainedExecutorBackend(
}(ThreadUtils.sameThread).onComplete {
// This is a very fast action so we can use "ThreadUtils.sameThread"
case Success(msg) =>
// Always receive `true`. Just ignore it
// Always receive `true`. Just ignore it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo.

case Failure(e) =>
exitExecutor(1, s"Cannot register with driver: $driverUrl", e, notifyDriver = false)
}(ThreadUtils.sameThread)
Expand Down Expand Up @@ -181,14 +181,15 @@ private[spark] class CoarseGrainedExecutorBackend(

private[spark] object CoarseGrainedExecutorBackend extends Logging {

private def run(
def run(
driverUrl: String,
executorId: String,
hostname: String,
cores: Int,
appId: String,
workerUrl: Option[String],
userClassPath: Seq[URL]) {
userClassPath: Seq[URL],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not used now. I'm almost suggesting you should just have CoarseGrainedExecutorBackendArguments as an argument here...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes nice suggestion. I missed it. Will address.

backendCreateFn: (RpcEnv, SparkEnv) => CoarseGrainedExecutorBackend) {

Utils.initDaemon(log)

Expand Down Expand Up @@ -228,8 +229,7 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
val env = SparkEnv.createExecutorEnv(
driverConf, executorId, hostname, cores, cfg.ioEncryptionKey, isLocal = false)

env.rpcEnv.setupEndpoint("Executor", new CoarseGrainedExecutorBackend(
env.rpcEnv, driverUrl, executorId, hostname, cores, userClassPath, env))
env.rpcEnv.setupEndpoint("Executor", backendCreateFn(env.rpcEnv, env))
workerUrl.foreach { url =>
env.rpcEnv.setupEndpoint("WorkerWatcher", new WorkerWatcher(env.rpcEnv, url))
}
Expand Down Expand Up @@ -285,25 +285,29 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
printUsageAndExit()
}

run(driverUrl, executorId, hostname, cores, appId, workerUrl, userClassPath)
val createFn: (RpcEnv, SparkEnv) => CoarseGrainedExecutorBackend = { case (rpcEnv, env) =>
new CoarseGrainedExecutorBackend(rpcEnv, driverUrl, executorId, hostname, cores,
userClassPath, env)
}
run(driverUrl, executorId, hostname, cores, appId, workerUrl, userClassPath, createFn)
System.exit(0)
}

private def printUsageAndExit() = {
// scalastyle:off println
System.err.println(
"""
|Usage: CoarseGrainedExecutorBackend [options]
|
| Options are:
| --driver-url <driverUrl>
| --executor-id <executorId>
| --hostname <hostname>
| --cores <cores>
| --app-id <appid>
| --worker-url <workerUrl>
| --user-class-path <url>
|""".stripMargin)
|Usage: CoarseGrainedExecutorBackend [options]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntelliJ automatically corrects these indentations: I guess we could push along with the change, but please let me know if we would not want to fix this in here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spark uses the previous indentation style in many places, so I guess that answers your question. I wouldn't exactly call this "correcting the indentation"...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wouldn't mind reverting this. Will revert.

Btw, I have a feeling that some style rule is conflicted with auto-correction (in point of IDE's view) of IDE and fixing it back is another kind of annoying. Does we have any recommend IDE configuration for avoiding this? Or does we have to deal with this manually?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use an IDE, can't help you there.

|
| Options are:
| --driver-url <driverUrl>
| --executor-id <executorId>
| --hostname <hostname>
| --cores <cores>
| --app-id <appid>
| --worker-url <workerUrl>
| --user-class-path <url>
|""".stripMargin)
// scalastyle:on println
System.exit(1)
}
Expand Down
18 changes: 18 additions & 0 deletions docs/running-on-yarn.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ To use a custom metrics.properties for the application master and executors, upd
<td>{{HTTP_SCHEME}}</td>
<td>`http://` or `https://` according to YARN HTTP policy. (Configured via `yarn.http.policy`)</td>
</tr>
<tr>
<td>{{NM_HOST}}</td>
<td>The "host" of node where container was run.</td>
</tr>
<tr>
<td>{{NM_PORT}}</td>
<td>The "port" of node manager where container was run.</td>
</tr>
<tr>
<td>{{NM_HTTP_PORT}}</td>
<td>The "port" of node manager's http server where container was run.</td>
</tr>
<tr>
<td>{{NM_HTTP_ADDRESS}}</td>
<td>Http URI of the node on which the container is allocated.</td>
Expand All @@ -502,6 +514,12 @@ To use a custom metrics.properties for the application master and executors, upd
</tr>
</table>

For example, suppose you would like to point log url link to Job History Server directly instead of let NodeManager http server redirects it, you can configure `spark.history.custom.executor.log.url` as below:

`{{HTTP_SCHEME}}<JHS_HOST>:<JHS_PORT>/jobhistory/logs/{{NM_HOST}}:{{NM_PORT}}/{{CONTAINER_ID}}/{{CONTAINER_ID}}/{{USER}}/{{FILE_NAME}}?start=-4096`

NOTE: you need to replace `<JHS_POST>` and `<JHS_PORT>` with actual value.

# Important notes

- Whether core requests are honored in scheduling decisions depends on which scheduler is in use and how it is configured.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private[yarn] class ExecutorRunnable(
val commands = prefixEnv ++
Seq(Environment.JAVA_HOME.$$() + "/bin/java", "-server") ++
javaOpts ++
Seq("org.apache.spark.executor.CoarseGrainedExecutorBackend",
Seq("org.apache.spark.executor.YarnCoarseGrainedExecutorBackend",
"--driver-url", masterAddress,
"--executor-id", executorId,
"--hostname", hostname,
Expand Down Expand Up @@ -235,21 +235,6 @@ private[yarn] class ExecutorRunnable(
}
}

// Add log urls, as well as executor attributes
container.foreach { c =>
YarnContainerInfoHelper.getLogUrls(conf, Some(c)).foreach { m =>
m.foreach { case (fileName, url) =>
env("SPARK_LOG_URL_" + fileName.toUpperCase(Locale.ROOT)) = url
}
}

YarnContainerInfoHelper.getAttributes(conf, Some(c)).foreach { m =>
m.foreach { case (attr, value) =>
env("SPARK_EXECUTOR_ATTRIBUTE_" + attr.toUpperCase(Locale.ROOT)) = value
}
}
}

env
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.executor

import java.net.URL

import scala.collection.mutable

import org.apache.spark.{SecurityManager, SparkConf, SparkEnv}
import org.apache.spark.deploy.SparkHadoopUtil
import org.apache.spark.deploy.worker.WorkerWatcher
import org.apache.spark.internal.Logging
import org.apache.spark.rpc.RpcEnv
import org.apache.spark.scheduler.cluster.CoarseGrainedClusterMessages.{RetrieveSparkAppConfig, SparkAppConfig}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long, just use a wildcard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there're unused imports including this line. Will sort them out.

import org.apache.spark.util.{Utils, YarnContainerInfoHelper}

/**
* Custom implementation of CoarseGrainedExecutorBackend for YARN resource manager.
* This class extracts executor log URLs and executor attributes from system environment which
* properties are available for container being set via YARN.
*/
private[spark] class YarnCoarseGrainedExecutorBackend(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some comments here as to what does this class do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry missed this. Just addressed.

rpcEnv: RpcEnv,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indent args and extends one more level.

@HeartSaVioR HeartSaVioR Feb 13, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I'm not sure I understand correctly. All args are 4 spaces and extends line is 2 spaces which doesn't seem to violate the style. Could you please guide your suggestion via actual code change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I swear I saw 2 spaces here when I looked at this code before. Ignore me.

driverUrl: String,
executorId: String,
hostname: String,
cores: Int,
userClassPath: Seq[URL],
env: SparkEnv)
extends CoarseGrainedExecutorBackend(
rpcEnv,
driverUrl,
executorId,
hostname,
cores,
userClassPath,
env) with Logging {

private lazy val hadoopConfiguration = SparkHadoopUtil.get.newConfiguration(env.conf)

override def extractLogUrls: Map[String, String] = {
YarnContainerInfoHelper.getLogUrls(hadoopConfiguration, container = None)
.getOrElse(Map())
}

override def extractAttributes: Map[String, String] = {
YarnContainerInfoHelper.getAttributes(hadoopConfiguration, container = None)
.getOrElse(Map())
}
}

private[spark] object YarnCoarseGrainedExecutorBackend extends Logging {

def main(args: Array[String]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: Unit =

var driverUrl: String = null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we also want to refactor this, as we might need to have redundant code again when one of case needs to have additional arguments. But I can also refactor if we think we can do it later when really needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the core argument parser and should remain the same.

If and when a new argument needs to be added just for the YARN side, then you can think about refactoring this.

var executorId: String = null
var hostname: String = null
var cores: Int = 0
var appId: String = null
var workerUrl: Option[String] = None
val userClassPath = new mutable.ListBuffer[URL]()

var argv = args.toList
while (!argv.isEmpty) {
argv match {
case ("--driver-url") :: value :: tail =>
driverUrl = value
argv = tail
case ("--executor-id") :: value :: tail =>
executorId = value
argv = tail
case ("--hostname") :: value :: tail =>
hostname = value
argv = tail
case ("--cores") :: value :: tail =>
cores = value.toInt
argv = tail
case ("--app-id") :: value :: tail =>
appId = value
argv = tail
case ("--worker-url") :: value :: tail =>
// Worker url is used in spark standalone mode to enforce fate-sharing with worker
workerUrl = Some(value)
argv = tail
case ("--user-class-path") :: value :: tail =>
userClassPath += new URL(value)
argv = tail
case Nil =>
case tail =>
// scalastyle:off println
System.err.println(s"Unrecognized options: ${tail.mkString(" ")}")
// scalastyle:on println
printUsageAndExit()
}
}

if (driverUrl == null || executorId == null || hostname == null || cores <= 0 ||
appId == null) {
printUsageAndExit()
}

val createFn: (RpcEnv, SparkEnv) => CoarseGrainedExecutorBackend = { case (rpcEnv, env) =>
new YarnCoarseGrainedExecutorBackend(rpcEnv, driverUrl, executorId, hostname, cores,
userClassPath, env)
}
CoarseGrainedExecutorBackend.run(driverUrl, executorId, hostname, cores, appId, workerUrl,
userClassPath, createFn)
System.exit(0)
}

private def printUsageAndExit() = {
// scalastyle:off println
System.err.println(
"""
|Usage: YarnCoarseGrainedExecutorBackend [options]
|
| Options are:
| --driver-url <driverUrl>
| --executor-id <executorId>
| --hostname <hostname>
| --cores <cores>
| --app-id <appid>
| --worker-url <workerUrl>
| --user-class-path <url>
|""".stripMargin)
// scalastyle:on println
System.exit(1)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ private[spark] object YarnContainerInfoHelper extends Logging {
val yarnConf = new YarnConfiguration(conf)
Some(Map(
"HTTP_SCHEME" -> getYarnHttpScheme(yarnConf),
"NM_HOST" -> getNodeManagerHost(container),
"NM_PORT" -> getNodeManagerPort(container),
"NM_HTTP_PORT" -> getNodeManagerHttpPort(container),
"NM_HTTP_ADDRESS" -> getNodeManagerHttpAddress(container),
"CLUSTER_ID" -> getClusterId(yarnConf).getOrElse(""),
"CONTAINER_ID" -> ConverterUtils.toString(getContainerId(container)),
Expand Down Expand Up @@ -97,7 +100,22 @@ private[spark] object YarnContainerInfoHelper extends Logging {

def getNodeManagerHttpAddress(container: Option[Container]): String = container match {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies to all methods: now we don't have an actual usage to pass Container as parameter, but it's still safer given that it's independent on context of process. Would we want to leave this as it is, or remove this and add a note to class (or methods) javadoc?

case Some(c) => c.getNodeHttpAddress
case None => System.getenv(Environment.NM_HOST.name()) + ":" +
System.getenv(Environment.NM_HTTP_PORT.name())
case None => getNodeManagerHost(None) + ":" + getNodeManagerHttpPort(None)
}

def getNodeManagerHost(container: Option[Container]): String = container match {
case Some(c) => c.getNodeHttpAddress.split(":")(0)
case None => System.getenv(Environment.NM_HOST.name())
}

def getNodeManagerHttpPort(container: Option[Container]): String = container match {
case Some(c) => c.getNodeHttpAddress.split(":")(1)
case None => System.getenv(Environment.NM_HTTP_PORT.name())
}

def getNodeManagerPort(container: Option[Container]): String = container match {
case Some(_) => "-1" // Just return invalid port given we cannot retrieve the value
case None => System.getenv(Environment.NM_PORT.name())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ private object YarnClusterDriver extends Logging with Matchers {
val driverAttributes = listener.driverAttributes.get
val expectationAttributes = Map(
"HTTP_SCHEME" -> YarnContainerInfoHelper.getYarnHttpScheme(yarnConf),
"NM_HOST" -> YarnContainerInfoHelper.getNodeManagerHost(container = None),
"NM_PORT" -> YarnContainerInfoHelper.getNodeManagerPort(container = None),
"NM_HTTP_PORT" -> YarnContainerInfoHelper.getNodeManagerHttpPort(container = None),
"NM_HTTP_ADDRESS" -> YarnContainerInfoHelper.getNodeManagerHttpAddress(container = None),
"CLUSTER_ID" -> YarnContainerInfoHelper.getClusterId(yarnConf).getOrElse(""),
"CONTAINER_ID" -> ConverterUtils.toString(containerId),
Expand Down