mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-25 12:59:06 +01:00
Add version to job archive
This commit is contained in:
parent
ff8f013b56
commit
8447d011ad
@ -8,12 +8,15 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Version = 1
|
||||||
|
|
||||||
type ArchiveBackend interface {
|
type ArchiveBackend interface {
|
||||||
Init(rawConfig json.RawMessage) error
|
Init(rawConfig json.RawMessage) (int, error)
|
||||||
|
|
||||||
LoadJobMeta(job *schema.Job) (*schema.JobMeta, error)
|
LoadJobMeta(job *schema.Job) (*schema.JobMeta, error)
|
||||||
|
|
||||||
@ -50,9 +53,11 @@ func Init(rawConfig json.RawMessage) error {
|
|||||||
return fmt.Errorf("unkown archive backend '%s''", kind.Kind)
|
return fmt.Errorf("unkown archive backend '%s''", kind.Kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ar.Init(rawConfig); err != nil {
|
version, err := ar.Init(rawConfig)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Infof("Load archive version %d", version)
|
||||||
return initClusterConfig()
|
return initClusterConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,31 +61,47 @@ func loadJobMeta(filename string) (*schema.JobMeta, error) {
|
|||||||
return DecodeJobMeta(bufio.NewReader(f))
|
return DecodeJobMeta(bufio.NewReader(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fsa *FsArchive) Init(rawConfig json.RawMessage) error {
|
func (fsa *FsArchive) Init(rawConfig json.RawMessage) (int, error) {
|
||||||
|
|
||||||
var config FsArchiveConfig
|
var config FsArchiveConfig
|
||||||
if err := json.Unmarshal(rawConfig, &config); err != nil {
|
if err := json.Unmarshal(rawConfig, &config); err != nil {
|
||||||
log.Errorf("fsBackend Init()- %v", err)
|
log.Errorf("fsBackend Init()- %v", err)
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
if config.Path == "" {
|
if config.Path == "" {
|
||||||
err := fmt.Errorf("fsBackend Init()- empty path")
|
err := fmt.Errorf("fsBackend Init()- empty path")
|
||||||
log.Errorf("fsBackend Init()- %v", err)
|
log.Errorf("fsBackend Init()- %v", err)
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
fsa.path = config.Path
|
fsa.path = config.Path
|
||||||
|
|
||||||
|
b, err := os.ReadFile(fmt.Sprintf("%s/version.txt", fsa.path))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Err")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
version, err := strconv.Atoi(string(b))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("fsBackend Init()- %v", err)
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if version != Version {
|
||||||
|
return version, fmt.Errorf("Unsupported version %d, need %d", version, Version)
|
||||||
|
}
|
||||||
|
|
||||||
entries, err := os.ReadDir(fsa.path)
|
entries, err := os.ReadDir(fsa.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("fsBackend Init()- %v", err)
|
log.Errorf("fsBackend Init()- %v", err)
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, de := range entries {
|
for _, de := range entries {
|
||||||
fsa.clusters = append(fsa.clusters, de.Name())
|
fsa.clusters = append(fsa.clusters, de.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fsa *FsArchive) LoadJobData(job *schema.Job) (schema.JobData, error) {
|
func (fsa *FsArchive) LoadJobData(job *schema.Job) (schema.JobData, error) {
|
||||||
|
@ -7,6 +7,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -17,6 +18,8 @@ import (
|
|||||||
"github.com/ClusterCockpit/cc-backend/pkg/units"
|
"github.com/ClusterCockpit/cc-backend/pkg/units"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Version = 1
|
||||||
|
|
||||||
var ar FsArchive
|
var ar FsArchive
|
||||||
|
|
||||||
func loadJobData(filename string) (*JobData, error) {
|
func loadJobData(filename string) (*JobData, error) {
|
||||||
@ -169,6 +172,10 @@ func main() {
|
|||||||
flag.StringVar(&srcPath, "s", "./var/job-archive", "Specify the source job archive path. Default is ./var/job-archive")
|
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.StringVar(&dstPath, "d", "./var/job-archive-new", "Specify the destination job archive path. Default is ./var/job-archive-new")
|
||||||
|
|
||||||
|
if _, err := os.Stat(fmt.Sprintf("%s/version.txt", srcPath)); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
log.Fatal("Archive version exists!")
|
||||||
|
}
|
||||||
|
|
||||||
srcConfig := fmt.Sprintf("{\"path\": \"%s\"}", srcPath)
|
srcConfig := fmt.Sprintf("{\"path\": \"%s\"}", srcPath)
|
||||||
err := ar.Init(json.RawMessage(srcConfig))
|
err := ar.Init(json.RawMessage(srcConfig))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -248,4 +255,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.WriteFile(fmt.Sprintf("%s/version.txt", dstPath), []byte(fmt.Sprintf("%d", Version)), 0644)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user