diff --git a/cmd/backup.go b/cmd/backup.go index 1df64cd..72b295f 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -2,7 +2,7 @@ package cmd import ( wisski_distillery "github.com/FAU-CDI/wisski-distillery" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshots" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter" "github.com/FAU-CDI/wisski-distillery/internal/core" "github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/tkw1536/goprogram/exit" @@ -41,18 +41,18 @@ func (bk backup) Run(context wisski_distillery.Context) error { // prune old backups if !bk.NoPrune { defer logging.LogOperation(func() error { - return dis.ExportManager().PruneExports(context.IOStream) + return dis.Exporter().PruneExports(context.IOStream) }, context.IOStream, "Pruning old backups") } // do the handling - err := dis.ExportManager().MakeExport(context.IOStream, snapshots.ExportTask{ + err := dis.Exporter().MakeExport(context.IOStream, exporter.ExportTask{ Dest: bk.Positionals.Dest, StagingOnly: bk.StagingOnly, Instance: nil, - BackupDescription: snapshots.BackupDescription{ + BackupDescription: exporter.BackupDescription{ ConcurrentSnapshots: bk.ConcurrentSnapshots, }, }) diff --git a/cmd/snapshot.go b/cmd/snapshot.go index 256556b..3116d1e 100644 --- a/cmd/snapshot.go +++ b/cmd/snapshot.go @@ -2,7 +2,7 @@ package cmd import ( wisski_distillery "github.com/FAU-CDI/wisski-distillery" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshots" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter" "github.com/FAU-CDI/wisski-distillery/internal/core" "github.com/tkw1536/goprogram/exit" ) @@ -45,7 +45,7 @@ func (sn snapshot) Run(context wisski_distillery.Context) error { } // do a snapshot of it! - err = dis.ExportManager().MakeExport(context.IOStream, snapshots.ExportTask{ + err = dis.Exporter().MakeExport(context.IOStream, exporter.ExportTask{ Dest: sn.Positionals.Dest, StagingOnly: sn.StagingOnly, diff --git a/cmd/system_update.go b/cmd/system_update.go index 7beab85..0239d84 100644 --- a/cmd/system_update.go +++ b/cmd/system_update.go @@ -70,8 +70,8 @@ func (si systemupdate) Run(context wisski_distillery.Context) error { for _, d := range []string{ dis.Config.DeployRoot, dis.Instances().Path(), - dis.ExportManager().StagingPath(), - dis.ExportManager().ArchivePath(), + dis.Exporter().StagingPath(), + dis.Exporter().ArchivePath(), } { context.Println(d) if err := dis.Core.Environment.MkdirAll(d, environment.DefaultDirPerm); err != nil { diff --git a/internal/component/snapshots/backup.go b/internal/component/exporter/backup.go similarity index 86% rename from internal/component/snapshots/backup.go rename to internal/component/exporter/backup.go index b94f97b..41ccd71 100644 --- a/internal/component/snapshots/backup.go +++ b/internal/component/exporter/backup.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "fmt" @@ -49,7 +49,7 @@ type BackupDescription struct { } // New create a new Backup -func (manager *Manager) NewBackup(io stream.IOStream, description BackupDescription) (backup Backup) { +func (exporter *Exporter) NewBackup(io stream.IOStream, description BackupDescription) (backup Backup) { backup.Description = description // catch anything critical that happened during the snapshot @@ -60,7 +60,7 @@ func (manager *Manager) NewBackup(io stream.IOStream, description BackupDescript // do the create keeping track of time! logging.LogOperation(func() error { backup.StartTime = time.Now().UTC() - backup.run(io, manager) + backup.run(io, exporter) backup.EndTime = time.Now().UTC() return nil @@ -69,13 +69,13 @@ func (manager *Manager) NewBackup(io stream.IOStream, description BackupDescript return } -func (backup *Backup) run(ios stream.IOStream, manager *Manager) { +func (backup *Backup) run(ios stream.IOStream, exporter *Exporter) { // create a manifest manifest, done := backup.handleManifest(backup.Description.Dest) defer done() // create a new status display - backups := manager.Backupable + backups := exporter.Backupable backup.ComponentErrors = make(map[string]error, len(backups)) // Component backup tasks @@ -93,7 +93,7 @@ func (backup *Backup) run(ios stream.IOStream, manager *Manager) { Handler: func(bc component.Backupable, index int, writer io.Writer) error { return bc.Backup( component.NewStagingContext( - manager.Environment, + exporter.Environment, stream.NewIOStream(writer, writer, nil, 0), filepath.Join(backup.Description.Dest, bc.BackupName()), manifest, @@ -118,13 +118,13 @@ func (backup *Backup) run(ios stream.IOStream, manager *Manager) { defer st.Stop() instancesBackupDir := filepath.Join(backup.Description.Dest, "instances") - if err := manager.Environment.Mkdir(instancesBackupDir, environment.DefaultDirPerm); err != nil { + if err := exporter.Environment.Mkdir(instancesBackupDir, environment.DefaultDirPerm); err != nil { backup.InstanceListErr = err return nil } // list all instances - wissKIs, err := manager.Instances.All() + wissKIs, err := exporter.Instances.All() if err != nil { backup.InstanceListErr = err return nil @@ -139,7 +139,7 @@ func (backup *Backup) run(ios stream.IOStream, manager *Manager) { 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 { + if err := exporter.Environment.Mkdir(dir, environment.DefaultDirPerm); err != nil { return Snapshot{ ErrPanic: err, } @@ -147,7 +147,7 @@ func (backup *Backup) run(ios stream.IOStream, manager *Manager) { manifest <- dir - return manager.NewSnapshot(instance, stream.NewIOStream(writer, writer, nil, 0), SnapshotDescription{ + return exporter.NewSnapshot(instance, stream.NewIOStream(writer, writer, nil, 0), SnapshotDescription{ Dest: dir, }) }, diff --git a/internal/component/snapshots/manager.go b/internal/component/exporter/exporter.go similarity index 77% rename from internal/component/snapshots/manager.go rename to internal/component/exporter/exporter.go index 8a44140..547fe4a 100644 --- a/internal/component/snapshots/manager.go +++ b/internal/component/exporter/exporter.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "fmt" @@ -6,48 +6,49 @@ import ( "time" "github.com/FAU-CDI/wisski-distillery/internal/component" + + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter/logger" "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" "github.com/FAU-CDI/wisski-distillery/pkg/password" ) -// Manager manages snapshots and backups -type Manager struct { +// Exporter manages snapshots and backups +type Exporter struct { component.ComponentBase - SQL *sql.SQL - Instances *instances.Instances - SnapshotsLog *snapshotslog.SnapshotsLog + SQL *sql.SQL + Instances *instances.Instances + ExporterLogger *logger.Logger Snapshotable []component.Snapshotable Backupable []component.Backupable } -func (Manager) Name() string { return "snapshots" } +func (Exporter) Name() string { return "snapshots" } // Path returns the path that contains all snapshot related data. -func (dis *Manager) Path() string { +func (dis *Exporter) Path() string { return filepath.Join(dis.Config.DeployRoot, "snapshots") } // StagingPath returns the path to the directory containing a temporary staging area for snapshots. // Use NewSnapshotStagingDir to generate a new staging area. -func (dis *Manager) StagingPath() string { +func (dis *Exporter) StagingPath() string { return filepath.Join(dis.Path(), "staging") } // ArchivePath returns the path to the directory containing all exported archives. // Use NewSnapshotArchivePath to generate a path to a new archive in this directory. -func (dis *Manager) ArchivePath() string { +func (dis *Exporter) ArchivePath() string { return filepath.Join(dis.Path(), "archives") } // NewArchivePath returns the path to a new archive with the provided prefix. // The path is guaranteed to not exist. -func (dis *Manager) NewArchivePath(prefix string) (path string) { +func (dis *Exporter) NewArchivePath(prefix string) (path string) { // TODO: Consider moving these into a subdirectory with the provided prefix. for path == "" || fsx.Exists(dis.Environment, path) { name := dis.newSnapshotName(prefix) + ".tar.gz" @@ -58,7 +59,7 @@ func (dis *Manager) NewArchivePath(prefix string) (path string) { // newSnapshot name returns a new basename for a snapshot with the provided prefix. // The name is guaranteed to be unique within this process. -func (*Manager) newSnapshotName(prefix string) string { +func (*Exporter) newSnapshotName(prefix string) string { suffix, _ := password.Password(10) // silently ignore any errors! if prefix == "" { prefix = "backup" @@ -70,7 +71,7 @@ func (*Manager) newSnapshotName(prefix string) string { // NewStagingDir returns the path to a new snapshot directory. // The directory is guaranteed to have been freshly created. -func (dis *Manager) NewStagingDir(prefix string) (path string, err error) { +func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) { for path == "" || environment.IsExist(err) { path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix)) err = dis.Core.Environment.Mkdir(path, environment.DefaultFilePerm) diff --git a/internal/component/snapshots/extras_bookkeeping.go b/internal/component/exporter/extras_bookkeeping.go similarity index 97% rename from internal/component/snapshots/extras_bookkeeping.go rename to internal/component/exporter/extras_bookkeeping.go index fcf79fe..16bebc5 100644 --- a/internal/component/snapshots/extras_bookkeeping.go +++ b/internal/component/exporter/extras_bookkeeping.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "fmt" diff --git a/internal/component/snapshots/extras_config.go b/internal/component/exporter/extras_config.go similarity index 98% rename from internal/component/snapshots/extras_config.go rename to internal/component/exporter/extras_config.go index 138e6d1..cde4791 100644 --- a/internal/component/snapshots/extras_config.go +++ b/internal/component/exporter/extras_config.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "path/filepath" diff --git a/internal/component/snapshots/extras_filesystem.go b/internal/component/exporter/extras_filesystem.go similarity index 97% rename from internal/component/snapshots/extras_filesystem.go rename to internal/component/exporter/extras_filesystem.go index d348d67..4812641 100644 --- a/internal/component/snapshots/extras_filesystem.go +++ b/internal/component/exporter/extras_filesystem.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "github.com/FAU-CDI/wisski-distillery/internal/component" diff --git a/internal/component/snapshots/extras_pathbuilders.go b/internal/component/exporter/extras_pathbuilders.go similarity index 98% rename from internal/component/snapshots/extras_pathbuilders.go rename to internal/component/exporter/extras_pathbuilders.go index 86efb1e..0a7862f 100644 --- a/internal/component/snapshots/extras_pathbuilders.go +++ b/internal/component/exporter/extras_pathbuilders.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "io" diff --git a/internal/component/snapshots/iface.go b/internal/component/exporter/iface.go similarity index 83% rename from internal/component/snapshots/iface.go rename to internal/component/exporter/iface.go index 52ef9a6..37fa4c6 100644 --- a/internal/component/snapshots/iface.go +++ b/internal/component/exporter/iface.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "io" @@ -14,7 +14,7 @@ import ( ) // ExportTask describes a task that makes either a [Backup] or a [Snapshot]. -// See [Manager.MakeExport] +// See [Exporter.MakeExport] type ExportTask struct { // Dest is the destination path to write the backup to. // When empty, this is created automatically in the staging or archive directory. @@ -42,7 +42,7 @@ type export interface { // MakeExport performs an export task as described by flags. // Output is directed to the provided io. -func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err error) { +func (exporter *Exporter) MakeExport(io stream.IOStream, task ExportTask) (err error) { // extract parameters Title := "Backup" Slug := "" @@ -60,20 +60,20 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err archivePath = task.Dest } if stagingDir == "" { - stagingDir, err = manager.NewStagingDir(Slug) + stagingDir, err = exporter.NewStagingDir(Slug) if err != nil { return err } } if !task.StagingOnly && archivePath == "" { - archivePath = manager.NewArchivePath(Slug) + archivePath = exporter.NewArchivePath(Slug) } io.Printf("Staging Directory: %s\n", stagingDir) io.Printf("Archive Path: %s\n", archivePath) // create the staging directory logging.LogMessage(io, "Creating staging directory") - err = manager.Environment.Mkdir(stagingDir, environment.DefaultDirPerm) + err = exporter.Environment.Mkdir(stagingDir, environment.DefaultDirPerm) if !environment.IsExist(err) && err != nil { return err } @@ -83,7 +83,7 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err if !task.StagingOnly { defer func() { logging.LogMessage(io, "Removing staging directory") - manager.Environment.RemoveAll(stagingDir) + exporter.Environment.RemoveAll(stagingDir) }() } @@ -95,11 +95,11 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err var sl export if task.Instance == nil { task.BackupDescription.Dest = stagingDir - backup := manager.NewBackup(io, task.BackupDescription) + backup := exporter.NewBackup(io, task.BackupDescription) sl = &backup } else { task.SnapshotDescription.Dest = stagingDir - snapshot := manager.NewSnapshot(task.Instance, io, task.SnapshotDescription) + snapshot := exporter.NewSnapshot(task.Instance, io, task.SnapshotDescription) sl = &snapshot } @@ -111,7 +111,7 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err io.Println(reportPath) // create the path - report, err := manager.Environment.Create(reportPath, environment.DefaultFilePerm) + report, err := exporter.Environment.Create(reportPath, environment.DefaultFilePerm) if err != nil { return err } @@ -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.SnapshotsLog.Add(entry) + exporter.ExporterLogger.Add(entry) io.Printf("Wrote %s\n", stagingDir) return nil @@ -146,7 +146,7 @@ func (manager *Manager) MakeExport(io stream.IOStream, task ExportTask) (err err st.Start() defer st.Stop() - count, err = targz.Package(manager.Environment, archivePath, stagingDir, func(dst, src string) { + count, err = targz.Package(exporter.Environment, archivePath, stagingDir, func(dst, src string) { st.Set(0, dst) }) @@ -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.SnapshotsLog.Add(entry) + exporter.ExporterLogger.Add(entry) // and we're done! return nil diff --git a/internal/component/snapshots/log.go b/internal/component/exporter/log.go similarity index 94% rename from internal/component/snapshots/log.go rename to internal/component/exporter/log.go index aac8e94..b1f0f9b 100644 --- a/internal/component/snapshots/log.go +++ b/internal/component/exporter/log.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import "github.com/FAU-CDI/wisski-distillery/internal/models" diff --git a/internal/component/snapshotslog/snapshotslog.go b/internal/component/exporter/logger/logger.go similarity index 82% rename from internal/component/snapshotslog/snapshotslog.go rename to internal/component/exporter/logger/logger.go index a01e753..5efa16a 100644 --- a/internal/component/snapshotslog/snapshotslog.go +++ b/internal/component/exporter/logger/logger.go @@ -1,4 +1,4 @@ -package snapshotslog +package logger import ( "github.com/FAU-CDI/wisski-distillery/internal/component" @@ -8,19 +8,19 @@ import ( "github.com/tkw1536/goprogram/lib/collection" ) -// SnapshotsLog is responsible for logging snapshots -type SnapshotsLog struct { +// Logger is responsible for logging backups and snapshots +type Logger struct { component.ComponentBase SQL *sql.SQL } -func (*SnapshotsLog) Name() string { return "snapshots-log" } +func (*Logger) Name() string { return "snapshots-log" } // For retrieves (and prunes) the ExportLog. // Slug determines if entries for Backups (empty slug) // or a specific Instance (non-empty slug) are returned. -func (log *SnapshotsLog) For(slug string) (exports []models.Export, err error) { +func (log *Logger) For(slug string) (exports []models.Export, err error) { exports, err = log.Log() if err != nil { return nil, err @@ -32,7 +32,7 @@ func (log *SnapshotsLog) For(slug string) (exports []models.Export, err error) { } // Log retrieves (and prunes) all entries in the snapshot log. -func (log *SnapshotsLog) Log() ([]models.Export, error) { +func (log *Logger) Log() ([]models.Export, error) { // query the table! table, err := log.SQL.QueryTable(false, models.ExportTable) if err != nil { @@ -64,7 +64,7 @@ func (log *SnapshotsLog) Log() ([]models.Export, error) { } // AddToExportLog adds the provided export to the log. -func (log *SnapshotsLog) Add(export models.Export) error { +func (log *Logger) Add(export models.Export) error { // find the table table, err := log.SQL.QueryTable(false, models.ExportTable) if err != nil { diff --git a/internal/component/snapshots/manifest.go b/internal/component/exporter/manifest.go similarity index 97% rename from internal/component/snapshots/manifest.go rename to internal/component/exporter/manifest.go index 13f0b4c..150c350 100644 --- a/internal/component/snapshots/manifest.go +++ b/internal/component/exporter/manifest.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "path/filepath" diff --git a/internal/component/snapshots/prune.go b/internal/component/exporter/prune.go similarity index 59% rename from internal/component/snapshots/prune.go rename to internal/component/exporter/prune.go index 60abab7..211ca3b 100644 --- a/internal/component/snapshots/prune.go +++ b/internal/component/exporter/prune.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "path/filepath" @@ -9,16 +9,16 @@ import ( // ShouldPrune determines if a file with the provided modification time should be // removed from the export log. -func (manager *Manager) ShouldPrune(modtime time.Time) bool { - return time.Since(modtime) > time.Duration(manager.Config.MaxBackupAge)*24*time.Hour +func (exporter *Exporter) ShouldPrune(modtime time.Time) bool { + return time.Since(modtime) > time.Duration(exporter.Config.MaxBackupAge)*24*time.Hour } // Prune prunes all old exports -func (manager *Manager) PruneExports(io stream.IOStream) error { - sPath := manager.ArchivePath() +func (exporter *Exporter) PruneExports(io stream.IOStream) error { + sPath := exporter.ArchivePath() // list all the files - entries, err := manager.Core.Environment.ReadDir(sPath) + entries, err := exporter.Core.Environment.ReadDir(sPath) if err != nil { return err } @@ -36,20 +36,20 @@ func (manager *Manager) PruneExports(io stream.IOStream) error { } // check if it should be pruned! - if !manager.ShouldPrune(info.ModTime()) { + if !exporter.ShouldPrune(info.ModTime()) { continue } // assemble path, and then remove the file! path := filepath.Join(sPath, entry.Name()) - io.Printf("Removing %s cause it is older than %d days", path, manager.Config.MaxBackupAge) + io.Printf("Removing %s cause it is older than %d days", path, exporter.Config.MaxBackupAge) - if err := manager.Core.Environment.Remove(path); err != nil { + if err := exporter.Core.Environment.Remove(path); err != nil { return err } } // prune the snapshot log! - _, err = manager.SnapshotsLog.Log() + _, err = exporter.ExporterLogger.Log() return err } diff --git a/internal/component/snapshots/report.go b/internal/component/exporter/report.go similarity index 99% rename from internal/component/snapshots/report.go rename to internal/component/exporter/report.go index f48b607..349cfef 100644 --- a/internal/component/snapshots/report.go +++ b/internal/component/exporter/report.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "encoding/json" diff --git a/internal/component/snapshots/snapshot.go b/internal/component/exporter/snapshot.go similarity index 93% rename from internal/component/snapshots/snapshot.go rename to internal/component/exporter/snapshot.go index 39cbc39..c4ae1f0 100644 --- a/internal/component/snapshots/snapshot.go +++ b/internal/component/exporter/snapshot.go @@ -1,4 +1,4 @@ -package snapshots +package exporter import ( "fmt" @@ -43,7 +43,7 @@ type Snapshot struct { } // Snapshot creates a new snapshot of this instance into dest -func (snapshots *Manager) NewSnapshot(instance *wisski.WissKI, io stream.IOStream, desc SnapshotDescription) (snapshot Snapshot) { +func (snapshots *Exporter) 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 *wisski.WissKI, io stream.IOStrea return } -func (snapshot *Snapshot) makeParts(ios stream.IOStream, snapshots *Manager, instance *wisski.WissKI, needsRunning bool) map[string]error { +func (snapshot *Snapshot) makeParts(ios stream.IOStream, snapshots *Exporter, instance *wisski.WissKI, needsRunning bool) map[string]error { if !needsRunning && !snapshot.Description.Keepalive { stack := instance.Barrel() diff --git a/internal/component/info/info.go b/internal/component/info/info.go index 6cac7e6..bd07a0f 100644 --- a/internal/component/info/info.go +++ b/internal/component/info/info.go @@ -5,9 +5,10 @@ import ( "net/http" "github.com/FAU-CDI/wisski-distillery/internal/component" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter/logger" + "github.com/FAU-CDI/wisski-distillery/internal/component/instances" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshots" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshotslog" "github.com/FAU-CDI/wisski-distillery/pkg/httpx" "github.com/tkw1536/goprogram/stream" ) @@ -15,9 +16,9 @@ import ( type Info struct { component.ComponentBase - SnapshotManager *snapshots.Manager - Instances *instances.Instances - SnapshotsLog *snapshotslog.SnapshotsLog + Exporter *exporter.Exporter + Instances *instances.Instances + SnapshotsLog *logger.Logger } func (Info) Name() string { return "control-info" } diff --git a/internal/component/info/socket.go b/internal/component/info/socket.go index a8356f0..aa811a9 100644 --- a/internal/component/info/socket.go +++ b/internal/component/info/socket.go @@ -1,7 +1,7 @@ package info import ( - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshots" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter" "github.com/FAU-CDI/wisski-distillery/internal/wisski" "github.com/FAU-CDI/wisski-distillery/pkg/httpx" "github.com/tkw1536/goprogram/status" @@ -12,9 +12,9 @@ type instanceActionFunc = func(info *Info, instance *wisski.WissKI, str stream.I var socketInstanceActions = map[string]instanceActionFunc{ "snapshot": func(info *Info, instance *wisski.WissKI, str stream.IOStream) error { - return info.SnapshotManager.MakeExport( + return info.Exporter.MakeExport( str, - snapshots.ExportTask{ + exporter.ExportTask{ Dest: "", Instance: instance, diff --git a/internal/component/instances/instances.go b/internal/component/instances/instances.go index d4a6d5a..d058703 100644 --- a/internal/component/instances/instances.go +++ b/internal/component/instances/instances.go @@ -5,8 +5,9 @@ import ( "path/filepath" "github.com/FAU-CDI/wisski-distillery/internal/component" + + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter/logger" "github.com/FAU-CDI/wisski-distillery/internal/component/meta" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshotslog" "github.com/FAU-CDI/wisski-distillery/internal/component/sql" "github.com/FAU-CDI/wisski-distillery/internal/component/triplestore" "github.com/FAU-CDI/wisski-distillery/internal/models" @@ -20,10 +21,10 @@ import ( type Instances struct { component.ComponentBase - TS *triplestore.Triplestore - SQL *sql.SQL - Meta *meta.Meta - SnapshotsLog *snapshotslog.SnapshotsLog + TS *triplestore.Triplestore + SQL *sql.SQL + Meta *meta.Meta + ExporterLog *logger.Logger } func (Instances) Name() string { @@ -48,7 +49,7 @@ func (instances *Instances) use(wisski *wisski.WissKI) { wisski.SQL = instances.SQL wisski.TS = instances.TS wisski.Meta = instances.Meta - wisski.SnapshotsLog = instances.SnapshotsLog + wisski.ExporterLog = instances.ExporterLog } // WissKI returns the WissKI with the provided slug, if it exists. diff --git a/internal/dis/component.go b/internal/dis/component.go index e7b1f4a..408f1c6 100644 --- a/internal/dis/component.go +++ b/internal/dis/component.go @@ -5,13 +5,14 @@ import ( "github.com/FAU-CDI/wisski-distillery/internal/component" "github.com/FAU-CDI/wisski-distillery/internal/component/control" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter/logger" + "github.com/FAU-CDI/wisski-distillery/internal/component/home" "github.com/FAU-CDI/wisski-distillery/internal/component/info" "github.com/FAU-CDI/wisski-distillery/internal/component/instances" "github.com/FAU-CDI/wisski-distillery/internal/component/meta" "github.com/FAU-CDI/wisski-distillery/internal/component/resolver" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshots" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshotslog" "github.com/FAU-CDI/wisski-distillery/internal/component/sql" "github.com/FAU-CDI/wisski-distillery/internal/component/ssh" "github.com/FAU-CDI/wisski-distillery/internal/component/static" @@ -42,12 +43,12 @@ func (dis *Distillery) register(context component.ComponentPoolContext) []compon auto[*meta.Meta], // Snapshots - auto[*snapshots.Manager], - auto[*snapshotslog.SnapshotsLog], - auto[*snapshots.Config], - auto[*snapshots.Bookkeeping], - auto[*snapshots.Filesystem], - auto[*snapshots.Pathbuilders], + auto[*exporter.Exporter], + auto[*logger.Logger], + auto[*exporter.Config], + auto[*exporter.Bookkeeping], + auto[*exporter.Filesystem], + auto[*exporter.Pathbuilders], // Control server auto[*control.Control], diff --git a/internal/dis/distillery.go b/internal/dis/distillery.go index cda2c49..c3b7870 100644 --- a/internal/dis/distillery.go +++ b/internal/dis/distillery.go @@ -6,9 +6,9 @@ import ( "github.com/FAU-CDI/wisski-distillery/internal/component" "github.com/FAU-CDI/wisski-distillery/internal/component/control" + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter" "github.com/FAU-CDI/wisski-distillery/internal/component/instances" "github.com/FAU-CDI/wisski-distillery/internal/component/resolver" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshots" "github.com/FAU-CDI/wisski-distillery/internal/component/sql" "github.com/FAU-CDI/wisski-distillery/internal/component/ssh" "github.com/FAU-CDI/wisski-distillery/internal/component/triplestore" @@ -85,8 +85,8 @@ func (dis *Distillery) Triplestore() *triplestore.Triplestore { func (dis *Distillery) Instances() *instances.Instances { return e[*instances.Instances](dis) } -func (dis *Distillery) ExportManager() *snapshots.Manager { - return e[*snapshots.Manager](dis) +func (dis *Distillery) Exporter() *exporter.Exporter { + return e[*exporter.Exporter](dis) } func (dis *Distillery) Installable() []component.Installable { diff --git a/internal/wisski/snapshots.go b/internal/wisski/snapshots.go index d442414..bc58250 100644 --- a/internal/wisski/snapshots.go +++ b/internal/wisski/snapshots.go @@ -4,5 +4,5 @@ import "github.com/FAU-CDI/wisski-distillery/internal/models" // Snapshots returns the list of snapshots of this WissKI func (wisski *WissKI) Snapshots() (snapshots []models.Export, err error) { - return wisski.SnapshotsLog.For(wisski.Slug) + return wisski.ExporterLog.For(wisski.Slug) } diff --git a/internal/wisski/wisski.go b/internal/wisski/wisski.go index 5618e8b..e6ed089 100644 --- a/internal/wisski/wisski.go +++ b/internal/wisski/wisski.go @@ -3,8 +3,9 @@ package wisski import ( "github.com/FAU-CDI/wisski-distillery/internal/component" + + "github.com/FAU-CDI/wisski-distillery/internal/component/exporter/logger" "github.com/FAU-CDI/wisski-distillery/internal/component/meta" - "github.com/FAU-CDI/wisski-distillery/internal/component/snapshotslog" "github.com/FAU-CDI/wisski-distillery/internal/component/sql" "github.com/FAU-CDI/wisski-distillery/internal/component/triplestore" "github.com/FAU-CDI/wisski-distillery/internal/models" @@ -24,7 +25,7 @@ type WissKI struct { TS *triplestore.Triplestore SQL *sql.SQL - SnapshotsLog *snapshotslog.SnapshotsLog + ExporterLog *logger.Logger } // Save saves this instance in the bookkeeping table