Skip to content

Commit

Permalink
Cleanup: Added TimelineViewUtils.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak committed Apr 2, 2015
1 parent a76e569 commit e85e9aa
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 57 deletions.
66 changes: 66 additions & 0 deletions core/src/main/scala/org/apache/spark/ui/TimelineViewUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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 scala.xml.Node

object TimelineViewUtils {

def executorsLegend: Seq[Node] = {
<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>
}

def jobsLegend: Seq[Node] = {
<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>
}

def stagesLegend: Seq[Node] = {
<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">Completed Stage </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 Stage</text>
<rect x="5px" y="65px" width="20px" height="15px"
rx="2px" ry="2px" stroke="#97B0F8" fill="#FDFFCA"></rect>
<text x="35px" y="77px">Active Stage</text>
</svg></div>
}

def nodesToFlatString(nodes: Seq[Node]): String = {
nodes.toString.filter(_ != '\n')
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/org/apache/spark/ui/UIUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ private[spark] object UIUtils extends Logging {
type="text/css" />
<link rel="stylesheet" href={prependBaseUri("/static/vis.min.css")}
typ="text/css" />
<link rel="stylesheet" href={prependBaseUri("/static/debug-tools.css")}></link>
<link rel="stylesheet" href={prependBaseUri("/static/timeline-view.css")}></link>
<script src={prependBaseUri("/static/sorttable.js")} ></script>
<script src={prependBaseUri("/static/jquery-1.11.1.min.js")}></script>
<script src={prependBaseUri("/static/vis.min.js")}></script>
<script src={prependBaseUri("/static/bootstrap-tooltip.js")}></script>
<script src={prependBaseUri("/static/initialize-tooltips.js")}></script>
<script src={prependBaseUri("/static/table.js")}></script>
<script src={prependBaseUri("/static/additional-metrics.js")}></script>
<script src={prependBaseUri("/static/debug-tools.js")}></script>
<script src={prependBaseUri("/static/timeline-view.js")}></script>
}

/** Returns a spark page with correctly formatted headers */
Expand Down
32 changes: 4 additions & 28 deletions core/src/main/scala/org/apache/spark/ui/jobs/AllJobsPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ 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.{UIUtils, WebUIPage}
import org.apache.spark.ui.TimelineViewUtils._
import org.apache.spark.ui.jobs.UIData.JobUIData
import org.apache.spark.JobExecutionStatus

Expand Down Expand Up @@ -105,31 +106,6 @@ private[ui] class AllJobsPage(parent: JobsTab) extends WebUIPage("") {
</div>
}

private val executorsLegend: Seq[Node] = {
<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>
}

private val jobsLegend: Seq[Node] = {
<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>
}

def render(request: HttpServletRequest): Seq[Node] = {
listener.synchronized {
val activeJobs = listener.activeJobs.values.toSeq
Expand Down Expand Up @@ -196,11 +172,11 @@ private[ui] class AllJobsPage(parent: JobsTab) extends WebUIPage("") {
|[
| {
| 'id': 'executors',
| 'content': '<div>Executors</div>${executorsLegend.toString().filter(_ != '\n')}',
| 'content': '<div>Executors</div>${nodesToFlatString(executorsLegend)}',
| },
| {
| 'id': 'jobs',
| 'content': '<div>Jobs</div>${jobsLegend.toString().filter(_ != '\n')}',
| 'content': '<div>Jobs</div>${nodesToFlatString(jobsLegend)}',
| }
|]
""".stripMargin
Expand Down
30 changes: 3 additions & 27 deletions core/src/main/scala/org/apache/spark/ui/jobs/JobPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest
import org.apache.spark.JobExecutionStatus
import org.apache.spark.scheduler.StageInfo
import org.apache.spark.ui.{UIUtils, WebUIPage}
import org.apache.spark.ui.TimelineViewUtils._

/** Page showing statistics and stage list for a given job */
private[ui] class JobPage(parent: JobsTab) extends WebUIPage("job") {
Expand All @@ -41,31 +42,6 @@ private[ui] class JobPage(parent: JobsTab) extends WebUIPage("job") {
</div>
}

private val executorsLegend: Seq[Node] = {
<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>
}

private val stagesLegend: Seq[Node] = {
<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">Completed Stage </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 Stage</text>
<rect x="5px" y="65px" width="20px" height="15px"
rx="2px" ry="2px" stroke="#97B0F8" fill="#FDFFCA"></rect>
<text x="35px" y="77px">Active Stage</text>
</svg></div>
}

def render(request: HttpServletRequest): Seq[Node] = {
listener.synchronized {
val parameterId = request.getParameter("id")
Expand Down Expand Up @@ -195,11 +171,11 @@ private[ui] class JobPage(parent: JobsTab) extends WebUIPage("job") {
|[
| {
| 'id': 'executors',
| 'content': '<div>Executors</div>${executorsLegend.toString().filter(_ != '\n')}',
| 'content': '<div>Executors</div>${nodesToFlatString(executorsLegend)}',
| },
| {
| 'id': 'stages',
| 'content': '<div>Stages</div>${stagesLegend.toString().filter(_ != '\n')}',
| 'content': '<div>Stages</div>${nodesToFlatString(stagesLegend)}',
| }
|]
""".stripMargin
Expand Down

0 comments on commit e85e9aa

Please sign in to comment.