-
Notifications
You must be signed in to change notification settings - Fork 70
Add command cluster create-failure-domain
#21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b4fa7eb
Add command cluster `get-peer-clusters`
zymap 18e6420
Add command cluster `create-failure-domain`
zymap 9904852
Fix typo
zymap 528e494
Add an empty line
zymap 919d4d0
Fix build
zymap b3721e6
Add stop cmd for Pulsar Functions (#25)
wolfstudy 664934d
Address comments
zymap 1e6457b
format code
zymap 064bb44
Add handler to handle test error (#27)
zymap ed3f709
Add command cluster `get-peer-clusters`
zymap 9b271e2
Add command cluster `create-failure-domain`
zymap 6366905
Fix typo
zymap 562ef27
Add an empty line
zymap 851cbf8
Fix build
zymap 3d4ccb6
Address comments
zymap a0d049a
format code
zymap a38ce86
address comments
zymap 0327cdb
Fix conflicts
zymap 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
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
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,94 @@ | ||
| package cluster | ||
|
|
||
| import ( | ||
| "errors" | ||
| "github.com/spf13/pflag" | ||
| "github.com/streamnative/pulsarctl/pkg/cmdutils" | ||
| "github.com/streamnative/pulsarctl/pkg/pulsar" | ||
| ) | ||
|
|
||
| func createFailureDomainCmd(vc *cmdutils.VerbCmd) { | ||
| var desc pulsar.LongDescription | ||
| desc.CommandUsedFor = "This command is used for creating a failure domain of the <cluster-name>." | ||
| desc.CommandPermission = "This command requires super-user permissions." | ||
|
|
||
| var examples []pulsar.Example | ||
| create := pulsar.Example{ | ||
| Desc: "create the failure domain", | ||
| Command: "pulsarctl clusters create-failure-domain <cluster-name> <domain-name>", | ||
| } | ||
| examples = append(examples, create) | ||
|
|
||
| createWithBrokers := pulsar.Example{ | ||
| Desc: "create the failure domain with brokers", | ||
| Command: "pulsarctl clusters create-failure-domain" + | ||
| " --broker-list <cluster-A> --broker-list <cluster-B> <cluster-name> <domain-name>", | ||
| } | ||
| examples = append(examples, createWithBrokers) | ||
| desc.CommandExamples = examples | ||
|
|
||
| var out []pulsar.Output | ||
| successOut := pulsar.Output{ | ||
| Desc: "normal output", | ||
| Out: "Create failure domain <domain-name> for cluster <cluster-name> succeed", | ||
| } | ||
| out = append(out, successOut) | ||
|
|
||
| argsErrorOut := pulsar.Output{ | ||
| Desc: "the args need to be specified as <cluster-name> <domain-name>", | ||
| Out: "[✖] need specified two names for cluster and failure domain", | ||
| } | ||
| out = append(out, argsErrorOut) | ||
| out = append(out, clusterNonExist) | ||
|
Member
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. clusterNonExist is for cluster commands. please make sure the error message is correct. |
||
| desc.CommandOutput = out | ||
|
|
||
| vc.SetDescription( | ||
| "create-failure-domain", | ||
| "Create a failure domain", | ||
| desc.ToString(), | ||
| "cfd") | ||
|
|
||
| var failureDomainData pulsar.FailureDomainData | ||
|
|
||
| vc.SetRunFuncWithNameArg(func() error { | ||
| return doCreateFailureDomain(vc, &failureDomainData) | ||
| }) | ||
|
|
||
| checkArgs := func(args []string) error { | ||
| if len(args) != 2 { | ||
| return errors.New("need to specified two names for cluster and failure domain") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| vc.SetRunFuncWithNameArgs(func() error { | ||
| return doCreateFailureDomain(vc, &failureDomainData) | ||
| }, checkArgs) | ||
|
|
||
| vc.FlagSetGroup.InFlagSet("FailureDomainData", func(set *pflag.FlagSet) { | ||
| set.StringSliceVarP( | ||
| &failureDomainData.BrokerList, | ||
| "broker-list", | ||
| "b", | ||
| nil, | ||
| "Set the failure domain clusters") | ||
| }) | ||
| } | ||
|
|
||
| func doCreateFailureDomain(vc *cmdutils.VerbCmd, failureDomain *pulsar.FailureDomainData) error { | ||
| failureDomain.ClusterName = vc.NameArgs[0] | ||
| failureDomain.DomainName = vc.NameArgs[1] | ||
|
|
||
| if len(failureDomain.BrokerList) == 0 || failureDomain.BrokerList == nil { | ||
| return errors.New("broker list must be specified") | ||
| } | ||
|
|
||
| admin := cmdutils.NewPulsarClient() | ||
| err := admin.Clusters().CreateFailureDomain(*failureDomain) | ||
| if err == nil { | ||
| vc.Command.Printf( | ||
| "Create failure domain [%s] for cluster [%s] succeed\n", | ||
| failureDomain.DomainName, failureDomain.ClusterName) | ||
| } | ||
| return err | ||
| } | ||
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,20 @@ | ||
| package cluster | ||
|
|
||
| import ( | ||
| "github.com/stretchr/testify/assert" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestCreateFailureDomainCmdSuccess(t *testing.T) { | ||
|
Member
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. please add test cases for failure cases. |
||
| args := []string{"create-failure-domain", "-b", "cluster-A", "standalone", "standalone-failure-domain"} | ||
| _, execErr, NameErr, err := TestClusterCommands(createFailureDomainCmd, args) | ||
| assert.Nil(t, execErr) | ||
| assert.Nil(t, NameErr) | ||
| assert.Nil(t, err) | ||
| } | ||
|
|
||
| func TestCreateFailureDomainCmdBrokerListError(t *testing.T) { | ||
| args := []string{"create-failure-domain", "standalone", "standalone-failure-domain"} | ||
| _, execErr, _, _ := TestClusterCommands(createFailureDomainCmd, args) | ||
| assert.Equal(t, "broker list must be specified", execErr.Error()) | ||
| } | ||
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
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
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
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
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.
does Pulsar allow creating a failure domain without a broker list?
I don't think that is a valid case.
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.
yes. I will check the broker list in pulsarctl.
Using pulsar-admin
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.
ok