-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Spilchen
committed
Mar 24, 2024
1 parent
15f8a02
commit 45acd3e
Showing
18 changed files
with
615 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
(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 ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/vertica/vcluster/vclusterops" | ||
"github.com/vertica/vcluster/vclusterops/vlog" | ||
) | ||
|
||
/* CmdConfigRecover | ||
* | ||
* A subcommand recovering the YAML config file | ||
* in the default or a specified location. | ||
* | ||
* Implements ClusterCommand interface | ||
*/ | ||
type CmdConfigRecover struct { | ||
recoverConfigOptions *vclusterops.VFetchCoordinationDatabaseOptions | ||
CmdBase | ||
} | ||
|
||
func makeCmdConfigRecover() *cobra.Command { | ||
newCmd := &CmdConfigRecover{} | ||
opt := vclusterops.VRecoverConfigOptionsFactory() | ||
newCmd.recoverConfigOptions = &opt | ||
|
||
cmd := makeBasicCobraCmd( | ||
newCmd, | ||
configRecoverSubCmd, | ||
"recover the content of the config file", | ||
`This subcommand is used to recover the content of the config file. | ||
You must provide the all hosts that participate in the database. | ||
If there is an existing file at the provided config file location, the recover function | ||
will not create a new config file unless you explicitly specify --overwrite. | ||
Examples: | ||
# Recover the config file to the default location | ||
vcluster manage_config recover --db-name test_db \ | ||
--hosts 10.20.30.41,10.20.30.42,10.20.30.43 \ | ||
--catalog-path /data --depot-path /data | ||
# Recover the config file to /tmp/vertica_cluster.yaml | ||
vcluster manage_config recover --db-name test_db \ | ||
--hosts 10.20.30.41,10.20.30.42,10.20.30.43 \ | ||
--catalog-path /data --depot-path /data \ | ||
--config /tmp/vertica_cluster.yaml | ||
`, | ||
[]string{dbNameFlag, hostsFlag, catalogPathFlag, depotPathFlag, ipv6Flag, configFlag}, | ||
) | ||
|
||
// require db-name, hosts, catalog-path, and data-path | ||
markFlagsRequired(cmd, []string{dbNameFlag, hostsFlag, catalogPathFlag}) | ||
|
||
// local flags | ||
newCmd.setLocalFlags(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// setLocalFlags will set the local flags the command has | ||
func (c *CmdConfigRecover) setLocalFlags(cmd *cobra.Command) { | ||
cmd.Flags().BoolVar( | ||
&c.recoverConfigOptions.Overwrite, | ||
"overwrite", | ||
false, | ||
"overwrite the existing config file", | ||
) | ||
} | ||
|
||
func (c *CmdConfigRecover) Parse(inputArgv []string, logger vlog.Printer) error { | ||
c.argv = inputArgv | ||
logger.LogArgParse(&c.argv) | ||
|
||
return c.validateParse(logger) | ||
} | ||
|
||
// all validations of the arguments should go in here | ||
func (c *CmdConfigRecover) validateParse(logger vlog.Printer) error { | ||
logger.Info("Called validateParse()") | ||
err := c.ValidateParseBaseOptions(&c.recoverConfigOptions.DatabaseOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *CmdConfigRecover) Run(vcc vclusterops.ClusterCommands) error { | ||
vdb, err := vcc.VFetchCoordinationDatabase(c.recoverConfigOptions) | ||
if err != nil { | ||
vcc.LogError(err, "failed to recover the config file") | ||
return err | ||
} | ||
// write db info to vcluster config file | ||
err = writeConfig(&vdb, vcc.GetLog()) | ||
if err != nil { | ||
return fmt.Errorf("fail to write config file, details: %s", err) | ||
} | ||
vcc.PrintInfo("Recovered config file for database %s at %s", vdb.Name, | ||
c.recoverConfigOptions.ConfigPath) | ||
|
||
return nil | ||
} | ||
|
||
// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance | ||
func (c *CmdConfigRecover) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) { | ||
c.recoverConfigOptions.DatabaseOptions = *opt | ||
} |
Oops, something went wrong.