apache/spark — pull request #2852 by JoshRosen (2014-10-20 06:10:52+00:00)
Title: [WIP] Add WebUITableBuilder to simplify table-building code

This work-in-progress commit illustrates a weekend hack project that I came up with for significantly simplifying the web UI's table rendering code. See the huge block comment in `WebUITableBuilder` for more details. This isn't ready to merge yet; I wanted to get some feedback before converting the rest of the table construction code to use this (I know that I should open a JIRA for this, too; I'll do it tomorrow).

Essentially, this commit adds a small builder class for constructing objects that know how to render web UI tables. This builder helps us to avoid several sources of errors / maintenance headaches, such as duplicate/boilerplate markup, inconsistent formatting of columns in different tables (e.g. durations or memory being displayed differently), separation of column names from column data values, etc. This is best illustrated by some sample code; this new framework lets you write

```scala
private val appTable: UITable[ApplicationInfo] = {
val builder = new UITableBuilder[ApplicationInfo]()
import builder._
customCol("ID") { app =>
{app.id}
}
col("Name") { _.id }
intCol("Cores") { _.coresGranted }
memCol("Memory per Node") { _.desc.memoryPerSlave }
dateCol("Submitted Time") { _.submitDate }
col("User") { _.desc.user }
col("State") { _.state.toString }
durationCol("Duration") { _.duration }
build
}
```

to render the "applications" table in the standalone Master UI. I find this significantly easier to understand and maintain than the old code. For example, this makes it trivial to re-order columns.