diff --git a/commands/cluster_command_launcher.go b/commands/cluster_command_launcher.go index 200020e..adbeb93 100644 --- a/commands/cluster_command_launcher.go +++ b/commands/cluster_command_launcher.go @@ -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) } @@ -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 } diff --git a/commands/cmd_add_node.go b/commands/cmd_add_node.go index d789f64..a16acc9 100644 --- a/commands/cmd_add_node.go +++ b/commands/cmd_add_node.go @@ -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", @@ -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) @@ -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) } @@ -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 } diff --git a/commands/cmd_add_subcluster.go b/commands/cmd_add_subcluster.go index 90ef061..75d7b2b 100644 --- a/commands/cmd_add_subcluster.go +++ b/commands/cmd_add_subcluster.go @@ -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" @@ -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", @@ -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) @@ -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 } @@ -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) } @@ -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 diff --git a/commands/cmd_base.go b/commands/cmd_base.go index e7da365..e6ea124 100644 --- a/commands/cmd_base.go +++ b/commands/cmd_base.go @@ -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 @@ -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 } @@ -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) @@ -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( @@ -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 { diff --git a/commands/cmd_config_recover.go b/commands/cmd_config_recover.go index 460c150..54b6a08 100644 --- a/commands/cmd_config_recover.go +++ b/commands/cmd_config_recover.go @@ -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. diff --git a/commands/cmd_create_db.go b/commands/cmd_create_db.go index eea068f..7eda090 100644 --- a/commands/cmd_create_db.go +++ b/commands/cmd_create_db.go @@ -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 diff --git a/commands/cmd_drop_db.go b/commands/cmd_drop_db.go index 2d44ff4..cce0fdc 100644 --- a/commands/cmd_drop_db.go +++ b/commands/cmd_drop_db.go @@ -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. @@ -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 } @@ -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) } @@ -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 } diff --git a/commands/cmd_install_packages.go b/commands/cmd_install_packages.go index fb0e903..c7636d5 100644 --- a/commands/cmd_install_packages.go +++ b/commands/cmd_install_packages.go @@ -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", @@ -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) @@ -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() } @@ -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 diff --git a/commands/cmd_list_all_nodes.go b/commands/cmd_list_all_nodes.go index ba8e7d4..b51df15 100644 --- a/commands/cmd_list_all_nodes.go +++ b/commands/cmd_list_all_nodes.go @@ -36,7 +36,6 @@ type CmdListAllNodes struct { func makeListAllNodes() *cobra.Command { newCmd := &CmdListAllNodes{} - newCmd.ipv6 = new(bool) opt := vclusterops.VFetchNodeStateOptionsFactory() newCmd.fetchNodeStateOptions = &opt @@ -76,7 +75,7 @@ func (c *CmdListAllNodes) 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.fetchNodeStateOptions.DatabaseOptions) return c.validateParse(logger) } diff --git a/commands/cmd_re_ip.go b/commands/cmd_re_ip.go index e839a98..f8b6354 100644 --- a/commands/cmd_re_ip.go +++ b/commands/cmd_re_ip.go @@ -36,11 +36,10 @@ type CmdReIP struct { func makeCmdReIP() *cobra.Command { newCmd := &CmdReIP{} - newCmd.ipv6 = new(bool) opt := vclusterops.VReIPFactory() newCmd.reIPOptions = &opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, reIPSubCmd, "Re-ip database nodes", @@ -67,11 +66,9 @@ Examples: vcluster re_ip --db-name test_db --re-ip-file /data/re_ip_map.json \ --config /opt/vertica/config/vertica_cluster.yaml `, + []string{dbNameFlag, hostsFlag, catalogPathFlag, configParamFlag, configFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, catalogPathFlag, configParamFlag, configFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -127,14 +124,6 @@ func (c *CmdReIP) Run(vcc vclusterops.ClusterCommands) error { canUpdateConfig = false } - // VER-92369 should clean up the block below - // as the GetDBConfig function will be removed - config, err := options.GetDBConfig(vcc) - if err != nil { - return err - } - options.Config = config - err = vcc.VReIP(options) if err != nil { vcc.LogError(err, "fail to re-ip") diff --git a/commands/cmd_remove_node.go b/commands/cmd_remove_node.go index 881f5f2..78209f9 100644 --- a/commands/cmd_remove_node.go +++ b/commands/cmd_remove_node.go @@ -37,11 +37,10 @@ type CmdRemoveNode struct { func makeCmdRemoveNode() *cobra.Command { // CmdRemoveNode newCmd := &CmdRemoveNode{} - newCmd.ipv6 = new(bool) opt := vclusterops.VRemoveNodeOptionsFactory() newCmd.removeNodeOptions = &opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, removeNodeSubCmd, "Remove host(s) from an existing database", @@ -62,12 +61,9 @@ Examples: vcluster db_remove_node --db-name test_db --remove 10.20.30.42 \ --hosts 10.20.30.40 --data-path /data `, + []string{dbNameFlag, configFlag, hostsFlag, catalogPathFlag, dataPathFlag, depotPathFlag, passwordFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, dataPathFlag, - depotPathFlag, passwordFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -100,7 +96,7 @@ func (c *CmdRemoveNode) 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.removeNodeOptions.DatabaseOptions) return c.validateParse(logger) } @@ -142,25 +138,18 @@ func (c *CmdRemoveNode) Run(vcc vclusterops.ClusterCommands) error { options := c.removeNodeOptions - // get config from vertica_cluster.yaml - config, err := c.removeNodeOptions.GetDBConfig(vcc) + vdb, err := vcc.VRemoveNode(options) if err != nil { return err } - options.Config = config - vdb, err := vcc.VRemoveNode(options) + // write db info to vcluster config file + err = writeConfig(&vdb, vcc.GetLog()) if err != nil { - return err + vcc.PrintWarning("fail to write config file, details: %s", err) } vcc.PrintInfo("Successfully removed nodes %v from database %s", c.removeNodeOptions.HostsToRemove, *options.DBName) - // write cluster information to the YAML config file. - err = vdb.WriteClusterConfig(options.ConfigPath, vcc.GetLog()) - if err != nil { - vcc.PrintWarning("failed to write config file, details: %s", err) - } - vcc.PrintInfo("Successfully updated config file") return nil } diff --git a/commands/cmd_remove_subcluster.go b/commands/cmd_remove_subcluster.go index bcbccf1..a5ad52d 100644 --- a/commands/cmd_remove_subcluster.go +++ b/commands/cmd_remove_subcluster.go @@ -17,6 +17,7 @@ package commands import ( "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/vertica/vcluster/vclusterops" "github.com/vertica/vcluster/vclusterops/vlog" ) @@ -34,11 +35,10 @@ type CmdRemoveSubcluster struct { func makeCmdRemoveSubcluster() *cobra.Command { // CmdRemoveSubcluster newCmd := &CmdRemoveSubcluster{} - newCmd.ipv6 = new(bool) opt := vclusterops.VRemoveScOptionsFactory() newCmd.removeScOptions = &opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, removeSCSubCmd, "Remove a subcluster", @@ -59,17 +59,18 @@ Examples: --hosts 10.20.30.40,10.20.30.41,10.20.30.42 --subcluster sc1 \ --data-path /data --depot-path /data `, + []string{dbNameFlag, configFlag, hostsFlag, eonModeFlag, dataPathFlag, depotPathFlag, passwordFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, dataPathFlag, depotPathFlag, passwordFlag}) - // local flags newCmd.setLocalFlags(cmd) // require name of subcluster to remove 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 } @@ -92,6 +93,15 @@ func (c *CmdRemoveSubcluster) setLocalFlags(cmd *cobra.Command) { func (c *CmdRemoveSubcluster) 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.removeScOptions.DatabaseOptions) + + // remove_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.removeScOptions.IsEon = true + } return c.validateParse(logger) } @@ -118,27 +128,19 @@ func (c *CmdRemoveSubcluster) Run(vcc vclusterops.ClusterCommands) error { options := c.removeScOptions - // get config from vertica_cluster.yaml - config, err := c.removeScOptions.GetDBConfig(vcc) + vdb, err := vcc.VRemoveSubcluster(options) if err != nil { return err } - options.Config = config - vdb, err := vcc.VRemoveSubcluster(options) + // write db info to vcluster config file + err = writeConfig(&vdb, vcc.GetLog()) if err != nil { - return err + vcc.PrintWarning("fail to write config file, details: %s", err) } vcc.PrintInfo("Successfully removed subcluster %s from database %s", *options.SubclusterToRemove, *options.DBName) - // write cluster information to the YAML config file. - err = vdb.WriteClusterConfig(options.ConfigPath, vcc.GetLog()) - if err != nil { - vcc.PrintWarning("failed to write config file, details: %s", err) - } - vcc.PrintInfo("Successfully updated config file") - return nil } diff --git a/commands/cmd_restart_node.go b/commands/cmd_restart_node.go index 05d2dfe..63f5f61 100644 --- a/commands/cmd_restart_node.go +++ b/commands/cmd_restart_node.go @@ -37,11 +37,10 @@ type CmdRestartNodes struct { func makeCmdRestartNodes() *cobra.Command { // CmdRestartNodes newCmd := &CmdRestartNodes{} - newCmd.ipv6 = new(bool) opt := vclusterops.VStartNodesOptionsFactory() newCmd.restartNodesOptions = &opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, restartNodeSubCmd, "Restart nodes in the database", @@ -71,11 +70,9 @@ Examples: --restart v_test_db_node0003=10.20.30.42,v_test_db_node0004=10.20.30.43 \ --password testpassword --config /opt/vertica/config/vertica_cluster.yaml `, + []string{dbNameFlag, hostsFlag, configFlag, passwordFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, configFlag, passwordFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -108,7 +105,7 @@ func (c *CmdRestartNodes) 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.restartNodesOptions.DatabaseOptions) return c.validateParse(logger) } @@ -137,16 +134,8 @@ func (c *CmdRestartNodes) Run(vcc vclusterops.ClusterCommands) error { options := c.restartNodesOptions - // load vdb info from the YAML config file - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig(vcc) - if err != nil { - return err - } - options.Config = config - // this is the instruction that will be used by both CLI and operator - err = vcc.VStartNodes(options) + err := vcc.VStartNodes(options) if err != nil { return err } diff --git a/commands/cmd_revive_db.go b/commands/cmd_revive_db.go index 6da1c4d..2ba2903 100644 --- a/commands/cmd_revive_db.go +++ b/commands/cmd_revive_db.go @@ -36,12 +36,11 @@ type CmdReviveDB struct { func makeCmdReviveDB() *cobra.Command { // CmdReviveDB newCmd := &CmdReviveDB{} - newCmd.ipv6 = new(bool) opt := vclusterops.VReviveDBOptionsFactory() newCmd.reviveDBOptions = &opt newCmd.reviveDBOptions.CommunalStorageLocation = new(string) - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, reviveDBSubCmd, "Revive a database", @@ -53,7 +52,7 @@ If access to communal storage requires access keys, these can be provided through the --config-param option. You must also specify a set of hosts that matches the number of hosts when the -database was running. You can omit the hosts only if --diplays-only +database was running. You can omit the hosts only if --display-only is specified. The name of the database must be provided. @@ -64,7 +63,7 @@ by either --restore-point-index or --restore-point-id (not both). Examples: # Revive a database with user input and save the generated config file - # under given directory + # under the given directory vcluster revive_db --db-name test_db \ --hosts 10.20.30.40,10.20.30.41,10.20.30.42 \ --communal-storage-location /communal \ @@ -82,12 +81,9 @@ Examples: --ignore-cluster-lease --restore-point-archive db --restore-point-index 1 `, + []string{dbNameFlag, hostsFlag, communalStorageLocationFlag, configFlag, outputFileFlag, configParamFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, communalStorageLocationFlag, - configFlag, outputFileFlag, configParamFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -152,13 +148,6 @@ func (c *CmdReviveDB) 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.ipv6 = nil - } - return c.validateParse(logger) } @@ -192,7 +181,8 @@ func (c *CmdReviveDB) Run(vcc vclusterops.ClusterCommands) error { return nil } - err = vdb.WriteClusterConfig(c.reviveDBOptions.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) } diff --git a/commands/cmd_sandbox.go b/commands/cmd_sandbox.go index a372276..0d10653 100644 --- a/commands/cmd_sandbox.go +++ b/commands/cmd_sandbox.go @@ -42,11 +42,10 @@ func (c *CmdSandboxSubcluster) TypeName() string { func makeCmdSandboxSubcluster() *cobra.Command { // CmdSandboxSubcluster newCmd := &CmdSandboxSubcluster{} - newCmd.ipv6 = new(bool) opt := vclusterops.VSandboxOptionsFactory() newCmd.sbOptions = opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, sandboxSubCmd, "Sandbox a subcluster", @@ -70,11 +69,9 @@ Examples: vcluster sandbox_subcluster --subcluster sc1 --sandbox sand \ --hosts 10.20.30.40,10.20.30.41,10.20.30.42 --db-name test_db `, + []string{dbNameFlag, configFlag, hostsFlag, passwordFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, passwordFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -132,13 +129,8 @@ func (c *CmdSandboxSubcluster) Run(vcc vclusterops.ClusterCommands) error { vcc.LogInfo("Calling method Run() for command " + sandboxSubCmd) options := c.sbOptions - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig(vcc) - if err != nil { - return err - } - options.Config = config - err = vcc.VSandbox(&options) + + err := vcc.VSandbox(&options) vcc.PrintInfo("Completed method Run() for command " + sandboxSubCmd) return err } diff --git a/commands/cmd_scrutinize.go b/commands/cmd_scrutinize.go index e0169c1..ba8579d 100644 --- a/commands/cmd_scrutinize.go +++ b/commands/cmd_scrutinize.go @@ -28,7 +28,6 @@ import ( "github.com/spf13/cobra" "github.com/vertica/vcluster/vclusterops" "github.com/vertica/vcluster/vclusterops/vlog" - "github.com/vertica/vcluster/vclusterops/vstruct" "github.com/vertica/vertica-kubernetes/pkg/secrets" ) @@ -79,13 +78,11 @@ type CmdScrutinize struct { func makeCmdScrutinize() *cobra.Command { newCmd := &CmdScrutinize{} - newCmd.isEon = new(bool) - newCmd.ipv6 = new(bool) opt := vclusterops.VScrutinizeOptionsFactory() newCmd.sOptions = opt newCmd.secretStoreRetriever = secretStoreRetrieverStruct{} - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, scrutinizeSubCmd, "Scrutinize a database", @@ -106,11 +103,9 @@ Examples: vcluster scrutinize --db-name test_db --db-user dbadmin \ --password testpassword --config /opt/vertica/config/vertica_cluster.yaml `, + []string{dbNameFlag, hostsFlag, configFlag, catalogPathFlag, passwordFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, configFlag, passwordFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -198,13 +193,7 @@ func (c *CmdScrutinize) 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() - - // remove eomModeFlag check in VER-92369 - // just so generic parsing works - not relevant for functionality - if !c.parser.Changed(eonModeFlag) { - c.sOptions.OldIsEon = vstruct.NotSet - } + c.ResetUserInputOptions(&c.sOptions.DatabaseOptions) // if the tarballName was provided in the cli, we check // if it matches GRASP regex @@ -258,13 +247,6 @@ func (c *CmdScrutinize) Run(vcc vclusterops.ClusterCommands) error { return err } - // get config from vertica_cluster.yaml (if exists) - config, err := c.sOptions.GetDBConfig(vcc) - if err != nil { - return err - } - c.sOptions.Config = config - err = vcc.VScrutinize(&c.sOptions) if err != nil { vcc.LogError(err, "scrutinize run failed") diff --git a/commands/cmd_show_restore_points.go b/commands/cmd_show_restore_points.go index e94bd75..e0988e4 100644 --- a/commands/cmd_show_restore_points.go +++ b/commands/cmd_show_restore_points.go @@ -33,11 +33,10 @@ type CmdShowRestorePoints struct { func makeCmdShowRestorePoints() *cobra.Command { // CmdShowRestorePoints newCmd := &CmdShowRestorePoints{} - newCmd.ipv6 = new(bool) opt := vclusterops.VShowRestorePointsFactory() newCmd.showRestorePointsOptions = &opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, showRestorePointsSubCmd, "Query and list restore point(s) in archive(s)", @@ -78,12 +77,10 @@ Examples: --start-timestamp 2024-03-04 08:32:33.277569 \ --end-timestamp 2024-03-04 08:32:34.176391 `, + []string{dbNameFlag, configFlag, passwordFlag, hostsFlag, + communalStorageLocationFlag, configParamFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, passwordFlag, hostsFlag, - communalStorageLocationFlag, configParamFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -131,7 +128,7 @@ func (c *CmdShowRestorePoints) Parse(inputArgv []string, logger vlog.Printer) er // 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.showRestorePointsOptions.DatabaseOptions) return c.validateParse(logger) } @@ -160,11 +157,6 @@ func (c *CmdShowRestorePoints) Run(vcc vclusterops.ClusterCommands) error { vcc.V(1).Info("Called method Run()") options := c.showRestorePointsOptions - config, err := options.GetDBConfig(vcc) - if err != nil { - return err - } - options.Config = config restorePoints, err := vcc.VShowRestorePoints(options) if err != nil { diff --git a/commands/cmd_start_db.go b/commands/cmd_start_db.go index 7283611..ec7a8a3 100644 --- a/commands/cmd_start_db.go +++ b/commands/cmd_start_db.go @@ -40,13 +40,11 @@ type CmdStartDB struct { func makeCmdStartDB() *cobra.Command { // CmdStartDB newCmd := &CmdStartDB{} - newCmd.isEon = new(bool) - newCmd.ipv6 = new(bool) opt := vclusterops.VStartDatabaseOptionsFactory() newCmd.startDBOptions = &opt newCmd.startDBOptions.CommunalStorageLocation = new(string) - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, startDBSubCmd, "Start a database", @@ -69,12 +67,10 @@ Examples: vcluster start_db --password testpassword \ --config /opt/vertica/config/vertica_cluster.yaml `, + []string{dbNameFlag, hostsFlag, communalStorageLocationFlag, + configFlag, catalogPathFlag, passwordFlag, eonModeFlag, configParamFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, communalStorageLocationFlag, - configFlag, catalogPathFlag, passwordFlag, eonModeFlag, configParamFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -141,16 +137,7 @@ func (c *CmdStartDB) Parse(inputArgv []string, logger vlog.Printer) error { c.argv = inputArgv logger.LogMaskedArgParse(c.argv) - // remove eonModeFlag check in VER-92369 - // 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(eonModeFlag) { - c.CmdBase.isEon = nil - } else { - *c.CmdBase.isEon = true - } - c.OldResetUserInputOptions() + c.ResetUserInputOptions(&c.startDBOptions.DatabaseOptions) return c.validateParse(logger) } @@ -174,16 +161,6 @@ func (c *CmdStartDB) Run(vcc vclusterops.ClusterCommands) error { options := c.startDBOptions - // VER-92369 should clean up the block below - // as the GetDBConfig function will be removed - // load vdb info from the YAML config file - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig(vcc) - if err != nil { - return err - } - options.Config = config - vdb, err := vcc.VStartDatabase(options) if err != nil { vcc.LogError(err, "failed to start the database") @@ -193,7 +170,7 @@ func (c *CmdStartDB) Run(vcc vclusterops.ClusterCommands) error { vcc.PrintInfo("Successfully start the database %s", *options.DBName) // for Eon database, update config file to fill nodes' subcluster information - if options.OldIsEon.ToBool() { + if options.IsEon { // write db info to vcluster config file err := writeConfig(vdb, vcc.GetLog()) if err != nil { diff --git a/commands/cmd_start_replication.go b/commands/cmd_start_replication.go index e3fa47d..bd36a6f 100644 --- a/commands/cmd_start_replication.go +++ b/commands/cmd_start_replication.go @@ -147,7 +147,7 @@ func (c *CmdStartReplication) Parse(inputArgv []string, logger vlog.Printer) err // 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.startRepOptions.DatabaseOptions) // replication only works for an Eon db // When eon mode cannot be found in config file, we set its value to true diff --git a/commands/cmd_stop_db.go b/commands/cmd_stop_db.go index 0194556..1607320 100644 --- a/commands/cmd_stop_db.go +++ b/commands/cmd_stop_db.go @@ -117,7 +117,7 @@ func (c *CmdStopDB) 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.stopDBOptions.DatabaseOptions) if !c.parser.Changed("drain-seconds") { c.stopDBOptions.DrainSeconds = nil diff --git a/commands/cmd_unsandbox.go b/commands/cmd_unsandbox.go index 819cbbc..ec8a755 100644 --- a/commands/cmd_unsandbox.go +++ b/commands/cmd_unsandbox.go @@ -41,11 +41,10 @@ func (c *CmdUnsandboxSubcluster) TypeName() string { func makeCmdUnsandboxSubcluster() *cobra.Command { // CmdUnsandboxSubcluster newCmd := &CmdUnsandboxSubcluster{} - newCmd.ipv6 = new(bool) opt := vclusterops.VUnsandboxOptionsFactory() newCmd.usOptions = opt - cmd := OldMakeBasicCobraCmd( + cmd := makeBasicCobraCmd( newCmd, unsandboxSubCmd, "Unsandbox a subcluster", @@ -74,11 +73,9 @@ Examples: vcluster unsandbox_subcluster --subcluster sc1 \ --hosts 10.20.30.40,10.20.30.41,10.20.30.42 --db-name test_db `, + []string{dbNameFlag, configFlag, passwordFlag, hostsFlag}, ) - // common db flags - newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, passwordFlag, hostsFlag}) - // local flags newCmd.setLocalFlags(cmd) @@ -133,13 +130,7 @@ func (c *CmdUnsandboxSubcluster) Run(vcc vclusterops.ClusterCommands) error { options := c.usOptions - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig(vcc) - if err != nil { - return err - } - options.Config = config - err = vcc.VUnsandbox(&options) + err := vcc.VUnsandbox(&options) vcc.PrintInfo("Completed method Run() for command " + unsandboxSubCmd) return err } diff --git a/commands/init.go b/commands/init.go index 58667e3..cbfa328 100644 --- a/commands/init.go +++ b/commands/init.go @@ -15,12 +15,7 @@ limitations under the License. package commands func init() { - // move below memory allocation code to setDefaultValues() in - // vcluster_database_options.go in VER-92369 - // allocate memory to Password and LogPath for flags parse dbOptions.Password = new(string) - dbOptions.LogPath = new(string) - // set the log path depending on executable path setLogPath() diff --git a/commands/vcluster_config.go b/commands/vcluster_config.go index f5c0df0..c200197 100644 --- a/commands/vcluster_config.go +++ b/commands/vcluster_config.go @@ -159,13 +159,13 @@ func loadConfigToViper() error { dbConfig := MakeDatabaseConfig() err = viper.Unmarshal(&dbConfig) if err != nil { - fmt.Printf("Warning: fail to unmarshal config file into DatabaseConfig: %v\n", err) + fmt.Printf("Warning: fail to unmarshal configuration file into DatabaseConfig: %v\n", err) return nil } // if we can read config file, check if dbName in user input matches the one in config file if viper.IsSet(dbNameKey) && dbConfig.Name != viper.GetString(dbNameKey) { - return fmt.Errorf("database %q does not match name found in the config file %q", dbConfig.Name, viper.GetString(dbNameKey)) + return fmt.Errorf("database %q does not match name found in the configuration file %q", dbConfig.Name, viper.GetString(dbNameKey)) } // hosts, catalogPrefix, dataPrefix, depotPrefix are special in config file, @@ -190,7 +190,7 @@ func loadConfigToViper() error { // It will be called in the end of some subcommands that will change the db state. func writeConfig(vdb *vclusterops.VCoordinationDatabase, logger vlog.Printer) error { if dbOptions.ConfigPath == "" { - return fmt.Errorf("config path is empty") + return fmt.Errorf("configuration file path is empty") } dbConfig, err := readVDBToDBConfig(vdb) @@ -214,6 +214,22 @@ func writeConfig(vdb *vclusterops.VCoordinationDatabase, logger vlog.Printer) er return nil } +// removeConfig remove the config file vertica_cluster.yaml. +// It will be called in the end of drop_db subcommands. +func removeConfig(logger vlog.Printer) error { + if dbOptions.ConfigPath == "" { + return fmt.Errorf("configuration file path is empty") + } + // back up the old config file + err := backupConfigFile(dbOptions.ConfigPath, logger) + if err != nil { + return err + } + + // remove the old db config + return os.Remove(dbOptions.ConfigPath) +} + // readVDBToDBConfig converts vdb to DatabaseConfig func readVDBToDBConfig(vdb *vclusterops.VCoordinationDatabase) (DatabaseConfig, error) { dbConfig := MakeDatabaseConfig() @@ -262,7 +278,7 @@ func backupConfigFile(configFilePath string, logger vlog.Printer) error { // copy file to vertica_cluster.yaml.backup configDirPath := filepath.Dir(configFilePath) configFileBackup := filepath.Join(configDirPath, configBackupName) - logger.Info("Config file exists and, creating a backup", "config file", configFilePath, + logger.Info("Configuration file exists and, creating a backup", "config file", configFilePath, "backup file", configFileBackup) err := util.CopyFile(configFilePath, configFileBackup, configFilePerm) if err != nil { @@ -279,17 +295,17 @@ func readConfig() (dbConfig *DatabaseConfig, err error) { configFilePath := dbOptions.ConfigPath if configFilePath == "" { - return nil, fmt.Errorf("no config file provided") + return nil, fmt.Errorf("configuration file path is empty") } configBytes, err := os.ReadFile(configFilePath) if err != nil { - return nil, fmt.Errorf("fail to read config file, details: %w", err) + return nil, fmt.Errorf("fail to read configuration file, details: %w", err) } var config Config err = yaml.Unmarshal(configBytes, &config) if err != nil { - return nil, fmt.Errorf("fail to unmarshal config file, details: %w", err) + return nil, fmt.Errorf("fail to unmarshal configuration file, details: %w", err) } return &config.Database, nil @@ -306,11 +322,11 @@ func (c *DatabaseConfig) write(configFilePath string) error { configBytes, err := yaml.Marshal(&config) if err != nil { - return fmt.Errorf("fail to marshal config data, details: %w", err) + return fmt.Errorf("fail to marshal configuration data, details: %w", err) } err = os.WriteFile(configFilePath, configBytes, configFilePerm) if err != nil { - return fmt.Errorf("fail to write config file, details: %w", err) + return fmt.Errorf("fail to write configuration file, details: %w", err) } return nil diff --git a/vclusterops/add_node.go b/vclusterops/add_node.go index f9fae00..e19a1c6 100644 --- a/vclusterops/add_node.go +++ b/vclusterops/add_node.go @@ -94,7 +94,7 @@ func (o *VAddNodeOptions) validateParseOptions(logger vlog.Printer) error { // analyzeOptions will modify some options based on what is chosen func (o *VAddNodeOptions) analyzeOptions() (err error) { - o.NewHosts, err = util.ResolveRawHostsToAddresses(o.NewHosts, o.OldIpv6.ToBool()) + o.NewHosts, err = util.ResolveRawHostsToAddresses(o.NewHosts, o.IPv6) if err != nil { return err } @@ -102,7 +102,7 @@ func (o *VAddNodeOptions) analyzeOptions() (err error) { // we analyze host names when it is set in user input, otherwise we use hosts in yaml config // resolve RawHosts to be IP addresses if len(o.RawHosts) > 0 { - o.Hosts, err = util.ResolveRawHostsToAddresses(o.RawHosts, o.OldIpv6.ToBool()) + o.Hosts, err = util.ResolveRawHostsToAddresses(o.RawHosts, o.IPv6) if err != nil { return err } @@ -126,20 +126,7 @@ func (o *VAddNodeOptions) validateAnalyzeOptions(logger vlog.Printer) error { func (vcc VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDatabase, error) { vdb := makeVCoordinationDatabase() - // set db name and hosts - err := options.setDBNameAndHosts() - if err != nil { - return vdb, err - } - - // get depot and data prefix from config file or options. - // after VER-88122, we will able to get them from an https endpoint. - *options.DepotPrefix, *options.DataPrefix, err = options.getDepotAndDataPrefix(options.Config) - if err != nil { - return vdb, err - } - - err = options.validateAnalyzeOptions(vcc.Log) + err := options.validateAnalyzeOptions(vcc.Log) if err != nil { return vdb, err } diff --git a/vclusterops/add_subcluster.go b/vclusterops/add_subcluster.go index 44dc2c0..bd04b41 100644 --- a/vclusterops/add_subcluster.go +++ b/vclusterops/add_subcluster.go @@ -86,14 +86,8 @@ func (options *VAddSubclusterOptions) validateRequiredOptions(logger vlog.Printe return nil } -func (options *VAddSubclusterOptions) validateEonOptions(config *DatabaseConfig) error { - isEon, err := options.isEonMode(config) - if err != nil { - return err - } - - if !isEon && config != nil { - // config file confirms that the db is not Eon +func (options *VAddSubclusterOptions) validateEonOptions() error { + if !options.IsEon { return fmt.Errorf("add subcluster is only supported in Eon mode") } return nil @@ -135,14 +129,14 @@ func (options *VAddSubclusterOptions) validateExtraOptions(logger vlog.Printer) return nil } -func (options *VAddSubclusterOptions) validateParseOptions(config *DatabaseConfig, vcc VClusterCommands) error { +func (options *VAddSubclusterOptions) validateParseOptions(vcc VClusterCommands) error { // batch 1: validate required parameters err := options.validateRequiredOptions(vcc.Log) if err != nil { return err } // batch 2: validate eon params - err = options.validateEonOptions(config) + err = options.validateEonOptions() if err != nil { return err } @@ -159,7 +153,7 @@ func (options *VAddSubclusterOptions) analyzeOptions() (err error) { // we analyze hostnames when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -167,7 +161,7 @@ func (options *VAddSubclusterOptions) analyzeOptions() (err error) { // resolve SCRawHosts to be IP addresses if len(options.SCRawHosts) > 0 { - options.SCHosts, err = util.ResolveRawHostsToAddresses(options.SCRawHosts, options.OldIpv6.ToBool()) + options.SCHosts, err = util.ResolveRawHostsToAddresses(options.SCRawHosts, options.IPv6) if err != nil { return err } @@ -176,8 +170,8 @@ func (options *VAddSubclusterOptions) analyzeOptions() (err error) { return nil } -func (options *VAddSubclusterOptions) validateAnalyzeOptions(config *DatabaseConfig, vcc VClusterCommands) error { - if err := options.validateParseOptions(config, vcc); err != nil { +func (options *VAddSubclusterOptions) validateAnalyzeOptions(vcc VClusterCommands) error { + if err := options.validateParseOptions(vcc); err != nil { return err } err := options.analyzeOptions() @@ -196,14 +190,8 @@ func (vcc VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) error * - Give the instructions to the VClusterOpEngine to run */ - // set db name and hosts - err := options.setDBNameAndHosts() - if err != nil { - return err - } - // validate and analyze all options - err = options.validateAnalyzeOptions(options.Config, vcc) + err := options.validateAnalyzeOptions(vcc) if err != nil { return err } diff --git a/vclusterops/coordinator_database.go b/vclusterops/coordinator_database.go index 66659ae..8b652a3 100644 --- a/vclusterops/coordinator_database.go +++ b/vclusterops/coordinator_database.go @@ -68,25 +68,14 @@ func makeVCoordinationDatabase() VCoordinationDatabase { return VCoordinationDatabase{} } -func (vdb *VCoordinationDatabase) setFromCreateDBOptions(options *VCreateDatabaseOptions, logger vlog.Printer) error { - // build after validating the options - err := options.validateAnalyzeOptions(logger) - if err != nil { - return err - } - - // build coordinate db object from the create db options - // section 1: set db info +func (vdb *VCoordinationDatabase) setFromBasicDBOptions(options *VCreateDatabaseOptions) error { + // we trust the information in the config file + // so we do not perform validation here vdb.Name = *options.DBName vdb.CatalogPrefix = *options.CatalogPrefix vdb.DataPrefix = *options.DataPrefix - vdb.HostList = make([]string, len(options.Hosts)) - vdb.HostList = options.Hosts - vdb.HostNodeMap = makeVHostNodeMap() - vdb.LicensePathOnNode = *options.LicensePathOnNode - vdb.Ipv6 = options.IPv6 + vdb.DepotPrefix = *options.DepotPrefix - // section 2: eon info vdb.IsEon = false if *options.CommunalStorageLocation != "" { vdb.IsEon = true @@ -94,27 +83,52 @@ func (vdb *VCoordinationDatabase) setFromCreateDBOptions(options *VCreateDatabas vdb.DepotPrefix = *options.DepotPrefix vdb.DepotSize = *options.DepotSize } + vdb.UseDepot = false if *options.DepotPrefix != "" { vdb.UseDepot = true } - if *options.GetAwsCredentialsFromEnv { - err := vdb.getAwsCredentialsFromEnv() + + vdb.HostNodeMap = makeVHostNodeMap() + for _, address := range options.Hosts { + vnode := VCoordinationNode{} + err := vnode.setFromBasicDBOptions(options, address) + if err != nil { + return err + } + err = vdb.addNode(&vnode) if err != nil { return err } } - vdb.NumShards = *options.ShardCount - // section 3: build VCoordinationNode info - for _, host := range vdb.HostList { - vNode := makeVCoordinationNode() - err := vNode.setFromCreateDBOptions(options, host) + return nil +} + +func (vdb *VCoordinationDatabase) setFromCreateDBOptions(options *VCreateDatabaseOptions, logger vlog.Printer) error { + // build after validating the options + err := options.validateAnalyzeOptions(logger) + if err != nil { + return err + } + + err = vdb.setFromBasicDBOptions(options) + if err != nil { + return err + } + + // set additional db info from the create db options + vdb.HostList = make([]string, len(options.Hosts)) + vdb.HostList = options.Hosts + vdb.LicensePathOnNode = *options.LicensePathOnNode + + if *options.GetAwsCredentialsFromEnv { + err := vdb.getAwsCredentialsFromEnv() if err != nil { return err } - vdb.HostNodeMap[host] = &vNode } + vdb.NumShards = *options.ShardCount return nil } @@ -144,12 +158,7 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string, scName string) error return fmt.Errorf("could not generate a vnode name for %s", host) } nodeNameToHost[name] = host - nodeConfig := NodeConfig{ - Address: host, - Name: name, - Subcluster: scName, - } - vNode.setFromNodeConfig(&nodeConfig, vdb) + vNode.setNode(vdb, host, name, scName) err := vdb.addNode(&vNode) if err != nil { return err @@ -159,46 +168,6 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string, scName string) error return nil } -func (vdb *VCoordinationDatabase) setFromClusterConfig(dbName string, - dbConfig *DatabaseConfig) error { - // if db name from user input is different than the one in config file, - // we throw an error - if dbConfig.Name != dbName { - return cannotFindDBFromConfigErr(dbName) - } - - // we trust the information in the config file - // so we do not perform validation here - vdb.Name = dbName - - catalogPrefix, dataPrefix, depotPrefix, err := dbConfig.getPathPrefix(dbName) - if err != nil { - return err - } - vdb.CatalogPrefix = catalogPrefix - vdb.DataPrefix = dataPrefix - vdb.DepotPrefix = depotPrefix - - vdb.IsEon = dbConfig.IsEon - vdb.CommunalStorageLocation = dbConfig.CommunalStorageLocation - vdb.Ipv6 = dbConfig.Ipv6 - if vdb.DepotPrefix != "" { - vdb.UseDepot = true - } - - vdb.HostNodeMap = makeVHostNodeMap() - for _, nodeConfig := range dbConfig.Nodes { - vnode := VCoordinationNode{} - vnode.setFromNodeConfig(nodeConfig, vdb) - err = vdb.addNode(&vnode) - if err != nil { - return err - } - } - - return nil -} - // copy copies the receiver's fields into a new VCoordinationDatabase struct and // returns that struct. You can choose to copy only a subset of the receiver's hosts // by passing a slice of hosts to keep. @@ -369,7 +338,7 @@ func makeVCoordinationNode() VCoordinationNode { return VCoordinationNode{} } -func (vnode *VCoordinationNode) setFromCreateDBOptions( +func (vnode *VCoordinationNode) setFromBasicDBOptions( options *VCreateDatabaseOptions, host string, ) error { @@ -405,12 +374,12 @@ func (vnode *VCoordinationNode) setFromCreateDBOptions( return fmt.Errorf("fail to set up vnode from options: host %s does not exist in options", host) } -func (vnode *VCoordinationNode) setFromNodeConfig(nodeConfig *NodeConfig, vdb *VCoordinationDatabase) { +func (vnode *VCoordinationNode) setNode(vdb *VCoordinationDatabase, address, name, scName string) { // we trust the information in the config file // so we do not perform validation here - vnode.Address = nodeConfig.Address - vnode.Name = nodeConfig.Name - vnode.Subcluster = nodeConfig.Subcluster + vnode.Address = address + vnode.Name = name + vnode.Subcluster = scName vnode.CatalogPath = vdb.genCatalogPath(vnode.Name) dataPath := vdb.genDataPath(vnode.Name) vnode.StorageLocations = append(vnode.StorageLocations, dataPath) @@ -423,72 +392,3 @@ func (vnode *VCoordinationNode) setFromNodeConfig(nodeConfig *NodeConfig, vdb *V vnode.ControlAddressFamily = util.DefaultControlAddressFamily } } - -// remove this function in VER-92369 -// WriteClusterConfig updates cluster configuration with the YAML-formatted file in the configPath -// and writes to the log and stdout. -// It returns any error encountered. -func (vdb *VCoordinationDatabase) WriteClusterConfig(configPath string, logger vlog.Printer) error { - // Early out if this config path not provided. This just means there is no - // config file to write out. No error is provided as the config file is - // meant to cache frequently specified items on the command line. - if configPath == "" { - return nil - } - - logger.Info("vdb content", "vdb", fmt.Sprintf("%+v", *vdb)) - - /* build config information - */ - dbConfig := MakeDatabaseConfig() - // loop over HostList is needed as we want to preserve the order - for _, host := range vdb.HostList { - vnode, ok := vdb.HostNodeMap[host] - if !ok { - return fmt.Errorf("cannot find host %s from HostNodeMap", host) - } - logger.Info("vnode content", "vnode", fmt.Sprintf("%+v", *vnode)) - nodeConfig := NodeConfig{} - nodeConfig.Name = vnode.Name - nodeConfig.Address = vnode.Address - nodeConfig.Subcluster = vnode.Subcluster - - // VER-91869 will replace the path prefixes with full paths - if vdb.CatalogPrefix == "" { - nodeConfig.CatalogPath = util.GetPathPrefix(vnode.CatalogPath) - } else { - nodeConfig.CatalogPath = vdb.CatalogPrefix - } - if vdb.DataPrefix == "" && len(vnode.StorageLocations) > 0 { - nodeConfig.DataPath = util.GetPathPrefix(vnode.StorageLocations[0]) - } else { - nodeConfig.DataPath = vdb.DataPrefix - } - if vdb.IsEon && vdb.DepotPrefix == "" { - nodeConfig.DepotPath = util.GetPathPrefix(vnode.DepotPath) - } else { - nodeConfig.DepotPath = vdb.DepotPrefix - } - - dbConfig.Nodes = append(dbConfig.Nodes, &nodeConfig) - } - dbConfig.IsEon = vdb.IsEon - dbConfig.CommunalStorageLocation = vdb.CommunalStorageLocation - dbConfig.Ipv6 = vdb.Ipv6 - dbConfig.Name = vdb.Name - - // if the config file exists already - // create its backup before overwriting it - err := backupConfigFile(configPath, logger) - if err != nil { - return err - } - - // update db config with the given database info - err = dbConfig.WriteConfig(configPath, logger) - if err != nil { - return err - } - - return nil -} diff --git a/vclusterops/create_db_test.go b/vclusterops/create_db_test.go index 9650f4d..f89b912 100644 --- a/vclusterops/create_db_test.go +++ b/vclusterops/create_db_test.go @@ -16,16 +16,9 @@ package vclusterops import ( - "bytes" - "fmt" - "os" - "path/filepath" "testing" "github.com/stretchr/testify/assert" - - "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) const defaultPath = "/data" @@ -58,53 +51,3 @@ func TestValidateDepotSize(t *testing.T) { assert.Equal(t, res, true) assert.Nil(t, err) } - -func TestWriteClusterConfig(t *testing.T) { - const dbName = "practice_db" - const scName = "default_subcluster" - - // generate a YAML file based on a stub vdb - vdb := VCoordinationDatabase{} - vdb.Name = dbName - vdb.CatalogPrefix = defaultPath - vdb.DataPrefix = defaultPath - vdb.DepotPrefix = defaultPath - vdb.HostList = []string{"ip_1", "ip_2", "ip_3"} - vdb.HostNodeMap = makeVHostNodeMap() - for i, h := range vdb.HostList { - n := VCoordinationNode{} - n.Name = fmt.Sprintf("node_name_%d", i+1) - n.Address = h - n.Subcluster = scName - vdb.HostNodeMap[h] = &n - } - vdb.IsEon = true - - tmp, err := os.CreateTemp("", "cluster-config-test.*.yaml") - assert.NoError(t, err) - tmp.Close() - os.Remove(tmp.Name()) - - err = vdb.WriteClusterConfig(tmp.Name(), vlog.Printer{}) - assert.NoError(t, err) - defer os.Remove(tmp.Name()) - - // compare the generated file with expected output - actualBytes, err := os.ReadFile(tmp.Name()) - assert.NoError(t, err) - expectedBytes, err := os.ReadFile("test_data/" + ConfigFileName) - assert.NoError(t, err) - assert.True(t, bytes.Equal(actualBytes, expectedBytes)) - - // now write the config file again - // a backup file should be generated - err = vdb.WriteClusterConfig(tmp.Name(), vlog.Printer{}) - assert.NoError(t, err) - bkpName := fmt.Sprintf("%s/%s", filepath.Dir(tmp.Name()), ConfigBackupName) - err = util.CanReadAccessDir(bkpName) - assert.NoError(t, err) - defer os.Remove(bkpName) - - // clean up - defer os.RemoveAll(dbName) -} diff --git a/vclusterops/db_config.go b/vclusterops/db_config.go deleted file mode 100644 index 0cc94d7..0000000 --- a/vclusterops/db_config.go +++ /dev/null @@ -1,186 +0,0 @@ -/* - (c) Copyright [2023] Open Text. - 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, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -// remove this file in VER-92369 -package vclusterops - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" - "gopkg.in/yaml.v3" -) - -const ( - ConfigDirPerm = 0755 - ConfigFilePerm = 0600 - CurrentConfigFileVersion = "1.0" - ConfigFileName = "vertica_cluster.yaml" - ConfigBackupName = "vertica_cluster.yaml.backup" -) - -type Config struct { - Version string `yaml:"configFileVersion"` - Database DatabaseConfig `yaml:",inline"` -} - -type DatabaseConfig struct { - Name string `yaml:"dbName"` - Nodes []*NodeConfig `yaml:"nodes"` - IsEon bool `yaml:"eonMode"` - CommunalStorageLocation string `yaml:"communalStorageLocation"` - Ipv6 bool `yaml:"ipv6"` -} - -type NodeConfig struct { - Name string `yaml:"name"` - Address string `yaml:"address"` - Subcluster string `yaml:"subcluster"` - CatalogPath string `yaml:"catalogPath"` - DataPath string `yaml:"dataPath"` - DepotPath string `yaml:"depotPath"` -} - -func MakeDatabaseConfig() DatabaseConfig { - return DatabaseConfig{} -} - -// ReadConfig reads database configuration information from a YAML-formatted file in configDirectory. -// It returns a DatabaseConfig and any error encountered when reading and parsing the file. -func ReadConfig(configFilePath string, logger vlog.Printer) (*DatabaseConfig, error) { - if configFilePath == "" { - return nil, fmt.Errorf("no config file provided") - } - configBytes, err := os.ReadFile(configFilePath) - if err != nil { - return nil, fmt.Errorf("fail to read config file, details: %w", err) - } - - var config Config - err = yaml.Unmarshal(configBytes, &config) - if err != nil { - return nil, fmt.Errorf("fail to unmarshal config file, details: %w", err) - } - - // the config file content will look like - /* - configFileVersion: "1.0" - dbName: test_db - nodes: - - name: v_test_db_node0001 - address: 192.168.1.101 - subcluster: default_subcluster - catalogPath: /data - dataPath: /data - depotPath: /data - ... - eonMode: false - communalStorageLocation: "" - ipv6: false - */ - - dbConfig := config.Database - logger.PrintInfo("The content of database config: %+v", dbConfig) - nodesDetails := "The database config nodes details: " - for _, node := range dbConfig.Nodes { - nodesDetails += fmt.Sprintf("%+v ", *node) - } - logger.PrintInfo(nodesDetails) - return &dbConfig, nil -} - -// WriteConfig writes configuration information to configFilePath. -// It returns any write error encountered. -func (c *DatabaseConfig) WriteConfig(configFilePath string, logger vlog.Printer) error { - var config Config - config.Version = CurrentConfigFileVersion - config.Database = *c - - configBytes, err := yaml.Marshal(&config) - if err != nil { - return fmt.Errorf("fail to marshal config data, details: %w", err) - } - err = os.WriteFile(configFilePath, configBytes, ConfigFilePerm) - if err != nil { - return fmt.Errorf("fail to write config file, details: %w", err) - } - logger.Info("Config file successfully written", "config file path", configFilePath) - - return nil -} - -// getPathPrefix returns catalog, data, and depot prefixes -func (c *DatabaseConfig) getPathPrefix(dbName string) (catalogPrefix string, - dataPrefix string, depotPrefix string, err error) { - if dbName != c.Name { - return "", "", "", cannotFindDBFromConfigErr(dbName) - } - - if len(c.Nodes) == 0 { - return "", "", "", - fmt.Errorf("no node was found from the config file of %s", dbName) - } - - return c.Nodes[0].CatalogPath, c.Nodes[0].DataPath, - c.Nodes[0].DepotPath, nil -} - -func (c *DatabaseConfig) getCommunalStorageLocation(dbName string) (communalStorageLocation string, - err error) { - if dbName != c.Name { - return "", cannotFindDBFromConfigErr(dbName) - } - return c.CommunalStorageLocation, nil -} - -func (c *DatabaseConfig) removeConfigFile(configFilePath string, logger vlog.Printer) error { - // back up the old config file - err := backupConfigFile(configFilePath, logger) - if err != nil { - return err - } - - // remove the old db config - return os.Remove(configFilePath) -} - -func (c *DatabaseConfig) getHosts() []string { - var hostList []string - - for _, vnode := range c.Nodes { - hostList = append(hostList, vnode.Address) - } - - return hostList -} - -func backupConfigFile(configFilePath string, logger vlog.Printer) error { - if util.CanReadAccessDir(configFilePath) == nil { - // copy file to vertica_cluster.yaml.backup - configDirPath := filepath.Dir(configFilePath) - configFileBackup := filepath.Join(configDirPath, ConfigBackupName) - logger.Info("Config file exists and, creating a backup", "config file", configFilePath, - "backup file", configFileBackup) - err := util.CopyFile(configFilePath, configFileBackup, ConfigFilePerm) - if err != nil { - return err - } - } - - return nil -} diff --git a/vclusterops/drop_db.go b/vclusterops/drop_db.go index 80d3379..2c948e9 100644 --- a/vclusterops/drop_db.go +++ b/vclusterops/drop_db.go @@ -35,11 +35,11 @@ func VDropDatabaseOptionsFactory() VDropDatabaseOptions { return opt } -// AnalyzeOptions verifies the host options for the VDropDatabaseOptions struct and +// analyzeOptions verifies the host options for the VDropDatabaseOptions struct and // returns any error encountered. -func (options *VDropDatabaseOptions) AnalyzeOptions() error { +func (options *VDropDatabaseOptions) analyzeOptions() error { if len(options.RawHosts) > 0 { - hostAddresses, err := util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + hostAddresses, err := util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -53,7 +53,7 @@ func (options *VDropDatabaseOptions) validateAnalyzeOptions() error { if *options.DBName == "" { return fmt.Errorf("database name must be provided") } - return nil + return options.analyzeOptions() } func (vcc VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error { @@ -66,28 +66,12 @@ func (vcc VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error { // Analyze to produce vdb info for drop db use vdb := makeVCoordinationDatabase() - // TODO: this currently requires a config file to exist. We should allow - // drop to proceed with just options provided and no config file. - - dbConfig, err := ReadConfig(options.ConfigPath, vcc.Log) + err := options.validateAnalyzeOptions() if err != nil { return err } - options.Config = dbConfig - // set db name and hosts - err = options.setDBNameAndHosts() - if err != nil { - return err - } - - // load vdb info from the YAML config file. - err = vdb.setFromClusterConfig(*options.DBName, dbConfig) - if err != nil { - return err - } - - err = options.validateAnalyzeOptions() + err = vdb.setFromBasicDBOptions(&options.VCreateDatabaseOptions) if err != nil { return err } @@ -108,14 +92,6 @@ func (vcc VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error { return fmt.Errorf("fail to drop database: %w", runError) } - // 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 = dbConfig.removeConfigFile(options.ConfigPath, vcc.Log) - if err != nil { - vcc.Log.PrintWarning("Fail to remove config file %q, "+ - "please manually do it. Details: %v", options.ConfigPath, err) - } - return nil } diff --git a/vclusterops/fetch_database.go b/vclusterops/fetch_database.go index cb54afe..14815a7 100644 --- a/vclusterops/fetch_database.go +++ b/vclusterops/fetch_database.go @@ -44,7 +44,7 @@ func (opt *VFetchCoordinationDatabaseOptions) validateParseOptions(logger vlog.P func (opt *VFetchCoordinationDatabaseOptions) analyzeOptions() error { // resolve RawHosts to be IP addresses if len(opt.RawHosts) > 0 { - hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.OldIpv6.ToBool()) + hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.IPv6) if err != nil { return err } diff --git a/vclusterops/fetch_node_state.go b/vclusterops/fetch_node_state.go index 8747f58..2db94bc 100644 --- a/vclusterops/fetch_node_state.go +++ b/vclusterops/fetch_node_state.go @@ -32,7 +32,7 @@ func (options *VFetchNodeStateOptions) validateParseOptions(vcc VClusterCommands func (options *VFetchNodeStateOptions) analyzeOptions() error { if len(options.RawHosts) > 0 { - hostAddresses, err := util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + hostAddresses, err := util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } diff --git a/vclusterops/helpers.go b/vclusterops/helpers.go index f9f4913..e987b43 100644 --- a/vclusterops/helpers.go +++ b/vclusterops/helpers.go @@ -264,10 +264,6 @@ func getInitiatorFromUpHosts(upHosts, userProvidedHosts []string) string { return "" } -func cannotFindDBFromConfigErr(dbName string) error { - return fmt.Errorf("database %s cannot be found in the config file", dbName) -} - // validates each host has an entry in each map func validateHostMaps(hosts []string, maps ...map[string]string) error { var allErrors error diff --git a/vclusterops/install_packages.go b/vclusterops/install_packages.go index 6ada327..87fa032 100644 --- a/vclusterops/install_packages.go +++ b/vclusterops/install_packages.go @@ -43,7 +43,7 @@ func (options *VInstallPackagesOptions) analyzeOptions() (err error) { // we analyze hostnames when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -66,14 +66,8 @@ func (vcc VClusterCommands) VInstallPackages(options *VInstallPackagesOptions) ( * - Give the instructions to the VClusterOpEngine to run */ - // set db name and hosts - err := options.setDBNameAndHosts() - if err != nil { - return nil, err - } - // validate and analyze all options - err = options.validateAnalyzeOptions(vcc.Log) + err := options.validateAnalyzeOptions(vcc.Log) if err != nil { return nil, err } diff --git a/vclusterops/nma_bootstrap_catalog_op.go b/vclusterops/nma_bootstrap_catalog_op.go index c59efc6..ef70314 100644 --- a/vclusterops/nma_bootstrap_catalog_op.go +++ b/vclusterops/nma_bootstrap_catalog_op.go @@ -102,7 +102,7 @@ func (op *nmaBootstrapCatalogOp) setupRequestBody(vdb *VCoordinationDatabase, op } bootstrapData.SpreadLogging = *options.SpreadLogging bootstrapData.SpreadLoggingLevel = *options.SpreadLoggingLevel - bootstrapData.Ipv6 = options.OldIpv6.ToBool() + bootstrapData.Ipv6 = options.IPv6 bootstrapData.SuperuserName = *options.UserName bootstrapData.DBPassword = *options.Password diff --git a/vclusterops/re_ip.go b/vclusterops/re_ip.go index 36a9937..2d8657c 100644 --- a/vclusterops/re_ip.go +++ b/vclusterops/re_ip.go @@ -61,7 +61,7 @@ func (opt *VReIPOptions) validateParseOptions(logger vlog.Printer) error { func (opt *VReIPOptions) analyzeOptions() error { if len(opt.RawHosts) > 0 { - hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.OldIpv6.ToBool()) + hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.IPv6) if err != nil { return err } @@ -84,7 +84,7 @@ func (opt *VReIPOptions) validateAnalyzeOptions(logger vlog.Printer) error { } // address check - ipv6 := opt.OldIpv6.ToBool() + ipv6 := opt.IPv6 nodeAddresses := make(map[string]struct{}) for _, info := range opt.ReIPList { // the addresses must be valid IPs @@ -124,30 +124,7 @@ func (vcc VClusterCommands) VReIP(options *VReIPOptions) error { * - Give the instructions to the VClusterOpEngine to run */ - // set db name and hosts - err := options.setDBNameAndHosts() - if err != nil { - return err - } - - // set catalog prefix - options.CatalogPrefix, err = options.getCatalogPrefix(options.Config) - if err != nil { - return err - } - - isEon, err := options.isEonMode(options.Config) - if err != nil { - return err - } - if isEon { - options.CommunalStorageLocation, err = options.getCommunalStorageLocation(options.Config) - if err != nil { - return err - } - } - - err = options.validateAnalyzeOptions(vcc.Log) + err := options.validateAnalyzeOptions(vcc.Log) if err != nil { return err } @@ -156,7 +133,7 @@ func (vcc VClusterCommands) VReIP(options *VReIPOptions) error { // from the config file var pVDB *VCoordinationDatabase // retrieve database information from cluster_config.json for Eon databases - if isEon { + if options.IsEon { const warningMsg = " for an Eon database, re_ip after revive_db could fail " + "because we cannot retrieve the correct database information" if *options.CommunalStorageLocation != "" { @@ -302,7 +279,7 @@ func (opt *VReIPOptions) ReadReIPFile(path string) error { return nil } - ipv6 := opt.OldIpv6.ToBool() + ipv6 := opt.IPv6 for _, row := range reIPRows { var info ReIPInfo info.NodeAddress = row.CurrentAddress diff --git a/vclusterops/re_ip_test.go b/vclusterops/re_ip_test.go index 397248b..1897475 100644 --- a/vclusterops/re_ip_test.go +++ b/vclusterops/re_ip_test.go @@ -22,7 +22,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/vertica/vcluster/vclusterops/vlog" - "github.com/vertica/vcluster/vclusterops/vstruct" ) func TestReIPOptions(t *testing.T) { @@ -52,7 +51,7 @@ func TestReadReIPFile(t *testing.T) { currentDir, _ := os.Getwd() // ipv4 positive - opt.OldIpv6 = vstruct.False + opt.IPv6 = false err := opt.ReadReIPFile(currentDir + "/test_data/re_ip_v4.json") assert.NoError(t, err) @@ -61,7 +60,7 @@ func TestReadReIPFile(t *testing.T) { assert.ErrorContains(t, err, "192.168.1.10a in the re-ip file is not a valid IPv4 address") // ipv6 - opt.OldIpv6 = vstruct.True + opt.IPv6 = true err = opt.ReadReIPFile(currentDir + "/test_data/re_ip_v6.json") assert.NoError(t, err) diff --git a/vclusterops/remove_node.go b/vclusterops/remove_node.go index 265d52d..b38ebc8 100644 --- a/vclusterops/remove_node.go +++ b/vclusterops/remove_node.go @@ -74,7 +74,7 @@ func (o *VRemoveNodeOptions) validateParseOptions(log vlog.Printer) error { } func (o *VRemoveNodeOptions) analyzeOptions() (err error) { - o.HostsToRemove, err = util.ResolveRawHostsToAddresses(o.HostsToRemove, o.OldIpv6.ToBool()) + o.HostsToRemove, err = util.ResolveRawHostsToAddresses(o.HostsToRemove, o.IPv6) if err != nil { return err } @@ -82,7 +82,7 @@ func (o *VRemoveNodeOptions) analyzeOptions() (err error) { // we analyze host names when it is set in user input, otherwise we use hosts in yaml config if len(o.RawHosts) > 0 { // resolve RawHosts to be IP addresses - o.Hosts, err = util.ResolveRawHostsToAddresses(o.RawHosts, o.OldIpv6.ToBool()) + o.Hosts, err = util.ResolveRawHostsToAddresses(o.RawHosts, o.IPv6) if err != nil { return err } @@ -105,24 +105,8 @@ func (o *VRemoveNodeOptions) validateAnalyzeOptions(log vlog.Printer) error { func (vcc VClusterCommands) VRemoveNode(options *VRemoveNodeOptions) (VCoordinationDatabase, error) { vdb := makeVCoordinationDatabase() - // set db name and hosts - err := options.setDBNameAndHosts() - if err != nil { - return vdb, err - } - - // get depot, data and catalog prefix from config file or options - *options.DepotPrefix, *options.DataPrefix, err = options.getDepotAndDataPrefix(options.Config) - if err != nil { - return vdb, err - } - options.CatalogPrefix, err = options.getCatalogPrefix(options.Config) - if err != nil { - return vdb, err - } - // validate and analyze options - err = options.validateAnalyzeOptions(vcc.Log) + err := options.validateAnalyzeOptions(vcc.Log) if err != nil { return vdb, err } @@ -512,7 +496,7 @@ func (vcc VClusterCommands) findRemovedNodesInCatalog(options *VRemoveNodeOption fetchNodeStateOpt := VFetchNodeStateOptionsFactory() fetchNodeStateOpt.DBName = options.DBName fetchNodeStateOpt.RawHosts = remainingHosts - fetchNodeStateOpt.OldIpv6 = options.OldIpv6 + fetchNodeStateOpt.IPv6 = options.IPv6 fetchNodeStateOpt.UserName = options.UserName fetchNodeStateOpt.Password = options.Password diff --git a/vclusterops/remove_subcluster.go b/vclusterops/remove_subcluster.go index 9df1572..572c78c 100644 --- a/vclusterops/remove_subcluster.go +++ b/vclusterops/remove_subcluster.go @@ -71,13 +71,13 @@ func (o *VRemoveScOptions) validatePathOptions() error { return util.ValidateRequiredAbsPath(o.DepotPrefix, "depot path") } -func (o *VRemoveScOptions) validateParseOptions(config *DatabaseConfig, logger vlog.Printer) error { +func (o *VRemoveScOptions) validateParseOptions(logger vlog.Printer) error { err := o.validateRequiredOptions(logger) if err != nil { return err } - err = o.validateEonOptions(config) + err = o.validateEonOptions() if err != nil { return err } @@ -85,14 +85,8 @@ func (o *VRemoveScOptions) validateParseOptions(config *DatabaseConfig, logger v return o.validatePathOptions() } -func (o *VRemoveScOptions) validateEonOptions(config *DatabaseConfig) error { - isEon, err := o.isEonMode(config) - if err != nil { - return err - } - - if !isEon && config != nil { - // config file confirms that the db is not Eon +func (o *VRemoveScOptions) validateEonOptions() error { + if !o.IsEon { return fmt.Errorf(`cannot remove subcluster from an enterprise database '%s'`, *o.DBName) } @@ -103,7 +97,7 @@ func (o *VRemoveScOptions) analyzeOptions() (err error) { // we analyze host names when it is set in user input, otherwise we use hosts in yaml config if len(o.RawHosts) > 0 { // resolve RawHosts to be IP addresses - o.Hosts, err = util.ResolveRawHostsToAddresses(o.RawHosts, o.OldIpv6.ToBool()) + o.Hosts, err = util.ResolveRawHostsToAddresses(o.RawHosts, o.IPv6) if err != nil { return err } @@ -112,8 +106,8 @@ func (o *VRemoveScOptions) analyzeOptions() (err error) { return nil } -func (o *VRemoveScOptions) validateAnalyzeOptions(config *DatabaseConfig, logger vlog.Printer) error { - if err := o.validateParseOptions(config, logger); err != nil { +func (o *VRemoveScOptions) validateAnalyzeOptions(logger vlog.Printer) error { + if err := o.validateParseOptions(logger); err != nil { return err } err := o.analyzeOptions() @@ -131,20 +125,8 @@ func (o *VRemoveScOptions) validateAnalyzeOptions(config *DatabaseConfig, logger func (vcc VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (VCoordinationDatabase, error) { vdb := makeVCoordinationDatabase() - // set db name and hosts - err := removeScOpt.setDBNameAndHosts() - if err != nil { - return vdb, err - } - - // get depot, data and catalog prefix from config file or options - *removeScOpt.DepotPrefix, *removeScOpt.DataPrefix, err = removeScOpt.getDepotAndDataPrefix(removeScOpt.Config) - if err != nil { - return vdb, err - } - // validate and analyze options - err = removeScOpt.validateAnalyzeOptions(removeScOpt.Config, vcc.Log) + err := removeScOpt.validateAnalyzeOptions(vcc.Log) if err != nil { return vdb, err } diff --git a/vclusterops/remove_subcluster_test.go b/vclusterops/remove_subcluster_test.go index 1f6831b..a22cd2f 100644 --- a/vclusterops/remove_subcluster_test.go +++ b/vclusterops/remove_subcluster_test.go @@ -31,13 +31,8 @@ func TestRemoveSubcluster(t *testing.T) { // input db name *options.DBName = dbName - config := &DatabaseConfig{ - Name: dbName, - IsEon: true, - } - // options without sc name, data path, and depot path - err := options.validateParseOptions(config, vlog.Printer{}) + err := options.validateParseOptions(vlog.Printer{}) assert.ErrorContains(t, err, "must specify a subcluster name") // input sc name @@ -45,21 +40,21 @@ func TestRemoveSubcluster(t *testing.T) { *options.SubclusterToRemove = "sc1" // verify Eon mode is set - config.IsEon = false - err = options.validateParseOptions(config, vlog.Printer{}) + options.IsEon = false + err = options.validateParseOptions(vlog.Printer{}) assert.ErrorContains(t, err, "cannot remove subcluster from an enterprise database") - config.IsEon = true + options.IsEon = true - err = options.validateParseOptions(config, vlog.Printer{}) + err = options.validateParseOptions(vlog.Printer{}) assert.ErrorContains(t, err, "must specify an absolute data path") // input data path *options.DataPrefix = defaultPath - err = options.validateParseOptions(config, vlog.Printer{}) + err = options.validateParseOptions(vlog.Printer{}) assert.ErrorContains(t, err, "must specify an absolute depot path") // input depot path *options.DepotPrefix = defaultPath - err = options.validateParseOptions(config, vlog.Printer{}) + err = options.validateParseOptions(vlog.Printer{}) assert.NoError(t, err) } diff --git a/vclusterops/replication.go b/vclusterops/replication.go index d86f938..6d362ac 100644 --- a/vclusterops/replication.go +++ b/vclusterops/replication.go @@ -86,7 +86,7 @@ func (opt *VReplicationDatabaseOptions) validateParseOptions(logger vlog.Printer func (opt *VReplicationDatabaseOptions) analyzeOptions() (err error) { if len(opt.TargetHosts) > 0 { // resolve RawHosts to be IP addresses - opt.TargetHosts, err = util.ResolveRawHostsToAddresses(opt.TargetHosts, opt.OldIpv6.ToBool()) + opt.TargetHosts, err = util.ResolveRawHostsToAddresses(opt.TargetHosts, opt.IPv6) if err != nil { return err } @@ -94,7 +94,7 @@ func (opt *VReplicationDatabaseOptions) analyzeOptions() (err error) { // we analyze host names when it is set in user input, otherwise we use hosts in yaml config if len(opt.RawHosts) > 0 { // resolve RawHosts to be IP addresses - hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.OldIpv6.ToBool()) + hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.IPv6) if err != nil { return err } diff --git a/vclusterops/restore_points.go b/vclusterops/restore_points.go index 6934409..f966051 100644 --- a/vclusterops/restore_points.go +++ b/vclusterops/restore_points.go @@ -131,7 +131,7 @@ func (opt *VShowRestorePointsOptions) analyzeOptions() (err error) { // we analyze host names when it is set in user input, otherwise we use hosts in yaml config if len(opt.RawHosts) > 0 { // resolve RawHosts to be IP addresses - hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.OldIpv6.ToBool()) + hostAddresses, err := util.ResolveRawHostsToAddresses(opt.RawHosts, opt.IPv6) if err != nil { return err } @@ -155,18 +155,6 @@ func (vcc VClusterCommands) VShowRestorePoints(options *VShowRestorePointsOption * - Give the instructions to the VClusterOpEngine to run */ - // set db name and hosts - err = options.setDBNameAndHosts() - if err != nil { - return restorePoints, err - } - - // get communal storage location from config file and options - options.CommunalStorageLocation, err = options.getCommunalStorageLocation(options.Config) - if err != nil { - return restorePoints, err - } - // validate and analyze options err = options.validateAnalyzeOptions(vcc.Log) if err != nil { diff --git a/vclusterops/revive_db.go b/vclusterops/revive_db.go index 21085e1..827aa0f 100644 --- a/vclusterops/revive_db.go +++ b/vclusterops/revive_db.go @@ -173,7 +173,7 @@ func (options *VReviveDatabaseOptions) analyzeOptions() (err error) { // resolve RawHosts to be IP addresses if len(options.RawHosts) > 0 { - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -262,7 +262,7 @@ func (vcc VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (db vdb.Name = *options.DBName vdb.IsEon = true vdb.CommunalStorageLocation = *options.CommunalStorageLocation - vdb.Ipv6 = options.OldIpv6.ToBool() + vdb.Ipv6 = options.IPv6 return dbInfo, &vdb, nil } diff --git a/vclusterops/sandbox.go b/vclusterops/sandbox.go index 64233cc..e4993c8 100644 --- a/vclusterops/sandbox.go +++ b/vclusterops/sandbox.go @@ -63,7 +63,7 @@ func (options *VSandboxOptions) analyzeOptions() (err error) { // we analyze hostnames when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -71,7 +71,7 @@ func (options *VSandboxOptions) analyzeOptions() (err error) { // resolve SCRawHosts to be IP addresses if len(options.SCRawHosts) > 0 { - options.SCHosts, err = util.ResolveRawHostsToAddresses(options.SCRawHosts, options.OldIpv6.ToBool()) + options.SCHosts, err = util.ResolveRawHostsToAddresses(options.SCRawHosts, options.IPv6) if err != nil { return err } @@ -160,7 +160,6 @@ func (vcc VClusterCommands) VSandbox(options *VSandboxOptions) error { // sandboxInterface is an interface that will be used by runSandboxCmd(). // The purpose of this interface is to avoid code duplication. type sandboxInterface interface { - setDBNameAndHosts() error ValidateAnalyzeOptions(vcc VClusterCommands) error runCommand(vcc VClusterCommands) error } @@ -188,13 +187,8 @@ func (options *VSandboxOptions) runCommand(vcc VClusterCommands) error { // runSandboxCmd is a help function to run sandbox/unsandbox command. // It can avoid code duplication between VSandbox and VUnsandbox. func runSandboxCmd(vcc VClusterCommands, i sandboxInterface) error { - err := i.setDBNameAndHosts() - if err != nil { - return err - } - // check required options - err = i.ValidateAnalyzeOptions(vcc) + err := i.ValidateAnalyzeOptions(vcc) if err != nil { vcc.Log.Error(err, "failed to validate the options") return err diff --git a/vclusterops/scrutinize.go b/vclusterops/scrutinize.go index 254ca02..befc635 100644 --- a/vclusterops/scrutinize.go +++ b/vclusterops/scrutinize.go @@ -162,7 +162,7 @@ func (options *VScrutinizeOptions) analyzeOptions(logger vlog.Printer) (err erro // we analyze host names when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -186,23 +186,8 @@ func (options *VScrutinizeOptions) ValidateAnalyzeOptions(logger vlog.Printer) e } func (vcc VClusterCommands) VScrutinize(options *VScrutinizeOptions) error { - // fill in vars from cluster config if necessary - err := options.setDBNameAndHosts() - if err != nil { - vcc.Log.Error(err, "failed to retrieve info from cluster config for database", - "dbname", *options.DBName) - return err - } - catPrefix, err := options.getCatalogPrefix(options.Config) - if err != nil { - vcc.Log.Error(err, "failed to retrieve info from cluster config for database", - "dbname", *options.DBName) - return err - } - options.CatalogPrefix = catPrefix - // check required options (including those that can come from cluster config) - err = options.ValidateAnalyzeOptions(vcc.Log) + err := options.ValidateAnalyzeOptions(vcc.Log) if err != nil { vcc.Log.Error(err, "validation of scrutinize arguments failed") return err diff --git a/vclusterops/start_db.go b/vclusterops/start_db.go index 09f8ca4..b57de5a 100644 --- a/vclusterops/start_db.go +++ b/vclusterops/start_db.go @@ -86,7 +86,7 @@ func (options *VStartDatabaseOptions) analyzeOptions() (err error) { // we analyze hostnames when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -108,30 +108,6 @@ func (vcc VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) (vdbP * - Give the instructions to the VClusterOpEngine to run */ - // set db name and hosts - err = options.setDBNameAndHosts() - if err != nil { - return nil, err - } - - isEon, err := options.isEonMode(options.Config) - if err != nil { - return nil, err - } - options.OldIsEon.FromBoolPointer(&isEon) - - options.CatalogPrefix, err = options.getCatalogPrefix(options.Config) - if err != nil { - return nil, err - } - - if isEon { - options.CommunalStorageLocation, err = options.getCommunalStorageLocation(options.Config) - if err != nil { - return nil, err - } - } - // set default value to StatePollingTimeout if *options.StatePollingTimeout == 0 { *options.StatePollingTimeout = util.DefaultStatePollingTimeout @@ -147,7 +123,7 @@ func (vcc VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) (vdbP // from the config file var vdb VCoordinationDatabase // retrieve database information from cluster_config.json for Eon databases - if isEon { + if options.IsEon { const warningMsg = " for an Eon database, start_db after revive_db could fail " + "because we cannot retrieve the correct database information" if *options.CommunalStorageLocation != "" { @@ -348,7 +324,7 @@ func (vcc VClusterCommands) produceStartDBInstructions(options *VStartDatabaseOp &httpsPollNodeStateOp, ) - if options.OldIsEon.ToBool() { + if options.IsEon { httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(options.Hosts, options.usePassword, *options.UserName, options.Password, StartDBSyncCat) if err != nil { return instructions, err diff --git a/vclusterops/start_node.go b/vclusterops/start_node.go index e89632c..44694f0 100644 --- a/vclusterops/start_node.go +++ b/vclusterops/start_node.go @@ -75,7 +75,7 @@ func (options *VStartNodesOptions) analyzeOptions() (err error) { // we analyze host names when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -89,7 +89,7 @@ func (options *VStartNodesOptions) analyzeOptions() (err error) { func (options *VStartNodesOptions) ParseNodesList(rawNodeMap map[string]string) error { options.Nodes = make(map[string]string) for k, v := range rawNodeMap { - ip, err := util.ResolveToOneIP(v, options.OldIpv6.ToBool()) + ip, err := util.ResolveToOneIP(v, options.IPv6) if err != nil { return err } @@ -143,19 +143,13 @@ func (vcc VClusterCommands) VStartNodes(options *VStartNodesOptions) error { * - Give the instructions to the VClusterOpEngine to run */ - // set db name and hosts - err := options.setDBNameAndHosts() - if err != nil { - return err - } - // set default value to StatePollingTimeout if options.StatePollingTimeout == 0 { options.StatePollingTimeout = util.DefaultStatePollingTimeout } // validate and analyze options - err = options.validateAnalyzeOptions(vcc.Log) + err := options.validateAnalyzeOptions(vcc.Log) if err != nil { return err } diff --git a/vclusterops/unsandbox.go b/vclusterops/unsandbox.go index 9bb2c90..166d2c2 100644 --- a/vclusterops/unsandbox.go +++ b/vclusterops/unsandbox.go @@ -63,7 +63,7 @@ func (options *VUnsandboxOptions) analyzeOptions() (err error) { // we analyze hostnames when it is set in user input, otherwise we use hosts in yaml config if len(options.RawHosts) > 0 { // resolve RawHosts to be IP addresses - options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.OldIpv6.ToBool()) + options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) if err != nil { return err } @@ -71,7 +71,7 @@ func (options *VUnsandboxOptions) analyzeOptions() (err error) { // resolve SCRawHosts to be IP addresses if len(options.SCRawHosts) > 0 { - options.SCHosts, err = util.ResolveRawHostsToAddresses(options.SCRawHosts, options.OldIpv6.ToBool()) + options.SCHosts, err = util.ResolveRawHostsToAddresses(options.SCRawHosts, options.IPv6) if err != nil { return err } diff --git a/vclusterops/vcluster_database_options.go b/vclusterops/vcluster_database_options.go index 0ebfb8d..463876b 100644 --- a/vclusterops/vcluster_database_options.go +++ b/vclusterops/vcluster_database_options.go @@ -22,7 +22,6 @@ import ( "github.com/vertica/vcluster/vclusterops/util" "github.com/vertica/vcluster/vclusterops/vlog" - "github.com/vertica/vcluster/vclusterops/vstruct" "golang.org/x/exp/slices" ) @@ -37,8 +36,6 @@ type DatabaseOptions struct { Hosts []string // whether using IPv6 for host addresses IPv6 bool - // remove OldIpv6 in VER-92369 - OldIpv6 vstruct.NullableBool // path of catalog directory CatalogPrefix *string // path of data directory @@ -52,8 +49,6 @@ type DatabaseOptions struct { DepotPrefix *string // whether the database is in Eon mode IsEon bool - // remove OldIsEon in VER-92369 - OldIsEon vstruct.NullableBool // path of the communal storage CommunalStorageLocation *string // database configuration parameters @@ -78,10 +73,6 @@ type DatabaseOptions struct { LogPath *string // whether use password usePassword bool - - // remove Config in VER-92369 - // pointer to the db config object - Config *DatabaseConfig } const ( @@ -126,10 +117,9 @@ func (opt *DatabaseOptions) setDefaultValues() { opt.DataPrefix = new(string) opt.DepotPrefix = new(string) opt.UserName = new(string) - opt.OldIpv6 = vstruct.NotSet - opt.OldIsEon = vstruct.NotSet opt.CommunalStorageLocation = new(string) opt.ConfigurationParameters = make(map[string]string) + opt.LogPath = new(string) } func (opt *DatabaseOptions) checkNilPointerParams() error { @@ -237,8 +227,7 @@ func (opt *DatabaseOptions) validatePaths(commandName string) error { } // depot prefix - // remove `|| opt.OldIsEon == vstruct.True` in VER-92369 - if opt.IsEon || opt.OldIsEon == vstruct.True { + if opt.IsEon { err = util.ValidateRequiredAbsPath(opt.DepotPrefix, "depot path") if err != nil { return err @@ -302,175 +291,6 @@ func (opt *DatabaseOptions) setUsePassword(log vlog.Printer) error { return nil } -// remove this function in VER-92369 -// isEonMode can choose the right eon mode from user input and config file -func (opt *DatabaseOptions) isEonMode(config *DatabaseConfig) (bool, error) { - // if eon mode is set in user input, we use the value in user input - if opt.OldIsEon != vstruct.NotSet { - return opt.OldIsEon.ToBool(), nil - } - - // when config file is not available, we do not return an error because we want - // to delay eon mode check in each command's validateAnalyzeOptions(), which is - // a central place to check all the options. - if config == nil { - return opt.OldIsEon.ToBool(), nil - } - - // if db name from user input is different than the one in config file, - // we throw an error - if *opt.DBName != "" && config.Name != *opt.DBName { - return false, cannotFindDBFromConfigErr(*opt.DBName) - } - - isEon := config.IsEon - return isEon, nil -} - -// remove this function in VER-92369 -// setNameAndHosts can assign the right dbName and hosts to DatabaseOptions -func (opt *DatabaseOptions) setDBNameAndHosts() error { - dbName, hosts, err := opt.getNameAndHosts(opt.Config) - if err != nil { - return err - } - opt.DBName = &dbName - opt.Hosts = hosts - return nil -} - -// remove this function in VER-92369 -// getNameAndHosts can choose the right dbName and hosts from user input and config file -func (opt *DatabaseOptions) getNameAndHosts(config *DatabaseConfig) (dbName string, hosts []string, err error) { - // DBName is now a required flag, we always get it from user input - dbName = opt.getDBName(config) - if dbName == "" { - return dbName, hosts, fmt.Errorf("must specify a database name") - } - hosts, err = opt.getHosts(config) - return dbName, hosts, err -} - -// remove this function in VER-92369 -// getDBName chooses the right db name from user input and config file -func (opt *DatabaseOptions) getDBName(config *DatabaseConfig) string { - // if db name is set in user input, we use the value in user input - if *opt.DBName != "" { - return *opt.DBName - } - - if config == nil { - return "" - } - - return config.Name -} - -// remove this function in VER-92369 -// getHosts chooses the right hosts from user input and config file -func (opt *DatabaseOptions) getHosts(config *DatabaseConfig) (hosts []string, err error) { - // if Hosts is set in user input, we use the value in user input - if len(opt.Hosts) > 0 { - return opt.Hosts, nil - } - - // when config file is not available, we do not return an error because we want - // to delay hosts check in each command's validateAnalyzeOptions(), which is - // a central place to check all the options. - if config == nil { - return opt.Hosts, nil - } - - // if db name from user input is different than the one in config file, - // we throw an error - if *opt.DBName != "" && config.Name != *opt.DBName { - return hosts, cannotFindDBFromConfigErr(*opt.DBName) - } - - hosts = config.getHosts() - return hosts, nil -} - -// remove this function in VER-92369 -// getCatalogPrefix can choose the right catalog prefix from user input and config file -func (opt *DatabaseOptions) getCatalogPrefix(config *DatabaseConfig) (catalogPrefix *string, err error) { - // when config file is not available, we use user input - if config == nil { - return opt.CatalogPrefix, nil - } - - catalogPrefix = new(string) - *catalogPrefix, _, _, err = config.getPathPrefix(*opt.DBName) - if err != nil { - return catalogPrefix, err - } - - // if CatalogPrefix is set in user input, we use the value in user input - if *opt.CatalogPrefix != "" { - catalogPrefix = opt.CatalogPrefix - } - return catalogPrefix, nil -} - -// remove this function in VER-92369 -// getCommunalStorageLocation can choose the right communal storage location from user input and config file -func (opt *DatabaseOptions) getCommunalStorageLocation(config *DatabaseConfig) (communalStorageLocation *string, err error) { - // when config file is not available, we use user input - if config == nil { - return opt.CommunalStorageLocation, nil - } - - communalStorageLocation = new(string) - *communalStorageLocation, err = config.getCommunalStorageLocation(*opt.DBName) - if err != nil { - return communalStorageLocation, err - } - - // if CommunalStorageLocation is set in user input, we use the value in user input - if *opt.CommunalStorageLocation != "" { - communalStorageLocation = opt.CommunalStorageLocation - } - return communalStorageLocation, nil -} - -// remove this function in VER-92369 -// getDepotAndDataPrefix chooses the right depot/data prefix from user input and config file. -func (opt *DatabaseOptions) getDepotAndDataPrefix( - config *DatabaseConfig) (depotPrefix, dataPrefix string, err error) { - if config == nil { - return *opt.DepotPrefix, *opt.DataPrefix, nil - } - - _, dataPrefix, depotPrefix, err = config.getPathPrefix(*opt.DBName) - if err != nil { - return "", "", err - } - - // if DepotPrefix and DataPrefix are set in user input, we use the value in user input - if *opt.DepotPrefix != "" { - depotPrefix = *opt.DepotPrefix - } - if *opt.DataPrefix != "" { - dataPrefix = *opt.DataPrefix - } - return depotPrefix, dataPrefix, nil -} - -// remove this function in VER-92369 -// GetDBConfig reads database configurations from the config file into a DatabaseConfig struct. -// It returns the DatabaseConfig and any error encountered. -func (opt *DatabaseOptions) GetDBConfig(vcc ClusterCommands) (config *DatabaseConfig, err error) { - config, err = ReadConfig(opt.ConfigPath, vcc.GetLog()) - if err != nil { - // when we cannot read config file, config points to an empty DatabaseConfig with default values - // we want to reset config to nil so we will use user input later rather than those default values - config = nil - vcc.PrintWarning("Failed to read %s, details: %v", opt.ConfigPath, err) - } - - return config, nil -} - // normalizePaths replaces all '//' to be '/', and trim // catalog, data and depot prefixes. func (opt *DatabaseOptions) normalizePaths() {