- Notifications
You must be signed in to change notification settings - Fork 2.9k
Add quorum commands to CLI #17570
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
Add quorum commands to CLI #17570
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
| * (the "License"). You may not use this work except in compliance with the License, which is | ||
| * available at www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
| * either express or implied, as more fully set forth in the License. | ||
| * | ||
| * See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
| */ | ||
| | ||
| package quorum | ||
| | ||
| import ( | ||
| "github.com/palantir/stacktrace" | ||
| "github.com/spf13/cobra" | ||
| | ||
| "alluxio.org/cli/env" | ||
| ) | ||
| | ||
| var Elect = &ElectCommand{ | ||
| QuorumCommand: &QuorumCommand{ | ||
| BaseJavaCommand: &env.BaseJavaCommand{ | ||
| CommandName: "elect", | ||
| JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell", | ||
| Parameters: []string{"journal", "quorum", "elect"}, | ||
| }, | ||
| allowedDomains: []string{domainMaster}, | ||
| }, | ||
| } | ||
| | ||
| type ElectCommand struct { | ||
| *QuorumCommand | ||
| | ||
| serverAddress string | ||
| } | ||
| | ||
| func (c *ElectCommand) ToCommand() *cobra.Command { | ||
| cmd := c.Base().InitRunJavaClassCmd(&cobra.Command{ | ||
| Use: Elect.CommandName, | ||
| Short: "Transfers leadership of the quorum to the specified server", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return c.Run(nil) | ||
| }, | ||
| }) | ||
| | ||
| const address = "address" | ||
| cmd.Flags().StringVar(&c.serverAddress, address, "", "Address of new leader server in the format <hostname>:<port>") | ||
| if err := cmd.MarkFlagRequired(address); err != nil { | ||
| panic(err) | ||
| } | ||
| return cmd | ||
| } | ||
| | ||
| func (c *ElectCommand) Run(_ []string) error { | ||
| if err := checkDomain(c.QuorumCommand.domain, c.QuorumCommand.allowedDomains...); err != nil { | ||
| Contributor 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. for validation I think a better tool would be https://github.com/go-playground/validator. | ||
| return stacktrace.Propagate(err, "error checking domain %v", c.QuorumCommand.domain) | ||
| } | ||
| // TODO: ignore the domain flag for now since elect command can only operate on MASTER | ||
| // java command needs to be updated such that it can accept the domain flag | ||
| return c.Base().Run([]string{"-address", c.serverAddress}) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
| * (the "License"). You may not use this work except in compliance with the License, which is | ||
| * available at www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
| * either express or implied, as more fully set forth in the License. | ||
| * | ||
| * See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
| */ | ||
| | ||
| package quorum | ||
| | ||
| import ( | ||
| "github.com/spf13/cobra" | ||
| | ||
| "alluxio.org/cli/env" | ||
| ) | ||
| | ||
| var Info = &InfoCommand{ | ||
| QuorumCommand: &QuorumCommand{ | ||
| BaseJavaCommand: &env.BaseJavaCommand{ | ||
| CommandName: "info", | ||
| JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell", | ||
| Parameters: []string{"journal", "quorum", "info"}, | ||
| }, | ||
| allowedDomains: []string{domainJobMaster, domainMaster}, | ||
| }, | ||
| } | ||
| | ||
| type InfoCommand struct { | ||
| *QuorumCommand | ||
| } | ||
| | ||
| func (c *InfoCommand) ToCommand() *cobra.Command { | ||
| cmd := c.QuorumCommand.InitQuorumCmd(c.Base().InitRunJavaClassCmd(&cobra.Command{ | ||
| Use: Info.CommandName, | ||
| Short: "Shows quorum information", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return c.Run(nil) | ||
| }, | ||
| })) | ||
| return cmd | ||
| } | ||
| | ||
| func (c *InfoCommand) Run(_ []string) error { | ||
| return c.QuorumCommand.Run(nil) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||
| /* | ||||||
| * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||||||
| * (the "License"). You may not use this work except in compliance with the License, which is | ||||||
| * available at www.apache.org/licenses/LICENSE-2.0 | ||||||
| * | ||||||
| * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||||||
| * either express or implied, as more fully set forth in the License. | ||||||
| * | ||||||
| * See the NOTICE file distributed with this work for information regarding copyright ownership. | ||||||
| */ | ||||||
| | ||||||
| package quorum | ||||||
| | ||||||
| import ( | ||||||
| "fmt" | ||||||
| "strings" | ||||||
| | ||||||
| "github.com/palantir/stacktrace" | ||||||
| "github.com/spf13/cobra" | ||||||
| | ||||||
| "alluxio.org/cli/env" | ||||||
| ) | ||||||
| | ||||||
| var ( | ||||||
| Service = &env.Service{ | ||||||
| Name: "quorum", | ||||||
| Description: "Manage the high availability server quorum, such as electing a new leader", | ||||||
| Commands: []env.Command{ | ||||||
| Elect, | ||||||
| Info, | ||||||
| Remove, | ||||||
| }, | ||||||
| } | ||||||
| ) | ||||||
| | ||||||
| const ( | ||||||
| domainJobMaster = "JOB_MASTER" | ||||||
| domainMaster = "MASTER" | ||||||
| ) | ||||||
| | ||||||
| type QuorumCommand struct { | ||||||
| *env.BaseJavaCommand | ||||||
| | ||||||
| allowedDomains []string | ||||||
| domain string | ||||||
| Contributor 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. Using validator. Suggested change
| ||||||
| } | ||||||
| | ||||||
| func (c *QuorumCommand) Base() *env.BaseJavaCommand { | ||||||
| return c.BaseJavaCommand | ||||||
| } | ||||||
| | ||||||
| func (c *QuorumCommand) InitQuorumCmd(cmd *cobra.Command) *cobra.Command { | ||||||
| const domain = "domain" | ||||||
| cmd.Flags().StringVar(&c.domain, domain, "", fmt.Sprintf("Quorum domain to operate on, must be one of %v", strings.Join(c.allowedDomains, ", "))) | ||||||
| if err := cmd.MarkFlagRequired(domain); err != nil { | ||||||
| panic(err) | ||||||
| } | ||||||
| return cmd | ||||||
| } | ||||||
| | ||||||
| func (c *QuorumCommand) Run(args []string) error { | ||||||
| if err := checkDomain(c.domain, c.allowedDomains...); err != nil { | ||||||
| return stacktrace.Propagate(err, "error checking domain %v", c.domain) | ||||||
| } | ||||||
| var javaArgs []string | ||||||
| javaArgs = append(javaArgs, args...) | ||||||
| javaArgs = append(javaArgs, "-domain", c.domain) | ||||||
| return c.Base().Run(javaArgs) | ||||||
| } | ||||||
| | ||||||
| func checkDomain(domain string, allowedDomains ...string) error { | ||||||
| for _, d := range allowedDomains { | ||||||
| if domain == d { | ||||||
| return nil | ||||||
| } | ||||||
| } | ||||||
| return stacktrace.NewError("domain is %v but must be one of %v", domain, strings.Join(allowedDomains, ",")) | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||
| /* | ||||||
| * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||||||
| * (the "License"). You may not use this work except in compliance with the License, which is | ||||||
| * available at www.apache.org/licenses/LICENSE-2.0 | ||||||
| * | ||||||
| * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||||||
| * either express or implied, as more fully set forth in the License. | ||||||
| * | ||||||
| * See the NOTICE file distributed with this work for information regarding copyright ownership. | ||||||
| */ | ||||||
| | ||||||
| package quorum | ||||||
| | ||||||
| import ( | ||||||
| "github.com/spf13/cobra" | ||||||
| | ||||||
| "alluxio.org/cli/env" | ||||||
| ) | ||||||
| | ||||||
| var Remove = &RemoveCommand{ | ||||||
| QuorumCommand: &QuorumCommand{ | ||||||
| BaseJavaCommand: &env.BaseJavaCommand{ | ||||||
| CommandName: "remove", | ||||||
| JavaClassName: "alluxio.cli.fsadmin.FileSystemAdminShell", | ||||||
| Parameters: []string{"journal", "quorum", "remove"}, | ||||||
| }, | ||||||
| allowedDomains: []string{domainJobMaster, domainMaster}, | ||||||
| }, | ||||||
| } | ||||||
| | ||||||
| type RemoveCommand struct { | ||||||
| *QuorumCommand | ||||||
| | ||||||
| serverAddress string | ||||||
| Contributor 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. With validator. Suggested change
| ||||||
| } | ||||||
| | ||||||
| func (c *RemoveCommand) ToCommand() *cobra.Command { | ||||||
| cmd := c.QuorumCommand.InitQuorumCmd(c.Base().InitRunJavaClassCmd(&cobra.Command{ | ||||||
| Use: Remove.CommandName, | ||||||
| Short: "Removes the specified server from the quorum", | ||||||
| RunE: func(cmd *cobra.Command, args []string) error { | ||||||
| return c.Run(nil) | ||||||
| }, | ||||||
| })) | ||||||
| const address = "address" | ||||||
| cmd.Flags().StringVar(&c.serverAddress, address, "", "Address of server in the format <hostname>:<port>") | ||||||
| if err := cmd.MarkFlagRequired(address); err != nil { | ||||||
| panic(err) | ||||||
| } | ||||||
| return cmd | ||||||
| } | ||||||
| | ||||||
| func (c *RemoveCommand) Run(_ []string) error { | ||||||
| return c.QuorumCommand.Run([]string{"-address", c.serverAddress}) | ||||||
| } | ||||||
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.
can use the
hostname_portvalidator for this as well