Refactor component/extras into snapshotting
This commit is contained in:
parent
6d9c83c842
commit
6f409be8b2
9 changed files with 81 additions and 79 deletions
29
internal/component/snapshots/extras_bookkeeping.go
Normal file
29
internal/component/snapshots/extras_bookkeeping.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package snapshots
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
)
|
||||
|
||||
type Bookkeeping struct {
|
||||
component.ComponentBase
|
||||
}
|
||||
|
||||
func (Bookkeeping) Name() string { return "bookkeeping" }
|
||||
|
||||
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
||||
func (Bookkeeping) SnapshotNeedsRunning() bool { return false }
|
||||
|
||||
// SnapshotName returns a new name to be used as an argument for path.
|
||||
func (Bookkeeping) SnapshotName() string { return "bookkeeping.txt" }
|
||||
|
||||
// Snapshot creates a snapshot of this instance
|
||||
func (*Bookkeeping) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.AddFile(".", func(file io.Writer) error {
|
||||
_, err := fmt.Fprintf(file, "%#v\n", wisski)
|
||||
return err
|
||||
})
|
||||
}
|
||||
43
internal/component/snapshots/extras_config.go
Normal file
43
internal/component/snapshots/extras_config.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package snapshots
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
)
|
||||
|
||||
// Config implements backing up configuration
|
||||
type Config struct {
|
||||
component.ComponentBase
|
||||
}
|
||||
|
||||
func (Config) Name() string { return "config" }
|
||||
|
||||
func (*Config) BackupName() string {
|
||||
return "config"
|
||||
}
|
||||
|
||||
func (control *Config) Backup(context component.StagingContext) error {
|
||||
files := control.backupFiles()
|
||||
|
||||
return context.AddDirectory("", func() error {
|
||||
for _, src := range files {
|
||||
name := filepath.Base(src)
|
||||
if err := context.CopyFile(name, src); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// backupfiles lists the files to be backed up.
|
||||
func (control *Config) backupFiles() []string {
|
||||
return []string{
|
||||
control.Config.ConfigPath,
|
||||
control.Config.ExecutablePath(),
|
||||
control.Config.SelfOverridesFile,
|
||||
control.Config.SelfResolverBlockFile,
|
||||
control.Config.GlobalAuthorizedKeysFile,
|
||||
}
|
||||
}
|
||||
24
internal/component/snapshots/extras_filesystem.go
Normal file
24
internal/component/snapshots/extras_filesystem.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package snapshots
|
||||
|
||||
import (
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
)
|
||||
|
||||
// Filesystem implements snapshotting an instnace filesystem
|
||||
type Filesystem struct {
|
||||
component.ComponentBase
|
||||
}
|
||||
|
||||
func (Filesystem) Name() string { return "filesystem" }
|
||||
|
||||
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
||||
func (Filesystem) SnapshotNeedsRunning() bool { return false }
|
||||
|
||||
// SnapshotName returns a new name to be used as an argument for path.
|
||||
func (Filesystem) SnapshotName() string { return "data" }
|
||||
|
||||
// Snapshot creates a snapshot of this instance
|
||||
func (*Filesystem) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.CopyDirectory(".", wisski.FilesystemBase)
|
||||
}
|
||||
39
internal/component/snapshots/extras_pathbuilders.go
Normal file
39
internal/component/snapshots/extras_pathbuilders.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package snapshots
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
type Pathbuilders struct {
|
||||
component.ComponentBase
|
||||
Instances *instances.Instances
|
||||
}
|
||||
|
||||
func (Pathbuilders) Name() string { return "pathbuilders" }
|
||||
|
||||
func (Pathbuilders) SnapshotNeedsRunning() bool { return true }
|
||||
|
||||
func (Pathbuilders) SnapshotName() string { return "pathbuilders" }
|
||||
|
||||
func (pbs *Pathbuilders) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.AddDirectory(".", func() error {
|
||||
builders, err := pbs.Instances.Instance(wisski).AllPathbuilders()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for name, bytes := range builders {
|
||||
if err := context.AddFile(name+".xml", func(file io.Writer) error {
|
||||
_, err := file.Write([]byte(bytes))
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue