Skip to content
Closed
Show file tree
Hide file tree
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 @@ -21,7 +21,7 @@ private[spark] object ApplicationState extends Enumeration {

type ApplicationState = Value

val WAITING, RUNNING, FINISHED, FAILED, UNKNOWN = Value
val WAITING, RUNNING, FINISHED, FAILED, KILLED, UNKNOWN = Value

val MAX_NUM_RETRY = 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import akka.pattern.ask
import org.json4s.JValue

import org.apache.spark.deploy.JsonProtocol
import org.apache.spark.deploy.DeployMessages.{MasterStateResponse, RequestMasterState}
import org.apache.spark.deploy.master.{ApplicationInfo, DriverInfo, WorkerInfo}
import org.apache.spark.deploy.DeployMessages.{RequestKillDriver, MasterStateResponse, RequestMasterState}
import org.apache.spark.deploy.master._
import org.apache.spark.ui.{WebUIPage, UIUtils}
import org.apache.spark.util.Utils

Expand All @@ -41,6 +41,31 @@ private[spark] class MasterPage(parent: MasterWebUI) extends WebUIPage("") {
JsonProtocol.writeMasterState(state)
}

def handleAppKillRequest(request: HttpServletRequest): Unit = {
handleKillRequest(request, id => {
parent.master.idToApp.get(id).foreach { app =>
parent.master.removeApplication(app, ApplicationState.KILLED)
}
})
}

def handleDriverKillRequest(request: HttpServletRequest): Unit = {
handleKillRequest(request, id => { master ! RequestKillDriver(id) })
}

private def handleKillRequest(request: HttpServletRequest, action: String => Unit): Unit = {
if (parent.killEnabled &&
parent.master.securityMgr.checkModifyPermissions(request.getRemoteUser)) {
val killFlag = Option(request.getParameter("terminate")).getOrElse("false").toBoolean
val id = Option(request.getParameter("id"))
if (id.isDefined && killFlag) {
action(id.get)
}

Thread.sleep(100)
}
}

/** Index view listing applications and executors */
def render(request: HttpServletRequest): Seq[Node] = {
val stateFuture = (master ? RequestMasterState)(timeout).mapTo[MasterStateResponse]
Expand Down Expand Up @@ -167,9 +192,20 @@ private[spark] class MasterPage(parent: MasterWebUI) extends WebUIPage("") {
}

private def appRow(app: ApplicationInfo, active: Boolean): Seq[Node] = {
val killLink = if (parent.killEnabled &&
(app.state == ApplicationState.RUNNING || app.state == ApplicationState.WAITING)) {
val killLinkUri = s"app/kill?id=${app.id}&terminate=true"
val confirm = "return window.confirm(" +
s"'Are you sure you want to kill application ${app.id} ?');"
<span class="kill-link">
(<a href={killLinkUri} onclick={confirm}>kill</a>)
</span>
}

<tr>
<td>
<a href={"app?appId=" + app.id}>{app.id}</a>
{killLink}
</td>
<td>
<a href={app.desc.appUiUrl}>{app.desc.name}</a>
Expand Down Expand Up @@ -203,8 +239,19 @@ private[spark] class MasterPage(parent: MasterWebUI) extends WebUIPage("") {
}

private def driverRow(driver: DriverInfo): Seq[Node] = {
val killLink = if (parent.killEnabled &&
(driver.state == DriverState.RUNNING ||
driver.state == DriverState.SUBMITTED ||
driver.state == DriverState.RELAUNCHING)) {
val killLinkUri = s"driver/kill?id=${driver.id}&terminate=true"
val confirm = "return window.confirm(" +
s"'Are you sure you want to kill driver ${driver.id} ?');"
<span class="kill-link">
(<a href={killLinkUri} onclick={confirm}>kill</a>)
</span>
}
<tr>
<td>{driver.id} </td>
<td>{driver.id} {killLink}</td>
<td>{driver.submitDate}</td>
<td>{driver.worker.map(w => <a href={w.webUiAddress}>{w.id.toString}</a>).getOrElse("None")}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ class MasterWebUI(val master: Master, requestedPort: Int)

val masterActorRef = master.self
val timeout = AkkaUtils.askTimeout(master.conf)
val killEnabled = master.conf.getBoolean("spark.ui.killEnabled", true)

initialize()

/** Initialize all components of the server. */
def initialize() {
val masterPage = new MasterPage(this)
attachPage(new ApplicationPage(this))
attachPage(new HistoryNotFoundPage(this))
attachPage(new MasterPage(this))
attachPage(masterPage)
attachHandler(createStaticHandler(MasterWebUI.STATIC_RESOURCE_DIR, "/static"))
attachHandler(
createRedirectHandler("/app/kill", "/", masterPage.handleAppKillRequest))
attachHandler(
createRedirectHandler("/driver/kill", "/", masterPage.handleDriverKillRequest))
}

/** Attach a reconstructed UI to this Master UI. Only valid after bind(). */
Expand Down