spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andrewor14 <...@git.apache.org>
Subject [GitHub] spark pull request #13620: [SPARK-15590] [WEBUI] Paginate Job Table in Jobs ...
Date Mon, 13 Jun 2016 23:15:16 GMT
Github user andrewor14 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13620#discussion_r66885512
  
    --- Diff: core/src/main/scala/org/apache/spark/ui/jobs/AllJobsPage.scala ---
    @@ -369,3 +361,246 @@ private[ui] class AllJobsPage(parent: JobsTab) extends WebUIPage("")
{
         }
       }
     }
    +
    +private[ui] class JobTableRowData(
    +    val jobData: JobUIData,
    +    val lastStageName: String,
    +    val lastStageDescription: String,
    +    val duration: Long,
    +    val formattedDuration: String,
    +    val submissionTime: Long,
    +    val formattedSubmissionTime: String,
    +    val jobDescription: NodeSeq,
    +    val detailUrl: String)
    +
    +private[ui] class JobDataSource(
    +    jobs: Seq[JobUIData],
    +    stageIdToInfo: HashMap[Int, StageInfo],
    +    stageIdToData: HashMap[(Int, Int), StageUIData],
    +    basePath: String,
    +    currentTime: Long,
    +    pageSize: Int,
    +    sortColumn: String,
    +    desc: Boolean) extends PagedDataSource[JobTableRowData](pageSize) {
    +
    +  // Convert JobUIData to JobTableRowData which contains the final contents to show in
the table
    +  // so that we can avoid creating duplicate contents during sorting the data
    +  private val data = jobs.map(jobRow).sorted(ordering(sortColumn, desc))
    +
    +  private var _slicedJobIds: Set[Int] = null
    +
    +  override def dataSize: Int = data.size
    +
    +  override def sliceData(from: Int, to: Int): Seq[JobTableRowData] = {
    +    val r = data.slice(from, to)
    +    _slicedJobIds = r.map(_.jobData.jobId).toSet
    +    r
    +  }
    +
    +  def slicedJobIds: Set[Int] = _slicedJobIds
    +
    +  private def getLastStageNameAndDescription(job: JobUIData): (String, String) = {
    +    val lastStageInfo = Option(job.stageIds)
    +      .filter(_.nonEmpty)
    +      .flatMap { ids => stageIdToInfo.get(ids.max)}
    +    val lastStageData = lastStageInfo.flatMap { s =>
    +      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 jobRow(jobData: JobUIData): JobTableRowData = {
    +    val (lastStageName, lastStageDescription) = getLastStageNameAndDescription(jobData)
    +    val duration: Option[Long] = {
    +      jobData.submissionTime.map { start =>
    +        val end = jobData.completionTime.getOrElse(System.currentTimeMillis())
    +        end - start
    +      }
    +    }
    +    val formattedDuration = duration.map(d => UIUtils.formatDuration(d)).getOrElse("Unknown")
    +    val submissionTime = jobData.submissionTime
    +    val formattedSubmissionTime = submissionTime.map(UIUtils.formatDate).getOrElse("Unknown")
    +    val jobDescription = UIUtils.makeDescription(lastStageDescription, basePath, plainText
= false)
    +
    +    val detailUrl = "%s/jobs/job?id=%s".format(basePath, jobData.jobId)
    +
    +    new JobTableRowData (
    +      jobData,
    +      lastStageName,
    +      lastStageDescription,
    +      duration.getOrElse(-1),
    +      formattedDuration,
    +      submissionTime.getOrElse(-1),
    +      formattedSubmissionTime,
    +      jobDescription,
    +      detailUrl
    +    )
    +  }
    +
    +  /**
    +   * Return Ordering according to sortColumn and desc
    +   */
    +  private def ordering(sortColumn: String, desc: Boolean): Ordering[JobTableRowData]
= {
    +    val ordering = sortColumn match {
    +      case "Job Id" | "Job Id (Job Group)" => new Ordering[JobTableRowData] {
    +        override def compare(x: JobTableRowData, y: JobTableRowData): Int =
    +          Ordering.Int.compare(x.jobData.jobId, y.jobData.jobId)
    +      }
    +      case "Description" => new Ordering[JobTableRowData] {
    +        override def compare(x: JobTableRowData, y: JobTableRowData): Int =
    +          Ordering.String.compare(x.lastStageDescription, y.lastStageDescription)
    +      }
    +      case "Submitted" => new Ordering[JobTableRowData] {
    +        override def compare(x: JobTableRowData, y: JobTableRowData): Int =
    +          Ordering.Long.compare(x.submissionTime, y.submissionTime)
    +      }
    +      case "Duration" => new Ordering[JobTableRowData] {
    +        override def compare(x: JobTableRowData, y: JobTableRowData): Int =
    +          Ordering.Long.compare(x.duration, y.duration)
    +      }
    +      case "Stages: Succeeded/Total" | "Tasks (for all stages): Succeeded/Total" =>
    +        throw new IllegalArgumentException(s"Unsortable column: $sortColumn")
    +      case unknownColumn => throw new IllegalArgumentException(s"Unknown column: $unknownColumn")
    +    }
    +    if (desc) {
    +      ordering.reverse
    +    } else {
    +      ordering
    +    }
    +  }
    +
    +}
    +private[ui] class JobPagedTable(
    +    data: Seq[JobUIData],
    +    jobTag: String,
    +    basePath: String,
    +    // TODO: Should use StageID instead of Int below, but cannot resolve. How?
    +    stageIdToInfo: HashMap[Int, StageInfo],
    +    stageIdToData: HashMap[(Int, Int), StageUIData],
    +    currentTime: Long,
    +    pageSize: Int,
    +    sortColumn: String,
    +    desc: Boolean
    +  ) extends PagedTable[JobTableRowData] {
    +
    +  override def tableId: String = jobTag + "-table"
    +
    +  override def tableCssClass: String =
    +    "table table-bordered table-condensed table-striped table-head-clickable"
    +
    +  override def pageSizeFormField: String = jobTag + ".pageSize"
    +
    +  override def prevPageSizeFormField: String = jobTag + ".prevPageSize"
    +
    +  override def pageNumberFormField: String = jobTag + ".page"
    +
    +  override val dataSource = new JobDataSource(
    +    data,
    +    stageIdToInfo,
    +    stageIdToData,
    +    basePath,
    +    currentTime,
    +    pageSize,
    +    sortColumn,
    +    desc)
    +
    +  override def pageLink(page: Int): String = {
    +    val encodedSortColumn = URLEncoder.encode(sortColumn, "UTF-8")
    +    basePath +
    +      s"?$pageNumberFormField=$page" +
    +      s"&$jobTag.sort=$encodedSortColumn" +
    +      s"&$jobTag.desc=$desc" +
    +      s"&$pageSizeFormField=$pageSize"
    +  }
    +
    +  override def goButtonFormPath: String = {
    +    val encodedSortColumn = URLEncoder.encode(sortColumn, "UTF-8")
    +    s"$basePath?$jobTag.sort=$encodedSortColumn&$jobTag.desc=$desc"
    +  }
    +
    +  def headers: Seq[Node] = {
    --- End diff --
    
    is this used anywhere? I can't find it


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message