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"
"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()
}

View File

@ -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
}

View File

@ -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{