diff --git a/commands/cluster_command_launcher.go b/commands/cluster_command_launcher.go index adbeb93..90d2682 100644 --- a/commands/cluster_command_launcher.go +++ b/commands/cluster_command_launcher.go @@ -214,7 +214,7 @@ func Execute() { func initVcc(cmd *cobra.Command) vclusterops.VClusterCommands { // setup logs logger := vlog.Printer{ForCli: true} - logger.SetupOrDie(*dbOptions.LogPath) + logger.SetupOrDie(dbOptions.LogPath) vcc := vclusterops.VClusterCommands{ VClusterCommandsLogger: vclusterops.VClusterCommandsLogger{ @@ -230,17 +230,17 @@ func initVcc(cmd *cobra.Command) vclusterops.VClusterCommands { func setDBOptionsUsingViper(flag string) error { switch flag { case dbNameFlag: - *dbOptions.DBName = viper.GetString(dbNameKey) + dbOptions.DBName = viper.GetString(dbNameKey) case hostsFlag: dbOptions.RawHosts = viper.GetStringSlice(hostsKey) case catalogPathFlag: - *dbOptions.CatalogPrefix = viper.GetString(catalogPathKey) + dbOptions.CatalogPrefix = viper.GetString(catalogPathKey) case depotPathFlag: - *dbOptions.DepotPrefix = viper.GetString(depotPathKey) + dbOptions.DepotPrefix = viper.GetString(depotPathKey) case dataPathFlag: - *dbOptions.DataPrefix = viper.GetString(dataPathKey) + dbOptions.DataPrefix = viper.GetString(dataPathKey) case communalStorageLocationFlag: - *dbOptions.CommunalStorageLocation = viper.GetString(communalStorageLocationKey) + dbOptions.CommunalStorageLocation = viper.GetString(communalStorageLocationKey) case ipv6Flag: dbOptions.IPv6 = viper.GetBool(ipv6Key) case eonModeFlag: @@ -248,7 +248,7 @@ func setDBOptionsUsingViper(flag string) error { case configParamFlag: dbOptions.ConfigurationParameters = viper.GetStringMapString(configParamKey) case logPathFlag: - *dbOptions.LogPath = viper.GetString(logPathKey) + dbOptions.LogPath = viper.GetString(logPathKey) case keyFileFlag: globals.keyFile = viper.GetString(keyFileKey) case certFileFlag: diff --git a/commands/cmd_add_node.go b/commands/cmd_add_node.go index a16acc9..bb316e3 100644 --- a/commands/cmd_add_node.go +++ b/commands/cmd_add_node.go @@ -93,7 +93,7 @@ func (c *CmdAddNode) setLocalFlags(cmd *cobra.Command) { "Comma-separated list of host(s) to add to the database", ) cmd.Flags().BoolVar( - c.addNodeOptions.ForceRemoval, + &c.addNodeOptions.ForceRemoval, "force-removal", false, "Whether to force clean-up of existing directories before adding host(s)", @@ -105,14 +105,14 @@ func (c *CmdAddNode) setLocalFlags(cmd *cobra.Command) { util.GetEonFlagMsg("Skip the subcluster shards rebalancing"), ) cmd.Flags().StringVar( - c.addNodeOptions.SCName, + &c.addNodeOptions.SCName, subclusterFlag, "", util.GetEonFlagMsg("The Name of subcluster"+ " to which the host(s) must be added. If empty default subcluster is considered"), ) cmd.Flags().StringVar( - c.addNodeOptions.DepotSize, + &c.addNodeOptions.DepotSize, "depot-size", "", util.GetEonFlagMsg("Size of depot"), @@ -179,7 +179,7 @@ func (c *CmdAddNode) parseNodeNameList() error { if c.parser.Changed("node-names") { if c.nodeNameListStr == "" { return fmt.Errorf("when --node-names is specified, "+ - "must provide all existing node names in %q", *c.addNodeOptions.DBName) + "must provide all existing node names in %q", c.addNodeOptions.DBName) } c.addNodeOptions.ExpectedNodeNames = strings.Split(c.nodeNameListStr, ",") @@ -204,7 +204,7 @@ func (c *CmdAddNode) Run(vcc vclusterops.ClusterCommands) error { vcc.PrintWarning("fail to write config file, details: %s", err) } - vcc.PrintInfo("Added nodes %v to database %s", c.addNodeOptions.NewHosts, *options.DBName) + 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 75d7b2b..fc3b30a 100644 --- a/commands/cmd_add_subcluster.go +++ b/commands/cmd_add_subcluster.go @@ -100,19 +100,19 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdAddSubcluster) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - c.addSubclusterOptions.SCName, + &c.addSubclusterOptions.SCName, subclusterFlag, "", "The name of the new subcluster", ) cmd.Flags().BoolVar( - c.addSubclusterOptions.IsPrimary, + &c.addSubclusterOptions.IsPrimary, "is-primary", false, "The new subcluster will be a primary subcluster", ) cmd.Flags().IntVar( - c.addSubclusterOptions.ControlSetSize, + &c.addSubclusterOptions.ControlSetSize, "control-set-size", vclusterops.ControlSetSizeDefaultValue, "The number of nodes that will run spread within the subcluster", @@ -124,7 +124,7 @@ func (c *CmdAddSubcluster) setLocalFlags(cmd *cobra.Command) { "Comma-separated list of host(s) to add to the new subcluster", ) cmd.Flags().BoolVar( - c.addSubclusterOptions.ForceRemoval, + &c.addSubclusterOptions.ForceRemoval, "force-removal", false, "Whether to force clean-up of existing directories before adding host(s)", @@ -136,7 +136,7 @@ func (c *CmdAddSubcluster) setLocalFlags(cmd *cobra.Command) { util.GetEonFlagMsg("Skip the subcluster shards rebalancing"), ) cmd.Flags().StringVar( - c.addSubclusterOptions.DepotSize, + &c.addSubclusterOptions.DepotSize, "depot-size", "", util.GetEonFlagMsg("Size of depot"), @@ -153,7 +153,7 @@ func (c *CmdAddSubcluster) setHiddenFlags(cmd *cobra.Command) { "", ) cmd.Flags().StringVar( - c.addSubclusterOptions.CloneSC, + &c.addSubclusterOptions.CloneSC, "like", "", "", @@ -209,7 +209,7 @@ func (c *CmdAddSubcluster) Run(vcc vclusterops.ClusterCommands) error { if len(options.NewHosts) > 0 { fmt.Printf("Adding hosts %v to subcluster %s\n", - options.NewHosts, *options.SCName) + options.NewHosts, options.SCName) options.VAddNodeOptions.DatabaseOptions = c.addSubclusterOptions.DatabaseOptions options.VAddNodeOptions.SCName = c.addSubclusterOptions.SCName @@ -228,9 +228,9 @@ func (c *CmdAddSubcluster) Run(vcc vclusterops.ClusterCommands) error { if len(options.NewHosts) > 0 { vcc.PrintInfo("Added subcluster %s with nodes %v to database %s", - *options.SCName, options.NewHosts, *options.DBName) + options.SCName, options.NewHosts, options.DBName) } else { - vcc.PrintInfo("Added subcluster %s to database %s", *options.SCName, *options.DBName) + vcc.PrintInfo("Added subcluster %s to database %s", options.SCName, options.DBName) } return nil } diff --git a/commands/cmd_base.go b/commands/cmd_base.go index e6ea124..45eeaaf 100644 --- a/commands/cmd_base.go +++ b/commands/cmd_base.go @@ -76,7 +76,7 @@ func (c *CmdBase) setCommonFlags(cmd *cobra.Command, flags []string) { } // log-path is a flag that all the subcommands need cmd.Flags().StringVarP( - dbOptions.LogPath, + &dbOptions.LogPath, logPathFlag, "l", logPath, @@ -122,7 +122,7 @@ func (c *CmdBase) setCommonFlags(cmd *cobra.Command, flags []string) { } if util.StringInArray(dbUserFlag, flags) { cmd.Flags().StringVar( - dbOptions.UserName, + &dbOptions.UserName, dbUserFlag, "", "The username for connecting to the database", @@ -135,7 +135,7 @@ func (c *CmdBase) setCommonFlags(cmd *cobra.Command, flags []string) { func setConfigFlags(cmd *cobra.Command, flags []string) { if util.StringInArray(dbNameFlag, flags) { cmd.Flags().StringVarP( - dbOptions.DBName, + &dbOptions.DBName, dbNameFlag, "d", "", @@ -159,7 +159,7 @@ func setConfigFlags(cmd *cobra.Command, flags []string) { } if util.StringInArray(catalogPathFlag, flags) { cmd.Flags().StringVar( - dbOptions.CatalogPrefix, + &dbOptions.CatalogPrefix, catalogPathFlag, "", "Path of catalog directory") @@ -167,7 +167,7 @@ func setConfigFlags(cmd *cobra.Command, flags []string) { } if util.StringInArray(dataPathFlag, flags) { cmd.Flags().StringVar( - dbOptions.DataPrefix, + &dbOptions.DataPrefix, dataPathFlag, "", "Path of data directory") @@ -175,14 +175,14 @@ func setConfigFlags(cmd *cobra.Command, flags []string) { } if util.StringInArray(communalStorageLocationFlag, flags) { cmd.Flags().StringVar( - dbOptions.CommunalStorageLocation, + &dbOptions.CommunalStorageLocation, communalStorageLocationFlag, "", util.GetEonFlagMsg("Location of communal storage")) } if util.StringInArray(depotPathFlag, flags) { cmd.Flags().StringVar( - dbOptions.DepotPrefix, + &dbOptions.DepotPrefix, depotPathFlag, "", util.GetEonFlagMsg("Path to depot directory")) diff --git a/commands/cmd_create_db.go b/commands/cmd_create_db.go index 7eda090..bfae8ef 100644 --- a/commands/cmd_create_db.go +++ b/commands/cmd_create_db.go @@ -121,92 +121,92 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdCreateDB) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - c.createDBOptions.LicensePathOnNode, + &c.createDBOptions.LicensePathOnNode, "license", "", "Database license", ) cmd.Flags().StringVar( - c.createDBOptions.Policy, + &c.createDBOptions.Policy, "policy", util.DefaultRestartPolicy, "Restart policy of the database", ) cmd.Flags().StringVar( - c.createDBOptions.SQLFile, + &c.createDBOptions.SQLFile, "sql", "", "SQL file to run (as dbadmin) immediately on database creation", ) markFlagsFileName(cmd, map[string][]string{"sql": {"sql"}}) cmd.Flags().IntVar( - c.createDBOptions.ShardCount, + &c.createDBOptions.ShardCount, "shard-count", 0, util.GetEonFlagMsg("Number of shards in the database"), ) cmd.Flags().StringVar( - c.createDBOptions.DepotSize, + &c.createDBOptions.DepotSize, "depot-size", "", util.GetEonFlagMsg("Size of depot"), ) cmd.Flags().BoolVar( - c.createDBOptions.GetAwsCredentialsFromEnv, + &c.createDBOptions.GetAwsCredentialsFromEnv, "get-aws-credentials-from-env-vars", false, util.GetEonFlagMsg("Read AWS credentials from environment variables"), ) cmd.Flags().BoolVar( - c.createDBOptions.P2p, + &c.createDBOptions.P2p, "point-to-point", true, "Configure Spread to use point-to-point communication between all Vertica nodes", ) cmd.Flags().BoolVar( - c.createDBOptions.Broadcast, + &c.createDBOptions.Broadcast, "broadcast", false, "Configure Spread to use UDP broadcast traffic between nodes on the same subnet", ) cmd.Flags().IntVar( - c.createDBOptions.LargeCluster, + &c.createDBOptions.LargeCluster, "large-cluster", -1, "Enables a large cluster layout", ) cmd.Flags().BoolVar( - c.createDBOptions.SpreadLogging, + &c.createDBOptions.SpreadLogging, "spread-logging", false, "Whether enable spread logging", ) cmd.Flags().IntVar( - c.createDBOptions.SpreadLoggingLevel, + &c.createDBOptions.SpreadLoggingLevel, "spread-logging-level", -1, "Spread logging level", ) cmd.Flags().BoolVar( - c.createDBOptions.ForceCleanupOnFailure, + &c.createDBOptions.ForceCleanupOnFailure, "force-cleanup-on-failure", false, "Force removal of existing directories on failure of command", ) cmd.Flags().BoolVar( - c.createDBOptions.ForceRemovalAtCreation, + &c.createDBOptions.ForceRemovalAtCreation, "force-removal-at-creation", false, "Force removal of existing directories before creating the database", ) cmd.Flags().BoolVar( - c.createDBOptions.SkipPackageInstall, + &c.createDBOptions.SkipPackageInstall, "skip-package-install", false, "Skip the installation of packages from /opt/vertica/packages.", ) cmd.Flags().IntVar( - c.createDBOptions.TimeoutNodeStartupSeconds, + &c.createDBOptions.TimeoutNodeStartupSeconds, "startup-timeout", util.DefaultTimeoutSeconds, "The timeout to wait for the nodes to start", @@ -217,13 +217,13 @@ func (c *CmdCreateDB) setLocalFlags(cmd *cobra.Command) { // These hidden flags will not be shown in help and usage of the command, and they will be used internally. func (c *CmdCreateDB) setHiddenFlags(cmd *cobra.Command) { cmd.Flags().IntVar( - c.createDBOptions.ClientPort, + &c.createDBOptions.ClientPort, "client-port", util.DefaultClientPort, "", ) cmd.Flags().BoolVar( - c.createDBOptions.SkipStartupPolling, + &c.createDBOptions.SkipStartupPolling, "skip-startup-polling", false, "", diff --git a/commands/cmd_drop_db.go b/commands/cmd_drop_db.go index cce0fdc..9b57f93 100644 --- a/commands/cmd_drop_db.go +++ b/commands/cmd_drop_db.go @@ -35,7 +35,6 @@ func makeCmdDropDB() *cobra.Command { newCmd := &CmdDropDB{} opt := vclusterops.VDropDatabaseOptionsFactory() newCmd.dropDBOptions = &opt - newCmd.dropDBOptions.ForceDelete = new(bool) // VER-92345 update the long description about the hosts option cmd := makeBasicCobraCmd( @@ -75,7 +74,7 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdDropDB) setLocalFlags(cmd *cobra.Command) { cmd.Flags().BoolVar( - c.dropDBOptions.ForceDelete, + &c.dropDBOptions.ForceDelete, "force-delete", false, "Delete local directories like catalog, depot, and data.", @@ -107,7 +106,7 @@ func (c *CmdDropDB) Run(vcc vclusterops.ClusterCommands) error { return err } - vcc.PrintInfo("Successfully dropped database %s", *c.dropDBOptions.DBName) + 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()) diff --git a/commands/cmd_install_packages.go b/commands/cmd_install_packages.go index c7636d5..6f71b58 100644 --- a/commands/cmd_install_packages.go +++ b/commands/cmd_install_packages.go @@ -72,7 +72,7 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdInstallPackages) setLocalFlags(cmd *cobra.Command) { cmd.Flags().BoolVar( - c.installPkgOpts.ForceReinstall, + &c.installPkgOpts.ForceReinstall, "force-reinstall", false, "Install the packages, even if they are already installed.", diff --git a/commands/cmd_remove_node.go b/commands/cmd_remove_node.go index 78209f9..dfd3bfc 100644 --- a/commands/cmd_remove_node.go +++ b/commands/cmd_remove_node.go @@ -82,7 +82,7 @@ func (c *CmdRemoveNode) setLocalFlags(cmd *cobra.Command) { "Comma-separated list of host(s) to remove from the database", ) cmd.Flags().BoolVar( - c.removeNodeOptions.ForceDelete, + &c.removeNodeOptions.ForceDelete, "force-delete", true, "Whether to force clean-up of existing directories if they are not empty", @@ -148,7 +148,7 @@ func (c *CmdRemoveNode) Run(vcc vclusterops.ClusterCommands) error { if err != nil { vcc.PrintWarning("fail to write config file, details: %s", err) } - vcc.PrintInfo("Successfully removed nodes %v from database %s", c.removeNodeOptions.HostsToRemove, *options.DBName) + vcc.PrintInfo("Successfully removed nodes %v from database %s", c.removeNodeOptions.HostsToRemove, options.DBName) return nil } diff --git a/commands/cmd_remove_subcluster.go b/commands/cmd_remove_subcluster.go index a5ad52d..132410e 100644 --- a/commands/cmd_remove_subcluster.go +++ b/commands/cmd_remove_subcluster.go @@ -77,13 +77,13 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdRemoveSubcluster) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - c.removeScOptions.SubclusterToRemove, + &c.removeScOptions.SubclusterToRemove, subclusterFlag, "", "Name of subcluster to be removed", ) cmd.Flags().BoolVar( - c.removeScOptions.ForceDelete, + &c.removeScOptions.ForceDelete, "force-delete", true, "Whether force delete directories if they are not empty", @@ -139,7 +139,7 @@ func (c *CmdRemoveSubcluster) Run(vcc vclusterops.ClusterCommands) error { vcc.PrintWarning("fail to write config file, details: %s", err) } vcc.PrintInfo("Successfully removed subcluster %s from database %s", - *options.SubclusterToRemove, *options.DBName) + options.SubclusterToRemove, options.DBName) return nil } diff --git a/commands/cmd_restart_node.go b/commands/cmd_restart_node.go index 63f5f61..7484cc2 100644 --- a/commands/cmd_restart_node.go +++ b/commands/cmd_restart_node.go @@ -144,7 +144,7 @@ func (c *CmdRestartNodes) Run(vcc vclusterops.ClusterCommands) error { for _, ip := range options.Nodes { hostToRestart = append(hostToRestart, ip) } - vcc.PrintInfo("Successfully restart hosts %s of the database %s", hostToRestart, *options.DBName) + vcc.PrintInfo("Successfully restart hosts %s of the database %s", hostToRestart, options.DBName) return nil } diff --git a/commands/cmd_revive_db.go b/commands/cmd_revive_db.go index 2ba2903..46c8676 100644 --- a/commands/cmd_revive_db.go +++ b/commands/cmd_revive_db.go @@ -38,7 +38,6 @@ func makeCmdReviveDB() *cobra.Command { newCmd := &CmdReviveDB{} opt := vclusterops.VReviveDBOptionsFactory() newCmd.reviveDBOptions = &opt - newCmd.reviveDBOptions.CommunalStorageLocation = new(string) cmd := makeBasicCobraCmd( newCmd, @@ -171,7 +170,7 @@ func (c *CmdReviveDB) Run(vcc vclusterops.ClusterCommands) error { vcc.LogInfo("Called method Run()") dbInfo, vdb, err := vcc.VReviveDatabase(c.reviveDBOptions) if err != nil { - vcc.LogError(err, "fail to revive database", "DBName", *c.reviveDBOptions.DBName) + vcc.LogError(err, "fail to revive database", "DBName", c.reviveDBOptions.DBName) return err } @@ -187,7 +186,7 @@ func (c *CmdReviveDB) Run(vcc vclusterops.ClusterCommands) error { vcc.PrintWarning("fail to write config file, details: %s", err) } - vcc.PrintInfo("Successfully revived database %s", *c.reviveDBOptions.DBName) + vcc.PrintInfo("Successfully revived database %s", c.reviveDBOptions.DBName) return nil } diff --git a/commands/cmd_sandbox.go b/commands/cmd_sandbox.go index 0d10653..5f1d547 100644 --- a/commands/cmd_sandbox.go +++ b/commands/cmd_sandbox.go @@ -84,13 +84,13 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdSandboxSubcluster) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - c.sbOptions.SCName, + &c.sbOptions.SCName, subclusterFlag, "", "The name of the subcluster to be sandboxed", ) cmd.Flags().StringVar( - c.sbOptions.SandboxName, + &c.sbOptions.SandboxName, sandboxFlag, "", "The name of the sandbox", diff --git a/commands/cmd_scrutinize.go b/commands/cmd_scrutinize.go index ba8579d..976cb38 100644 --- a/commands/cmd_scrutinize.go +++ b/commands/cmd_scrutinize.go @@ -115,7 +115,7 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdScrutinize) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - dbOptions.UserName, + &dbOptions.UserName, "db-user", "", "Database username. Consider using single quotes "+ @@ -252,7 +252,7 @@ func (c *CmdScrutinize) Run(vcc vclusterops.ClusterCommands) error { vcc.LogError(err, "scrutinize run failed") return err } - vcc.PrintInfo("Successfully completed scrutinize run for the database %s", *c.sOptions.DBName) + vcc.PrintInfo("Successfully completed scrutinize run for the database %s", c.sOptions.DBName) return err } @@ -445,16 +445,16 @@ func (c *CmdScrutinize) readOptionsFromK8sEnv(logger vlog.Printer) (allErrs erro if !found || dbName == "" { allErrs = errors.Join(allErrs, fmt.Errorf("unable to get database name from environment variable. ")) } else { - c.sOptions.DBName = &dbName - logger.Info("Setting database name from env as", "DBName", *c.sOptions.DBName) + c.sOptions.DBName = dbName + logger.Info("Setting database name from env as", "DBName", c.sOptions.DBName) } catPrefix, found := os.LookupEnv(catalogPathPref) if !found || catPrefix == "" { allErrs = errors.Join(allErrs, fmt.Errorf("unable to get catalog path from environment variable. ")) } else { - c.sOptions.CatalogPrefix = &catPrefix - logger.Info("Setting catalog path from env as", "CatalogPrefix", *c.sOptions.CatalogPrefix) + c.sOptions.CatalogPrefix = catPrefix + logger.Info("Setting catalog path from env as", "CatalogPrefix", c.sOptions.CatalogPrefix) } return } diff --git a/commands/cmd_show_restore_points.go b/commands/cmd_show_restore_points.go index e0988e4..db6ef5d 100644 --- a/commands/cmd_show_restore_points.go +++ b/commands/cmd_show_restore_points.go @@ -90,31 +90,31 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdShowRestorePoints) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - c.showRestorePointsOptions.FilterOptions.ArchiveName, + &c.showRestorePointsOptions.FilterOptions.ArchiveName, "restore-point-archive", "", "Archive name to filter restore points with", ) cmd.Flags().StringVar( - c.showRestorePointsOptions.FilterOptions.ArchiveID, + &c.showRestorePointsOptions.FilterOptions.ArchiveID, "restore-point-id", "", "ID to filter restore points with", ) cmd.Flags().StringVar( - c.showRestorePointsOptions.FilterOptions.ArchiveIndex, + &c.showRestorePointsOptions.FilterOptions.ArchiveIndex, "restore-point-index", "", "Index to filter restore points with", ) cmd.Flags().StringVar( - c.showRestorePointsOptions.FilterOptions.StartTimestamp, + &c.showRestorePointsOptions.FilterOptions.StartTimestamp, "start-timestamp", "", "Only show restores points created no earlier than this", ) cmd.Flags().StringVar( - c.showRestorePointsOptions.FilterOptions.EndTimestamp, + &c.showRestorePointsOptions.FilterOptions.EndTimestamp, "end-timestamp", "", "Only show restores points created no later than this", @@ -160,11 +160,11 @@ func (c *CmdShowRestorePoints) Run(vcc vclusterops.ClusterCommands) error { restorePoints, err := vcc.VShowRestorePoints(options) if err != nil { - vcc.LogError(err, "fail to show restore points", "DBName", *options.DBName) + vcc.LogError(err, "fail to show restore points", "DBName", options.DBName) return err } - vcc.PrintInfo("Successfully show restore points %v in database %s", restorePoints, *options.DBName) + vcc.PrintInfo("Successfully show restore points %v in database %s", restorePoints, options.DBName) return nil } diff --git a/commands/cmd_start_db.go b/commands/cmd_start_db.go index ec7a8a3..eeee280 100644 --- a/commands/cmd_start_db.go +++ b/commands/cmd_start_db.go @@ -42,7 +42,6 @@ func makeCmdStartDB() *cobra.Command { newCmd := &CmdStartDB{} opt := vclusterops.VStartDatabaseOptionsFactory() newCmd.startDBOptions = &opt - newCmd.startDBOptions.CommunalStorageLocation = new(string) cmd := makeBasicCobraCmd( newCmd, @@ -84,7 +83,7 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdStartDB) setLocalFlags(cmd *cobra.Command) { cmd.Flags().IntVar( - c.startDBOptions.StatePollingTimeout, + &c.startDBOptions.StatePollingTimeout, "timeout", util.DefaultTimeoutSeconds, "The timeout (in seconds) to wait for polling node state operation", @@ -125,7 +124,7 @@ func (c *CmdStartDB) setHiddenFlags(cmd *cobra.Command) { "", ) cmd.Flags().BoolVar( - c.startDBOptions.TrimHostList, + &c.startDBOptions.TrimHostList, "trim-hosts", false, "", @@ -167,7 +166,7 @@ func (c *CmdStartDB) Run(vcc vclusterops.ClusterCommands) error { return err } - vcc.PrintInfo("Successfully start the database %s", *options.DBName) + vcc.PrintInfo("Successfully start the database %s", options.DBName) // for Eon database, update config file to fill nodes' subcluster information if options.IsEon { diff --git a/commands/cmd_stop_db.go b/commands/cmd_stop_db.go index 1607320..0db3a7f 100644 --- a/commands/cmd_stop_db.go +++ b/commands/cmd_stop_db.go @@ -79,13 +79,13 @@ func (c *CmdStopDB) setLocalFlags(cmd *cobra.Command) { " When the time expires, connections will be forcibly closed and the db will shut down"), ) cmd.Flags().StringVar( - c.stopDBOptions.Sandbox, + &c.stopDBOptions.Sandbox, sandboxFlag, "", "Name of the sandbox to stop", ) cmd.Flags().BoolVar( - c.stopDBOptions.MainCluster, + &c.stopDBOptions.MainCluster, "main-cluster-only", false, "Stop the database, but don't stop any of the sandboxes", @@ -96,13 +96,13 @@ func (c *CmdStopDB) setLocalFlags(cmd *cobra.Command) { // These hidden flags will not be shown in help and usage of the command, and they will be used internally. func (c *CmdStopDB) setHiddenFlags(cmd *cobra.Command) { cmd.Flags().BoolVar( - c.stopDBOptions.CheckUserConn, + &c.stopDBOptions.CheckUserConn, "if-no-users", false, "", ) cmd.Flags().BoolVar( - c.stopDBOptions.ForceKill, + &c.stopDBOptions.ForceKill, "force-kill", false, "", @@ -150,13 +150,13 @@ func (c *CmdStopDB) Run(vcc vclusterops.ClusterCommands) error { vcc.LogError(err, "failed to stop the database") return err } - msg := fmt.Sprintf("Stopped a database with name %s", *options.DBName) - if *options.Sandbox != "" { - sandboxMsg := fmt.Sprintf(" on sandbox %s", *options.Sandbox) + msg := fmt.Sprintf("Stopped a database with name %s", options.DBName) + if options.Sandbox != "" { + sandboxMsg := fmt.Sprintf(" on sandbox %s", options.Sandbox) vcc.PrintInfo(msg + sandboxMsg) return nil } - if *options.MainCluster { + if options.MainCluster { stopMsg := " on main cluster" vcc.PrintInfo(msg + stopMsg) return nil diff --git a/commands/cmd_unsandbox.go b/commands/cmd_unsandbox.go index ec8a755..919c931 100644 --- a/commands/cmd_unsandbox.go +++ b/commands/cmd_unsandbox.go @@ -88,7 +88,7 @@ Examples: // setLocalFlags will set the local flags the command has func (c *CmdUnsandboxSubcluster) setLocalFlags(cmd *cobra.Command) { cmd.Flags().StringVar( - c.usOptions.SCName, + &c.usOptions.SCName, subclusterFlag, "", "The name of the subcluster to be unsandboxed", diff --git a/commands/scrutinize_test.go b/commands/scrutinize_test.go index 2f7eda3..ed7b4ee 100644 --- a/commands/scrutinize_test.go +++ b/commands/scrutinize_test.go @@ -81,8 +81,8 @@ func TestScrutinCmd(t *testing.T) { c.SetParser(&pflag.FlagSet{}) err := c.Run(vclusterops.VClusterCommands{}) assert.ErrorContains(t, err, "must specify a host or host list") - assert.Equal(t, dbName, *c.sOptions.DBName) - assert.Equal(t, catalogPath, *c.sOptions.CatalogPrefix) + assert.Equal(t, dbName, c.sOptions.DBName) + assert.Equal(t, catalogPath, c.sOptions.CatalogPrefix) // Catalog Path not provided os.Setenv(catalogPathPref, "") diff --git a/commands/user_input_test.go b/commands/user_input_test.go index 9ba30f3..ed5fea7 100644 --- a/commands/user_input_test.go +++ b/commands/user_input_test.go @@ -29,7 +29,7 @@ var tempConfigFilePath = os.TempDir() + "/test_vertica_cluster.yaml" func simulateVClusterCli(vclusterCmd string) error { // if no log file is given, the log will go to stdout - *dbOptions.LogPath = "" + dbOptions.LogPath = "" // convert the input string into a slice // extra spaces will be trimmed diff --git a/rfc7807/errors.go b/rfc7807/errors.go index 00aefca..88173a6 100644 --- a/rfc7807/errors.go +++ b/rfc7807/errors.go @@ -197,4 +197,14 @@ var ( "Unauthorized-request", http.StatusUnauthorized, ) + CatalogPathNotExistError = newProblemID( + path.Join(errorEndpointsPrefix, "catalog-path-not-exist-error"), + "Target path does not exist", + http.StatusBadRequest, + ) + CECatalogDirEmptyError = newProblemID( + path.Join(errorEndpointsPrefix, "catalog-dir-empty-error"), + "Target directory is empty", + http.StatusInternalServerError, + ) ) diff --git a/vclusterops/add_node.go b/vclusterops/add_node.go index e19a1c6..389101d 100644 --- a/vclusterops/add_node.go +++ b/vclusterops/add_node.go @@ -29,20 +29,20 @@ type VAddNodeOptions struct { // Hosts to add to database NewHosts []string // Name of the subcluster that the new nodes will be added to - SCName *string + SCName string // A primary up host that will be used to execute add_node operations Initiator string - // Depot size, e.g. 10G - DepotSize *string + // Depot size, e.g., 10G + DepotSize string // Skip rebalance shards if true SkipRebalanceShards *bool // Use force remove if true - ForceRemoval *bool + ForceRemoval bool // If the path is set, the NMA will store the Vertica start command at the path // instead of executing it. This is useful in containerized environments where // you may not want to have both the NMA and Vertica server in the same container. // This feature requires version 24.2.0+. - StartUpConf *string + StartUpConf string // Names of the existing nodes in the cluster. This option can be // used to remove partially added nodes from catalog. ExpectedNodeNames []string @@ -59,15 +59,11 @@ func VAddNodeOptionsFactory() VAddNodeOptions { func (o *VAddNodeOptions) setDefaultValues() { o.DatabaseOptions.setDefaultValues() - o.SCName = new(string) o.SkipRebalanceShards = new(bool) - o.DepotSize = new(string) - o.ForceRemoval = new(bool) - o.StartUpConf = new(string) } func (o *VAddNodeOptions) validateEonOptions() error { - if *o.DepotPrefix != "" { + if o.DepotPrefix != "" { return util.ValidateRequiredAbsPath(o.DepotPrefix, "depot path") } return nil @@ -75,7 +71,7 @@ func (o *VAddNodeOptions) validateEonOptions() error { func (o *VAddNodeOptions) validateExtraOptions() error { // data prefix - if *o.DataPrefix != "" { + if o.DataPrefix != "" { return util.ValidateRequiredAbsPath(o.DataPrefix, "data path") } return nil @@ -168,7 +164,7 @@ func (vcc VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDat return vdb, err } - err = vdb.addHosts(options.NewHosts, *options.SCName) + err = vdb.addHosts(options.NewHosts, options.SCName) if err != nil { return vdb, err } @@ -200,8 +196,8 @@ func checkAddNodeRequirements(vdb *VCoordinationDatabase, hostsToAdd []string) e // completeVDBSetting sets some VCoordinationDatabase fields we cannot get yet // from the https endpoints. We set those fields from options. func (o *VAddNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) error { - vdb.DataPrefix = *o.DataPrefix - vdb.DepotPrefix = *o.DepotPrefix + vdb.DataPrefix = o.DataPrefix + vdb.DepotPrefix = o.DepotPrefix hostNodeMap := makeVHostNodeMap() // TODO: we set the depot and data path from /nodes rather than manually @@ -269,7 +265,7 @@ func (vcc VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase, // mark k-safety if len(aliveHosts) < ksafetyThreshold { httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(initiator, - options.usePassword, *options.UserName, options.Password, + options.usePassword, options.UserName, options.Password, ksafeValueZero) if err != nil { return err @@ -280,7 +276,7 @@ func (vcc VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase, // remove down nodes from catalog for _, nodeName := range nodesToTrim { httpsDropNodeOp, err := makeHTTPSDropNodeOp(nodeName, initiator, - options.usePassword, *options.UserName, options.Password, vdb.IsEon) + options.usePassword, options.UserName, options.Password, vdb.IsEon) if err != nil { return err } @@ -327,7 +323,7 @@ func (vcc VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDatabas initiatorHost := []string{options.Initiator} newHosts := options.NewHosts allExistingHosts := util.SliceDiff(vdb.HostList, options.NewHosts) - username := *options.UserName + username := options.UserName usePassword := options.usePassword password := options.Password @@ -336,7 +332,7 @@ func (vcc VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDatabas if vdb.IsEon { httpsFindSubclusterOp, e := makeHTTPSFindSubclusterOp( - allExistingHosts, usePassword, username, password, *options.SCName, + allExistingHosts, usePassword, username, password, options.SCName, true /*ignore not found*/, AddNodeCmd) if e != nil { return instructions, e @@ -352,13 +348,13 @@ func (vcc VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDatabas // contains the hosts to add. newHostNodeMap := vdb.copyHostNodeMap(options.NewHosts) nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(newHostNodeMap, - *options.ForceRemoval /*force cleanup*/, false /*for db revive*/) + options.ForceRemoval /*force cleanup*/, false /*for db revive*/) if err != nil { return instructions, err } nmaNetworkProfileOp := makeNMANetworkProfileOp(vdb.HostList) httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(newHosts, initiatorHost, - usePassword, username, password, vdb, *options.SCName) + usePassword, username, password, vdb, options.SCName) if err != nil { return instructions, err } @@ -384,7 +380,7 @@ func (vcc VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDatabas vdb.HostList, vdb /*db configurations retrieved from a running db*/) - nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newHosts, *options.StartUpConf, vdb) + nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newHosts, options.StartUpConf, vdb) httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(newHosts, usePassword, username, password) if err != nil { return instructions, err @@ -420,7 +416,7 @@ func (vcc VClusterCommands) prepareAdditionalEonInstructions(vdb *VCoordinationD instructions = append(instructions, &httpsSyncCatalogOp) if !*options.SkipRebalanceShards { httpsRBSCShardsOp, err := makeHTTPSRebalanceSubclusterShardsOp( - initiatorHost, usePassword, username, options.Password, *options.SCName) + initiatorHost, usePassword, username, options.Password, options.SCName) if err != nil { return instructions, err } diff --git a/vclusterops/add_subcluster.go b/vclusterops/add_subcluster.go index bd04b41..47dbdc6 100644 --- a/vclusterops/add_subcluster.go +++ b/vclusterops/add_subcluster.go @@ -32,12 +32,12 @@ type VAddSubclusterOptions struct { // part 1: basic db info DatabaseOptions // part 2: subcluster info - SCName *string + SCName string SCHosts []string SCRawHosts []string - IsPrimary *bool - ControlSetSize *int - CloneSC *string + IsPrimary bool + ControlSetSize int + CloneSC string // part 3: add node info VAddNodeOptions } @@ -67,11 +67,7 @@ func VAddSubclusterOptionsFactory() VAddSubclusterOptions { func (options *VAddSubclusterOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() - options.SCName = new(string) - options.IsPrimary = new(bool) - options.ControlSetSize = new(int) - *options.ControlSetSize = -1 - options.CloneSC = new(string) + options.ControlSetSize = util.DefaultControlSetSize } func (options *VAddSubclusterOptions) validateRequiredOptions(logger vlog.Printer) error { @@ -80,7 +76,7 @@ func (options *VAddSubclusterOptions) validateRequiredOptions(logger vlog.Printe return err } - if *options.SCName == "" { + if options.SCName == "" { return fmt.Errorf("must specify a subcluster name") } return nil @@ -95,13 +91,13 @@ func (options *VAddSubclusterOptions) validateEonOptions() error { func (options *VAddSubclusterOptions) validateExtraOptions(logger vlog.Printer) error { // control-set-size can only be -1 or [1 to 120] - if !(*options.ControlSetSize == ControlSetSizeDefaultValue || - (*options.ControlSetSize >= ControlSetSizeLowerBound && *options.ControlSetSize <= ControlSetSizeUpperBound)) { + if !(options.ControlSetSize == ControlSetSizeDefaultValue || + (options.ControlSetSize >= ControlSetSizeLowerBound && options.ControlSetSize <= ControlSetSizeUpperBound)) { return fmt.Errorf("control-set-size is out of bounds: valid values are %d or [%d to %d]", ControlSetSizeDefaultValue, ControlSetSizeLowerBound, ControlSetSizeUpperBound) } - if *options.CloneSC != "" { + if options.CloneSC != "" { // TODO remove this log after we supported subcluster clone logger.PrintWarning("option CloneSC is not implemented yet so it will be ignored") } @@ -119,7 +115,7 @@ func (options *VAddSubclusterOptions) validateExtraOptions(logger vlog.Printer) } } if len(dupHosts) > 0 { - return fmt.Errorf("new subcluster has hosts %v which already exist in database %s", dupHosts, *options.DBName) + return fmt.Errorf("new subcluster has hosts %v which already exist in database %s", dupHosts, options.DBName) } // TODO remove this log after we supported adding subcluster with nodes @@ -208,7 +204,7 @@ func (vcc VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) error // Give the instructions to the VClusterOpEngine to run runError := clusterOpEngine.run(vcc.Log) if runError != nil { - return fmt.Errorf("fail to add subcluster %s, %w", *options.SCName, runError) + return fmt.Errorf("fail to add subcluster %s, %w", options.SCName, runError) } return nil @@ -242,21 +238,21 @@ func (vcc *VClusterCommands) produceAddSubclusterInstructions(options *VAddSubcl return instructions, fmt.Errorf("add subcluster is only supported in Eon mode") } - username := *options.UserName - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(*options.DBName, options.Hosts, + username := options.UserName + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(options.DBName, options.Hosts, options.usePassword, username, options.Password, AddSubclusterCmd) if err != nil { return instructions, err } httpsAddSubclusterOp, err := makeHTTPSAddSubclusterOp(options.usePassword, username, options.Password, - *options.SCName, *options.IsPrimary, *options.ControlSetSize) + options.SCName, options.IsPrimary, options.ControlSetSize) if err != nil { return instructions, err } httpsCheckSubclusterOp, err := makeHTTPSCheckSubclusterOp(options.usePassword, username, options.Password, - *options.SCName, *options.IsPrimary, *options.ControlSetSize) + options.SCName, options.IsPrimary, options.ControlSetSize) if err != nil { return instructions, err } diff --git a/vclusterops/coordinator_database.go b/vclusterops/coordinator_database.go index 8b652a3..554c771 100644 --- a/vclusterops/coordinator_database.go +++ b/vclusterops/coordinator_database.go @@ -71,21 +71,21 @@ func makeVCoordinationDatabase() VCoordinationDatabase { 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.DepotPrefix = *options.DepotPrefix + vdb.Name = options.DBName + vdb.CatalogPrefix = options.CatalogPrefix + vdb.DataPrefix = options.DataPrefix + vdb.DepotPrefix = options.DepotPrefix vdb.IsEon = false - if *options.CommunalStorageLocation != "" { + if options.CommunalStorageLocation != "" { vdb.IsEon = true - vdb.CommunalStorageLocation = *options.CommunalStorageLocation - vdb.DepotPrefix = *options.DepotPrefix - vdb.DepotSize = *options.DepotSize + vdb.CommunalStorageLocation = options.CommunalStorageLocation + vdb.DepotPrefix = options.DepotPrefix + vdb.DepotSize = options.DepotSize } vdb.UseDepot = false - if *options.DepotPrefix != "" { + if options.DepotPrefix != "" { vdb.UseDepot = true } @@ -120,15 +120,15 @@ func (vdb *VCoordinationDatabase) setFromCreateDBOptions(options *VCreateDatabas // set additional db info from the create db options vdb.HostList = make([]string, len(options.Hosts)) vdb.HostList = options.Hosts - vdb.LicensePathOnNode = *options.LicensePathOnNode + vdb.LicensePathOnNode = options.LicensePathOnNode - if *options.GetAwsCredentialsFromEnv { + if options.GetAwsCredentialsFromEnv { err := vdb.getAwsCredentialsFromEnv() if err != nil { return err } } - vdb.NumShards = *options.ShardCount + vdb.NumShards = options.ShardCount return nil } @@ -342,7 +342,7 @@ func (vnode *VCoordinationNode) setFromBasicDBOptions( options *VCreateDatabaseOptions, host string, ) error { - dbName := *options.DBName + dbName := options.DBName dbNameInNode := strings.ToLower(dbName) // compute node name and complete paths for each node for i, h := range options.Hosts { @@ -351,17 +351,17 @@ func (vnode *VCoordinationNode) setFromBasicDBOptions( } vnode.Address = host - vnode.Port = *options.ClientPort + vnode.Port = options.ClientPort nodeNameSuffix := i + 1 vnode.Name = fmt.Sprintf("v_%s_node%04d", dbNameInNode, nodeNameSuffix) catalogSuffix := fmt.Sprintf("%s_catalog", vnode.Name) - vnode.CatalogPath = filepath.Join(*options.CatalogPrefix, dbName, catalogSuffix) + vnode.CatalogPath = filepath.Join(options.CatalogPrefix, dbName, catalogSuffix) dataSuffix := fmt.Sprintf("%s_data", vnode.Name) - dataPath := filepath.Join(*options.DataPrefix, dbName, dataSuffix) + dataPath := filepath.Join(options.DataPrefix, dbName, dataSuffix) vnode.StorageLocations = append(vnode.StorageLocations, dataPath) - if *options.DepotPrefix != "" { + if options.DepotPrefix != "" { depotSuffix := fmt.Sprintf("%s_depot", vnode.Name) - vnode.DepotPath = filepath.Join(*options.DepotPrefix, dbName, depotSuffix) + vnode.DepotPath = filepath.Join(options.DepotPrefix, dbName, depotSuffix) } if options.IPv6 { vnode.ControlAddressFamily = util.IPv6ControlAddressFamily diff --git a/vclusterops/create_db.go b/vclusterops/create_db.go index fdfd32d..1409981 100644 --- a/vclusterops/create_db.go +++ b/vclusterops/create_db.go @@ -29,40 +29,41 @@ import ( // VCreateDatabase. type VCreateDatabaseOptions struct { /* part 1: basic db info */ + DatabaseOptions - Policy *string // database restart policy - SQLFile *string // SQL file to run (as dbadmin) immediately on database creation - LicensePathOnNode *string // required to be a fully qualified path + Policy string // database restart policy + SQLFile string // SQL file to run (as dbadmin) immediately on database creation + LicensePathOnNode string // required to be a fully qualified path /* part 2: eon db info */ - ShardCount *int // number of shards in the database" - DepotSize *string // depot size with two supported formats: % and KMGT, e.g., 50% or 10G - GetAwsCredentialsFromEnv *bool // whether get AWS credentials from environmental variables + ShardCount int // number of shards in the database" + DepotSize string // depot size with two supported formats: % and KMGT, e.g., 50% or 10G + GetAwsCredentialsFromEnv bool // whether get AWS credentials from environmental variables // part 3: optional info - ForceCleanupOnFailure *bool // whether force remove existing directories on failure - ForceRemovalAtCreation *bool // whether force remove existing directories before creating the database - SkipPackageInstall *bool // whether skip package installation - TimeoutNodeStartupSeconds *int // timeout in seconds for polling node start up state + ForceCleanupOnFailure bool // whether force remove existing directories on failure + ForceRemovalAtCreation bool // whether force remove existing directories before creating the database + SkipPackageInstall bool // whether skip package installation + TimeoutNodeStartupSeconds int // timeout in seconds for polling node start up state /* part 3: new params originally in installer generated admintools.conf, now in create db op */ - Broadcast *bool // configure Spread to use UDP broadcast traffic between nodes on the same subnet - P2p *bool // configure Spread to use point-to-point communication between all Vertica nodes - LargeCluster *int // whether enables a large cluster layout - ClientPort *int // for internal QA test only, do not abuse - SpreadLogging *bool // whether enable spread logging - SpreadLoggingLevel *int // spread logging level + Broadcast bool // configure Spread to use UDP broadcast traffic between nodes on the same subnet + P2p bool // configure Spread to use point-to-point communication between all Vertica nodes + LargeCluster int // whether enables a large cluster layout + ClientPort int // for internal QA test only, do not abuse + SpreadLogging bool // whether enable spread logging + SpreadLoggingLevel int // spread logging level /* part 4: other params */ - SkipStartupPolling *bool // whether skip startup polling - GenerateHTTPCerts *bool // whether generate http certificates + SkipStartupPolling bool // whether skip startup polling + GenerateHTTPCerts bool // whether generate http certificates // If the path is set, the NMA will store the Vertica start command at the path // instead of executing it. This is useful in containerized environments where // you may not want to have both the NMA and Vertica server in the same container. // This feature requires version 24.2.0+. - StartUpConf *string + StartUpConf string /* hidden options (which cache information only) */ @@ -82,117 +83,16 @@ func (opt *VCreateDatabaseOptions) setDefaultValues() { // basic db info defaultPolicy := util.DefaultRestartPolicy - opt.Policy = &defaultPolicy - opt.SQLFile = new(string) - opt.LicensePathOnNode = new(string) - - // eon db Info - opt.ShardCount = new(int) - opt.DepotSize = new(string) - opt.GetAwsCredentialsFromEnv = new(bool) + opt.Policy = defaultPolicy // optional info - opt.ForceCleanupOnFailure = new(bool) - opt.ForceRemovalAtCreation = new(bool) - opt.SkipPackageInstall = new(bool) - opt.GenerateHTTPCerts = new(bool) - opt.StartUpConf = new(string) - - defaultTimeoutNodeStartupSeconds := util.DefaultTimeoutSeconds - opt.TimeoutNodeStartupSeconds = &defaultTimeoutNodeStartupSeconds + opt.TimeoutNodeStartupSeconds = util.DefaultTimeoutSeconds // new params originally in installer generated admintools.conf, now in create db op - opt.Broadcast = new(bool) - - defaultP2p := true - opt.P2p = &defaultP2p - - defaultLargeCluster := -1 - opt.LargeCluster = &defaultLargeCluster - - defaultClientPort := util.DefaultClientPort - opt.ClientPort = &defaultClientPort - opt.SpreadLogging = new(bool) - - defaultSpreadLoggingLevel := -1 - opt.SpreadLoggingLevel = &defaultSpreadLoggingLevel - - // other params - opt.SkipStartupPolling = new(bool) -} - -func (opt *VCreateDatabaseOptions) checkNilPointerParams() error { - if err := opt.DatabaseOptions.checkNilPointerParams(); err != nil { - return err - } - - // basic params - if opt.Policy == nil { - return util.ParamNotSetErrorMsg("policy") - } - if opt.SQLFile == nil { - return util.ParamNotSetErrorMsg("sql") - } - if opt.LicensePathOnNode == nil { - return util.ParamNotSetErrorMsg("license") - } - - // eon params - if opt.ShardCount == nil { - return util.ParamNotSetErrorMsg("shard-count") - } - if opt.CommunalStorageLocation == nil { - return util.ParamNotSetErrorMsg("communal-storage-location") - } - if opt.DepotSize == nil { - return util.ParamNotSetErrorMsg("depot-size") - } - if opt.GetAwsCredentialsFromEnv == nil { - return util.ParamNotSetErrorMsg("get-aws-credentials-from-env-vars") - } - - return opt.checkExtraNilPointerParams() -} - -func (opt *VCreateDatabaseOptions) checkExtraNilPointerParams() error { - // optional params - if opt.ForceCleanupOnFailure == nil { - return util.ParamNotSetErrorMsg("force-cleanup-on-failure") - } - if opt.ForceRemovalAtCreation == nil { - return util.ParamNotSetErrorMsg("force-removal-at-creation") - } - if opt.SkipPackageInstall == nil { - return util.ParamNotSetErrorMsg("skip-package-install") - } - if opt.TimeoutNodeStartupSeconds == nil { - return util.ParamNotSetErrorMsg("startup-timeout") - } - - // other params - if opt.Broadcast == nil { - return util.ParamNotSetErrorMsg("broadcast") - } - if opt.P2p == nil { - return util.ParamNotSetErrorMsg("point-to-point") - } - if opt.LargeCluster == nil { - return util.ParamNotSetErrorMsg("large-cluster") - } - if opt.ClientPort == nil { - return util.ParamNotSetErrorMsg("client-port") - } - if opt.SpreadLogging == nil { - return util.ParamNotSetErrorMsg("spread-logging") - } - if opt.SpreadLoggingLevel == nil { - return util.ParamNotSetErrorMsg("spread-logging-level") - } - if opt.SkipStartupPolling == nil { - return util.ParamNotSetErrorMsg("skip-startup-polling") - } - - return nil + opt.P2p = util.DefaultP2p + opt.LargeCluster = util.DefaultLargeCluster + opt.ClientPort = util.DefaultClientPort + opt.SpreadLoggingLevel = util.DefaultSpreadLoggingLevel } func (opt *VCreateDatabaseOptions) validateRequiredOptions(logger vlog.Printer) error { @@ -203,7 +103,7 @@ func (opt *VCreateDatabaseOptions) validateRequiredOptions(logger vlog.Printer) logger.Info("no password specified, using none") } - if !util.StringInArray(*opt.Policy, util.RestartPolicyList) { + if !util.StringInArray(opt.Policy, util.RestartPolicyList) { return fmt.Errorf("policy must be one of %v", util.RestartPolicyList) } @@ -214,7 +114,7 @@ func (opt *VCreateDatabaseOptions) validateRequiredOptions(logger vlog.Printer) // // empty string ("") will be converted to the default license path (/opt/vertica/share/license.key) // in the /bootstrap-catalog endpoint - if *opt.LicensePathOnNode != "" && !util.IsAbsPath(*opt.LicensePathOnNode) { + if opt.LicensePathOnNode != "" && !util.IsAbsPath(opt.LicensePathOnNode) { return fmt.Errorf("must provide a fully qualified path for license file") } @@ -291,29 +191,29 @@ func validateDepotSize(size string) (bool, error) { } func (opt *VCreateDatabaseOptions) validateEonOptions() error { - if *opt.CommunalStorageLocation != "" { - err := util.ValidateCommunalStorageLocation(*opt.CommunalStorageLocation) + if opt.CommunalStorageLocation != "" { + err := util.ValidateCommunalStorageLocation(opt.CommunalStorageLocation) if err != nil { return err } - if *opt.DepotPrefix == "" { + if opt.DepotPrefix == "" { return fmt.Errorf("must specify a depot path with commual storage location") } - if *opt.ShardCount == 0 { + if opt.ShardCount == 0 { return fmt.Errorf("must specify a shard count greater than 0 with communal storage location") } } - if *opt.DepotPrefix != "" && *opt.CommunalStorageLocation == "" { + if opt.DepotPrefix != "" && opt.CommunalStorageLocation == "" { return fmt.Errorf("when depot path is given, communal storage location cannot be empty") } - if *opt.GetAwsCredentialsFromEnv && *opt.CommunalStorageLocation == "" { + if opt.GetAwsCredentialsFromEnv && opt.CommunalStorageLocation == "" { return fmt.Errorf("AWS credentials are only used in Eon mode") } - if *opt.DepotSize != "" { - if *opt.DepotPrefix == "" { + if opt.DepotSize != "" { + if opt.DepotPrefix == "" { return fmt.Errorf("when depot size is given, depot path cannot be empty") } - validDepotSize, err := validateDepotSize(*opt.DepotSize) + validDepotSize, err := validateDepotSize(opt.DepotSize) if !validDepotSize { return err } @@ -322,25 +222,19 @@ func (opt *VCreateDatabaseOptions) validateEonOptions() error { } func (opt *VCreateDatabaseOptions) validateExtraOptions() error { - if *opt.Broadcast && *opt.P2p { + if opt.Broadcast && opt.P2p { return fmt.Errorf("cannot use both Broadcast and Point-to-point networking mode") } // -1 is the default large cluster value, meaning 120 control nodes - if *opt.LargeCluster != util.DefaultLargeCluster && (*opt.LargeCluster < 1 || *opt.LargeCluster > util.MaxLargeCluster) { + if opt.LargeCluster != util.DefaultLargeCluster && (opt.LargeCluster < 1 || opt.LargeCluster > util.MaxLargeCluster) { return fmt.Errorf("must specify a valid large cluster value in range [1, 120]") } return nil } func (opt *VCreateDatabaseOptions) validateParseOptions(logger vlog.Printer) error { - // check nil pointers in the required options - err := opt.checkNilPointerParams() - if err != nil { - return err - } - // validate base options - err = opt.validateBaseOptions("create_db", logger) + err := opt.validateBaseOptions("create_db", logger) if err != nil { return err } @@ -375,15 +269,10 @@ func (opt *VCreateDatabaseOptions) analyzeOptions() error { } // process correct catalog path, data path and depot path prefixes - *opt.CatalogPrefix = util.GetCleanPath(*opt.CatalogPrefix) - *opt.DataPrefix = util.GetCleanPath(*opt.DataPrefix) - *opt.DepotPrefix = util.GetCleanPath(*opt.DepotPrefix) - if opt.ClientPort == nil { - *opt.ClientPort = util.DefaultClientPort - } - if opt.LargeCluster == nil { - *opt.LargeCluster = util.DefaultLargeCluster - } + opt.CatalogPrefix = util.GetCleanPath(opt.CatalogPrefix) + opt.DataPrefix = util.GetCleanPath(opt.DataPrefix) + opt.DepotPrefix = util.GetCleanPath(opt.DepotPrefix) + return nil } @@ -496,13 +385,13 @@ func (vcc VClusterCommands) produceCreateDBBootstrapInstructions( } checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(hosts, true, /* use password auth */ - *options.UserName, options.Password, CreateDB) + options.UserName, options.Password, CreateDB) if err != nil { return instructions, err } nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(vdb.HostNodeMap, - *options.ForceRemovalAtCreation, false /*for db revive*/) + options.ForceRemovalAtCreation, false /*for db revive*/) if err != nil { return instructions, err } @@ -539,10 +428,10 @@ func (vcc VClusterCommands) produceCreateDBBootstrapInstructions( ) } - nmaStartNodeOp := makeNMAStartNodeOp(bootstrapHost, *options.StartUpConf) + nmaStartNodeOp := makeNMAStartNodeOp(bootstrapHost, options.StartUpConf) httpsPollBootstrapNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(bootstrapHost, true, /* useHTTPPassword */ - *options.UserName, options.Password, *options.TimeoutNodeStartupSeconds, CreateDBCmd) + options.UserName, options.Password, options.TimeoutNodeStartupSeconds, CreateDBCmd) if err != nil { return instructions, err } @@ -567,7 +456,7 @@ func (vcc VClusterCommands) produceCreateDBWorkerNodesInstructions( newNodeHosts := util.SliceDiff(hosts, bootstrapHost) if len(hosts) > 1 { httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(newNodeHosts, bootstrapHost, - true /* use password auth */, *options.UserName, options.Password, vdb, "") + true /* use password auth */, options.UserName, options.Password, vdb, "") if err != nil { return instructions, err } @@ -575,7 +464,7 @@ func (vcc VClusterCommands) produceCreateDBWorkerNodesInstructions( } httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(bootstrapHost, - true /* use password auth */, *options.UserName, options.Password) + true /* use password auth */, options.UserName, options.Password) if err != nil { return instructions, err } @@ -587,14 +476,14 @@ func (vcc VClusterCommands) produceCreateDBWorkerNodesInstructions( } if len(hosts) > 1 { - httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(*options.DBName, bootstrapHost, - true /* use password auth */, *options.UserName, options.Password, vdb, false, util.MainClusterSandbox) + httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(options.DBName, bootstrapHost, + true /* use password auth */, options.UserName, options.Password, vdb, false, util.MainClusterSandbox) if err != nil { return instructions, err } httpsStartUpCommandOp, err := makeHTTPSStartUpCommandOp(true, /*use https password*/ - *options.UserName, options.Password, vdb) + options.UserName, options.Password, vdb) if err != nil { return instructions, err } @@ -606,7 +495,7 @@ func (vcc VClusterCommands) produceCreateDBWorkerNodesInstructions( bootstrapHost, vdb.HostList, vdb /*db configurations retrieved from a running db*/) - nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newNodeHosts, *options.StartUpConf, vdb) + nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newNodeHosts, options.StartUpConf, vdb) instructions = append(instructions, &nmaStartNewNodesOp) } @@ -620,11 +509,11 @@ func (vcc VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordina hosts := vdb.HostList bootstrapHost := options.bootstrapHost - username := *options.UserName + username := options.UserName - if !*options.SkipStartupPolling { + if !options.SkipStartupPolling { httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(hosts, true, username, options.Password, - *options.TimeoutNodeStartupSeconds, CreateDBCmd) + options.TimeoutNodeStartupSeconds, CreateDBCmd) if err != nil { return instructions, err } @@ -648,7 +537,7 @@ func (vcc VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordina instructions = append(instructions, &httpsMarkDesignKSafeOp) } - if !*options.SkipPackageInstall { + if !options.SkipPackageInstall { httpsInstallPackagesOp, err := makeHTTPSInstallPackagesOp(bootstrapHost, true, username, options.Password, false /* forceReinstall */, true /* verbose */) if err != nil { diff --git a/vclusterops/drop_db.go b/vclusterops/drop_db.go index 2c948e9..3cc63cf 100644 --- a/vclusterops/drop_db.go +++ b/vclusterops/drop_db.go @@ -24,7 +24,7 @@ import ( // VDropDatabaseOptions adds to VCreateDatabaseOptions the option to force delete directories. type VDropDatabaseOptions struct { VCreateDatabaseOptions - ForceDelete *bool // whether force delete directories + ForceDelete bool // whether force delete directories } func VDropDatabaseOptionsFactory() VDropDatabaseOptions { @@ -50,7 +50,7 @@ func (options *VDropDatabaseOptions) analyzeOptions() error { } func (options *VDropDatabaseOptions) validateAnalyzeOptions() error { - if *options.DBName == "" { + if options.DBName == "" { return fmt.Errorf("database name must be provided") } return options.analyzeOptions() @@ -121,12 +121,12 @@ func (vcc VClusterCommands) produceDropDBInstructions(vdb *VCoordinationDatabase // when checking the running database, // drop_db has the same checking items with create_db checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(hosts, usePassword, - *options.UserName, options.Password, CreateDB) + options.UserName, options.Password, CreateDB) if err != nil { return instructions, err } - nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(vdb, *options.ForceDelete) + nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(vdb, options.ForceDelete) if err != nil { return instructions, err } diff --git a/vclusterops/fetch_database.go b/vclusterops/fetch_database.go index 14815a7..1b091d2 100644 --- a/vclusterops/fetch_database.go +++ b/vclusterops/fetch_database.go @@ -52,7 +52,7 @@ func (opt *VFetchCoordinationDatabaseOptions) analyzeOptions() error { } // process correct catalog path - *opt.CatalogPrefix = util.GetCleanPath(*opt.CatalogPrefix) + opt.CatalogPrefix = util.GetCleanPath(opt.CatalogPrefix) // check existing config file at the same location if !opt.readOnly && !opt.Overwrite { @@ -87,10 +87,10 @@ func (vcc VClusterCommands) VFetchCoordinationDatabase(options *VFetchCoordinati } // pre-fill vdb from the user input - vdb.Name = *options.DBName + vdb.Name = options.DBName vdb.HostList = options.Hosts - vdb.CatalogPrefix = *options.CatalogPrefix - vdb.DepotPrefix = *options.DepotPrefix + vdb.CatalogPrefix = options.CatalogPrefix + vdb.DepotPrefix = options.DepotPrefix vdb.Ipv6 = options.IPv6 // produce list_allnodes instructions @@ -148,7 +148,7 @@ func (vcc VClusterCommands) produceRecoverConfigInstructions( var instructions []clusterOp nmaHealthOp := makeNMAHealthOp(options.Hosts) - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, *options.DBName, *options.CatalogPrefix, + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, options.DBName, options.CatalogPrefix, true /* ignore internal errors */, vdb) nmaReadCatalogEditorOp, err := makeNMAReadCatalogEditorOp(vdb) if err != nil { diff --git a/vclusterops/fetch_node_state.go b/vclusterops/fetch_node_state.go index 2db94bc..06e9713 100644 --- a/vclusterops/fetch_node_state.go +++ b/vclusterops/fetch_node_state.go @@ -142,7 +142,7 @@ func (vcc VClusterCommands) produceListAllNodesInstructions(options *VFetchNodeS } httpsCheckNodeStateOp, err := makeHTTPSCheckNodeStateOp(hosts, - usePassword, *options.UserName, options.Password) + usePassword, options.UserName, options.Password) if err != nil { return instructions, err } diff --git a/vclusterops/fetch_nodes_details.go b/vclusterops/fetch_nodes_details.go index 26da754..954b326 100644 --- a/vclusterops/fetch_nodes_details.go +++ b/vclusterops/fetch_nodes_details.go @@ -164,14 +164,14 @@ func (vcc *VClusterCommands) produceFetchNodesDetailsInstructions(options *VFetc return instructions, err } - httpsGetNodeStateOp, err := makeHTTPSGetLocalNodeStateOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, hostsWithNodeDetails) + httpsGetNodeStateOp, err := makeHTTPSGetLocalNodeStateOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, hostsWithNodeDetails) if err != nil { return instructions, err } httpsGetStorageLocationsOp, err := makeHTTPSGetStorageLocsOp(options.Hosts, options.usePassword, - *options.UserName, options.Password, hostsWithNodeDetails) + options.UserName, options.Password, hostsWithNodeDetails) if err != nil { return instructions, err } diff --git a/vclusterops/fetch_nodes_details_test.go b/vclusterops/fetch_nodes_details_test.go index dc1471a..5b5c968 100644 --- a/vclusterops/fetch_nodes_details_test.go +++ b/vclusterops/fetch_nodes_details_test.go @@ -31,7 +31,7 @@ func TestRequiredOptions(t *testing.T) { assert.ErrorContains(t, err, `must specify a database name`) // hosts are required - *options.DBName = "testDB" + options.DBName = "testDB" nodesDetails, err = vcc.VFetchNodesDetails(&options) assert.Empty(t, nodesDetails) assert.ErrorContains(t, err, `must specify a host or host list`) diff --git a/vclusterops/helpers.go b/vclusterops/helpers.go index e987b43..11bbd2e 100644 --- a/vclusterops/helpers.go +++ b/vclusterops/helpers.go @@ -172,14 +172,14 @@ func (vcc VClusterCommands) getVDBFromRunningDBImpl(vdb *VCoordinationDatabase, return fmt.Errorf("fail to set userPassword while retrieving database configurations, %w", err) } - httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, vdb, allowUseSandboxRes, sandbox) + httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, vdb, allowUseSandboxRes, sandbox) if err != nil { return fmt.Errorf("fail to produce httpsGetNodesInfo instructions while retrieving database configurations, %w", err) } - httpsGetClusterInfoOp, err := makeHTTPSGetClusterInfoOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, vdb) + httpsGetClusterInfoOp, err := makeHTTPSGetClusterInfoOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, vdb) if err != nil { return fmt.Errorf("fail to produce httpsGetClusterInfo instructions while retrieving database configurations, %w", err) } @@ -204,8 +204,8 @@ func (vcc VClusterCommands) getClusterInfoFromRunningDB(vdb *VCoordinationDataba return fmt.Errorf("fail to set userPassword while retrieving cluster configurations, %w", err) } - httpsGetClusterInfoOp, err := makeHTTPSGetClusterInfoOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, vdb) + httpsGetClusterInfoOp, err := makeHTTPSGetClusterInfoOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, vdb) if err != nil { return fmt.Errorf("fail to produce httpsGetClusterInfo instructions while retrieving cluster configurations, %w", err) } diff --git a/vclusterops/install_packages.go b/vclusterops/install_packages.go index 87fa032..b3645be 100644 --- a/vclusterops/install_packages.go +++ b/vclusterops/install_packages.go @@ -27,13 +27,11 @@ type VInstallPackagesOptions struct { DatabaseOptions // If true, the packages will be reinstalled even if they are already installed. - ForceReinstall *bool + ForceReinstall bool } func VInstallPackagesOptionsFactory() VInstallPackagesOptions { - opt := VInstallPackagesOptions{ - ForceReinstall: new(bool), - } + opt := VInstallPackagesOptions{} opt.DatabaseOptions.setDefaultValues() return opt } @@ -113,15 +111,15 @@ func (vcc *VClusterCommands) produceInstallPackagesInstructions(opts *VInstallPa } } - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(*opts.DBName, opts.Hosts, - usePassword, *opts.UserName, opts.Password, InstallPackageCmd) + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(opts.DBName, opts.Hosts, + usePassword, opts.UserName, opts.Password, InstallPackageCmd) if err != nil { return nil, nil, err } var noHosts = []string{} // We pass in no hosts so that this op picks an up node from the previous call. verbose := false // Silence verbose output as we will print package status at the end - installOp, err := makeHTTPSInstallPackagesOp(noHosts, usePassword, *opts.UserName, opts.Password, *opts.ForceReinstall, verbose) + installOp, err := makeHTTPSInstallPackagesOp(noHosts, usePassword, opts.UserName, opts.Password, opts.ForceReinstall, verbose) if err != nil { return nil, nil, err } diff --git a/vclusterops/nma_bootstrap_catalog_op.go b/vclusterops/nma_bootstrap_catalog_op.go index ef70314..74a548d 100644 --- a/vclusterops/nma_bootstrap_catalog_op.go +++ b/vclusterops/nma_bootstrap_catalog_op.go @@ -94,20 +94,20 @@ func (op *nmaBootstrapCatalogOp) setupRequestBody(vdb *VCoordinationDatabase, op bootstrapData.LicenseKey = vdb.LicensePathOnNode // large cluster mode temporariliy disabled - bootstrapData.LargeCluster = *options.LargeCluster - if *options.P2p { + bootstrapData.LargeCluster = options.LargeCluster + if options.P2p { bootstrapData.NetworkingMode = "pt2pt" } else { bootstrapData.NetworkingMode = "broadcast" } - bootstrapData.SpreadLogging = *options.SpreadLogging - bootstrapData.SpreadLoggingLevel = *options.SpreadLoggingLevel + bootstrapData.SpreadLogging = options.SpreadLogging + bootstrapData.SpreadLoggingLevel = options.SpreadLoggingLevel bootstrapData.Ipv6 = options.IPv6 - bootstrapData.SuperuserName = *options.UserName + bootstrapData.SuperuserName = options.UserName bootstrapData.DBPassword = *options.Password // Flag to generate certs and tls configuration - bootstrapData.GenerateHTTPCerts = *options.GenerateHTTPCerts + bootstrapData.GenerateHTTPCerts = options.GenerateHTTPCerts // Eon params bootstrapData.NumShards = vdb.NumShards diff --git a/vclusterops/nma_show_restore_points_op.go b/vclusterops/nma_show_restore_points_op.go index bd165b8..5da8672 100644 --- a/vclusterops/nma_show_restore_points_op.go +++ b/vclusterops/nma_show_restore_points_op.go @@ -28,22 +28,22 @@ type nmaShowRestorePointsOp struct { dbName string communalLocation string configurationParameters map[string]string - filterOptions *ShowRestorePointFilterOptions + filterOptions ShowRestorePointFilterOptions } // Optional arguments to list only restore points that // meet the specified condition(s) type ShowRestorePointFilterOptions struct { // Only list restore points with given archive name - ArchiveName *string + ArchiveName string // Only list restore points created no earlier than this timestamp (must be UTC timezone) - StartTimestamp *string + StartTimestamp string // Only list restore points created no later than this timestamp (must be UTC timezone) - EndTimestamp *string + EndTimestamp string // Only list restore points with given ID - ArchiveID *string + ArchiveID string // Only list restore points with given index - ArchiveIndex *string + ArchiveIndex string } type showRestorePointsRequestData struct { @@ -70,7 +70,6 @@ func makeNMAShowRestorePointsOp(logger vlog.Printer, dbName: dbName, configurationParameters: configurationParameters, communalLocation: communalLocation, - filterOptions: nil, } } @@ -79,7 +78,7 @@ func makeNMAShowRestorePointsOpWithFilterOptions(logger vlog.Printer, hosts []string, dbName, communalLocation string, configurationParameters map[string]string, filterOptions *ShowRestorePointFilterOptions) nmaShowRestorePointsOp { op := makeNMAShowRestorePointsOp(logger, hosts, dbName, communalLocation, configurationParameters) - op.filterOptions = filterOptions + op.filterOptions = *filterOptions return op } @@ -91,23 +90,11 @@ func (op *nmaShowRestorePointsOp) setupRequestBody() (map[string]string, error) requestData.DBName = op.dbName requestData.CommunalLocation = op.communalLocation requestData.Parameters = op.configurationParameters - if op.filterOptions != nil { - if op.filterOptions.ArchiveName != nil { - requestData.ArchiveName = *op.filterOptions.ArchiveName - } - if op.filterOptions.StartTimestamp != nil { - requestData.StartTimestamp = *op.filterOptions.StartTimestamp - } - if op.filterOptions.EndTimestamp != nil { - requestData.EndTimestamp = *op.filterOptions.EndTimestamp - } - if op.filterOptions.ArchiveID != nil { - requestData.ArchiveID = *op.filterOptions.ArchiveID - } - if op.filterOptions.ArchiveIndex != nil { - requestData.ArchiveIndex = *op.filterOptions.ArchiveIndex - } - } + requestData.ArchiveName = op.filterOptions.ArchiveName + requestData.StartTimestamp = op.filterOptions.StartTimestamp + requestData.EndTimestamp = op.filterOptions.EndTimestamp + requestData.ArchiveID = op.filterOptions.ArchiveID + requestData.ArchiveIndex = op.filterOptions.ArchiveIndex dataBytes, err := json.Marshal(requestData) if err != nil { diff --git a/vclusterops/nma_show_restore_points_op_test.go b/vclusterops/nma_show_restore_points_op_test.go index 204cd24..0f139e4 100644 --- a/vclusterops/nma_show_restore_points_op_test.go +++ b/vclusterops/nma_show_restore_points_op_test.go @@ -43,11 +43,11 @@ func TestShowRestorePointsRequestBody(t *testing.T) { op = makeNMAShowRestorePointsOpWithFilterOptions(vlog.Printer{}, []string{hostName}, dbName, communalLocation, nil, &ShowRestorePointFilterOptions{ - ArchiveName: &archiveName, - ArchiveID: &archiveID, - ArchiveIndex: &archiveIndex, - StartTimestamp: &startTimestamp, - EndTimestamp: &endTimestamp, + ArchiveName: archiveName, + ArchiveID: archiveID, + ArchiveIndex: archiveIndex, + StartTimestamp: startTimestamp, + EndTimestamp: endTimestamp, }) requestBody, err = op.setupRequestBody() @@ -63,9 +63,9 @@ func TestShowRestorePointsRequestBody(t *testing.T) { op = makeNMAShowRestorePointsOpWithFilterOptions(vlog.Printer{}, []string{hostName}, dbName, communalLocation, nil, &ShowRestorePointFilterOptions{ - ArchiveName: &archiveName, - ArchiveID: &archiveID, - ArchiveIndex: &archiveIndex, + ArchiveName: archiveName, + ArchiveID: archiveID, + ArchiveIndex: archiveIndex, }) requestBody, err = op.setupRequestBody() diff --git a/vclusterops/re_ip.go b/vclusterops/re_ip.go index 2d8657c..172d8b0 100644 --- a/vclusterops/re_ip.go +++ b/vclusterops/re_ip.go @@ -52,8 +52,8 @@ func (opt *VReIPOptions) validateParseOptions(logger vlog.Printer) error { return err } - if *opt.CommunalStorageLocation != "" { - return util.ValidateCommunalStorageLocation(*opt.CommunalStorageLocation) + if opt.CommunalStorageLocation != "" { + return util.ValidateCommunalStorageLocation(opt.CommunalStorageLocation) } return opt.validateBaseOptions("re_ip", logger) @@ -136,7 +136,7 @@ func (vcc VClusterCommands) VReIP(options *VReIPOptions) error { 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 != "" { + if options.CommunalStorageLocation != "" { vdb, e := options.getVDBWhenDBIsDown(vcc) if e != nil { // show a warning message if we cannot get VDB from a down database @@ -203,7 +203,7 @@ func (vcc VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb * // When we cannot get db info from cluster_config.json, we will fetch it from NMA /nodes endpoint. if vdb == nil { vdb = new(VCoordinationDatabase) - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, *options.DBName, *options.CatalogPrefix, + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, options.DBName, options.CatalogPrefix, false /* report all errors */, vdb) // read catalog editor to get hosts with latest catalog nmaReadCatEdOp, err := makeNMAReadCatalogEditorOp(vdb) diff --git a/vclusterops/re_ip_test.go b/vclusterops/re_ip_test.go index 1897475..cfe46fe 100644 --- a/vclusterops/re_ip_test.go +++ b/vclusterops/re_ip_test.go @@ -29,12 +29,12 @@ func TestReIPOptions(t *testing.T) { err := opt.validateAnalyzeOptions(vlog.Printer{}) assert.Error(t, err) - *opt.DBName = "test_db" + opt.DBName = "test_db" opt.RawHosts = []string{"192.168.1.101", "192.168.1.102"} err = opt.validateAnalyzeOptions(vlog.Printer{}) assert.ErrorContains(t, err, "must specify an absolute catalog path") - *opt.CatalogPrefix = "/data" + opt.CatalogPrefix = "/data" err = opt.validateAnalyzeOptions(vlog.Printer{}) assert.ErrorContains(t, err, "the re-ip list is not provided") diff --git a/vclusterops/remove_node.go b/vclusterops/remove_node.go index b38ebc8..e24fa5c 100644 --- a/vclusterops/remove_node.go +++ b/vclusterops/remove_node.go @@ -29,7 +29,7 @@ type VRemoveNodeOptions struct { DatabaseOptions HostsToRemove []string // Hosts to remove from database Initiator string // A primary up host that will be used to execute remove_node operations. - ForceDelete *bool // whether force delete directories + ForceDelete bool // whether force delete directories } func VRemoveNodeOptionsFactory() VRemoveNodeOptions { @@ -43,8 +43,7 @@ func VRemoveNodeOptionsFactory() VRemoveNodeOptions { func (o *VRemoveNodeOptions) setDefaultValues() { o.DatabaseOptions.setDefaultValues() - o.ForceDelete = new(bool) - *o.ForceDelete = true + o.ForceDelete = true } func (o *VRemoveNodeOptions) validateRequiredOptions(log vlog.Printer) error { @@ -57,7 +56,7 @@ func (o *VRemoveNodeOptions) validateRequiredOptions(log vlog.Printer) error { func (o *VRemoveNodeOptions) validateExtraOptions() error { // data prefix - if *o.DataPrefix != "" { + if o.DataPrefix != "" { return util.ValidateRequiredAbsPath(o.DataPrefix, "data path") } return nil @@ -193,7 +192,7 @@ func (vcc VClusterCommands) handleRemoveNodeForHostsNotInCatalog(vdb *VCoordinat vcc.Log.Info("Doing cleanup of hosts missing from database", "hostsNotInCatalog", missingHosts) // We need to find the paths for the hosts we are removing. - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(missingHosts, *options.DBName, *options.CatalogPrefix, + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(missingHosts, options.DBName, options.CatalogPrefix, false /* report all errors */, vdb) instructions := []clusterOp{&nmaGetNodesInfoOp} certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} @@ -213,7 +212,7 @@ func (vcc VClusterCommands) handleRemoveNodeForHostsNotInCatalog(vdb *VCoordinat // Using the paths fetched earlier, we can now build the list of directories // that the NMA should remove. - nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(&vdbForDeleteDir, *options.ForceDelete) + nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(&vdbForDeleteDir, options.ForceDelete) if err != nil { return *vdb, err } @@ -253,9 +252,9 @@ func checkRemoveNodeRequirements(vdb *VCoordinationDatabase, options *VRemoveNod // completeVDBSetting sets some VCoordinationDatabase fields we cannot get yet // from the https endpoints. We set those fields from options. func (o *VRemoveNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) error { - vdb.DataPrefix = *o.DataPrefix + vdb.DataPrefix = o.DataPrefix - if *o.DepotPrefix == "" { + if o.DepotPrefix == "" { return nil } if vdb.IsEon { @@ -267,7 +266,7 @@ func (o *VRemoveNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) erro return err } } - vdb.DepotPrefix = *o.DepotPrefix + vdb.DepotPrefix = o.DepotPrefix hostNodeMap := makeVHostNodeMap() // TODO: we set the depot path from /nodes rather than manually // (VER-92725). This is useful for nmaDeleteDirectoriesOp. @@ -309,7 +308,7 @@ func (vcc VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationData var initiatorHost []string initiatorHost = append(initiatorHost, options.Initiator) - username := *options.UserName + username := options.UserName usePassword := options.usePassword password := options.Password @@ -381,7 +380,7 @@ func (vcc VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationData } instructions = append(instructions, &httpsReloadSpreadOp) - nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(&v, *options.ForceDelete) + nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(&v, options.ForceDelete) if err != nil { return instructions, err } diff --git a/vclusterops/remove_subcluster.go b/vclusterops/remove_subcluster.go index 572c78c..9e43120 100644 --- a/vclusterops/remove_subcluster.go +++ b/vclusterops/remove_subcluster.go @@ -28,8 +28,8 @@ import ( // database. type VRemoveScOptions struct { DatabaseOptions - SubclusterToRemove *string // subcluster to remove from database - ForceDelete *bool // whether force delete directories + SubclusterToRemove string // subcluster to remove from database + ForceDelete bool // whether force delete directories } func VRemoveScOptionsFactory() VRemoveScOptions { @@ -42,8 +42,6 @@ func VRemoveScOptionsFactory() VRemoveScOptions { func (o *VRemoveScOptions) setDefaultValues() { o.DatabaseOptions.setDefaultValues() - o.SubclusterToRemove = new(string) - o.ForceDelete = new(bool) } func (o *VRemoveScOptions) validateRequiredOptions(logger vlog.Printer) error { @@ -52,7 +50,7 @@ func (o *VRemoveScOptions) validateRequiredOptions(logger vlog.Printer) error { return err } - if o.SubclusterToRemove == nil || *o.SubclusterToRemove == "" { + if o.SubclusterToRemove == "" { return fmt.Errorf("must specify a subcluster name") } return nil @@ -88,7 +86,7 @@ func (o *VRemoveScOptions) validateParseOptions(logger vlog.Printer) error { func (o *VRemoveScOptions) validateEonOptions() error { if !o.IsEon { return fmt.Errorf(`cannot remove subcluster from an enterprise database '%s'`, - *o.DBName) + o.DBName) } return nil } @@ -144,7 +142,7 @@ func (vcc VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (VC vcc.Log.V(1).Info("Nodes to be removed: %+v", hostsToRemove) if len(hostsToRemove) == 0 { vcc.Log.PrintInfo("no node found in subcluster %s", - *removeScOpt.SubclusterToRemove) + removeScOpt.SubclusterToRemove) needRemoveNodes = false } else { needRemoveNodes = true @@ -158,7 +156,7 @@ func (vcc VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (VC removeNodeOpt.ForceDelete = removeScOpt.ForceDelete vcc.Log.PrintInfo("Removing nodes %q from subcluster %s", - hostsToRemove, *removeScOpt.SubclusterToRemove) + hostsToRemove, removeScOpt.SubclusterToRemove) vdb, err = vcc.VRemoveNode(&removeNodeOpt) if err != nil { return vdb, err @@ -204,7 +202,7 @@ func (vcc VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, options if !vdb.IsEon { // info from running db confirms that the db is not Eon return hostsToRemove, fmt.Errorf(`cannot remove subcluster from an enterprise database '%s'`, - *options.DBName) + options.DBName) } err = options.completeVDBSetting(vdb) @@ -215,8 +213,8 @@ func (vcc VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, options // get default subcluster // cannot remove sandbox subcluster httpsFindSubclusterOp, err := makeHTTPSFindSubclusterOp(options.Hosts, - options.usePassword, *options.UserName, options.Password, - *options.SubclusterToRemove, + options.usePassword, options.UserName, options.Password, + options.SubclusterToRemove, false /*do not ignore not found*/, RemoveSubclusterCmd) if err != nil { return hostsToRemove, fmt.Errorf("fail to get default subcluster %s, details: %w", @@ -242,13 +240,13 @@ func (vcc VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, options } // the default subcluster should not be removed - if *options.SubclusterToRemove == clusterOpEngine.execContext.defaultSCName { - return hostsToRemove, &removeDefaultSubclusterError{Name: *options.SubclusterToRemove} + if options.SubclusterToRemove == clusterOpEngine.execContext.defaultSCName { + return hostsToRemove, &removeDefaultSubclusterError{Name: options.SubclusterToRemove} } // get nodes of the to-be-removed subcluster for h, vnode := range vdb.HostNodeMap { - if vnode.Subcluster == *options.SubclusterToRemove { + if vnode.Subcluster == options.SubclusterToRemove { hostsToRemove = append(hostsToRemove, h) } } @@ -259,8 +257,8 @@ func (vcc VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, options // completeVDBSetting sets some VCoordinationDatabase fields we cannot get yet // from the https endpoints. We set those fields from options. func (o *VRemoveScOptions) completeVDBSetting(vdb *VCoordinationDatabase) error { - vdb.DataPrefix = *o.DataPrefix - vdb.DepotPrefix = *o.DepotPrefix + vdb.DataPrefix = o.DataPrefix + vdb.DepotPrefix = o.DepotPrefix hostNodeMap := makeVHostNodeMap() // TODO: we set the depot path from /nodes rather than manually @@ -274,7 +272,7 @@ func (o *VRemoveScOptions) completeVDBSetting(vdb *VCoordinationDatabase) error } func (vcc VClusterCommands) dropSubcluster(vdb *VCoordinationDatabase, options *VRemoveScOptions) error { - dropScErrMsg := fmt.Sprintf("fail to drop subcluster %s", *options.SubclusterToRemove) + dropScErrMsg := fmt.Sprintf("fail to drop subcluster %s", options.SubclusterToRemove) // the initiator is a list of one primary up host // that will call the https /v1/subclusters/{scName}/drop endpoint @@ -285,8 +283,8 @@ func (vcc VClusterCommands) dropSubcluster(vdb *VCoordinationDatabase, options * } httpsDropScOp, err := makeHTTPSDropSubclusterOp([]string{initiator}, - *options.SubclusterToRemove, - options.usePassword, *options.UserName, options.Password) + options.SubclusterToRemove, + options.usePassword, options.UserName, options.Password) if err != nil { vcc.Log.Error(err, "details: %v", dropScErrMsg) return err diff --git a/vclusterops/remove_subcluster_test.go b/vclusterops/remove_subcluster_test.go index a22cd2f..26d3530 100644 --- a/vclusterops/remove_subcluster_test.go +++ b/vclusterops/remove_subcluster_test.go @@ -29,15 +29,14 @@ func TestRemoveSubcluster(t *testing.T) { options.RawHosts = []string{"vnode1", "vnode2"} options.Password = new(string) // input db name - *options.DBName = dbName + options.DBName = dbName // options without sc name, data path, and depot path err := options.validateParseOptions(vlog.Printer{}) assert.ErrorContains(t, err, "must specify a subcluster name") // input sc name - options.SubclusterToRemove = new(string) - *options.SubclusterToRemove = "sc1" + options.SubclusterToRemove = "sc1" // verify Eon mode is set options.IsEon = false @@ -49,12 +48,12 @@ func TestRemoveSubcluster(t *testing.T) { assert.ErrorContains(t, err, "must specify an absolute data path") // input data path - *options.DataPrefix = defaultPath + options.DataPrefix = defaultPath err = options.validateParseOptions(vlog.Printer{}) assert.ErrorContains(t, err, "must specify an absolute depot path") // input depot path - *options.DepotPrefix = defaultPath + options.DepotPrefix = defaultPath err = options.validateParseOptions(vlog.Printer{}) assert.NoError(t, err) } diff --git a/vclusterops/replication.go b/vclusterops/replication.go index 6d362ac..9a47dcc 100644 --- a/vclusterops/replication.go +++ b/vclusterops/replication.go @@ -73,7 +73,7 @@ func (opt *VReplicationDatabaseOptions) validateParseOptions(logger vlog.Printer } // need to provide a password or TLSconfig if source and target username are different - if opt.TargetUserName != *opt.UserName { + if opt.TargetUserName != opt.UserName { if opt.TargetPassword == nil && opt.SourceTLSConfig == "" { return fmt.Errorf("only trust authentication can support username without password or TLSConfig") } @@ -178,7 +178,7 @@ func (vcc VClusterCommands) produceDBReplicationInstructions(options *VReplicati } httpsGetUpNodesOp, err := makeHTTPSCheckNodeStateOp(options.Hosts, - options.usePassword, *options.UserName, options.Password) + options.usePassword, options.UserName, options.Password) if err != nil { return instructions, err } @@ -189,8 +189,8 @@ func (vcc VClusterCommands) produceDBReplicationInstructions(options *VReplicati nmaVerticaVersionOp := makeNMAVerticaVersionOp(options.Hosts, true, true /*IsEon*/) initiatorTargetHost := getInitiator(options.TargetHosts) - httpsStartReplicationOp, err := makeHTTPSStartReplicationOp(*options.DBName, options.Hosts, options.usePassword, - *options.UserName, options.Password, targetUserPassword, options.TargetDB, options.TargetUserName, initiatorTargetHost, + httpsStartReplicationOp, err := makeHTTPSStartReplicationOp(options.DBName, options.Hosts, options.usePassword, + options.UserName, options.Password, targetUserPassword, options.TargetDB, options.TargetUserName, initiatorTargetHost, options.TargetPassword, options.SourceTLSConfig) if err != nil { return instructions, err diff --git a/vclusterops/restore_points.go b/vclusterops/restore_points.go index f966051..7753dec 100644 --- a/vclusterops/restore_points.go +++ b/vclusterops/restore_points.go @@ -27,7 +27,7 @@ type VShowRestorePointsOptions struct { DatabaseOptions // Optional arguments to list only restore points that // meet the specified condition(s) - FilterOptions *ShowRestorePointFilterOptions + FilterOptions ShowRestorePointFilterOptions } func VShowRestorePointsFactory() VShowRestorePointsOptions { @@ -35,23 +35,17 @@ func VShowRestorePointsFactory() VShowRestorePointsOptions { // set default values to the params opt.setDefaultValues() - opt.FilterOptions = &ShowRestorePointFilterOptions{ - ArchiveName: new(string), - StartTimestamp: new(string), - EndTimestamp: new(string), - ArchiveID: new(string), - ArchiveIndex: new(string), - } + opt.FilterOptions = ShowRestorePointFilterOptions{} return opt } func (p *ShowRestorePointFilterOptions) hasNonEmptyStartTimestamp() bool { - return (p.StartTimestamp != nil && *p.StartTimestamp != "") + return (p.StartTimestamp != "") } func (p *ShowRestorePointFilterOptions) hasNonEmptyEndTimestamp() bool { - return (p.EndTimestamp != nil && *p.EndTimestamp != "") + return (p.EndTimestamp != "") } // Check that all non-empty timestamps specified have valid date time or date only format, @@ -74,11 +68,11 @@ func (p *ShowRestorePointFilterOptions) ValidateAndStandardizeTimestampsIfAny() if dateOnlyErr != nil { // give up return fmt.Errorf("start timestamp %q is invalid; cannot parse as a datetime: %w; "+ - "cannot parse as a date as well: %w", *p.StartTimestamp, dateTimeErr, dateOnlyErr) + "cannot parse as a date as well: %w", p.StartTimestamp, dateTimeErr, dateOnlyErr) } // default value of time parsed from date only string is already indicating the start of a day // invoke this function here to only rewrite p.StartTimestamp in date time format - util.FillInDefaultTimeForStartTimestamp(p.StartTimestamp) + util.FillInDefaultTimeForStartTimestamp(&p.StartTimestamp) } // try date time first @@ -89,10 +83,10 @@ func (p *ShowRestorePointFilterOptions) ValidateAndStandardizeTimestampsIfAny() if dateOnlyErr != nil { // give up return fmt.Errorf("end timestamp %q is invalid; cannot parse as a datetime: %w; "+ - "cannot parse as a date as well: %w", *p.EndTimestamp, dateTimeErr, dateOnlyErr) + "cannot parse as a date as well: %w", p.EndTimestamp, dateTimeErr, dateOnlyErr) } // fill in default value for time and update the end timestamp - parsedEndDatetime = util.FillInDefaultTimeForEndTimestamp(p.EndTimestamp) + parsedEndDatetime = util.FillInDefaultTimeForEndTimestamp(&p.EndTimestamp) } // check if endTime is after start time if both of them are non-empty @@ -113,7 +107,7 @@ func (opt *VShowRestorePointsOptions) validateParseOptions(logger vlog.Printer) return err } - err = util.ValidateCommunalStorageLocation(*opt.CommunalStorageLocation) + err = util.ValidateCommunalStorageLocation(opt.CommunalStorageLocation) if err != nil { return err } @@ -197,8 +191,8 @@ func (vcc VClusterCommands) produceShowRestorePointsInstructions(options *VShowR // require to have the same vertica version nmaVerticaVersionOp := makeNMAVerticaVersionOp(hosts, true, true /*IsEon*/) - nmaShowRestorePointOp := makeNMAShowRestorePointsOpWithFilterOptions(vcc.Log, bootstrapHost, *options.DBName, - *options.CommunalStorageLocation, options.ConfigurationParameters, options.FilterOptions) + nmaShowRestorePointOp := makeNMAShowRestorePointsOpWithFilterOptions(vcc.Log, bootstrapHost, options.DBName, + options.CommunalStorageLocation, options.ConfigurationParameters, &options.FilterOptions) instructions = append(instructions, &nmaHealthOp, diff --git a/vclusterops/restore_points_test.go b/vclusterops/restore_points_test.go index 705e41f..e35b336 100644 --- a/vclusterops/restore_points_test.go +++ b/vclusterops/restore_points_test.go @@ -10,8 +10,8 @@ import ( func TestShowRestorePointFilterOptions_ValidateAndStandardizeTimestampsIfAny(t *testing.T) { // Test case 1: No validation needed filterOptions := ShowRestorePointFilterOptions{ - StartTimestamp: nil, - EndTimestamp: nil, + StartTimestamp: "", + EndTimestamp: "", } err := filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) @@ -19,8 +19,8 @@ func TestShowRestorePointFilterOptions_ValidateAndStandardizeTimestampsIfAny(t * // Test case 2: Invalid start timestamp startTimestamp := "invalid_start_timestamp" filterOptions = ShowRestorePointFilterOptions{ - StartTimestamp: &startTimestamp, - EndTimestamp: nil, + StartTimestamp: startTimestamp, + EndTimestamp: "", } err = filterOptions.ValidateAndStandardizeTimestampsIfAny() expectedErr := fmt.Errorf("start timestamp %q is invalid;", startTimestamp) @@ -29,8 +29,8 @@ func TestShowRestorePointFilterOptions_ValidateAndStandardizeTimestampsIfAny(t * // Test case 3: Invalid end timestamp endTimestamp := "invalid_end_timestamp" filterOptions = ShowRestorePointFilterOptions{ - StartTimestamp: nil, - EndTimestamp: &endTimestamp, + StartTimestamp: "", + EndTimestamp: endTimestamp, } err = filterOptions.ValidateAndStandardizeTimestampsIfAny() expectedErr = fmt.Errorf("end timestamp %q is invalid;", endTimestamp) @@ -43,44 +43,43 @@ func TestShowRestorePointFilterOptions_ValidateAndStandardizeTimestampsIfAny(t * startTimestamp = earlierDate + " 00:00:00" endTimestamp = laterDate + " 00:00:00" filterOptions = ShowRestorePointFilterOptions{ - StartTimestamp: &startTimestamp, - EndTimestamp: &endTimestamp, + StartTimestamp: startTimestamp, + EndTimestamp: endTimestamp, } err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) - startTimestamp = earlierDate - endTimestamp = laterDate + filterOptions.StartTimestamp = earlierDate + filterOptions.EndTimestamp = laterDate err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) - assert.Equal(t, earlierDate+" 00:00:00.000000000", *filterOptions.StartTimestamp) - assert.Equal(t, laterDate+" 23:59:59.999999999", *filterOptions.EndTimestamp) + assert.Equal(t, earlierDate+" 00:00:00.000000000", filterOptions.StartTimestamp) + assert.Equal(t, laterDate+" 23:59:59.999999999", filterOptions.EndTimestamp) - startTimestamp = earlierDate - endTimestamp = earlierDate + filterOptions.StartTimestamp = earlierDate + filterOptions.EndTimestamp = earlierDate err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) - startTimestamp = earlierDate - endTimestamp = laterDate + " 23:59:59" + filterOptions.StartTimestamp = earlierDate + filterOptions.EndTimestamp = laterDate + " 23:59:59" err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) - startTimestamp = earlierDate + " 01:01:01.010101010" - endTimestamp = laterDate + filterOptions.StartTimestamp = earlierDate + " 01:01:01.010101010" + filterOptions.EndTimestamp = laterDate err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) - assert.Equal(t, startTimestamp, *filterOptions.StartTimestamp) - startTimestamp = earlierDate + " 23:59:59" - endTimestamp = earlierDate + " 23:59:59.123456789" + filterOptions.StartTimestamp = earlierDate + " 23:59:59" + filterOptions.EndTimestamp = earlierDate + " 23:59:59.123456789" err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.NoError(t, err) // Test case 5: Start timestamp after end timestamp filterOptions = ShowRestorePointFilterOptions{ - StartTimestamp: &endTimestamp, - EndTimestamp: &startTimestamp, + StartTimestamp: endTimestamp, + EndTimestamp: startTimestamp, } err = filterOptions.ValidateAndStandardizeTimestampsIfAny() assert.EqualError(t, err, "start timestamp must be before end timestamp") diff --git a/vclusterops/revive_db.go b/vclusterops/revive_db.go index 827aa0f..f6d3e0c 100644 --- a/vclusterops/revive_db.go +++ b/vclusterops/revive_db.go @@ -38,7 +38,7 @@ type VReviveDatabaseOptions struct { // whether ignore the cluster lease IgnoreClusterLease bool // the restore policy - RestorePoint *RestorePointPolicy + RestorePoint RestorePointPolicy } type RestorePointPolicy struct { @@ -51,15 +51,15 @@ type RestorePointPolicy struct { } func (options *VReviveDatabaseOptions) isRestoreEnabled() bool { - return options.RestorePoint != nil && options.RestorePoint.Archive != "" + return options.RestorePoint.Archive != "" } func (options *VReviveDatabaseOptions) hasValidRestorePointID() bool { - return options.RestorePoint != nil && options.RestorePoint.ID != "" + return options.RestorePoint.ID != "" } func (options *VReviveDatabaseOptions) hasValidRestorePointIndex() bool { - return options.RestorePoint != nil && options.RestorePoint.Index > 0 + return options.RestorePoint.Index > 0 } func (options *VReviveDatabaseOptions) findSpecifiedRestorePoint(allRestorePoints []RestorePoint) (string, error) { @@ -122,15 +122,14 @@ func (options *VReviveDatabaseOptions) setDefaultValues() { // set default values for revive db options options.LoadCatalogTimeout = util.DefaultLoadCatalogTimeoutSeconds - options.RestorePoint = new(RestorePointPolicy) } func (options *VReviveDatabaseOptions) validateRequiredOptions() error { // database name - if *options.DBName == "" { + if options.DBName == "" { return fmt.Errorf("must specify a database name") } - err := util.ValidateName(*options.DBName, "database") + err := util.ValidateName(options.DBName, "database") if err != nil { return err } @@ -142,7 +141,7 @@ func (options *VReviveDatabaseOptions) validateRequiredOptions() error { } // communal storage - return util.ValidateCommunalStorageLocation(*options.CommunalStorageLocation) + return util.ValidateCommunalStorageLocation(options.CommunalStorageLocation) } func (options *VReviveDatabaseOptions) validateRestoreOptions() error { @@ -259,9 +258,9 @@ func (vcc VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (db } // fill vdb with VReviveDatabaseOptions information - vdb.Name = *options.DBName + vdb.Name = options.DBName vdb.IsEon = true - vdb.CommunalStorageLocation = *options.CommunalStorageLocation + vdb.CommunalStorageLocation = options.CommunalStorageLocation vdb.Ipv6 = options.IPv6 return dbInfo, &vdb, nil @@ -328,15 +327,15 @@ func (vcc VClusterCommands) producePreReviveDBInstructions(options *VReviveDatab initiator := getInitiator(hosts) bootstrapHost := []string{initiator} filterOptions := ShowRestorePointFilterOptions{} - filterOptions.ArchiveName = &options.RestorePoint.Archive + filterOptions.ArchiveName = options.RestorePoint.Archive if options.hasValidRestorePointID() { - filterOptions.ArchiveID = &options.RestorePoint.ID + filterOptions.ArchiveID = options.RestorePoint.ID } else { indexStr := strconv.Itoa(options.RestorePoint.Index) - filterOptions.ArchiveIndex = &indexStr + filterOptions.ArchiveIndex = indexStr } - nmaShowRestorePointsOp := makeNMAShowRestorePointsOpWithFilterOptions(vcc.GetLog(), bootstrapHost, *options.DBName, - *options.CommunalStorageLocation, options.ConfigurationParameters, &filterOptions) + nmaShowRestorePointsOp := makeNMAShowRestorePointsOpWithFilterOptions(vcc.GetLog(), bootstrapHost, options.DBName, + options.CommunalStorageLocation, options.ConfigurationParameters, &filterOptions) instructions = append(instructions, &nmaShowRestorePointsOp, ) @@ -411,7 +410,7 @@ func (vcc VClusterCommands) produceReviveDBInstructions(options *VReviveDatabase nmaNetworkProfileOp := makeNMANetworkProfileOp(options.Hosts) nmaLoadRemoteCatalogOp := makeNMALoadRemoteCatalogOp(oldHosts, options.ConfigurationParameters, - &newVDB, options.LoadCatalogTimeout, options.RestorePoint) + &newVDB, options.LoadCatalogTimeout, &options.RestorePoint) instructions = append(instructions, &nmaPrepareDirectoriesOp, @@ -426,8 +425,8 @@ func (vcc VClusterCommands) produceReviveDBInstructions(options *VReviveDatabase func (options *VReviveDatabaseOptions) generateReviveVDB(vdb *VCoordinationDatabase) (newVDB VCoordinationDatabase, oldHosts []string, err error) { newVDB = makeVCoordinationDatabase() - newVDB.Name = *options.DBName - newVDB.CommunalStorageLocation = *options.CommunalStorageLocation + newVDB.Name = options.DBName + newVDB.CommunalStorageLocation = options.CommunalStorageLocation // use new cluster hosts newVDB.HostList = options.Hosts diff --git a/vclusterops/revive_db_test.go b/vclusterops/revive_db_test.go index d8b6ec5..9a7068a 100644 --- a/vclusterops/revive_db_test.go +++ b/vclusterops/revive_db_test.go @@ -12,7 +12,7 @@ func TestFindSpecifiedRestorePoint(t *testing.T) { idVal := "id1" indexVal := 0 options := VReviveDatabaseOptions{ - RestorePoint: &RestorePointPolicy{ + RestorePoint: RestorePointPolicy{ Archive: archiveVal, ID: idVal, Index: indexVal, diff --git a/vclusterops/sandbox.go b/vclusterops/sandbox.go index e4993c8..e41261b 100644 --- a/vclusterops/sandbox.go +++ b/vclusterops/sandbox.go @@ -24,8 +24,8 @@ import ( type VSandboxOptions struct { DatabaseOptions - SandboxName *string - SCName *string + SandboxName string + SCName string SCHosts []string SCRawHosts []string } @@ -38,8 +38,6 @@ func VSandboxOptionsFactory() VSandboxOptions { func (options *VSandboxOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() - options.SCName = new(string) - options.SandboxName = new(string) } func (options *VSandboxOptions) validateRequiredOptions(logger vlog.Printer) error { @@ -48,11 +46,11 @@ func (options *VSandboxOptions) validateRequiredOptions(logger vlog.Printer) err return err } - if *options.SCName == "" { + if options.SCName == "" { return fmt.Errorf("must specify a subcluster name") } - if *options.SandboxName == "" { + if options.SandboxName == "" { return fmt.Errorf("must specify a sandbox name") } return nil @@ -112,31 +110,31 @@ func (vcc *VClusterCommands) produceSandboxSubclusterInstructions(options *VSand } } - username := *options.UserName + username := options.UserName // Get all up nodes - httpsGetUpNodesOp, err := makeHTTPSGetUpScNodesOp(*options.DBName, options.Hosts, - usePassword, username, options.Password, SandboxCmd, *options.SCName) + httpsGetUpNodesOp, err := makeHTTPSGetUpScNodesOp(options.DBName, options.Hosts, + usePassword, username, options.Password, SandboxCmd, options.SCName) if err != nil { return instructions, err } // Get subcluster sandboxing information and remove sandboxed nodes from prospective initator hosts list httpsCheckSubclusterSandboxOp, err := makeHTTPSCheckSubclusterSandboxOp(options.Hosts, - *options.SCName, *options.SandboxName, usePassword, username, options.Password) + options.SCName, options.SandboxName, usePassword, username, options.Password) if err != nil { return instructions, err } // Run Sandboxing - httpsSandboxSubclusterOp, err := makeHTTPSandboxingOp(vcc.Log, *options.SCName, *options.SandboxName, + httpsSandboxSubclusterOp, err := makeHTTPSandboxingOp(vcc.Log, options.SCName, options.SandboxName, usePassword, username, options.Password) if err != nil { return instructions, err } // Poll for sandboxed nodes to be up - httpsPollSubclusterNodeOp, err := makeHTTPSPollSubclusterNodeStateUpOp(*options.SCName, + httpsPollSubclusterNodeOp, err := makeHTTPSPollSubclusterNodeStateUpOp(options.SCName, usePassword, username, options.Password) if err != nil { return instructions, err @@ -179,7 +177,7 @@ func (options *VSandboxOptions) runCommand(vcc VClusterCommands) error { // run the engine runError := clusterOpEngine.run(vcc.Log) if runError != nil { - return fmt.Errorf("fail to sandbox subcluster %s, %w", *options.SCName, runError) + return fmt.Errorf("fail to sandbox subcluster %s, %w", options.SCName, runError) } return nil } diff --git a/vclusterops/scrutinize.go b/vclusterops/scrutinize.go index befc635..94c1893 100644 --- a/vclusterops/scrutinize.go +++ b/vclusterops/scrutinize.go @@ -234,14 +234,14 @@ func (vcc VClusterCommands) VScrutinize(options *VScrutinizeOptions) error { // abort scrutinize, so just prints a warning. func (options *VScrutinizeOptions) stageVclusterLog(id string, log vlog.Printer) { // if using vcluster command line, the log path will always be set - if options.LogPath == nil { + if options.LogPath == "" { log.PrintWarning("Path to scrutinize log not provided. " + "The log for this scrutinize run will not be included.") return } destPath := fmt.Sprintf("%s/%s/%s", scrutinizeRemoteOutputPath, id, scrutinizeLogFileName) - sourcePath := *options.LogPath + sourcePath := options.LogPath // copy the log instead of symlinking to avoid issues with tar log.Info("Copying scrutinize log", "source", sourcePath, "dest", destPath) @@ -282,8 +282,8 @@ func (options *VScrutinizeOptions) getVDBForScrutinize(logger vlog.Printer, } // get map of host to node name and fully qualified catalog path - getNodesInfoOp := makeNMAGetNodesInfoOp(vdb.HostList, *options.DBName, - *options.CatalogPrefix, true /* ignore internal errors */, vdb) + getNodesInfoOp := makeNMAGetNodesInfoOp(vdb.HostList, options.DBName, + options.CatalogPrefix, true /* ignore internal errors */, vdb) err = options.runClusterOpEngine(logger, []clusterOp{&getNodesInfoOp}) if err != nil { return err @@ -326,8 +326,8 @@ func (vcc VClusterCommands) produceScrutinizeInstructions(options *VScrutinizeOp } // Get up database nodes for the system table task - getUpNodesOp, err := makeHTTPSGetUpNodesOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, ScrutinizeCmd) + getUpNodesOp, err := makeHTTPSGetUpNodesOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, ScrutinizeCmd) if err != nil { return nil, err } @@ -428,7 +428,7 @@ func getNodeInfoForScrutinize(hosts []string, vdb *VCoordinationDatabase, if nodeName == "" { allErrors = errors.Join(allErrors, fmt.Errorf("host %s has empty name", host)) } - err = util.ValidateRequiredAbsPath(&catPath, "catalog path") + err = util.ValidateRequiredAbsPath(catPath, "catalog path") if err != nil { allErrors = errors.Join(allErrors, fmt.Errorf("host %s has problematic catalog path %s, details: %w", host, catPath, err)) } @@ -453,7 +453,7 @@ func getStageSystemTablesInstructions(logger vlog.Printer, options *VScrutinizeO // Get a list of existing system tables for staging system tables operation getSystemTablesOp, err := makeHTTPSGetSystemTablesOp(logger, options.Hosts, - options.usePassword, *options.UserName, options.Password) + options.usePassword, options.UserName, options.Password) if err != nil { return nil, err } @@ -461,7 +461,7 @@ func getStageSystemTablesInstructions(logger vlog.Printer, options *VScrutinizeO // Stage system tables stored in execContext stageSystemTablesOp, err := makeHTTPSStageSystemTablesOp(logger, - options.usePassword, *options.UserName, options.Password, options.ID, hostNodeNameMap, &stagingDir, + options.usePassword, options.UserName, options.Password, options.ID, hostNodeNameMap, &stagingDir, options.ExcludeContainers, options.ExcludeActiveQueries, options.IncludeRos, options.IncludeExternalTableDetails, options.IncludeUDXDetails, ) diff --git a/vclusterops/start_db.go b/vclusterops/start_db.go index b57de5a..78fe686 100644 --- a/vclusterops/start_db.go +++ b/vclusterops/start_db.go @@ -28,14 +28,14 @@ type VStartDatabaseOptions struct { // basic db info DatabaseOptions // timeout for polling the states of all nodes in the database in HTTPSPollNodeStateOp - StatePollingTimeout *int + StatePollingTimeout int // whether trim the input host list based on the catalog info - TrimHostList *bool + TrimHostList bool // If the path is set, the NMA will store the Vertica start command at the path // instead of executing it. This is useful in containerized environments where // you may not want to have both the NMA and Vertica server in the same container. // This feature requires version 24.2.0+. - StartUpConf *string + StartUpConf string } func VStartDatabaseOptionsFactory() VStartDatabaseOptions { @@ -44,15 +44,12 @@ func VStartDatabaseOptionsFactory() VStartDatabaseOptions { // set default values to the params opt.setDefaultValues() - opt.StatePollingTimeout = new(int) - opt.TrimHostList = new(bool) - opt.StartUpConf = new(string) - return opt } func (options *VStartDatabaseOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() + options.StatePollingTimeout = util.DefaultStatePollingTimeout } func (options *VStartDatabaseOptions) validateRequiredOptions(logger vlog.Printer) error { @@ -65,8 +62,8 @@ func (options *VStartDatabaseOptions) validateRequiredOptions(logger vlog.Printe } func (options *VStartDatabaseOptions) validateEonOptions() error { - if *options.CommunalStorageLocation != "" { - return util.ValidateCommunalStorageLocation(*options.CommunalStorageLocation) + if options.CommunalStorageLocation != "" { + return util.ValidateCommunalStorageLocation(options.CommunalStorageLocation) } return nil @@ -108,11 +105,6 @@ func (vcc VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) (vdbP * - Give the instructions to the VClusterOpEngine to run */ - // set default value to StatePollingTimeout - if *options.StatePollingTimeout == 0 { - *options.StatePollingTimeout = util.DefaultStatePollingTimeout - } - // validate and analyze all options err = options.validateAnalyzeOptions(vcc.Log) if err != nil { @@ -126,7 +118,7 @@ func (vcc VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) (vdbP 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 != "" { + if options.CommunalStorageLocation != "" { vdbNew, e := options.getVDBWhenDBIsDown(vcc) if e != nil { // show a warning message if we cannot get VDB from a down database @@ -177,7 +169,7 @@ func (vcc VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) (vdbP func (vcc VClusterCommands) runStartDBPrecheck(options *VStartDatabaseOptions, vdb *VCoordinationDatabase) error { // pre-instruction to perform basic checks and get basic information - preInstructions, err := vcc.produceStartDBPreCheck(options, vdb, *options.TrimHostList) + preInstructions, err := vcc.produceStartDBPreCheck(options, vdb, options.TrimHostList) if err != nil { return fmt.Errorf("fail to production instructions: %w", err) } @@ -193,7 +185,7 @@ func (vcc VClusterCommands) runStartDBPrecheck(options *VStartDatabaseOptions, v // If requested, remove any provided hosts that are not in the catalog. Use // the vdb that we just fetched by the catalog editor. It will be the from // the latest catalog. - if *options.TrimHostList { + if options.TrimHostList { options.Hosts = vcc.removeHostsNotInCatalog(&clusterOpEngine.execContext.nmaVDatabase, options.Hosts) } @@ -242,7 +234,7 @@ func (vcc VClusterCommands) produceStartDBPreCheck(options *VStartDatabaseOption } checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(options.Hosts, - options.usePassword, *options.UserName, options.Password, StartDB) + options.usePassword, options.UserName, options.Password, StartDB) if err != nil { return instructions, err } @@ -253,7 +245,7 @@ func (vcc VClusterCommands) produceStartDBPreCheck(options *VStartDatabaseOption // when we cannot get db info from cluster_config.json, we will fetch it from NMA /nodes endpoint. if len(vdb.HostNodeMap) == 0 { - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, *options.DBName, *options.CatalogPrefix, + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, options.DBName, options.CatalogPrefix, true /* ignore internal errors */, vdb) instructions = append(instructions, &nmaGetNodesInfoOp) } @@ -312,9 +304,9 @@ func (vcc VClusterCommands) produceStartDBInstructions(options *VStartDatabaseOp options.Hosts, nil /*db configurations retrieved from a running db*/) - nmaStartNewNodesOp := makeNMAStartNodeOp(options.Hosts, *options.StartUpConf) + nmaStartNewNodesOp := makeNMAStartNodeOp(options.Hosts, options.StartUpConf) httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(options.Hosts, - options.usePassword, *options.UserName, options.Password, *options.StatePollingTimeout, StartDBCmd) + options.usePassword, options.UserName, options.Password, options.StatePollingTimeout, StartDBCmd) if err != nil { return instructions, err } @@ -325,7 +317,7 @@ func (vcc VClusterCommands) produceStartDBInstructions(options *VStartDatabaseOp ) if options.IsEon { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(options.Hosts, options.usePassword, *options.UserName, options.Password, StartDBSyncCat) + 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 44694f0..fe170e4 100644 --- a/vclusterops/start_node.go +++ b/vclusterops/start_node.go @@ -36,7 +36,7 @@ type VStartNodesOptions struct { // instead of executing it. This is useful in containerized environments where // you may not want to have both the NMA and Vertica server in the same container. // This feature requires version 24.2.0+. - StartUpConf *string + StartUpConf string } type VStartNodesInfo struct { @@ -63,7 +63,6 @@ func VStartNodesOptionsFactory() VStartNodesOptions { func (options *VStartNodesOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() - options.StartUpConf = new(string) } func (options *VStartNodesOptions) validateParseOptions(logger vlog.Printer) error { @@ -263,8 +262,8 @@ func (vcc VClusterCommands) produceStartNodesInstructions(startNodeInfo *VStartN return instructions, err } - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, StartNodeCommand) + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, StartNodeCommand) if err != nil { return instructions, err } @@ -278,19 +277,19 @@ func (vcc VClusterCommands) produceStartNodesInstructions(startNodeInfo *VStartN if len(startNodeInfo.ReIPList) != 0 { nmaNetworkProfileOp := makeNMANetworkProfileOp(startNodeInfo.ReIPList) httpsReIPOp, e := makeHTTPSReIPOp(startNodeInfo.NodeNamesToStart, startNodeInfo.ReIPList, - options.usePassword, *options.UserName, options.Password) + options.usePassword, options.UserName, options.Password) if e != nil { return instructions, e } // host is set to nil value in the reload spread step // we use information from node information to find the up host later - httpsReloadSpreadOp, e := makeHTTPSReloadSpreadOp(true, *options.UserName, options.Password) + httpsReloadSpreadOp, e := makeHTTPSReloadSpreadOp(true, options.UserName, options.Password) if e != nil { return instructions, e } // update new vdb information after re-ip - httpsGetNodesInfoOp, e := makeHTTPSGetNodesInfoOp(*options.DBName, options.Hosts, - options.usePassword, *options.UserName, options.Password, vdb, true, startNodeInfo.Sandbox) + httpsGetNodesInfoOp, e := makeHTTPSGetNodesInfoOp(options.DBName, options.Hosts, + options.usePassword, options.UserName, options.Password, vdb, true, startNodeInfo.Sandbox) if e != nil { return instructions, e } @@ -316,15 +315,15 @@ func (vcc VClusterCommands) produceStartNodesInstructions(startNodeInfo *VStartN startNodeInfo.HostsToStart, vdb) - httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandWithSandboxOp(options.usePassword, *options.UserName, options.Password, + httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandWithSandboxOp(options.usePassword, options.UserName, options.Password, vdb, startNodeInfo.Sandbox) if err != nil { return instructions, err } - nmaRestartNewNodesOp := makeNMAStartNodeOpWithVDB(startNodeInfo.HostsToStart, *options.StartUpConf, vdb) + nmaRestartNewNodesOp := makeNMAStartNodeOpWithVDB(startNodeInfo.HostsToStart, options.StartUpConf, vdb) httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(startNodeInfo.HostsToStart, - options.usePassword, *options.UserName, options.Password, options.StatePollingTimeout, StartNodeCmd) + options.usePassword, options.UserName, options.Password, options.StatePollingTimeout, StartNodeCmd) if err != nil { return instructions, err } @@ -336,7 +335,7 @@ func (vcc VClusterCommands) produceStartNodesInstructions(startNodeInfo *VStartN ) if vdb.IsEon { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(options.Hosts, options.usePassword, *options.UserName, + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(options.Hosts, options.usePassword, options.UserName, options.Password, StartNodeSyncCat) if err != nil { return instructions, err diff --git a/vclusterops/stop_db.go b/vclusterops/stop_db.go index 925f559..e43b5be 100644 --- a/vclusterops/stop_db.go +++ b/vclusterops/stop_db.go @@ -27,12 +27,12 @@ type VStopDatabaseOptions struct { DatabaseOptions /* part 2: eon db info */ - DrainSeconds *int // time in seconds to wait for database users' disconnection - Sandbox *string // Stop db on given sandbox - MainCluster *bool // Stop db on main cluster only + DrainSeconds *int // time in seconds to wait for database users' disconnection + Sandbox string // Stop db on given sandbox + MainCluster bool // Stop db on main cluster only /* part 3: hidden info */ - CheckUserConn *bool // whether check user connection - ForceKill *bool // whether force kill connections + CheckUserConn bool // whether check user connection + ForceKill bool // whether force kill connections } func VStopDatabaseOptionsFactory() VStopDatabaseOptions { @@ -45,10 +45,6 @@ func VStopDatabaseOptionsFactory() VStopDatabaseOptions { func (options *VStopDatabaseOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() - options.Sandbox = new(string) - options.MainCluster = new(bool) - options.CheckUserConn = new(bool) - options.ForceKill = new(bool) } func (options *VStopDatabaseOptions) validateRequiredOptions(log vlog.Printer) error { @@ -61,7 +57,7 @@ func (options *VStopDatabaseOptions) validateRequiredOptions(log vlog.Printer) e } func (options *VStopDatabaseOptions) validateEonOptions(log vlog.Printer) error { - if *options.Sandbox != "" && *options.MainCluster { + if options.Sandbox != "" && options.MainCluster { return fmt.Errorf("Error: cannot use both --sandbox and --main-cluster-only options together ") } @@ -189,15 +185,15 @@ func (vcc *VClusterCommands) produceStopDBInstructions(options *VStopDatabaseOpt } } - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesWithSandboxOp(*options.DBName, options.Hosts, - usePassword, *options.UserName, options.Password, StopDBCmd, *options.Sandbox, *options.MainCluster) + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesWithSandboxOp(options.DBName, options.Hosts, + usePassword, options.UserName, options.Password, StopDBCmd, options.Sandbox, options.MainCluster) if err != nil { return instructions, err } instructions = append(instructions, &httpsGetUpNodesOp) if options.IsEon { - httpsSyncCatalogOp, e := makeHTTPSSyncCatalogOpWithoutHosts(usePassword, *options.UserName, options.Password, StopDBSyncCat) + httpsSyncCatalogOp, e := makeHTTPSSyncCatalogOpWithoutHosts(usePassword, options.UserName, options.Password, StopDBSyncCat) if e != nil { return instructions, e } @@ -206,14 +202,14 @@ func (vcc *VClusterCommands) produceStopDBInstructions(options *VStopDatabaseOpt vcc.Log.PrintInfo("Skipping sync catalog for an enterprise database") } - httpsStopDBOp, err := makeHTTPSStopDBOp(usePassword, *options.UserName, options.Password, options.DrainSeconds, - *options.Sandbox, *options.MainCluster) + httpsStopDBOp, err := makeHTTPSStopDBOp(usePassword, options.UserName, options.Password, options.DrainSeconds, + options.Sandbox, options.MainCluster) if err != nil { return instructions, err } httpsCheckDBRunningOp, err := makeHTTPSCheckRunningDBWithSandboxOp(options.Hosts, - usePassword, *options.UserName, *options.Sandbox, *options.MainCluster, options.Password, StopDB) + usePassword, options.UserName, options.Sandbox, options.MainCluster, options.Password, StopDB) if err != nil { return instructions, err } @@ -230,7 +226,7 @@ func (vcc *VClusterCommands) produceStopDBInstructions(options *VStopDatabaseOpt // return an error if a requirement isn't met. func (options *VStopDatabaseOptions) checkStopDBRequirements(vdb *VCoordinationDatabase) error { // if stop db on the whole cluster, at least one UP main cluster host in the host list - if *options.Sandbox == "" && !*options.MainCluster { + if options.Sandbox == "" && !options.MainCluster { hasMainClusterHost := false for _, host := range options.Hosts { vnode, ok := vdb.HostNodeMap[host] diff --git a/vclusterops/stop_subcluster.go b/vclusterops/stop_subcluster.go index 89557d1..8241b51 100644 --- a/vclusterops/stop_subcluster.go +++ b/vclusterops/stop_subcluster.go @@ -163,24 +163,24 @@ func (vcc *VClusterCommands) produceStopSCInstructions(options *VStopSubclusterO } } - httpsGetUpNodesOp, err := makeHTTPSGetUpScNodesOp(*options.DBName, options.Hosts, - usePassword, *options.UserName, options.Password, StopSubclusterCmd, options.SCName) + httpsGetUpNodesOp, err := makeHTTPSGetUpScNodesOp(options.DBName, options.Hosts, + usePassword, options.UserName, options.Password, StopSubclusterCmd, options.SCName) if err != nil { return instructions, err } - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOpWithoutHosts(usePassword, *options.UserName, options.Password, StopSCSyncCat) + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOpWithoutHosts(usePassword, options.UserName, options.Password, StopSCSyncCat) if err != nil { return instructions, err } - httpsStopSCOp, err := makeHTTPSStopSCOp(usePassword, *options.UserName, options.Password, + httpsStopSCOp, err := makeHTTPSStopSCOp(usePassword, options.UserName, options.Password, options.SCName, options.DrainSeconds, options.Force) if err != nil { return instructions, err } - httpsCheckDBRunningOp, err := makeHTTPSCheckRunningDBOpWithoutHosts(usePassword, *options.UserName, options.Password, StopSC) + httpsCheckDBRunningOp, err := makeHTTPSCheckRunningDBOpWithoutHosts(usePassword, options.UserName, options.Password, StopSC) if err != nil { return instructions, err } diff --git a/vclusterops/unsandbox.go b/vclusterops/unsandbox.go index 166d2c2..d4427b7 100644 --- a/vclusterops/unsandbox.go +++ b/vclusterops/unsandbox.go @@ -25,7 +25,7 @@ import ( type VUnsandboxOptions struct { DatabaseOptions - SCName *string + SCName string SCHosts []string SCRawHosts []string // if restart the subcluster after unsandboxing it, the default value of it is true @@ -42,7 +42,6 @@ func VUnsandboxOptionsFactory() VUnsandboxOptions { func (options *VUnsandboxOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() - options.SCName = new(string) options.RestartSC = true } @@ -52,7 +51,7 @@ func (options *VUnsandboxOptions) validateRequiredOptions(logger vlog.Printer) e return err } - if *options.SCName == "" { + if options.SCName == "" { return fmt.Errorf("must specify a subcluster name") } return nil @@ -111,21 +110,21 @@ func (vcc *VClusterCommands) unsandboxPreCheck(vdb *VCoordinationDatabase, optio } if !vdb.IsEon { return fmt.Errorf(`cannot unsandbox subclusters for an enterprise database '%s'`, - *options.DBName) + options.DBName) } scFound := false var sandboxedHosts []string for _, vnode := range vdb.HostNodeMap { - if !scFound && vnode.Subcluster == *options.SCName { + if !scFound && vnode.Subcluster == options.SCName { scFound = true } - if vnode.Subcluster == *options.SCName { + if vnode.Subcluster == options.SCName { // if the subcluster is not sandboxed, return error immediately if vnode.Sandbox == "" { - return &SubclusterNotSandboxedError{SCName: *options.SCName} + return &SubclusterNotSandboxedError{SCName: options.SCName} } sandboxedHosts = append(sandboxedHosts, vnode.Address) // when the node state is not "DOWN" ("UP" or "UNKNOWN"), we consider @@ -137,14 +136,14 @@ func (vcc *VClusterCommands) unsandboxPreCheck(vdb *VCoordinationDatabase, optio } if !scFound { - vcc.Log.PrintError(`subcluster '%s' does not exist`, *options.SCName) + vcc.Log.PrintError(`subcluster '%s' does not exist`, options.SCName) rfcErr := rfc7807.New(rfc7807.SubclusterNotFound).WithHost(options.Hosts[0]) return rfcErr } mainClusterHost := util.SliceDiff(options.Hosts, sandboxedHosts) if len(mainClusterHost) == 0 { - return fmt.Errorf(`require at least one UP host outside of the sandbox subcluster '%s'in the input host list`, *options.SCName) + return fmt.Errorf(`require at least one UP host outside of the sandbox subcluster '%s'in the input host list`, options.SCName) } return nil } @@ -179,11 +178,11 @@ func (vcc *VClusterCommands) produceUnsandboxSCInstructions(options *VUnsandboxO } } - username := *options.UserName + username := options.UserName // Get all up nodes - httpsGetUpNodesOp, err := makeHTTPSGetUpScNodesOp(*options.DBName, options.Hosts, - usePassword, username, options.Password, UnsandboxCmd, *options.SCName) + httpsGetUpNodesOp, err := makeHTTPSGetUpScNodesOp(options.DBName, options.Hosts, + usePassword, username, options.Password, UnsandboxCmd, options.SCName) if err != nil { return instructions, err } @@ -198,7 +197,7 @@ func (vcc *VClusterCommands) produceUnsandboxSCInstructions(options *VUnsandboxO } // Poll for nodes down - httpsPollScDown, e := makeHTTPSPollSubclusterNodeStateDownOp(*options.SCName, + httpsPollScDown, e := makeHTTPSPollSubclusterNodeStateDownOp(options.SCName, usePassword, username, options.Password) if e != nil { return instructions, e @@ -211,7 +210,7 @@ func (vcc *VClusterCommands) produceUnsandboxSCInstructions(options *VUnsandboxO } // Run Unsandboxing - httpsUnsandboxSubclusterOp, err := makeHTTPSUnsandboxingOp(*options.SCName, + httpsUnsandboxSubclusterOp, err := makeHTTPSUnsandboxingOp(options.SCName, usePassword, username, options.Password) if err != nil { return instructions, err @@ -230,7 +229,7 @@ func (vcc *VClusterCommands) produceUnsandboxSCInstructions(options *VUnsandboxO if options.RestartSC { // NMA check vertica versions before restart - nmaVersionCheck := makeNMAVerticaVersionOpAfterUnsandbox(true, *options.SCName) + nmaVersionCheck := makeNMAVerticaVersionOpAfterUnsandbox(true, options.SCName) // Get startup commands httpsStartUpCommandOp, err := makeHTTPSStartUpCommandOpAfterUnsandbox(usePassword, username, options.Password) @@ -242,7 +241,7 @@ func (vcc *VClusterCommands) produceUnsandboxSCInstructions(options *VUnsandboxO nmaRestartNodesOp := makeNMAStartNodeOpAfterUnsandbox("") // Poll for nodes UP - httpsPollScUp, err := makeHTTPSPollSubclusterNodeStateUpOp(*options.SCName, + httpsPollScUp, err := makeHTTPSPollSubclusterNodeStateUpOp(options.SCName, usePassword, username, options.Password) if err != nil { return instructions, err @@ -284,7 +283,7 @@ func (options *VUnsandboxOptions) runCommand(vcc VClusterCommands) error { // run the engine runError := clusterOpEngine.run(vcc.Log) if runError != nil { - return fmt.Errorf("fail to unsandbox subcluster %s, %w", *options.SCName, runError) + return fmt.Errorf("fail to unsandbox subcluster %s, %w", options.SCName, runError) } return nil } diff --git a/vclusterops/util/defaults.go b/vclusterops/util/defaults.go index 4a4911e..704d3e6 100644 --- a/vclusterops/util/defaults.go +++ b/vclusterops/util/defaults.go @@ -32,10 +32,13 @@ const ( DefaultLoadCatalogTimeoutSeconds = 3600 DefaultStatePollingTimeout = 1200 DefaultLargeCluster = -1 + DefaultP2p = true + DefaultSpreadLoggingLevel = -1 MaxLargeCluster = 120 MinDepotSize = 0 MaxDepotSize = 100 DefaultDrainSeconds = 60 + DefaultControlSetSize = -1 NodeUpState = "UP" NodeDownState = "DOWN" SuppressHelp = "SUPPRESS_HELP" diff --git a/vclusterops/util/util.go b/vclusterops/util/util.go index bd53ddc..a824fee 100644 --- a/vclusterops/util/util.go +++ b/vclusterops/util/util.go @@ -17,7 +17,6 @@ package util import ( "encoding/json" - "errors" "flag" "fmt" "io/fs" @@ -472,29 +471,23 @@ func GetEonFlagMsg(message string) string { return "[Eon only] " + message } -func ValidateAbsPath(path *string, pathName string) error { - if path != nil { - err := AbsPathCheck(*path) - if err != nil { - return fmt.Errorf("must specify an absolute %s", pathName) - } +func ValidateAbsPath(path, pathName string) error { + err := AbsPathCheck(path) + if err != nil { + return fmt.Errorf("must specify an absolute %s", pathName) } + return nil } // ValidateRequiredAbsPath check whether a required path is set // then validate it -func ValidateRequiredAbsPath(path *string, pathName string) error { - pathNotSpecifiedMsg := fmt.Sprintf("must specify an absolute %s", pathName) - - if path != nil { - if *path == "" { - return errors.New(pathNotSpecifiedMsg) - } - return ValidateAbsPath(path, pathName) +func ValidateRequiredAbsPath(path, pathName string) error { + if path == "" { + return fmt.Errorf("must specify an absolute %s", pathName) } - return errors.New(pathNotSpecifiedMsg) + return ValidateAbsPath(path, pathName) } func ParamNotSetErrorMsg(param string) error { @@ -586,11 +579,11 @@ const DefaultDateOnlyFormat = time.DateOnly // import time package in this util file so other files don't need to import time // wrapper function to handle empty input string, returns an error if the time is invalid // caller responsible for passing in correct layout -func IsEmptyOrValidTimeStr(layout string, value *string) (*time.Time, error) { - if value == nil || *value == "" { +func IsEmptyOrValidTimeStr(layout, value string) (*time.Time, error) { + if value == "" { return nil, nil } - parsedTime, err := time.Parse(layout, *value) + parsedTime, err := time.Parse(layout, value) if err != nil { return nil, err } diff --git a/vclusterops/util/util_test.go b/vclusterops/util/util_test.go index f9ecfa3..36d8e9e 100644 --- a/vclusterops/util/util_test.go +++ b/vclusterops/util/util_test.go @@ -355,19 +355,18 @@ func TestValidateCommunalStorageLocation(t *testing.T) { func TestIsEmptyOrValidTimeStr(t *testing.T) { const layout = "2006-01-02 15:04:05.000000" - testTimeString := new(string) + testTimeString := "" // positive cases - *testTimeString = "" _, err := IsEmptyOrValidTimeStr(layout, testTimeString) assert.NoError(t, err) - *testTimeString = "2023-05-02 14:10:31.038289" + testTimeString = "2023-05-02 14:10:31.038289" _, err = IsEmptyOrValidTimeStr(layout, testTimeString) assert.NoError(t, err) // negative case - *testTimeString = "invalid time" + testTimeString = "invalid time" _, err = IsEmptyOrValidTimeStr(layout, testTimeString) assert.ErrorContains(t, err, "cannot parse") } diff --git a/vclusterops/vcluster_database_options.go b/vclusterops/vcluster_database_options.go index 463876b..25d103d 100644 --- a/vclusterops/vcluster_database_options.go +++ b/vclusterops/vcluster_database_options.go @@ -29,7 +29,7 @@ type DatabaseOptions struct { /* part 1: basic database info */ // name of the database - DBName *string + DBName string // expected to be IP addresses or hostnames RawHosts []string // expected to be IP addresses resolved from RawHosts @@ -37,27 +37,27 @@ type DatabaseOptions struct { // whether using IPv6 for host addresses IPv6 bool // path of catalog directory - CatalogPrefix *string + CatalogPrefix string // path of data directory - DataPrefix *string + DataPrefix string // File path to YAML config file ConfigPath string /* part 2: Eon database info */ // path of depot directory - DepotPrefix *string + DepotPrefix string // whether the database is in Eon mode IsEon bool // path of the communal storage - CommunalStorageLocation *string + CommunalStorageLocation string // database configuration parameters ConfigurationParameters map[string]string /* part 3: authentication info */ // user name - UserName *string + UserName string // password Password *string // TLS Key @@ -70,7 +70,7 @@ type DatabaseOptions struct { /* part 4: other info */ // path of the log file - LogPath *string + LogPath string // whether use password usePassword bool } @@ -112,42 +112,17 @@ func DatabaseOptionsFactory() DatabaseOptions { } func (opt *DatabaseOptions) setDefaultValues() { - opt.DBName = new(string) - opt.CatalogPrefix = new(string) - opt.DataPrefix = new(string) - opt.DepotPrefix = new(string) - opt.UserName = new(string) - opt.CommunalStorageLocation = new(string) opt.ConfigurationParameters = make(map[string]string) - opt.LogPath = new(string) -} - -func (opt *DatabaseOptions) checkNilPointerParams() error { - // basic params - if opt.DBName == nil { - return util.ParamNotSetErrorMsg("name") - } - if opt.CatalogPrefix == nil { - return util.ParamNotSetErrorMsg("catalog-path") - } - if opt.DataPrefix == nil { - return util.ParamNotSetErrorMsg("data-path") - } - if opt.DepotPrefix == nil { - return util.ParamNotSetErrorMsg("depot-path") - } - - return nil } func (opt *DatabaseOptions) validateBaseOptions(commandName string, log vlog.Printer) error { // get vcluster commands log.WithName(commandName) // database name - if *opt.DBName == "" { + if opt.DBName == "" { return fmt.Errorf("must specify a database name") } - err := util.ValidateDBName(*opt.DBName) + err := util.ValidateDBName(opt.DBName) if err != nil { return err } @@ -205,7 +180,6 @@ func (opt *DatabaseOptions) validateHostsAndPwd(commandName string, log vlog.Pri // validate catalog, data, and depot paths func (opt *DatabaseOptions) validatePaths(commandName string) error { // validate for the following commands only - // TODO: add other commands into the command list commands := []string{commandCreateDB, commandDropDB, commandConfigRecover} if !slices.Contains(commands, commandName) { return nil @@ -255,7 +229,7 @@ func (opt *DatabaseOptions) validateConfigDir(commandName string) error { return nil } - err := util.ValidateAbsPath(&opt.ConfigPath, "config") + err := util.ValidateAbsPath(opt.ConfigPath, "config") if err != nil { return err } @@ -264,14 +238,14 @@ func (opt *DatabaseOptions) validateConfigDir(commandName string) error { } func (opt *DatabaseOptions) validateUserName(log vlog.Printer) error { - if *opt.UserName == "" { + if opt.UserName == "" { username, err := util.GetCurrentUsername() if err != nil { return err } - *opt.UserName = username + opt.UserName = username } - log.Info("Current username", "username", *opt.UserName) + log.Info("Current username", "username", opt.UserName) return nil } @@ -295,9 +269,9 @@ func (opt *DatabaseOptions) setUsePassword(log vlog.Printer) error { // catalog, data and depot prefixes. func (opt *DatabaseOptions) normalizePaths() { // process correct catalog path, data path and depot path prefixes - *opt.CatalogPrefix = util.GetCleanPath(*opt.CatalogPrefix) - *opt.DataPrefix = util.GetCleanPath(*opt.DataPrefix) - *opt.DepotPrefix = util.GetCleanPath(*opt.DepotPrefix) + opt.CatalogPrefix = util.GetCleanPath(opt.CatalogPrefix) + opt.DataPrefix = util.GetCleanPath(opt.DataPrefix) + opt.DepotPrefix = util.GetCleanPath(opt.DepotPrefix) } // getVDBWhenDBIsDown can retrieve db configurations from NMA /nodes endpoint and cluster_config.json when db is down @@ -319,7 +293,7 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown(vcc VClusterCommands) (vdb VCoord vdb1 := VCoordinationDatabase{} var instructions1 []clusterOp nmaHealthOp := makeNMAHealthOp(opt.Hosts) - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(opt.Hosts, *opt.DBName, *opt.CatalogPrefix, + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(opt.Hosts, opt.DBName, opt.CatalogPrefix, false /* report all errors */, &vdb1) instructions1 = append(instructions1, &nmaHealthOp, @@ -382,7 +356,7 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown(vcc VClusterCommands) (vdb VCoord func (opt *DatabaseOptions) getCurrConfigFilePath() string { // description file will be in the location: {communal_storage_location}/metadata/{db_name}/cluster_config.json // an example: s3://tfminio/test_loc/metadata/test_db/cluster_config.json - descriptionFilePath := filepath.Join(*opt.CommunalStorageLocation, descriptionFileMetadataFolder, *opt.DBName, descriptionFileName) + descriptionFilePath := filepath.Join(opt.CommunalStorageLocation, descriptionFileMetadataFolder, opt.DBName, descriptionFileName) // filepath.Join() will change "://" of the remote communal storage path to ":/" // as a result, we need to change the separator back to url format descriptionFilePath = strings.Replace(descriptionFilePath, ":/", "://", 1) @@ -399,8 +373,8 @@ func (options *VReviveDatabaseOptions) getRestorePointConfigFilePath(validatedRe // description file will be in the location: // {communal_storage_location}/metadata/{db_name}/archives/{archive_name}/{restore_point_id}/cluster_config.json // an example: s3://tfminio/test_loc/metadata/test_db/archives/test_archive_name/2251e5cc-3e16-4fb1-8cd0-e4b8651f5779/cluster_config.json - descriptionFilePath := filepath.Join(*options.CommunalStorageLocation, descriptionFileMetadataFolder, - *options.DBName, archivesFolder, options.RestorePoint.Archive, validatedRestorePointID, descriptionFileName) + descriptionFilePath := filepath.Join(options.CommunalStorageLocation, descriptionFileMetadataFolder, + options.DBName, archivesFolder, options.RestorePoint.Archive, validatedRestorePointID, descriptionFileName) // filepath.Join() will change "://" of the remote communal storage path to ":/" // as a result, we need to change the separator back to url format descriptionFilePath = strings.Replace(descriptionFilePath, ":/", "://", 1) diff --git a/vclusterops/vcluster_database_options_test.go b/vclusterops/vcluster_database_options_test.go index d588025..fd560c0 100644 --- a/vclusterops/vcluster_database_options_test.go +++ b/vclusterops/vcluster_database_options_test.go @@ -23,27 +23,27 @@ import ( func TestGetDescriptionFilePath(t *testing.T) { opt := VReviveDBOptionsFactory() - *opt.DBName = "test_eon_db" + opt.DBName = "test_eon_db" // local communal storage: targetPath := "/communal/metadata/test_eon_db/cluster_config.json" // case 1: normal communal storage path - *opt.CommunalStorageLocation = "/communal" + opt.CommunalStorageLocation = "/communal" path := opt.getCurrConfigFilePath() assert.Equal(t, targetPath, path) // case 2: double-slash communal storage path - *opt.CommunalStorageLocation = "//communal" + opt.CommunalStorageLocation = "//communal" path = opt.getCurrConfigFilePath() assert.Equal(t, targetPath, path) // case 3: double-slash communal storage path followed by a slash - *opt.CommunalStorageLocation = "//communal/" + opt.CommunalStorageLocation = "//communal/" path = opt.getCurrConfigFilePath() assert.Equal(t, targetPath, path) // case 4: double-slash communal storage path followed by a double-slash - *opt.CommunalStorageLocation = "//communal//" + opt.CommunalStorageLocation = "//communal//" path = opt.getCurrConfigFilePath() assert.Equal(t, targetPath, path) @@ -51,17 +51,17 @@ func TestGetDescriptionFilePath(t *testing.T) { targetS3Path := "s3://vertica-fleeting/k8s/revive_eon_5/metadata/test_eon_db/cluster_config.json" targetGCPPath := "gs://vertica-fleeting/k8s/revive_eon_5/metadata/test_eon_db/cluster_config.json" // case 1 - normal s3 communal storage: - *opt.CommunalStorageLocation = "s3://vertica-fleeting/k8s/revive_eon_5" + opt.CommunalStorageLocation = "s3://vertica-fleeting/k8s/revive_eon_5" path = opt.getCurrConfigFilePath() assert.Equal(t, targetS3Path, path) // case 2: double-slash s3 communal storage path - *opt.CommunalStorageLocation = "s3://vertica-fleeting//k8s//revive_eon_5" + opt.CommunalStorageLocation = "s3://vertica-fleeting//k8s//revive_eon_5" path = opt.getCurrConfigFilePath() assert.Equal(t, targetS3Path, path) // case 3: other cloud communal storage paths like GCP - *opt.CommunalStorageLocation = "gs://vertica-fleeting/k8s/revive_eon_5" + opt.CommunalStorageLocation = "gs://vertica-fleeting/k8s/revive_eon_5" path = opt.getCurrConfigFilePath() assert.Equal(t, targetGCPPath, path) }