Commit e769b9ad authored by Mathieu's avatar Mathieu
Browse files

Implement k8s pod list

parent d6ad2f61
......@@ -12,6 +12,7 @@ val scaladgetVersion = "1.2.7"
val scalajsDomVersion = "0.9.7"
val scalaJWTVersion = "4.0.0"
val rosHttpVersion = "2.2.4"
val skuberVersion = "2.2.0"
val Resolvers = Seq(Resolver.sonatypeRepo("snapshots"),
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
......@@ -47,11 +48,12 @@ lazy val server = project.in(file("server")) settings (defaultSettings) settings
"org.eclipse.jetty" % "jetty-server" % jettyVersion,
"org.json4s" %% "json4s-jackson" % json4sVersion,
"com.pauldijou" %% "jwt-core" % scalaJWTVersion,
"fr.hmil" %% "roshttp" % rosHttpVersion
"fr.hmil" %% "roshttp" % rosHttpVersion,
"io.skuber" %% "skuber" % skuberVersion
)
) dependsOn (shared) enablePlugins (ScalatraPlugin)
lazy val application = project.in(file("application")) settings (defaultSettings) dependsOn (server) enablePlugins(JavaServerAppPackaging) settings(
lazy val application = project.in(file("application")) settings (defaultSettings) dependsOn (server) enablePlugins (JavaServerAppPackaging) settings(
dockerCommands := Seq(
Cmd("FROM", "gafiatulin/alpine-sbt as simop"),
Cmd("RUN", "apk update && apk add bash git sudo nodejs-npm"),
......
......@@ -71,6 +71,7 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
def connectionAppRedirection = {
withTokenData { tokenData =>
println("UP ??" + K8sService.isServiceUp(tokenData.uuid))
proxyRequest
}
}
......
......@@ -2,7 +2,7 @@ package org.openmoleconnect.server
import org.json4s.DefaultFormats
import org.json4s.jackson.JsonMethods._
import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim, JwtHeader, JwtTime}
import pdi.jwt.{Jwt, JwtAlgorithm, JwtBase64, JwtClaim, JwtHeader, JwtTime}
import java.time.Clock
import DB._
......
package org.openmoleconnect.server
import org.openmoleconnect.server.DB.UUID
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import skuber._
import skuber.Timestamp
import skuber.json.format._
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
object K8sService {
case class PodInfo(
name: String,
status: String,
restarts: Int,
createTime: Timestamp
)
private def listPods = {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val dispatcher = system.dispatcher
val k8s = k8sInit
val podList: Future[PodList] = k8s list[PodList]()
podList map {
_.items.flatMap {
pod: Pod =>
println("POD " + pod.name)
val name = pod.name
val ns = pod.namespace
(for {
stat <- pod.status.toList
containerStat <- stat.containerStatuses
status <- containerStat.state
restarts <- stat.containerStatuses.headOption
createTime <- pod.metadata.creationTimestamp
} yield {
PodInfo(name, status.toString.slice(0, status.toString.indexOf("(")), restarts.restartCount, createTime)
})
}
}
}
private def pod(uuid: UUID) = {
import monix.execution.Scheduler.Implicits.global
Await.result(
listPods.map { list =>
list.find {
_.name.contains(uuid)
}
}, 1 minute)
}
def isServiceUp(uuid: UUID): Boolean = {
pod(uuid).isDefined
// existsInMap(uuid) match {
// case true=>
// if(isUp(uuid)) forwarRequest
// else createOMService(uuid)
// case false => addService(uuid)
// }
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment