Skip to content
Snippets Groups Projects
Commit 0340b3c4 authored by Richard Alam's avatar Richard Alam
Browse files

- add response to health check

parent 5fc07946
No related branches found
No related tags found
No related merge requests found
......@@ -6,17 +6,20 @@ import akka.actor.ActorSystem
import akka.http.scaladsl.server.Directives._
import akka.stream.Materializer
import com.google.gson.Gson
import org.bigbluebutton.service.{HealthzResponse, HealthzService}
import org.bigbluebutton.service.{ HealthzResponse, HealthzService }
import scala.util.{ Failure, Success }
class ApiService(healthz: HealthzService)(implicit executor: ExecutionContext, as: ActorSystem, mat: Materializer) {
def routes =
path("healthz") {
get {
val resp = healthz.getHealthz()
val res = healthz.getHealthz()
val gson = new Gson()
val response = new HealthzResponse(resp, "fine")
complete(StatusCodes.ServiceUnavailable, HttpEntity(ContentTypes.`application/json`, gson.toJson(response)))
val response = new HealthzResponse(res.toFS, res.fromFS)
complete(StatusCodes.OK, HttpEntity(ContentTypes.`application/json`, gson.toJson(response)))
}
}
}
package org.bigbluebutton
import org.bigbluebutton.common2.bus.IncomingJsonMessageBus
import org.bigbluebutton.common2.redis.{RedisConfig, RedisPublisher}
import org.bigbluebutton.common2.redis.{ RedisConfig, RedisPublisher }
import org.bigbluebutton.endpoint.redis.FSESLRedisSubscriberActor
import org.bigbluebutton.freeswitch.{RxJsonMsgHdlrActor, VoiceConferenceService}
import org.bigbluebutton.freeswitch.{ RxJsonMsgHdlrActor, VoiceConferenceService }
import org.bigbluebutton.freeswitch.voice.FreeswitchConferenceEventListener
import org.bigbluebutton.freeswitch.voice.freeswitch.{ConnectionManager, ESLEventListener, FreeswitchApplication}
import org.bigbluebutton.freeswitch.voice.freeswitch.{ ConnectionManager, ESLEventListener, FreeswitchApplication }
import org.freeswitch.esl.client.manager.DefaultManagerConnection
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
......@@ -31,7 +31,9 @@ object Boot extends App with SystemConfiguration with WebApi {
val eslConnection = new DefaultManagerConnection(eslHost, eslPort, eslPassword)
val voiceConfService = new VoiceConferenceService(redisPublisher)
val healthz = HealthzService(system)
val voiceConfService = new VoiceConferenceService(healthz, redisPublisher)
val fsConfEventListener = new FreeswitchConferenceEventListener(voiceConfService)
fsConfEventListener.start()
......@@ -62,7 +64,6 @@ object Boot extends App with SystemConfiguration with WebApi {
"redis-subscriber"
)
val healthz = HealthzService()(system.)
val apiService = new ApiService(healthz)
val bindingFuture = Http().bindAndHandle(apiService.routes, httpHost, httpPort)
......
......@@ -5,9 +5,12 @@ import org.bigbluebutton.freeswitch.voice.IVoiceConferenceService
import org.bigbluebutton.common2.msgs._
import org.bigbluebutton.common2.util.JsonUtil
import org.bigbluebutton.common2.redis.RedisPublisher
import org.bigbluebutton.freeswitch.voice.events.{ ConfMember, ConfRecording }
import org.bigbluebutton.freeswitch.voice.events.{ConfMember, ConfRecording}
import org.bigbluebutton.service.HealthzService
class VoiceConferenceService(sender: RedisPublisher) extends IVoiceConferenceService with SystemConfiguration {
class VoiceConferenceService(healthz: HealthzService,
sender: RedisPublisher,
) extends IVoiceConferenceService with SystemConfiguration {
val FROM_VOICE_CONF_SYSTEM_CHAN = "bigbluebutton:from-voice-conf:system"
......@@ -311,11 +314,13 @@ class VoiceConferenceService(sender: RedisPublisher) extends IVoiceConferenceSer
//println("***** >>>> " + sendCommandTimestamp)
//println(json)
//println("<<<< ***** " + receivedResponsTimestatmp)
healthz.setFreeswitchStatus(json)
}
def freeswitchHeartbeatEvent(json: String): Unit = {
//println("***** >>>> ")
//println(json)
//println("<<<< ***** ")
healthz.setFreeswitchHeartbeat(json)
}
}
package org.bigbluebutton.service
import akka.actor.{Actor, ActorContext, ActorLogging, Props}
import akka.actor.{ Actor, ActorContext, ActorLogging, Props }
import akka.actor.ActorSystem
import akka.pattern.{ask}
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import scala.util.Success
import scala.util.Failure
import scala.concurrent.{ Await, Future }
case class HealthzResponse(toFS: String, fromFS: String)
case class ToFSStatus(status: String)
......@@ -14,26 +16,43 @@ case class FromFsStatus(status: String)
case object GetHealthStatus
object HealthzService {
def apply() (implicit context: ActorContext) = new HealthzService()
def apply(system: ActorSystem) = new HealthzService(system)
}
class HealthzService() (implicit val context: ActorContext, system: ActorSystem) {
class HealthzService(system: ActorSystem) {
implicit def executionContext = system.dispatcher
implicit val timeout: Timeout = 5.seconds
val actorRef = system.actorOf(HealthzActor.props())
val actorRef = context.actorOf(HealthzActor.props())
def getHealthz(): HealthzResponse = {
println("GETTING HEALTH")
var toRes = ""
def getHealthz():String = {
val future = actorRef.ask(GetHealthStatus)(5 seconds)
val future = actorRef.ask(GetHealthStatus).mapTo[HealthzResponse]
val result2 = Await.result(future, 1 second)
/**
* future onComplete {
* case Success(result) =>
* println("SUCCESS")
* result.foreach { x =>
* toRes = "Success"
* }
* case Failure(failure) =>
* println("FAILED")
* toRes = "failed"
* }
*/
println("************** GOT HERE !!!!!!!!")
result2
}
var toReturn = ""
future onComplete {
case Success(result) =>
toReturn = "Success"
case Failure(failure) =>
toReturn = "Failed"
}
def setFreeswitchHeartbeat(json: String): Unit = {
actorRef ! FromFsStatus(json)
}
toReturn
def setFreeswitchStatus(json: String): Unit = {
actorRef ! ToFSStatus(json)
}
}
......@@ -44,10 +63,24 @@ object HealthzActor {
class HealthzActor extends Actor
with ActorLogging {
var heartbeat = ""
var lastHeartbeatTimestamp: Long = System.currentTimeMillis()
var fsStatus = ""
var lastFsStatus: Long = System.currentTimeMillis()
def receive = {
case msg: ToFSStatus => println(msg)
case msg: FromFsStatus => println(msg)
case GetHealthStatus => println("GetHealthStatus")
case _ => println("that was unexpected")
case msg: ToFSStatus =>
println(msg)
fsStatus = msg.status
lastFsStatus = System.currentTimeMillis()
case msg: FromFsStatus =>
println(msg)
heartbeat = msg.status
lastHeartbeatTimestamp = System.currentTimeMillis()
case GetHealthStatus =>
println("GetHealthStatus")
sender ! HealthzResponse(fsStatus, heartbeat)
case _ => println("that was unexpected")
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment