component: Add 'Snapshottable' component
This commit is contained in:
parent
1dac09bc03
commit
b6c36b5488
7 changed files with 28 additions and 13 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ func (*Control) BackupName() string {
|
|||
}
|
||||
|
||||
// Backup backups all control plane configuration files into dest
|
||||
func (control *Control) Backup(context component.BackupContext) error {
|
||||
func (control *Control) Backup(context component.StagingContext) error {
|
||||
files := control.backupFiles()
|
||||
|
||||
return context.AddDirectory("", func() error {
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, snapshots *Manager, i
|
|||
defer nquads.Close()
|
||||
|
||||
// directly store the result
|
||||
_, err = snapshots.TS.Snapshot(nquads, instance.GraphDBRepository)
|
||||
_, err = snapshots.TS.SnapshotDB(nquads, instance.GraphDBRepository)
|
||||
return err
|
||||
}, &snapshot.ErrTriplestore)
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, snapshots *Manager, i
|
|||
defer sql.Close()
|
||||
|
||||
// directly store the result
|
||||
return snapshots.SQL.Snapshot(io, sql, instance.SqlDatabase)
|
||||
return snapshots.SQL.SnapshotDB(io, sql, instance.SqlDatabase)
|
||||
}, &snapshot.ErrSQL)
|
||||
|
||||
// wait for the group!
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func (*SQL) BackupName() string {
|
|||
}
|
||||
|
||||
// Backup makes a backup of all SQL databases into the path dest.
|
||||
func (sql *SQL) Backup(context component.BackupContext) error {
|
||||
func (sql *SQL) Backup(context component.StagingContext) error {
|
||||
return context.AddFile("", func(file io.Writer) error {
|
||||
io := context.IO().Streams(file, nil, nil, 0).NonInteractive()
|
||||
code, err := sql.Stack(sql.Environment).Exec(io, "sql", "mysqldump", "--all-databases")
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Snapshot makes a backup of the sql database into dest.
|
||||
func (sql SQL) Snapshot(io stream.IOStream, dest io.Writer, database string) error {
|
||||
// SnapshotDB makes a backup of the sql database into dest.
|
||||
func (sql SQL) SnapshotDB(io stream.IOStream, dest io.Writer, database string) error {
|
||||
io = io.Streams(dest, nil, nil, 0).NonInteractive()
|
||||
|
||||
code, err := sql.Stack(sql.Environment).Exec(io, "sql", "mysqldump", "--databases", database)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
func (ts *Triplestore) BackupName() string { return "triplestore" }
|
||||
|
||||
// Backup makes a backup of all Triplestore repositories databases into the path dest.
|
||||
func (ts *Triplestore) Backup(context component.BackupContext) error {
|
||||
func (ts *Triplestore) Backup(context component.StagingContext) error {
|
||||
|
||||
// list all the directories
|
||||
repos, err := ts.listRepositories()
|
||||
|
|
@ -22,7 +22,7 @@ func (ts *Triplestore) Backup(context component.BackupContext) error {
|
|||
return context.AddDirectory("", func() error {
|
||||
for _, repo := range repos {
|
||||
if err := context.AddFile(repo.ID+".nq", func(file io.Writer) error {
|
||||
_, err := ts.Snapshot(file, repo.ID)
|
||||
_, err := ts.SnapshotDB(file, repo.ID)
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ func (ts Triplestore) PurgeRepo(repo string) error {
|
|||
|
||||
var errTSBackupWrongStatusCode = errors.New("Distillery.Backup: Wrong status code")
|
||||
|
||||
// Snapshot snapshots the provided repository into dst
|
||||
func (ts Triplestore) Snapshot(dst io.Writer, repo string) (int64, error) {
|
||||
// SnapshotDB snapshots the provided repository into dst
|
||||
func (ts Triplestore) SnapshotDB(dst io.Writer, repo string) (int64, error) {
|
||||
res, err := ts.OpenRaw("GET", "/repositories/"+repo+"/statements?infer=false", nil, "", "application/n-quads")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue