mirror of
				https://github.com/ClusterCockpit/cc-backend
				synced 2025-10-31 07:55:06 +01:00 
			
		
		
		
	add web init with uiconfig file path, add cli flag
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,6 +1,7 @@ | |||||||
| /cc-backend | /cc-backend | ||||||
| /.env | /.env | ||||||
| /config.json | /config.json | ||||||
|  | /uiConfig.json | ||||||
|  |  | ||||||
| /var/job-archive | /var/job-archive | ||||||
| /var/machine-state | /var/machine-state | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import "flag" | |||||||
| var ( | var ( | ||||||
| 	flagReinitDB, flagInit, flagServer, flagSyncLDAP, flagGops, flagMigrateDB, flagRevertDB, | 	flagReinitDB, flagInit, flagServer, flagSyncLDAP, flagGops, flagMigrateDB, flagRevertDB, | ||||||
| 	flagForceDB, flagDev, flagVersion, flagLogDateTime, flagApplyTags bool | 	flagForceDB, flagDev, flagVersion, flagLogDateTime, flagApplyTags bool | ||||||
| 	flagNewUser, flagDelUser, flagGenJWT, flagConfigFile, flagImportJob, flagLogLevel string | 	flagNewUser, flagDelUser, flagGenJWT, flagConfigFile, flagUiConfigFile, flagImportJob, flagLogLevel string | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func cliInit() { | func cliInit() { | ||||||
| @@ -26,6 +26,7 @@ func cliInit() { | |||||||
| 	flag.BoolVar(&flagForceDB, "force-db", false, "Force database version, clear dirty flag and exit") | 	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.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(&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(&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(&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`") | 	flag.StringVar(&flagGenJWT, "jwt", "", "Generate and print a JWT for the user specified by its `username`") | ||||||
|   | |||||||
| @@ -52,6 +52,8 @@ func onFailureResponse(rw http.ResponseWriter, r *http.Request, err error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func serverInit() { | func serverInit() { | ||||||
|  | 	// Init Web Package (Primarily: uiDefaults) | ||||||
|  | 	web.Init(flagUiConfigFile) | ||||||
| 	// Setup the http.Handler/Router used by the server | 	// Setup the http.Handler/Router used by the server | ||||||
| 	graph.Init() | 	graph.Init() | ||||||
| 	resolver := graph.GetResolverInstance() | 	resolver := graph.GetResolverInstance() | ||||||
|   | |||||||
							
								
								
									
										45
									
								
								configs/uiConfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								configs/uiConfig.json
									
									
									
									
									
										Normal 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" | ||||||
|  |     ] | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								web/web.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								web/web.go
									
									
									
									
									
								
							| @@ -11,7 +11,9 @@ import ( | |||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/fs" | 	"io/fs" | ||||||
|  | 	"log" | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"github.com/ClusterCockpit/cc-backend/internal/config" | 	"github.com/ClusterCockpit/cc-backend/internal/config" | ||||||
| @@ -115,9 +117,18 @@ var UIDefaultsMap map[string]any | |||||||
| // 	"status_view_selectedTopProjectCategory": "totalJobs", | // 	"status_view_selectedTopProjectCategory": "totalJobs", | ||||||
| // } | // } | ||||||
|  |  | ||||||
| func Init(rawConfig json.RawMessage) error { | func Init(configFilePath string) error { | ||||||
| 	var err 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 { | 	if rawConfig != nil { | ||||||
| 		config.Validate(configSchema, rawConfig) | 		config.Validate(configSchema, rawConfig) | ||||||
| 		if err = json.Unmarshal(rawConfig, &UIDefaults); err != nil { | 		if err = json.Unmarshal(rawConfig, &UIDefaults); err != nil { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user