diff --git a/README.md b/README.md index 2c941af..a3e25aa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ClusterCockpit with a Golang backend (Only supports archived jobs) +# ClusterCockpit with a Golang backend [![Build](https://github.com/ClusterCockpit/cc-jobarchive/actions/workflows/test.yml/badge.svg)](https://github.com/ClusterCockpit/cc-jobarchive/actions/workflows/test.yml) @@ -11,7 +11,12 @@ git clone --recursive git@github.com:ClusterCockpit/cc-jobarchive.git # Prepare frontend cd ./cc-jobarchive/frontend yarn install -CCFRONTEND_ROLLUP_INTRO="" yarn build +export CCFRONTEND_ROLLUP_INTRO=' +const JOBVIEW_URL = job => `/monitoring/job/${job.jobId}`; +const USERVIEW_URL = userId => `/monitoring/user/${userId}`; +const TAG_URL = tag => `/monitoring/jobs/?tag=${tag.id}`; +' +yarn build cd .. go get @@ -45,4 +50,6 @@ This project uses [gqlgen](https://github.com/99designs/gqlgen) for the GraphQL - [ ] Documentation - [ ] Write more TODOs +- [ ] Caching +- [ ] Generate JWTs based on the provided keys diff --git a/frontend b/frontend index 41b8953..cc48461 160000 --- a/frontend +++ b/frontend @@ -1 +1 @@ -Subproject commit 41b8953eb14e52fe9f3c4fe69167202f8002de45 +Subproject commit cc48461a810dbd3565000150fc99332743de92ba diff --git a/server.go b/server.go index 5cd4790..b87c881 100644 --- a/server.go +++ b/server.go @@ -176,8 +176,27 @@ func main() { secured.HandleFunc("/config.json", config.ServeConfig).Methods(http.MethodGet) secured.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { + conf, err := config.GetUIConfig(r) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + + infos := map[string]interface{}{ + "clusters": config.Clusters, + "username": "", + "admin": true, + } + + if user := auth.GetUser(r.Context()); user != nil { + infos["username"] = user.Username + infos["admin"] = user.IsAdmin + } + templates.Render(rw, r, "home", &templates.Page{ - Title: "ClusterCockpit", + Title: "ClusterCockpit", + Config: conf, + Infos: infos, }) }) @@ -208,9 +227,34 @@ func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) { return } + filterPresets := map[string]interface{}{} + query := r.URL.Query() + if query.Get("tag") != "" { + filterPresets["tagId"] = query.Get("tag") + } + if query.Get("cluster") != "" { + filterPresets["clusterId"] = query.Get("cluster") + } + if query.Get("project") != "" { + filterPresets["projectId"] = query.Get("project") + } + if query.Get("running") == "true" { + filterPresets["isRunning"] = true + } + if query.Get("running") == "false" { + filterPresets["isRunning"] = false + } + if query.Get("from") != "" && query.Get("to") != "" { + filterPresets["startTime"] = map[string]string{ + "from": query.Get("from"), + "to": query.Get("to"), + } + } + templates.Render(rw, r, "monitoring/jobs/", &templates.Page{ - Title: "Jobs - ClusterCockpit", - Config: conf, + Title: "Jobs - ClusterCockpit", + Config: conf, + FilterPresets: filterPresets, }) }) @@ -266,8 +310,64 @@ func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) { templates.Render(rw, r, "monitoring/user/", &templates.Page{ Title: fmt.Sprintf("User %s - ClusterCockpit", id), Config: conf, + Infos: map[string]interface{}{"userId": id}, + }) + }) + + router.HandleFunc("/monitoring/analysis/", func(rw http.ResponseWriter, r *http.Request) { + conf, err := config.GetUIConfig(r) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + + filterPresets := map[string]interface{}{} + query := r.URL.Query() + if query.Get("cluster") != "" { + filterPresets["clusterId"] = query.Get("cluster") + } + + templates.Render(rw, r, "monitoring/analysis/", &templates.Page{ + Title: "Analysis View - ClusterCockpit", + Config: conf, + FilterPresets: filterPresets, + }) + }) + + router.HandleFunc("/monitoring/systems/", func(rw http.ResponseWriter, r *http.Request) { + conf, err := config.GetUIConfig(r) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + + filterPresets := map[string]interface{}{} + query := r.URL.Query() + if query.Get("cluster") != "" { + filterPresets["clusterId"] = query.Get("cluster") + } + + templates.Render(rw, r, "monitoring/systems/", &templates.Page{ + Title: "System View - ClusterCockpit", + Config: conf, + FilterPresets: filterPresets, + }) + }) + + router.HandleFunc("/monitoring/node/{clusterId}/{nodeId}", func(rw http.ResponseWriter, r *http.Request) { + conf, err := config.GetUIConfig(r) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + + vars := mux.Vars(r) + templates.Render(rw, r, "monitoring/node/", &templates.Page{ + Title: fmt.Sprintf("Node %s - ClusterCockpit", vars["nodeId"]), + Config: conf, Infos: map[string]interface{}{ - "userId": id, + "nodeId": vars["nodeId"], + "clusterId": vars["clusterId"], }, }) }) diff --git a/templates/home.html b/templates/home.html index 7bbee5a..6b23b2f 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,10 +1,57 @@ {{define "content"}}
Name/ID | +Jobs | +System View | +Analysis View | +
---|---|---|---|
{{.ClusterID}} | +Jobs | +System View | +Analysis View | +