This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
.*: add list-member command #654
Merged
Merged
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fabfc8f
add get-leader command
GMHDBJD 3c6afe7
change help_cnt
GMHDBJD f1428ef
add get-leader tool
GMHDBJD 42f4e76
add get-leader integration test
GMHDBJD 6a57c43
add list-member command
GMHDBJD 76cb180
Merge remote-tracking branch 'upstream/master' into addGetLeaderCommand
GMHDBJD e79f07c
add list-member command
GMHDBJD 3a1fd03
fix useless change
GMHDBJD e2a64d9
Merge branch 'master' into addGetLeaderCommand
GMHDBJD 5fe7d6b
change inferface
GMHDBJD f88a59d
Merge branch 'addGetLeaderCommand' of https://github.com/gmhdbjd/dm i…
GMHDBJD 4d9b343
Merge branch 'master' into addGetLeaderCommand
GMHDBJD 608c304
add sleep
GMHDBJD 51ba9f2
Merge branch 'addGetLeaderCommand' of https://github.com/gmhdbjd/dm i…
GMHDBJD b0feea5
remove alive in listMemberLeader
GMHDBJD e59f7c4
add err for scheduler not started
GMHDBJD da734a8
add type and name flags
GMHDBJD 2bfe4b9
Merge remote-tracking branch 'upstream/master' into addGetLeaderCommand
GMHDBJD 63e96f6
add retry in test
GMHDBJD a8cf11d
Update dm/ctl/master/list_member.go
GMHDBJD 5cc9634
address comment
GMHDBJD 2dacb9a
remove type
GMHDBJD b559f33
Merge remote-tracking branch 'upstream/master' into addGetLeaderCommand
GMHDBJD 866d8c9
remove reset function
GMHDBJD 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 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 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,102 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package master | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/pingcap/dm/dm/ctl/common" | ||
"github.com/pingcap/dm/dm/pb" | ||
) | ||
|
||
var ( | ||
listMemberFlags = ListMemberFlags{} | ||
) | ||
|
||
// ListMemberFlags are flags that used in ListMember command | ||
type ListMemberFlags struct { | ||
names []string // specify names to list information | ||
} | ||
|
||
// Reset clears cache of ListMemberFlags | ||
func (c ListMemberFlags) Reset() { | ||
c.names = c.names[:0] | ||
} | ||
|
||
// NewListMemberCmd creates an ListMember command | ||
func NewListMemberCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list-member [--type leader/master/worker] [--name master-name/worker-name ...]", | ||
Short: "list member information", | ||
Run: listMemberFunc, | ||
} | ||
cmd.Flags().StringP("type", "t", "", "specify a member type from master, worker, and leader") | ||
lichunzhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cmd.Flags().StringSliceVarP(&listMemberFlags.names, "name", "n", []string{}, "specify member names in choosing type") | ||
return cmd | ||
} | ||
|
||
func convertListMemberType(t string) pb.MemberType { | ||
switch t { | ||
case "master": | ||
return pb.MemberType_MasterType | ||
case "worker": | ||
return pb.MemberType_WorkerType | ||
case "leader": | ||
return pb.MemberType_LeaderType | ||
case "": | ||
return pb.MemberType_AllType | ||
default: | ||
return pb.MemberType_InvalidType | ||
} | ||
} | ||
|
||
// listMemberFunc does list member request | ||
func listMemberFunc(cmd *cobra.Command, _ []string) { | ||
if len(cmd.Flags().Args()) != 0 { | ||
cmd.SetOut(os.Stdout) | ||
cmd.Usage() | ||
return | ||
} | ||
|
||
member, err := cmd.Flags().GetString("type") | ||
if err != nil { | ||
common.PrintLines("%s", errors.ErrorStack(err)) | ||
return | ||
} | ||
|
||
memType := convertListMemberType(member) | ||
lichunzhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if memType == pb.MemberType_InvalidType { | ||
common.PrintLines("invalid type '%s', choose from master, worker, and leader", member) | ||
return | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
cli := common.MasterClient() | ||
resp, err := cli.ListMember(ctx, &pb.ListMemberRequest{ | ||
MemType: memType, | ||
Names: listMemberFlags.names, | ||
}) | ||
|
||
if err != nil { | ||
common.PrintLines("list member failed, error:\n%v", errors.ErrorStack(err)) | ||
return | ||
} | ||
common.PrettyPrintResponse(resp) | ||
} |
This file contains 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 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
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.
Is this necessary? and where do we call this
Reset
?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.
Not necessary. I have removed it.