aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/spark/deploy/master/MasterWebUI.scala
blob: f03c0a02290c348bd548288ef13b3974975b6c53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package spark.deploy.master

import akka.actor.{ActorRef, ActorSystem}
import akka.dispatch.Await
import akka.pattern.ask
import akka.util.Timeout
import akka.util.duration._
import cc.spray.Directives
import cc.spray.directives._
import cc.spray.typeconversion.TwirlSupport._
import spark.deploy._

class MasterWebUI(val actorSystem: ActorSystem, master: ActorRef) extends Directives {
  val RESOURCE_DIR = "spark/deploy/master/webui"
  val STATIC_RESOURCE_DIR = "spark/deploy/static"
  
  implicit val timeout = Timeout(1 seconds)
  
  val handler = {
    get {
      path("") {
        completeWith {
          val future = master ? RequestMasterState
          future.map { 
            masterState => masterui.html.index.render(masterState.asInstanceOf[MasterState])
          }
        }
      } ~
      path("job") {
        parameter("jobId") { jobId =>
          completeWith {
            val future = master ? RequestMasterState
            future.map { state => 
              val masterState = state.asInstanceOf[MasterState]
              
              // A bit ugly an inefficient, but we won't have a number of jobs 
              // so large that it will make a significant difference.
              (masterState.activeJobs ::: masterState.completedJobs).find(_.id == jobId) match {
                case Some(job) => masterui.html.job_details.render(job)
                case _ => null
              }
            }
          }
        }
      } ~
      pathPrefix("static") {
        getFromResourceDirectory(STATIC_RESOURCE_DIR)
      } ~
      getFromResourceDirectory(RESOURCE_DIR)
    }
  }

}