diff --git a/commands/cmd_add_node.go b/commands/cmd_add_node.go index d52af97..f6d6f97 100644 --- a/commands/cmd_add_node.go +++ b/commands/cmd_add_node.go @@ -159,15 +159,25 @@ func (c *CmdAddNode) Run(log vlog.Printer) error { Log: log.WithName(c.CommandType()), } vcc.Log.V(1).Info("Called method Run()") - vdb, addNodeError := vcc.VAddNode(c.addNodeOptions) + + options := c.addNodeOptions + + // get config from vertica_cluster.yaml + config, err := options.GetDBConfig() + 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 := vclusterops.WriteClusterConfig(&vdb, c.addNodeOptions.ConfigDirectory) + err = vclusterops.WriteClusterConfig(&vdb, options.ConfigDirectory) if err != nil { vlog.LogPrintWarning("fail to write config file, details: %s", err) } - vcc.Log.PrintInfo("Added nodes %s to database %s", *c.newHostListStr, *c.addNodeOptions.DBName) + vcc.Log.PrintInfo("Added nodes %s to database %s", *c.newHostListStr, *options.DBName) return nil } diff --git a/commands/cmd_add_subcluster.go b/commands/cmd_add_subcluster.go index fcadd8f..7b4a9ec 100644 --- a/commands/cmd_add_subcluster.go +++ b/commands/cmd_add_subcluster.go @@ -129,11 +129,22 @@ func (c *CmdAddSubcluster) Run(log vlog.Printer) error { Log: log.WithName(c.CommandType()), } vcc.Log.V(1).Info("Called method Run()") - err := vcc.VAddSubcluster(c.addSubclusterOptions) + + options := c.addSubclusterOptions + + // get config from vertica_cluster.yaml + config, err := options.GetDBConfig() + if err != nil { + return err + } + options.Config = config + + err = vcc.VAddSubcluster(options) if err != nil { vcc.Log.Error(err, "failed to add subcluster") return err } - vlog.LogPrintInfo("Added subcluster %s to database %s", *c.addSubclusterOptions.SCName, *c.addSubclusterOptions.DBName) + + vlog.LogPrintInfo("Added subcluster %s to database %s", *options.SCName, *options.DBName) return nil } diff --git a/commands/cmd_remove_node.go b/commands/cmd_remove_node.go index b9c8d12..8570375 100644 --- a/commands/cmd_remove_node.go +++ b/commands/cmd_remove_node.go @@ -112,14 +112,23 @@ func (c *CmdRemoveNode) Run(log vlog.Printer) error { } vcc.Log.V(1).Info("Called method Run()") - vdb, err := vcc.VRemoveNode(c.removeNodeOptions) + options := c.removeNodeOptions + + // get config from vertica_cluster.yaml + config, err := c.removeNodeOptions.GetDBConfig() + if err != nil { + return err + } + options.Config = config + + vdb, err := vcc.VRemoveNode(options) if err != nil { return err } - vlog.LogPrintInfo("Successfully removed nodes %s from database %s", *c.hostToRemoveListStr, *c.removeNodeOptions.DBName) + vlog.LogPrintInfo("Successfully removed nodes %s from database %s", *c.hostToRemoveListStr, *options.DBName) // write cluster information to the YAML config file. - err = vclusterops.WriteClusterConfig(&vdb, c.removeNodeOptions.ConfigDirectory) + err = vclusterops.WriteClusterConfig(&vdb, options.ConfigDirectory) if err != nil { vlog.LogPrintWarning("failed to write config file, details: %s", err) } diff --git a/commands/cmd_restart_node.go b/commands/cmd_restart_node.go index c6cec40..05050c5 100644 --- a/commands/cmd_restart_node.go +++ b/commands/cmd_restart_node.go @@ -105,17 +105,28 @@ func (c *CmdRestartNodes) Run(log vlog.Printer) error { Log: log.WithName(c.CommandType()), } vcc.Log.V(1).Info("Called method Run()") + + options := c.restartNodesOptions + + // load vdb info from the YAML config file + // get config from vertica_cluster.yaml + config, err := options.GetDBConfig() + if err != nil { + return err + } + options.Config = config + // this is the instruction that will be used by both CLI and operator - err := vcc.VRestartNodes(c.restartNodesOptions) + err = vcc.VRestartNodes(options) if err != nil { return err } var hostToRestart []string - for _, ip := range c.restartNodesOptions.Nodes { + for _, ip := range options.Nodes { hostToRestart = append(hostToRestart, ip) } - vlog.LogPrintInfo("Successfully restart hosts %s of the database %s", hostToRestart, *c.restartNodesOptions.DBName) + vlog.LogPrintInfo("Successfully restart hosts %s of the database %s", hostToRestart, *options.DBName) return nil } diff --git a/commands/cmd_start_db.go b/commands/cmd_start_db.go index 1c77eca..1842ab5 100644 --- a/commands/cmd_start_db.go +++ b/commands/cmd_start_db.go @@ -134,12 +134,23 @@ func (c *CmdStartDB) Run(log vlog.Printer) error { Log: log.WithName(c.CommandType()), } vcc.Log.V(1).Info("Called method Run()") - err := vcc.VStartDatabase(c.startDBOptions) + + options := c.startDBOptions + + // load vdb info from the YAML config file + // get config from vertica_cluster.yaml + config, err := options.GetDBConfig() + if err != nil { + return err + } + options.Config = config + + err = vcc.VStartDatabase(options) if err != nil { vcc.Log.Error(err, "failed to start the database") return err } - vlog.LogPrintInfo("Successfully start the database %s\n", *c.startDBOptions.DBName) + vlog.LogPrintInfo("Successfully start the database %s\n", *options.DBName) return nil } diff --git a/commands/cmd_stop_db.go b/commands/cmd_stop_db.go index 78a7f81..29ff9d0 100644 --- a/commands/cmd_stop_db.go +++ b/commands/cmd_stop_db.go @@ -130,11 +130,22 @@ func (c *CmdStopDB) Run(log vlog.Printer) error { Log: log.WithName(c.CommandType()), } vcc.Log.Info("Called method Run()") - err := vcc.VStopDatabase(c.stopDBOptions) + + options := c.stopDBOptions + + // get config from vertica_cluster.yaml + config, err := options.GetDBConfig() + if err != nil { + return err + } + options.Config = config + + err = vcc.VStopDatabase(options) if err != nil { vcc.Log.Error(err, "failed to stop the database") return err } - vlog.LogPrintInfo("Stopped a database with name %s", *c.stopDBOptions.DBName) + + vlog.LogPrintInfo("Stopped a database with name %s", *options.DBName) return nil } diff --git a/vclusterops/add_node.go b/vclusterops/add_node.go index 593a3a7..4d8402e 100644 --- a/vclusterops/add_node.go +++ b/vclusterops/add_node.go @@ -123,26 +123,17 @@ func (o *VAddNodeOptions) validateAnalyzeOptions() error { func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDatabase, error) { vdb := MakeVCoordinationDatabase() - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig() - if err != nil { - return vdb, err - } - - err = options.validateAnalyzeOptions() + err := options.validateAnalyzeOptions() if err != nil { return vdb, err } // get hosts from config file and options. - // this, as well as all the config file related parts, - // will be moved to cmd_add_node.go after VER-88442, - // as the operator does not support config file. - hosts := options.GetHosts(config) + hosts := options.GetHosts(options.Config) options.Hosts = hosts // 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 = options.getDepotAndDataPrefix(config) + *options.DepotPrefix, *options.DataPrefix = options.getDepotAndDataPrefix(options.Config) err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions) if err != nil { diff --git a/vclusterops/add_subcluster.go b/vclusterops/add_subcluster.go index 5f6304f..05bdde5 100644 --- a/vclusterops/add_subcluster.go +++ b/vclusterops/add_subcluster.go @@ -178,13 +178,8 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro * - Create a VClusterOpEngine * - Give the instructions to the VClusterOpEngine to run */ - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig() - if err != nil { - return err - } - err = options.ValidateAnalyzeOptions(config) + err := options.ValidateAnalyzeOptions(options.Config) if err != nil { return err } @@ -199,7 +194,7 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro ControlSetSize: *options.ControlSetSize, CloneSC: *options.CloneSC, } - addSubclusterInfo.DBName, addSubclusterInfo.Hosts = options.GetNameAndHosts(config) + addSubclusterInfo.DBName, addSubclusterInfo.Hosts = options.GetNameAndHosts(options.Config) instructions, err := produceAddSubclusterInstructions(&addSubclusterInfo, options) if err != nil { diff --git a/vclusterops/remove_node.go b/vclusterops/remove_node.go index e5c7534..56e2f49 100644 --- a/vclusterops/remove_node.go +++ b/vclusterops/remove_node.go @@ -122,26 +122,18 @@ func (o *VRemoveNodeOptions) validateAnalyzeOptions() error { func (vcc *VClusterCommands) VRemoveNode(options *VRemoveNodeOptions) (VCoordinationDatabase, error) { vdb := MakeVCoordinationDatabase() - config, err := options.GetDBConfig() - if err != nil { - return vdb, err - } - // validate and analyze options - err = options.validateAnalyzeOptions() + err := options.validateAnalyzeOptions() if err != nil { return vdb, err } // get db name and hosts from config file and options. - // this, as well as all the config file related parts, - // will be moved to cmd_remove_node.go after VER-88122, - // as the operator does not support config file. - dbName, hosts := options.GetNameAndHosts(config) + dbName, hosts := options.GetNameAndHosts(options.Config) options.DBName = &dbName options.Hosts = hosts // get depot and data prefix from config file or options - *options.DepotPrefix, *options.DataPrefix = options.getDepotAndDataPrefix(config) + *options.DepotPrefix, *options.DataPrefix = options.getDepotAndDataPrefix(options.Config) err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions) if err != nil { diff --git a/vclusterops/restart_node.go b/vclusterops/restart_node.go index 7e50d63..4f2b923 100644 --- a/vclusterops/restart_node.go +++ b/vclusterops/restart_node.go @@ -119,22 +119,14 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error * - Give the instructions to the VClusterOpEngine to run */ - // TODO: library users won't have vertica_cluster.yaml, remove GetDBConfig() when VER-88442 is closed. - // load vdb info from the YAML config file - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig() - if err != nil { - return err - } - // validate and analyze options - err = options.ValidateAnalyzeOptions() + err := options.ValidateAnalyzeOptions() if err != nil { return err } // get db name and hosts from config file and options - dbName, hosts := options.GetNameAndHosts(config) + dbName, hosts := options.GetNameAndHosts(options.Config) options.DBName = &dbName options.Hosts = hosts diff --git a/vclusterops/start_db.go b/vclusterops/start_db.go index e466bb5..eb4f937 100644 --- a/vclusterops/start_db.go +++ b/vclusterops/start_db.go @@ -102,23 +102,16 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro * - Give the instructions to the VClusterOpEngine to run */ - // load vdb info from the YAML config file - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig() - if err != nil { - return err - } - - err = options.ValidateAnalyzeOptions() + err := options.ValidateAnalyzeOptions() if err != nil { return err } // get db name and hosts from config file and options - dbName, hosts := options.GetNameAndHosts(config) + dbName, hosts := options.GetNameAndHosts(options.Config) options.DBName = &dbName options.Hosts = hosts - options.CatalogPrefix = options.GetCatalogPrefix(config) + options.CatalogPrefix = options.GetCatalogPrefix(options.Config) // set default value to StatePollingTimeout if options.StatePollingTimeout == 0 { @@ -127,7 +120,7 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro var pVDB *VCoordinationDatabase // retrieve database information from cluster_config.json for EON databases - if options.IsEonMode(config) { + if options.IsEonMode(options.Config) { if *options.CommunalStorageLocation != "" { vdb, e := options.getVDBWhenDBIsDown() if e != nil { diff --git a/vclusterops/stop_db.go b/vclusterops/stop_db.go index d95e121..1683f3b 100644 --- a/vclusterops/stop_db.go +++ b/vclusterops/stop_db.go @@ -130,13 +130,7 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error * - Give the instructions to the VClusterOpEngine to run */ - // get config from vertica_cluster.yaml - config, err := options.GetDBConfig() - if err != nil { - return err - } - - err = options.ValidateAnalyzeOptions(config) + err := options.ValidateAnalyzeOptions(options.Config) if err != nil { return err } @@ -146,8 +140,8 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error stopDBInfo.UserName = *options.UserName stopDBInfo.Password = options.Password stopDBInfo.DrainSeconds = options.DrainSeconds - stopDBInfo.DBName, stopDBInfo.Hosts = options.GetNameAndHosts(config) - stopDBInfo.IsEon = options.IsEonMode(config) + stopDBInfo.DBName, stopDBInfo.Hosts = options.GetNameAndHosts(options.Config) + stopDBInfo.IsEon = options.IsEonMode(options.Config) instructions, err := vcc.produceStopDBInstructions(stopDBInfo, options) if err != nil { diff --git a/vclusterops/vcluster_database_options.go b/vclusterops/vcluster_database_options.go index 7937492..ae1c637 100644 --- a/vclusterops/vcluster_database_options.go +++ b/vclusterops/vcluster_database_options.go @@ -54,6 +54,7 @@ type DatabaseOptions struct { LogPath *string HonorUserInput *bool usePassword bool + Config *ClusterConfig } const (