diff --git a/.gitignore b/.gitignore index 5e1346e..153e354 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ /web/frontend/public/build /web/frontend/node_modules -.vscode/settings.json +/.vscode/* /archive-migration -.vscode/launch.json +/archive-manager diff --git a/pkg/archive/fsBackend.go b/pkg/archive/fsBackend.go index 9668e5d..1bfa081 100644 --- a/pkg/archive/fsBackend.go +++ b/pkg/archive/fsBackend.go @@ -52,14 +52,18 @@ func getPath( func loadJobMeta(filename string) (*schema.JobMeta, error) { - f, err := os.Open(filename) + b, err := os.ReadFile(filename) if err != nil { log.Errorf("fsBackend loadJobMeta()- %v", err) return &schema.JobMeta{}, err } - defer f.Close() + if config.Keys.Validate { + if err := schema.Validate(schema.Meta, bytes.NewReader(b)); err != nil { + return &schema.JobMeta{}, fmt.Errorf("validate cluster config: %v", err) + } + } - return DecodeJobMeta(bufio.NewReader(f)) + return DecodeJobMeta(bytes.NewReader(b)) } func (fsa *FsArchive) Init(rawConfig json.RawMessage) (int, error) { diff --git a/tools/archive-manager/main.go b/tools/archive-manager/main.go index 3d0f513..9b58918 100644 --- a/tools/archive-manager/main.go +++ b/tools/archive-manager/main.go @@ -4,6 +4,32 @@ // license that can be found in the LICENSE file. package main -func main() { +import ( + "encoding/json" + "flag" + "fmt" + "log" + "github.com/ClusterCockpit/cc-backend/internal/config" + "github.com/ClusterCockpit/cc-backend/pkg/archive" +) + +func main() { + var srcPath, flagConfigFile string + + flag.StringVar(&srcPath, "s", "./var/job-archive", "Specify the source job archive path. Default is ./var/job-archive") + flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`") + flag.Parse() + archiveCfg := fmt.Sprintf("{\"kind\": \"file\",\"path\": \"%s\"}", srcPath) + + config.Init(flagConfigFile) + + if err := archive.Init(json.RawMessage(archiveCfg)); err != nil { + log.Fatal(err) + } + ar := archive.GetHandle() + + for jobMeta := range ar.Iter() { + fmt.Printf("Validate %s - %d\n", jobMeta.Cluster, jobMeta.JobID) + } } diff --git a/tools/archive-migration/main.go b/tools/archive-migration/main.go index e644407..a1dd58d 100644 --- a/tools/archive-migration/main.go +++ b/tools/archive-migration/main.go @@ -180,6 +180,7 @@ func main() { flag.StringVar(&srcPath, "s", "./var/job-archive", "Specify the source job archive path. Default is ./var/job-archive") flag.StringVar(&dstPath, "d", "./var/job-archive-new", "Specify the destination job archive path. Default is ./var/job-archive-new") + flag.Parse() if _, err := os.Stat(filepath.Join(srcPath, "version.txt")); !errors.Is(err, os.ErrNotExist) { log.Fatal("Archive version exists!")