component: Add 'Snapshottable' component

This commit is contained in:
Tom Wiesing 2022-10-01 20:11:01 +02:00
parent 1dac09bc03
commit b6c36b5488
No known key found for this signature in database
7 changed files with 28 additions and 13 deletions

View file

@ -3,6 +3,7 @@ package component
import (
"io"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/tkw1536/goprogram/stream"
)
@ -14,11 +15,11 @@ type Backupable interface {
BackupName() string
// Backup backs up this component into the destination path path
Backup(context BackupContext) error
Backup(context StagingContext) error
}
// BackupContext is the context for backups
type BackupContext interface {
// StagingContext represents a context for [Backupable] and [Snapshotable]
type StagingContext interface {
// IO returns the input output stream belonging to this backup file
IO() stream.IOStream
@ -41,3 +42,17 @@ type BackupContext interface {
// AddFile will not return before op has returned.
AddFile(path string, op func(file io.Writer) error) error
}
// Snapshotable represents a component with a Snapshot method.
type Snapshotable interface {
Component
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
SnapshotNeedsRunning() bool
// SnapshotName returns a new name to be used as an argument for path.
SnapshotName() string
// Snapshot snapshots a part of the instance
Snapshot(wisski models.Instance, context StagingContext) error
}