Commit 77f145e0 authored by Mathieu's avatar Mathieu

Fix Pod satuses

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