Skip to content

Commit

Permalink
Sync from server repo (36dc356d774)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchen-vertica committed Jun 6, 2024
1 parent c66c9e9 commit fcf68fd
Show file tree
Hide file tree
Showing 44 changed files with 286 additions and 259 deletions.
9 changes: 4 additions & 5 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ const (
stopNodeFlag = "stop-hosts"
reIPFileFlag = "re-ip-file"
removeNodeFlag = "remove"
// VER-90436: restart -> start
startNodeFlag = "restart"
startHostFlag = "start-hosts"
startNodeFlag = "start"
startHostFlag = "start-hosts"
)

// Flag and key for database replication
Expand Down Expand Up @@ -169,7 +168,7 @@ const (
startSCSubCmd = "start_subcluster"
stopNodeCmd = "stop_node"
removeNodeSubCmd = "remove_node"
restartNodeSubCmd = "restart_node"
startNodeSubCmd = "start_node"
reIPSubCmd = "re_ip"
sandboxSubCmd = "sandbox_subcluster"
unsandboxSubCmd = "unsandbox_subcluster"
Expand Down Expand Up @@ -527,7 +526,7 @@ func constructCmds() []*cobra.Command {
makeCmdSandboxSubcluster(),
makeCmdUnsandboxSubcluster(),
// node-scope cmds
makeCmdRestartNodes(),
makeCmdStartNodes(),
makeCmdAddNode(),
makeCmdStopNode(),
makeCmdRemoveNode(),
Expand Down
13 changes: 7 additions & 6 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,19 @@ func (c *CmdAddNode) Run(vcc vclusterops.ClusterCommands) error {

options := c.addNodeOptions

vdb, addNodeError := vcc.VAddNode(options)
if addNodeError != nil {
return addNodeError
vdb, err := vcc.VAddNode(options)
if err != nil {
vcc.LogError(err, "fail to add node")
return err
}

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

vcc.PrintInfo("Added nodes %v to database %s", c.addNodeOptions.NewHosts, options.DBName)
vcc.DisplayInfo("Successfully added nodes %v to database %s", c.addNodeOptions.NewHosts, options.DBName)
return nil
}

Expand Down
15 changes: 6 additions & 9 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vertica/vcluster/vclusterops"
Expand Down Expand Up @@ -203,7 +201,7 @@ func (c *CmdAddSubcluster) Run(vcc vclusterops.ClusterCommands) error {

err := vcc.VAddSubcluster(options)
if err != nil {
vcc.LogError(err, "failed to add subcluster")
vcc.LogError(err, "fail to add subcluster")
return err
}

Expand All @@ -215,24 +213,23 @@ func (c *CmdAddSubcluster) Run(vcc vclusterops.ClusterCommands) error {

vdb, err := vcc.VAddNode(&options.VAddNodeOptions)
if err != nil {
const msg = "Failed to add nodes into the new subcluster"
vcc.LogError(err, msg)
fmt.Printf("%s\nHint: subcluster %q is successfully created, you should use add_node to add nodes\n",
const msg = "Fail to add nodes into the new subcluster"
vcc.DisplayError("%s\nHint: subcluster %q is successfully created, you should use add_node to add nodes\n",
msg, options.VAddNodeOptions.SCName)
return err
}
// update db info in the config file
err = writeConfig(&vdb, true /*forceOverwrite*/)
if err != nil {
vcc.PrintWarning("fail to write config file, details: %s", err)
vcc.DisplayWarning("fail to write config file, details: %s", err)
}
}

if len(options.NewHosts) > 0 {
vcc.PrintInfo("Added subcluster %s with nodes %v to database %s",
vcc.DisplayInfo("Successfully added subcluster %s with nodes %v to database %s",
options.SCName, options.NewHosts, options.DBName)
} else {
vcc.PrintInfo("Added subcluster %s to database %s", options.SCName, options.DBName)
vcc.DisplayInfo("Successfully added subcluster %s to database %s", options.SCName, options.DBName)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ func (c *CmdBase) writeCmdOutputToFile(f *os.File, output []byte, logger vlog.Pr
_, err := f.Write(output)
if err != nil {
if f == os.Stdout {
logger.PrintWarning("%s", err)
logger.DisplayWarning("%s", err)
} else {
logger.PrintWarning("Could not write command output to file %s, details: %s", c.output, err)
logger.DisplayWarning("Could not write command output to file %s, details: %s", c.output, err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_config_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *CmdConfigRecover) validateParse(logger vlog.Printer) error {
func (c *CmdConfigRecover) Run(vcc vclusterops.ClusterCommands) error {
vdb, err := vcc.VFetchCoordinationDatabase(c.recoverConfigOptions)
if err != nil {
vcc.LogError(err, "failed to recover the config file")
vcc.LogError(err, "fail to recover the config file")
return err
}
// write db info to vcluster config file
Expand All @@ -124,7 +124,7 @@ func (c *CmdConfigRecover) Run(vcc vclusterops.ClusterCommands) error {
if err != nil {
return fmt.Errorf("fail to write config file, details: %s", err)
}
vcc.PrintInfo("Recovered config file for database %s at %s", vdb.Name,
vcc.DisplayInfo("Successfully recovered config file for database %s at %s", vdb.Name,
c.recoverConfigOptions.ConfigPath)

return nil
Expand Down
3 changes: 2 additions & 1 deletion commands/cmd_config_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ func (c *CmdConfigShow) Parse(inputArgv []string, logger vlog.Printer) error {
return nil
}

func (c *CmdConfigShow) Run(_ vclusterops.ClusterCommands) error {
func (c *CmdConfigShow) Run(vcc vclusterops.ClusterCommands) error {
fileBytes, err := os.ReadFile(dbOptions.ConfigPath)
if err != nil {
return fmt.Errorf("fail to read config file, details: %w", err)
}
fmt.Printf("%s", string(fileBytes))
vcc.DisplayInfo("Successfully read the config file %s", dbOptions.ConfigPath)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_create_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *CmdCreateConnection) Run(vcc vclusterops.ClusterCommands) error {
if err != nil {
return fmt.Errorf("fail to write connection file, details: %s", err)
}
fmt.Printf("Successfully write connection file in %s", globals.connFile)
vcc.DisplayInfo("Successfully wrote the connection file in %s", globals.connFile)
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
Expand Down Expand Up @@ -211,7 +209,7 @@ func (c *CmdCreateDB) setLocalFlags(cmd *cobra.Command) {
&c.createDBOptions.TimeoutNodeStartupSeconds,
"startup-timeout",
util.DefaultTimeoutSeconds,
"The timeout to wait for the nodes to start",
"The timeout in seconds to wait for the nodes to start",
)
}

Expand Down Expand Up @@ -275,20 +273,22 @@ func (c *CmdCreateDB) Run(vcc vclusterops.ClusterCommands) error {
vcc.V(1).Info("Called method Run()")
vdb, createError := vcc.VCreateDatabase(c.createDBOptions)
if createError != nil {
vcc.LogError(createError, "fail to create database")
return createError
}

vcc.DisplayInfo("Successfully created a database with name [%s]", vdb.Name)

// write db info to vcluster config file
err := writeConfig(&vdb, c.createDBOptions.ForceOverwriteFile)
if err != nil {
fmt.Printf("Warning: Fail to write config file, details: %s\n", err)
vcc.DisplayWarning("Fail to write config file, details: %s\n", err)
}
// write config parameters to vcluster config param file
err = c.writeConfigParam(c.createDBOptions.ConfigurationParameters, c.createDBOptions.ForceOverwriteFile)
if err != nil {
vcc.PrintWarning("fail to write config param file, details: %s", err)
vcc.DisplayWarning("fail to write config param file, details: %s", err)
}
vcc.PrintInfo("Created a database with name [%s]", vdb.Name)
return nil
}

Expand Down
21 changes: 4 additions & 17 deletions commands/cmd_drop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,12 @@ Examples:
[]string{dbNameFlag, configFlag, hostsFlag, ipv6Flag, catalogPathFlag, dataPathFlag, depotPathFlag},
)

// 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
}

// setLocalFlags will set the local flags the command has
func (c *CmdDropDB) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(
&c.dropDBOptions.ForceDelete,
"force-delete",
false,
"Delete local directories like catalog, depot, and data.",
)
}

func (c *CmdDropDB) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogArgParse(&c.argv)
Expand All @@ -106,17 +93,17 @@ func (c *CmdDropDB) Run(vcc vclusterops.ClusterCommands) error {

err := vcc.VDropDatabase(c.dropDBOptions)
if err != nil {
vcc.LogError(err, "failed do drop the database")
vcc.LogError(err, "fail do drop the database")
return err
}

vcc.PrintInfo("Successfully dropped database %s", c.dropDBOptions.DBName)
vcc.DisplayInfo("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()
if err != nil {
vcc.PrintWarning("Fail to remove config file %q, "+
"please manually do it. Details: %v", c.dropDBOptions.ConfigPath, err)
vcc.DisplayWarning("Fail to remove config file %q, "+
"please manually do it, details: %v", c.dropDBOptions.ConfigPath, err)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_install_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c *CmdInstallPackages) Run(vcc vclusterops.ClusterCommands) error {

status, err := vcc.VInstallPackages(options)
if err != nil {
vcc.LogError(err, "failed to install the packages")
vcc.LogError(err, "fail to install the packages")
return err
}

Expand All @@ -129,7 +129,7 @@ func (c *CmdInstallPackages) Run(vcc vclusterops.ClusterCommands) error {

c.writeCmdOutputToFile(globals.file, bytes, vcc.GetLog())
vcc.LogInfo("Installed the packages: ", "packages", string(bytes))

vcc.DisplayInfo("Successfully installed packages")
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion commands/cmd_list_all_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *CmdListAllNodes) Run(vcc vclusterops.ClusterCommands) error {
// if all nodes are down, the nodeStates list is not empty
// for this case, we don't want to show errors but show DOWN for the nodes
if len(nodeStates) == 0 {
vcc.PrintError("fail to list all nodes: %s", err)
vcc.LogError(err, "fail to list all nodes")
return err
}
}
Expand All @@ -117,6 +117,7 @@ func (c *CmdListAllNodes) Run(vcc vclusterops.ClusterCommands) error {

c.writeCmdOutputToFile(globals.file, bytes, vcc.GetLog())
vcc.LogInfo("Node states: ", "nodeStates", string(bytes))
vcc.DisplayInfo("Successfully listed all nodes")
return nil
}

Expand Down
8 changes: 3 additions & 5 deletions commands/cmd_re_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -46,7 +44,7 @@ func makeCmdReIP() *cobra.Command {
`This command changes the IP addresses of database nodes in the catalog.
The database must be down to change the IP addresses with re_ip. If
the database is up, you must run restart_node after re_ip for the
the database is up, you must run start_node after re_ip for the
IP changes to take effect.
The file specified by the re-ip-file option must be a JSON file in the
Expand Down Expand Up @@ -138,14 +136,14 @@ func (c *CmdReIP) Run(vcc vclusterops.ClusterCommands) error {
return err
}

vcc.PrintInfo("Re-ip is successfully completed")
vcc.DisplayInfo("Successfully changed the IP addresses of database nodes")

// update config file after running re_ip
if canUpdateConfig {
c.UpdateConfig(dbConfig)
err = dbConfig.write(options.ConfigPath, true /*forceOverwrite*/)
if err != nil {
fmt.Printf("Warning: fail to update config file, details %v\n", err)
vcc.DisplayWarning("fail to update config file, details %v\n", err)
}
}

Expand Down
11 changes: 3 additions & 8 deletions commands/cmd_remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ func (c *CmdRemoveNode) setLocalFlags(cmd *cobra.Command) {
[]string{},
"Comma-separated list of host(s) to remove from the database",
)
cmd.Flags().BoolVar(
&c.removeNodeOptions.ForceDelete,
"force-delete",
true,
"Whether to force clean-up of existing directories if they are not empty",
)
}

func (c *CmdRemoveNode) Parse(inputArgv []string, logger vlog.Printer) error {
Expand Down Expand Up @@ -140,15 +134,16 @@ func (c *CmdRemoveNode) Run(vcc vclusterops.ClusterCommands) error {

vdb, err := vcc.VRemoveNode(options)
if err != nil {
vcc.LogError(err, "fail to remove node")
return err
}

// write db info to vcluster config file
err = writeConfig(&vdb, true /*forceOverwrite*/)
if err != nil {
vcc.PrintWarning("fail to write config file, details: %s", err)
vcc.DisplayWarning("fail to write config file, details: %s", err)
}
vcc.PrintInfo("Successfully removed nodes %v from database %s", c.removeNodeOptions.HostsToRemove, options.DBName)
vcc.DisplayInfo("Successfully removed nodes %v from database %s", c.removeNodeOptions.HostsToRemove, options.DBName)

return nil
}
Expand Down
14 changes: 5 additions & 9 deletions commands/cmd_remove_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ func (c *CmdRemoveSubcluster) setLocalFlags(cmd *cobra.Command) {
"",
"Name of subcluster to be removed",
)
cmd.Flags().BoolVar(
&c.removeScOptions.ForceDelete,
"force-delete",
true,
"Whether force delete directories if they are not empty",
)
}

func (c *CmdRemoveSubcluster) Parse(inputArgv []string, logger vlog.Printer) error {
Expand Down Expand Up @@ -130,16 +124,18 @@ func (c *CmdRemoveSubcluster) Run(vcc vclusterops.ClusterCommands) error {

vdb, err := vcc.VRemoveSubcluster(options)
if err != nil {
vcc.LogError(err, "fail to remove subcluster")
return err
}

vcc.DisplayInfo("Successfully removed subcluster %s from database %s",
options.SCName, options.DBName)

// write db info to vcluster config file
err = writeConfig(&vdb, true /*forceOverwrite*/)
if err != nil {
vcc.PrintWarning("fail to write config file, details: %s", err)
vcc.DisplayWarning("fail to write config file, details: %s", err)
}
vcc.PrintInfo("Successfully removed subcluster %s from database %s",
options.SCName, options.DBName)

return nil
}
Expand Down
Loading

0 comments on commit fcf68fd

Please sign in to comment.