Move wisski instance code to separate package

This commit is contained in:
Tom Wiesing 2022-10-17 14:20:15 +02:00
parent 7c3c84e116
commit 063f3f9b7d
No known key found for this signature in database
67 changed files with 533 additions and 409 deletions

View file

@ -7,7 +7,7 @@ import (
"time"
"github.com/FAU-CDI/wisski-distillery/internal/component"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
@ -131,13 +131,13 @@ func (backup *Backup) run(ios stream.IOStream, manager *Manager) {
}
// make a backup of the snapshots
backup.InstanceSnapshots = status.Group[instances.WissKI, Snapshot]{
PrefixString: func(item instances.WissKI, index int) string {
backup.InstanceSnapshots = status.Group[*wisski.WissKI, Snapshot]{
PrefixString: func(item *wisski.WissKI, index int) string {
return fmt.Sprintf("[snapshot %q]: ", item.Slug)
},
PrefixAlign: true,
Handler: func(instance instances.WissKI, index int, writer io.Writer) Snapshot {
Handler: func(instance *wisski.WissKI, index int, writer io.Writer) Snapshot {
dir := filepath.Join(instancesBackupDir, instance.Slug)
if err := manager.Environment.Mkdir(dir, environment.DefaultDirPerm); err != nil {
return Snapshot{
@ -151,10 +151,10 @@ func (backup *Backup) run(ios stream.IOStream, manager *Manager) {
Dest: dir,
})
},
ResultString: func(res Snapshot, item instances.WissKI, index int) string {
ResultString: func(res Snapshot, item *wisski.WissKI, index int) string {
return "done"
},
WaitString: status.DefaultWaitString[instances.WissKI],
WaitString: status.DefaultWaitString[*wisski.WissKI],
HandlerLimit: backup.Description.ConcurrentSnapshots,
}.Use(st, wissKIs)

View file

@ -4,8 +4,8 @@ import (
"io"
"path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/targz"
@ -26,7 +26,7 @@ type ExportTask struct {
// Instance is the instance to generate a snapshot of.
// To generate a backup, leave this to be nil.
Instance *instances.WissKI
Instance *wisski.WissKI
// BackupDescriptions and SnapshotDescriptions further specitfy options for the export.
// The Dest parameter is ignored, and updated automatically.
@ -99,7 +99,7 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err
sl = &backup
} else {
task.SnapshotDescription.Dest = stagingDir
snapshot := manager.NewSnapshot(*task.Instance, io, task.SnapshotDescription)
snapshot := manager.NewSnapshot(task.Instance, io, task.SnapshotDescription)
sl = &snapshot
}
@ -131,7 +131,7 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err
// write out the log entry
entry.Path = stagingDir
entry.Packed = false
manager.Instances.AddToExportLog(entry)
manager.SnapshotsLog.Add(entry)
io.Printf("Wrote %s\n", stagingDir)
return nil
@ -159,7 +159,7 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err
logging.LogMessage(io, "Writing Log Entry")
entry.Path = archivePath
entry.Packed = true
manager.Instances.AddToExportLog(entry)
manager.SnapshotsLog.Add(entry)
// and we're done!
return nil

View file

@ -7,6 +7,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/component"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/component/snapshotslog"
"github.com/FAU-CDI/wisski-distillery/internal/component/sql"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
@ -17,8 +18,9 @@ import (
type Manager struct {
component.ComponentBase
SQL *sql.SQL
Instances *instances.Instances
SQL *sql.SQL
Instances *instances.Instances
SnapshotsLog *snapshotslog.SnapshotsLog
Snapshotable []component.Snapshotable
Backupable []component.Backupable

View file

@ -50,6 +50,6 @@ func (manager *Manager) PruneExports(io stream.IOStream) error {
}
// prune the snapshot log!
_, err = manager.Instances.ExportLog()
_, err = manager.SnapshotsLog.Log()
return err
}

View file

@ -7,8 +7,8 @@ import (
"time"
"github.com/FAU-CDI/wisski-distillery/internal/component"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/goprogram/lib/collection"
"github.com/tkw1536/goprogram/status"
@ -43,7 +43,7 @@ type Snapshot struct {
}
// Snapshot creates a new snapshot of this instance into dest
func (snapshots *Manager) NewSnapshot(instance instances.WissKI, io stream.IOStream, desc SnapshotDescription) (snapshot Snapshot) {
func (snapshots *Manager) NewSnapshot(instance *wisski.WissKI, io stream.IOStream, desc SnapshotDescription) (snapshot Snapshot) {
logging.LogMessage(io, "Locking instance")
if err := instance.TryLock(); err != nil {
@ -83,7 +83,7 @@ func (snapshots *Manager) NewSnapshot(instance instances.WissKI, io stream.IOStr
return
}
func (snapshot *Snapshot) makeParts(ios stream.IOStream, snapshots *Manager, instance instances.WissKI, needsRunning bool) map[string]error {
func (snapshot *Snapshot) makeParts(ios stream.IOStream, snapshots *Manager, instance *wisski.WissKI, needsRunning bool) map[string]error {
if !needsRunning && !snapshot.Description.Keepalive {
stack := instance.Barrel()