Skip to content

Commit

Permalink
Sync from server repo (63169351518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Jan 3, 2024
1 parent 7c04c63 commit 91d1c33
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 18 deletions.
2 changes: 2 additions & 0 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func constructCmds(_ vlog.Printer) []ClusterCommand {
// sc-scope cmds
makeCmdAddSubcluster(),
makeCmdRemoveSubcluster(),
makeCmdSandboxSubcluster(),
makeCmdUnsandboxSubcluster(),
// node-scope cmds
makeCmdAddNode(),
makeCmdRemoveNode(),
Expand Down
6 changes: 6 additions & 0 deletions commands/cmd_revive_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func makeCmdReviveDB() *CmdReviveDB {
reviveDBOptions.IgnoreClusterLease = newCmd.parser.Bool("ignore-cluster-lease", false,
util.GetOptionalFlagMsg("Ignore the check of other clusters running on the same communal storage."+
" The communal storage can be corrupted when two clusters modified it at the same time. Proceed with caution"))
reviveDBOptions.RestorePoint.Archive = newCmd.parser.String("restore-point-archive", "", util.GetOptionalFlagMsg(
"Name of the restore archive to use for bootstrapping"))
reviveDBOptions.RestorePoint.Index = newCmd.parser.Int("restore-point-index", 0, util.GetOptionalFlagMsg(
"The (1-based) index of the restore point in the restore archive to restore from"))
reviveDBOptions.RestorePoint.ID = newCmd.parser.String("restore-point-id", "", util.GetOptionalFlagMsg(
"The identifier of the restore point in the restore archive to restore from"))

newCmd.reviveDBOptions = &reviveDBOptions

Expand Down
110 changes: 110 additions & 0 deletions commands/cmd_sandbox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
(c) Copyright [2023] 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 (
"flag"
"fmt"

"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdSandbox
*
* Implements ClusterCommand interface
*
* Parses CLI arguments for sandbox operation.
* Prepares the inputs for the library.
*
*/

type CmdSandboxSubcluster struct {
CmdBase
sbOptions vclusterops.VSandboxOptions
}

func (c *CmdSandboxSubcluster) TypeName() string {
return "CmdSandboxSubcluster"
}

func makeCmdSandboxSubcluster() *CmdSandboxSubcluster {
newCmd := &CmdSandboxSubcluster{}
newCmd.parser = flag.NewFlagSet("sandbox_subcluster", flag.ExitOnError)
newCmd.sbOptions = vclusterops.VSandboxOptionsFactory()

// required flags
newCmd.sbOptions.DBName = newCmd.parser.String("db-name", "", "The name of the database to run sandbox. May be omitted on k8s.")
newCmd.sbOptions.SCName = newCmd.parser.String("subcluster", "", "The name of the subcluster to be sandboxed")
newCmd.sbOptions.SandboxName = newCmd.parser.String("sandbox", "", "The name of the sandbox")

// optional flags
newCmd.sbOptions.Password = newCmd.parser.String("password", "",
util.GetOptionalFlagMsg("Database password. Consider using in single quotes to avoid shell substitution."))
newCmd.hostListStr = newCmd.parser.String("hosts", "", util.GetOptionalFlagMsg("Comma-separated list of hosts to participate in database."+
" Use it when you do not trust "+vclusterops.ConfigFileName))
newCmd.ipv6 = newCmd.parser.Bool("ipv6", false, "start database with with IPv6 hosts")
newCmd.sbOptions.HonorUserInput = newCmd.parser.Bool("honor-user-input", false,
util.GetOptionalFlagMsg("Forcefully use the user's input instead of reading the options from "+vclusterops.ConfigFileName))
newCmd.sbOptions.ConfigDirectory = newCmd.parser.String("config-directory", "",
util.GetOptionalFlagMsg("Directory where "+vclusterops.ConfigFileName+" is located"))

return newCmd
}

func (c *CmdSandboxSubcluster) CommandType() string {
return "sandbox_subcluster"
}

func (c *CmdSandboxSubcluster) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
// from now on we use the internal copy of argv
return c.parseInternal(logger)
}

func (c *CmdSandboxSubcluster) parseInternal(logger vlog.Printer) error {
if c.parser == nil {
return fmt.Errorf("unexpected nil for CmdSandboxSubcluster.parser")
}
logger.PrintInfo("Parsing sandboxing command input")
parseError := c.ParseArgv()
if parseError != nil {
return parseError
}
return nil
}

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

func (c *CmdSandboxSubcluster) Run(vcc vclusterops.VClusterCommands) error {
vcc.Log.PrintInfo("Running sandbox subcluster")
vcc.Log.Info("Calling method Run() for command " + c.CommandType())

options := c.sbOptions
// get config from vertica_cluster.yaml
config, err := options.GetDBConfig(vcc)
if err != nil {
return err
}
options.Config = config
err = vcc.VSandbox(&options)
vcc.Log.PrintInfo("Completed method Run() for command " + c.CommandType())
return err
}
109 changes: 109 additions & 0 deletions commands/cmd_unsandbox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
(c) Copyright [2023] 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 (
"flag"
"fmt"

"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdUnsandbox
*
* Implements ClusterCommand interface
*
* Parses CLI arguments for Unsandboxing operation.
* Prepares the inputs for the library.
*
*/
type CmdUnsandboxSubcluster struct {
CmdBase
usOptions vclusterops.VUnsandboxOptions
}

func (c *CmdUnsandboxSubcluster) TypeName() string {
return "CmdUnsandboxSubcluster"
}

func makeCmdUnsandboxSubcluster() *CmdUnsandboxSubcluster {
newCmd := &CmdUnsandboxSubcluster{}
newCmd.parser = flag.NewFlagSet("unsandbox", flag.ExitOnError)
newCmd.usOptions = vclusterops.VUnsandboxOptionsFactory()

// required flags
newCmd.usOptions.DBName = newCmd.parser.String("db-name", "", "The name of the database to run unsandboxing. May be omitted on k8s.")
newCmd.usOptions.SCName = newCmd.parser.String("subcluster", "", "The name of the subcluster to be unsandboxed")

// optional flags
newCmd.usOptions.Password = newCmd.parser.String("password", "",
util.GetOptionalFlagMsg("Database password. Consider using in single quotes to avoid shell substitution."))
newCmd.hostListStr = newCmd.parser.String("hosts", "", util.GetOptionalFlagMsg("Comma-separated list of hosts to participate in database."+
" Use it when you do not trust "+vclusterops.ConfigFileName))
newCmd.ipv6 = newCmd.parser.Bool("ipv6", false, "start database with with IPv6 hosts")
newCmd.usOptions.HonorUserInput = newCmd.parser.Bool("honor-user-input", false,
util.GetOptionalFlagMsg("Forcefully use the user's input instead of reading the options from "+vclusterops.ConfigFileName))
newCmd.usOptions.ConfigDirectory = newCmd.parser.String("config-directory", "",
util.GetOptionalFlagMsg("Directory where "+vclusterops.ConfigFileName+" is located"))

return newCmd
}

func (c *CmdUnsandboxSubcluster) CommandType() string {
return "unsandbox_subcluster"
}

func (c *CmdUnsandboxSubcluster) Parse(inputArgv []string, logger vlog.Printer) error {
c.argv = inputArgv
// from now on we use the internal copy of argv
return c.parseInternal(logger)
}

func (c *CmdUnsandboxSubcluster) parseInternal(logger vlog.Printer) error {
if c.parser == nil {
return fmt.Errorf("unexpected nil for CmdUnsandboxSubcluster.parser")
}
logger.PrintInfo("Parsing Unsandboxing command input")
parseError := c.ParseArgv()
if parseError != nil {
return parseError
}
return nil
}

func (c *CmdUnsandboxSubcluster) Analyze(logger vlog.Printer) error {
logger.Info("Called method Analyze()")

return nil
}

func (c *CmdUnsandboxSubcluster) Run(vcc vclusterops.VClusterCommands) error {
vcc.Log.PrintInfo("Running unsandbox subcluster")
vcc.Log.Info("Calling method Run() for command " + c.CommandType())

options := c.usOptions
// get config from vertica_cluster.yaml
config, err := options.GetDBConfig(vcc)
if err != nil {
return err
}
options.Config = config
err = vcc.VUnsandbox(&options)
vcc.Log.PrintInfo("Completed method Run() for command " + c.CommandType())
return err
}
38 changes: 27 additions & 11 deletions vclusterops/nma_load_remote_catalog_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@ type nmaLoadRemoteCatalogOp struct {
vdb *VCoordinationDatabase
timeout uint
primaryNodeCount uint
restorePoint *RestorePointPolicy
}

type loadRemoteCatalogRequestData struct {
DBName string `json:"db_name"`
StorageLocations []string `json:"storage_locations"`
CommunalLocation string `json:"communal_location"`
CatalogPath string `json:"catalog_path"`
Host string `json:"host"`
NodeName string `json:"node_name"`
AWSAccessKeyID string `json:"aws_access_key_id,omitempty"`
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
NodeAddresses map[string][]string `json:"node_addresses"`
Parameters map[string]string `json:"parameters,omitempty"`
DBName string `json:"db_name"`
StorageLocations []string `json:"storage_locations"`
CommunalLocation string `json:"communal_location"`
CatalogPath string `json:"catalog_path"`
Host string `json:"host"`
NodeName string `json:"node_name"`
AWSAccessKeyID string `json:"aws_access_key_id,omitempty"`
AWSSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
NodeAddresses map[string][]string `json:"node_addresses"`
Parameters map[string]string `json:"parameters,omitempty"`
RestorePointArchive string `json:"restore_point_archive,omitempty"`
RestorePointIndex int `json:"restore_point_index,omitempty"`
RestorePointID string `json:"restore_point_id,omitempty"`
}

func makeNMALoadRemoteCatalogOp(logger vlog.Printer, oldHosts []string, configurationParameters map[string]string,
vdb *VCoordinationDatabase, timeout uint) nmaLoadRemoteCatalogOp {
vdb *VCoordinationDatabase, timeout uint, restorePoint *RestorePointPolicy) nmaLoadRemoteCatalogOp {
op := nmaLoadRemoteCatalogOp{}
op.name = "NMALoadRemoteCatalogOp"
op.logger = logger.WithName(op.name)
Expand All @@ -56,6 +60,7 @@ func makeNMALoadRemoteCatalogOp(logger vlog.Printer, oldHosts []string, configur
op.configurationParameters = configurationParameters
op.vdb = vdb
op.timeout = timeout
op.restorePoint = restorePoint

op.primaryNodeCount = 0
for _, vnode := range vdb.HostNodeMap {
Expand Down Expand Up @@ -98,6 +103,17 @@ func (op *nmaLoadRemoteCatalogOp) setupRequestBody(execContext *opEngineExecCont
requestData.StorageLocations = vNode.StorageLocations
requestData.NodeAddresses = nodeAddresses
requestData.Parameters = op.configurationParameters
if op.restorePoint != nil {
if op.restorePoint.Archive != nil {
requestData.RestorePointArchive = *op.restorePoint.Archive
}
if op.restorePoint.Index != nil {
requestData.RestorePointIndex = *op.restorePoint.Index
}
if op.restorePoint.ID != nil {
requestData.RestorePointID = *op.restorePoint.ID
}
}

dataBytes, err := json.Marshal(requestData)
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion vclusterops/revive_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ type VReviveDatabaseOptions struct {
DisplayOnly *bool
// whether ignore the cluster lease
IgnoreClusterLease *bool
// the restore policy
RestorePoint *RestorePointPolicy
}

type RestorePointPolicy struct {
// Name of the restore archive to use for bootstrapping
Archive *string
// The (1-based) index of the restore point in the restore archive to restore from
Index *int
// The identifier of the restore point in the restore archive to restore from
ID *string
}

func VReviveDBOptionsFactory() VReviveDatabaseOptions {
Expand All @@ -56,6 +67,10 @@ func (options *VReviveDatabaseOptions) setDefaultValues() {
options.ForceRemoval = new(bool)
options.DisplayOnly = new(bool)
options.IgnoreClusterLease = new(bool)
options.RestorePoint = new(RestorePointPolicy)
options.RestorePoint.Archive = new(string)
options.RestorePoint.Index = new(int)
options.RestorePoint.ID = new(string)
}

func (options *VReviveDatabaseOptions) validateRequiredOptions() error {
Expand Down Expand Up @@ -239,7 +254,7 @@ func (vcc *VClusterCommands) produceReviveDBInstructions(options *VReviveDatabas
nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, options.Hosts)

nmaLoadRemoteCatalogOp := makeNMALoadRemoteCatalogOp(vcc.Log, oldHosts, options.ConfigurationParameters,
&newVDB, *options.LoadCatalogTimeout)
&newVDB, *options.LoadCatalogTimeout, options.RestorePoint)

instructions = append(instructions,
&nmaPrepareDirectoriesOp,
Expand Down
Loading

0 comments on commit 91d1c33

Please sign in to comment.