2017-09-10 16:13:05 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-08-08 13:09:51 +02:00
|
|
|
"net"
|
2017-09-10 16:13:05 +02:00
|
|
|
|
2017-09-16 21:12:26 +02:00
|
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
2017-09-10 16:13:05 +02:00
|
|
|
"github.com/zrepl/zrepl/zfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2017-09-11 13:43:18 +02:00
|
|
|
Global Global
|
|
|
|
Jobs map[string]Job
|
|
|
|
}
|
|
|
|
|
2017-09-16 21:12:26 +02:00
|
|
|
func (c *Config) LookupJob(name string) (j Job, err error) {
|
2017-09-17 17:45:02 +02:00
|
|
|
j, ok := c.Jobs[name]
|
2017-09-16 21:12:26 +02:00
|
|
|
if !ok {
|
|
|
|
return nil, errors.Errorf("job '%s' is not defined", name)
|
|
|
|
}
|
|
|
|
return j, nil
|
|
|
|
}
|
|
|
|
|
2017-09-11 13:43:18 +02:00
|
|
|
type Global struct {
|
|
|
|
Serve struct {
|
|
|
|
Stdinserver struct {
|
|
|
|
SockDir string
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 23:54:23 +02:00
|
|
|
Control struct {
|
|
|
|
Sockpath string
|
|
|
|
}
|
2017-09-22 14:13:58 +02:00
|
|
|
logging *LoggingConfig
|
2017-09-10 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2017-09-11 15:45:10 +02:00
|
|
|
type JobDebugSettings struct {
|
|
|
|
Conn struct {
|
|
|
|
ReadDump string `mapstructure:"read_dump"`
|
|
|
|
WriteDump string `mapstructure:"write_dump"`
|
|
|
|
}
|
|
|
|
RPC struct {
|
|
|
|
Log bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 13:09:51 +02:00
|
|
|
type ListenerFactory interface {
|
|
|
|
Listen() (net.Listener, error)
|
2017-09-10 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SSHStdinServerConnectDescr struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrunePolicy interface {
|
2018-02-17 20:48:31 +01:00
|
|
|
// Prune filters versions and decide which to keep and which to remove.
|
|
|
|
// Prune **does not** implement the actual removal of the versions.
|
2017-09-13 23:46:57 +02:00
|
|
|
Prune(fs *zfs.DatasetPath, versions []zfs.FilesystemVersion) (keep, remove []zfs.FilesystemVersion, err error)
|
2017-09-10 16:13:05 +02:00
|
|
|
}
|
2017-09-16 21:12:26 +02:00
|
|
|
|
|
|
|
type PruningJob interface {
|
2018-08-26 16:49:40 +02:00
|
|
|
Pruner(side PrunePolicySide, dryRun bool) (Pruner, error)
|
2017-09-16 21:12:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A type for constants describing different prune policies of a PruningJob
|
|
|
|
// This is mostly a special-case for LocalJob, which is the only job that has two prune policies
|
|
|
|
// instead of one.
|
|
|
|
// It implements github.com/spf13/pflag.Value to be used as CLI flag for the test subcommand
|
|
|
|
type PrunePolicySide string
|
|
|
|
|
|
|
|
const (
|
|
|
|
PrunePolicySideDefault PrunePolicySide = ""
|
|
|
|
PrunePolicySideLeft PrunePolicySide = "left"
|
|
|
|
PrunePolicySideRight PrunePolicySide = "right"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *PrunePolicySide) String() string {
|
|
|
|
return string(*s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *PrunePolicySide) Set(news string) error {
|
|
|
|
p := PrunePolicySide(news)
|
|
|
|
switch p {
|
|
|
|
case PrunePolicySideRight:
|
|
|
|
fallthrough
|
|
|
|
case PrunePolicySideLeft:
|
|
|
|
*s = p
|
|
|
|
default:
|
|
|
|
return errors.Errorf("must be either %s or %s", PrunePolicySideLeft, PrunePolicySideRight)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *PrunePolicySide) Type() string {
|
|
|
|
return fmt.Sprintf("%s | %s", PrunePolicySideLeft, PrunePolicySideRight)
|
|
|
|
}
|