diff --git a/configs/clusterConfig.json b/configs/clusterConfig.json deleted file mode 100644 index 188ac45..0000000 --- a/configs/clusterConfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - [ - "name": "alex", - "metricDataRepository": { - "kind": "cc-metric-store", - "url": "http://localhost:8082", - "token": "eyJhbGciOiJF-E-pQBQ" - }, - "filterRanges": { - "numNodes": { "from": 1, "to": 64 }, - "duration": { "from": 0, "to": 86400 }, - "startTime": { "from": "2022-01-01T00:00:00Z", "to": null } - } - ] -} diff --git a/configs/config.json b/configs/config.json index 400468a..49c5f26 100644 --- a/configs/config.json +++ b/configs/config.json @@ -1,12 +1,12 @@ { "addr": "0.0.0.0:443", "ldap": { - "url": "ldaps://hpcldap.rrze.uni-erlangen.de", - "user_base": "ou=people,ou=hpc,dc=rrze,dc=uni-erlangen,dc=de", - "search_dn": "cn=hpcmonitoring,ou=roadm,ou=profile,ou=hpc,dc=rrze,dc=uni-erlangen,dc=de", - "user_bind": "uid={username},ou=people,ou=hpc,dc=rrze,dc=uni-erlangen,dc=de", - "user_filter": "(&(objectclass=posixAccount)(uid=*))" - }, + "url": "ldaps://hpcldap.rrze.uni-erlangen.de", + "user_base": "ou=people,ou=hpc,dc=rrze,dc=uni-erlangen,dc=de", + "search_dn": "cn=hpcmonitoring,ou=roadm,ou=profile,ou=hpc,dc=rrze,dc=uni-erlangen,dc=de", + "user_bind": "uid={username},ou=people,ou=hpc,dc=rrze,dc=uni-erlangen,dc=de", + "user_filter": "(&(objectclass=posixAccount)(uid=*))" + }, "https-cert-file": "/etc/letsencrypt/live/monitoring.nhr.fau.de/fullchain.pem", "https-key-file": "/etc/letsencrypt/live/monitoring.nhr.fau.de/privkey.pem", "user": "clustercockpit", @@ -14,5 +14,20 @@ "archive": { "kind": "file", "path": "./var/job-archive" - } + }, + "clusters": [ + { + "name": "test", + "metricDataRepository": { + "kind": "cc-metric-store", + "url": "http://localhost:8082", + "token": "eyJhbGciOiJF-E-pQBQ" + }, + "filterRanges": { + "numNodes": { "from": 1, "to": 64 }, + "duration": { "from": 0, "to": 86400 }, + "startTime": { "from": "2022-01-01T00:00:00Z", "to": null } + } + } + ] } diff --git a/internal/config/config.go b/internal/config/config.go index 1474bab..9c5d0b7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -76,7 +76,7 @@ type ProgramConfig struct { StopJobsExceedingWalltime int `json:"stop-jobs-exceeding-walltime"` // Array of Clusters - Clusters []*Cluster `json:"Clusters"` + Clusters []*Cluster `json:"clusters"` } var Keys ProgramConfig = ProgramConfig{ @@ -85,7 +85,7 @@ var Keys ProgramConfig = ProgramConfig{ EmbedStaticFiles: true, DBDriver: "sqlite3", DB: "./var/job.db", - Archive: []byte(`{\"kind\":\"file\",\"path\":\"./var/job-archive\"}`), + Archive: json.RawMessage(`{\"kind\":\"file\",\"path\":\"./var/job-archive\"}`), DisableArchive: false, LdapConfig: nil, SessionMaxAge: "168h", @@ -113,7 +113,7 @@ var Keys ProgramConfig = ProgramConfig{ func Init(flagConfigFile string) { f, err := os.Open(flagConfigFile) if err != nil { - if !os.IsNotExist(err) || flagConfigFile != "./config.json" { + if !os.IsNotExist(err) { log.Fatal(err) } } else { @@ -123,5 +123,9 @@ func Init(flagConfigFile string) { log.Fatal(err) } f.Close() + + if Keys.Clusters == nil || len(Keys.Clusters) < 1 { + log.Fatal("At least one cluster required in config!") + } } } diff --git a/pkg/archive/fsBackend.go b/pkg/archive/fsBackend.go index a420991..8ff9f31 100644 --- a/pkg/archive/fsBackend.go +++ b/pkg/archive/fsBackend.go @@ -20,7 +20,7 @@ import ( ) type FsArchiveConfig struct { - Path string `json:"filePath"` + Path string `json:"path"` } type FsArchive struct { diff --git a/test/api_test.go b/test/api_test.go index ec6dfbd..ed1304d 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -28,11 +28,17 @@ import ( func setup(t *testing.T) *api.RestApi { const testconfig = `{ - "addr": "0.0.0.0:80", + "addr": "0.0.0.0:8080", "archive": { "kind": "file", "path": "./var/job-archive" + }, + "clusters": [ + { + "name": "testcluster", + "metricDataRepository": {"kind": "test"} } + ] }` const testclusterJson = `{ "name": "testcluster", @@ -109,12 +115,11 @@ func setup(t *testing.T) *api.RestApi { config.Init(cfgFilePath) archiveCfg := fmt.Sprintf("{\"kind\":\"file\",\"path\":\"%s\"}", jobarchive) - config.Keys.Archive = []byte(archiveCfg) repository.Connect("sqlite3", dbfilepath) db := repository.GetConnection() - if err := archive.Init(config.Keys.Archive); err != nil { + if err := archive.Init(json.RawMessage(archiveCfg)); err != nil { t.Fatal(err) }