add web init with uiconfig file path, add cli flag

This commit is contained in:
Christoph Kluge
2025-10-08 16:25:50 +02:00
parent 31cfa8cd7c
commit e296cd7ca0
5 changed files with 63 additions and 3 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
/cc-backend
/.env
/config.json
/uiConfig.json
/var/job-archive
/var/machine-state

View File

@@ -9,7 +9,7 @@ import "flag"
var (
flagReinitDB, flagInit, flagServer, flagSyncLDAP, flagGops, flagMigrateDB, flagRevertDB,
flagForceDB, flagDev, flagVersion, flagLogDateTime, flagApplyTags bool
flagNewUser, flagDelUser, flagGenJWT, flagConfigFile, flagImportJob, flagLogLevel string
flagNewUser, flagDelUser, flagGenJWT, flagConfigFile, flagUiConfigFile, flagImportJob, flagLogLevel string
)
func cliInit() {
@@ -26,6 +26,7 @@ func cliInit() {
flag.BoolVar(&flagForceDB, "force-db", false, "Force database version, clear dirty flag and exit")
flag.BoolVar(&flagLogDateTime, "logdate", false, "Set this flag to add date and time to log messages")
flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`")
flag.StringVar(&flagUiConfigFile, "ui-config", "./uiConfig.json", "Specify alternative path to `uiConfig.json`")
flag.StringVar(&flagNewUser, "add-user", "", "Add a new user. Argument format: <username>:[admin,support,manager,api,user]:<password>")
flag.StringVar(&flagDelUser, "del-user", "", "Remove a existing user. Argument format: <username>")
flag.StringVar(&flagGenJWT, "jwt", "", "Generate and print a JWT for the user specified by its `username`")

View File

@@ -52,6 +52,8 @@ func onFailureResponse(rw http.ResponseWriter, r *http.Request, err error) {
}
func serverInit() {
// Init Web Package (Primarily: uiDefaults)
web.Init(flagUiConfigFile)
// Setup the http.Handler/Router used by the server
graph.Init()
resolver := graph.GetResolverInstance()

45
configs/uiConfig.json Normal file
View File

@@ -0,0 +1,45 @@
{
"jobList": {
"usePaging": false,
"showFootprint":false
},
"jobView": {
"showPolarPlot": true,
"showFootprint": true,
"showRoofline": true,
"showStatTable": true
},
"metricConfig": {
"jobListMetrics": ["mem_bw", "flops_dp"],
"jobViewPlotMetrics": ["mem_bw", "flops_dp"],
"jobViewTableMetrics": ["mem_bw", "flops_dp"],
"clusters": [
{
"name": "test",
"subClusters": [
{
"name": "one",
"jobListMetrics": ["mem_used", "flops_sp"]
}
]
}
]
},
"nodeList": {
"usePaging": true
},
"plotConfiguration": {
"plotsPerRow": 3,
"colorBackground": true,
"lineWidth": 3,
"colorScheme": [
"#00bfff",
"#0000ff",
"#ff00ff",
"#ff0000",
"#ff8000",
"#ffff00",
"#80ff00"
]
}
}

View File

@@ -11,7 +11,9 @@ import (
"encoding/json"
"html/template"
"io/fs"
"log"
"net/http"
"os"
"strings"
"github.com/ClusterCockpit/cc-backend/internal/config"
@@ -115,9 +117,18 @@ var UIDefaultsMap map[string]any
// "status_view_selectedTopProjectCategory": "totalJobs",
// }
func Init(rawConfig json.RawMessage) error {
var err error
func Init(configFilePath string) error {
var rawConfig json.RawMessage = nil
raw, rerr := os.ReadFile(configFilePath)
if rerr != nil {
if !os.IsNotExist(rerr) {
log.Fatalf("UI-CONFIG ERROR: %v", rerr)
}
} else {
rawConfig = json.RawMessage(raw)
}
var err error
if rawConfig != nil {
config.Validate(configSchema, rawConfig)
if err = json.Unmarshal(rawConfig, &UIDefaults); err != nil {