Skip to content

Commit

Permalink
Sync from server repo (4cfaf1494ee)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Oct 30, 2023
1 parent 205f6b3 commit ded60d7
Show file tree
Hide file tree
Showing 68 changed files with 594 additions and 363 deletions.
32 changes: 16 additions & 16 deletions vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ type VAddNodeOptions struct {
func VAddNodeOptionsFactory() VAddNodeOptions {
opt := VAddNodeOptions{}
// set default values to the params
opt.SetDefaultValues()
opt.setDefaultValues()

return opt
}

func (o *VAddNodeOptions) SetDefaultValues() {
o.DatabaseOptions.SetDefaultValues()
func (o *VAddNodeOptions) setDefaultValues() {
o.DatabaseOptions.setDefaultValues()

o.SCName = new(string)
o.SkipRebalanceShards = new(bool)
Expand Down Expand Up @@ -81,7 +81,7 @@ func (o *VAddNodeOptions) validateExtraOptions() error {

func (o *VAddNodeOptions) validateParseOptions(log vlog.Printer) error {
// batch 1: validate required parameters
err := o.ValidateBaseOptions("db_add_node", log)
err := o.validateBaseOptions("db_add_node", log)
if err != nil {
return err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa
}

// get hosts from config file and options.
hosts, err := options.GetHosts(options.Config)
hosts, err := options.getHosts(options.Config)
if err != nil {
return vdb, err
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa
return vdb, err
}

err = vdb.addHosts(options.NewHosts)
err = vdb.addHosts(options.NewHosts, *options.SCName)
if err != nil {
return vdb, err
}
Expand All @@ -190,8 +190,8 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa
}

certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := MakeClusterOpEngine(instructions, &certs)
if runError := clusterOpEngine.Run(vcc.Log); runError != nil {
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
if runError := clusterOpEngine.run(vcc.Log); runError != nil {
return vdb, fmt.Errorf("fail to complete add node operation, %w", runError)
}
return vdb, nil
Expand Down Expand Up @@ -299,8 +299,8 @@ func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase,
}

certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := MakeClusterOpEngine(instructions, &certs)
err := clusterOpEngine.Run(vcc.Log)
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
err := clusterOpEngine.run(vcc.Log)
if err != nil {
vcc.Log.Error(err, "fail to trim nodes from catalog, %v")
return err
Expand All @@ -319,9 +319,9 @@ func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase,
// The generated instructions will later perform the following operations necessary
// for a successful add_node:
// - Check NMA connectivity
// - Check NMA versions
// - If we have subcluster in the input, check if the subcluster exists. If not, we stop.
// If we do not have a subcluster in the input, fetch the current default subcluster name
// - Check NMA versions
// - Prepare directories
// - Get network profiles
// - Create the new node
Expand All @@ -343,11 +343,7 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
password := options.Password

nmaHealthOp := makeNMAHealthOp(vcc.Log, vdb.HostList)
// require to have the same vertica version
nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, vdb.HostList, true)
instructions = append(instructions,
&nmaHealthOp,
&nmaVerticaVersionOp)
instructions = append(instructions, &nmaHealthOp)

if vdb.IsEon {
httpsFindSubclusterOp, e := makeHTTPSFindSubclusterOp(
Expand All @@ -359,6 +355,10 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
instructions = append(instructions, &httpsFindSubclusterOp)
}

// require to have the same vertica version
nmaVerticaVersionOp := makeNMAVerticaVersionOpWithVDB(vcc.Log, true, vdb)
instructions = append(instructions, &nmaVerticaVersionOp)

// this is a copy of the original HostNodeMap that only
// contains the hosts to add.
newHostNodeMap := vdb.copyHostNodeMap(options.NewHosts)
Expand Down
22 changes: 11 additions & 11 deletions vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ type VAddSubclusterInfo struct {
func VAddSubclusterOptionsFactory() VAddSubclusterOptions {
opt := VAddSubclusterOptions{}
// set default values to the params
opt.SetDefaultValues()
opt.setDefaultValues()

return opt
}

func (options *VAddSubclusterOptions) SetDefaultValues() {
options.DatabaseOptions.SetDefaultValues()
func (options *VAddSubclusterOptions) setDefaultValues() {
options.DatabaseOptions.setDefaultValues()

options.SCName = new(string)
options.IsPrimary = new(bool)
Expand All @@ -71,7 +71,7 @@ func (options *VAddSubclusterOptions) SetDefaultValues() {
}

func (options *VAddSubclusterOptions) validateRequiredOptions(log vlog.Printer) error {
err := options.ValidateBaseOptions("db_add_subcluster", log)
err := options.validateBaseOptions("db_add_subcluster", log)
if err != nil {
return err
}
Expand All @@ -83,7 +83,7 @@ func (options *VAddSubclusterOptions) validateRequiredOptions(log vlog.Printer)
}

func (options *VAddSubclusterOptions) validateEonOptions(config *ClusterConfig) error {
isEon, err := options.IsEonMode(config)
isEon, err := options.isEonMode(config)
if err != nil {
return err
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (options *VAddSubclusterOptions) analyzeOptions() (err error) {
return nil
}

func (options *VAddSubclusterOptions) ValidateAnalyzeOptions(config *ClusterConfig, vcc *VClusterCommands) error {
func (options *VAddSubclusterOptions) validateAnalyzeOptions(config *ClusterConfig, vcc *VClusterCommands) error {
if err := options.validateParseOptions(config, vcc); err != nil {
return err
}
Expand All @@ -184,7 +184,7 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro
* - Give the instructions to the VClusterOpEngine to run
*/

err := options.ValidateAnalyzeOptions(options.Config, vcc)
err := options.validateAnalyzeOptions(options.Config, vcc)
if err != nil {
return err
}
Expand All @@ -199,7 +199,7 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro
ControlSetSize: *options.ControlSetSize,
CloneSC: *options.CloneSC,
}
addSubclusterInfo.DBName, addSubclusterInfo.Hosts, err = options.GetNameAndHosts(options.Config)
addSubclusterInfo.DBName, addSubclusterInfo.Hosts, err = options.getNameAndHosts(options.Config)
if err != nil {
return err
}
Expand All @@ -211,10 +211,10 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro

// Create a VClusterOpEngine, and add certs to the engine
certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := MakeClusterOpEngine(instructions, &certs)
clusterOpEngine := makeClusterOpEngine(instructions, &certs)

// Give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.Run(vcc.Log)
runError := clusterOpEngine.run(vcc.Log)
if runError != nil {
return fmt.Errorf("fail to add subcluster %s, %w", addSubclusterInfo.SCName, runError)
}
Expand All @@ -241,7 +241,7 @@ func (vcc *VClusterCommands) produceAddSubclusterInstructions(addSubclusterInfo
usePassword := false
if addSubclusterInfo.Password != nil {
usePassword = true
err := options.ValidateUserName(vcc.Log)
err := options.validateUserName(vcc.Log)
if err != nil {
return instructions, err
}
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (c *ClusterConfig) GetPathPrefix(dbName string) (catalogPrefix string,
dbConfig.Nodes[0].DepotPath, nil
}

func (c *DatabaseConfig) GetHosts() []string {
func (c *DatabaseConfig) getHosts() []string {
var hostList []string

for _, vnode := range c.Nodes {
Expand Down
16 changes: 8 additions & 8 deletions vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ const respSuccStatusCode = 0
// 3. The local node has not yet joined the cluster; the HTTP server will accept connections once the node joins the cluster.
// HTTPCheckDBRunningOp in create_db need to check all scenarios to see any HTTP running
// For HTTPSPollNodeStateOp in start_db, it requires only handling the first and second scenarios
func (hostResult *HostHTTPResult) IsUnauthorizedRequest() bool {
func (hostResult *HostHTTPResult) isUnauthorizedRequest() bool {
return hostResult.statusCode == UnauthorizedCode
}

// IsSuccess returns true if status code is 200
func (hostResult *HostHTTPResult) IsSuccess() bool {
// isSuccess returns true if status code is 200
func (hostResult *HostHTTPResult) isSuccess() bool {
return hostResult.statusCode == SuccessCode
}

// check only password and certificate for start_db
func (hostResult *HostHTTPResult) IsPasswordAndCertificateError(log vlog.Printer) bool {
if !hostResult.IsUnauthorizedRequest() {
func (hostResult *HostHTTPResult) isPasswordAndCertificateError(log vlog.Printer) bool {
if !hostResult.isUnauthorizedRequest() {
return false
}
resultString := fmt.Sprintf("%v", hostResult)
Expand All @@ -119,12 +119,12 @@ func (hostResult *HostHTTPResult) IsPasswordAndCertificateError(log vlog.Printer
return false
}

func (hostResult *HostHTTPResult) IsInternalError() bool {
func (hostResult *HostHTTPResult) isInternalError() bool {
return hostResult.statusCode == InternalErrorCode
}

func (hostResult *HostHTTPResult) IsHTTPRunning() bool {
if hostResult.isPassing() || hostResult.IsUnauthorizedRequest() || hostResult.IsInternalError() {
func (hostResult *HostHTTPResult) isHTTPRunning() bool {
if hostResult.isPassing() || hostResult.isUnauthorizedRequest() || hostResult.isInternalError() {
return true
}
return false
Expand Down
6 changes: 3 additions & 3 deletions vclusterops/cluster_op_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type VClusterOpEngine struct {
execContext *OpEngineExecContext
}

func MakeClusterOpEngine(instructions []ClusterOp, certs *HTTPSCerts) VClusterOpEngine {
func makeClusterOpEngine(instructions []ClusterOp, certs *HTTPSCerts) VClusterOpEngine {
newClusterOpEngine := VClusterOpEngine{}
newClusterOpEngine.instructions = instructions
newClusterOpEngine.certs = certs
Expand All @@ -38,8 +38,8 @@ func (opEngine *VClusterOpEngine) shouldGetCertsFromOptions() bool {
return (opEngine.certs.key != "" && opEngine.certs.cert != "" && opEngine.certs.caCert != "")
}

func (opEngine *VClusterOpEngine) Run(log vlog.Printer) error {
execContext := MakeOpEngineExecContext(log)
func (opEngine *VClusterOpEngine) run(log vlog.Printer) error {
execContext := makeOpEngineExecContext(log)
opEngine.execContext = &execContext

findCertsInOptions := opEngine.shouldGetCertsFromOptions()
Expand Down
4 changes: 2 additions & 2 deletions vclusterops/cluster_op_engine_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type OpEngineExecContext struct {
dbInfo string // store the db info that retrieved from communal storage
}

func MakeOpEngineExecContext(log vlog.Printer) OpEngineExecContext {
func makeOpEngineExecContext(log vlog.Printer) OpEngineExecContext {
newOpEngineExecContext := OpEngineExecContext{}
newOpEngineExecContext.dispatcher = MakeHTTPRequestDispatcher(log)
newOpEngineExecContext.dispatcher = makeHTTPRequestDispatcher(log)

return newOpEngineExecContext
}
4 changes: 2 additions & 2 deletions vclusterops/cluster_op_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestSkipExecuteOp(t *testing.T) {
opWithSkipDisabled := makeMockOp(false)
instructions := []ClusterOp{&opWithSkipDisabled, &opWithSkipEnabled}
certs := HTTPSCerts{key: "key", cert: "cert", caCert: "ca-cert"}
opEngn := MakeClusterOpEngine(instructions, &certs)
err := opEngn.Run(vlog.Printer{})
opEngn := makeClusterOpEngine(instructions, &certs)
err := opEngn.run(vlog.Printer{})
assert.Equal(t, nil, err)
assert.True(t, opWithSkipDisabled.calledPrepare)
assert.True(t, opWithSkipDisabled.calledExecute)
Expand Down
32 changes: 17 additions & 15 deletions vclusterops/coordinator_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func MakeVCoordinationDatabase() VCoordinationDatabase {
return VCoordinationDatabase{}
}

func (vdb *VCoordinationDatabase) SetFromCreateDBOptions(options *VCreateDatabaseOptions, log vlog.Printer) error {
func (vdb *VCoordinationDatabase) setFromCreateDBOptions(options *VCreateDatabaseOptions, log vlog.Printer) error {
// build after validating the options
err := options.ValidateAnalyzeOptions(log)
err := options.validateAnalyzeOptions(log)
if err != nil {
return err
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (vdb *VCoordinationDatabase) SetFromCreateDBOptions(options *VCreateDatabas
vdb.UseDepot = true
}
if *options.GetAwsCredentialsFromEnv {
err := vdb.GetAwsCredentialsFromEnv()
err := vdb.getAwsCredentialsFromEnv()
if err != nil {
return err
}
Expand All @@ -113,7 +113,7 @@ func (vdb *VCoordinationDatabase) SetFromCreateDBOptions(options *VCreateDatabas
// section 3: build VCoordinationNode info
for _, host := range vdb.HostList {
vNode := MakeVCoordinationNode()
err := vNode.SetFromCreateDBOptions(options, host)
err := vNode.setFromCreateDBOptions(options, host)
if err != nil {
return err
}
Expand All @@ -138,7 +138,7 @@ func (vdb *VCoordinationDatabase) addNode(vnode *VCoordinationNode) error {

// addHosts adds a given list of hosts to the VDB's HostList
// and HostNodeMap.
func (vdb *VCoordinationDatabase) addHosts(hosts []string) error {
func (vdb *VCoordinationDatabase) addHosts(hosts []string, scName string) error {
totalHostCount := len(hosts) + len(vdb.HostList)
nodeNameToHost := vdb.genNodeNameToHostMap()
for _, host := range hosts {
Expand All @@ -149,10 +149,11 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string) error {
}
nodeNameToHost[name] = host
nodeConfig := NodeConfig{
Address: host,
Name: name,
Address: host,
Name: name,
Subcluster: scName,
}
vNode.SetFromNodeConfig(&nodeConfig, vdb)
vNode.setFromNodeConfig(&nodeConfig, vdb)
err := vdb.addNode(&vNode)
if err != nil {
return err
Expand All @@ -162,7 +163,7 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string) error {
return nil
}

func (vdb *VCoordinationDatabase) SetFromClusterConfig(dbName string,
func (vdb *VCoordinationDatabase) setFromClusterConfig(dbName string,
clusterConfig *ClusterConfig) error {
// we trust the information in the config file
// so we do not perform validation here
Expand Down Expand Up @@ -190,7 +191,7 @@ func (vdb *VCoordinationDatabase) SetFromClusterConfig(dbName string,
vdb.HostNodeMap = makeVHostNodeMap()
for _, nodeConfig := range dbConfig.Nodes {
vnode := VCoordinationNode{}
vnode.SetFromNodeConfig(nodeConfig, vdb)
vnode.setFromNodeConfig(nodeConfig, vdb)
err = vdb.addNode(&vnode)
if err != nil {
return err
Expand All @@ -200,10 +201,10 @@ func (vdb *VCoordinationDatabase) SetFromClusterConfig(dbName string,
return nil
}

// Copy copies the receiver's fields into a new VCoordinationDatabase struct and
// copy copies the receiver's fields into a new VCoordinationDatabase struct and
// returns that struct. You can choose to copy only a subset of the receiver's hosts
// by passing a slice of hosts to keep.
func (vdb *VCoordinationDatabase) Copy(targetHosts []string) VCoordinationDatabase {
func (vdb *VCoordinationDatabase) copy(targetHosts []string) VCoordinationDatabase {
v := VCoordinationDatabase{
Name: vdb.Name,
CatalogPrefix: vdb.CatalogPrefix,
Expand Down Expand Up @@ -316,7 +317,7 @@ func (vdb *VCoordinationDatabase) genCatalogPath(nodeName string) string {
}

// set aws id key and aws secret key
func (vdb *VCoordinationDatabase) GetAwsCredentialsFromEnv() error {
func (vdb *VCoordinationDatabase) getAwsCredentialsFromEnv() error {
awsIDKey := os.Getenv("AWS_ACCESS_KEY_ID")
if awsIDKey == "" {
return fmt.Errorf("unable to get AWS ID key from environment variable")
Expand Down Expand Up @@ -371,7 +372,7 @@ func MakeVCoordinationNode() VCoordinationNode {
return VCoordinationNode{}
}

func (vnode *VCoordinationNode) SetFromCreateDBOptions(
func (vnode *VCoordinationNode) setFromCreateDBOptions(
options *VCreateDatabaseOptions,
host string,
) error {
Expand Down Expand Up @@ -407,11 +408,12 @@ func (vnode *VCoordinationNode) SetFromCreateDBOptions(
return fmt.Errorf("fail to set up vnode from options: host %s does not exist in options", host)
}

func (vnode *VCoordinationNode) SetFromNodeConfig(nodeConfig *NodeConfig, vdb *VCoordinationDatabase) {
func (vnode *VCoordinationNode) setFromNodeConfig(nodeConfig *NodeConfig, vdb *VCoordinationDatabase) {
// we trust the information in the config file
// so we do not perform validation here
vnode.Address = nodeConfig.Address
vnode.Name = nodeConfig.Name
vnode.Subcluster = nodeConfig.Subcluster
vnode.CatalogPath = vdb.genCatalogPath(vnode.Name)
dataPath := vdb.genDataPath(vnode.Name)
vnode.StorageLocations = append(vnode.StorageLocations, dataPath)
Expand Down
Loading

0 comments on commit ded60d7

Please sign in to comment.