Skip to content

Commit

Permalink
Sync from server repo (a2f8bd7b114)
Browse files Browse the repository at this point in the history
  • Loading branch information
releng committed Sep 13, 2024
1 parent 9abf223 commit 026df08
Show file tree
Hide file tree
Showing 29 changed files with 1,206 additions and 274 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

[![Go Reference](https://pkg.go.dev/badge/github.com/vertica/vcluster.svg)](https://pkg.go.dev/github.com/vertica/vcluster)

This repository contains the vcluster-ops Go library and command-line interface to administer a Vertica cluster with a REST API. The REST API endpoints are exposed by the following services:
This repository contains the vcluster-ops Go library and command-line
interface to administer a Vertica cluster with a REST API. The REST API
endpoints are exposed by the following services:
- Node Management Agent (NMA)
- Embedded HTTPS service

This CLI tool combines REST calls to provide a coherent Go interface so that you can perform the following administrator operations:
This CLI tool combines REST calls to provide a coherent Go interface so that
you can perform the following administrator operations:
- Create a database
- Scale a cluster up and down
- Restart a cluster
Expand Down Expand Up @@ -58,9 +61,14 @@ directories in this project.


## Usage
Each source file in `vclusterops/` contains a `V<Operation>Options` struct with option fields that you can set for that operation, and a `V<Operation>OptionsFactory` factory function that returns a struct with sensible option defaults. General database and authentication options are available in `DatabaseOptions` in `vclusterops/vcluster_database_options.go`.
Each source file in `vclusterops/` contains a `V<Operation>Options` struct
with option fields that you can set for that operation, and a `V<Operation>OptionsFactory`
factory function that returns a struct with sensible option defaults. General
database and authentication options are available in `DatabaseOptions` in
`vclusterops/vcluster_database_options.go`.

The following example imports the `vclusterops` library, and then calls functions from `vclusterops/create_db.go` to create a database:
The following example imports the `vclusterops` library, and then calls
functions from `vclusterops/create_db.go` to create a database:


```
Expand Down Expand Up @@ -94,4 +102,5 @@ We can use similar way to set up and call other vcluster-ops commands.


## Licensing
vcluster is open source code and is under the Apache 2.0 license. Please see `LICENSE` for details.
vcluster is open source and is under the Apache 2.0 license. Please see
`LICENSE` for details.
9 changes: 8 additions & 1 deletion commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const (
dataPathKey = "dataPath"
communalStorageLocationFlag = "communal-storage-location"
communalStorageLocationKey = "communalStorageLocation"
archiveNameFlag = "archive-name"
archiveNameKey = "archiveName"
ipv6Flag = "ipv6"
ipv6Key = "ipv6"
eonModeFlag = "eon-mode"
Expand Down Expand Up @@ -156,6 +158,7 @@ var flagKeyMap = map[string]string{
verboseFlag: verboseKey,
outputFileFlag: outputFileKey,
sandboxFlag: sandboxKey,
archiveNameFlag: archiveNameKey,
targetDBNameFlag: targetDBNameKey,
targetHostsFlag: targetHostsKey,
targetUserNameFlag: targetUserNameKey,
Expand Down Expand Up @@ -213,8 +216,10 @@ const (
showRestorePointsSubCmd = "show_restore_points"
installPkgSubCmd = "install_packages"
// hidden Cmds (for internal testing only)
getDrainingStatusSubCmd = "get_draining_status"
promoteSandboxSubCmd = "promote_sandbox"
createArchiveCmd = "create_archive"
saveRestorePointsSubCmd = "save_restore_point"
getDrainingStatusSubCmd = "get_draining_status"
)

// cmdGlobals holds global variables shared by multiple
Expand Down Expand Up @@ -580,6 +585,8 @@ func constructCmds() []*cobra.Command {
// hidden cmds (for internal testing only)
makeCmdGetDrainingStatus(),
makeCmdPromoteSandbox(),
makeCmdCreateArchive(),
makeCmdSaveRestorePoint(),
}
}

Expand Down
176 changes: 176 additions & 0 deletions commands/cmd_create_archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
(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/spf13/viper"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdCreateArchive
*
* Parses arguments to create-archive and calls
* the high-level function for create-archive.
*
* Implements ClusterCommand interface
*/

type CmdCreateArchive struct {
CmdBase
createArchiveOptions *vclusterops.VCreateArchiveOptions
}

func makeCmdCreateArchive() *cobra.Command {
newCmd := &CmdCreateArchive{}
opt := vclusterops.VCreateArchiveFactory()
newCmd.createArchiveOptions = &opt

cmd := makeBasicCobraCmd(
newCmd,
createArchiveCmd,
"Create an archive in a given archive name and number.",
`Create an archive in a given archive name and number.
Examples:
# Create an archive in a given archive name
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE
# Create an archive in a given archive name and number of restore point(default 3)
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE \
--num-restore-points 6
# Create an archive in main cluster with user input password
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE \
--hosts 10.20.30.40,10.20.30.41,10.20.30.42 --password "PASSWORD"
# Create an archive for a sandbox
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE \
--sandbox SANDBOX_ONE --password "PASSWORD"
`,
[]string{dbNameFlag, configFlag, passwordFlag,
hostsFlag, ipv6Flag, eonModeFlag},
)

// local flags
newCmd.setLocalFlags(cmd)

// require archive-name
markFlagsRequired(cmd, archiveNameFlag)

// hide this subcommand
cmd.Hidden = true

return cmd
}

// setLocalFlags will set the local flags the command has
func (c *CmdCreateArchive) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&c.createArchiveOptions.ArchiveName,
archiveNameFlag,
"",
"The name of archive to be created.",
)
cmd.Flags().IntVar(
&c.createArchiveOptions.NumRestorePoint,
"num-restore-points",
vclusterops.CreateArchiveDefaultNumRestore,
"Maximum number of restore points that archive can contain."+
"If you provide 0, the number of restore points will be unlimited. "+
"By default, the value is 0. Negative number is disallowed.",
)
cmd.Flags().StringVar(
&c.createArchiveOptions.Sandbox,
sandboxFlag,
"",
"The name of target sandbox",
)
}

func (c *CmdCreateArchive) 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.createArchiveOptions.DatabaseOptions)

// create_archive 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.createArchiveOptions.IsEon = true
}

return c.validateParse(logger)
}

// all validations of the arguments should go in here
func (c *CmdCreateArchive) validateParse(logger vlog.Printer) error {
logger.Info("Called validateParse()")

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

err = c.setConfigParam(&c.createArchiveOptions.DatabaseOptions)
if err != nil {
return err
}

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

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

return nil
}

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

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

options := c.createArchiveOptions

err := vcc.VCreateArchive(options)
if err != nil {
vcc.LogError(err, "failed to create archive", "archiveName", options.ArchiveName)
return err
}

vcc.DisplayInfo("Successfully created archive: %s", options.ArchiveName)
return nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdCreateArchive
func (c *CmdCreateArchive) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
c.createArchiveOptions.DatabaseOptions = *opt
}
1 change: 0 additions & 1 deletion commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func (c *CmdCreateDB) Run(vcc vclusterops.ClusterCommands) error {
vcc.V(1).Info("Called method Run()")
vdb, createError := vcc.VCreateDatabase(c.createDBOptions)
if createError != nil {
vcc.LogError(createError, "Failed to create the database.")
return createError
}

Expand Down
Loading

0 comments on commit 026df08

Please sign in to comment.