Skip to content

Commit

Permalink
Sync from server repo (3e78a0a7279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Nov 2, 2023
1 parent ded60d7 commit 82f2d75
Show file tree
Hide file tree
Showing 68 changed files with 363 additions and 594 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, *options.SCName)
err = vdb.addHosts(options.NewHosts)
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,7 +343,11 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
password := options.Password

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

if vdb.IsEon {
httpsFindSubclusterOp, e := makeHTTPSFindSubclusterOp(
Expand All @@ -355,10 +359,6 @@ 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: 15 additions & 17 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, scName string) error {
func (vdb *VCoordinationDatabase) addHosts(hosts []string) error {
totalHostCount := len(hosts) + len(vdb.HostList)
nodeNameToHost := vdb.genNodeNameToHostMap()
for _, host := range hosts {
Expand All @@ -149,11 +149,10 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string, scName string) error
}
nodeNameToHost[name] = host
nodeConfig := NodeConfig{
Address: host,
Name: name,
Subcluster: scName,
Address: host,
Name: name,
}
vNode.setFromNodeConfig(&nodeConfig, vdb)
vNode.SetFromNodeConfig(&nodeConfig, vdb)
err := vdb.addNode(&vNode)
if err != nil {
return err
Expand All @@ -163,7 +162,7 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string, scName 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 @@ -191,7 +190,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 @@ -201,10 +200,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 @@ -317,7 +316,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 @@ -372,7 +371,7 @@ func MakeVCoordinationNode() VCoordinationNode {
return VCoordinationNode{}
}

func (vnode *VCoordinationNode) setFromCreateDBOptions(
func (vnode *VCoordinationNode) SetFromCreateDBOptions(
options *VCreateDatabaseOptions,
host string,
) error {
Expand Down Expand Up @@ -408,12 +407,11 @@ 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 82f2d75

Please sign in to comment.