jove.notebook.services.Clusters.scala Maven / Gradle / Ivy
The newest version!
package jove.notebook
package services
import jove.notebook.components.Cluster
import org.http4s.dsl._
import org.http4s.argonaut._
import argonaut._, Argonaut._, Shapeless._
object Clusters {
def apply(cluster: Cluster): Plan = {
case GET -> Root / "clusters" =>
Ok(cluster.clusters.toList.map{
case (id, cluster) =>
Protocol.Cluster(id, cluster.dir, cluster.status, cluster.n)
}.asJson)
case req @ (POST -> Root / "clusters" / profile) =>
cluster.clusters.get(profile) match {
case Some(cluster) =>
Ok(Protocol.Cluster(profile, cluster.dir, cluster.status, cluster.n).asJson)
case None =>
BadRequest()
}
case req @ (POST -> Root / "clusters" / profile / action) =>
cluster.clusters.get(profile) match {
case Some(cluster) =>
action match {
case "start" =>
cluster.start()
case "stop" =>
cluster.stop()
case _ =>
}
Ok(Protocol.Cluster(profile, cluster.dir, cluster.status, cluster.n).asJson)
case None =>
BadRequest()
}
}
}