Skip to content

Commit

Permalink
don't wrap the entire block in the try
Browse files Browse the repository at this point in the history
  • Loading branch information
Sephiroth-Lin committed Apr 5, 2015
1 parent ee2b2fd commit aaacb42
Showing 1 changed file with 46 additions and 45 deletions.
91 changes: 46 additions & 45 deletions yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -560,56 +560,57 @@ private[spark] class Client(
var lastState: YarnApplicationState = null
while (true) {
Thread.sleep(interval)
try {
val report = getApplicationReport(appId)
val state = report.getYarnApplicationState

if (logApplicationReport) {
logInfo(s"Application report for $appId (state: $state)")
val details = Seq[(String, String)](
("client token", getClientToken(report)),
("diagnostics", report.getDiagnostics),
("ApplicationMaster host", report.getHost),
("ApplicationMaster RPC port", report.getRpcPort.toString),
("queue", report.getQueue),
("start time", report.getStartTime.toString),
("final status", report.getFinalApplicationStatus.toString),
("tracking URL", report.getTrackingUrl),
("user", report.getUser)
)

// Use more loggable format if value is null or empty
val formattedDetails = details
.map { case (k, v) =>
val newValue = Option(v).filter(_.nonEmpty).getOrElse("N/A")
s"\n\t $k: $newValue" }
.mkString("")

// If DEBUG is enabled, log report details every iteration
// Otherwise, log them every time the application changes state
if (log.isDebugEnabled) {
logDebug(formattedDetails)
} else if (lastState != state) {
logInfo(formattedDetails)
}
val report: ApplicationReport =
try {
getApplicationReport(appId)
} catch {
case e: ApplicationNotFoundException =>
logError(s"Application $appId not found.")
return (YarnApplicationState.KILLED, FinalApplicationStatus.KILLED)
}

if (state == YarnApplicationState.FINISHED ||
state == YarnApplicationState.FAILED ||
state == YarnApplicationState.KILLED) {
return (state, report.getFinalApplicationStatus)
val state = report.getYarnApplicationState

if (logApplicationReport) {
logInfo(s"Application report for $appId (state: $state)")
val details = Seq[(String, String)](
("client token", getClientToken(report)),
("diagnostics", report.getDiagnostics),
("ApplicationMaster host", report.getHost),
("ApplicationMaster RPC port", report.getRpcPort.toString),
("queue", report.getQueue),
("start time", report.getStartTime.toString),
("final status", report.getFinalApplicationStatus.toString),
("tracking URL", report.getTrackingUrl),
("user", report.getUser)
)

// Use more loggable format if value is null or empty
val formattedDetails = details
.map { case (k, v) =>
val newValue = Option(v).filter(_.nonEmpty).getOrElse("N/A")
s"\n\t $k: $newValue" }
.mkString("")

// If DEBUG is enabled, log report details every iteration
// Otherwise, log them every time the application changes state
if (log.isDebugEnabled) {
logDebug(formattedDetails)
} else if (lastState != state) {
logInfo(formattedDetails)
}
}

if (returnOnRunning && state == YarnApplicationState.RUNNING) {
return (state, report.getFinalApplicationStatus)
}
if (state == YarnApplicationState.FINISHED ||
state == YarnApplicationState.FAILED ||
state == YarnApplicationState.KILLED) {
return (state, report.getFinalApplicationStatus)
}

lastState = state
} catch {
case e: ApplicationNotFoundException =>
logError(s"Application $appId not found.")
return (YarnApplicationState.KILLED, FinalApplicationStatus.KILLED)
if (returnOnRunning && state == YarnApplicationState.RUNNING) {
return (state, report.getFinalApplicationStatus)
}

lastState = state
}

// Never reached, but keeps compiler happy
Expand Down

0 comments on commit aaacb42

Please sign in to comment.