Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Display user-friendly error messages
  • Loading branch information
zsxwing committed Jul 19, 2015
commit bad52eb9aa3ec67d567910c54c786438ba5c33fd
6 changes: 4 additions & 2 deletions core/src/main/scala/org/apache/spark/ui/PagedTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ private[ui] abstract class PagedDataSource[T](page: Int, pageSize: Int) {
def pageData: PageData[T] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be a val?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It uses data. So it cannot be val because data is null in this class's constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see. But it can be a lazy val right?

val dataSize = data.size
val totalPages = (dataSize + pageSize - 1) / pageSize
require(page > 0, "page must be positive")
require(page <= totalPages, s"page must not exceed $totalPages")
if (page <= 0 || page > totalPages) {
throw new IllegalArgumentException(
s"Page $page is out of range. Please select a page number between 1 and $totalPages.")
}
val from = (page - 1) * pageSize
val to = dataSize.min(page * pageSize)
PageData(page, totalPages, data.slice(from, to))
Expand Down
43 changes: 25 additions & 18 deletions core/src/main/scala/org/apache/spark/ui/jobs/StagePage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,28 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
accumulables.values.toSeq)

val currentTime = System.currentTimeMillis()
val taskTable = new TaskPagedTable(
UIUtils.prependBaseUri(parent.basePath) +
s"/stages/stage?id=${stageId}&attempt=${stageAttemptId}",
tasks,
hasAccumulators,
stageData.hasInput,
stageData.hasOutput,
stageData.hasShuffleRead,
stageData.hasShuffleWrite,
stageData.hasBytesSpilled,
currentTime,
page = taskPage,
pageSize = 100, // Show 100 tasks at most in the table
sortColumn = taskSortColumn,
desc = taskSortDesc
)
val (taskTable, taskTableHTML) = try {
val _taskTable = new TaskPagedTable(
UIUtils.prependBaseUri(parent.basePath) +
s"/stages/stage?id=${stageId}&attempt=${stageAttemptId}",
tasks,
hasAccumulators,
stageData.hasInput,
stageData.hasOutput,
stageData.hasShuffleRead,
stageData.hasShuffleWrite,
stageData.hasBytesSpilled,
currentTime,
page = taskPage,
pageSize = 100, // Show 100 tasks at most in the table
sortColumn = taskSortColumn,
desc = taskSortDesc
)
(_taskTable, _taskTable.table)
} catch {
case e: IllegalArgumentException =>
(null, <div>{e.getMessage}</div>)
}

val jsForScrollingDownToTaskTable =
<script>
Expand All @@ -274,7 +280,8 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
}
</script>

val taskIdsInPage = taskTable.dataSource.pageData.data.map(_.taskId).toSet
val taskIdsInPage = if (taskTable == null) Set.empty[Long]
else taskTable.dataSource.pageData.data.map(_.taskId).toSet
// Excludes tasks which failed and have incomplete metrics
val validTasks = tasks.filter(t => t.taskInfo.status == "SUCCESS" && t.taskMetrics.isDefined)

Expand Down Expand Up @@ -505,7 +512,7 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
<div>{summaryTable.getOrElse("No tasks have reported metrics yet.")}</div> ++
<h4>Aggregated Metrics by Executor</h4> ++ executorTable.toNodeSeq ++
maybeAccumulableTable ++
<h4 id="tasks-section">Tasks</h4> ++ taskTable.table ++ jsForScrollingDownToTaskTable
<h4 id="tasks-section">Tasks</h4> ++ taskTableHTML ++ jsForScrollingDownToTaskTable
UIUtils.headerSparkPage(stageHeader, content, parent, showVisualization = true)
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/test/scala/org/apache/spark/ui/PagedTableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ class PagedDataSourceSuite extends SparkFunSuite {
val e1 = intercept[IllegalArgumentException] {
dataSource4.pageData
}
assert(e1.getMessage === "requirement failed: page must not exceed 3")
assert(e1.getMessage === "Page 4 is out of range. Please select a page number between 1 and 3.")

val dataSource5 = new PagedDataSource[Int](page = 0, pageSize = 2) {
override protected val data: Seq[Int] = (1 to 5)
}
val e2 = intercept[IllegalArgumentException] {
dataSource5.pageData
}
assert(e2.getMessage === "requirement failed: page must be positive")
assert(e2.getMessage === "Page 0 is out of range. Please select a page number between 1 and 3.")

}
}

Expand Down