mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-12-16 12:16:16 +01:00
Also import ClusterConfigs
This commit is contained in:
Binary file not shown.
@@ -79,6 +79,18 @@ func TestImportFileToSqlite(t *testing.T) {
|
|||||||
if srcCount != dstCount {
|
if srcCount != dstCount {
|
||||||
t.Errorf("Job count mismatch: source has %d jobs, destination has %d jobs", srcCount, dstCount)
|
t.Errorf("Job count mismatch: source has %d jobs, destination has %d jobs", srcCount, dstCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify cluster config
|
||||||
|
clusters := srcBackend.GetClusters()
|
||||||
|
for _, cluster := range clusters {
|
||||||
|
cfg, err := dstBackend.LoadClusterCfg(cluster)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to load cluster config for %s from destination: %v", cluster, err)
|
||||||
|
}
|
||||||
|
if cfg.Name != cluster {
|
||||||
|
t.Errorf("Cluster name mismatch: expected %s, got %s", cluster, cfg.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestImportFileToFile tests importing jobs from one file backend to another
|
// TestImportFileToFile tests importing jobs from one file backend to another
|
||||||
@@ -339,3 +351,49 @@ func TestJobStub(t *testing.T) {
|
|||||||
t.Errorf("Expected JobID 123, got %d", job.JobID)
|
t.Errorf("Expected JobID 123, got %d", job.JobID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestImportToEmptyFileDestination tests importing to an empty file backend (bootstrapping version)
|
||||||
|
func TestImportToEmptyFileDestination(t *testing.T) {
|
||||||
|
tmpdir := t.TempDir()
|
||||||
|
srcArchive := filepath.Join(tmpdir, "src-archive")
|
||||||
|
dstArchive := filepath.Join(tmpdir, "dst-archive-empty")
|
||||||
|
|
||||||
|
// Setup valid source
|
||||||
|
testDataPath := "../../pkg/archive/testdata/archive"
|
||||||
|
if _, err := os.Stat(testDataPath); os.IsNotExist(err) {
|
||||||
|
t.Skip("Test data not found")
|
||||||
|
}
|
||||||
|
util.CopyDir(testDataPath, srcArchive)
|
||||||
|
|
||||||
|
// Setup empty destination directory
|
||||||
|
os.MkdirAll(dstArchive, 0755)
|
||||||
|
// NOTE: NOT writing version.txt here!
|
||||||
|
|
||||||
|
// Initialize source
|
||||||
|
srcConfig := fmt.Sprintf(`{"kind":"file","path":"%s"}`, srcArchive)
|
||||||
|
srcBackend, err := archive.InitBackend(json.RawMessage(srcConfig))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to init source: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize destination (should succeed with changes, currently fails)
|
||||||
|
dstConfig := fmt.Sprintf(`{"kind":"file","path":"%s"}`, dstArchive)
|
||||||
|
dstBackend, err := archive.InitBackend(json.RawMessage(dstConfig))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to init destination (should bootstrap): %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform import
|
||||||
|
imported, _, err := importArchive(srcBackend, dstBackend)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Import failed: %v", err)
|
||||||
|
}
|
||||||
|
if imported == 0 {
|
||||||
|
t.Error("No jobs imported")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if version.txt was created
|
||||||
|
if _, err := os.Stat(filepath.Join(dstArchive, "version.txt")); os.IsNotExist(err) {
|
||||||
|
t.Error("version.txt was not created in destination")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func importArchive(srcBackend, dstBackend archive.ArchiveBackend) (int, int, err
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
// Start worker goroutines
|
// Start worker goroutines
|
||||||
for i := 0; i < numWorkers; i++ {
|
for i := range numWorkers {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(workerID int) {
|
go func(workerID int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
@@ -104,6 +104,22 @@ func importArchive(srcBackend, dstBackend archive.ArchiveBackend) (int, int, err
|
|||||||
|
|
||||||
// Feed jobs to workers
|
// Feed jobs to workers
|
||||||
go func() {
|
go func() {
|
||||||
|
// Import cluster configs first
|
||||||
|
clusters := srcBackend.GetClusters()
|
||||||
|
for _, clusterName := range clusters {
|
||||||
|
clusterCfg, err := srcBackend.LoadClusterCfg(clusterName)
|
||||||
|
if err != nil {
|
||||||
|
cclog.Errorf("Failed to load cluster config for %s: %v", clusterName, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := dstBackend.StoreClusterCfg(clusterName, clusterCfg); err != nil {
|
||||||
|
cclog.Errorf("Failed to store cluster config for %s: %v", clusterName, err)
|
||||||
|
} else {
|
||||||
|
cclog.Infof("Imported cluster config for %s", clusterName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for job := range srcBackend.Iter(true) {
|
for job := range srcBackend.Iter(true) {
|
||||||
jobs <- job
|
jobs <- job
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user