Commit e73c8937 authored by mengxue's avatar mengxue
Browse files

Change CREATE TIME to AGE in all the lists

parent db25bf1a
......@@ -30,8 +30,8 @@ object ListDeployments extends App{
private def listDeployments(deployments: List[Deployment]) = {
System.out.println("")
System.out.println("NAME NAMESPACE READY UP-TO-DATE AVAILABLE CREATE TIME")
System.out.println("==== ========= ===== ========== ========= ===========")
System.out.println("NAME NAMESPACE READY UP-TO-DATE AVAILABLE AGE")
System.out.println("==== ========= ===== ========== ========= ===")
deployments.map { deployment: Deployment =>
val name = deployment.name
......@@ -44,13 +44,37 @@ object ListDeployments extends App{
} yield {
DeploymentInfo(status.replicas, status.updatedReplicas, status.availableReplicas, createTime)
}).headOption
val createTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(deploymentInfo.map{_.createTime}.getOrElse("None").toString())
//val createTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(deploymentInfo.map{_.createTime}.getOrElse("None").toString())
def getAge():String = {
import java.time._
val createTime = deploymentInfo.map{_.createTime}.get
val now = ZonedDateTime.now
val diff = Duration.between(createTime, now).toMillis
val diffSecond = diff / 1000; val minute = 60
val hour = 60*60; val day = 60*60*24
var age = ""
if (diffSecond < 2*minute) {
age = diffSecond + "s"
} else if (2*minute <= diffSecond && diffSecond < 10*minute) {
age = diffSecond / minute + "m" + diffSecond % minute + "s"
} else if (10*minute <= diffSecond && diffSecond < hour) {
age = diffSecond / minute + "m"
} else if (hour <= diffSecond && diffSecond < 2*day) {
age = diffSecond / hour + "h"
} else {
age = diffSecond / day + "d"
}
(age)
}
System.out.println(f"${name}%-25s${ns}%-20s" +
f"${deploymentInfo.map{_.availableReplicas}.getOrElse("None")}"+"/"+ f"${deploymentInfo.map{_.replicas}.getOrElse("None")}%-18s" +
f"${deploymentInfo.map{_.updatedReplicas}.getOrElse("<None>")}%-20s" +
f"${deploymentInfo.map{_.availableReplicas}.getOrElse("None")}%-20s" +
f"${createTimeString}")
f"${getAge()}")
}
}
......
......@@ -28,8 +28,8 @@ object ListNodes extends App {
private def listNodes(nodes: List[Node]) = {
System.out.println("")
System.out.println("Node STATUS VERSION CREATE TIME")
System.out.println("==== ====== ======= ===========")
System.out.println("Node STATUS VERSION AGE")
System.out.println("==== ====== ======= ===")
nodes.map { node: Node =>
val name = node.name
......@@ -40,9 +40,34 @@ object ListNodes extends App {
} yield {
NodeInfo(status._type, stat.nodeInfo.get.kubeletVersion, node.metadata.creationTimestamp.get)
}).reverse.headOption
val startTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(nodeInfo.map{_.startTime}.getOrElse("None").toString())
//val startTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(nodeInfo.map{_.startTime}.getOrElse("None").toString())
System.out.println(f"${name}%-20s${nodeInfo.map{_.status.toString}.getOrElse("Nono")}%-20s${nodeInfo.map{_.version}.getOrElse("None")}%-20s${startTimeString}")
def getAge():String = {
import java.time._
val createTime = nodeInfo.map{_.startTime}.get
val now = ZonedDateTime.now
val diff = Duration.between(createTime, now).toMillis
val diffSecond = diff / 1000; val minute = 60
val hour = 60*60; val day = 60*60*24
var age = ""
if (diffSecond < 2*minute) {
age = diffSecond + "s"
} else if (2*minute <= diffSecond && diffSecond < 10*minute) {
age = diffSecond / minute + "m" + diffSecond % minute + "s"
} else if (10*minute <= diffSecond && diffSecond < hour) {
age = diffSecond / minute + "m"
} else if (hour <= diffSecond && diffSecond < 2*day) {
age = diffSecond / hour + "h"
} else {
age = diffSecond / day + "d"
}
(age)
}
System.out.println(f"${name}%-20s${nodeInfo.map{_.status.toString}.getOrElse("Nono")}%-20s" +
f"${nodeInfo.map{_.version}.getOrElse("None")}%-20s${getAge()}")
}
}
......
......@@ -30,8 +30,8 @@ object ListPods extends App{
private def listPods(pods: List[Pod]) = {
System.out.println("")
System.out.println("POD NAME NAMESPACE STATUS RESTARTS CREATE TIME")
System.out.println("======== ========= ====== ======== ===========")
System.out.println("POD NAME NAMESPACE STATUS RESTARTS AGE")
System.out.println("======== ========= ====== ======== ===")
pods.map { pod: Pod =>
val name = pod.name
......@@ -48,9 +48,36 @@ object ListPods extends App{
//st = status.containerStatuses.map {_.restartCount}
PodInfo(status.toString.slice(0,7), restarts.restartCount, createTime)
}).headOption
val createTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(podInfo.map{_.createTime}.getOrElse("None").toString())
System.out.println(f"${name}%-50s${ns}%-20s${podInfo.map{_.status}.getOrElse("None")}%-20s${podInfo.map{_.restarts}.getOrElse("None")}%-20s${createTimeString}")
//val createTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(podInfo.map{_.createTime}.getOrElse("None").toString())
def getAge():String = {
import java.time._
val createTime = podInfo.map{_.createTime}.get
val now = ZonedDateTime.now
val diff = Duration.between(createTime, now).toMillis
val diffSecond = diff / 1000; val minute = 60
val hour = 60*60; val day = 60*60*24
var age = ""
if (diffSecond < 2*minute) {
age = diffSecond + "s"
} else if (2*minute <= diffSecond && diffSecond < 10*minute) {
age = diffSecond / minute + "m" + diffSecond % minute + "s"
} else if (10*minute <= diffSecond && diffSecond < hour) {
age = diffSecond / minute + "m"
} else if (hour <= diffSecond && diffSecond < 2*day) {
age = diffSecond / hour + "h"
} else {
age = diffSecond / day + "d"
}
(age)
}
System.out.println(f"${name}%-50s${ns}%-20s" +
f"${podInfo.map{_.status}.getOrElse("None")}%-20s" +
f"${podInfo.map{_.restarts}.getOrElse("None")}%-20s" +
f"${getAge()}")
}
}
......
......@@ -70,8 +70,8 @@ object ListServices extends App{
age = diffSecond / minute + "m" + diffSecond % minute + "s"
} else if (10*minute <= diffSecond && diffSecond < hour) {
age = diffSecond / minute + "m"
} else if (hour <= diffSecond && diffSecond < day) {
age = diffSecond / hour + "h" + diffSecond % hour + "m"
} else if (hour <= diffSecond && diffSecond < 2*day) {
age = diffSecond / hour + "h"
} else {
age = diffSecond / day + "d"
}
......
......@@ -23,22 +23,8 @@ object ServiceOpenmole extends App {
val openmoleServiceName = "openmole-scaladepl-svc"
run
// run.onComplete { serv =>
// serv match {
// case Success(_) => println("\nSuccessfully created service of openmole ")
// case Failure(exception) => exception.printStackTrace()
// }
// k8s.close
// println("\n(Waiting 30 seconds before terminating)")
// Thread.sleep(30000)
// system.terminate()
// materializer.shutdown()
// }
def serviceOpenmole: (Service, ReplicaSet) = {
val openmoleLabel = "app" -> "openmole"
......@@ -82,7 +68,7 @@ object ServiceOpenmole extends App {
*/
def buildIngress: Ingress = {
Ingress("openmole-ing")
.addHttpRule("skuber-openmole.iscpif.fr", Map("/guo" -> "openmole-scalasvc:21000"))
.addHttpRule("skuber-openmole.iscpif.fr", Map("/guo" -> "openmole-scalasvc:20002"))
}
def run = {
......@@ -92,8 +78,6 @@ object ServiceOpenmole extends App {
val k8s = k8sInit
val serv = serviceOpenmole
val servS = serviceOpenmole._1
val ingressSpec = buildIngress
......@@ -101,7 +85,6 @@ object ServiceOpenmole extends App {
def ignore409: PartialFunction[Throwable, Any] = {
case ex: K8SException if (ex.status.code.contains(409)) => {
println("It seems the resource already exists - continuing")
}
}
......@@ -127,7 +110,6 @@ object ServiceOpenmole extends App {
createSvc(servS)
createIngress
createIngress.onComplete { serv =>
serv match {
case Success(_) => println("\nSuccessfully created service of openmole ")
......@@ -138,7 +120,7 @@ object ServiceOpenmole extends App {
Thread.sleep(30000)
system.terminate()
materializer.shutdown()
}
}
}
......
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