WIP: reset handling, unified wait token TODO: task-level invocations (replication, snapshotting, pruning)
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/zrepl/zrepl/cli"
|
||||
"github.com/zrepl/zrepl/config"
|
||||
"github.com/zrepl/zrepl/daemon"
|
||||
"github.com/zrepl/zrepl/daemon/job"
|
||||
)
|
||||
|
||||
var SignalCmd = &cli.Subcommand{
|
||||
Use: "signal JOB [replication|reset|snapshot]",
|
||||
Short: "run a job replication, abort its current invocation, run a snapshot job",
|
||||
Run: func(ctx context.Context, subcommand *cli.Subcommand, args []string) error {
|
||||
return runSignalCmd(subcommand.Config(), args)
|
||||
},
|
||||
}
|
||||
|
||||
func runSignalCmd(config *config.Config, args []string) error {
|
||||
if len(args) != 2 {
|
||||
return errors.Errorf("Expected 2 arguments: [replication|reset|snapshot] JOB")
|
||||
}
|
||||
|
||||
httpc, err := controlHttpClient(config.Global.Control.SockPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jobName := args[0]
|
||||
what := args[1]
|
||||
|
||||
var res job.ActiveSideSignalResponse
|
||||
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointSignalActive,
|
||||
struct {
|
||||
Job string
|
||||
job.ActiveSideSignalRequest
|
||||
}{
|
||||
Job: jobName,
|
||||
ActiveSideSignalRequest: job.ActiveSideSignalRequest{
|
||||
What: what,
|
||||
},
|
||||
},
|
||||
&res,
|
||||
)
|
||||
|
||||
pollRequest := daemon.ControlJobEndpointSignalActiveRequest{
|
||||
Job: jobName,
|
||||
ActiveSidePollRequest: job.ActiveSidePollRequest{
|
||||
InvocationId: res.InvocationId,
|
||||
What: what,
|
||||
},
|
||||
}
|
||||
|
||||
j, err := json.Marshal(pollRequest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(string(j))
|
||||
return err
|
||||
}
|
||||
@@ -44,13 +44,13 @@ func (c *Client) StatusRaw() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (c *Client) signal(jobName, sig string) error {
|
||||
return jsonRequestResponse(c.h, daemon.ControlJobEndpointSignalActive,
|
||||
return jsonRequestResponse(c.h, daemon.ControlJobEndpointTriggerActive,
|
||||
struct {
|
||||
Job string
|
||||
job.ActiveSideSignalRequest
|
||||
job.ActiveSideTriggerRequest
|
||||
}{
|
||||
Job: jobName,
|
||||
ActiveSideSignalRequest: job.ActiveSideSignalRequest{
|
||||
ActiveSideTriggerRequest: job.ActiveSideTriggerRequest{
|
||||
What: sig,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/zrepl/zrepl/cli"
|
||||
"github.com/zrepl/zrepl/config"
|
||||
"github.com/zrepl/zrepl/daemon"
|
||||
"github.com/zrepl/zrepl/daemon/job"
|
||||
)
|
||||
|
||||
var TriggerCmd = &cli.Subcommand{
|
||||
Use: "trigger JOB [replication|snapshot]",
|
||||
Short: "",
|
||||
Run: func(ctx context.Context, subcommand *cli.Subcommand, args []string) error {
|
||||
return runTriggerCmd(subcommand.Config(), args)
|
||||
},
|
||||
}
|
||||
|
||||
type TriggerToken struct {
|
||||
// TODO version, daemon invocation id, etc.
|
||||
Job string
|
||||
InvocationId uint64
|
||||
}
|
||||
|
||||
func (t TriggerToken) Encode() string {
|
||||
j, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(j)
|
||||
}
|
||||
|
||||
func (t *TriggerToken) Decode(s string) error {
|
||||
return json.Unmarshal([]byte(s), t)
|
||||
}
|
||||
|
||||
func (t TriggerToken) ToReset() daemon.ControlJobEndpointResetActiveRequest {
|
||||
return daemon.ControlJobEndpointResetActiveRequest{
|
||||
Job: t.Job,
|
||||
ActiveSideResetRequest: job.ActiveSideResetRequest{
|
||||
InvocationId: t.InvocationId,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (t TriggerToken) ToWait() daemon.ControlJobEndpointWaitActiveRequest {
|
||||
return daemon.ControlJobEndpointWaitActiveRequest{
|
||||
Job: t.Job,
|
||||
ActiveSidePollRequest: job.ActiveSidePollRequest{
|
||||
InvocationId: t.InvocationId,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func runTriggerCmd(config *config.Config, args []string) error {
|
||||
if len(args) != 2 {
|
||||
return errors.Errorf("Expected 2 arguments: [replication|reset|snapshot] JOB")
|
||||
}
|
||||
|
||||
httpc, err := controlHttpClient(config.Global.Control.SockPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jobName := args[0]
|
||||
what := args[1]
|
||||
|
||||
var res job.ActiveSideSignalResponse
|
||||
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointTriggerActive,
|
||||
struct {
|
||||
Job string
|
||||
job.ActiveSideTriggerRequest
|
||||
}{
|
||||
Job: jobName,
|
||||
ActiveSideTriggerRequest: job.ActiveSideTriggerRequest{
|
||||
What: what,
|
||||
},
|
||||
},
|
||||
&res,
|
||||
)
|
||||
|
||||
token := TriggerToken{
|
||||
Job: jobName,
|
||||
InvocationId: res.InvocationId,
|
||||
}
|
||||
|
||||
fmt.Println(token.Encode())
|
||||
return err
|
||||
}
|
||||
+10
-20
@@ -2,7 +2,6 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -24,7 +23,7 @@ var waitCmdArgs struct {
|
||||
}
|
||||
|
||||
var WaitCmd = &cli.Subcommand{
|
||||
Use: "wait [-t TOKEN | [replication|snapshotting|prune_sender|prune_receiver JOB]]",
|
||||
Use: "wait [-t TOKEN | JOB INVOCATION [replication|snapshotting|prune_sender|prune_receiver]]",
|
||||
Short: "",
|
||||
Run: func(ctx context.Context, subcommand *cli.Subcommand, args []string) error {
|
||||
return runWaitCmd(subcommand.Config(), args)
|
||||
@@ -43,22 +42,16 @@ func runWaitCmd(config *config.Config, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var pollRequest daemon.ControlJobEndpointSignalActiveRequest
|
||||
var req daemon.ControlJobEndpointWaitActiveRequest
|
||||
if waitCmdArgs.token != "" {
|
||||
if len(args) != 0 {
|
||||
return fmt.Errorf("-t and regular usage is mutually exclusive")
|
||||
}
|
||||
err := json.Unmarshal([]byte(waitCmdArgs.token), &pollRequest)
|
||||
var token TriggerToken
|
||||
err := token.Decode(resetCmdArgs.token)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot unmarshal token")
|
||||
return errors.Wrap(err, "cannot decode token")
|
||||
}
|
||||
req = token.ToWait()
|
||||
} else {
|
||||
|
||||
if args[0] != "active" {
|
||||
panic(args)
|
||||
}
|
||||
args = args[1:]
|
||||
|
||||
jobName := args[0]
|
||||
|
||||
invocationId, err := strconv.ParseUint(args[1], 10, 64)
|
||||
@@ -66,14 +59,11 @@ func runWaitCmd(config *config.Config, args []string) error {
|
||||
return errors.Wrap(err, "parse invocation id")
|
||||
}
|
||||
|
||||
waitWhat := args[2]
|
||||
|
||||
// updated by subsequent requests
|
||||
pollRequest = daemon.ControlJobEndpointSignalActiveRequest{
|
||||
req = daemon.ControlJobEndpointWaitActiveRequest{
|
||||
Job: jobName,
|
||||
ActiveSidePollRequest: job.ActiveSidePollRequest{
|
||||
InvocationId: invocationId,
|
||||
What: waitWhat,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -83,10 +73,10 @@ func runWaitCmd(config *config.Config, args []string) error {
|
||||
pollOnce := func() error {
|
||||
var res job.ActiveSidePollResponse
|
||||
if waitCmdArgs.verbose {
|
||||
pretty.Println("making poll request", pollRequest)
|
||||
pretty.Println("making poll request", req)
|
||||
}
|
||||
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointPollActive,
|
||||
pollRequest,
|
||||
req,
|
||||
&res,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -101,7 +91,7 @@ func runWaitCmd(config *config.Config, args []string) error {
|
||||
return doneErr
|
||||
}
|
||||
|
||||
pollRequest.InvocationId = res.InvocationId
|
||||
req.InvocationId = res.InvocationId
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user