Skip to content

Commit

Permalink
Sync from server repo (7c09332db7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Oct 5, 2023
1 parent ac6b0a4 commit 6fa6318
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 75 deletions.
16 changes: 13 additions & 3 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 13 additions & 2 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 12 additions & 3 deletions commands/cmd_remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 14 additions & 3 deletions commands/cmd_restart_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 13 additions & 2 deletions commands/cmd_start_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 13 additions & 2 deletions commands/cmd_stop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 3 additions & 12 deletions vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
14 changes: 3 additions & 11 deletions vclusterops/remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 2 additions & 10 deletions vclusterops/restart_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 4 additions & 11 deletions vclusterops/start_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 3 additions & 9 deletions vclusterops/stop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions vclusterops/vcluster_database_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type DatabaseOptions struct {
LogPath *string
HonorUserInput *bool
usePassword bool
Config *ClusterConfig
}

const (
Expand Down

0 comments on commit 6fa6318

Please sign in to comment.