Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/20474#discussion_r166088600
--- Diff:
core/src/main/scala/org/apache/spark/status/api/v1/OneApplicationResource.scala
---
@@ -51,6 +51,52 @@ private[v1] class AbstractApplicationResource extends
BaseAppResource {
@Path("executors")
def executorList(): Seq[ExecutorSummary] =
withUI(_.store.executorList(true))
+ @GET
+ @Path("executors/{executorId}/threads")
+ def threadDump(@PathParam("executorId") executorId: String): Response =
withUI { ui =>
+ val safeExecutorId =
+ Option(UIUtils.stripXSS(executorId)).map { executorId =>
+ UIUtils.decodeURLParameter(executorId)
+ }.getOrElse {
+ throw new IllegalArgumentException(s"Missing executorId parameter")
+ }
+
+ def isAllDigits(x: String) = x.forall(Character.isDigit)
+
+ if (executorId != SparkContext.DRIVER_IDENTIFIER &&
!isAllDigits(executorId)) {
--- End diff --
So this kind of code is where I prefer the "return early" approach to avoid
nesting. It makes code easier to follow IMO.
```
if (executorId != SparkContext.DRIVER_IDENTIFIER &&
!isAllDigits(executorId)) {
return // or throw
}
if (ui.sc.isEmpty) {
return // or throw
}
ui.store.asOption(...) match {
case Some(e) if e.isActive => ...
case Some(e) => ...
case _ => ...
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]