Skip to content

Commit

Permalink
Sync from server repo (e5ae7a99bb3)
Browse files Browse the repository at this point in the history
  • Loading branch information
releng committed Aug 22, 2024
1 parent 7aac987 commit f7f0c36
Show file tree
Hide file tree
Showing 58 changed files with 1,101 additions and 268 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
# When changing this, be sure to update the version at:
# vertica/make/build-container/*Dockerfile
go-version: "1.20.13"
go-version: "1.22.5"

- name: Run unit tests
run: make vet lint test
Expand Down
21 changes: 18 additions & 3 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,18 @@ const (
targetPasswordFileKey = "targetPasswordFile"
targetConnFlag = "target-conn"
targetConnKey = "targetConn"
asyncFlag = "async"
asyncKey = "async"
sourceTLSConfigFlag = "source-tlsconfig"
sourceTLSConfigKey = "sourceTLSConfig"
tableOrSchemaNameFlag = "table-or-schema-name"
tableOrSchemaNameKey = "tableOrSchemaName"
includePatternFlag = "include-pattern"
includePatternKey = "includePattern"
excludePatternFlag = "exclude-pattern"
excludePatternKey = "excludePattern"
targetNamespaceFlag = "target-namespace"
targetNamespaceKey = "targetNamespace"
)

// flags to viper key map
Expand Down Expand Up @@ -150,7 +160,12 @@ var flagKeyMap = map[string]string{
targetHostsFlag: targetHostsKey,
targetUserNameFlag: targetUserNameKey,
targetPasswordFileFlag: targetPasswordFileKey,
asyncFlag: asyncKey,
sourceTLSConfigFlag: sourceTLSConfigKey,
tableOrSchemaNameFlag: tableOrSchemaNameKey,
includePatternFlag: includePatternKey,
excludePatternFlag: excludePatternKey,
targetNamespaceFlag: targetNamespaceKey,
}

// target database flags to viper key map
Expand Down Expand Up @@ -198,7 +213,8 @@ const (
showRestorePointsSubCmd = "show_restore_points"
installPkgSubCmd = "install_packages"
// hidden Cmds (for internal testing only)
promoteSandboxSubCmd = "promote_sandbox"
getDrainingStatusSubCmd = "get_draining_status"
promoteSandboxSubCmd = "promote_sandbox"
)

// cmdGlobals holds global variables shared by multiple
Expand Down Expand Up @@ -562,9 +578,8 @@ func constructCmds() []*cobra.Command {
makeCmdReplication(),
makeCmdCreateConnection(),
// hidden cmds (for internal testing only)
makeCmdGetDrainingStatus(),
makeCmdPromoteSandbox(),

makeCmdCheckVClusterServerPid(),
}
}

Expand Down
4 changes: 1 addition & 3 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ func (c *CmdAddNode) setLocalFlags(cmd *cobra.Command) {
&c.addNodeOptions.DepotSize,
"depot-size",
"",
util.GetEonFlagMsg("Size of depot in one of the following formats:\n"+
"integer{K|M|G|T}, where K is kilobytes, M is megabytes, G is gigabytes, and T is terabytes.\n"+
"integer%, which expresses the depot size as a percentage of the total disk size."),
util.GetEonFlagMsg(util.DepotFmtMsg+util.DepotSizeKMGTMsg+util.DepotSizeHint),
)
cmd.Flags().StringVar(
&c.nodeNameListStr,
Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ func (c *CmdAddSubcluster) setLocalFlags(cmd *cobra.Command) {
&c.addSubclusterOptions.DepotSize,
"depot-size",
"",
util.GetEonFlagMsg("Size of depot in one of the following formats:\n"+
"integer{K|M|G|T}, where K is kilobytes, M is megabytes, G is gigabytes, and T is terabytes.\n"+
util.GetEonFlagMsg(util.DepotFmtMsg+util.DepotSizeKMGTMsg+
"integer%, which expresses the depot size as a percentage of the total disk size.\n"),
)
}
Expand Down
86 changes: 0 additions & 86 deletions commands/cmd_check_vcluster_server_pid.go

This file was deleted.

4 changes: 1 addition & 3 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ func (c *CmdCreateDB) setLocalFlags(cmd *cobra.Command) {
&c.createDBOptions.DepotSize,
"depot-size",
"",
util.GetEonFlagMsg("Size of depot in one of the following formats:\n"+
"integer {K|M|G|T}, where K is kilobytes, M is megabytes, G is gigabytes, and T is terabytes.\n"+
"integer%, which expresses the depot size as a percentage of the total disk size."),
util.GetEonFlagMsg(util.DepotFmtMsg+util.DepotSizeKMGTMsg+util.DepotSizeHint),
)
cmd.Flags().BoolVar(
&c.createDBOptions.GetAwsCredentialsFromEnv,
Expand Down
159 changes: 159 additions & 0 deletions commands/cmd_get_draining_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
(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.
DISCLAIMER:
The subcommand (get_draining_status) within this file is intended solely for internal testing purposes.
It is not designed, intended, or authorized for use in production environments. The behavior of this
subcommand may change without prior notice and is not guaranteed to be maintained in future releases.
*/

package commands

import (
"encoding/json"

"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"
)

/* CmdGetDrainingStatus
*
* Implements ClusterCommand interface
*/
type CmdGetDrainingStatus struct {
CmdBase
getDrainingStatusOpt *vclusterops.VGetDrainingStatusOptions
}

func makeCmdGetDrainingStatus() *cobra.Command {
// CmdGetDrainingStatus
newCmd := &CmdGetDrainingStatus{}
opt := vclusterops.VGetDrainingStatusFactory()
newCmd.getDrainingStatusOpt = &opt

cmd := makeBasicCobraCmd(
newCmd,
getDrainingStatusSubCmd,
"Get draining status.",
`Get draining status.
Examples:
# Show draining status of all subclusters in main cluster with user input
vcluster get_draining_status --db-name test_db \
--hosts 10.20.30.40,10.20.30.41,10.20.30.42
# Show draining status of all subclusters in main cluster with config file
vcluster get_draining_status \
--config /opt/vertica/config/vertica_cluster.yaml
# Show draining status of all subclusters in a sandbox with config file
vcluster get_draining_status --sandbox sand1 \
--config /opt/vertica/config/vertica_cluster.yaml
`,
[]string{dbNameFlag, configFlag, passwordFlag, hostsFlag, ipv6Flag, sandboxFlag,
eonModeFlag, outputFileFlag},
)

// local flags
newCmd.setLocalFlags(cmd)

// hide this subcommand
cmd.Hidden = true

return cmd
}

// setLocalFlags will set the local flags the command has
func (c *CmdGetDrainingStatus) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&c.getDrainingStatusOpt.Sandbox,
sandboxFlag,
"",
"The name of target sandbox",
)
}

func (c *CmdGetDrainingStatus) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogMaskedArgParse(c.argv)

// for some options, we do not want to use their default values,
// if they are not provided in cli,
// reset the value of those options to nil
c.ResetUserInputOptions(&c.getDrainingStatusOpt.DatabaseOptions)

// get_draining_status 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.getDrainingStatusOpt.IsEon = true
}

return c.validateParse(logger)
}

func (c *CmdGetDrainingStatus) validateParse(logger vlog.Printer) error {
logger.Info("Called validateParse()")

if !c.usePassword() {
err := c.getCertFilesFromCertPaths(&c.getDrainingStatusOpt.DatabaseOptions)
if err != nil {
return err
}
}

err := c.ValidateParseBaseOptions(&c.getDrainingStatusOpt.DatabaseOptions)
if err != nil {
return err
}

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

func (c *CmdGetDrainingStatus) Analyze(logger vlog.Printer) error {
logger.Info("Called method Analyze()")
return nil
}

func (c *CmdGetDrainingStatus) Run(vcc vclusterops.ClusterCommands) error {
vcc.V(1).Info("Called method Run()")

options := c.getDrainingStatusOpt

drainingStatusList, err := vcc.VGetDrainingStatus(options)
if err != nil {
vcc.LogError(err, "failed to get draining status list", "cluster", util.GetClusterName(options.Sandbox))
return err
}
bytes, err := json.MarshalIndent(drainingStatusList, "", " ")
if err != nil {
return err
}
bytes = append(bytes, '\n')
c.writeCmdOutputToFile(globals.file, bytes, vcc.GetLog())

vcc.DisplayInfo("Successfully displayed draining status list for %s", util.GetClusterName(options.Sandbox))
return nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdGetDrainingStatus
func (c *CmdGetDrainingStatus) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
c.getDrainingStatusOpt.DatabaseOptions = *opt
}
14 changes: 12 additions & 2 deletions commands/cmd_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package commands
import (
"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
)

Expand Down Expand Up @@ -155,7 +156,7 @@ func (c *CmdSandboxSubcluster) Analyze(logger vlog.Printer) error {
}

func (c *CmdSandboxSubcluster) Run(vcc vclusterops.ClusterCommands) error {
vcc.LogInfo("Calling method Run() for command " + sandboxSubCmd)
vcc.LogInfo(util.CallCommand + sandboxSubCmd)

options := c.sbOptions

Expand All @@ -182,9 +183,18 @@ func (c *CmdSandboxSubcluster) Run(vcc vclusterops.ClusterCommands) error {

writeErr := dbConfig.write(options.ConfigPath, true /*forceOverwrite*/)
if writeErr != nil {
vcc.DisplayWarning("Failed to write the configuration file: " + writeErr.Error())
vcc.DisplayWarning(util.FailToWriteToConfig + writeErr.Error())
return nil
}

options.DatabaseOptions.Hosts = options.SCHosts
pollOpts := vclusterops.VPollSubclusterStateOptions{DatabaseOptions: options.DatabaseOptions,
SkipOptionsValidation: true, SCName: options.SCName}
err = vcc.VPollSubclusterState(&pollOpts)
if err != nil {
vcc.LogError(err, "Failed to wait for sandboxed subcluster to come up")
return err
}
return nil
}

Expand Down
Loading

0 comments on commit f7f0c36

Please sign in to comment.