forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor UI interface to allow dynamically adding tabs #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d57444
Refactoring the UI interface to add flexibility
andrewor14 cd000b0
Merge github.com:apache/spark into ui-refactor
andrewor14 a37ad4f
Comments, imports and formatting (minor)
andrewor14 ed25dfc
Generalize SparkUI header to display tabs dynamically
andrewor14 9a48fa1
Allow adding tabs to SparkUI dynamically + add example
andrewor14 0d61ee8
Merge branch 'streaming-web-ui' of github.com:tdas/spark into ui-refa…
andrewor14 8f7323b
End of file new lines, indentation, and imports (minor)
andrewor14 c78c92d
Remove outdated comment
andrewor14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow adding tabs to SparkUI dynamically + add example
An example of how this is done is in org.apache.spark.ui.FooTab. Run it through bin/spark-class to see what it looks like (which should more or less match your expectations...).
- Loading branch information
commit 9a48fa1de7b357f6ffdaad8e93af7b2b7e39bc06
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.ui | ||
|
|
||
| import javax.servlet.http.HttpServletRequest | ||
|
|
||
| import scala.collection.mutable | ||
| import scala.xml.Node | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkContext} | ||
| import org.apache.spark.SparkContext._ | ||
| import org.apache.spark.scheduler.{SparkListener, SparkListenerJobEnd} | ||
|
|
||
| /* | ||
| * This is an example of how to extend the SparkUI by adding new tabs to it. It is intended | ||
| * only as a demonstration and should be removed before merging into master! | ||
| * | ||
| * bin/spark-class org.apache.spark.ui.FooTab | ||
| */ | ||
|
|
||
| /** A tab that displays basic information about jobs seen so far. */ | ||
| private[spark] class FooTab(parent: SparkUI) extends UITab("foo") { | ||
| val appName = parent.appName | ||
| val basePath = parent.basePath | ||
|
|
||
| def start() { | ||
| listener = Some(new FooListener) | ||
| attachPage(new IndexPage(this)) | ||
| } | ||
|
|
||
| def fooListener: FooListener = { | ||
| assert(listener.isDefined, "ExecutorsTab has not started yet!") | ||
| listener.get.asInstanceOf[FooListener] | ||
| } | ||
|
|
||
| def headerTabs: Seq[UITab] = parent.getTabs | ||
| } | ||
|
|
||
| /** A foo page. Enough said. */ | ||
| private[spark] class IndexPage(parent: FooTab) extends UIPage("") { | ||
| private val appName = parent.appName | ||
| private val basePath = parent.basePath | ||
| private val listener = parent.fooListener | ||
|
|
||
| override def render(request: HttpServletRequest): Seq[Node] = { | ||
| val results = listener.jobResultMap.toSeq.sortBy { case (k, _) => k } | ||
| val content = | ||
| <div class="row-fluid"> | ||
| <div class="span12"> | ||
| <strong>Foo Jobs: </strong> | ||
| <ul> | ||
| {results.map { case (k, v) => <li>Job {k}: <strong>{v}</strong></li> }} | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| UIUtils.headerSparkPage(content, basePath, appName, "Foo", parent.headerTabs, parent) | ||
| } | ||
| } | ||
|
|
||
| /** A listener that maintains a mapping between job IDs and job results. */ | ||
| private[spark] class FooListener extends SparkListener { | ||
| val jobResultMap = mutable.Map[Int, String]() | ||
|
|
||
| override def onJobEnd(end: SparkListenerJobEnd) { | ||
| jobResultMap(end.jobId) = end.jobResult.toString | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Start a SparkContext and a SparkUI with a FooTab attached. | ||
| */ | ||
| private[spark] object FooTab { | ||
| def main(args: Array[String]) { | ||
| val sc = new SparkContext("local", "Foo Tab", new SparkConf) | ||
| val fooTab = new FooTab(sc.ui) | ||
| sc.ui.attachTab(fooTab) | ||
|
|
||
| // Run a few jobs | ||
| sc.parallelize(1 to 1000).count() | ||
| sc.parallelize(1 to 2000).persist().count() | ||
| sc.parallelize(1 to 3000).map(i => (i/2, i)).groupByKey().count() | ||
| sc.parallelize(1 to 4000).map(i => (i/2, i)).groupByKey().persist().count() | ||
| sc.parallelize(1 to 5000).map(i => (i/2, i)).groupByKey().persist().count() | ||
| sc.parallelize(1 to 6000).map(i => (i/2, i)).groupByKey().persist().count() | ||
| sc.parallelize(1 to 7000).map(i => (i/2, i)).groupByKey().persist().count() | ||
|
|
||
| readLine("\n> Started SparkUI with a Foo tab...") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A demonstration of how to attach a tab to SparkUI, and what this tab should look like. (Delete before merge)