From 3f1eabea4b4450295f5d7988cdabd740d17f9b65 Mon Sep 17 00:00:00 2001 From: Dario Rexin Date: Tue, 27 Jan 2015 14:59:32 +0100 Subject: [PATCH] fixes #1106 - Return empty HealthCheck result instead on None, when no results are present --- .../mesosphere/marathon/api/v2/json/EnrichedTask.scala | 2 +- .../scala/mesosphere/marathon/health/HealthCheckActor.scala | 2 +- .../mesosphere/marathon/health/HealthCheckManager.scala | 2 +- .../marathon/health/MarathonHealthCheckManager.scala | 6 +++--- .../marathon/health/MarathonHealthCheckManagerTest.scala | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/scala/mesosphere/marathon/api/v2/json/EnrichedTask.scala b/src/main/scala/mesosphere/marathon/api/v2/json/EnrichedTask.scala index 02300892662..4e77de9b296 100644 --- a/src/main/scala/mesosphere/marathon/api/v2/json/EnrichedTask.scala +++ b/src/main/scala/mesosphere/marathon/api/v2/json/EnrichedTask.scala @@ -7,5 +7,5 @@ import mesosphere.marathon.state.PathId case class EnrichedTask( appId: PathId, task: MarathonTask, - healthCheckResults: Seq[Option[Health]], + healthCheckResults: Seq[Health], servicePorts: Seq[Int] = Nil) diff --git a/src/main/scala/mesosphere/marathon/health/HealthCheckActor.scala b/src/main/scala/mesosphere/marathon/health/HealthCheckActor.scala index 0e4b2fd4300..268b775e80a 100644 --- a/src/main/scala/mesosphere/marathon/health/HealthCheckActor.scala +++ b/src/main/scala/mesosphere/marathon/health/HealthCheckActor.scala @@ -118,7 +118,7 @@ class HealthCheckActor( } def receive: Receive = { - case GetTaskHealth(taskId) => sender() ! taskHealth.get(taskId) + case GetTaskHealth(taskId) => sender() ! taskHealth.getOrElse(taskId, Health(taskId)) case Tick => purgeStatusOfDoneTasks() diff --git a/src/main/scala/mesosphere/marathon/health/HealthCheckManager.scala b/src/main/scala/mesosphere/marathon/health/HealthCheckManager.scala index 06825ac6306..c29f63b8bce 100644 --- a/src/main/scala/mesosphere/marathon/health/HealthCheckManager.scala +++ b/src/main/scala/mesosphere/marathon/health/HealthCheckManager.scala @@ -55,6 +55,6 @@ trait HealthCheckManager { /** * Returns the health status of the supplied task. */ - def status(appId: PathId, taskId: String): Future[Seq[Option[Health]]] + def status(appId: PathId, taskId: String): Future[Seq[Health]] } diff --git a/src/main/scala/mesosphere/marathon/health/MarathonHealthCheckManager.scala b/src/main/scala/mesosphere/marathon/health/MarathonHealthCheckManager.scala index e6ac9e3f159..4cf874e426c 100644 --- a/src/main/scala/mesosphere/marathon/health/MarathonHealthCheckManager.scala +++ b/src/main/scala/mesosphere/marathon/health/MarathonHealthCheckManager.scala @@ -175,17 +175,17 @@ class MarathonHealthCheckManager @Inject() ( override def status( appId: PathId, - taskId: String): Future[Seq[Option[Health]]] = + taskId: String): Future[Seq[Health]] = withReadLock { import mesosphere.marathon.health.HealthCheckActor.GetTaskHealth implicit val timeout: Timeout = Timeout(2, SECONDS) val maybeAppVersion: Option[Timestamp] = taskTracker.getVersion(appId, taskId) - val taskHealth: Seq[Future[Option[Health]]] = maybeAppVersion.map { appVersion => + val taskHealth: Seq[Future[Health]] = maybeAppVersion.map { appVersion => listActive(appId, appVersion).toSeq.collect { case ActiveHealthCheck(_, actor) => - (actor ? GetTaskHealth(taskId)).mapTo[Option[Health]] + (actor ? GetTaskHealth(taskId)).mapTo[Health] } }.getOrElse(Nil) diff --git a/src/test/scala/mesosphere/marathon/health/MarathonHealthCheckManagerTest.scala b/src/test/scala/mesosphere/marathon/health/MarathonHealthCheckManagerTest.scala index c1846fe28b4..70523fe9640 100644 --- a/src/test/scala/mesosphere/marathon/health/MarathonHealthCheckManagerTest.scala +++ b/src/test/scala/mesosphere/marathon/health/MarathonHealthCheckManagerTest.scala @@ -91,14 +91,14 @@ class MarathonHealthCheckManagerTest extends MarathonSpec with Logging { hcManager.add(appId, version, healthCheck) val status1 = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds) - assert(status1 == Seq(None)) + assert(status1 == Seq(Health(taskId.getValue))) // send unhealthy task status EventFilter.info(start = "Received health result: [", occurrences = 1).intercept { hcManager.update(taskStatus.toBuilder.setHealthy(false).build, version) } - val Seq(Some(health2)) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds) + val Seq(health2) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds) assert(health2.lastFailure.isDefined) assert(health2.lastSuccess.isEmpty) @@ -107,7 +107,7 @@ class MarathonHealthCheckManagerTest extends MarathonSpec with Logging { hcManager.update(taskStatus.toBuilder.setHealthy(true).build, version) } - val Seq(Some(health3)) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds) + val Seq(health3) = Await.result(hcManager.status(appId, taskId.getValue), 5.seconds) assert(health3.lastFailure.isDefined) assert(health3.lastSuccess.isDefined) assert(health3.lastSuccess > health3.lastFailure)