From f5567ae9712a4c540c85ae048a56e32531490246 Mon Sep 17 00:00:00 2001 From: Richard Alam <ritzalam@gmail.com> Date: Fri, 7 Feb 2020 15:01:37 -0800 Subject: [PATCH] - add health service --- .../scala/org/bigbluebutton/ApiService.scala | 20 +++----- .../service/HealthzService.scala | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+), 13 deletions(-) create mode 100755 akka-bbb-fsesl/src/main/scala/org/bigbluebutton/service/HealthzService.scala diff --git a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/ApiService.scala b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/ApiService.scala index 2827ee4503..2ee19fed11 100755 --- a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/ApiService.scala +++ b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/ApiService.scala @@ -5,23 +5,17 @@ import akka.http.scaladsl.model._ import akka.actor.ActorSystem import akka.http.scaladsl.server.Directives._ import akka.stream.Materializer +import com.google.gson.Gson +import org.bigbluebutton.service.HealthzResponse class ApiService()(implicit executor: ExecutionContext, as: ActorSystem, mat: Materializer) { def routes = - path("hello") { + path("healthz") { get { - complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>")) - } - } ~ - // Add a new route - pathPrefix("healthz") { - pathEndOrSingleSlash { - get { - complete { - "Hello World!" - } - } - } + val gson = new Gson() + val response = new HealthzResponse("ok", "fine") + complete(StatusCodes.ServiceUnavailable, HttpEntity(ContentTypes.`application/json`, gson.toJson(response))) } + } } diff --git a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/service/HealthzService.scala b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/service/HealthzService.scala new file mode 100755 index 0000000000..54a1b10549 --- /dev/null +++ b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/service/HealthzService.scala @@ -0,0 +1,49 @@ +package org.bigbluebutton.service + +import akka.actor.{Actor, ActorContext, ActorLogging, Props} +import akka.actor.ActorSystem +import akka.pattern.{ask} +import akka.util.Timeout +import scala.concurrent.duration._ +import scala.util.Success +import scala.util.Failure + +case class HealthzResponse(toFS: String, fromFS: String) +case class ToFSStatus(status: String) +case class FromFsStatus(status: String) +case object GetHealthStatus + +class HealthzService() (implicit val context: ActorContext, system: ActorSystem) { + implicit def executionContext = system.dispatcher + + val actorRef = context.actorOf(HealthzActor.props()) + + def getHealthz():String = { + val future = actorRef.ask(GetHealthStatus)(5 seconds) + + var toReturn = "" + future onComplete { + case Success(result) => + toReturn = "Success" + case Failure(failure) => + toReturn = "Failed" + } + + toReturn + } +} + +object HealthzActor { + def props(): Props = Props(classOf[HealthzActor]) +} + +class HealthzActor extends Actor + with ActorLogging { + + def receive = { + case msg: ToFSStatus => println(msg) + case msg: FromFsStatus => println(msg) + case GetHealthStatus => println("GetHealthStatus") + case _ => println("that was unexpected") + } +} \ No newline at end of file -- GitLab