Remove dependency on config package

This commit is contained in:
Jan Eitzinger 2022-09-06 08:57:38 +02:00
parent 98d62f739f
commit 42cbf217cd
3 changed files with 35 additions and 23 deletions

View File

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/ClusterCockpit/cc-backend/internal/config"
"github.com/ClusterCockpit/cc-backend/internal/graph/model" "github.com/ClusterCockpit/cc-backend/internal/graph/model"
"github.com/ClusterCockpit/cc-backend/pkg/schema" "github.com/ClusterCockpit/cc-backend/pkg/schema"
) )
@ -28,32 +27,32 @@ type ArchiveBackend interface {
Import(jobMeta *schema.JobMeta, jobData *schema.JobData) error Import(jobMeta *schema.JobMeta, jobData *schema.JobData) error
GetClusters() []string
Iter() <-chan *schema.JobMeta Iter() <-chan *schema.JobMeta
} }
var ar ArchiveBackend var ar ArchiveBackend
func Init() error { func Init(rawConfig json.RawMessage) error {
if config.Keys.Archive != nil { var kind struct {
var kind struct { Kind string `json:"kind"`
Kind string `json:"kind"` }
} if err := json.Unmarshal(rawConfig, &kind); err != nil {
if err := json.Unmarshal(config.Keys.Archive, &kind); err != nil { return err
return err }
}
switch kind.Kind { switch kind.Kind {
case "file": case "file":
ar = &FsArchive{} ar = &FsArchive{}
// case "s3": // case "s3":
// ar = &S3Archive{} // ar = &S3Archive{}
default: default:
return fmt.Errorf("unkown archive backend '%s''", kind.Kind) return fmt.Errorf("unkown archive backend '%s''", kind.Kind)
} }
if err := ar.Init(config.Keys.Archive); err != nil { if err := ar.Init(rawConfig); err != nil {
return err return err
}
} }
return initClusterConfig() return initClusterConfig()
} }

View File

@ -9,7 +9,6 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/ClusterCockpit/cc-backend/internal/config"
"github.com/ClusterCockpit/cc-backend/internal/graph/model" "github.com/ClusterCockpit/cc-backend/internal/graph/model"
"github.com/ClusterCockpit/cc-backend/pkg/lrucache" "github.com/ClusterCockpit/cc-backend/pkg/lrucache"
"github.com/ClusterCockpit/cc-backend/pkg/schema" "github.com/ClusterCockpit/cc-backend/pkg/schema"
@ -24,9 +23,9 @@ func initClusterConfig() error {
Clusters = []*model.Cluster{} Clusters = []*model.Cluster{}
nodeLists = map[string]map[string]NodeList{} 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 { if err != nil {
return err return err
} }

View File

@ -24,7 +24,8 @@ type FsArchiveConfig struct {
} }
type FsArchive struct { type FsArchive struct {
path string path string
clusters []string
} }
// For a given job, return the path of the `data.json`/`meta.json` file. // 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 { if err := json.Unmarshal(rawConfig, &config); err != nil {
return err return err
} }
fsa.path = config.Path 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 return nil
} }
@ -166,6 +176,10 @@ func (fsa *FsArchive) StoreMeta(jobMeta *schema.JobMeta) error {
return nil return nil
} }
func (fsa *FsArchive) GetClusters() []string {
return fsa.clusters
}
func (fsa *FsArchive) Import(jobMeta *schema.JobMeta, jobData *schema.JobData) error { func (fsa *FsArchive) Import(jobMeta *schema.JobMeta, jobData *schema.JobData) error {
job := schema.Job{ job := schema.Job{