mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-17 02:11:03 +02:00
WIP: Switch to new config format.
Don't use jobrun for daemon, just call JobDo() once, the job must organize stuff itself. Sacrifice all the oneshot commands, they will be reintroduced as client-calls to the daemon.
This commit is contained in:
@ -3,75 +3,13 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zrepl/zrepl/jobrun"
|
||||
"github.com/zrepl/zrepl/rpc"
|
||||
"github.com/zrepl/zrepl/util"
|
||||
"github.com/zrepl/zrepl/zfs"
|
||||
)
|
||||
|
||||
var runArgs struct {
|
||||
job string
|
||||
once bool
|
||||
}
|
||||
|
||||
var PushCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "run push job (first positional argument)",
|
||||
Run: cmdPush,
|
||||
}
|
||||
|
||||
var PullCmd = &cobra.Command{
|
||||
Use: "pull",
|
||||
Short: "run pull job (first positional argument)",
|
||||
Run: cmdPull,
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(PushCmd)
|
||||
RootCmd.AddCommand(PullCmd)
|
||||
}
|
||||
|
||||
func cmdPush(cmd *cobra.Command, args []string) {
|
||||
|
||||
if len(args) != 1 {
|
||||
log.Printf("must specify exactly one job as positional argument")
|
||||
os.Exit(1)
|
||||
}
|
||||
job, ok := conf.Pushs[args[0]]
|
||||
if !ok {
|
||||
log.Printf("could not find push job %s", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := jobPush(job, log); err != nil {
|
||||
log.Printf("error doing push: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func cmdPull(cmd *cobra.Command, args []string) {
|
||||
|
||||
if len(args) != 1 {
|
||||
log.Printf("must specify exactly one job as positional argument")
|
||||
os.Exit(1)
|
||||
}
|
||||
job, ok := conf.Pulls[args[0]]
|
||||
if !ok {
|
||||
log.Printf("could not find pull job %s", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := jobPull(job, log); err != nil {
|
||||
log.Printf("error doing pull: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type localPullACL struct{}
|
||||
|
||||
func (a localPullACL) Filter(p *zfs.DatasetPath) (pass bool, err error) {
|
||||
@ -89,47 +27,6 @@ const (
|
||||
InitialReplPolicyAll InitialReplPolicy = "all"
|
||||
)
|
||||
|
||||
func jobPull(pull *Pull, log jobrun.Logger) (err error) {
|
||||
|
||||
var remote rpc.RPCClient
|
||||
|
||||
if remote, err = pull.From.Transport.Connect(log); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer closeRPCWithTimeout(log, remote, time.Second*10, "")
|
||||
|
||||
return doPull(PullContext{remote, log, pull.Mapping, pull.InitialReplPolicy})
|
||||
}
|
||||
|
||||
func jobPush(push *Push, log jobrun.Logger) (err error) {
|
||||
|
||||
if _, ok := push.To.Transport.(LocalTransport); ok {
|
||||
panic("no support for local pushs")
|
||||
}
|
||||
|
||||
var remote rpc.RPCClient
|
||||
if remote, err = push.To.Transport.Connect(log); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer closeRPCWithTimeout(log, remote, time.Second*10, "")
|
||||
|
||||
log.Printf("building handler for PullMeRequest")
|
||||
handler := Handler{
|
||||
Logger: log,
|
||||
PullACL: push.Filter,
|
||||
SinkMappingFunc: nil, // no need for that in the handler for PullMe
|
||||
}
|
||||
log.Printf("handler: %#v", handler)
|
||||
|
||||
panic("no support for push atm")
|
||||
|
||||
log.Printf("push job finished")
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func closeRPCWithTimeout(log Logger, remote rpc.RPCClient, timeout time.Duration, goodbye string) {
|
||||
log.Printf("closing rpc connection")
|
||||
|
||||
|
Reference in New Issue
Block a user