Commit 77f145e0 authored by Mathieu's avatar Mathieu
Browse files

Fix Pod satuses

parent 31b5023a
...@@ -11,7 +11,6 @@ import autowire._ ...@@ -11,7 +11,6 @@ import autowire._
import rx._ import rx._
import scaladget.bootstrapnative.Table.StaticSubRow import scaladget.bootstrapnative.Table.StaticSubRow
import scaladget.bootstrapnative._ import scaladget.bootstrapnative._
import scaladget.bootstrapnative.bsn.{glyph_edit2, glyph_save}
import scalatags.JsDom.styles import scalatags.JsDom.styles
import shared.Data._ import shared.Data._
...@@ -21,6 +20,8 @@ import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer} ...@@ -21,6 +20,8 @@ import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
import scaladget.bootstrapnative.bsn._ import scaladget.bootstrapnative.bsn._
import scaladget.tools.{ModifierSeq, _} import scaladget.tools.{ModifierSeq, _}
import scalatags.JsDom.all._ import scalatags.JsDom.all._
import scala.scalajs.js.timers._
import Utils._ import Utils._
import scala.scalajs.js.Date import scala.scalajs.js.Date
...@@ -31,7 +32,7 @@ object AdminPanel { ...@@ -31,7 +32,7 @@ object AdminPanel {
def admin() = { def admin() = {
implicit def userDataSeqToRows(userData: Seq[UserData]): Seq[ExpandableRow] = userData.map { u => implicit def userDataSeqToRows(userData: Seq[UserData]): Seq[ExpandableRow] = userData.map { u =>
buildExpandable(u.name, u.email, u.password, u.role, u.omVersion, u.lastAccess, running) buildExpandable(u.name, u.email, u.password, u.role, u.omVersion, u.lastAccess, podInfos.now.filter{_.userEmail == u.email}.headOption)
} }
...@@ -40,6 +41,7 @@ object AdminPanel { ...@@ -40,6 +41,7 @@ object AdminPanel {
lazy val rows: Var[Seq[ExpandableRow]] = Var(Seq()) lazy val rows: Var[Seq[ExpandableRow]] = Var(Seq())
lazy val podInfos: Var[Seq[PodInfo]] = Var(Seq())
def save(expandableRow: ExpandableRow, userData: UserData): Unit = { def save(expandableRow: ExpandableRow, userData: UserData): Unit = {
...@@ -60,6 +62,24 @@ object AdminPanel { ...@@ -60,6 +62,24 @@ object AdminPanel {
rows() = _ rows() = _
} }
def updateRows =
Post[AdminApi].users().call().foreach { us =>
rows() = us
}
def updatePodInfos =
Post[AdminApi].podInfos().call().foreach {pi=>
podInfos() = pi
updateRows
}
def updatePodInfoTimer:Unit = {
setTimeout(5000) {
updatePodInfos
updatePodInfoTimer
}
}
def closeAll(except: ExpandableRow) = rows.now.filterNot { def closeAll(except: ExpandableRow) = rows.now.filterNot {
_ == except _ == except
...@@ -74,7 +94,7 @@ object AdminPanel { ...@@ -74,7 +94,7 @@ object AdminPanel {
userRole: Role = "", userRole: Role = "",
userOMVersion: String = "", userOMVersion: String = "",
userLastAccess: Long = 0L, userLastAccess: Long = 0L,
userStatus: Status = user, podInfo: Option[PodInfo] = None,
expanded: Boolean = false): ExpandableRow = { expanded: Boolean = false): ExpandableRow = {
val aVar = Var(expanded) val aVar = Var(expanded)
...@@ -92,9 +112,9 @@ object AdminPanel { ...@@ -92,9 +112,9 @@ object AdminPanel {
) )
}, aVar) }, aVar)
def statusStyle(s: Status) = def statusStyle(s: String) =
if (s == running) label_success if (s == "Running") label_success
else if (s == off) label_default else if (s == "Waiting") label_warning
else label_danger else label_danger
lazy val expandableRow: ExpandableRow = ExpandableRow(EditableRow(Seq( lazy val expandableRow: ExpandableRow = ExpandableRow(EditableRow(Seq(
...@@ -102,19 +122,21 @@ object AdminPanel { ...@@ -102,19 +122,21 @@ object AdminPanel {
closeAll(expandableRow) closeAll(expandableRow)
aVar() = !aVar.now aVar() = !aVar.now
})), })),
LabelCell(userStatus, Seq(), optionStyle = statusStyle), LabelCell(podInfo.map {
_.status
}.getOrElse("Unknown"), Seq(), optionStyle = _ => podInfo.map { pi => statusStyle(pi.status) }.getOrElse(label_danger)),
)), aSubRow) )), aSubRow)
lazy val groupCell: GroupCell = UserPanel.editableData(userName, userEmail, userPassword, userRole, userStatus, userOMVersion, userLastAccess, expanded, (uData: UserData) => save(expandableRow, uData)) lazy val groupCell: GroupCell = UserPanel.editableData(userName, userEmail, userPassword, userRole, podInfo, userOMVersion, userLastAccess, expanded, (uData: UserData) => save(expandableRow, uData))
expandableRow expandableRow
} }
Post[AdminApi].users().call().foreach { us => updateRows
rows() = us updatePodInfos
} updatePodInfoTimer
val addUserButton = button(btn_primary, "Add", onclick := { () => val addUserButton = button(btn_primary, "Add", onclick := { () =>
val row = buildExpandable(userRole = user, userOMVersion = "LATEST", expanded = true) val row = buildExpandable(userRole = user, userOMVersion = "LATEST", expanded = true)
......
...@@ -22,7 +22,7 @@ object UserPanel { ...@@ -22,7 +22,7 @@ object UserPanel {
userEmail: String = "", userEmail: String = "",
userPassword: String = "", userPassword: String = "",
userRole: Role = "", userRole: Role = "",
userStatus: Status = user, podInfo: Option[PodInfo] = None,
userOMVersion: String, userOMVersion: String,
userLastAccess: Long, userLastAccess: Long,
expanded: Boolean = false, expanded: Boolean = false,
......
package org.openmoleconnect.server package org.openmoleconnect.server
import shared.Data.UserData import shared.Data.{PodInfo, UserData}
import DB._ import DB._
object AdminApiImpl extends shared.AdminApi { object AdminApiImpl extends shared.AdminApi {
...@@ -22,4 +22,8 @@ object AdminApiImpl extends shared.AdminApi { ...@@ -22,4 +22,8 @@ object AdminApiImpl extends shared.AdminApi {
} }
users users
} }
//PODS
def podInfos(): Seq[PodInfo] = K8sService.podInfos
} }
\ No newline at end of file
...@@ -139,6 +139,10 @@ object DB { ...@@ -139,6 +139,10 @@ object DB {
_.uuid _.uuid
} }
def uuids = users.map{_.uuid}
def email(uuid: UUID) = users.find(u=> u.uuid == uuid).map{_.email}
def get(email: Email) = { def get(email: Email) = {
runQuery( runQuery(
getQuery(email) getQuery(email)
......
package org.openmoleconnect.server package org.openmoleconnect.server
import java.time.temporal.ChronoField
import org.openmoleconnect.server.DB.UUID import org.openmoleconnect.server.DB.UUID
import akka.actor.ActorSystem import akka.actor.ActorSystem
import akka.stream.ActorMaterializer import akka.stream.ActorMaterializer
import shared.Data
import skuber._ import skuber._
import skuber.Timestamp import skuber.Timestamp
import skuber.json.format._ import skuber.json.format._
import shared.Data._
import scala.concurrent.duration._ import scala.concurrent.duration._
import scala.concurrent.{Await, Future} import scala.concurrent.{Await, Future}
object K8sService { object K8sService {
case class PodInfo(
name: String,
status: String,
restarts: Int,
createTime: Timestamp,
podIP: String
)
private def listPods = { private def listPods = {
implicit val system = ActorSystem() implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer() implicit val materializer = ActorMaterializer()
...@@ -41,7 +35,7 @@ object K8sService { ...@@ -41,7 +35,7 @@ object K8sService {
_.flatMap { _.flatMap {
pod: Pod => pod: Pod =>
val name = pod.name val name = pod.name
val ns = pod.namespace // val ns = pod.namespace
(for { (for {
stat <- pod.status.toList stat <- pod.status.toList
...@@ -51,13 +45,20 @@ object K8sService { ...@@ -51,13 +45,20 @@ object K8sService {
createTime <- pod.metadata.creationTimestamp createTime <- pod.metadata.creationTimestamp
podIP <- stat.podIP podIP <- stat.podIP
} yield { } yield {
PodInfo(name, status.toString.slice(0, status.toString.indexOf("(")), restarts.restartCount, createTime, podIP)
val st: Status = status match {
case Container.Waiting(reason)=> Data.Waiting(reason.getOrElse(""))
case _: Container.Running=> Data.Running()
case Container.Terminated(_,_,_,message,_,finishedAt, _)=> Data.Terminated(message.getOrElse(""), finishedAt.map{_.toLocalTime.getLong(ChronoField.INSTANT_SECONDS)}.getOrElse(0L))
}
PodInfo(name, st.value, restarts.restartCount, createTime.toLocalTime.getLong(ChronoField.INSTANT_SECONDS), podIP, DB.email(UUID(pod.metadata.name)).map{_.value})
}) })
} }
} }
} }
private def pod(uuid: UUID) = { private def podInfo(uuid: UUID) = {
import monix.execution.Scheduler.Implicits.global import monix.execution.Scheduler.Implicits.global
Await.result( Await.result(
...@@ -70,14 +71,15 @@ object K8sService { ...@@ -70,14 +71,15 @@ object K8sService {
def isServiceUp(uuid: UUID): Boolean = { def isServiceUp(uuid: UUID): Boolean = {
pod(uuid).isDefined podInfo(uuid).map{_.status} == Some(Running)
// existsInMap(uuid) match { }
// case true=>
// if(isUp(uuid)) forwarRequest def podInfos: Seq[PodInfo] = {
// else createOMService(uuid) for {
// case false => addService(uuid) uuid <- DB.uuids
// } podInfo <- podInfo(uuid)
} yield (podInfo)
} }
def hostIP(uuid:UUID) = pod(uuid).map{_.podIP} def hostIP(uuid:UUID) = podInfo(uuid).map{_.podIP}
} }
package shared package shared
import shared.Data.UserData import shared.Data.{PodInfo, UserData}
trait AdminApi { trait AdminApi {
// USERS
def users(): Seq[UserData] def users(): Seq[UserData]
def upserted(userData: UserData): Seq[UserData] def upserted(userData: UserData): Seq[UserData]
def delete(userData: UserData): Seq[UserData] def delete(userData: UserData): Seq[UserData]
// PODS
def podInfos(): Seq[PodInfo]
} }
\ No newline at end of file
...@@ -9,15 +9,22 @@ object Data { ...@@ -9,15 +9,22 @@ object Data {
val admin: Role = "Admin" val admin: Role = "Admin"
val user: Role = "User" val user: Role = "User"
type Status = String trait Status {
val running: Status = "Running" def value: String
val off: Status = "Off" }
val error: Status = "Error" case class Waiting(message: String, value: String = "Waiting") extends Status
case class Terminated(message: String, finishedAt: Long, value: String = "Terminated") extends Status
case class Running(value: String = "Running") extends Status
case class PodInfo(
name: String,
status: String,
restarts: Int,
createTime: Long,
podIP: String,
userEmail: Option[String]
)
case class UserData(name: String, email: String, password: String, role: Role, omVersion: String, lastAccess: Long) case class UserData(name: String, email: String, password: String, role: Role, omVersion: String, lastAccess: Long)
case class PersonalUserData(name: String, email: String, password: String, role: Role)
case class UserStatus(uuid: String, status: Status)
} }
\ No newline at end of file
Markdown is supported
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