blob: 34cee878531158c8ea5627b29ac531be7ff7929c (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package spark.deploy.master
import akka.actor.{ActorRef, ActorContext, ActorRefFactory}
import scala.concurrent.Await
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import spray.routing.Directives
import spray.routing.directives._
import spray.httpx.TwirlSupport._
import spray.httpx.SprayJsonSupport._
import spray.http.MediaTypes._
import spark.deploy._
import spark.deploy.JsonProtocol._
/**
* Web UI server for the standalone master.
*/
private[spark]
class MasterWebUI(master: ActorRef)(implicit val context: ActorContext) extends Directives {
import context.dispatcher
val actorSystem = context.system
val RESOURCE_DIR = "spark/deploy/master/webui"
val STATIC_RESOURCE_DIR = "spark/deploy/static"
implicit val timeout = Timeout(Duration.create(System.getProperty("spark.akka.askTimeout", "10").toLong, "seconds"))
val handler = {
get {
(path("") & parameters('format ?)) {
case Some(js) if js.equalsIgnoreCase("json") =>
val future = (master ? RequestMasterState).mapTo[MasterState]
respondWithMediaType(`application/json`) { ctx =>
ctx.complete(future.mapTo[MasterState])
}
case _ =>
complete {
val future = (master ? RequestMasterState).mapTo[MasterState]
future.map {
masterState => spark.deploy.master.html.index.render(masterState)
}
}
} ~
path("app") {
parameters("appId", 'format ?) {
case (appId, Some(js)) if (js.equalsIgnoreCase("json")) =>
val future = master ? RequestMasterState
val appInfo = for (masterState <- future.mapTo[MasterState]) yield {
masterState.activeApps.find(_.id == appId).getOrElse({
masterState.completedApps.find(_.id == appId).getOrElse(null)
})
}
respondWithMediaType(`application/json`) { ctx =>
ctx.complete(appInfo.mapTo[ApplicationInfo])
}
case (appId, _) =>
complete {
val future = master ? RequestMasterState
future.map { state =>
val masterState = state.asInstanceOf[MasterState]
val app = masterState.activeApps.find(_.id == appId).getOrElse({
masterState.completedApps.find(_.id == appId).getOrElse(null)
})
spark.deploy.master.html.app_details.render(app)
}
}
}
} ~
pathPrefix("static") {
getFromResourceDirectory(STATIC_RESOURCE_DIR)
} ~
getFromResourceDirectory(RESOURCE_DIR)
}
}
}
|