Skip to content

Commit

Permalink
Sync from server repo (05fc577c5a)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Sep 22, 2023
1 parent 08fdc8b commit f0bd199
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 13 additions & 0 deletions vclusterops/https_sync_catalog_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func makeHTTPSSyncCatalogOp(hosts []string, useHTTPPassword bool,
return op, nil
}

func makeHTTPSSyncCatalogOpWithoutHosts(useHTTPPassword bool,
userName string, httpsPassword *string) (HTTPSSyncCatalogOp, error) {
return makeHTTPSSyncCatalogOp(nil, useHTTPPassword, userName, httpsPassword)
}

func (op *HTTPSSyncCatalogOp) setupClusterHTTPRequest(hosts []string) error {
op.clusterHTTPRequest = ClusterHTTPRequest{}
op.clusterHTTPRequest.RequestCollection = make(map[string]HostHTTPRequest)
Expand All @@ -68,6 +73,14 @@ func (op *HTTPSSyncCatalogOp) setupClusterHTTPRequest(hosts []string) error {
}

func (op *HTTPSSyncCatalogOp) prepare(execContext *OpEngineExecContext) error {
// If no hosts passed in, we will find the hosts from execute-context
if len(op.hosts) == 0 {
if len(execContext.upHosts) == 0 {
return fmt.Errorf(`[%s] Cannot find any up hosts in OpEngineExecContext`, op.name)
}
// use first up host to execute https post request
op.hosts = []string{execContext.upHosts[0]}
}
execContext.dispatcher.Setup(op.hosts)

return op.setupClusterHTTPRequest(op.hosts)
Expand Down
17 changes: 15 additions & 2 deletions vclusterops/stop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type VStopDatabaseInfo struct {
UserName string
Password *string
DrainSeconds *int
IsEon bool
}

func VStopDatabaseOptionsFactory() VStopDatabaseOptions {
Expand Down Expand Up @@ -146,6 +147,7 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error
stopDBInfo.Password = options.Password
stopDBInfo.DrainSeconds = options.DrainSeconds
stopDBInfo.DBName, stopDBInfo.Hosts = options.GetNameAndHosts(config)
stopDBInfo.IsEon = options.IsEonMode(config)

instructions, err := vcc.produceStopDBInstructions(stopDBInfo, options)
if err != nil {
Expand Down Expand Up @@ -173,7 +175,8 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error
// The generated instructions will later perform the following operations necessary
// for a successful stop_db:
// - Get up nodes through https call
// - Stop db on the first up node
// - Sync catalog through the first up node
// - Stop db through the first up node
// - Check there is not any database running
func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabaseInfo,
options *VStopDatabaseOptions,
Expand All @@ -195,6 +198,17 @@ func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabase
if err != nil {
return instructions, err
}
instructions = append(instructions, &httpsGetUpNodesOp)

if stopDBInfo.IsEon {
httpsSyncCatalogOp, e := makeHTTPSSyncCatalogOpWithoutHosts(usePassword, *options.UserName, stopDBInfo.Password)
if e != nil {
return instructions, e
}
instructions = append(instructions, &httpsSyncCatalogOp)
} else {
vlog.LogPrintInfoln("Skipping sync catalog for an enterprise database")
}

httpsStopDBOp, err := makeHTTPSStopDBOp(usePassword, *options.UserName, stopDBInfo.Password, stopDBInfo.DrainSeconds)
if err != nil {
Expand All @@ -208,7 +222,6 @@ func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabase
}

instructions = append(instructions,
&httpsGetUpNodesOp,
&httpsStopDBOp,
&httpsCheckDBRunningOp,
)
Expand Down

0 comments on commit f0bd199

Please sign in to comment.