-
Notifications
You must be signed in to change notification settings - Fork 719
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
pdctl: support show keyspace group primary #6747
Changes from 3 commits
94f2431
be30d79
0ab36f4
ddc2ae9
4a1f76a
6f12b4c
ff3da0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ func NewKeyspaceGroupCommand() *cobra.Command { | |
cmd.AddCommand(newFinishMergeKeyspaceGroupCommand()) | ||
cmd.AddCommand(newSetNodesKeyspaceGroupCommand()) | ||
cmd.AddCommand(newSetPriorityKeyspaceGroupCommand()) | ||
cmd.AddCommand(newShowKeyspaceGroupPrimaryCommand()) | ||
cmd.Flags().String("state", "", "state filter") | ||
return cmd | ||
} | ||
|
@@ -111,6 +112,15 @@ func newSetPriorityKeyspaceGroupCommand() *cobra.Command { | |
return r | ||
} | ||
|
||
func newShowKeyspaceGroupPrimaryCommand() *cobra.Command { | ||
r := &cobra.Command{ | ||
Use: "primary <keyspace_group_id>", | ||
Short: "show th primary of tso nodes for keyspace group with the given ID.", | ||
Run: showKeyspaceGroupPrimaryCommandFunc, | ||
} | ||
return r | ||
} | ||
|
||
func showKeyspaceGroupsCommandFunc(cmd *cobra.Command, args []string) { | ||
prefix := keyspaceGroupsPrefix | ||
if len(args) > 1 { | ||
|
@@ -337,6 +347,24 @@ func setPriorityKeyspaceGroupCommandFunc(cmd *cobra.Command, args []string) { | |
}) | ||
} | ||
|
||
func showKeyspaceGroupPrimaryCommandFunc(cmd *cobra.Command, args []string) { | ||
if len(args) < 1 { | ||
cmd.Usage() | ||
return | ||
} | ||
_, err := strconv.ParseUint(args[0], 10, 32) | ||
if err != nil { | ||
cmd.Printf("Failed to parse the keyspace group ID: %s\n", err) | ||
return | ||
} | ||
r, err := doRequest(cmd, fmt.Sprintf("%s/%s?get_param=primary", keyspaceGroupsPrefix, args[0]), http.MethodGet, http.Header{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be a bool, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "%s/%s?only_primary_member=" so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you can google it to find the best practice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it is better, "%s/%s?fields=primary" and return |
||
if err != nil { | ||
cmd.Printf("Failed to get the keyspace group primary information: %s\n", err) | ||
return | ||
} | ||
cmd.Println(r) | ||
} | ||
|
||
func convertToKeyspaceGroup(content string) string { | ||
kg := endpoint.KeyspaceGroup{} | ||
err := json.Unmarshal([]byte(content), &kg) | ||
|
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.
This code is duplicated in many places
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 will move them to mcsutil
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.
#6755