2022-07-29 06:29:21 +02:00
|
|
|
// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2021-10-26 10:24:43 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-09-19 16:16:05 +02:00
|
|
|
"bytes"
|
2021-10-26 10:24:43 +02:00
|
|
|
"encoding/json"
|
2022-09-05 17:46:38 +02:00
|
|
|
"log"
|
2021-10-26 10:24:43 +02:00
|
|
|
"os"
|
2021-11-26 10:32:36 +01:00
|
|
|
|
2022-09-07 12:24:45 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
2021-10-26 10:24:43 +02:00
|
|
|
)
|
|
|
|
|
2022-09-07 12:24:45 +02:00
|
|
|
var Keys schema.ProgramConfig = schema.ProgramConfig{
|
2022-09-27 10:33:36 +02:00
|
|
|
Addr: "localhost:8080",
|
2022-09-19 16:16:05 +02:00
|
|
|
DisableAuthentication: false,
|
|
|
|
EmbedStaticFiles: true,
|
|
|
|
DBDriver: "sqlite3",
|
|
|
|
DB: "./var/job.db",
|
|
|
|
Archive: json.RawMessage(`{\"kind\":\"file\",\"path\":\"./var/job-archive\"}`),
|
|
|
|
DisableArchive: false,
|
|
|
|
Validate: false,
|
|
|
|
SessionMaxAge: "168h",
|
|
|
|
StopJobsExceedingWalltime: 0,
|
2023-03-01 16:34:59 +01:00
|
|
|
ShortRunningJobsDuration: 5 * 60,
|
2022-09-05 17:46:38 +02:00
|
|
|
UiDefaults: map[string]interface{}{
|
2023-08-30 15:15:53 +02:00
|
|
|
"analysis_view_histogramMetrics": []string{"flops_any", "mem_bw", "mem_used"},
|
|
|
|
"analysis_view_scatterPlotMetrics": [][]string{{"flops_any", "mem_bw"}, {"flops_any", "cpu_load"}, {"cpu_load", "mem_bw"}},
|
|
|
|
"job_view_nodestats_selectedMetrics": []string{"flops_any", "mem_bw", "mem_used"},
|
|
|
|
"job_view_polarPlotMetrics": []string{"flops_any", "mem_bw", "mem_used"},
|
|
|
|
"job_view_selectedMetrics": []string{"flops_any", "mem_bw", "mem_used"},
|
|
|
|
"plot_general_colorBackground": true,
|
|
|
|
"plot_general_colorscheme": []string{"#00bfff", "#0000ff", "#ff00ff", "#ff0000", "#ff8000", "#ffff00", "#80ff00"},
|
|
|
|
"plot_general_lineWidth": 3,
|
|
|
|
"plot_list_jobsPerPage": 50,
|
|
|
|
"plot_list_selectedMetrics": []string{"cpu_load", "mem_used", "flops_any", "mem_bw"},
|
|
|
|
"plot_view_plotsPerRow": 3,
|
|
|
|
"plot_view_showPolarplot": true,
|
|
|
|
"plot_view_showRoofline": true,
|
|
|
|
"plot_view_showStatTable": true,
|
|
|
|
"system_view_selectedMetric": "cpu_load",
|
|
|
|
"analysis_view_selectedTopEntity": "user",
|
|
|
|
"analysis_view_selectedTopCategory": "totalWalltime",
|
|
|
|
"status_view_selectedTopUserCategory": "totalJobs",
|
|
|
|
"status_view_selectedTopProjectCategory": "totalJobs",
|
2022-09-05 17:46:38 +02:00
|
|
|
},
|
2022-03-14 10:18:56 +01:00
|
|
|
}
|
2022-03-24 14:34:42 +01:00
|
|
|
|
2022-09-05 17:46:38 +02:00
|
|
|
func Init(flagConfigFile string) {
|
2022-09-19 16:16:05 +02:00
|
|
|
raw, err := os.ReadFile(flagConfigFile)
|
2022-09-05 17:46:38 +02:00
|
|
|
if err != nil {
|
2022-09-06 14:40:14 +02:00
|
|
|
if !os.IsNotExist(err) {
|
2023-01-23 18:48:06 +01:00
|
|
|
log.Fatalf("CONFIG ERROR: %v", err)
|
2022-03-24 14:34:42 +01:00
|
|
|
}
|
2022-09-05 17:46:38 +02:00
|
|
|
} else {
|
2022-09-19 16:16:05 +02:00
|
|
|
if err := schema.Validate(schema.Config, bytes.NewReader(raw)); err != nil {
|
2023-01-23 18:48:06 +01:00
|
|
|
log.Fatalf("Validate config: %v\n", err)
|
2022-09-19 16:16:05 +02:00
|
|
|
}
|
|
|
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
2022-09-05 17:46:38 +02:00
|
|
|
dec.DisallowUnknownFields()
|
|
|
|
if err := dec.Decode(&Keys); err != nil {
|
2023-01-23 18:48:06 +01:00
|
|
|
log.Fatalf("could not decode: %v", err)
|
2022-09-05 17:46:38 +02:00
|
|
|
}
|
2022-09-06 14:40:14 +02:00
|
|
|
|
|
|
|
if Keys.Clusters == nil || len(Keys.Clusters) < 1 {
|
2023-01-23 18:48:06 +01:00
|
|
|
log.Fatal("At least one cluster required in config!")
|
2022-09-06 14:40:14 +02:00
|
|
|
}
|
2022-03-24 14:34:42 +01:00
|
|
|
}
|
|
|
|
}
|