Github user pwendell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2342#discussion_r29007086
  
    --- Diff: core/src/main/scala/org/apache/spark/ui/jobs/AllJobsPage.scala ---
    @@ -17,17 +17,172 @@
     
     package org.apache.spark.ui.jobs
     
    -import scala.xml.{Node, NodeSeq}
    +import scala.collection.mutable.{HashMap, ListBuffer}
    +import scala.xml.{Node, NodeSeq, Unparsed}
     
    +import java.util.Date
     import javax.servlet.http.HttpServletRequest
     
    -import org.apache.spark.ui.{WebUIPage, UIUtils}
    -import org.apache.spark.ui.jobs.UIData.JobUIData
    +import org.apache.spark.ui.{UIUtils, WebUIPage}
    +import org.apache.spark.ui.jobs.UIData.{ExecutorUIData, JobUIData}
    +import org.apache.spark.JobExecutionStatus
     
     /** Page showing list of all ongoing and recently finished jobs */
     private[ui] class AllJobsPage(parent: JobsTab) extends WebUIPage("") {
    -  private val startTime: Option[Long] = parent.sc.map(_.startTime)
    -  private val listener = parent.listener
    +  private val JOBS_LEGEND =
    +    <div class="legend-area"><svg width="200px" height="85px">
    +      <rect x="5px" y="5px" width="20px" height="15px"
    +            rx="2px" ry="2px" stroke="#97B0F8" fill="#D5DDF6"></rect>
    +      <text x="35px" y="17px">Succeeded Job</text>
    +      <rect x="5px" y="35px" width="20px" height="15px"
    +            rx="2px" ry="2px" stroke="#97B0F8" fill="#FF5475"></rect>
    +      <text x="35px" y="47px">Failed Job</text>
    +      <rect x="5px" y="65px" width="20px" height="15px"
    +            rx="2px" ry="2px" stroke="#97B0F8" fill="#FDFFCA"></rect>
    +      <text x="35px" y="77px">Running Job</text>
    +    </svg></div>.toString.filter(_ != '\n')
    +
    +  private val EXECUTORS_LEGEND =
    +    <div class="legend-area"><svg width="200px" height="55px">
    +      <rect x="5px" y="5px" width="20px" height="15px"
    +            rx="2px" ry="2px" stroke="#97B0F8" fill="#D5DDF6"></rect>
    +      <text x="35px" y="17px">Executor Added</text>
    +      <rect x="5px" y="35px" width="20px" height="15px"
    +            rx="2px" ry="2px" stroke="#97B0F8" fill="#EBCA59"></rect>
    +      <text x="35px" y="47px">Executor Removed</text>
    +    </svg></div>.toString.filter(_ != '\n')
    +
    +  private def getLastStageNameAndDescription(job: JobUIData): (String, 
String) = {
    +    val lastStageInfo = Option(job.stageIds)
    +      .filter(_.nonEmpty)
    +      .flatMap { ids => 
parent.jobProgresslistener.stageIdToInfo.get(ids.max)}
    +    val lastStageData = lastStageInfo.flatMap { s =>
    +      parent.jobProgresslistener.stageIdToData.get((s.stageId, 
s.attemptId))
    +    }
    +    val name = lastStageInfo.map(_.name).getOrElse("(Unknown Stage Name)")
    +    val description = lastStageData.flatMap(_.description).getOrElse("")
    +    (name, description)
    +  }
    +
    +  private def makeJobEvent(jobUIDatas: Seq[JobUIData]): Seq[String] = {
    +    jobUIDatas.filter { jobUIData =>
    +      jobUIData.status != JobExecutionStatus.UNKNOWN && 
jobUIData.submissionTime.isDefined
    +    }.map { jobUIData =>
    +      val jobId = jobUIData.jobId
    +      val status = jobUIData.status
    +      val (jobName, jobDescription) = 
getLastStageNameAndDescription(jobUIData)
    +      val displayJobDescription = if (jobDescription.isEmpty) jobName else 
jobDescription
    +      val submissionTime = jobUIData.submissionTime.get
    +      val completionTimeOpt = jobUIData.completionTime
    +      val completionTime = 
completionTimeOpt.getOrElse(System.currentTimeMillis())
    +      val classNameByStatus = status match {
    +        case JobExecutionStatus.SUCCEEDED => "succeeded"
    +        case JobExecutionStatus.FAILED => "failed"
    +        case JobExecutionStatus.RUNNING => "running"
    +      }
    +
    +      val jobEventJsonAsStr =
    +        s"""
    +           |{
    +           |  'className': 'job application-timeline-object 
${classNameByStatus}',
    +           |  'group': 'jobs',
    +           |  'start': new Date(${submissionTime}),
    +           |  'end': new Date(${completionTime}),
    +           |  'content': '<div class="application-timeline-content">' +
    +           |    '${displayJobDescription} (Job ${jobId})</div>',
    +           |  'title': '${displayJobDescription} (Job ${jobId})\\nStatus: 
${status}\\n' +
    +           |    'Submission Time: ${UIUtils.formatDate(new 
Date(submissionTime))}' +
    +           |    '${
    +          if (status != JobExecutionStatus.RUNNING) {
    +            s"""\\nCompletion Time: ${UIUtils.formatDate(new 
Date(completionTime))}"""
    +          } else {
    +            ""
    +          }
    +        }'
    +           |}
    +         """.stripMargin
    +      jobEventJsonAsStr
    +    }
    +  }
    +
    +  private def makeExecutorEvent(executorUIDatas: HashMap[String, 
ExecutorUIData]): Seq[String] = {
    +    val events = ListBuffer[String]()
    +    executorUIDatas.foreach {
    +      case (executorId, event) =>
    +      val addedEvent =
    +        s"""
    +           |{
    +           |  'className': 'executor added',
    +           |  'group': 'executors',
    +           |  'start': new Date(${event.startTime}),
    +           |  'content': '<div>Executor ${executorId} added</div>',
    +           |  'title': 'Added at ${UIUtils.formatDate(new 
Date(event.startTime))}'
    +           |}
    +         """.stripMargin
    +      events += addedEvent
    +
    +      if (event.finishTime.isDefined) {
    +        val removedEvent =
    +          s"""
    +               |{
    +               |  'className': 'executor removed',
    +               |  'group': 'executors',
    +               |  'start': new Date(${event.finishTime.get}),
    +               |  'content': '<div>Executor ${executorId} removed</div>',
    +               |  'title': 'Removed at ${UIUtils.formatDate(new 
Date(event.finishTime.get))}' +
    +               |    '${
    +                        if (event.finishReason.isDefined) {
    +                          s"""\\nReason: ${event.finishReason.get}"""
    +                        } else {
    +                          ""
    +                        }
    +                     }'
    +               |}
    +             """.stripMargin
    +        events += removedEvent
    +      }
    +    }
    +    events.toSeq
    +  }
    +
    +  private def makeTimeline(
    +      jobs: Seq[JobUIData],
    +      executors: HashMap[String, ExecutorUIData],
    +      startTime: Long): Seq[Node] = {
    +
    +    val jobEventJsonAsStrSeq = makeJobEvent(jobs)
    +    val executorEventJsonAsStrSeq = makeExecutorEvent(executors)
    +
    +    val groupJsonArrayAsStr =
    +      s"""
    +          |[
    +          |  {
    +          |    'id': 'executors',
    +          |    'content': '<div>Executors</div>${EXECUTORS_LEGEND}',
    +          |  },
    +          |  {
    +          |    'id': 'jobs',
    +          |    'content': '<div>Jobs</div>${JOBS_LEGEND}',
    +          |  }
    +          |]
    +        """.stripMargin
    +
    +    val eventArrayAsStr =
    +      (jobEventJsonAsStrSeq ++ executorEventJsonAsStrSeq).mkString("[", 
",", "]")
    +
    +    <div id="application-timeline">
    +      <div class="control-panel">
    --- End diff --
    
    It might be good to give this div a 5 pixel lower margin.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to