|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.deploy.mesos.ui |
| 19 | + |
| 20 | +import javax.servlet.http.HttpServletRequest |
| 21 | + |
| 22 | +import scala.xml.Node |
| 23 | + |
| 24 | +import org.apache.spark.deploy.Command |
| 25 | +import org.apache.spark.deploy.mesos.MesosDriverDescription |
| 26 | +import org.apache.spark.scheduler.cluster.mesos.{MesosClusterSubmissionState, MesosClusterRetryState} |
| 27 | +import org.apache.spark.ui.{UIUtils, WebUIPage} |
| 28 | + |
| 29 | + |
| 30 | +private[ui] class DriverPage(parent: MesosClusterUI) extends WebUIPage("driver") { |
| 31 | + |
| 32 | + override def render(request: HttpServletRequest): Seq[Node] = { |
| 33 | + val driverId = request.getParameter("id") |
| 34 | + require(driverId != null && driverId.nonEmpty, "Missing id parameter") |
| 35 | + |
| 36 | + val state = parent.scheduler.getDriverState(driverId) |
| 37 | + if (state.isEmpty) { |
| 38 | + val content = |
| 39 | + <div> |
| 40 | + <p>Cannot find driver {driverId}</p> |
| 41 | + </div> |
| 42 | + return UIUtils.basicSparkPage(content, s"Details for Job $driverId") |
| 43 | + } |
| 44 | + val driverState = state.get |
| 45 | + val driverHeaders = Seq("Driver property", "Value") |
| 46 | + val schedulerHeaders = Seq("Scheduler property", "Value") |
| 47 | + val commandEnvHeaders = Seq("Command environment variable", "Value") |
| 48 | + val launchedHeaders = Seq("Launched property", "Value") |
| 49 | + val commandHeaders = Seq("Comamnd property", "Value") |
| 50 | + val retryHeaders = Seq("Last failed status", "Next retry time", "Retry count") |
| 51 | + val driverDescription = Iterable.apply(driverState.description) |
| 52 | + val submissionState = Iterable.apply(driverState.submissionState) |
| 53 | + val command = Iterable.apply(driverState.description.command) |
| 54 | + val schedulerProperties = Iterable.apply(driverState.description.schedulerProperties) |
| 55 | + val commandEnv = Iterable.apply(driverState.description.command.environment) |
| 56 | + val driverTable = |
| 57 | + UIUtils.listingTable(driverHeaders, driverRow, driverDescription) |
| 58 | + val commandTable = |
| 59 | + UIUtils.listingTable(commandHeaders, commandRow, command) |
| 60 | + val commandEnvTable = |
| 61 | + UIUtils.listingTable(commandEnvHeaders, propertiesRow, commandEnv) |
| 62 | + val schedulerTable = |
| 63 | + UIUtils.listingTable(schedulerHeaders, propertiesRow, schedulerProperties) |
| 64 | + val launchedTable = |
| 65 | + UIUtils.listingTable(launchedHeaders, launchedRow, submissionState) |
| 66 | + val retryTable = |
| 67 | + UIUtils.listingTable( |
| 68 | + retryHeaders, retryRow, Iterable.apply(driverState.description.retryState)) |
| 69 | + val content = |
| 70 | + <p>Driver state information for driver id {driverId}</p> |
| 71 | + <a href="/">Back to Drivers</a> |
| 72 | + <div class="row-fluid"> |
| 73 | + <div class="span12"> |
| 74 | + <h4>Driver state: {driverState.state}</h4> |
| 75 | + <h4>Driver properties</h4> |
| 76 | + {driverTable} |
| 77 | + <h4>Driver command</h4> |
| 78 | + {commandTable} |
| 79 | + <h4>Driver command environment</h4> |
| 80 | + {commandEnvTable} |
| 81 | + <h4>Scheduler properties</h4> |
| 82 | + {schedulerTable} |
| 83 | + <h4>Launched state</h4> |
| 84 | + {launchedTable} |
| 85 | + <h4>Retry state</h4> |
| 86 | + {retryTable} |
| 87 | + </div> |
| 88 | + </div>; |
| 89 | + |
| 90 | + UIUtils.basicSparkPage(content, s"Details for Job $driverId") |
| 91 | + } |
| 92 | + |
| 93 | + private def launchedRow(submissionState: Option[MesosClusterSubmissionState]): Seq[Node] = { |
| 94 | + submissionState.map { state => |
| 95 | + <tr> |
| 96 | + <td>Mesos Slave ID</td> |
| 97 | + <td>{state.slaveId.getValue}</td> |
| 98 | + </tr> |
| 99 | + <tr> |
| 100 | + <td>Mesos Task ID</td> |
| 101 | + <td>{state.taskId.getValue}</td> |
| 102 | + </tr> |
| 103 | + <tr> |
| 104 | + <td>Launch Time</td> |
| 105 | + <td>{state.startDate}</td> |
| 106 | + </tr> |
| 107 | + <tr> |
| 108 | + <td>Finish Time</td> |
| 109 | + <td>{state.finishDate.map(_.toString).getOrElse("")}</td> |
| 110 | + </tr> |
| 111 | + <tr> |
| 112 | + <td>Last Task Status</td> |
| 113 | + <td>{state.mesosTaskStatus.map(_.toString).getOrElse("")}</td> |
| 114 | + </tr> |
| 115 | + }.getOrElse(Seq[Node]()) |
| 116 | + } |
| 117 | + |
| 118 | + private def propertiesRow(properties: collection.Map[String, String]): Seq[Node] = { |
| 119 | + properties.map { case (k, v) => |
| 120 | + <tr> |
| 121 | + <td>{k}</td><td>{v}</td> |
| 122 | + </tr> |
| 123 | + }.toSeq |
| 124 | + } |
| 125 | + |
| 126 | + private def commandRow(command: Command): Seq[Node] = { |
| 127 | + <tr> |
| 128 | + <td>Main class</td><td>{command.mainClass}</td> |
| 129 | + </tr> |
| 130 | + <tr> |
| 131 | + <td>Arguments</td><td>{command.arguments.mkString(" ")}</td> |
| 132 | + </tr> |
| 133 | + <tr> |
| 134 | + <td>Class path entries</td><td>{command.classPathEntries.mkString(" ")}</td> |
| 135 | + </tr> |
| 136 | + <tr> |
| 137 | + <td>Java options</td><td>{command.javaOpts.mkString((" "))}</td> |
| 138 | + </tr> |
| 139 | + <tr> |
| 140 | + <td>Library path entries</td><td>{command.libraryPathEntries.mkString((" "))}</td> |
| 141 | + </tr> |
| 142 | + } |
| 143 | + |
| 144 | + private def driverRow(driver: MesosDriverDescription): Seq[Node] = { |
| 145 | + <tr> |
| 146 | + <td>Name</td><td>{driver.name}</td> |
| 147 | + </tr> |
| 148 | + <tr> |
| 149 | + <td>Id</td><td>{driver.submissionId}</td> |
| 150 | + </tr> |
| 151 | + <tr> |
| 152 | + <td>Cores</td><td>{driver.cores}</td> |
| 153 | + </tr> |
| 154 | + <tr> |
| 155 | + <td>Memory</td><td>{driver.mem}</td> |
| 156 | + </tr> |
| 157 | + <tr> |
| 158 | + <td>Submitted</td><td>{driver.submissionDate}</td> |
| 159 | + </tr> |
| 160 | + <tr> |
| 161 | + <td>Supervise</td><td>{driver.supervise}</td> |
| 162 | + </tr> |
| 163 | + } |
| 164 | + |
| 165 | + private def retryRow(retryState: Option[MesosClusterRetryState]): Seq[Node] = { |
| 166 | + retryState.map { state => |
| 167 | + <tr> |
| 168 | + <td> |
| 169 | + {state.lastFailureStatus} |
| 170 | + </td> |
| 171 | + <td> |
| 172 | + {state.nextRetry} |
| 173 | + </td> |
| 174 | + <td> |
| 175 | + {state.retries} |
| 176 | + </td> |
| 177 | + </tr> |
| 178 | + }.getOrElse(Seq[Node]()) |
| 179 | + } |
| 180 | +} |
0 commit comments