diff options
author | Denny <dennybritz@gmail.com> | 2012-08-02 14:11:27 -0700 |
---|---|---|
committer | Denny <dennybritz@gmail.com> | 2012-08-02 14:11:27 -0700 |
commit | 7312a5c30f3e3c9e8b618009ea3093abfc101a00 (patch) | |
tree | 35b493b684a9c9c49159c54f44cf1c9970e91ced | |
parent | ba7e30fb5ee31ab3f99dcb95148f0c95bf3f45b4 (diff) | |
download | spark-7312a5c30f3e3c9e8b618009ea3093abfc101a00.tar.gz spark-7312a5c30f3e3c9e8b618009ea3093abfc101a00.tar.bz2 spark-7312a5c30f3e3c9e8b618009ea3093abfc101a00.zip |
Use spray's implicit Marshaller for Futures.
-rw-r--r-- | core/src/main/scala/spark/deploy/master/MasterWebUI.scala | 36 | ||||
-rw-r--r-- | core/src/main/scala/spark/deploy/worker/WorkerWebUI.scala | 16 |
2 files changed, 25 insertions, 27 deletions
diff --git a/core/src/main/scala/spark/deploy/master/MasterWebUI.scala b/core/src/main/scala/spark/deploy/master/MasterWebUI.scala index cb94174bcc..f03c0a0229 100644 --- a/core/src/main/scala/spark/deploy/master/MasterWebUI.scala +++ b/core/src/main/scala/spark/deploy/master/MasterWebUI.scala @@ -13,25 +13,32 @@ 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 masterState = getMasterState() - // Render the HTML - masterui.html.index.render(masterState) + val future = master ? RequestMasterState + future.map { + masterState => masterui.html.index.render(masterState.asInstanceOf[MasterState]) + } } } ~ path("job") { parameter("jobId") { jobId => completeWith { - val masterState = getMasterState() - // 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 + 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 + } } } } @@ -42,12 +49,5 @@ class MasterWebUI(val actorSystem: ActorSystem, master: ActorRef) extends Direct getFromResourceDirectory(RESOURCE_DIR) } } - - // Requests the current state from the Master and waits for the response - def getMasterState() : MasterState = { - implicit val timeout = Timeout(1 seconds) - val future = master ? RequestMasterState - return Await.result(future, timeout.duration).asInstanceOf[MasterState] - } - + } diff --git a/core/src/main/scala/spark/deploy/worker/WorkerWebUI.scala b/core/src/main/scala/spark/deploy/worker/WorkerWebUI.scala index e66b33c2c2..58a05e1a38 100644 --- a/core/src/main/scala/spark/deploy/worker/WorkerWebUI.scala +++ b/core/src/main/scala/spark/deploy/worker/WorkerWebUI.scala @@ -12,12 +12,17 @@ import spark.deploy.{WorkerState, RequestWorkerState} class WorkerWebUI(val actorSystem: ActorSystem, worker: ActorRef) extends Directives { val RESOURCE_DIR = "spark/deploy/worker/webui" val STATIC_RESOURCE_DIR = "spark/deploy/static" - + + implicit val timeout = Timeout(1 seconds) + val handler = { get { path("") { completeWith{ - workerui.html.index(getWorkerState()) + val future = worker ? RequestWorkerState + future.map { workerState => + workerui.html.index(workerState.asInstanceOf[WorkerState]) + } } } ~ path("log") { @@ -34,11 +39,4 @@ class WorkerWebUI(val actorSystem: ActorSystem, worker: ActorRef) extends Direct } } - // Requests the current state from the Master and waits for the response - def getWorkerState() : WorkerState = { - implicit val timeout = Timeout(1 seconds) - val future = worker ? RequestWorkerState - return Await.result(future, timeout.duration).asInstanceOf[WorkerState] - } - } |