Skip to content

Commit

Permalink
Add app kill function in master web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryshao committed Feb 27, 2015
1 parent e60ad2f commit ff5195d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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 @@ -27,7 +27,7 @@ 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.master.{ApplicationInfo, ApplicationState, DriverInfo, WorkerInfo}
import org.apache.spark.ui.{WebUIPage, UIUtils}
import org.apache.spark.util.Utils

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

def handleKillRequest(request: HttpServletRequest): Unit = {
if (parent.killEnabled &&
parent.master.securityMgr.checkModifyPermissions(request.getRemoteUser)) {
val killFlag = Option(request.getParameter("terminate")).getOrElse("false").toBoolean
val appId = Option(request.getParameter("id"))
if (appId.isDefined && killFlag) {
parent.master.idToApp.get(appId.get).map { app =>
parent.master.removeApplication(app, ApplicationState.KILLED)
}
}

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 +182,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) {
val killLinkUri = "app/kill?id=%s&terminate=true"
.format(app.id)
val confirm = "return window.confirm('Are you sure you want to kill application %s ?');"
.format(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
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ 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.handleKillRequest))
}

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

0 comments on commit ff5195d

Please sign in to comment.