Skip to content

Commit

Permalink
Sync from server repo (9303b253b25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Sep 8, 2023
1 parent a7b1e1f commit aa31924
Show file tree
Hide file tree
Showing 36 changed files with 213 additions and 134 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ linters-settings:
funlen:
lines: 100
statements: 50
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
Expand Down
22 changes: 0 additions & 22 deletions .vscode/launch.json

This file was deleted.

4 changes: 2 additions & 2 deletions commands/cluster_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package commands

import "github.com/go-logr/logr"
import "github.com/vertica/vcluster/vclusterops/vlog"

type ClusterCommand interface {
CommandType() string
Expand All @@ -27,6 +27,6 @@ type ClusterCommand interface {
* cluster discovery.
*/
Analyze() error
Run(log logr.Logger) error
Run(log vlog.Printer) error
PrintUsage(string)
}
3 changes: 2 additions & 1 deletion commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ func (c ClusterCommandLauncher) Run(inputArgv []string) error {
if analyzeError != nil {
return analyzeError
}
return subCommand.Run(vlog.GetGlobalLogger().Log)
log := vlog.GetGlobalLogger().Printer
return subCommand.Run(log)
}

func identifySubcommand(commands map[string]ClusterCommand) (ClusterCommand, error) {
Expand Down
5 changes: 2 additions & 3 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"flag"
"fmt"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (c *CmdAddNode) Analyze() error {
return nil
}

func (c *CmdAddNode) Run(log logr.Logger) error {
func (c *CmdAddNode) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand All @@ -140,6 +139,6 @@ func (c *CmdAddNode) Run(log logr.Logger) error {
if err != nil {
vlog.LogPrintWarning("fail to write config file, details: %s", err)
}
vlog.LogPrintInfo("Added nodes %s to database %s", *c.newHostListStr, *c.addNodeOptions.Name)
vcc.Log.PrintInfo("Added nodes %s to database %s", *c.newHostListStr, *c.addNodeOptions.Name)
return nil
}
3 changes: 1 addition & 2 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands
import (
"flag"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -125,7 +124,7 @@ func (c *CmdAddSubcluster) Analyze() error {
return nil
}

func (c *CmdAddSubcluster) Run(log logr.Logger) error {
func (c *CmdAddSubcluster) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"path/filepath"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
)
Expand Down Expand Up @@ -83,7 +82,7 @@ func (c *CmdConfig) Analyze() error {
return nil
}

func (c *CmdConfig) Run(_ logr.Logger) error {
func (c *CmdConfig) Run(_ vlog.Printer) error {
if *c.show {
configFilePath := filepath.Join(*c.directory, vclusterops.ConfigFileName)
fileBytes, err := os.ReadFile(configFilePath)
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands
import (
"flag"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (c *CmdCreateDB) Analyze() error {
return nil
}

func (c *CmdCreateDB) Run(log logr.Logger) error {
func (c *CmdCreateDB) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
5 changes: 2 additions & 3 deletions commands/cmd_drop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"flag"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -80,13 +79,13 @@ func (c *CmdDropDB) Analyze() error {
return nil
}

func (c *CmdDropDB) Run(log logr.Logger) error {
func (c *CmdDropDB) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
vcc.Log.V(1).Info("Called method Run()")

err := vclusterops.VDropDatabase(c.dropDBOptions)
err := vcc.VDropDatabase(c.dropDBOptions)
if err != nil {
vcc.Log.Error(err, "failed do drop the database")
return err
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"flag"
"fmt"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops/vlog"
)

Expand Down Expand Up @@ -73,6 +72,6 @@ func (c *CmdHelp) Analyze() error {
return nil
}

func (c *CmdHelp) Run(_ logr.Logger) error {
func (c *CmdHelp) Run(_ vlog.Printer) error {
return nil
}
3 changes: 1 addition & 2 deletions commands/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"path/filepath"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -94,7 +93,7 @@ func (c *CmdInit) Analyze() error {
return nil
}

func (c *CmdInit) Run(_ logr.Logger) error {
func (c *CmdInit) Run(_ vlog.Printer) error {
configFilePath := filepath.Join(*c.directory, vclusterops.ConfigFileName)

// check config file existence
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_list_all_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -76,7 +75,7 @@ func (c *CmdListAllNodes) Analyze() error {
return nil
}

func (c *CmdListAllNodes) Run(log logr.Logger) error {
func (c *CmdListAllNodes) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
5 changes: 2 additions & 3 deletions commands/cmd_re_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
)
Expand Down Expand Up @@ -80,7 +79,7 @@ func (c *CmdReIP) Analyze() error {
return c.reIPOptions.ReadReIPFile(*c.reIPFilePath)
}

func (c *CmdReIP) Run(log logr.Logger) error {
func (c *CmdReIP) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand All @@ -91,6 +90,6 @@ func (c *CmdReIP) Run(log logr.Logger) error {
return err
}

vlog.LogPrintInfo("Re-ip is successfully completed")
vcc.Log.PrintInfo("Re-ip is successfully completed")
return nil
}
3 changes: 1 addition & 2 deletions commands/cmd_remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands
import (
"flag"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -107,7 +106,7 @@ func (c *CmdRemoveNode) Analyze() error {
return nil
}

func (c *CmdRemoveNode) Run(log logr.Logger) error {
func (c *CmdRemoveNode) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
12 changes: 5 additions & 7 deletions commands/cmd_remove_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands
import (
"flag"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -98,26 +97,25 @@ func (c *CmdRemoveSubcluster) Analyze() error {
return nil
}

func (c *CmdRemoveSubcluster) Run(log logr.Logger) error {
vlog.LogInfo("[%s] Called method Run()", c.CommandType())

func (c *CmdRemoveSubcluster) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}

vcc.Log.V(1).Info("Called method Run()")
vdb, err := vcc.VRemoveSubcluster(c.removeScOptions)
if err != nil {
return err
}
vlog.LogPrintInfo("Successfully removed subcluster %s from database %s",
vcc.Log.PrintInfo("Successfully removed subcluster %s from database %s",
*c.removeScOptions.SubclusterToRemove, *c.removeScOptions.Name)

// write cluster information to the YAML config file.
err = vclusterops.WriteClusterConfig(&vdb, c.removeScOptions.ConfigDirectory)
if err != nil {
vlog.LogPrintWarning("failed to write config file, details: %s", err)
vcc.Log.PrintWarning("failed to write config file, details: %s", err)
}
vlog.LogPrintInfo("Successfully updated config file")
vcc.Log.PrintInfo("Successfully updated config file")

return nil
}
3 changes: 1 addition & 2 deletions commands/cmd_restart_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strconv"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -101,7 +100,7 @@ func (c *CmdRestartNodes) Analyze() error {
return nil
}

func (c *CmdRestartNodes) Run(log logr.Logger) error {
func (c *CmdRestartNodes) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
7 changes: 3 additions & 4 deletions commands/cmd_revive_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"strconv"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -106,7 +105,7 @@ func (c *CmdReviveDB) Analyze() error {
return nil
}

func (c *CmdReviveDB) Run(log logr.Logger) error {
func (c *CmdReviveDB) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand All @@ -118,11 +117,11 @@ func (c *CmdReviveDB) Run(log logr.Logger) error {
}

if *c.reviveDBOptions.DisplayOnly {
vlog.LogPrintInfo("database details:\n%s", dbInfo)
vcc.Log.PrintInfo("database details:\n%s", dbInfo)
return nil
}

vlog.LogPrintInfo("Successfully revived database %s", *c.reviveDBOptions.Name)
vcc.Log.PrintInfo("Successfully revived database %s", *c.reviveDBOptions.Name)

return nil
}
3 changes: 1 addition & 2 deletions commands/cmd_start_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strconv"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -115,7 +114,7 @@ func (c *CmdStartDB) Analyze() error {
return nil
}

func (c *CmdStartDB) Run(log logr.Logger) error {
func (c *CmdStartDB) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_stop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"flag"
"strconv"

"github.com/go-logr/logr"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (c *CmdStopDB) Analyze() error {
return nil
}

func (c *CmdStopDB) Run(log logr.Logger) error {
func (c *CmdStopDB) Run(log vlog.Printer) error {
vcc := vclusterops.VClusterCommands{
Log: log.WithName(c.CommandType()),
}
Expand Down
6 changes: 4 additions & 2 deletions commands/init_and_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func TestInitCmd(t *testing.T) {
func TestConfigCmd(t *testing.T) {
// redirect log to a local bytes.Buffer
var logStr bytes.Buffer
log := buflogr.NewWithBuffer(&logStr)
log := vlog.Printer{
Log: buflogr.NewWithBuffer(&logStr),
}
vlogger := vlog.GetGlobalLogger()
vlogger.Log = log
vlogger.Log = log.Log

// create a stub YAML file
const yamlPath = vclusterops.ConfigFileName
Expand Down
Loading

0 comments on commit aa31924

Please sign in to comment.