This repository was archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add node, disk, server, remote-command related command #1
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5366d54
init
foreverneverer 05f2ee2
init
foreverneverer c24280a
init
foreverneverer e26b0ca
add file save
foreverneverer 087df73
update
foreverneverer fd9d6df
update
foreverneverer 1e9579a
update
foreverneverer 5899beb
update
foreverneverer 767d5c6
update
foreverneverer 01bada9
update
foreverneverer 84d5919
update
foreverneverer b21f2b3
update
foreverneverer 447db7e
merge
foreverneverer 41508a6
update
foreverneverer 3f21566
add gpid serialize test
foreverneverer 65a5b59
update
foreverneverer b537a14
update
foreverneverer f290ed4
update
foreverneverer dbffe83
update
foreverneverer b43efd9
add remote command
foreverneverer e4a45cf
add remote command
foreverneverer d4ae741
add remote command
foreverneverer e8269ad
add remote command
foreverneverer 3512891
add remote command
foreverneverer 64f8b12
format remote command
foreverneverer 5ecdc2f
refomater
foreverneverer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| bin/ | ||
| .admin-cli-history | ||
| pegasus.log | ||
| .idea | ||
| shell.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "admin-cli/executor" | ||
| "admin-cli/shell" | ||
|
|
||
| "github.com/desertbit/grumble" | ||
| ) | ||
|
|
||
| func init() { | ||
| shell.AddCommand(&grumble.Command{ | ||
| Name: "disk-migrate", | ||
| Help: "migrate replica between the two disks within a specified ReplicaServer node", | ||
| Flags: func(f *grumble.Flags) { | ||
| /*define the flags*/ | ||
| f.String("g", "gpid", "", "gpid, for example, '2.1'") | ||
| f.String("n", "node", "", "target node, for example, 127.0.0.1:34801") | ||
| f.String("f", "from", "", "origin disk tag, for example, ssd1") | ||
| f.String("t", "to", "", "target disk tag, for example, ssd2") | ||
| }, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.DiskMigrate( | ||
| pegasusClient, | ||
| c.Flags.String("node"), | ||
| c.Flags.String("gpid"), | ||
| c.Flags.String("from"), | ||
| c.Flags.String("to")) | ||
| }, | ||
| }) | ||
|
|
||
| // TODO(jiashuo1) need generate migrate strategy(step) depends the disk-info result to run | ||
| shell.AddCommand(&grumble.Command{ | ||
| Name: "disk-balance", | ||
| Help: "migrate replica automatically to let the disk capacity balance within a specified ReplicaServer node", | ||
| Flags: func(f *grumble.Flags) { | ||
| /*define the flags*/ | ||
| }, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.DiskBalance() | ||
| }, | ||
| }) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "admin-cli/executor" | ||
| "admin-cli/shell" | ||
|
|
||
| "github.com/desertbit/grumble" | ||
| ) | ||
|
|
||
| func init() { | ||
| shell.AddCommand(&grumble.Command{ | ||
| Name: "disk-capacity", | ||
| Help: "query disk capacity info ", | ||
| Flags: func(f *grumble.Flags) { | ||
| /*define the flags*/ | ||
| f.Bool("r", "resolve", false, "resolve input or output address, default false") | ||
| f.Bool("j", "json", false, "use JSON as the format of the output results. By default tabular format is used.") | ||
| f.String("n", "node", "", "node address(ip:port), for example, 127.0.0.1:34801") | ||
| f.String("d", "disk", "", "disk tag, for example, ssd1") | ||
| f.String("a", "app", "", "app name, for example, temp") | ||
| }, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.QueryDiskInfo( | ||
| pegasusClient, | ||
| executor.CapacitySize, | ||
| c.Flags.String("node"), | ||
| c.Flags.String("app"), | ||
| c.Flags.String("disk")) | ||
| }, | ||
| }) | ||
|
|
||
| shell.AddCommand(&grumble.Command{ | ||
| Name: "disk-replica", | ||
| Help: "query disk replica count info", | ||
| Flags: func(f *grumble.Flags) { | ||
| /*define the flags*/ | ||
| f.Bool("r", "resolve", false, "resolve input or output address, default false") | ||
| f.Bool("j", "json", false, "use JSON as the format of the output results. By default tabular format is used.") | ||
| f.String("n", "node", "", "node address(ip:port), for example, 127.0.0.1:34801") | ||
| f.String("a", "app", "", "app name, for example, temp") | ||
| }, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.QueryDiskInfo( | ||
| pegasusClient, | ||
| executor.ReplicaCount, | ||
| c.Flags.String("node"), | ||
| c.Flags.String("app"), | ||
| "") | ||
| }, | ||
| }) | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "admin-cli/executor" | ||
| "admin-cli/shell" | ||
| "github.com/desertbit/grumble" | ||
| ) | ||
|
|
||
| func init() { | ||
| shell.AddCommand(&grumble.Command{ | ||
| Name: "list-nodes", | ||
| Aliases: []string{"nodes"}, | ||
| Help: "list all nodes in the cluster", | ||
| Flags: func(f *grumble.Flags) { | ||
| f.Bool("d", "detail", false, "show detail replica count in all node") | ||
| }, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.ListNodes( | ||
| pegasusClient, | ||
| c.Flags.Bool("detail"), | ||
| ) | ||
| }, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "admin-cli/executor" | ||
| "github.com/desertbit/grumble" | ||
| ) | ||
|
|
||
| func init() { | ||
| rootCmd := &grumble.Command{ | ||
| Name: "remote-command", | ||
| Help: "send remote command, for example, remote-command meta or replica", | ||
| } | ||
|
|
||
| rootCmd.AddCommand(&grumble.Command{ | ||
| Name: "meta", | ||
| Help: "send remote command to meta server", | ||
| Flags: initFlag, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.RemoteCommand(pegasusClient, "meta", c.Flags.String("node"), c.Flags.String("command"), c.Flags.String("arguments")) | ||
| }, | ||
| }) | ||
|
|
||
| rootCmd.AddCommand(&grumble.Command{ | ||
| Name: "replica", | ||
| Help: "send remote command to replica server", | ||
| Flags: initFlag, | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.RemoteCommand(pegasusClient, "replica", c.Flags.String("node"), c.Flags.String("command"), c.Flags.String("arguments")) | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func initFlag(f *grumble.Flags) { | ||
| /*define the flags*/ | ||
| f.String("n", "node", "", "specify server node address, such as 127.0.0.1:34801, empty mean all node") | ||
| f.String("c", "command", "help", "remote command name, you can -c help to see support command") | ||
| f.String("a", "arguments", "", "if empty means query the command argument value, otherwise mean set update value") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "admin-cli/executor" | ||
| "admin-cli/shell" | ||
|
|
||
| "github.com/desertbit/grumble" | ||
| ) | ||
|
|
||
| func init() { | ||
| shell.AddCommand(&grumble.Command{ | ||
| Name: "server-info", | ||
| Help: "displays the overall server information", | ||
| Run: func(c *grumble.Context) error { | ||
| return executor.ServerInfo(pegasusClient) | ||
| }, | ||
| }) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package executor | ||
|
|
||
| import ( | ||
| "admin-cli/helper" | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/XiaoMi/pegasus-go-client/idl/radmin" | ||
| ) | ||
|
|
||
| func DiskMigrate(client *Client, replicaServer string, pidStr string, from string, to string) error { | ||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
| defer cancel() | ||
|
|
||
| var addr, err = helper.Resolve(replicaServer, helper.Host2Addr) | ||
| if err == nil { | ||
| replicaServer = addr | ||
| } | ||
|
|
||
| pid, err := helper.Str2Gpid(pidStr) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| replicaClient, err := client.GetReplicaClient(replicaServer) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| resp, err := replicaClient.DiskMigrate(ctx, &radmin.ReplicaDiskMigrateRequest{ | ||
| Pid: pid, | ||
| OriginDisk: from, | ||
| TargetDisk: to, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| if resp != nil && resp.Hint != nil { | ||
| return fmt.Errorf("Internal server error [%s:%s]", err, *resp.Hint) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // TODO(jiashuo1) need generate migrate strategy(step) depends the disk-info result to run | ||
| func DiskBalance() error { | ||
| fmt.Println("Wait support") | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use PerfClient instead, PerfSession is low level primitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know
PerfClient, I only use one node session to query counter, but query all node and then filter one of them