Skip to content

Commit

Permalink
Sync from server repo (99aa32b4094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Apr 1, 2024
1 parent 045acf3 commit a64507c
Show file tree
Hide file tree
Showing 22 changed files with 618 additions and 34 deletions.
4 changes: 4 additions & 0 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const (
verboseKey = "verbose"
outputFileFlag = "output-file"
outputFileKey = "outputFile"
subclusterFlag = "subcluster"
sandboxFlag = "sandbox"
)

// flags to viper key map
Expand Down Expand Up @@ -111,6 +113,7 @@ const (
dropDBSubCmd = "drop_db"
addSCSubCmd = "db_add_subcluster"
removeSCSubCmd = "db_remove_subcluster"
stopSCSubCmd = "stop_subcluster"
addNodeSubCmd = "db_add_node"
removeNodeSubCmd = "db_remove_node"
restartNodeSubCmd = "restart_node"
Expand Down Expand Up @@ -403,6 +406,7 @@ func constructCmds() []*cobra.Command {
// sc-scope cmds
makeCmdAddSubcluster(),
makeCmdRemoveSubcluster(),
makeCmdStopSubcluster(),
makeCmdSandboxSubcluster(),
makeCmdUnsandboxSubcluster(),
// node-scope cmds
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *CmdAddNode) setLocalFlags(cmd *cobra.Command) {
)
cmd.Flags().StringVar(
c.addNodeOptions.SCName,
"subcluster",
subclusterFlag,
"",
util.GetEonFlagMsg("The Name of subcluster"+
" to which the host(s) must be added. If empty default subcluster is considered"),
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Examples:
newCmd.setHiddenFlags(cmd)

// require name of subcluster to add
markFlagsRequired(cmd, []string{"subcluster"})
markFlagsRequired(cmd, []string{subclusterFlag})

return cmd
}
Expand All @@ -86,7 +86,7 @@ Examples:
func (c *CmdAddSubcluster) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
c.addSubclusterOptions.SCName,
"subcluster",
subclusterFlag,
"",
"The name of the new subcluster",
)
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_remove_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Examples:
newCmd.setLocalFlags(cmd)

// require name of subcluster to remove
markFlagsRequired(cmd, []string{"subcluster"})
markFlagsRequired(cmd, []string{subclusterFlag})

return cmd
}
Expand All @@ -77,7 +77,7 @@ Examples:
func (c *CmdRemoveSubcluster) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
c.removeScOptions.SubclusterToRemove,
"subcluster",
subclusterFlag,
"",
"Name of subcluster to be removed",
)
Expand Down
6 changes: 3 additions & 3 deletions commands/cmd_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Examples:
newCmd.setLocalFlags(cmd)

// require name of subcluster to sandbox as well as the sandbox name
markFlagsRequired(cmd, []string{"subcluster", "sandbox"})
markFlagsRequired(cmd, []string{subclusterFlag, sandboxFlag})

return cmd
}
Expand All @@ -88,13 +88,13 @@ Examples:
func (c *CmdSandboxSubcluster) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
c.sbOptions.SCName,
"subcluster",
subclusterFlag,
"",
"The name of the subcluster to be sandboxed",
)
cmd.Flags().StringVar(
c.sbOptions.SandboxName,
"sandbox",
sandboxFlag,
"",
"The name of the sandbox",
)
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_stop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *CmdStopDB) setLocalFlags(cmd *cobra.Command) {
)
cmd.Flags().StringVar(
c.stopDBOptions.Sandbox,
"sandbox",
sandboxFlag,
"",
"Name of the sandbox to stop",
)
Expand Down
163 changes: 163 additions & 0 deletions commands/cmd_stop_subcluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
(c) Copyright [2023-2024] Open Text.
Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package commands

import (
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdStopSubcluster
*
* Parses arguments to StopSubcluster and calls
* the high-level function for StopSubcluster.
*
* Implements ClusterCommand interface
*/

type CmdStopSubcluster struct {
CmdBase
stopSCOptions *vclusterops.VStopSubclusterOptions
}

func makeCmdStopSubcluster() *cobra.Command {
newCmd := &CmdStopSubcluster{}
opt := vclusterops.VStopSubclusterOptionsFactory()
newCmd.stopSCOptions = &opt

cmd := makeBasicCobraCmd(
newCmd,
stopSCSubCmd,
"Stop a subcluster",
`This subcommand stops a subcluster from an existing Eon Mode database.
You must provide the subcluster name with the --subcluster option.
All hosts in the subcluster will be stopped. You cannot stop a sandboxed
subcluster.
Examples:
# Gracefully stop a subcluster with config file
vcluster stop_subcluster --subcluster sc1 --drain-seconds 10 \
--config /opt/vertica/config/vertica_cluster.yaml
# Forcibly stop a subcluster with config file
vcluster stop_subcluster --subcluster sc1 --force \
--config /opt/vertica/config/vertica_cluster.yaml
# Gracefully stop a subcluster with user input
vcluster stop_subcluster --db-name test_db --subcluster sc1 \
--hosts 10.20.30.40,10.20.30.41,10.20.30.42 --drain-seconds 10
# Forcibly stop a subcluster with user input
vcluster stop_subcluster --db-name test_db --subcluster sc1 \
--hosts 10.20.30.40,10.20.30.41,10.20.30.42 --force
`,
[]string{dbNameFlag, hostsFlag, ipv6Flag, eonModeFlag, configFlag, passwordFlag},
)

// local flags
newCmd.setLocalFlags(cmd)

// require name of subcluster to add
markFlagsRequired(cmd, []string{subclusterFlag})

// hide eon mode flag since we expect it to come from config file, not from user input
hideLocalFlags(cmd, []string{eonModeFlag})

return cmd
}

// setLocalFlags will set the local flags the command has
func (c *CmdStopSubcluster) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().IntVar(
&c.stopSCOptions.DrainSeconds,
"drain-seconds",
util.DefaultDrainSeconds,
util.GetEonFlagMsg("seconds to wait for user connections to close."+
" Default value is "+strconv.Itoa(util.DefaultDrainSeconds)+" seconds."+
" When the time expires, connections will be forcibly closed and the subcluster will shut down."+
" If the value is 0, VCluster closes all user connections immediately."+
" If the value is negative, VCluster waits indefinitely until all user sessions disconnect"),
)
cmd.Flags().StringVar(
&c.stopSCOptions.SCName,
subclusterFlag,
"",
"The name of the target subcluster",
)
cmd.Flags().BoolVar(
&c.stopSCOptions.Force,
"force",
false,
"Force the subcluster to shutdown immediately even if users are connected",
)
cmd.MarkFlagsMutuallyExclusive("drain-seconds", "force")
}

func (c *CmdStopSubcluster) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogArgParse(&c.argv)

// reset some options that are not included in user input
c.ResetUserInputOptions(&c.stopSCOptions.DatabaseOptions)

// stop_subcluster only works for an Eon db so we assume the user always runs this subcommand
// on an Eon db. When Eon mode cannot be found in config file, we set its value to true.
if !viper.IsSet(eonModeKey) {
c.stopSCOptions.IsEon = true
}

return c.validateParse(logger)
}

func (c *CmdStopSubcluster) validateParse(logger vlog.Printer) error {
logger.Info("Called validateParse()")
err := c.getCertFilesFromCertPaths(&c.stopSCOptions.DatabaseOptions)
if err != nil {
return err
}

err = c.ValidateParseBaseOptions(&c.stopSCOptions.DatabaseOptions)
if err != nil {
return err
}
return c.setDBPassword(&c.stopSCOptions.DatabaseOptions)
}

func (c *CmdStopSubcluster) Run(vcc vclusterops.ClusterCommands) error {
vcc.LogInfo("Called method Run()")

options := c.stopSCOptions

err := vcc.VStopSubcluster(options)
if err != nil {
vcc.LogError(err, "failed to stop the subcluster", "Subcluster", options.SCName)
return err
}
vcc.PrintInfo("Successfully stopped subcluster %s", options.SCName)
return nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdStopSubcluster
func (c *CmdStopSubcluster) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
c.stopSCOptions.DatabaseOptions = *opt
}
4 changes: 2 additions & 2 deletions commands/cmd_unsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Examples:
newCmd.setLocalFlags(cmd)

// require name of subcluster to unsandbox
markFlagsRequired(cmd, []string{"subcluster"})
markFlagsRequired(cmd, []string{subclusterFlag})

return cmd
}
Expand All @@ -92,7 +92,7 @@ Examples:
func (c *CmdUnsandboxSubcluster) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
c.usOptions.SCName,
"subcluster",
subclusterFlag,
"",
"The name of the subcluster to be unsandboxed",
)
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (vcc VClusterCommands) prepareAdditionalEonInstructions(vdb *VCoordinationD
}

if vdb.IsEon {
httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(initiatorHost, true, username, options.Password)
httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(initiatorHost, true, username, options.Password, AddNodeSyncCat)
if err != nil {
return instructions, err
}
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (vcc *VClusterCommands) produceAddSubclusterInstructions(options *VAddSubcl

username := *options.UserName
httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(*options.DBName, options.Hosts,
options.usePassword, username, options.Password, DBAddSubclusterCmd)
options.usePassword, username, options.Password, AddSubclusterCmd)
if err != nil {
return instructions, err
}
Expand Down
1 change: 1 addition & 0 deletions vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ type ClusterCommands interface {
VStopDatabase(options *VStopDatabaseOptions) error
VFetchCoordinationDatabase(options *VFetchCoordinationDatabaseOptions) (VCoordinationDatabase, error)
VUnsandbox(options *VUnsandboxOptions) error
VStopSubcluster(options *VStopSubclusterOptions) error
}

type VClusterCommandsLogger struct {
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (vcc VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordina
}

if vdb.IsEon {
httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(bootstrapHost, true, username, options.Password)
httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(bootstrapHost, true, username, options.Password, CreateDBSyncCat)
if err != nil {
return instructions, err
}
Expand Down
Loading

0 comments on commit a64507c

Please sign in to comment.