Skip to content

Commit cfdf15c

Browse files
author
releng
committed
Sync from server repo (a52b42ec26d)
1 parent 9abf223 commit cfdf15c

28 files changed

+1205
-273
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

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

5-
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:
5+
This repository contains the vcluster-ops Go library and command-line
6+
interface to administer a Vertica cluster with a REST API. The REST API
7+
endpoints are exposed by the following services:
68
- Node Management Agent (NMA)
79
- Embedded HTTPS service
810

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

5962

6063
## Usage
61-
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`.
64+
Each source file in `vclusterops/` contains a `V<Operation>Options` struct
65+
with option fields that you can set for that operation, and a `V<Operation>OptionsFactory`
66+
factory function that returns a struct with sensible option defaults. General
67+
database and authentication options are available in `DatabaseOptions` in
68+
`vclusterops/vcluster_database_options.go`.
6269

63-
The following example imports the `vclusterops` library, and then calls functions from `vclusterops/create_db.go` to create a database:
70+
The following example imports the `vclusterops` library, and then calls
71+
functions from `vclusterops/create_db.go` to create a database:
6472

6573

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

95103

96104
## Licensing
97-
vcluster is open source code and is under the Apache 2.0 license. Please see `LICENSE` for details.
105+
vcluster is open source and is under the Apache 2.0 license. Please see
106+
`LICENSE` for details.

commands/cluster_command_launcher.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const (
5959
dataPathKey = "dataPath"
6060
communalStorageLocationFlag = "communal-storage-location"
6161
communalStorageLocationKey = "communalStorageLocation"
62+
archiveNameFlag = "archive-name"
63+
archiveNameKey = "archiveName"
6264
ipv6Flag = "ipv6"
6365
ipv6Key = "ipv6"
6466
eonModeFlag = "eon-mode"
@@ -156,6 +158,7 @@ var flagKeyMap = map[string]string{
156158
verboseFlag: verboseKey,
157159
outputFileFlag: outputFileKey,
158160
sandboxFlag: sandboxKey,
161+
archiveNameFlag: archiveNameKey,
159162
targetDBNameFlag: targetDBNameKey,
160163
targetHostsFlag: targetHostsKey,
161164
targetUserNameFlag: targetUserNameKey,
@@ -213,8 +216,10 @@ const (
213216
showRestorePointsSubCmd = "show_restore_points"
214217
installPkgSubCmd = "install_packages"
215218
// hidden Cmds (for internal testing only)
216-
getDrainingStatusSubCmd = "get_draining_status"
217219
promoteSandboxSubCmd = "promote_sandbox"
220+
createArchiveCmd = "create_archive"
221+
saveRestorePointsSubCmd = "save_restore_point"
222+
getDrainingStatusSubCmd = "get_draining_status"
218223
)
219224

220225
// cmdGlobals holds global variables shared by multiple
@@ -580,6 +585,8 @@ func constructCmds() []*cobra.Command {
580585
// hidden cmds (for internal testing only)
581586
makeCmdGetDrainingStatus(),
582587
makeCmdPromoteSandbox(),
588+
makeCmdCreateArchive(),
589+
makeCmdSaveRestorePoint(),
583590
}
584591
}
585592

commands/cmd_create_archive.go

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
(c) Copyright [2023-2024] Open Text.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
You may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package commands
17+
18+
import (
19+
"github.com/spf13/cobra"
20+
"github.com/spf13/viper"
21+
"github.com/vertica/vcluster/vclusterops"
22+
"github.com/vertica/vcluster/vclusterops/vlog"
23+
)
24+
25+
/* CmdCreateArchive
26+
*
27+
* Parses arguments to create-archive and calls
28+
* the high-level function for create-archive.
29+
*
30+
* Implements ClusterCommand interface
31+
*/
32+
33+
type CmdCreateArchive struct {
34+
CmdBase
35+
createArchiveOptions *vclusterops.VCreateArchiveOptions
36+
}
37+
38+
func makeCmdCreateArchive() *cobra.Command {
39+
newCmd := &CmdCreateArchive{}
40+
opt := vclusterops.VCreateArchiveFactory()
41+
newCmd.createArchiveOptions = &opt
42+
43+
cmd := makeBasicCobraCmd(
44+
newCmd,
45+
createArchiveCmd,
46+
"Create an archive in a given archive name and number.",
47+
`Create an archive in a given archive name and number.
48+
49+
Examples:
50+
# Create an archive in a given archive name
51+
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE
52+
53+
# Create an archive in a given archive name and number of restore point(default 3)
54+
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE \
55+
--num-restore-points 6
56+
57+
# Create an archive in main cluster with user input password
58+
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE \
59+
--hosts 10.20.30.40,10.20.30.41,10.20.30.42 --password "PASSWORD"
60+
61+
# Create an archive for a sandbox
62+
vcluster create_archive --db-name DBNAME --archive-name ARCHIVE_ONE \
63+
--sandbox SANDBOX_ONE --password "PASSWORD"
64+
65+
`,
66+
[]string{dbNameFlag, configFlag, passwordFlag,
67+
hostsFlag, ipv6Flag, eonModeFlag},
68+
)
69+
70+
// local flags
71+
newCmd.setLocalFlags(cmd)
72+
73+
// require archive-name
74+
markFlagsRequired(cmd, archiveNameFlag)
75+
76+
// hide this subcommand
77+
cmd.Hidden = true
78+
79+
return cmd
80+
}
81+
82+
// setLocalFlags will set the local flags the command has
83+
func (c *CmdCreateArchive) setLocalFlags(cmd *cobra.Command) {
84+
cmd.Flags().StringVar(
85+
&c.createArchiveOptions.ArchiveName,
86+
archiveNameFlag,
87+
"",
88+
"The name of archive to be created.",
89+
)
90+
cmd.Flags().IntVar(
91+
&c.createArchiveOptions.NumRestorePoint,
92+
"num-restore-points",
93+
vclusterops.CreateArchiveDefaultNumRestore,
94+
"Maximum number of restore points that archive can contain."+
95+
"If you provide 0, the number of restore points will be unlimited. "+
96+
"By default, the value is 0. Negative number is disallowed.",
97+
)
98+
cmd.Flags().StringVar(
99+
&c.createArchiveOptions.Sandbox,
100+
sandboxFlag,
101+
"",
102+
"The name of target sandbox",
103+
)
104+
}
105+
106+
func (c *CmdCreateArchive) Parse(inputArgv []string, logger vlog.Printer) error {
107+
c.argv = inputArgv
108+
logger.LogArgParse(&c.argv)
109+
110+
// for some options, we do not want to use their default values,
111+
// if they are not provided in cli,
112+
// reset the value of those options to nil
113+
c.ResetUserInputOptions(&c.createArchiveOptions.DatabaseOptions)
114+
115+
// create_archive only works for an Eon db so we assume the user always runs this subcommand
116+
// on an Eon db. When Eon mode cannot be found in config file, we set its value to true.
117+
if !viper.IsSet(eonModeKey) {
118+
c.createArchiveOptions.IsEon = true
119+
}
120+
121+
return c.validateParse(logger)
122+
}
123+
124+
// all validations of the arguments should go in here
125+
func (c *CmdCreateArchive) validateParse(logger vlog.Printer) error {
126+
logger.Info("Called validateParse()")
127+
128+
err := c.ValidateParseBaseOptions(&c.createArchiveOptions.DatabaseOptions)
129+
if err != nil {
130+
return err
131+
}
132+
133+
err = c.setConfigParam(&c.createArchiveOptions.DatabaseOptions)
134+
if err != nil {
135+
return err
136+
}
137+
138+
if !c.usePassword() {
139+
err = c.getCertFilesFromCertPaths(&c.createArchiveOptions.DatabaseOptions)
140+
if err != nil {
141+
return err
142+
}
143+
}
144+
145+
err = c.setDBPassword(&c.createArchiveOptions.DatabaseOptions)
146+
if err != nil {
147+
return err
148+
}
149+
150+
return nil
151+
}
152+
153+
func (c *CmdCreateArchive) Analyze(logger vlog.Printer) error {
154+
logger.Info("Called method Analyze()")
155+
return nil
156+
}
157+
158+
func (c *CmdCreateArchive) Run(vcc vclusterops.ClusterCommands) error {
159+
vcc.LogInfo("Called method Run()")
160+
161+
options := c.createArchiveOptions
162+
163+
err := vcc.VCreateArchive(options)
164+
if err != nil {
165+
vcc.LogError(err, "failed to create archive", "archiveName", options.ArchiveName)
166+
return err
167+
}
168+
169+
vcc.DisplayInfo("Successfully created archive: %s", options.ArchiveName)
170+
return nil
171+
}
172+
173+
// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdCreateArchive
174+
func (c *CmdCreateArchive) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
175+
c.createArchiveOptions.DatabaseOptions = *opt
176+
}

commands/cmd_create_db.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ func (c *CmdCreateDB) Run(vcc vclusterops.ClusterCommands) error {
275275
vcc.V(1).Info("Called method Run()")
276276
vdb, createError := vcc.VCreateDatabase(c.createDBOptions)
277277
if createError != nil {
278-
vcc.LogError(createError, "Failed to create the database.")
279278
return createError
280279
}
281280

0 commit comments

Comments
 (0)