{snapshot,backup}: Keep track of errors when writing report

This commit is contained in:
Tom Wiesing 2022-09-13 14:37:04 +02:00
parent 40a1aafbee
commit ac43221932
No known key found for this signature in database
3 changed files with 124 additions and 51 deletions

View file

@ -12,6 +12,7 @@ import (
"time"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/countwriter"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/pkg/errors"
@ -58,45 +59,48 @@ func (backup Backup) String() string {
}
// Report writes a report from backup into w
func (backup Backup) Report(w io.Writer) {
// TODO: Errors
encoder := json.NewEncoder(w)
func (backup Backup) Report(w io.Writer) (int, error) {
cw := countwriter.NewCountWriter(w)
encoder := json.NewEncoder(cw)
encoder.SetIndent("", " ")
io.WriteString(w, "======= Backup =======\n")
io.WriteString(cw, "======= Backup =======\n")
fmt.Fprintf(w, "Start: %s\n", backup.StartTime)
fmt.Fprintf(w, "End: %s\n", backup.EndTime)
io.WriteString(w, "\n")
fmt.Fprintf(cw, "Start: %s\n", backup.StartTime)
fmt.Fprintf(cw, "End: %s\n", backup.EndTime)
io.WriteString(cw, "\n")
io.WriteString(w, "======= Description =======\n")
io.WriteString(cw, "======= Description =======\n")
encoder.Encode(backup.Description)
io.WriteString(w, "\n")
io.WriteString(cw, "\n")
io.WriteString(w, "======= Errors =======\n")
fmt.Fprintf(w, "Panic: %v\n", backup.ErrPanic)
fmt.Fprintf(w, "SQLErr: %s\n", backup.SQLErr)
fmt.Fprintf(w, "TSErr: %s\n", backup.TSErr)
fmt.Fprintf(w, "ConfigFileErr: %s\n", backup.ConfigFileErr)
fmt.Fprintf(w, "InstanceListErr: %s\n", backup.InstanceListErr)
io.WriteString(cw, "======= Errors =======\n")
fmt.Fprintf(cw, "Panic: %v\n", backup.ErrPanic)
fmt.Fprintf(cw, "SQLErr: %s\n", backup.SQLErr)
fmt.Fprintf(cw, "TSErr: %s\n", backup.TSErr)
fmt.Fprintf(cw, "ConfigFileErr: %s\n", backup.ConfigFileErr)
fmt.Fprintf(cw, "InstanceListErr: %s\n", backup.InstanceListErr)
io.WriteString(w, "\n")
io.WriteString(cw, "\n")
io.WriteString(w, "======= Config Files =======\n")
io.WriteString(cw, "======= Config Files =======\n")
encoder.Encode(backup.ConfigFilesManifest) // TODO: Proper manifest
io.WriteString(w, "======= Snapshots =======\n")
io.WriteString(cw, "======= Snapshots =======\n")
for _, s := range backup.InstanceSnapshots {
io.WriteString(w, s.String())
io.WriteString(w, "\n")
io.WriteString(cw, s.String())
io.WriteString(cw, "\n")
}
io.WriteString(w, "======= Manifest =======\n")
io.WriteString(cw, "======= Manifest =======\n")
for _, file := range backup.Manifest {
io.WriteString(w, file+"\n")
io.WriteString(cw, file+"\n")
}
io.WriteString(w, "\n")
io.WriteString(cw, "\n")
return cw.Sum()
}
func (dis *Distillery) Backup(io stream.IOStream, description BackupDescription) (backup Backup) {

View file

@ -12,6 +12,7 @@ import (
"time"
"github.com/FAU-CDI/wisski-distillery/pkg/bookkeeping"
"github.com/FAU-CDI/wisski-distillery/pkg/countwriter"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/password"
@ -112,47 +113,51 @@ func (snapshot Snapshot) String() string {
}
// Report writes a report from snapshot into w
func (snapshot Snapshot) Report(w io.Writer) {
func (snapshot Snapshot) Report(w io.Writer) (int, error) {
ww := countwriter.NewCountWriter(w)
// TODO: Errors of the writer!
encoder := json.NewEncoder(w)
encoder := json.NewEncoder(ww)
encoder.SetIndent("", " ")
io.WriteString(w, "======= Begin Snapshot Report "+snapshot.Instance.Slug+" =======\n")
io.WriteString(ww, "======= Begin Snapshot Report "+snapshot.Instance.Slug+" =======\n")
fmt.Fprintf(w, "Slug: %s\n", snapshot.Instance.Slug)
fmt.Fprintf(w, "Dest: %s\n", snapshot.Description.Dest)
fmt.Fprintf(ww, "Slug: %s\n", snapshot.Instance.Slug)
fmt.Fprintf(ww, "Dest: %s\n", snapshot.Description.Dest)
fmt.Fprintf(w, "Start: %s\n", snapshot.StartTime)
fmt.Fprintf(w, "End: %s\n", snapshot.EndTime)
io.WriteString(w, "\n")
fmt.Fprintf(ww, "Start: %s\n", snapshot.StartTime)
fmt.Fprintf(ww, "End: %s\n", snapshot.EndTime)
io.WriteString(ww, "\n")
io.WriteString(w, "======= Description =======\n")
io.WriteString(ww, "======= Description =======\n")
encoder.Encode(snapshot.Description)
io.WriteString(w, "\n")
io.WriteString(ww, "\n")
io.WriteString(w, "======= Instance =======\n")
io.WriteString(ww, "======= Instance =======\n")
encoder.Encode(snapshot.Instance)
io.WriteString(w, "\n")
io.WriteString(ww, "\n")
io.WriteString(w, "======= Errors =======\n")
fmt.Fprintf(w, "Panic: %v\n", snapshot.ErrPanic)
fmt.Fprintf(w, "Start: %s\n", snapshot.ErrStart)
fmt.Fprintf(w, "Stop: %s\n", snapshot.ErrStop)
fmt.Fprintf(w, "Bookkeep: %s\n", snapshot.ErrBookkeep)
fmt.Fprintf(w, "Pathbuilder: %s\n", snapshot.ErrPathbuilder)
fmt.Fprintf(w, "Filesystem: %s\n", snapshot.ErrFilesystem)
fmt.Fprintf(w, "Triplestore: %s\n", snapshot.ErrTriplestore)
fmt.Fprintf(w, "SQL: %s\n", snapshot.ErrSQL)
io.WriteString(w, "\n")
io.WriteString(ww, "======= Errors =======\n")
fmt.Fprintf(ww, "Panic: %v\n", snapshot.ErrPanic)
fmt.Fprintf(ww, "Start: %s\n", snapshot.ErrStart)
fmt.Fprintf(ww, "Stop: %s\n", snapshot.ErrStop)
fmt.Fprintf(ww, "Bookkeep: %s\n", snapshot.ErrBookkeep)
fmt.Fprintf(ww, "Pathbuilder: %s\n", snapshot.ErrPathbuilder)
fmt.Fprintf(ww, "Filesystem: %s\n", snapshot.ErrFilesystem)
fmt.Fprintf(ww, "Triplestore: %s\n", snapshot.ErrTriplestore)
fmt.Fprintf(ww, "SQL: %s\n", snapshot.ErrSQL)
io.WriteString(ww, "\n")
io.WriteString(w, "======= Manifest =======\n")
io.WriteString(ww, "======= Manifest =======\n")
for _, file := range snapshot.Manifest {
io.WriteString(w, file+"\n")
io.WriteString(ww, file+"\n")
}
io.WriteString(w, "\n")
io.WriteString(ww, "\n")
io.WriteString(w, "======= End Snapshot Report "+snapshot.Instance.Slug+" =======\n")
io.WriteString(ww, "======= End Snapshot Report "+snapshot.Instance.Slug+"=======\n")
return ww.Sum()
}
// Snapshot creates a new snapshot of this instance into dest
@ -169,7 +174,7 @@ func (instance Instance) Snapshot(io stream.IOStream, desc SnapshotDescription)
// do the create keeping track of time!
logging.LogOperation(func() error {
snapshot.StartTime = time.Now()
snapshot.create(io, instance)
snapshot.makeBlackbox(io, instance)
snapshot.EndTime = time.Now()
return nil
@ -178,7 +183,9 @@ func (instance Instance) Snapshot(io stream.IOStream, desc SnapshotDescription)
return
}
func (snapshot *Snapshot) create(io stream.IOStream, instance Instance) {
// mainBlackbox runs the blackbox backup of the system.
// It pauses the Instance, if a consistent state is required.
func (snapshot *Snapshot) makeBlackbox(io stream.IOStream, instance Instance) {
stack := instance.Stack()
// stop the instance (unless it was explicitly asked to not do so!)