From 7312a5c30f3e3c9e8b618009ea3093abfc101a00 Mon Sep 17 00:00:00 2001 From: Denny Date: Thu, 2 Aug 2012 14:11:27 -0700 Subject: Use spray's implicit Marshaller for Futures. --- .../scala/spark/deploy/master/MasterWebUI.scala | 36 +++++++++++----------- .../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] - } - } -- cgit v1.2.3