Skip to content

Commit

Permalink
Sync from server repo (9416716a171)
Browse files Browse the repository at this point in the history
  • Loading branch information
releng committed Dec 11, 2024
1 parent cf50448 commit 0b1e7d9
Show file tree
Hide file tree
Showing 32 changed files with 1,196 additions and 90 deletions.
5 changes: 5 additions & 0 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ const (
archiveNameKey = "archiveName"
ipv6Flag = "ipv6"
ipv6Key = "ipv6"
enableTLSAuthFlag = "enable-tls-authentication"
eonModeFlag = "eon-mode"
eonModeKey = "eonMode"
configParamFlag = "config-param"
configParamKey = "configParam"
configParamFileFlag = "config-param-file"
configParamFileKey = "configParamFile"
licenseFileFlag = "license-file"
licenseHostFlag = "license-host"
logPathFlag = "log-path"
logPathKey = "logPath"
keyFileFlag = "key-file"
Expand Down Expand Up @@ -245,6 +248,7 @@ const (
createArchiveCmd = "create_archive"
saveRestorePointsSubCmd = "save_restore_point"
getDrainingStatusSubCmd = "get_draining_status"
upgradeLicenseCmd = "upgrade_license"
)

// cmdGlobals holds global variables shared by multiple
Expand Down Expand Up @@ -630,6 +634,7 @@ func constructCmds() []*cobra.Command {
makeCmdPromoteSandbox(),
makeCmdCreateArchive(),
makeCmdSaveRestorePoint(),
makeCmdUpgradeLicense(),
}
}

Expand Down
6 changes: 6 additions & 0 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ func (c *CmdCreateDB) setLocalFlags(cmd *cobra.Command) {
util.GetEnvInt("NODE_STATE_POLLING_TIMEOUT", util.DefaultTimeoutSeconds),
"The time, in seconds, to wait for the nodes to start after database creation (default: 300).",
)
cmd.Flags().BoolVar(
&c.createDBOptions.EnableTLSAuth,
enableTLSAuthFlag,
false,
"Enable TLS authentication for all users after database creation",
)
c.setSpreadlFlags(cmd)
}

Expand Down
10 changes: 8 additions & 2 deletions commands/cmd_re_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ This file should only include the IP addresses of nodes that you want to update.
Examples:
# Alter the IP address of database nodes with user input
vcluster re_ip --db-name test_db --hosts 10.20.30.40,10.20.30.41,10.20.30.42 \
--catalog-path /data --re-ip-file /data/re_ip_map.json \
--catalog-path /data --re-ip-file /data/re_ip_map.json --sandbox sand \
--password "PASSWORD"
# Alter the IP address of database nodes with config file
vcluster re_ip --db-name test_db --re-ip-file /data/re_ip_map.json \
--config /opt/vertica/config/vertica_cluster.yaml \
--password "PASSWORD"
`,
[]string{dbNameFlag, hostsFlag, ipv6Flag, catalogPathFlag, configParamFlag, configFlag},
[]string{dbNameFlag, hostsFlag, ipv6Flag, catalogPathFlag, configParamFlag, configFlag, sandboxFlag},
)

// local flags
Expand All @@ -88,6 +88,12 @@ func (c *CmdReIP) setLocalFlags(cmd *cobra.Command) {
"",
"Path of the re-ip file",
)
cmd.Flags().StringVar(
&c.reIPOptions.SandboxName,
sandboxFlag,
"",
"The name of the sandbox. Required if the re-ip hosts are in a sandbox.",
)
}

func (c *CmdReIP) Parse(inputArgv []string, logger vlog.Printer) error {
Expand Down
142 changes: 142 additions & 0 deletions commands/cmd_upgrade_license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
(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 (
"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdUpgradeLicense
*
* Parses arguments to upgrade-license and calls
* the high-level function for upgrade-license.
*
* Implements ClusterCommand interface
*/

type CmdUpgradeLicense struct {
CmdBase
upgradeLicenseOptions *vclusterops.VUpgradeLicenseOptions
}

func makeCmdUpgradeLicense() *cobra.Command {
newCmd := &CmdUpgradeLicense{}
opt := vclusterops.VUpgradeLicenseFactory()
newCmd.upgradeLicenseOptions = &opt

cmd := makeBasicCobraCmd(
newCmd,
upgradeLicenseCmd,
"Upgrade license.",
`Upgrade license.
Examples:
# Upgrade license
vcluster upgrade_license --license-file LICENSE_FILE --license-host HOST_OF_LICENSE_FILE
# Upgrade license with connecting using database password
vcluster upgrade_license --license-file LICENSE_FILE --license-host HOST_OF_LICENSE_FILE --password "PASSWORD"
`,
[]string{dbNameFlag, configFlag, passwordFlag,
hostsFlag, ipv6Flag},
)

// local flags
newCmd.setLocalFlags(cmd)

// require license file path
markFlagsRequired(cmd, licenseFileFlag)
markFlagsRequired(cmd, licenseHostFlag)

return cmd
}

// setLocalFlags will set the local flags the command has
func (c *CmdUpgradeLicense) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&c.upgradeLicenseOptions.LicenseFilePath,
licenseFileFlag,
"",
"Absolute path of the license file.",
)
cmd.Flags().StringVar(
&c.upgradeLicenseOptions.LicenseHost,
licenseHostFlag,
"",
"The host the license file located on.",
)
}

func (c *CmdUpgradeLicense) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
logger.LogArgParse(&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.upgradeLicenseOptions.DatabaseOptions)

return c.validateParse(logger)
}

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

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

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

return nil
}

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

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

options := c.upgradeLicenseOptions

err := vcc.VUpgradeLicense(options)
if err != nil {
vcc.LogError(err, "failed to upgrade license", "license file", options.LicenseFilePath)
return err
}

vcc.DisplayInfo("Successfully upgraded license: %s", options.LicenseFilePath)
return nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdUpgradeLicense
func (c *CmdUpgradeLicense) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
c.upgradeLicenseOptions.DatabaseOptions = *opt
}
16 changes: 16 additions & 0 deletions commands/user_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vertica/vcluster/vclusterops"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -90,6 +91,21 @@ func TestManageReplication(t *testing.T) {
assert.ErrorContains(t, err, `unknown command "test" for "vcluster replication start"`)
}

func TestAsyncReplicationErrorMessage(t *testing.T) {
vcommand := vclusterops.VClusterCommands{}
replicationDatabaseOptions := vclusterops.VReplicationDatabaseFactory()
replicationDatabaseOptions.DBName = "db"
replicationDatabaseOptions.Hosts = []string{"12.34.56.78"}
replicationDatabaseOptions.IsEon = true
password := "password"
replicationDatabaseOptions.Password = &password
replicationDatabaseOptions.TargetDB.Hosts = []string{"23.45.67.89"}
replicationDatabaseOptions.TargetDB.DBName = "targetDb"
replicationDatabaseOptions.TableOrSchemaName = ".ns1.s1.*"
_, err := vcommand.VReplicateDatabase(&replicationDatabaseOptions)
assert.ErrorContains(t, err, "not allowed in --table-or-schema-name. HINT:")
}

func TestCreateConnectionFileWrongFileType(t *testing.T) {
// vertica_connection.txt will not be created and a unique name is not required
var tempConnFilePath = filepath.Join(os.TempDir(), "vertica_connection.txt")
Expand Down
12 changes: 12 additions & 0 deletions vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ func (hostResult *hostHTTPResult) isEOF() bool {
return hostResult.status == EOFEXCEPTION
}

// process a single result, return the error in the result
func (hostResult *hostHTTPResult) getError(host, opName string) error {
if hostResult.isUnauthorizedRequest() {
return fmt.Errorf("[%s] wrong password/certificates for https service on host %s", opName, host)
}
if !hostResult.isPassing() {
return hostResult.err
}
return nil
}

// getStatusString converts ResultStatus to string
func (status resultStatus) getStatusString() string {
if status == FAILURE {
Expand Down Expand Up @@ -601,6 +612,7 @@ type ClusterCommands interface {
VStopNode(options *VStopNodeOptions) error
VStopSubcluster(options *VStopSubclusterOptions) error
VUnsandbox(options *VUnsandboxOptions) error
VUpgradeLicense(options *VUpgradeLicenseOptions) error
}

type VClusterCommandsLogger struct {
Expand Down
1 change: 1 addition & 0 deletions vclusterops/cluster_op_engine_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type opEngineExecContext struct {
networkProfiles map[string]networkProfile
nmaVDatabase nmaVDatabase
upHosts []string // a sorted host list that contains all up nodes
computeHosts []string // a sorted host list that contains all up (COMPUTE) compute nodes
nodesInfo []NodeInfo
scNodesInfo []NodeInfo // a node list contains all nodes in a subcluster

Expand Down
2 changes: 2 additions & 0 deletions vclusterops/cmd_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
RemoveNodeSyncCat
CreateArchiveCmd
PollSubclusterStateCmd
UpgradeLicenseCmd
)

var cmdStringMap = map[CmdType]string{
Expand Down Expand Up @@ -84,6 +85,7 @@ var cmdStringMap = map[CmdType]string{
RemoveNodeSyncCat: "remove_node_sync_cat",
CreateArchiveCmd: "create_archive",
PollSubclusterStateCmd: "poll_subcluster_state",
UpgradeLicenseCmd: "upgrade_license",
}

func (cmd CmdType) CmdString() string {
Expand Down
Loading

0 comments on commit 0b1e7d9

Please sign in to comment.