Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1330 from mesosphere/wip-1278-drexin
Browse files Browse the repository at this point in the history
fixes #1278 - Improves response time of /v2/tasks and /v2/apps/{appId}/t...
  • Loading branch information
Peter Kolloch committed Mar 27, 2015
2 parents 4a17801 + aae9d31 commit 64a6732
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class AppTasksResource @Inject() (service: MarathonSchedulerService,

def tasks(appIds: Set[PathId]): Set[EnrichedTask] = for {
id <- appIds
health = result(healthCheckManager.statuses(id))
task <- taskTracker.get(id)
} yield EnrichedTask(id, task, result(healthCheckManager.status(id, task.getId)))
} yield EnrichedTask(id, task, health.getOrElse(task.getId, Nil).map(Some(_)))

val matchingApps = appId match {
case GroupTasks(gid) =>
Expand Down
45 changes: 31 additions & 14 deletions src/main/scala/mesosphere/marathon/api/v2/TasksResource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,40 @@ class TasksResource @Inject() (
@GET
@Produces(Array(MediaType.APPLICATION_JSON))
@Timed
def indexJson(@QueryParam("status") status: String,
@QueryParam("status[]") statuses: util.List[String]): Response = {
def indexJson(
@QueryParam("status") status: String,
@QueryParam("status[]") statuses: util.List[String]): Response = {
if (status != null) statuses.add(status)
val statusSet = statuses.asScala.flatMap(toTaskState).toSet

val tasks = taskTracker.list.values.view.flatMap { app =>
app.tasks.view.map(t => app.appName -> t)
}

val appIds = taskTracker.list.keySet

val appToPorts = appIds.map { appId =>
appId -> service.getApp(appId).map(_.servicePorts()).getOrElse(Nil)
}.toMap

val health = appIds.flatMap { appId =>
result(healthCheckManager.statuses(appId))
}.toMap

val enrichedTasks = for {
(appId, task) <- tasks
if statusSet.isEmpty || statusSet(task.getStatus.getState)
} yield {
EnrichedTask(
appId,
task,
health.getOrElse(task.getId, Nil).map(Some(_)),
appToPorts.getOrElse(appId, Nil)
)
}

ok(Map(
"tasks" -> taskTracker.list.flatMap {
case (appId, setOfTasks) =>
setOfTasks.tasks.collect {
case task if statusSet.isEmpty || statusSet(task.getStatus.getState) =>
EnrichedTask(
appId,
task,
result(healthCheckManager.status(appId, task.getId)),
service.getApp(appId).map(_.servicePorts).getOrElse(Nil)
)
}
}
"tasks" -> enrichedTasks
))
}

Expand Down

0 comments on commit 64a6732

Please sign in to comment.