Skip to content

Commit

Permalink
Added /tasks/{task} Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCGuyGitHub committed Jul 7, 2024
1 parent b9ebbfc commit 48fa1ab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.swagger.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import jakarta.inject.Named
Expand Down Expand Up @@ -146,7 +147,7 @@ class CloudNet_Rest_Module : DriverModule() {

routing {

//swaggerUI(path = "swagger", swaggerFile = "openapi/swagger.yaml")
swaggerUI(path = "swagger", swaggerFile = "openapi/swagger.yaml")
authenticate("auth-basic") {
get("/auth") {
call.respond(jsonUtils.token().toString(4))
Expand Down Expand Up @@ -178,7 +179,7 @@ class CloudNet_Rest_Module : DriverModule() {
if (serv) {
call.respond(jsonUtils.service(cloudServiceManager, call.parameters["service"].toString()).toString(4))
} else {
call.respondText("Du Mensch, es gibt diesen Service NICHT! Wasn vollidiot!")
call.response.status(HttpStatusCode.NotFound)
}
} else {
call.response.status(HttpStatusCode.Unauthorized)
Expand All @@ -196,6 +197,22 @@ class CloudNet_Rest_Module : DriverModule() {
}
}

get("/tasks/{task}") {
val tasks = serviceTaskProvider.serviceTasks().map { it.name() }.toList()
val tas = tasks.contains(call.parameters["task"])
val tokens = dbm.tokens()
val rToken = call.request.headers["Authorization"]
if (tokens.contains(rToken)) {
if (tas) {
call.respond(jsonUtils.task(serviceTaskProvider, call.parameters["task"].toString()))
} else {
call.response.status(HttpStatusCode.NotFound)
}
} else {
call.response.status(HttpStatusCode.Unauthorized)
}
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,32 @@ class JsonUtils internal constructor() {
val serv = JSONObject()
if (ser != null) {
serv.put("name", ser.name())
println("1")

val addressObject = JSONObject()
addressObject.put("host", ser.address().host)
addressObject.put("port", ser.address().port)
serv.put("address", addressObject)
println("2")

serv.put("connected", ser.connected())
serv.put("connectedTime", ser.connectedTime())
serv.put("lifeCycle", ser.lifeCycle())
serv.put("creationTime", ser.creationTime())
println("3")

val configuration = JSONObject()
configuration.put("staticService", ser.configuration().staticService())
configuration.put("autoDeleteOnStop", ser.configuration().autoDeleteOnStop())
configuration.put("groups", ser.configuration().groups())
configuration.put("runtime", ser.configuration().runtime())
serv.put("configuration", configuration)
println("4")

val processConfig = JSONObject()
processConfig.put("jvmOptions", ser.configuration().processConfig().jvmOptions)
processConfig.put("environment", ser.configuration().processConfig().environment)
processConfig.put("maxHeapMemorySize", ser.configuration().processConfig().maxHeapMemorySize)
processConfig.put("processParameters", ser.configuration().processConfig().processParameters)
processConfig.put("environmentVariables", ser.configuration().processConfig().environmentVariables)
serv.put("processConfig", processConfig)
println("5")

val processSnapshot = JSONObject()
processSnapshot.put("pid", ser.processSnapshot().pid)
processSnapshot.put("threads", ser.processSnapshot().threads)
Expand All @@ -79,10 +79,8 @@ class JsonUtils internal constructor() {
processSnapshot.put("systemCpuUsage", ser.processSnapshot().systemCpuUsage)
processSnapshot.put("unloadedClassCount", ser.processSnapshot().unloadedClassCount)
serv.put("processSnapshot", processSnapshot)
println("6")

}
println("7")
println(serv.toString(4))

return serv
}
Expand Down Expand Up @@ -122,6 +120,37 @@ class JsonUtils internal constructor() {
return result
}

fun task(taskProvider: ServiceTaskProvider, vTask: String): JSONObject {
val task = taskProvider.serviceTask(vTask)
val jTask = JSONObject()
if (task != null) {
jTask.put("name", task.name())
jTask.put("groups", task.groups())
jTask.put("runtime", task.runtime())
jTask.put("startPort", task.startPort())
jTask.put("associatedNodes", task.associatedNodes())
jTask.put("autoDeleteOnStop", task.autoDeleteOnStop())
jTask.put("hostAddress", task.hostAddress())
jTask.put("javaCommand", task.javaCommand())
jTask.put("maintenance", task.maintenance())
jTask.put("minServiceCount", task.minServiceCount())
jTask.put("nameSplitter", task.nameSplitter())
jTask.put("staticServices", task.staticServices())

val processConfiguration = JSONObject()
processConfiguration.put("environment", task.processConfiguration().environment)
processConfiguration.put("jvmOptions", task.processConfiguration().jvmOptions)
processConfiguration.put("processParameters", task.processConfiguration().processParameters)
processConfiguration.put("maxHeapMemorySize", task.processConfiguration().maxHeapMemorySize)
processConfiguration.put("environmentVariables", task.processConfiguration().environmentVariables)
jTask.put("processConfiguration", processConfiguration)
}

return jTask
}





fun token():JSONObject {
Expand Down

0 comments on commit 48fa1ab

Please sign in to comment.