From 42cbf217cd0dd758cb51e9e88cd1ef088352324a Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Tue, 6 Sep 2022 08:57:38 +0200 Subject: [PATCH] Remove dependency on config package --- pkg/archive/archive.go | 35 +++++++++++++++++------------------ pkg/archive/clusterConfig.go | 5 ++--- pkg/archive/fsBackend.go | 18 ++++++++++++++++-- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index 0518927..78ade6f 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" - "github.com/ClusterCockpit/cc-backend/internal/config" "github.com/ClusterCockpit/cc-backend/internal/graph/model" "github.com/ClusterCockpit/cc-backend/pkg/schema" ) @@ -28,32 +27,32 @@ type ArchiveBackend interface { Import(jobMeta *schema.JobMeta, jobData *schema.JobData) error + GetClusters() []string + Iter() <-chan *schema.JobMeta } var ar ArchiveBackend -func Init() error { - if config.Keys.Archive != nil { - var kind struct { - Kind string `json:"kind"` - } - if err := json.Unmarshal(config.Keys.Archive, &kind); err != nil { - return err - } +func Init(rawConfig json.RawMessage) error { + var kind struct { + Kind string `json:"kind"` + } + if err := json.Unmarshal(rawConfig, &kind); err != nil { + return err + } - switch kind.Kind { - case "file": - ar = &FsArchive{} + switch kind.Kind { + case "file": + ar = &FsArchive{} // case "s3": // ar = &S3Archive{} - default: - return fmt.Errorf("unkown archive backend '%s''", kind.Kind) - } + default: + return fmt.Errorf("unkown archive backend '%s''", kind.Kind) + } - if err := ar.Init(config.Keys.Archive); err != nil { - return err - } + if err := ar.Init(rawConfig); err != nil { + return err } return initClusterConfig() } diff --git a/pkg/archive/clusterConfig.go b/pkg/archive/clusterConfig.go index 9d29a67..98d8680 100644 --- a/pkg/archive/clusterConfig.go +++ b/pkg/archive/clusterConfig.go @@ -9,7 +9,6 @@ import ( "fmt" "time" - "github.com/ClusterCockpit/cc-backend/internal/config" "github.com/ClusterCockpit/cc-backend/internal/graph/model" "github.com/ClusterCockpit/cc-backend/pkg/lrucache" "github.com/ClusterCockpit/cc-backend/pkg/schema" @@ -24,9 +23,9 @@ func initClusterConfig() error { Clusters = []*model.Cluster{} nodeLists = map[string]map[string]NodeList{} - for _, c := range config.Keys.Clusters { + for _, c := range ar.GetClusters() { - cluster, err := ar.LoadClusterCfg(c.Name) + cluster, err := ar.LoadClusterCfg(c) if err != nil { return err } diff --git a/pkg/archive/fsBackend.go b/pkg/archive/fsBackend.go index d73ea40..f23221a 100644 --- a/pkg/archive/fsBackend.go +++ b/pkg/archive/fsBackend.go @@ -24,7 +24,8 @@ type FsArchiveConfig struct { } type FsArchive struct { - path string + path string + clusters []string } // For a given job, return the path of the `data.json`/`meta.json` file. @@ -54,8 +55,17 @@ func (fsa *FsArchive) Init(rawConfig json.RawMessage) error { if err := json.Unmarshal(rawConfig, &config); err != nil { return err } - fsa.path = config.Path + + entries, err := os.ReadDir(fsa.path) + if err != nil { + return err + } + + for _, de := range entries { + fsa.clusters = append(fsa.clusters, de.Name()) + } + return nil } @@ -166,6 +176,10 @@ func (fsa *FsArchive) StoreMeta(jobMeta *schema.JobMeta) error { return nil } +func (fsa *FsArchive) GetClusters() []string { + return fsa.clusters +} + func (fsa *FsArchive) Import(jobMeta *schema.JobMeta, jobData *schema.JobData) error { job := schema.Job{