Skip to content
Closed
Changes from all 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 @@ -17,17 +17,19 @@

package org.apache.spark.deploy.yarn

import scala.util.control.NonFatal

import java.io.{File, IOException}
import java.lang.reflect.InvocationTargetException
import java.net.{Socket, URL}
import java.util.concurrent.atomic.AtomicReference

import scala.util.control.NonFatal

import org.apache.commons.lang3.SystemUtils
import org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.hadoop.yarn.api._
import org.apache.hadoop.yarn.api.records._
import org.apache.hadoop.yarn.conf.YarnConfiguration
import sun.misc.{Signal, SignalHandler}

import org.apache.spark.rpc._
import org.apache.spark.{Logging, SecurityManager, SparkConf, SparkContext, SparkEnv,
Expand Down Expand Up @@ -117,6 +119,20 @@ private[spark] class ApplicationMaster(

private var delegationTokenRenewerOption: Option[AMDelegationTokenRenewer] = None

if (SystemUtils.IS_OS_UNIX) {
// Register signal handler for signal "TERM", "INT" and "HUP". For the cases where AM receive a
// signal and stop, from RM's aspect this application needs to be reattempted, rather than mark
// as success.
class AMSignalHandler(name: String) extends SignalHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

make this private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think here modifier is not allowed.

[error] /Users/sshao/projects/apache-spark/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala:126: illegal start of statement (no modifiers allowed here)
[error]     private class AMSignalHandler(name: String) extends SignalHandler {
[error]     ^
[error] one error found

val prevHandler = Signal.handle(new Signal(name), this)
override def handle(sig: Signal): Unit = {
finish(FinalApplicationStatus.FAILED, ApplicationMaster.EXIT_SIGNAL)
prevHandler.handle(sig)
}
}
Seq("TERM", "INT", "HUP").foreach { sig => new AMSignalHandler(sig) }
}

final def run(): Int = {
try {
val appAttemptId = client.getAttemptId()
Expand Down Expand Up @@ -642,6 +658,7 @@ object ApplicationMaster extends Logging {
private val EXIT_SC_NOT_INITED = 13
private val EXIT_SECURITY = 14
private val EXIT_EXCEPTION_USER_CLASS = 15
private val EXIT_SIGNAL = 16

private var master: ApplicationMaster = _

Expand Down