2020-06-27 23:53:33 +02:00
|
|
|
package job
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
2020-08-31 16:04:00 +02:00
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
"github.com/zrepl/zrepl/config"
|
|
|
|
"github.com/zrepl/zrepl/daemon/filters"
|
|
|
|
"github.com/zrepl/zrepl/endpoint"
|
2020-09-02 22:38:26 +02:00
|
|
|
"github.com/zrepl/zrepl/util/nodefault"
|
2020-06-27 23:53:33 +02:00
|
|
|
"github.com/zrepl/zrepl/zfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SendingJobConfig interface {
|
|
|
|
GetFilesystems() config.FilesystemsFilter
|
|
|
|
GetSendOptions() *config.SendOptions // must not be nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildSenderConfig(in SendingJobConfig, jobID endpoint.JobID) (*endpoint.SenderConfig, error) {
|
|
|
|
|
|
|
|
fsf, err := filters.DatasetMapFilterFromConfig(in.GetFilesystems())
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "cannot build filesystem filter")
|
|
|
|
}
|
2020-09-07 01:20:57 +02:00
|
|
|
sendOpts := in.GetSendOptions()
|
2021-07-09 16:30:44 +02:00
|
|
|
bwlim, err := buildBandwidthLimitConfig(sendOpts.BandwidthLimit)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "cannot build bandwith limit config")
|
|
|
|
}
|
|
|
|
|
|
|
|
sc := &endpoint.SenderConfig{
|
2020-09-07 01:20:57 +02:00
|
|
|
FSF: fsf,
|
|
|
|
JobID: jobID,
|
|
|
|
|
|
|
|
Encrypt: &nodefault.Bool{B: sendOpts.Encrypted},
|
|
|
|
SendRaw: sendOpts.Raw,
|
|
|
|
SendProperties: sendOpts.SendProperties,
|
|
|
|
SendBackupProperties: sendOpts.BackupProperties,
|
|
|
|
SendLargeBlocks: sendOpts.LargeBlocks,
|
|
|
|
SendCompressed: sendOpts.Compressed,
|
|
|
|
SendEmbeddedData: sendOpts.EmbeddedData,
|
|
|
|
SendSaved: sendOpts.Saved,
|
2021-07-09 16:30:44 +02:00
|
|
|
|
|
|
|
BandwidthLimit: bwlim,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := sc.Validate(); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "cannot build sender config")
|
|
|
|
}
|
|
|
|
|
|
|
|
return sc, nil
|
2020-06-27 23:53:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ReceivingJobConfig interface {
|
|
|
|
GetRootFS() string
|
|
|
|
GetAppendClientIdentity() bool
|
|
|
|
GetRecvOptions() *config.RecvOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildReceiverConfig(in ReceivingJobConfig, jobID endpoint.JobID) (rc endpoint.ReceiverConfig, err error) {
|
|
|
|
rootFs, err := zfs.NewDatasetPath(in.GetRootFS())
|
|
|
|
if err != nil {
|
|
|
|
return rc, errors.New("root_fs is not a valid zfs filesystem path")
|
|
|
|
}
|
|
|
|
if rootFs.Length() <= 0 {
|
|
|
|
return rc, errors.New("root_fs must not be empty") // duplicates error check of receiver
|
|
|
|
}
|
|
|
|
|
2020-09-07 01:20:57 +02:00
|
|
|
recvOpts := in.GetRecvOptions()
|
2021-07-09 16:30:44 +02:00
|
|
|
|
|
|
|
bwlim, err := buildBandwidthLimitConfig(recvOpts.BandwidthLimit)
|
|
|
|
if err != nil {
|
|
|
|
return rc, errors.Wrap(err, "cannot build bandwith limit config")
|
|
|
|
}
|
|
|
|
|
2020-06-27 23:53:33 +02:00
|
|
|
rc = endpoint.ReceiverConfig{
|
|
|
|
JobID: jobID,
|
|
|
|
RootWithoutClientComponent: rootFs,
|
|
|
|
AppendClientIdentity: in.GetAppendClientIdentity(),
|
2020-09-07 01:20:57 +02:00
|
|
|
|
|
|
|
InheritProperties: recvOpts.Properties.Inherit,
|
|
|
|
OverrideProperties: recvOpts.Properties.Override,
|
2021-07-09 16:30:44 +02:00
|
|
|
|
|
|
|
BandwidthLimit: bwlim,
|
2020-06-27 23:53:33 +02:00
|
|
|
}
|
|
|
|
if err := rc.Validate(); err != nil {
|
|
|
|
return rc, errors.Wrap(err, "cannot build receiver config")
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc, nil
|
|
|
|
}
|