Last active
September 4, 2017 20:36
-
-
Save notxcain/1c3138265fc62779268a9e4846b75589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import akka.http.scaladsl.server.Directives._ | |
| import akka.cluster.Member | |
| import akka.actor.Address | |
| import akka.http.scaladsl.model.StatusCodes | |
| import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ | |
| import io.circe.generic.auto._ | |
| val cluster = Cluster(system) | |
| final case class ClusterView(status: MemberStatus, | |
| address: Address, | |
| leader: Option[Address], | |
| members: Set[Member]) | |
| get { | |
| import cluster.selfUniqueAddress | |
| val clusterState = cluster.state | |
| val selfStatus = clusterState.members | |
| .find(_.uniqueAddress == selfUniqueAddress) | |
| .map(_.status) | |
| .getOrElse(MemberStatus.Removed) | |
| val clusterView = | |
| ClusterView( | |
| selfStatus, | |
| selfUniqueAddress.address, | |
| clusterState.leader, | |
| clusterState.members | |
| ) | |
| clusterView.status match { | |
| case MemberStatus.Up => | |
| complete { | |
| StatusCodes.OK -> clusterView | |
| } | |
| case _ => | |
| complete { | |
| StatusCodes.ServiceUnavailable -> clusterView | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import akka.http.scaladsl.server.Directives._ | |
| import akka.cluster.MemberStatus | |
| import akka.actor.Address | |
| import akka.http.scaladsl.model.StatusCodes | |
| import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ | |
| import io.circe.syntax._ | |
| val cluster = Cluster(system) | |
| get { | |
| val selfStatus = cluster.state.members | |
| .find(_.uniqueAddress == cluster.selfUniqueAddress) | |
| .map(_.status) | |
| .getOrElse(MemberStatus.Removed) | |
| selfStatus match { | |
| case MemberStatus.Up => | |
| complete { | |
| StatusCodes.OK -> Json.obj("status" -> "Up".asJson) | |
| } | |
| case other => | |
| complete { | |
| StatusCodes.ServiceUnavailable -> Json.obj("status" -> other.toString.asJson) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment