Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial meta stream move, pending fleshing out of server apis #521

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 48 additions & 1 deletion cli/server_raft_command.go
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"time"

"github.com/choria-io/fisk"
Expand All @@ -29,12 +30,17 @@ type SrvRaftCmd struct {
force bool
peer string
placementCluster string

moveServer string
moveAccount string
moveStream string
moveTags []string
}

func configureServerRaftCommand(srv *fisk.CmdClause) {
c := &SrvRaftCmd{}

raft := srv.Command("raft", "Manage JetStream Clustering").Alias("r")
raft := srv.Command("raft", "Manage JetStream Clustering").Alias("r").Alias("jetstream")
raft.Flag("json", "Produce JSON output").Short('j').UnNegatableBoolVar(&c.json)

sd := raft.Command("step-down", "Force a new leader election by standing down the current meta leader").Alias("stepdown").Alias("sd").Alias("elect").Alias("down").Alias("d").Action(c.metaLeaderStandDown)
Expand All @@ -43,6 +49,47 @@ func configureServerRaftCommand(srv *fisk.CmdClause) {
rm := raft.Command("peer-remove", "Removes a server from a JetStream cluster").Alias("rm").Alias("pr").Action(c.metaPeerRemove)
rm.Arg("name", "The Server Name to remove from the JetStream cluster").StringVar(&c.peer)
rm.Flag("force", "Force removal without prompting").Short('f').UnNegatableBoolVar(&c.force)

move := raft.Command("stream-move", "Moves a stream between servers").Hidden().Action(c.metaStreamMove)
move.Arg("server", "The name of the server to move the stream from").StringVar(&c.moveServer)
move.Arg("account", "The account the stream belong to").StringVar(&c.moveAccount)
move.Arg("stream", "The stream to move").StringVar(&c.moveStream)
move.Flag("tags", "Placement tags to use when deciding the new location for the stream").StringsVar(&c.moveTags)
}

func (c *SrvRaftCmd) metaStreamMove(_ *fisk.ParseContext) error {
nc, mgr, err := prepareHelper("", natsOpts()...)
if err != nil {
return err
}

res, err := doReq(server.JSzOptions{LeaderOnly: true}, "$SYS.REQ.SERVER.PING.JSZ", 1, nc)
if err != nil {
return err
}

if len(res) != 1 {
return fmt.Errorf("did not receive a response from the meta leader, ensure the account used has system privileges and appropriate permissions")
}

if len(c.moveTags) == 0 {
fmt.Printf("Moving %s > %s from %s\n", c.moveAccount, c.moveStream, c.moveServer)
} else {
fmt.Printf("Moving %s > %s from %s using placement tags %s\n", c.moveAccount, c.moveStream, c.moveServer, strings.Join(c.moveTags, ", "))
}

resp, err := mgr.MetaServerStreamMove(&api.JSApiMetaServerStreamMoveRequest{
Server: c.moveServer,
Account: c.moveAccount,
Stream: c.moveStream,
Tags: c.moveTags,
})
if err != nil {
return err
}

fmt.Printf("%#v\n", resp)
return nil
}

func (c *SrvRaftCmd) metaPeerRemove(_ *fisk.ParseContext) error {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -15,8 +15,8 @@ require (
github.com/guptarohit/asciigraph v0.5.5
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/klauspost/compress v1.15.7
github.com/nats-io/jsm.go v0.0.34-0.20220624081812-70883a58262d
github.com/nats-io/nats-server/v2 v2.8.5-0.20220629014533-b0580cdfc297
github.com/nats-io/jsm.go v0.0.34-0.20220701100907-3739476a382f
github.com/nats-io/nats-server/v2 v2.8.5-0.20220630223440-b7d94e1b5211
github.com/nats-io/nats.go v1.16.1-0.20220610202224-dcbb65a13ee9
github.com/nats-io/nuid v1.0.1
github.com/prometheus/client_golang v1.12.2
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Expand Up @@ -205,14 +205,14 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jsm.go v0.0.34-0.20220624081812-70883a58262d h1:JX28FB+sJPXxjKqAWw7xIXg1Tlhg5cxFQ7eQFD6pwXY=
github.com/nats-io/jsm.go v0.0.34-0.20220624081812-70883a58262d/go.mod h1:D++29QW9omjSpsq5gjrIPwZQiupi4cb3eq7zSPjJ2Cg=
github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/jsm.go v0.0.34-0.20220701094016-c245a42e1221 h1:kxxSBBeDNTvBKiJbZgpw7RQX1WZ8Qshkcr8qq+TDPuQ=
github.com/nats-io/jsm.go v0.0.34-0.20220701094016-c245a42e1221/go.mod h1:QGmPROy+VAkQ2y170WYZDVbz/PmoZduVhOaopVX7PjQ=
github.com/nats-io/jsm.go v0.0.34-0.20220701100907-3739476a382f h1:kkPiBgHvvyIq0Le9vPC/n0qHLnByZv9u2Q9EHiHBGwc=
github.com/nats-io/jsm.go v0.0.34-0.20220701100907-3739476a382f/go.mod h1:QGmPROy+VAkQ2y170WYZDVbz/PmoZduVhOaopVX7PjQ=
github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220603052622-d836076443f5/go.mod h1:lZPG1sK+0r7tR7Q89EcpiuJnqF8y1PtYNC5Cz69RPko=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220629014533-b0580cdfc297 h1:aTCxMfooHOM3pnjQPN5bfRJ4NZczmdmQL0Zft5Oq7NI=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220629014533-b0580cdfc297/go.mod h1:qiP3Ix8tErhcbkuzM7khoLXB+EWy9Zpl1IJPivFk37s=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220630223440-b7d94e1b5211 h1:x35AjlxVvVbF+iBe7DKtq/l/6wJGgxRew2YkOW4kkA0=
github.com/nats-io/nats-server/v2 v2.8.5-0.20220630223440-b7d94e1b5211/go.mod h1:DDSswj1ITPghvnFXGoj+aP13Zq5vTX40YJaqtiEYYkQ=
github.com/nats-io/nats.go v1.16.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nats.go v1.16.1-0.20220610202224-dcbb65a13ee9 h1:gHTW4UDAOW6j9SA2DLE7aZg7cxVixYzLyestoU0ukyA=
github.com/nats-io/nats.go v1.16.1-0.20220610202224-dcbb65a13ee9/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
Expand Down