Skip to content

Commit

Permalink
Sync from server repo (11f1b2aaa7d)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Apr 12, 2024
1 parent 29d822a commit 969c321
Show file tree
Hide file tree
Showing 48 changed files with 248 additions and 1,109 deletions.
14 changes: 1 addition & 13 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ type cmdInterface interface {
Run(vcc vclusterops.ClusterCommands) error
SetDatabaseOptions(opt *vclusterops.DatabaseOptions)
SetParser(parser *pflag.FlagSet)
SetIPv6(cmd *cobra.Command)
setCommonFlags(cmd *cobra.Command, flags []string)
initCmdOutputFile() (*os.File, error)
}
Expand Down Expand Up @@ -399,19 +398,8 @@ func makeBasicCobraCmd(i cmdInterface, use, short, long string, commonFlags []st
return nil
},
}
// remove length check of commonFlags in VER-92369
if len(commonFlags) > 0 {
i.setCommonFlags(cmd, commonFlags)
}
return cmd
}
i.setCommonFlags(cmd, commonFlags)

// remove this function in VER-92369
// OldMakeBasicCobraCmd can make a basic cobra command for all vcluster commands.
// It will be called inside cmd_create_db.go, cmd_stop_db.go, ...
func OldMakeBasicCobraCmd(i cmdInterface, use, short, long string) *cobra.Command {
cmd := makeBasicCobraCmd(i, use, short, long, []string{})
i.SetIPv6(cmd)
return cmd
}

Expand Down
24 changes: 8 additions & 16 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ type CmdAddNode struct {
func makeCmdAddNode() *cobra.Command {
// CmdAddNode
newCmd := &CmdAddNode{}
newCmd.ipv6 = new(bool)
opt := vclusterops.VAddNodeOptionsFactory()
newCmd.addNodeOptions = &opt

cmd := OldMakeBasicCobraCmd(
cmd := makeBasicCobraCmd(
newCmd,
addNodeSubCmd,
"Add host(s) to an existing database",
Expand All @@ -72,12 +71,10 @@ Examples:
--data-path /data --hosts 10.20.30.40 \
--node-names v_test_db_node0001,v_test_db_node0002
`,
[]string{dbNameFlag, configFlag, hostsFlag, dataPathFlag, depotPathFlag,
passwordFlag},
)

// common db flags
newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, dataPathFlag, depotPathFlag,
passwordFlag})

// local flags
newCmd.setLocalFlags(cmd)

Expand Down Expand Up @@ -135,7 +132,7 @@ func (c *CmdAddNode) Parse(inputArgv []string, logger vlog.Printer) error {
// for some options, we do not want to use their default values,
// if they are not provided in cli,
// reset the value of those options to nil
c.OldResetUserInputOptions()
c.ResetUserInputOptions(&c.addNodeOptions.DatabaseOptions)
return c.validateParse(logger)
}

Expand Down Expand Up @@ -196,22 +193,17 @@ func (c *CmdAddNode) Run(vcc vclusterops.ClusterCommands) error {

options := c.addNodeOptions

// get config from vertica_cluster.yaml
config, err := options.GetDBConfig(vcc)
if err != nil {
return err
}
options.Config = config

vdb, addNodeError := vcc.VAddNode(options)
if addNodeError != nil {
return addNodeError
}
// write cluster information to the YAML config file
err = vdb.WriteClusterConfig(options.ConfigPath, vcc.GetLog())

// write db info to vcluster config file
err := writeConfig(&vdb, vcc.GetLog())
if err != nil {
vcc.PrintWarning("fail to write config file, details: %s", err)
}

vcc.PrintInfo("Added nodes %v to database %s", c.addNodeOptions.NewHosts, *options.DBName)
return nil
}
Expand Down
31 changes: 17 additions & 14 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand All @@ -41,11 +42,10 @@ type CmdAddSubcluster struct {
func makeCmdAddSubcluster() *cobra.Command {
// CmdAddSubcluster
newCmd := &CmdAddSubcluster{}
newCmd.ipv6 = new(bool)
opt := vclusterops.VAddSubclusterOptionsFactory()
newCmd.addSubclusterOptions = &opt

cmd := OldMakeBasicCobraCmd(
cmd := makeBasicCobraCmd(
newCmd,
addSCSubCmd,
"Add a subcluster",
Expand Down Expand Up @@ -77,12 +77,10 @@ Examples:
--hosts 10.20.30.40,10.20.30.41,10.20.30.42 \
--is-primary --control-set-size -1 --new-hosts 10.20.30.43
`,
[]string{dbNameFlag, configFlag, hostsFlag, eonModeFlag, passwordFlag,
dataPathFlag, depotPathFlag},
)

// common db flags
newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, passwordFlag,
dataPathFlag, depotPathFlag})

// local flags
newCmd.setLocalFlags(cmd)

Expand All @@ -93,6 +91,9 @@ Examples:
// require name of subcluster to add
markFlagsRequired(cmd, []string{subclusterFlag})

// hide eon mode flag since we expect it to come from config file, not from user input
hideLocalFlags(cmd, []string{eonModeFlag})

return cmd
}

Expand Down Expand Up @@ -163,6 +164,15 @@ func (c *CmdAddSubcluster) setHiddenFlags(cmd *cobra.Command) {
func (c *CmdAddSubcluster) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogMaskedArgParse(c.argv)

// reset some options that are not included in user input
c.ResetUserInputOptions(&c.addSubclusterOptions.DatabaseOptions)

// add_subcluster only works for an Eon db so we assume the user always runs this subcommand
// on an Eon db. When Eon mode cannot be found in config file, we set its value to true.
if !viper.IsSet(eonModeKey) {
c.addSubclusterOptions.IsEon = true
}
return c.validateParse(logger)
}

Expand Down Expand Up @@ -191,14 +201,7 @@ func (c *CmdAddSubcluster) Run(vcc vclusterops.ClusterCommands) error {

options := c.addSubclusterOptions

// get config from vertica_cluster.yaml
config, err := options.GetDBConfig(vcc)
if err != nil {
return err
}
options.Config = config

err = vcc.VAddSubcluster(options)
err := vcc.VAddSubcluster(options)
if err != nil {
vcc.LogError(err, "failed to add subcluster")
return err
Expand Down
34 changes: 4 additions & 30 deletions commands/cmd_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type CmdBase struct {
argv []string
parser *pflag.FlagSet

// remove below two fields in VER-92369
isEon *bool // need further processing to see if the user inputted this flag or not
ipv6 *bool // need further processing to see if the user inputted this flag or not
// for some commands like list_allnodes, we want to allow the output to be written
// to a file instead of being displayed in stdout. This is the file the output will
// be written to
Expand All @@ -60,12 +57,6 @@ func (c *CmdBase) ValidateParseBaseOptions(opt *vclusterops.DatabaseOptions) err
}
}

// remove IsEon and Ipv6 process below in VER-92369
// parse IsEon
opt.OldIsEon.FromBoolPointer(c.isEon)
// parse Ipv6
opt.OldIpv6.FromBoolPointer(c.ipv6)

return nil
}

Expand All @@ -74,19 +65,11 @@ func (c *CmdBase) SetParser(parser *pflag.FlagSet) {
c.parser = parser
}

// remove this function in VER-92369
// SetIPv6 can create the flag --ipv6 for a cobra command
func (c *CmdBase) SetIPv6(cmd *cobra.Command) {
cmd.Flags().BoolVar(
c.ipv6,
ipv6Flag,
false,
"Whether the hosts are using IPv6 addresses",
)
}

// setCommonFlags is a helper function to let subcommands set some shared flags among them
func (c *CmdBase) setCommonFlags(cmd *cobra.Command, flags []string) {
if len(flags) == 0 {
return
}
setConfigFlags(cmd, flags)
if util.StringInArray(passwordFlag, flags) {
c.setPasswordFlags(cmd)
Expand Down Expand Up @@ -218,7 +201,7 @@ func setConfigFlags(cmd *cobra.Command, flags []string) {
eonModeFlag,
false,
util.GetEonFlagMsg("indicate if the database is an Eon db."+
" Use it when you do not trust "+vclusterops.ConfigFileName))
" Use it when you do not trust the configuration file"))
}
if util.StringInArray(configParamFlag, flags) {
cmd.Flags().StringToStringVar(
Expand Down Expand Up @@ -263,15 +246,6 @@ func (c *CmdBase) ResetUserInputOptions(opt *vclusterops.DatabaseOptions) {
}
}

// remove this function in VER-92369
// OldResetUserInputOptions reset password and ipv6 options to nil in each command
// if they are not provided in cli
func (c *CmdBase) OldResetUserInputOptions() {
if !c.parser.Changed(ipv6Flag) {
c.ipv6 = nil
}
}

// setDBPassword sets the password option if one of the password flags
// is provided in the cli
func (c *CmdBase) setDBPassword(opt *vclusterops.DatabaseOptions) error {
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_config_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func makeCmdConfigRecover() *cobra.Command {
"recover the content of the config file",
`This subcommand is used to recover the content of the config file.
You must provide the all hosts that participate in the database.
You must provide all the hosts that participate in the database.
If there is an existing file at the provided config file location, the recover function
will not create a new config file unless you explicitly specify --overwrite.
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ You must specify the database name, host list, catalog path, and data path.
If --config is not provided, a configuration file is created in one of the
following locations, in order of precedence:
- path set in VCLUSTER_CONFIG environment variable
- if running vcluster from /opt/vertica/bin, in
/opt/vertica/config/vertica_config.yaml
- /opt/vertica/config/vertica_config.yaml if running vcluster from /opt/vertica/bin
- $HOME/.config/vcluster/vertica_config.yaml
You can pass --config-param a comma-separated list of NAME=VALUE pairs to set
Expand Down
30 changes: 15 additions & 15 deletions commands/cmd_drop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ type CmdDropDB struct {

func makeCmdDropDB() *cobra.Command {
newCmd := &CmdDropDB{}
newCmd.ipv6 = new(bool)
opt := vclusterops.VDropDatabaseOptionsFactory()
newCmd.dropDBOptions = &opt
newCmd.dropDBOptions.ForceDelete = new(bool)

// VER-92345 update the long description about the hosts option
cmd := OldMakeBasicCobraCmd(
cmd := makeBasicCobraCmd(
newCmd,
dropDBSubCmd,
"Drop a database",
`This subcommand drops a stopped database.
For an Eon database, communal storage is not deleted, so you can recover
For an Eon database, communal storage is not deleted. You can recover
the dropped database with revive_db.
The config file must be specified to retrieve host information. If the config
file path is not specified via --config, the default path will be used (refer
to create_db subcommand for information about how default config file path is
determined). When the command completes, the config file is removed.
to create_db subcommand for information about how the default config file path
is determined). When the command completes, the config file is removed.
To remove the local directories like catalog, depot, and data, you can use the
--force-delete option. The data deleted with this option is unrecoverable.
Expand All @@ -61,14 +60,15 @@ Examples:
vcluster drop_db --db-name test_db \
--config /opt/vertica/config/vertica_cluster.yaml
`,
[]string{dbNameFlag, configFlag, hostsFlag, catalogPathFlag, dataPathFlag, depotPathFlag},
)

// common db flags
newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag})

// local flags
newCmd.setLocalFlags(cmd)

// hide flags since we expect it to come from config file, not from user input
hideLocalFlags(cmd, []string{hostsFlag, catalogPathFlag, dataPathFlag, depotPathFlag})

return cmd
}

Expand All @@ -86,13 +86,6 @@ func (c *CmdDropDB) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogArgParse(&c.argv)

// for some options, we do not want to use their default values,
// if they are not provided in cli,
// reset the value of those options to nil
if !c.parser.Changed(ipv6Flag) {
c.CmdBase.ipv6 = nil
}

return c.validateParse(logger)
}

Expand All @@ -115,6 +108,13 @@ func (c *CmdDropDB) Run(vcc vclusterops.ClusterCommands) error {
}

vcc.PrintInfo("Successfully dropped database %s", *c.dropDBOptions.DBName)
// if the database is successfully dropped, the config file will be removed
// if failed to remove it, we will ask users to manually do it
err = removeConfig(vcc.GetLog())
if err != nil {
vcc.PrintWarning("Fail to remove config file %q, "+
"please manually do it. Details: %v", c.dropDBOptions.ConfigPath, err)
}
return nil
}

Expand Down
20 changes: 4 additions & 16 deletions commands/cmd_install_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ type CmdInstallPackages struct {
func makeCmdInstallPackages() *cobra.Command {
// CmdInstallPackages
newCmd := &CmdInstallPackages{}
newCmd.ipv6 = new(bool)
opt := vclusterops.VInstallPackagesOptionsFactory()
newCmd.installPkgOpts = &opt

cmd := OldMakeBasicCobraCmd(
cmd := makeBasicCobraCmd(
newCmd,
installPkgSubCmd,
"Install default package(s) in database",
Expand All @@ -61,12 +60,9 @@ Examples:
vcluster install_packages --db-name test_db --force-reinstall \
--config /opt/vertica/config/vertica_cluster.yaml
`,
[]string{dbNameFlag, configFlag, hostsFlag, passwordFlag, outputFileFlag},
)

// common db flags
newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, passwordFlag,
outputFileFlag})

// local flags
newCmd.setLocalFlags(cmd)

Expand All @@ -90,7 +86,7 @@ func (c *CmdInstallPackages) Parse(inputArgv []string, logger vlog.Printer) erro
// for some options, we do not want to use their default values,
// if they are not provided in cli,
// reset the value of those options to nil
c.OldResetUserInputOptions()
c.ResetUserInputOptions(&c.installPkgOpts.DatabaseOptions)

return c.validateParse()
}
Expand All @@ -116,15 +112,7 @@ func (c *CmdInstallPackages) Analyze(_ vlog.Printer) error {
func (c *CmdInstallPackages) Run(vcc vclusterops.ClusterCommands) error {
options := c.installPkgOpts

// get config from vertica_cluster.yaml
config, err := options.GetDBConfig(vcc)
if err != nil {
return err
}
options.Config = config

var status *vclusterops.InstallPackageStatus
status, err = vcc.VInstallPackages(options)
status, err := vcc.VInstallPackages(options)
if err != nil {
vcc.LogError(err, "failed to install the packages")
return err
Expand Down
Loading

0 comments on commit 969c321

Please sign in to comment.