diff --git a/vclusterops/add_node.go b/vclusterops/add_node.go index 215d4fc..3f67f61 100644 --- a/vclusterops/add_node.go +++ b/vclusterops/add_node.go @@ -20,7 +20,6 @@ import ( "strings" "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) // VAddNodeOptions are the option arguments for the VAddNode API @@ -142,7 +141,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa return vdb, err } - err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions) + err = vcc.getVDBFromRunningDB(&vdb, &options.DatabaseOptions) if err != nil { return vdb, err } @@ -167,7 +166,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa // trim stale node information from catalog // if NodeNames is provided - err = trimNodesInCatalog(&vdb, options) + err = vcc.trimNodesInCatalog(&vdb, options) if err != nil { return vdb, err } @@ -186,15 +185,13 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa instructions, err := vcc.produceAddNodeInstructions(&vdb, options) if err != nil { - vlog.LogPrintError("fail to produce add node instructions, %s", err) - return vdb, err + return vdb, fmt.Errorf("fail to produce add node instructions, %w", err) } certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := MakeClusterOpEngine(instructions, &certs) if runError := clusterOpEngine.Run(); runError != nil { - vlog.LogPrintError("fail to complete add node operation, %s", runError) - return vdb, runError + return vdb, fmt.Errorf("fail to complete add node operation, %w", runError) } return vdb, nil } @@ -234,10 +231,10 @@ func (o *VAddNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) error { // trimNodesInCatalog removes failed node info from catalog // which can be used to remove partially added nodes -func trimNodesInCatalog(vdb *VCoordinationDatabase, +func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase, options *VAddNodeOptions) error { if len(options.ExpectedNodeNames) == 0 { - vlog.LogInfoln("ExpectedNodeNames is not set, skip trimming nodes") + vcc.Log.Info("ExpectedNodeNames is not set, skip trimming nodes", "ExpectedNodeNames", options.ExpectedNodeNames) return nil } @@ -272,7 +269,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase, invalidNodeNames, vdb.Name) } - vlog.LogPrintInfo("Trim nodes %+v from catalog", nodesToTrim) + vcc.Log.PrintInfo("Trim nodes %+v from catalog", nodesToTrim) // pick any up host as intiator initiator := aliveHosts[:1] @@ -281,7 +278,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase, // mark k-safety if len(aliveHosts) < ksafetyThreshold { - httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(initiator, + httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(vcc.Log, initiator, options.usePassword, *options.UserName, options.Password, ksafeValueZero) if err != nil { @@ -292,7 +289,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase, // remove down nodes from catalog for _, nodeName := range nodesToTrim { - httpsDropNodeOp, err := makeHTTPSDropNodeOp(nodeName, initiator, + httpsDropNodeOp, err := makeHTTPSDropNodeOp(vcc.Log, nodeName, initiator, options.usePassword, *options.UserName, options.Password, vdb.IsEon) if err != nil { return err @@ -304,7 +301,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase, clusterOpEngine := MakeClusterOpEngine(instructions, &certs) err := clusterOpEngine.Run() if err != nil { - vlog.LogPrintError("fail to trim nodes from catalog, %v", err) + vcc.Log.Error(err, "fail to trim nodes from catalog, %v") return err } @@ -344,7 +341,7 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba usePassword := options.usePassword password := options.Password - nmaHealthOp := makeNMAHealthOp(vdb.HostList) + nmaHealthOp := makeNMAHealthOp(vcc.Log, vdb.HostList) // require to have the same vertica version nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, vdb.HostList, true) instructions = append(instructions, @@ -353,7 +350,7 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba if vdb.IsEon { httpsFindSubclusterOp, e := makeHTTPSFindSubclusterOp( - allHosts, usePassword, username, password, *options.SCName, + vcc.Log, allHosts, usePassword, username, password, *options.SCName, true /*ignore not found*/) if e != nil { return instructions, e @@ -364,22 +361,22 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba // this is a copy of the original HostNodeMap that only // contains the hosts to add. newHostNodeMap := vdb.copyHostNodeMap(options.NewHosts) - nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(newHostNodeMap, + nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(vcc.Log, newHostNodeMap, *options.ForceRemoval /*force cleanup*/, false /*for db revive*/) if err != nil { return instructions, err } - nmaNetworkProfileOp := makeNMANetworkProfileOp(vdb.HostList) - httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(newHosts, initiatorHost, + nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, vdb.HostList) + httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(vcc.Log, newHosts, initiatorHost, usePassword, username, password, vdb, *options.SCName) if err != nil { return instructions, err } - httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(initiatorHost, usePassword, username, password) + httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(vcc.Log, initiatorHost, usePassword, username, password) if err != nil { return instructions, err } - httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(usePassword, username, password, vdb) + httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(vcc.Log, usePassword, username, password, vdb) if err != nil { return instructions, err } @@ -392,13 +389,13 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba ) // we will remove the nil parameters in VER-88401 by adding them in execContext - produceTransferConfigOps(&instructions, + produceTransferConfigOps(vcc.Log, &instructions, nil, vdb.HostList, vdb /*db configurations retrieved from a running db*/) - nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newHosts, vdb) - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(newHosts, usePassword, username, password) + nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(vcc.Log, newHosts, vdb) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(vcc.Log, newHosts, usePassword, username, password) if err != nil { return instructions, err } @@ -407,17 +404,17 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba &httpsPollNodeStateOp, ) - return prepareAdditionalEonInstructions(vdb, options, instructions, + return vcc.prepareAdditionalEonInstructions(vdb, options, instructions, username, usePassword, initiatorHost, newHosts) } -func prepareAdditionalEonInstructions(vdb *VCoordinationDatabase, +func (vcc *VClusterCommands) prepareAdditionalEonInstructions(vdb *VCoordinationDatabase, options *VAddNodeOptions, instructions []ClusterOp, username string, usePassword bool, initiatorHost, newHosts []string) ([]ClusterOp, error) { if vdb.UseDepot { - httpsCreateNodesDepotOp, err := makeHTTPSCreateNodesDepotOp(vdb, + httpsCreateNodesDepotOp, err := makeHTTPSCreateNodesDepotOp(vcc.Log, vdb, newHosts, usePassword, username, options.Password) if err != nil { return instructions, err @@ -426,14 +423,14 @@ func prepareAdditionalEonInstructions(vdb *VCoordinationDatabase, } if vdb.IsEon { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(initiatorHost, true, username, options.Password) + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(vcc.Log, initiatorHost, true, username, options.Password) if err != nil { return instructions, err } instructions = append(instructions, &httpsSyncCatalogOp) if !*options.SkipRebalanceShards { httpsRBSCShardsOp, err := makeHTTPSRebalanceSubclusterShardsOp( - initiatorHost, usePassword, username, options.Password, *options.SCName) + vcc.Log, initiatorHost, usePassword, username, options.Password, *options.SCName) if err != nil { return instructions, err } diff --git a/vclusterops/add_subcluster.go b/vclusterops/add_subcluster.go index 05e0bfc..ddf840f 100644 --- a/vclusterops/add_subcluster.go +++ b/vclusterops/add_subcluster.go @@ -204,10 +204,9 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro return err } - instructions, err := produceAddSubclusterInstructions(&addSubclusterInfo, options) + instructions, err := vcc.produceAddSubclusterInstructions(&addSubclusterInfo, options) if err != nil { - vlog.LogPrintError("fail to produce instructions, %s", err) - return err + return fmt.Errorf("fail to produce instructions, %w", err) } // Create a VClusterOpEngine, and add certs to the engine @@ -217,8 +216,7 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro // Give the instructions to the VClusterOpEngine to run runError := clusterOpEngine.Run() if runError != nil { - vlog.LogPrintError("fail to add subcluster %s, %s", addSubclusterInfo.SCName, runError) - return runError + return fmt.Errorf("fail to add subcluster %s, %w", addSubclusterInfo.SCName, runError) } return nil @@ -235,33 +233,34 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro // if the subcluster name already exists or the db is an enterprise db // - Check if the new subcluster is created in database through HTTPS call // - TODO: add new nodes to the subcluster -func produceAddSubclusterInstructions(addSubclusterInfo *VAddSubclusterInfo, options *VAddSubclusterOptions) ([]ClusterOp, error) { +func (vcc *VClusterCommands) produceAddSubclusterInstructions(addSubclusterInfo *VAddSubclusterInfo, + options *VAddSubclusterOptions) ([]ClusterOp, error) { var instructions []ClusterOp // when password is specified, we will use username/password to call https endpoints usePassword := false if addSubclusterInfo.Password != nil { usePassword = true - err := options.ValidateUserName() + err := options.ValidateUserName(vcc) if err != nil { return instructions, err } } username := *options.UserName - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(addSubclusterInfo.DBName, addSubclusterInfo.Hosts, + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(vcc.Log, addSubclusterInfo.DBName, addSubclusterInfo.Hosts, usePassword, username, addSubclusterInfo.Password) if err != nil { return instructions, err } - httpsAddSubclusterOp, err := makeHTTPSAddSubclusterOp(usePassword, username, addSubclusterInfo.Password, + httpsAddSubclusterOp, err := makeHTTPSAddSubclusterOp(vcc.Log, usePassword, username, addSubclusterInfo.Password, addSubclusterInfo.SCName, addSubclusterInfo.IsPrimary, addSubclusterInfo.ControlSetSize) if err != nil { return instructions, err } - httpsCheckSubclusterOp, err := makeHTTPSCheckSubclusterOp(usePassword, username, addSubclusterInfo.Password, + httpsCheckSubclusterOp, err := makeHTTPSCheckSubclusterOp(vcc.Log, usePassword, username, addSubclusterInfo.Password, addSubclusterInfo.SCName, addSubclusterInfo.IsPrimary, addSubclusterInfo.ControlSetSize) if err != nil { return instructions, err diff --git a/vclusterops/cluster_op.go b/vclusterops/cluster_op.go index 057bd31..868ebbf 100644 --- a/vclusterops/cluster_op.go +++ b/vclusterops/cluster_op.go @@ -204,11 +204,10 @@ func (op *OpBase) getName() string { func (op *OpBase) parseAndCheckResponse(host, responseContent string, responseObj any) error { err := util.GetJSONLogErrors(responseContent, &responseObj, op.name) if err != nil { - vlog.LogError("[%s] fail to parse response on host %s, detail: %s", op.name, host, err) + op.log.Error(err, "fail to parse response on host %s", host) return err } - vlog.LogInfo("[%s] JSON response from %s is %+v\n", op.name, host, responseObj) - + op.log.Info("JSON response", "host", host, "responseObj", responseObj) return nil } @@ -226,26 +225,26 @@ func (op *OpBase) setVersionToSemVar() { // TODO: implement another parse function for list response func (op *OpBase) logResponse(host string, result HostHTTPResult) { - vlog.LogPrintInfo("[%s] result from host %s summary %s, details: %+v", + op.log.PrintInfo("[%s] result from host %s summary %s, details: %+v", op.name, host, result.status.getStatusString(), result) } func (op *OpBase) logPrepare() { - vlog.LogInfo("[%s] Prepare() called\n", op.name) + op.log.Info("Prepare() called", "name", op.name) } func (op *OpBase) logExecute() { - vlog.LogInfo("[%s] Execute() called\n", op.name) + op.log.Info("Execute() called", "name", op.name) } func (op *OpBase) logFinalize() { - vlog.LogInfo("[%s] Finalize() called\n", op.name) + op.log.Info("Finalize() called", "name", op.name) } func (op *OpBase) runExecute(execContext *OpEngineExecContext) error { err := execContext.dispatcher.sendRequest(&op.clusterHTTPRequest) if err != nil { - vlog.LogError("Fail to dispatch request %v", op.clusterHTTPRequest) + op.log.Error(err, "Fail to dispatch request %v", op.clusterHTTPRequest) return err } return nil @@ -287,7 +286,7 @@ func (op *OpBase) isSkipExecute() bool { func (op *OpBase) hasQuorum(hostCount, primaryNodeCount uint) bool { quorumCount := (primaryNodeCount + 1) / 2 if hostCount < quorumCount { - vlog.LogPrintError("[%s] Quorum check failed: "+ + op.log.PrintError("[%s] Quorum check failed: "+ "number of hosts with latest catalog (%d) is not "+ "greater than or equal to 1/2 of number of the primary nodes (%d)\n", op.name, hostCount, primaryNodeCount) diff --git a/vclusterops/create_db.go b/vclusterops/create_db.go index 7cf7f27..c475e2f 100644 --- a/vclusterops/create_db.go +++ b/vclusterops/create_db.go @@ -463,13 +463,13 @@ func (vcc *VClusterCommands) produceCreateDBBootstrapInstructions( hosts := vdb.HostList initiator := getInitiator(hosts) - nmaHealthOp := makeNMAHealthOp(hosts) + nmaHealthOp := makeNMAHealthOp(vcc.Log, hosts) // require to have the same vertica version nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, hosts, true) // need username for https operations - err := options.ValidateUserName() + err := options.ValidateUserName(vcc) if err != nil { return instructions, err } @@ -480,24 +480,24 @@ func (vcc *VClusterCommands) produceCreateDBBootstrapInstructions( return instructions, err } - nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(vdb.HostNodeMap, + nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(vcc.Log, vdb.HostNodeMap, *options.ForceRemovalAtCreation, false /*for db revive*/) if err != nil { return instructions, err } - nmaNetworkProfileOp := makeNMANetworkProfileOp(hosts) + nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, hosts) // should be only one bootstrap host // making it an array to follow the convention of passing a list of hosts to each operation bootstrapHost := []string{initiator} options.bootstrapHost = bootstrapHost - nmaBootstrapCatalogOp, err := makeNMABootstrapCatalogOp(vdb, options, bootstrapHost) + nmaBootstrapCatalogOp, err := makeNMABootstrapCatalogOp(vcc.Log, vdb, options, bootstrapHost) if err != nil { return instructions, err } - nmaReadCatalogEditorOp, err := makeNMAReadCatalogEditorOpWithInitiator(bootstrapHost, vdb) + nmaReadCatalogEditorOp, err := makeNMAReadCatalogEditorOpWithInitiator(vcc.Log, bootstrapHost, vdb) if err != nil { return instructions, err } @@ -518,9 +518,9 @@ func (vcc *VClusterCommands) produceCreateDBBootstrapInstructions( ) } - nmaStartNodeOp := makeNMAStartNodeOp(bootstrapHost) + nmaStartNodeOp := makeNMAStartNodeOp(vcc.Log, bootstrapHost) - httpsPollBootstrapNodeStateOp, err := makeHTTPSPollNodeStateOp(bootstrapHost, true, /* useHTTPPassword */ + httpsPollBootstrapNodeStateOp, err := makeHTTPSPollNodeStateOp(vcc.Log, bootstrapHost, true, /* useHTTPPassword */ *options.UserName, options.Password) if err != nil { return instructions, err @@ -545,7 +545,7 @@ func (vcc *VClusterCommands) produceCreateDBWorkerNodesInstructions( newNodeHosts := util.SliceDiff(hosts, bootstrapHost) if len(hosts) > 1 { - httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(newNodeHosts, bootstrapHost, + httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(vcc.Log, newNodeHosts, bootstrapHost, true /* use password auth */, *options.UserName, options.Password, vdb, "") if err != nil { return instructions, err @@ -553,7 +553,7 @@ func (vcc *VClusterCommands) produceCreateDBWorkerNodesInstructions( instructions = append(instructions, &httpsCreateNodeOp) } - httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(bootstrapHost, + httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(vcc.Log, bootstrapHost, true /* use password auth */, *options.UserName, options.Password) if err != nil { return instructions, err @@ -566,13 +566,13 @@ func (vcc *VClusterCommands) produceCreateDBWorkerNodesInstructions( } if len(hosts) > 1 { - httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(*options.DBName, bootstrapHost, + httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(vcc.Log, *options.DBName, bootstrapHost, true /* use password auth */, *options.UserName, options.Password, vdb) if err != nil { return instructions, err } - httpsStartUpCommandOp, err := makeHTTPSStartUpCommandOp(true, /*use https password*/ + httpsStartUpCommandOp, err := makeHTTPSStartUpCommandOp(vcc.Log, true, /*use https password*/ *options.UserName, options.Password, vdb) if err != nil { return instructions, err @@ -580,11 +580,12 @@ func (vcc *VClusterCommands) produceCreateDBWorkerNodesInstructions( instructions = append(instructions, &httpsGetNodesInfoOp, &httpsStartUpCommandOp) - produceTransferConfigOps(&instructions, + produceTransferConfigOps(vcc.Log, + &instructions, bootstrapHost, vdb.HostList, vdb /*db configurations retrieved from a running db*/) - nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newNodeHosts, vdb) + nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(vcc.Log, newNodeHosts, vdb) instructions = append(instructions, &nmaStartNewNodesOp) } @@ -601,7 +602,7 @@ func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordin username := *options.UserName if !*options.SkipStartupPolling { - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(hosts, true, username, options.Password) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(vcc.Log, hosts, true, username, options.Password) if err != nil { return instructions, err } @@ -609,7 +610,7 @@ func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordin } if vdb.UseDepot { - httpsCreateDepotOp, err := makeHTTPSCreateClusterDepotOp(vdb, bootstrapHost, true, username, options.Password) + httpsCreateDepotOp, err := makeHTTPSCreateClusterDepotOp(vcc.Log, vdb, bootstrapHost, true, username, options.Password) if err != nil { return instructions, err } @@ -617,7 +618,7 @@ func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordin } if len(hosts) >= ksafetyThreshold { - httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(bootstrapHost, true, username, + httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(vcc.Log, bootstrapHost, true, username, options.Password, ksafeValueOne) if err != nil { return instructions, err @@ -626,7 +627,7 @@ func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordin } if !*options.SkipPackageInstall { - httpsInstallPackagesOp, err := makeHTTPSInstallPackagesOp(bootstrapHost, true, username, options.Password) + httpsInstallPackagesOp, err := makeHTTPSInstallPackagesOp(vcc.Log, bootstrapHost, true, username, options.Password) if err != nil { return instructions, err } @@ -634,7 +635,7 @@ func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordin } if vdb.IsEon { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(bootstrapHost, true, username, options.Password) + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(vcc.Log, bootstrapHost, true, username, options.Password) if err != nil { return instructions, err } diff --git a/vclusterops/drop_db.go b/vclusterops/drop_db.go index 9688f51..7f32601 100644 --- a/vclusterops/drop_db.go +++ b/vclusterops/drop_db.go @@ -97,8 +97,7 @@ func (vcc *VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error // produce drop_db instructions instructions, err := vcc.produceDropDBInstructions(&vdb, options) if err != nil { - vcc.Log.PrintError("fail to produce instructions, %s", err) - return err + return fmt.Errorf("fail to produce instructions, %w", err) } // create a VClusterOpEngine, and add certs to the engine @@ -108,8 +107,7 @@ func (vcc *VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error // give the instructions to the VClusterOpEngine to run runError := clusterOpEngine.Run() if runError != nil { - vcc.Log.PrintError("fail to drop database: %s", runError) - return runError + return fmt.Errorf("fail to drop database: %w", runError) } // if the database is successfully dropped, the config file will be removed @@ -138,13 +136,13 @@ func (vcc *VClusterCommands) produceDropDBInstructions(vdb *VCoordinationDatabas usePassword := false if options.Password != nil { usePassword = true - err := options.ValidateUserName() + err := options.ValidateUserName(vcc) if err != nil { return instructions, err } } - nmaHealthOp := makeNMAHealthOp(hosts) + nmaHealthOp := makeNMAHealthOp(vcc.Log, hosts) // require to have the same vertica version nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, hosts, true) @@ -157,7 +155,7 @@ func (vcc *VClusterCommands) produceDropDBInstructions(vdb *VCoordinationDatabas return instructions, err } - nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(vdb, *options.ForceDelete) + nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(vcc.Log, vdb, *options.ForceDelete) if err != nil { return instructions, err } diff --git a/vclusterops/fetch_node_state.go b/vclusterops/fetch_node_state.go index 77ab08a..30b03a9 100644 --- a/vclusterops/fetch_node_state.go +++ b/vclusterops/fetch_node_state.go @@ -64,10 +64,9 @@ func (vcc *VClusterCommands) VFetchNodeState(options *VFetchNodeStateOptions) ([ // TODO: we need to support reading hosts from config for Go client // produce list_allnodes instructions - instructions, err := produceListAllNodesInstructions(options) + instructions, err := vcc.produceListAllNodesInstructions(options) if err != nil { - vlog.LogPrintError("fail to produce instructions, %s", err) - return nil, err + return nil, fmt.Errorf("fail to produce instructions, %w", err) } // create a VClusterOpEngine, and add certs to the engine @@ -83,7 +82,7 @@ func (vcc *VClusterCommands) VFetchNodeState(options *VFetchNodeStateOptions) ([ // produceListAllNodesInstructions will build a list of instructions to execute for // the fetch node state operation. -func produceListAllNodesInstructions(options *VFetchNodeStateOptions) ([]ClusterOp, error) { +func (vcc *VClusterCommands) produceListAllNodesInstructions(options *VFetchNodeStateOptions) ([]ClusterOp, error) { var instructions []ClusterOp // get hosts @@ -93,13 +92,13 @@ func produceListAllNodesInstructions(options *VFetchNodeStateOptions) ([]Cluster usePassword := false if options.Password != nil { usePassword = true - err := options.ValidateUserName() + err := options.ValidateUserName(vcc) if err != nil { return instructions, err } } - httpsCheckNodeStateOp, err := makeHTTPCheckNodeStateOp(hosts, + httpsCheckNodeStateOp, err := makeHTTPCheckNodeStateOp(vcc.Log, hosts, usePassword, *options.UserName, options.Password) if err != nil { return instructions, err diff --git a/vclusterops/helpers.go b/vclusterops/helpers.go index fa6cdcc..2be5e7b 100644 --- a/vclusterops/helpers.go +++ b/vclusterops/helpers.go @@ -35,17 +35,18 @@ const ( // produceTransferConfigOps generates instructions to transfert some config // files from a sourceConfig node to target nodes. -func produceTransferConfigOps(instructions *[]ClusterOp, sourceConfigHost, targetHosts []string, vdb *VCoordinationDatabase) { +func produceTransferConfigOps(log vlog.Printer, instructions *[]ClusterOp, sourceConfigHost, + targetHosts []string, vdb *VCoordinationDatabase) { var verticaConfContent string nmaDownloadVerticaConfigOp := makeNMADownloadConfigOp( - "NMADownloadVerticaConfigOp", sourceConfigHost, "config/vertica", &verticaConfContent, vdb) + log, "NMADownloadVerticaConfigOp", sourceConfigHost, "config/vertica", &verticaConfContent, vdb) nmaUploadVerticaConfigOp := makeNMAUploadConfigOp( - "NMAUploadVerticaConfigOp", sourceConfigHost, targetHosts, "config/vertica", &verticaConfContent, vdb) + log, "NMAUploadVerticaConfigOp", sourceConfigHost, targetHosts, "config/vertica", &verticaConfContent, vdb) var spreadConfContent string nmaDownloadSpreadConfigOp := makeNMADownloadConfigOp( - "NMADownloadSpreadConfigOp", sourceConfigHost, "config/spread", &spreadConfContent, vdb) + log, "NMADownloadSpreadConfigOp", sourceConfigHost, "config/spread", &spreadConfContent, vdb) nmaUploadSpreadConfigOp := makeNMAUploadConfigOp( - "NMAUploadSpreadConfigOp", sourceConfigHost, targetHosts, "config/spread", &spreadConfContent, vdb) + log, "NMAUploadSpreadConfigOp", sourceConfigHost, targetHosts, "config/spread", &spreadConfContent, vdb) *instructions = append(*instructions, &nmaDownloadVerticaConfigOp, &nmaUploadVerticaConfigOp, @@ -100,25 +101,22 @@ func getInitiatorHost(primaryUpNodes, hostsToSkip []string) (string, error) { } // getVDBFromRunningDB will retrieve db configurations by calling https endpoints of a running db -func getVDBFromRunningDB(vdb *VCoordinationDatabase, options *DatabaseOptions) error { - err := options.SetUsePassword() +func (vcc *VClusterCommands) getVDBFromRunningDB(vdb *VCoordinationDatabase, options *DatabaseOptions) error { + err := options.SetUsePassword(vcc) if err != nil { - vlog.LogPrintError("fail to set userPassword while retrieving database configurations, %v", err) - return err + return fmt.Errorf("fail to set userPassword while retrieving database configurations, %w", err) } - httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(*options.DBName, options.Hosts, + httpsGetNodesInfoOp, err := makeHTTPSGetNodesInfoOp(vcc.Log, *options.DBName, options.Hosts, options.usePassword, *options.UserName, options.Password, vdb) if err != nil { - vlog.LogPrintError("fail to produce httpsGetNodesInfo instructions while retrieving database configurations, %v", err) - return err + return fmt.Errorf("fail to produce httpsGetNodesInfo instructions while retrieving database configurations, %w", err) } - httpsGetClusterInfoOp, err := makeHTTPSGetClusterInfoOp(*options.DBName, options.Hosts, + httpsGetClusterInfoOp, err := makeHTTPSGetClusterInfoOp(vcc.Log, *options.DBName, options.Hosts, options.usePassword, *options.UserName, options.Password, vdb) if err != nil { - vlog.LogPrintError("fail to produce httpsGetClusterInfo instructions while retrieving database configurations, %v", err) - return err + return fmt.Errorf("fail to produce httpsGetClusterInfo instructions while retrieving database configurations, %w", err) } var instructions []ClusterOp @@ -128,8 +126,7 @@ func getVDBFromRunningDB(vdb *VCoordinationDatabase, options *DatabaseOptions) e clusterOpEngine := MakeClusterOpEngine(instructions, &certs) err = clusterOpEngine.Run() if err != nil { - vlog.LogPrintError("fail to retrieve database configurations, %v", err) - return err + return fmt.Errorf("fail to retrieve database configurations, %w", err) } return nil diff --git a/vclusterops/https_add_subcluster_op.go b/vclusterops/https_add_subcluster_op.go index 546cce1..15bc606 100644 --- a/vclusterops/https_add_subcluster_op.go +++ b/vclusterops/https_add_subcluster_op.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSAddSubclusterOp struct { @@ -32,11 +33,12 @@ type HTTPSAddSubclusterOp struct { ctlSetSize int } -func makeHTTPSAddSubclusterOp(useHTTPPassword bool, userName string, httpsPassword *string, +func makeHTTPSAddSubclusterOp(log vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string, scName string, isPrimary bool, ctlSetSize int) (HTTPSAddSubclusterOp, error) { httpsAddSubclusterOp := HTTPSAddSubclusterOp{} httpsAddSubclusterOp.name = "HTTPSAddSubclusterOp" httpsAddSubclusterOp.scName = scName + httpsAddSubclusterOp.log = log.WithName(httpsAddSubclusterOp.name) httpsAddSubclusterOp.isSecondary = !isPrimary httpsAddSubclusterOp.ctlSetSize = ctlSetSize diff --git a/vclusterops/https_check_node_state_op.go b/vclusterops/https_check_node_state_op.go index 10c5042..54fad70 100644 --- a/vclusterops/https_check_node_state_op.go +++ b/vclusterops/https_check_node_state_op.go @@ -28,12 +28,13 @@ type HTTPCheckNodeStateOp struct { OpHTTPSBase } -func makeHTTPCheckNodeStateOp(hosts []string, +func makeHTTPCheckNodeStateOp(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, ) (HTTPCheckNodeStateOp, error) { nodeStateChecker := HTTPCheckNodeStateOp{} + nodeStateChecker.log = log.WithName(nodeStateChecker.name) nodeStateChecker.name = "HTTPCheckNodeStateOp" // The hosts are the ones we are going to talk to. // They can be a subset of the actual host information that we return, @@ -92,7 +93,7 @@ func (op *HTTPCheckNodeStateOp) processResult(execContext *OpEngineExecContext) op.logResponse(host, result) if result.IsUnauthorizedRequest() { - vlog.LogPrintError("[%s] unauthorized request: %s", op.name, result.content) + op.log.PrintError("[%s] unauthorized request: %s", op.name, result.content) // return here because we assume that // we will get the same error across other nodes allErrs = errors.Join(allErrs, result.err) diff --git a/vclusterops/https_check_subcluster_op.go b/vclusterops/https_check_subcluster_op.go index deb93ac..ccff427 100644 --- a/vclusterops/https_check_subcluster_op.go +++ b/vclusterops/https_check_subcluster_op.go @@ -19,6 +19,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSCheckSubclusterOp struct { @@ -29,10 +30,11 @@ type HTTPSCheckSubclusterOp struct { ctlSetSize int } -func makeHTTPSCheckSubclusterOp(useHTTPPassword bool, userName string, httpsPassword *string, +func makeHTTPSCheckSubclusterOp(log vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string, scName string, isPrimary bool, ctlSetSize int) (HTTPSCheckSubclusterOp, error) { httpsCheckSubclusterOp := HTTPSCheckSubclusterOp{} httpsCheckSubclusterOp.name = "HTTPSCheckSubclusterOp" + httpsCheckSubclusterOp.log = log.WithName(httpsCheckSubclusterOp.name) httpsCheckSubclusterOp.scName = scName httpsCheckSubclusterOp.isSecondary = !isPrimary httpsCheckSubclusterOp.ctlSetSize = ctlSetSize diff --git a/vclusterops/https_create_cluster_depot_op.go b/vclusterops/https_create_cluster_depot_op.go index 5010098..71f84ce 100644 --- a/vclusterops/https_create_cluster_depot_op.go +++ b/vclusterops/https_create_cluster_depot_op.go @@ -22,6 +22,7 @@ import ( "golang.org/x/exp/slices" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSCreateDepotOp struct { @@ -31,10 +32,11 @@ type HTTPSCreateDepotOp struct { RequestParams map[string]string } -func makeHTTPSCreateClusterDepotOp(vdb *VCoordinationDatabase, hosts []string, +func makeHTTPSCreateClusterDepotOp(log vlog.Printer, vdb *VCoordinationDatabase, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSCreateDepotOp, error) { httpsCreateDepotOp := HTTPSCreateDepotOp{} httpsCreateDepotOp.name = "HTTPSCreateDepotOp" + httpsCreateDepotOp.log = log.WithName(httpsCreateDepotOp.name) httpsCreateDepotOp.hosts = hosts httpsCreateDepotOp.useHTTPPassword = useHTTPPassword diff --git a/vclusterops/https_create_node_op.go b/vclusterops/https_create_node_op.go index 3dcefb0..2e0b5ca 100644 --- a/vclusterops/https_create_node_op.go +++ b/vclusterops/https_create_node_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSCreateNodeOp struct { @@ -28,11 +29,12 @@ type HTTPSCreateNodeOp struct { RequestParams map[string]string } -func makeHTTPSCreateNodeOp(hosts []string, bootstrapHost []string, +func makeHTTPSCreateNodeOp(log vlog.Printer, hosts []string, bootstrapHost []string, useHTTPPassword bool, userName string, httpsPassword *string, vdb *VCoordinationDatabase, scName string) (HTTPSCreateNodeOp, error) { createNodeOp := HTTPSCreateNodeOp{} createNodeOp.name = "HTTPSCreateNodeOp" + createNodeOp.log = log.WithName(createNodeOp.name) createNodeOp.hosts = bootstrapHost createNodeOp.RequestParams = make(map[string]string) // HTTPS create node endpoint requires passing everything before node name diff --git a/vclusterops/https_create_nodes_depot_op.go b/vclusterops/https_create_nodes_depot_op.go index 4c1dee7..21caa7c 100644 --- a/vclusterops/https_create_nodes_depot_op.go +++ b/vclusterops/https_create_nodes_depot_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSCreateNodesDepotOp struct { @@ -30,11 +31,12 @@ type HTTPSCreateNodesDepotOp struct { } // makeHTTPSCreateNodesDepotOp will make an op that call vertica-http service to create depot for the new nodes -func makeHTTPSCreateNodesDepotOp(vdb *VCoordinationDatabase, nodes []string, +func makeHTTPSCreateNodesDepotOp(log vlog.Printer, vdb *VCoordinationDatabase, nodes []string, useHTTPPassword bool, userName string, httpsPassword *string, ) (HTTPSCreateNodesDepotOp, error) { httpsCreateNodesDepotOp := HTTPSCreateNodesDepotOp{} httpsCreateNodesDepotOp.name = "HTTPSCreateNodesDepotOp" + httpsCreateNodesDepotOp.log = log.WithName(httpsCreateNodesDepotOp.name) httpsCreateNodesDepotOp.hosts = nodes httpsCreateNodesDepotOp.useHTTPPassword = useHTTPPassword httpsCreateNodesDepotOp.HostNodeMap = vdb.HostNodeMap diff --git a/vclusterops/https_drop_node_op.go b/vclusterops/https_drop_node_op.go index fbf7f3b..d60817b 100644 --- a/vclusterops/https_drop_node_op.go +++ b/vclusterops/https_drop_node_op.go @@ -19,6 +19,7 @@ import ( "errors" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSDropNodeOp struct { @@ -28,7 +29,7 @@ type HTTPSDropNodeOp struct { RequestParams map[string]string } -func makeHTTPSDropNodeOp(vnode string, +func makeHTTPSDropNodeOp(log vlog.Printer, vnode string, initiatorHost []string, useHTTPPassword bool, userName string, @@ -36,6 +37,7 @@ func makeHTTPSDropNodeOp(vnode string, isEon bool) (HTTPSDropNodeOp, error) { dropNodeOp := HTTPSDropNodeOp{} dropNodeOp.name = "HTTPSDropNodeOp" + dropNodeOp.log = log.WithName(dropNodeOp.name) dropNodeOp.hosts = initiatorHost dropNodeOp.targetHost = vnode dropNodeOp.useHTTPPassword = useHTTPPassword diff --git a/vclusterops/https_find_subcluster_op.go b/vclusterops/https_find_subcluster_op.go index dc6b96f..b51a342 100644 --- a/vclusterops/https_find_subcluster_op.go +++ b/vclusterops/https_find_subcluster_op.go @@ -33,12 +33,13 @@ type HTTPSFindSubclusterOp struct { // a subcluster by name and find the default subcluster. // When ignoreNotFound is true, the op will not error out if // the given cluster name is not found. -func makeHTTPSFindSubclusterOp(hosts []string, useHTTPPassword bool, +func makeHTTPSFindSubclusterOp(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, scName string, ignoreNotFound bool, ) (HTTPSFindSubclusterOp, error) { op := HTTPSFindSubclusterOp{} op.name = "HTTPSFindSubclusterOp" + op.log = log.WithName(op.name) op.hosts = hosts op.scName = scName op.ignoreNotFound = ignoreNotFound @@ -146,13 +147,13 @@ func (op *HTTPSFindSubclusterOp) processResult(execContext *OpEngineExecContext) for _, scInfo := range scResp.SCInfoList { if scInfo.SCName == op.scName { foundNamedSc = true - vlog.LogInfo(`[%s] subcluster '%s' exists in the database`, op.name, scInfo.SCName) + op.log.Info(`subcluster exists in the database`, "subcluster", scInfo.SCName, "dbName", op.name) } if scInfo.IsDefault { // store the default sc name into execContext foundDefaultSc = true execContext.defaultSCName = scInfo.SCName - vlog.LogInfo(`[%s] found default subcluster '%s' in the database`, op.name, scInfo.SCName) + op.log.Info(`found default subcluster in the database`, "subcluster", scInfo.SCName, "dbName", op.name) } if foundNamedSc && foundDefaultSc { break diff --git a/vclusterops/https_get_cluster_info_op.go b/vclusterops/https_get_cluster_info_op.go index 150b53b..fbd657e 100644 --- a/vclusterops/https_get_cluster_info_op.go +++ b/vclusterops/https_get_cluster_info_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type httpsGetClusterInfoOp struct { @@ -29,11 +30,12 @@ type httpsGetClusterInfoOp struct { vdb *VCoordinationDatabase } -func makeHTTPSGetClusterInfoOp(dbName string, hosts []string, +func makeHTTPSGetClusterInfoOp(log vlog.Printer, dbName string, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, vdb *VCoordinationDatabase, ) (httpsGetClusterInfoOp, error) { op := httpsGetClusterInfoOp{} op.name = "HTTPSGetClusterInfoOp" + op.log = log.WithName(op.name) op.dbName = dbName op.hosts = hosts op.vdb = vdb diff --git a/vclusterops/https_get_nodes_info_op.go b/vclusterops/https_get_nodes_info_op.go index 24d18d0..4b9090e 100644 --- a/vclusterops/https_get_nodes_info_op.go +++ b/vclusterops/https_get_nodes_info_op.go @@ -31,11 +31,12 @@ type httpsGetNodesInfoOp struct { vdb *VCoordinationDatabase } -func makeHTTPSGetNodesInfoOp(dbName string, hosts []string, +func makeHTTPSGetNodesInfoOp(log vlog.Printer, dbName string, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, vdb *VCoordinationDatabase, ) (httpsGetNodesInfoOp, error) { op := httpsGetNodesInfoOp{} op.name = "HTTPSGetNodeInfoOp" + op.log = log.WithName(op.name) op.dbName = dbName op.hosts = hosts op.vdb = vdb @@ -123,7 +124,7 @@ func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error { dbPath := "/" + node.Database index := strings.Index(node.CatalogPath, dbPath) if index == -1 { - vlog.LogPrintWarning("[%s] failed to get catalog prefix because catalog path %s does not contain database name %s", + op.log.PrintWarning("[%s] failed to get catalog prefix because catalog path %s does not contain database name %s", op.name, node.CatalogPath, node.Database) } op.vdb.CatalogPrefix = node.CatalogPath[:index] diff --git a/vclusterops/https_get_up_nodes_op.go b/vclusterops/https_get_up_nodes_op.go index fa07a1c..f9449c7 100644 --- a/vclusterops/https_get_up_nodes_op.go +++ b/vclusterops/https_get_up_nodes_op.go @@ -30,11 +30,12 @@ type HTTPSGetUpNodesOp struct { DBName string } -func makeHTTPSGetUpNodesOp(dbName string, hosts []string, +func makeHTTPSGetUpNodesOp(log vlog.Printer, dbName string, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, ) (HTTPSGetUpNodesOp, error) { httpsGetUpNodesOp := HTTPSGetUpNodesOp{} httpsGetUpNodesOp.name = "HTTPSGetUpNodesOp" + httpsGetUpNodesOp.log = log.WithName(httpsGetUpNodesOp.name) httpsGetUpNodesOp.hosts = hosts httpsGetUpNodesOp.useHTTPPassword = useHTTPPassword httpsGetUpNodesOp.DBName = dbName @@ -170,11 +171,11 @@ func (op *HTTPSGetUpNodesOp) processResult(execContext *OpEngineExecContext) err } if len(exceptionHosts) > 0 { - vlog.LogPrintError(`[%s] fail to call https endpoint of database %s on hosts %s`, op.name, op.DBName, exceptionHosts) + op.log.PrintError(`[%s] fail to call https endpoint of database %s on hosts %s`, op.name, op.DBName, exceptionHosts) } if len(downHosts) > 0 { - vlog.LogPrintError(`[%s] did not detect database %s running on hosts %v`, op.name, op.DBName, downHosts) + op.log.PrintError(`[%s] did not detect database %s running on hosts %v`, op.name, op.DBName, downHosts) } return errors.Join(allErrs, fmt.Errorf("no up nodes detected")) diff --git a/vclusterops/https_install_packages.go b/vclusterops/https_install_packages.go index b8fd23d..246e2d2 100644 --- a/vclusterops/https_install_packages.go +++ b/vclusterops/https_install_packages.go @@ -28,11 +28,12 @@ type HTTPSInstallPackagesOp struct { OpHTTPSBase } -func makeHTTPSInstallPackagesOp(hosts []string, useHTTPPassword bool, +func makeHTTPSInstallPackagesOp(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, ) (HTTPSInstallPackagesOp, error) { installPackagesOp := HTTPSInstallPackagesOp{} installPackagesOp.name = "HTTPSInstallPackagesOp" + installPackagesOp.log = log.WithName(installPackagesOp.name) installPackagesOp.hosts = hosts err := util.ValidateUsernameAndPassword(installPackagesOp.name, useHTTPPassword, userName) @@ -126,7 +127,7 @@ func (op *HTTPSInstallPackagesOp) processResult(_ *OpEngineExecContext) error { allErrs = errors.Join(allErrs, err) } - vlog.LogPrintInfo("[%s] installed packages: %v", op.name, installedPackages) + op.log.PrintInfo("[%s] installed packages: %v", op.name, installedPackages) } return allErrs } diff --git a/vclusterops/https_mark_design_ksafe_op.go b/vclusterops/https_mark_design_ksafe_op.go index c996cad..a9f1c33 100644 --- a/vclusterops/https_mark_design_ksafe_op.go +++ b/vclusterops/https_mark_design_ksafe_op.go @@ -35,6 +35,7 @@ type HTTPSMarkDesignKSafeOp struct { } func makeHTTPSMarkDesignKSafeOp( + log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, @@ -43,6 +44,7 @@ func makeHTTPSMarkDesignKSafeOp( ) (HTTPSMarkDesignKSafeOp, error) { httpsMarkDesignKSafeOp := HTTPSMarkDesignKSafeOp{} httpsMarkDesignKSafeOp.name = "HTTPSMarkDesignKsafeOp" + httpsMarkDesignKSafeOp.log = log.WithName(httpsMarkDesignKSafeOp.name) httpsMarkDesignKSafeOp.hosts = hosts httpsMarkDesignKSafeOp.useHTTPPassword = useHTTPPassword @@ -147,7 +149,7 @@ func (op *HTTPSMarkDesignKSafeOp) processResult(_ *OpEngineExecContext) error { continue } - vlog.LogPrintInfo(`[%s] The K-safety value of the database is set as %d`, op.name, ksafeValue) + op.log.PrintInfo(`[%s] The K-safety value of the database is set as %d`, op.name, ksafeValue) } return allErrs diff --git a/vclusterops/https_mark_nodes_ephemeral_op.go b/vclusterops/https_mark_nodes_ephemeral_op.go index 899d340..a03c1bd 100644 --- a/vclusterops/https_mark_nodes_ephemeral_op.go +++ b/vclusterops/https_mark_nodes_ephemeral_op.go @@ -19,6 +19,7 @@ import ( "errors" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSMarkEphemeralNodeOp struct { @@ -27,13 +28,14 @@ type HTTPSMarkEphemeralNodeOp struct { targetNodeName string } -func makeHTTPSMarkEphemeralNodeOp(nodeName string, +func makeHTTPSMarkEphemeralNodeOp(log vlog.Printer, nodeName string, initiatorHost []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSMarkEphemeralNodeOp, error) { op := HTTPSMarkEphemeralNodeOp{} op.name = "HTTPSMarkEphemeralNodeOp" + op.log = log.WithName(op.name) op.hosts = initiatorHost op.targetNodeName = nodeName op.useHTTPPassword = useHTTPPassword diff --git a/vclusterops/https_poll_node_state_op.go b/vclusterops/https_poll_node_state_op.go index 638169f..8b3cad6 100644 --- a/vclusterops/https_poll_node_state_op.go +++ b/vclusterops/https_poll_node_state_op.go @@ -56,10 +56,11 @@ type HTTPSPollNodeStateOp struct { cmdType CmdType } -func makeHTTPSPollNodeStateOpHelper(hosts []string, +func makeHTTPSPollNodeStateOpHelper(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSPollNodeStateOp, error) { httpsPollNodeStateOp := HTTPSPollNodeStateOp{} httpsPollNodeStateOp.name = "HTTPSPollNodeStateOp" + httpsPollNodeStateOp.log = log.WithName(httpsPollNodeStateOp.name) httpsPollNodeStateOp.hosts = hosts httpsPollNodeStateOp.useHTTPPassword = useHTTPPassword @@ -78,10 +79,10 @@ func makeHTTPSPollNodeStateOpHelper(hosts []string, return httpsPollNodeStateOp, nil } -func makeHTTPSPollNodeStateOpWithTimeoutAndCommand(hosts []string, +func makeHTTPSPollNodeStateOpWithTimeoutAndCommand(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, timeout int, cmdType CmdType) (HTTPSPollNodeStateOp, error) { - op, err := makeHTTPSPollNodeStateOpHelper(hosts, useHTTPPassword, userName, httpsPassword) + op, err := makeHTTPSPollNodeStateOpHelper(log, hosts, useHTTPPassword, userName, httpsPassword) if err != nil { return op, err } @@ -90,10 +91,10 @@ func makeHTTPSPollNodeStateOpWithTimeoutAndCommand(hosts []string, return op, nil } -func makeHTTPSPollNodeStateOp(hosts []string, +func makeHTTPSPollNodeStateOp(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSPollNodeStateOp, error) { - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpHelper(hosts, useHTTPPassword, userName, httpsPassword) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpHelper(log, hosts, useHTTPPassword, userName, httpsPassword) if err != nil { return httpsPollNodeStateOp, err } @@ -159,7 +160,6 @@ func (op *HTTPSPollNodeStateOp) processResult(execContext *OpEngineExecContext) vlog.LogPrintError(msg) return errors.New(msg) } - return nil } @@ -192,7 +192,7 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { if result.IsPasswordAndCertificateError() { switch op.cmdType { case StartDBCmd, RestartNodeCmd: - vlog.LogPrintError("[%s] The credentials are incorrect. 'Catalog Sync' will not be executed.", + op.log.PrintError("[%s] The credentials are incorrect. 'Catalog Sync' will not be executed.", op.name) return true, fmt.Errorf("[%s] wrong password/certificate for https service on host %s, but the nodes' startup have been in progress."+ "Please use vsql to check the nodes' status and manually run sync_catalog vsql command 'select sync_catalog()'", op.name, host) @@ -205,7 +205,7 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { nodesInfo := NodesInfo{} err := op.parseAndCheckResponse(host, result.content, &nodesInfo) if err != nil { - vlog.LogPrintError("[%s] fail to parse result on host %s, details: %s", + op.log.PrintError("[%s] fail to parse result on host %s, details: %s", op.name, host, err) return true, err } @@ -230,6 +230,6 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { return false, nil } - vlog.LogPrintInfoln("All nodes are up") + op.log.PrintInfo("All nodes are up") return true, nil } diff --git a/vclusterops/https_poll_node_state_op_test.go b/vclusterops/https_poll_node_state_op_test.go index e78730a..866634c 100644 --- a/vclusterops/https_poll_node_state_op_test.go +++ b/vclusterops/https_poll_node_state_op_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/vertica/vcluster/vclusterops/vlog" ) func TestTimeoutCase(t *testing.T) { @@ -28,7 +29,7 @@ func TestTimeoutCase(t *testing.T) { hosts := []string{"192.0.2.1"} username := "testUser" password := "testPwd" - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(hosts, true, username, &password) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(vlog.Printer{}, hosts, true, username, &password) assert.Nil(t, err) instructions = append(instructions, &httpsPollNodeStateOp) diff --git a/vclusterops/https_poll_subscription_state_op.go b/vclusterops/https_poll_subscription_state_op.go index 5cec8e7..5aa9348 100644 --- a/vclusterops/https_poll_subscription_state_op.go +++ b/vclusterops/https_poll_subscription_state_op.go @@ -153,7 +153,7 @@ func (op *httpsPollSubscriptionStateOp) shouldStopPolling() (bool, error) { } } - op.log.PrintInfo("All subscriptions are ACTIVE\n") + op.log.PrintInfo("All subscriptions are ACTIVE") return true, nil } } diff --git a/vclusterops/https_rebalance_cluster_op.go b/vclusterops/https_rebalance_cluster_op.go index 870008f..6e35d16 100644 --- a/vclusterops/https_rebalance_cluster_op.go +++ b/vclusterops/https_rebalance_cluster_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) const RebalanceClusterSuccMsg = "REBALANCED" @@ -31,10 +32,11 @@ type HTTPSRebalanceClusterOp struct { } // makeHTTPSRebalanceClusterOp will make an op that call vertica-http service to rebalance the cluster -func makeHTTPSRebalanceClusterOp(initiatorHost []string, useHTTPPassword bool, userName string, +func makeHTTPSRebalanceClusterOp(log vlog.Printer, initiatorHost []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSRebalanceClusterOp, error) { httpsRBCOp := HTTPSRebalanceClusterOp{} httpsRBCOp.name = "HTTPSRebalanceClusterOp" + httpsRBCOp.log = log.WithName(httpsRBCOp.name) httpsRBCOp.hosts = initiatorHost httpsRBCOp.useHTTPPassword = useHTTPPassword diff --git a/vclusterops/https_rebalance_subcluster_shards_op.go b/vclusterops/https_rebalance_subcluster_shards_op.go index 8cbb4db..11fb204 100644 --- a/vclusterops/https_rebalance_subcluster_shards_op.go +++ b/vclusterops/https_rebalance_subcluster_shards_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) const HTTPSSuccMsg = "REBALANCED SHARDS" @@ -31,10 +32,11 @@ type HTTPSRebalanceSubclusterShardsOp struct { } // makeHTTPSRebalanceSubclusterShardsOp creates an op that calls vertica-http service to rebalance shards of a subcluster -func makeHTTPSRebalanceSubclusterShardsOp(bootstrapHost []string, useHTTPPassword bool, userName string, +func makeHTTPSRebalanceSubclusterShardsOp(log vlog.Printer, bootstrapHost []string, useHTTPPassword bool, userName string, httpsPassword *string, scName string) (HTTPSRebalanceSubclusterShardsOp, error) { httpsRBSCShardsOp := HTTPSRebalanceSubclusterShardsOp{} httpsRBSCShardsOp.name = "HTTPSRebalanceSubclusterShardsOp" + httpsRBSCShardsOp.log = log.WithName(httpsRBSCShardsOp.name) httpsRBSCShardsOp.hosts = bootstrapHost httpsRBSCShardsOp.scName = scName diff --git a/vclusterops/https_reload_spread_op.go b/vclusterops/https_reload_spread_op.go index f730f24..60685f6 100644 --- a/vclusterops/https_reload_spread_op.go +++ b/vclusterops/https_reload_spread_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSReloadSpreadOp struct { @@ -27,11 +28,12 @@ type HTTPSReloadSpreadOp struct { OpHTTPSBase } -func makeHTTPSReloadSpreadOpWithInitiator(initHosts []string, +func makeHTTPSReloadSpreadOpWithInitiator(log vlog.Printer, initHosts []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSReloadSpreadOp, error) { httpsReloadSpreadOp := HTTPSReloadSpreadOp{} httpsReloadSpreadOp.name = "HTTPSReloadSpreadOp" + httpsReloadSpreadOp.log = log.WithName(httpsReloadSpreadOp.name) httpsReloadSpreadOp.hosts = initHosts httpsReloadSpreadOp.useHTTPPassword = useHTTPPassword @@ -44,9 +46,9 @@ func makeHTTPSReloadSpreadOpWithInitiator(initHosts []string, return httpsReloadSpreadOp, nil } -func makeHTTPSReloadSpreadOp(useHTTPPassword bool, +func makeHTTPSReloadSpreadOp(log vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSReloadSpreadOp, error) { - return makeHTTPSReloadSpreadOpWithInitiator(nil, useHTTPPassword, userName, httpsPassword) + return makeHTTPSReloadSpreadOpWithInitiator(log, nil, useHTTPPassword, userName, httpsPassword) } func (op *HTTPSReloadSpreadOp) setupClusterHTTPRequest(hosts []string) error { diff --git a/vclusterops/https_spread_remove_node_op.go b/vclusterops/https_spread_remove_node_op.go index 5b08e9d..6ba31ce 100644 --- a/vclusterops/https_spread_remove_node_op.go +++ b/vclusterops/https_spread_remove_node_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSSpreadRemoveNodeOp struct { @@ -28,10 +29,11 @@ type HTTPSSpreadRemoveNodeOp struct { RequestParams map[string]string } -func makeHTTPSSpreadRemoveNodeOp(hostsToRemove []string, initiatorHost []string, useHTTPPassword bool, +func makeHTTPSSpreadRemoveNodeOp(log vlog.Printer, hostsToRemove []string, initiatorHost []string, useHTTPPassword bool, userName string, httpsPassword *string, hostNodeMap vHostNodeMap) (HTTPSSpreadRemoveNodeOp, error) { op := HTTPSSpreadRemoveNodeOp{} op.name = "HTTPSSpreadRemoveNodeOp" + op.log = log.WithName(op.name) op.hosts = initiatorHost op.useHTTPPassword = useHTTPPassword diff --git a/vclusterops/https_startup_command_op.go b/vclusterops/https_startup_command_op.go index f47b35e..8b5b96d 100644 --- a/vclusterops/https_startup_command_op.go +++ b/vclusterops/https_startup_command_op.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type httpsStartUpCommandOp struct { @@ -28,10 +29,11 @@ type httpsStartUpCommandOp struct { vdb *VCoordinationDatabase } -func makeHTTPSStartUpCommandOp(useHTTPPassword bool, userName string, httpsPassword *string, +func makeHTTPSStartUpCommandOp(log vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string, vdb *VCoordinationDatabase) (httpsStartUpCommandOp, error) { op := httpsStartUpCommandOp{} op.name = "HTTPSStartUpCommandOp" + op.log = log.WithName(op.name) op.useHTTPPassword = useHTTPPassword op.vdb = vdb diff --git a/vclusterops/https_stop_db_op.go b/vclusterops/https_stop_db_op.go index 36f24b2..81baaa7 100644 --- a/vclusterops/https_stop_db_op.go +++ b/vclusterops/https_stop_db_op.go @@ -22,6 +22,7 @@ import ( "strconv" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type HTTPSStopDBOp struct { @@ -30,10 +31,11 @@ type HTTPSStopDBOp struct { RequestParams map[string]string } -func makeHTTPSStopDBOp(useHTTPPassword bool, userName string, +func makeHTTPSStopDBOp(log vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string, timeout *int) (HTTPSStopDBOp, error) { httpsStopDBOp := HTTPSStopDBOp{} httpsStopDBOp.name = "HTTPSStopDBOp" + httpsStopDBOp.log = log.WithName(httpsStopDBOp.name) httpsStopDBOp.useHTTPPassword = useHTTPPassword // set the query params, "timeout" is optional diff --git a/vclusterops/https_sync_catalog_op.go b/vclusterops/https_sync_catalog_op.go index 9a8b105..43f4921 100644 --- a/vclusterops/https_sync_catalog_op.go +++ b/vclusterops/https_sync_catalog_op.go @@ -29,10 +29,11 @@ type HTTPSSyncCatalogOp struct { OpHTTPSBase } -func makeHTTPSSyncCatalogOp(hosts []string, useHTTPPassword bool, +func makeHTTPSSyncCatalogOp(log vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSSyncCatalogOp, error) { op := HTTPSSyncCatalogOp{} op.name = "HTTPSSyncCatalogOp" + op.log = log.WithName(op.name) op.hosts = hosts op.useHTTPPassword = useHTTPPassword @@ -46,9 +47,9 @@ func makeHTTPSSyncCatalogOp(hosts []string, useHTTPPassword bool, return op, nil } -func makeHTTPSSyncCatalogOpWithoutHosts(useHTTPPassword bool, +func makeHTTPSSyncCatalogOpWithoutHosts(log vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSSyncCatalogOp, error) { - return makeHTTPSSyncCatalogOp(nil, useHTTPPassword, userName, httpsPassword) + return makeHTTPSSyncCatalogOp(log, nil, useHTTPPassword, userName, httpsPassword) } func (op *HTTPSSyncCatalogOp) setupClusterHTTPRequest(hosts []string) error { @@ -114,7 +115,7 @@ func (op *HTTPSSyncCatalogOp) processResult(_ *OpEngineExecContext) error { err = fmt.Errorf(`[%s] response does not contain field "new_truncation_version"`, op.name) allErrs = errors.Join(allErrs, err) } - vlog.LogPrintInfo(`[%s] the_latest_truncation_catalog_version: %s"`, op.name, version) + op.log.PrintInfo(`[%s] the_latest_truncation_catalog_version: %s"`, op.name, version) } else { allErrs = errors.Join(allErrs, result.err) } diff --git a/vclusterops/nma_bootstrap_catalog_op.go b/vclusterops/nma_bootstrap_catalog_op.go index 438eddf..ed1d559 100644 --- a/vclusterops/nma_bootstrap_catalog_op.go +++ b/vclusterops/nma_bootstrap_catalog_op.go @@ -51,11 +51,13 @@ type bootstrapCatalogRequestData struct { } func makeNMABootstrapCatalogOp( + log vlog.Printer, vdb *VCoordinationDatabase, options *VCreateDatabaseOptions, bootstrapHosts []string) (NMABootstrapCatalogOp, error) { nmaBootstrapCatalogOp := NMABootstrapCatalogOp{} nmaBootstrapCatalogOp.name = "NMABootstrapCatalogOp" + nmaBootstrapCatalogOp.log = log.WithName(nmaBootstrapCatalogOp.name) // usually, only one node need bootstrap catalog nmaBootstrapCatalogOp.hosts = bootstrapHosts @@ -128,7 +130,7 @@ func (op *NMABootstrapCatalogOp) updateRequestBody(execContext *OpEngineExecCont dataBytes, err := json.Marshal(op.hostRequestBodyMap[host]) if err != nil { - vlog.LogError(`[%s] fail to marshal request data to JSON string, detail %s`, op.name, err) + op.log.Error(err, `[%s] fail to marshal request data to JSON string`, op.name) return err } op.marshaledRequestBodyMap[host] = string(dataBytes) @@ -138,7 +140,7 @@ func (op *NMABootstrapCatalogOp) updateRequestBody(execContext *OpEngineExecCont maskedData.maskSensitiveInfo() maskedRequestBodyMap[host] = maskedData } - vlog.LogInfo("[%s] request data: %+v\n", op.name, maskedRequestBodyMap) + op.log.Info("request data", "opName", op.name, "bodyMap", maskedRequestBodyMap) return nil } diff --git a/vclusterops/nma_delete_dir_op.go b/vclusterops/nma_delete_dir_op.go index b169fc3..bb8a1ae 100644 --- a/vclusterops/nma_delete_dir_op.go +++ b/vclusterops/nma_delete_dir_op.go @@ -21,11 +21,13 @@ type deleteDirParams struct { } func makeNMADeleteDirectoriesOp( + log vlog.Printer, vdb *VCoordinationDatabase, forceDelete bool, ) (NMADeleteDirectoriesOp, error) { nmaDeleteDirectoriesOp := NMADeleteDirectoriesOp{} nmaDeleteDirectoriesOp.name = "NMADeleteDirectoriesOp" + nmaDeleteDirectoriesOp.log = log.WithName(nmaDeleteDirectoriesOp.name) nmaDeleteDirectoriesOp.hosts = vdb.HostList err := nmaDeleteDirectoriesOp.buildRequestBody(vdb, forceDelete) @@ -69,7 +71,7 @@ func (op *NMADeleteDirectoriesOp) buildRequestBody( } op.hostRequestBodyMap[h] = string(dataBytes) - vlog.LogInfo("Host %s delete directory params %+v", h, p) + op.log.Info("delete directory params", "host", h, "params", p) } return nil diff --git a/vclusterops/nma_download_config.go b/vclusterops/nma_download_config.go index 9b0254c..04413e8 100644 --- a/vclusterops/nma_download_config.go +++ b/vclusterops/nma_download_config.go @@ -32,6 +32,7 @@ type NMADownloadConfigOp struct { } func makeNMADownloadConfigOp( + log vlog.Printer, opName string, sourceConfigHost []string, endpoint string, @@ -40,6 +41,7 @@ func makeNMADownloadConfigOp( ) NMADownloadConfigOp { nmaDownloadConfigOp := NMADownloadConfigOp{} nmaDownloadConfigOp.name = opName + nmaDownloadConfigOp.log = log.WithName(nmaDownloadConfigOp.name) nmaDownloadConfigOp.hosts = sourceConfigHost nmaDownloadConfigOp.endpoint = endpoint nmaDownloadConfigOp.fileContent = fileContent @@ -135,7 +137,7 @@ func (op *NMADownloadConfigOp) processResult(_ *OpEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { // VER-88362 will re-enable the result details and hide sensitive info in it - vlog.LogPrintInfo("[%s] result from host %s summary %s", + op.log.PrintInfo("[%s] result from host %s summary %s", op.name, host, result.status.getStatusString()) if result.isPassing() { // The content of config file will be stored as content of the response diff --git a/vclusterops/nma_download_file_op.go b/vclusterops/nma_download_file_op.go index 614c324..f41a263 100644 --- a/vclusterops/nma_download_file_op.go +++ b/vclusterops/nma_download_file_op.go @@ -83,10 +83,11 @@ func (e *ReviveDBNodeCountMismatchError) Error() string { e.ReviveDBStep, e.FailureHost, e.NumOfNewNodes, e.NumOfOldNodes) } -func makeNMADownloadFileOp(newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, +func makeNMADownloadFileOp(log vlog.Printer, newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, configurationParameters map[string]string, vdb *VCoordinationDatabase) (NMADownloadFileOp, error) { op := NMADownloadFileOp{} op.name = "NMADownloadFileOp" + op.log = log.WithName(op.name) initiator := getInitiator(newNodes) op.hosts = []string{initiator} op.vdb = vdb @@ -112,9 +113,9 @@ func makeNMADownloadFileOp(newNodes []string, sourceFilePath, destinationFilePat return op, nil } -func makeNMADownloadFileOpForRevive(newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, +func makeNMADownloadFileOpForRevive(log vlog.Printer, newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, configurationParameters map[string]string, vdb *VCoordinationDatabase, displayOnly, ignoreClusterLease bool) (NMADownloadFileOp, error) { - op, err := makeNMADownloadFileOp(newNodes, sourceFilePath, destinationFilePath, + op, err := makeNMADownloadFileOp(log, newNodes, sourceFilePath, destinationFilePath, catalogPath, configurationParameters, vdb) if err != nil { return op, err @@ -197,7 +198,7 @@ func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) err result := strings.TrimSpace(response.Result) if result != respSuccResult { err = fmt.Errorf(`[%s] fail to download file on host %s, error result in the response is %s`, op.name, host, result) - vlog.LogError(err.Error()) + op.log.Error(err, "fail to download file, detail") allErrs = errors.Join(allErrs, err) break } @@ -289,7 +290,7 @@ func (op *NMADownloadFileOp) buildVDBFromClusterConfig(descFileContent fileConte func (op *NMADownloadFileOp) clusterLeaseCheck(clusterLeaseExpiration string) error { if op.ignoreClusterLease { - vlog.LogPrintWarningln("Skipping cluster lease check") + op.log.PrintWarning("Skipping cluster lease check\n") return nil } @@ -305,6 +306,6 @@ func (op *NMADownloadFileOp) clusterLeaseCheck(clusterLeaseExpiration string) er return &ClusterLeaseNotExpiredError{Expiration: clusterLeaseExpiration} } - vlog.LogPrintInfoln("Cluster lease check has passed. We proceed to revive the database") + op.log.PrintInfo("Cluster lease check has passed. We proceed to revive the database") return nil } diff --git a/vclusterops/nma_get_nodes_info_op.go b/vclusterops/nma_get_nodes_info_op.go index 6d6cc58..80e8b67 100644 --- a/vclusterops/nma_get_nodes_info_op.go +++ b/vclusterops/nma_get_nodes_info_op.go @@ -17,6 +17,8 @@ package vclusterops import ( "errors" + + "github.com/vertica/vcluster/vclusterops/vlog" ) // nmaGetNodesInfoOp get nodes info from the NMA /v1/nodes endpoint. @@ -28,11 +30,12 @@ type nmaGetNodesInfoOp struct { vdb *VCoordinationDatabase } -func makeNMAGetNodesInfoOp(hosts []string, +func makeNMAGetNodesInfoOp(log vlog.Printer, hosts []string, dbName, catalogPrefix string, vdb *VCoordinationDatabase) nmaGetNodesInfoOp { op := nmaGetNodesInfoOp{} op.name = "NMAGetNodesInfoOp" + op.log = log.WithName(op.name) op.hosts = hosts op.dbName = dbName op.catalogPrefix = catalogPrefix diff --git a/vclusterops/nma_health_op.go b/vclusterops/nma_health_op.go index 0075dcc..824f3b8 100644 --- a/vclusterops/nma_health_op.go +++ b/vclusterops/nma_health_op.go @@ -15,15 +15,20 @@ package vclusterops -import "errors" +import ( + "errors" + + "github.com/vertica/vcluster/vclusterops/vlog" +) type NMAHealthOp struct { OpBase } -func makeNMAHealthOp(hosts []string) NMAHealthOp { +func makeNMAHealthOp(log vlog.Printer, hosts []string) NMAHealthOp { nmaHealthOp := NMAHealthOp{} nmaHealthOp.name = "NMAHealthOp" + nmaHealthOp.log = log.WithName(nmaHealthOp.name) nmaHealthOp.hosts = hosts return nmaHealthOp } diff --git a/vclusterops/nma_load_remote_catalog_op.go b/vclusterops/nma_load_remote_catalog_op.go index ea24499..a16d5ab 100644 --- a/vclusterops/nma_load_remote_catalog_op.go +++ b/vclusterops/nma_load_remote_catalog_op.go @@ -46,10 +46,11 @@ type loadRemoteCatalogRequestData struct { Parameters map[string]string `json:"parameters,omitempty"` } -func makeNMALoadRemoteCatalogOp(oldHosts []string, configurationParameters map[string]string, +func makeNMALoadRemoteCatalogOp(log vlog.Printer, oldHosts []string, configurationParameters map[string]string, vdb *VCoordinationDatabase, timeout uint) nmaLoadRemoteCatalogOp { op := nmaLoadRemoteCatalogOp{} op.name = "NMALoadRemoteCatalogOp" + op.log = log.WithName(op.name) op.hosts = vdb.HostList op.oldHosts = oldHosts op.configurationParameters = configurationParameters @@ -183,7 +184,7 @@ func (op *nmaLoadRemoteCatalogOp) processResult(_ *OpEngineExecContext) error { // quorum check if !op.hasQuorum(successPrimaryNodeCount, op.primaryNodeCount) { err := fmt.Errorf("[%s] fail to load catalog on enough primary nodes. Success count: %d", op.name, successPrimaryNodeCount) - vlog.LogError(err.Error()) + op.log.Error(err, "fail to load catalog, detail") allErrs = errors.Join(allErrs, err) return allErrs } diff --git a/vclusterops/nma_network_profile_op.go b/vclusterops/nma_network_profile_op.go index 76c1b6a..143122e 100644 --- a/vclusterops/nma_network_profile_op.go +++ b/vclusterops/nma_network_profile_op.go @@ -20,15 +20,17 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" + "github.com/vertica/vcluster/vclusterops/vlog" ) type NMANetworkProfileOp struct { OpBase } -func makeNMANetworkProfileOp(hosts []string) NMANetworkProfileOp { +func makeNMANetworkProfileOp(log vlog.Printer, hosts []string) NMANetworkProfileOp { nmaNetworkProfileOp := NMANetworkProfileOp{} nmaNetworkProfileOp.name = "NMANetworkProfileOp" + nmaNetworkProfileOp.log = log.WithName(nmaNetworkProfileOp.name) nmaNetworkProfileOp.hosts = hosts return nmaNetworkProfileOp } diff --git a/vclusterops/nma_prepare_directories_op.go b/vclusterops/nma_prepare_directories_op.go index 7213100..28a8e6e 100644 --- a/vclusterops/nma_prepare_directories_op.go +++ b/vclusterops/nma_prepare_directories_op.go @@ -41,10 +41,11 @@ type prepareDirectoriesRequestData struct { IgnoreParent bool `json:"ignore_parent"` } -func makeNMAPrepareDirectoriesOp(hostNodeMap vHostNodeMap, +func makeNMAPrepareDirectoriesOp(log vlog.Printer, hostNodeMap vHostNodeMap, forceCleanup, forRevive bool) (NMAPrepareDirectoriesOp, error) { nmaPrepareDirectoriesOp := NMAPrepareDirectoriesOp{} nmaPrepareDirectoriesOp.name = "NMAPrepareDirectoriesOp" + nmaPrepareDirectoriesOp.log = log.WithName(nmaPrepareDirectoriesOp.name) nmaPrepareDirectoriesOp.forceCleanup = forceCleanup nmaPrepareDirectoriesOp.forRevive = forRevive @@ -78,7 +79,7 @@ func (op *NMAPrepareDirectoriesOp) setupRequestBody(hostNodeMap vHostNodeMap) er op.hostRequestBodyMap[host] = string(dataBytes) } - vlog.LogInfo("[%s] request data: %+v", op.name, op.hostRequestBodyMap) + op.log.Info("request data", "opName", op.name, "hostRequestBodyMap", op.hostRequestBodyMap) return nil } diff --git a/vclusterops/nma_re_ip_op.go b/vclusterops/nma_re_ip_op.go index 67e7512..7454015 100644 --- a/vclusterops/nma_re_ip_op.go +++ b/vclusterops/nma_re_ip_op.go @@ -33,9 +33,10 @@ type NMAReIPOp struct { mapHostToCatalogPath map[string]string } -func makeNMAReIPOp(reIPList []ReIPInfo, vdb *VCoordinationDatabase) NMAReIPOp { +func makeNMAReIPOp(log vlog.Printer, reIPList []ReIPInfo, vdb *VCoordinationDatabase) NMAReIPOp { op := NMAReIPOp{} op.name = "NMAReIPOp" + op.log = log.WithName(op.name) op.reIPList = reIPList op.vdb = vdb return op @@ -63,13 +64,13 @@ func (op *NMAReIPOp) updateRequestBody(_ *OpEngineExecContext) error { p.ReIPInfoList = op.reIPList dataBytes, err := json.Marshal(p) if err != nil { - vlog.LogError(`[%s] fail to marshal request data to JSON string, detail %s`, op.name, err) + op.log.Error(err, `[%s] fail to marshal request data to JSON string, detail %s`, op.name) return err } op.hostRequestBodyMap[host] = string(dataBytes) } - vlog.LogInfo("[%s] request data: %+v\n", op.name, op.hostRequestBodyMap) + op.log.Info("request data", "opName", op.name, "hostRequestBodyMap", op.hostRequestBodyMap) return nil } diff --git a/vclusterops/nma_read_catalog_editor_op.go b/vclusterops/nma_read_catalog_editor_op.go index 5266f79..65575e4 100644 --- a/vclusterops/nma_read_catalog_editor_op.go +++ b/vclusterops/nma_read_catalog_editor_op.go @@ -34,19 +34,21 @@ type NMAReadCatalogEditorOp struct { // makeNMAReadCatalogEditorOpWithInitiator creates an op to read catalog editor info. // Initiator is needed when creating new nodes func makeNMAReadCatalogEditorOpWithInitiator( + log vlog.Printer, initiator []string, vdb *VCoordinationDatabase, ) (NMAReadCatalogEditorOp, error) { op := NMAReadCatalogEditorOp{} op.name = "NMAReadCatalogEditorOp" + op.log = log.WithName(op.name) op.initiator = initiator op.vdb = vdb return op, nil } // makeNMAReadCatalogEditorOp creates an op to read catalog editor info. -func makeNMAReadCatalogEditorOp(vdb *VCoordinationDatabase) (NMAReadCatalogEditorOp, error) { - return makeNMAReadCatalogEditorOpWithInitiator([]string{}, vdb) +func makeNMAReadCatalogEditorOp(log vlog.Printer, vdb *VCoordinationDatabase) (NMAReadCatalogEditorOp, error) { + return makeNMAReadCatalogEditorOpWithInitiator(log, []string{}, vdb) } func (op *NMAReadCatalogEditorOp) setupClusterHTTPRequest(hosts []string) error { @@ -61,7 +63,9 @@ func (op *NMAReadCatalogEditorOp) setupClusterHTTPRequest(hosts []string) error catalogPath, ok := op.catalogPathMap[host] if !ok { - vlog.LogError("[%s] cannot find catalog path of host %s", op.name, host) + err := fmt.Errorf("[%s] cannot find catalog path of host %s", op.name, host) + op.log.Error(err, "fail to find catalog path, detail") + return err } httpRequest.QueryParams = map[string]string{"catalog_path": catalogPath} diff --git a/vclusterops/nma_start_node_op.go b/vclusterops/nma_start_node_op.go index f8ed10b..42c8548 100644 --- a/vclusterops/nma_start_node_op.go +++ b/vclusterops/nma_start_node_op.go @@ -19,6 +19,8 @@ import ( "encoding/json" "errors" "fmt" + + "github.com/vertica/vcluster/vclusterops/vlog" ) type nmaStartNodeOp struct { @@ -27,15 +29,17 @@ type nmaStartNodeOp struct { vdb *VCoordinationDatabase } -func makeNMAStartNodeOp(hosts []string) nmaStartNodeOp { +func makeNMAStartNodeOp(log vlog.Printer, + hosts []string) nmaStartNodeOp { startNodeOp := nmaStartNodeOp{} startNodeOp.name = "NMAStartNodeOp" + startNodeOp.log = log.WithName(startNodeOp.name) startNodeOp.hosts = hosts return startNodeOp } -func makeNMAStartNodeOpWithVDB(hosts []string, vdb *VCoordinationDatabase) nmaStartNodeOp { - startNodeOp := makeNMAStartNodeOp(hosts) +func makeNMAStartNodeOpWithVDB(log vlog.Printer, hosts []string, vdb *VCoordinationDatabase) nmaStartNodeOp { + startNodeOp := makeNMAStartNodeOp(log, hosts) startNodeOp.vdb = vdb return startNodeOp } diff --git a/vclusterops/nma_upload_config.go b/vclusterops/nma_upload_config.go index 94068b7..2d93075 100644 --- a/vclusterops/nma_upload_config.go +++ b/vclusterops/nma_upload_config.go @@ -48,6 +48,7 @@ type uploadConfigRequestData struct { // To add nodes to the DB, use the bootstrapHost value for sourceConfigHost, a list of newly added nodes // for newNodeHosts and provide a nil value for hosts. func makeNMAUploadConfigOp( + log vlog.Printer, opName string, sourceConfigHost []string, // source host for transferring configuration files, specifically, it is // 1. the bootstrap host when creating the database @@ -59,6 +60,7 @@ func makeNMAUploadConfigOp( ) NMAUploadConfigOp { nmaUploadConfigOp := NMAUploadConfigOp{} nmaUploadConfigOp.name = opName + nmaUploadConfigOp.log = log.WithName(nmaUploadConfigOp.name) nmaUploadConfigOp.endpoint = endpoint nmaUploadConfigOp.fileContent = fileContent nmaUploadConfigOp.catalogPathMap = make(map[string]string) @@ -123,7 +125,7 @@ func (op *NMAUploadConfigOp) prepare(execContext *OpEngineExecContext) error { // If no hosts to upload, skip this operation. This can happen if all // hosts have the latest catalog. if len(op.hosts) == 0 { - vlog.LogInfo("no hosts require an upload, skipping the operation") + op.log.Info("no hosts require an upload, skipping the operation") op.skipExecute = true return nil } diff --git a/vclusterops/re_ip.go b/vclusterops/re_ip.go index db15db1..e9d4d5e 100644 --- a/vclusterops/re_ip.go +++ b/vclusterops/re_ip.go @@ -22,7 +22,6 @@ import ( "os" "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) type VReIPOptions struct { @@ -124,7 +123,7 @@ func (vcc *VClusterCommands) VReIP(options *VReIPOptions) error { // retrieve database information from cluster_config.json for EON databases if options.IsEon.ToBool() { if *options.CommunalStorageLocation != "" { - vdb, e := options.getVDBWhenDBIsDown() + vdb, e := options.getVDBWhenDBIsDown(vcc) if e != nil { return e } @@ -133,7 +132,7 @@ func (vcc *VClusterCommands) VReIP(options *VReIPOptions) error { // When communal storage location is missing, we only log a debug message // because re-ip only fails in between revive_db and first start_db. // We should not ran re-ip in that case because revive_db has already done the re-ip work. - vlog.LogDebug("communal storage location is not specified for an eon database," + + vcc.Log.V(1).Info("communal storage location is not specified for an eon database," + " re_ip after revive_db could fail because we cannot retrieve the correct database information") } } @@ -141,8 +140,7 @@ func (vcc *VClusterCommands) VReIP(options *VReIPOptions) error { // produce re-ip instructions instructions, err := vcc.produceReIPInstructions(options, pVDB) if err != nil { - vlog.LogPrintError("fail to produce instructions, %v", err) - return err + return fmt.Errorf("fail to produce instructions, %w", err) } // create a VClusterOpEngine, and add certs to the engine @@ -152,8 +150,7 @@ func (vcc *VClusterCommands) VReIP(options *VReIPOptions) error { // give the instructions to the VClusterOpEngine to run runError := clusterOpEngine.Run() if runError != nil { - vlog.LogPrintError("fail to re-ip: %v", runError) - return runError + return fmt.Errorf("fail to re-ip: %w", runError) } return nil @@ -175,7 +172,7 @@ func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb hosts := options.Hosts - nmaHealthOp := makeNMAHealthOp(hosts) + nmaHealthOp := makeNMAHealthOp(vcc.Log, hosts) nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, hosts, true) // get network profiles of the new addresses @@ -183,7 +180,7 @@ func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb for _, info := range options.ReIPList { newAddresses = append(newAddresses, info.TargetAddress) } - nmaNetworkProfileOp := makeNMANetworkProfileOp(newAddresses) + nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, newAddresses) instructions = append(instructions, &nmaHealthOp, @@ -195,9 +192,9 @@ func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb // When we cannot get db info from cluster_config.json, we will fetch it from NMA /nodes endpoint. if vdb == nil { vdb = new(VCoordinationDatabase) - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, *options.DBName, *options.CatalogPrefix, vdb) + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(vcc.Log, options.Hosts, *options.DBName, *options.CatalogPrefix, vdb) // read catalog editor to get hosts with latest catalog - nmaReadCatEdOp, err := makeNMAReadCatalogEditorOp(vdb) + nmaReadCatEdOp, err := makeNMAReadCatalogEditorOp(vcc.Log, vdb) if err != nil { return instructions, err } @@ -210,7 +207,7 @@ func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb *vdbWithPrimaryNodes = *vdb vdbWithPrimaryNodes.filterPrimaryNodes() // read catalog editor to get hosts with latest catalog - nmaReadCatEdOp, err := makeNMAReadCatalogEditorOp(vdbWithPrimaryNodes) + nmaReadCatEdOp, err := makeNMAReadCatalogEditorOp(vcc.Log, vdbWithPrimaryNodes) if err != nil { return instructions, err } @@ -220,7 +217,7 @@ func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb // re-ip // at this stage the re-ip info should either by provided by // the re-ip file (for vcluster CLI) or the Kubernetes operator - nmaReIPOP := makeNMAReIPOp(options.ReIPList, vdb) + nmaReIPOP := makeNMAReIPOp(vcc.Log, options.ReIPList, vdb) instructions = append(instructions, &nmaReIPOP) diff --git a/vclusterops/remove_node.go b/vclusterops/remove_node.go index 73d44c6..61e6ab9 100644 --- a/vclusterops/remove_node.go +++ b/vclusterops/remove_node.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) // VRemoveNodeOptions are the option arguments for the VRemoveNode API @@ -108,7 +107,7 @@ func (o *VRemoveNodeOptions) analyzeOptions() (err error) { return nil } -func (o *VRemoveNodeOptions) validateAnalyzeOptions() error { +func (o *VRemoveNodeOptions) validateAnalyzeOptions(vcc *VClusterCommands) error { if err := o.validateParseOptions(); err != nil { return err } @@ -116,14 +115,14 @@ func (o *VRemoveNodeOptions) validateAnalyzeOptions() error { if err != nil { return err } - return o.SetUsePassword() + return o.SetUsePassword(vcc) } func (vcc *VClusterCommands) VRemoveNode(options *VRemoveNodeOptions) (VCoordinationDatabase, error) { vdb := MakeVCoordinationDatabase() // validate and analyze options - err := options.validateAnalyzeOptions() + err := options.validateAnalyzeOptions(vcc) if err != nil { return vdb, err } @@ -142,7 +141,7 @@ func (vcc *VClusterCommands) VRemoveNode(options *VRemoveNodeOptions) (VCoordina return vdb, err } - err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions) + err = vcc.getVDBFromRunningDB(&vdb, &options.DatabaseOptions) if err != nil { return vdb, err } @@ -165,15 +164,13 @@ func (vcc *VClusterCommands) VRemoveNode(options *VRemoveNodeOptions) (VCoordina instructions, err := vcc.produceRemoveNodeInstructions(&vdb, options) if err != nil { - vlog.LogPrintError("failed to produce remove node instructions, %s", err) - return vdb, err + return vdb, fmt.Errorf("fail to produce remove node instructions, %w", err) } certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := MakeClusterOpEngine(instructions, &certs) if runError := clusterOpEngine.Run(); runError != nil { - vlog.LogPrintError("failed to complete remove node operation, %s", runError) - return vdb, runError + return vdb, fmt.Errorf("fail to complete remove node operation, %w", runError) } remainingHosts := util.SliceDiff(vdb.HostList, options.HostsToRemove) @@ -252,7 +249,7 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat password := options.Password if (len(vdb.HostList) - len(options.HostsToRemove)) < ksafetyThreshold { - httpsMarkDesignKSafeOp, e := makeHTTPSMarkDesignKSafeOp(initiatorHost, usePassword, username, + httpsMarkDesignKSafeOp, e := makeHTTPSMarkDesignKSafeOp(vcc.Log, initiatorHost, usePassword, username, password, ksafeValueZero) if e != nil { return instructions, e @@ -260,7 +257,7 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat instructions = append(instructions, &httpsMarkDesignKSafeOp) } - err := produceMarkEphemeralNodeOps(&instructions, options.HostsToRemove, initiatorHost, + err := vcc.produceMarkEphemeralNodeOps(&instructions, options.HostsToRemove, initiatorHost, usePassword, username, password, vdb.HostNodeMap) if err != nil { return instructions, err @@ -271,7 +268,7 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat v := vdb.Copy(options.HostsToRemove) if vdb.IsEon { // we pass the set of subclusters of the nodes to remove. - err = produceRebalanceSubclusterShardsOps(&instructions, initiatorHost, v.getSCNames(), + err = vcc.produceRebalanceSubclusterShardsOps(&instructions, initiatorHost, v.getSCNames(), usePassword, username, password) if err != nil { return instructions, err @@ -287,7 +284,7 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat instructions = append(instructions, &httpsPollSubscriptionStateOp) } else { var httpsRebalanceClusterOp HTTPSRebalanceClusterOp - httpsRebalanceClusterOp, err = makeHTTPSRebalanceClusterOp(initiatorHost, usePassword, username, + httpsRebalanceClusterOp, err = makeHTTPSRebalanceClusterOp(vcc.Log, initiatorHost, usePassword, username, password) if err != nil { return instructions, err @@ -296,33 +293,33 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat } // only remove secondary nodes from spread - err = produceSpreadRemoveNodeOp(&instructions, options.HostsToRemove, + err = vcc.produceSpreadRemoveNodeOp(&instructions, options.HostsToRemove, usePassword, username, password, initiatorHost, vdb.HostNodeMap) if err != nil { return instructions, err } - err = produceDropNodeOps(&instructions, options.HostsToRemove, initiatorHost, + err = vcc.produceDropNodeOps(&instructions, options.HostsToRemove, initiatorHost, usePassword, username, password, vdb.HostNodeMap, vdb.IsEon) if err != nil { return instructions, err } - httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(initiatorHost, true, username, password) + httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(vcc.Log, initiatorHost, true, username, password) if err != nil { return instructions, err } instructions = append(instructions, &httpsReloadSpreadOp) - nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(&v, *options.ForceDelete) + nmaDeleteDirectoriesOp, err := makeNMADeleteDirectoriesOp(vcc.Log, &v, *options.ForceDelete) if err != nil { return instructions, err } instructions = append(instructions, &nmaDeleteDirectoriesOp) if vdb.IsEon { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(initiatorHost, true, username, password) + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(vcc.Log, initiatorHost, true, username, password) if err != nil { return instructions, err } @@ -334,11 +331,11 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat // produceMarkEphemeralNodeOps gets a slice of target hosts and for each of them // produces an HTTPSMarkEphemeralNodeOp. -func produceMarkEphemeralNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string, +func (vcc *VClusterCommands) produceMarkEphemeralNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, hostNodeMap vHostNodeMap) error { for _, host := range targetHosts { - httpsMarkEphemeralNodeOp, err := makeHTTPSMarkEphemeralNodeOp(hostNodeMap[host].Name, hosts, + httpsMarkEphemeralNodeOp, err := makeHTTPSMarkEphemeralNodeOp(vcc.Log, hostNodeMap[host].Name, hosts, useHTTPPassword, userName, httpsPassword) if err != nil { return err @@ -350,10 +347,10 @@ func produceMarkEphemeralNodeOps(instructions *[]ClusterOp, targetHosts, hosts [ // produceRebalanceSubclusterShardsOps gets a slice of subclusters and for each of them // produces an HTTPSRebalanceSubclusterShardsOp. -func produceRebalanceSubclusterShardsOps(instructions *[]ClusterOp, initiatorHost, scNames []string, +func (vcc *VClusterCommands) produceRebalanceSubclusterShardsOps(instructions *[]ClusterOp, initiatorHost, scNames []string, useHTTPPassword bool, userName string, httpsPassword *string) error { for _, scName := range scNames { - op, err := makeHTTPSRebalanceSubclusterShardsOp( + op, err := makeHTTPSRebalanceSubclusterShardsOp(vcc.Log, initiatorHost, useHTTPPassword, userName, httpsPassword, scName) if err != nil { return err @@ -366,11 +363,11 @@ func produceRebalanceSubclusterShardsOps(instructions *[]ClusterOp, initiatorHos // produceDropNodeOps produces an HTTPSDropNodeOp for each node to drop. // This is because we must drop node one by one to avoid losing quorum. -func produceDropNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string, +func (vcc *VClusterCommands) produceDropNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, hostNodeMap vHostNodeMap, isEon bool) error { for _, host := range targetHosts { - httpsDropNodeOp, err := makeHTTPSDropNodeOp(hostNodeMap[host].Name, hosts, + httpsDropNodeOp, err := makeHTTPSDropNodeOp(vcc.Log, hostNodeMap[host].Name, hosts, useHTTPPassword, userName, httpsPassword, isEon) if err != nil { return err @@ -383,7 +380,7 @@ func produceDropNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string, // produceSpreadRemoveNodeOp calls HTTPSSpreadRemoveNodeOp // when there is at least one secondary node to remove -func produceSpreadRemoveNodeOp(instructions *[]ClusterOp, hostsToRemove []string, +func (vcc *VClusterCommands) produceSpreadRemoveNodeOp(instructions *[]ClusterOp, hostsToRemove []string, useHTTPPassword bool, userName string, httpsPassword *string, initiatorHost []string, hostNodeMap vHostNodeMap) error { // find secondary nodes from HostsToRemove @@ -400,7 +397,7 @@ func produceSpreadRemoveNodeOp(instructions *[]ClusterOp, hostsToRemove []string // only call HTTPSSpreadRemoveNodeOp for secondary nodes to remove if len(secondaryHostsToRemove) > 0 { - httpsSpreadRemoveNodeOp, err := makeHTTPSSpreadRemoveNodeOp(secondaryHostsToRemove, initiatorHost, + httpsSpreadRemoveNodeOp, err := makeHTTPSSpreadRemoveNodeOp(vcc.Log, secondaryHostsToRemove, initiatorHost, useHTTPPassword, userName, httpsPassword, hostNodeMap) if err != nil { return err diff --git a/vclusterops/remove_subcluster.go b/vclusterops/remove_subcluster.go index 0db69d6..cd435bd 100644 --- a/vclusterops/remove_subcluster.go +++ b/vclusterops/remove_subcluster.go @@ -21,7 +21,6 @@ import ( "github.com/vertica/vcluster/rfc7807" "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) // VRemoveScOptions are the option arguments for the VRemoveSubcluster API @@ -93,7 +92,7 @@ func (o *VRemoveScOptions) analyzeOptions() (err error) { return nil } -func (o *VRemoveScOptions) validateAnalyzeOptions() error { +func (o *VRemoveScOptions) validateAnalyzeOptions(vcc *VClusterCommands) error { if err := o.validateParseOptions(); err != nil { return err } @@ -101,7 +100,7 @@ func (o *VRemoveScOptions) validateAnalyzeOptions() error { if err != nil { return err } - return o.SetUsePassword() + return o.SetUsePassword(vcc) } /* @@ -116,14 +115,14 @@ func (vcc *VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (V // VER-88594: read config file (may move this part to cmd_remove_subcluster) // validate and analyze options - err := removeScOpt.validateAnalyzeOptions() + err := removeScOpt.validateAnalyzeOptions(vcc) if err != nil { return vdb, err } // pre-check: should not remove the default subcluster - vlog.LogPrintInfoln("Performing db_remove_subcluster pre-checks") - hostsToRemove, err := removeScPreCheck(&vdb, removeScOpt) + vcc.Log.PrintInfo("Performing db_remove_subcluster pre-checks") + hostsToRemove, err := vcc.removeScPreCheck(&vdb, removeScOpt) if err != nil { return vdb, err } @@ -131,9 +130,9 @@ func (vcc *VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (V // proceed to run db_remove_node only if // the number of nodes to remove is greater than zero var needRemoveNodes bool - vlog.LogPrintDebug("Nodes to be removed: %+v", hostsToRemove) + vcc.Log.V(1).Info("Nodes to be removed: %+v", hostsToRemove) if len(hostsToRemove) == 0 { - vlog.LogPrintInfo("no node found in subcluster %s", + vcc.Log.PrintInfo("no node found in subcluster %s", *removeScOpt.SubclusterToRemove) needRemoveNodes = false } else { @@ -147,7 +146,7 @@ func (vcc *VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (V removeNodeOpt.HostsToRemove = hostsToRemove removeNodeOpt.ForceDelete = removeScOpt.ForceDelete - vlog.LogPrintInfo("Removing nodes %q from subcluster %s", + vcc.Log.PrintInfo("Removing nodes %q from subcluster %s", hostsToRemove, *removeScOpt.SubclusterToRemove) vdb, err = vcc.VRemoveNode(&removeNodeOpt) if err != nil { @@ -156,8 +155,8 @@ func (vcc *VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (V } // drop subcluster (i.e., remove the sc name from catalog) - vlog.LogPrintInfoln("Removing the subcluster name from catalog") - err = dropSubcluster(&vdb, removeScOpt) + vcc.Log.PrintInfo("Removing the subcluster name from catalog") + err = vcc.dropSubcluster(&vdb, removeScOpt) if err != nil { return vdb, err } @@ -180,12 +179,12 @@ func (e *RemoveDefaultSubclusterError) Error() string { // for a successful remove_node: // - Get cluster and nodes info (check if the target DB is Eon and get to-be-removed node list) // - Get the subcluster info (check if the target sc exists and if it is the default sc) -func removeScPreCheck(vdb *VCoordinationDatabase, options *VRemoveScOptions) ([]string, error) { +func (vcc *VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, options *VRemoveScOptions) ([]string, error) { var hostsToRemove []string const preCheckErrMsg = "while performing db_remove_subcluster pre-checks" // get cluster and nodes info - err := getVDBFromRunningDB(vdb, &options.DatabaseOptions) + err := vcc.getVDBFromRunningDB(vdb, &options.DatabaseOptions) if err != nil { return hostsToRemove, err } @@ -197,13 +196,13 @@ func removeScPreCheck(vdb *VCoordinationDatabase, options *VRemoveScOptions) ([] } // get default subcluster - httpsFindSubclusterOp, err := makeHTTPSFindSubclusterOp(options.Hosts, + httpsFindSubclusterOp, err := makeHTTPSFindSubclusterOp(vcc.Log, options.Hosts, options.usePassword, *options.UserName, options.Password, *options.SubclusterToRemove, false /*do not ignore not found*/) if err != nil { - vlog.LogPrintError("fail to get default subcluster %s, details: %v", preCheckErrMsg, err) - return hostsToRemove, err + return hostsToRemove, fmt.Errorf("fail to get default subcluster %s, details: %w", + preCheckErrMsg, err) } var instructions []ClusterOp @@ -217,7 +216,7 @@ func removeScPreCheck(vdb *VCoordinationDatabase, options *VRemoveScOptions) ([] if err != nil { // VER-88585 will improve this rfc error flow if strings.Contains(err.Error(), "does not exist in the database") { - vlog.LogPrintError("fail to get subclusters' information %s, %v", preCheckErrMsg, err) + vcc.Log.PrintError("fail to get subclusters' information %s, %v", preCheckErrMsg, err) rfcErr := rfc7807.New(rfc7807.SubclusterNotFound).WithHost(options.Hosts[0]) return hostsToRemove, rfcErr } @@ -239,7 +238,7 @@ func removeScPreCheck(vdb *VCoordinationDatabase, options *VRemoveScOptions) ([] return hostsToRemove, nil } -func dropSubcluster(vdb *VCoordinationDatabase, options *VRemoveScOptions) error { +func (vcc *VClusterCommands) dropSubcluster(vdb *VCoordinationDatabase, options *VRemoveScOptions) error { dropScErrMsg := fmt.Sprintf("fail to drop subcluster %s", *options.SubclusterToRemove) // the initiator is a list of one primary up host @@ -254,7 +253,7 @@ func dropSubcluster(vdb *VCoordinationDatabase, options *VRemoveScOptions) error *options.SubclusterToRemove, options.usePassword, *options.UserName, options.Password) if err != nil { - vlog.LogPrintError("%s, details: %v", dropScErrMsg, err) + vcc.Log.Error(err, "details: %v", dropScErrMsg) return err } @@ -265,7 +264,7 @@ func dropSubcluster(vdb *VCoordinationDatabase, options *VRemoveScOptions) error clusterOpEngine := MakeClusterOpEngine(instructions, &certs) err = clusterOpEngine.Run() if err != nil { - vlog.LogPrintError("%s, details: %v", dropScErrMsg, err) + vcc.Log.Error(err, "fail to drop subcluster, details: %v", dropScErrMsg) return err } diff --git a/vclusterops/restart_node.go b/vclusterops/restart_node.go index 46e1eb4..ce3b36b 100644 --- a/vclusterops/restart_node.go +++ b/vclusterops/restart_node.go @@ -141,7 +141,7 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error // retrieve database information to execute the command so we do not always rely on some user input vdb := MakeVCoordinationDatabase() - err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions) + err = vcc.getVDBFromRunningDB(&vdb, &options.DatabaseOptions) if err != nil { return err } @@ -162,7 +162,7 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error if oldIP != newIP { restartNodeInfo.ReIPList = append(restartNodeInfo.ReIPList, newIP) restartNodeInfo.NodeNamesToRestart = append(restartNodeInfo.NodeNamesToRestart, nodename) - vlog.LogInfo("the node with the name %s needs to be re-IP %s", restartNodeInfo.NodeNamesToRestart, restartNodeInfo.ReIPList) + vcc.Log.Info("the nodes need to be re-IP", "nodeNames", restartNodeInfo.NodeNamesToRestart, "IPs", restartNodeInfo.ReIPList) } else { // otherwise, we don't need to re-ip hostsNoNeedToReIP = append(hostsNoNeedToReIP, newIP) @@ -176,8 +176,7 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error // produce restart_node instructions instructions, err := vcc.produceRestartNodesInstructions(restartNodeInfo, options, &vdb) if err != nil { - vlog.LogPrintError("fail to produce instructions, %s", err) - return err + return fmt.Errorf("fail to produce instructions, %w", err) } // create a VClusterOpEngine, and add certs to the engine @@ -187,8 +186,7 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error // Give the instructions to the VClusterOpEngine to run err = clusterOpEngine.Run() if err != nil { - vlog.LogPrintError("fail to restart node, %s", err) - return err + return fmt.Errorf("fail to restart node, %w", err) } return nil } @@ -215,16 +213,16 @@ func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VR vdb *VCoordinationDatabase) ([]ClusterOp, error) { var instructions []ClusterOp - nmaHealthOp := makeNMAHealthOp(options.Hosts) + nmaHealthOp := makeNMAHealthOp(vcc.Log, options.Hosts) // require to have the same vertica version nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, options.Hosts, true) // need username for https operations - err := options.SetUsePassword() + err := options.SetUsePassword(vcc) if err != nil { return instructions, err } - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(*options.DBName, options.Hosts, + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(vcc.Log, *options.DBName, options.Hosts, options.usePassword, *options.UserName, options.Password) if err != nil { return instructions, err @@ -238,7 +236,7 @@ func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VR // If we identify any nodes that need re-IP, HostsToRestart will contain the nodes that need re-IP. // Otherwise, HostsToRestart will consist of all hosts with IPs recorded in the catalog, which are provided by user input. if len(restartNodeInfo.ReIPList) != 0 { - nmaNetworkProfileOp := makeNMANetworkProfileOp(restartNodeInfo.ReIPList) + nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, restartNodeInfo.ReIPList) httpsReIPOp, e := makeHTTPSReIPOp(restartNodeInfo.NodeNamesToRestart, restartNodeInfo.ReIPList, options.usePassword, *options.UserName, options.Password) if e != nil { @@ -246,12 +244,12 @@ func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VR } // host is set to nil value in the reload spread step // we use information from node information to find the up host later - httpsReloadSpreadOp, e := makeHTTPSReloadSpreadOp(true, *options.UserName, options.Password) + httpsReloadSpreadOp, e := makeHTTPSReloadSpreadOp(vcc.Log, true, *options.UserName, options.Password) if e != nil { return instructions, e } // update new vdb information after re-ip - httpsGetNodesInfoOp, e := makeHTTPSGetNodesInfoOp(*options.DBName, options.Hosts, + httpsGetNodesInfoOp, e := makeHTTPSGetNodesInfoOp(vcc.Log, *options.DBName, options.Hosts, options.usePassword, *options.UserName, options.Password, vdb) if err != nil { return instructions, e @@ -268,17 +266,18 @@ func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VR // we use information from v1/nodes endpoint to get all node information to update the sourceConfHost value // after we find any UP primary nodes as source host for syncing spread.conf and vertica.conf // we will remove the nil parameters in VER-88401 by adding them in execContext - produceTransferConfigOps(&instructions, + produceTransferConfigOps(vcc.Log, + &instructions, nil, /*source hosts for transferring configuration files*/ restartNodeInfo.HostsToRestart, vdb) - httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(options.usePassword, *options.UserName, options.Password, vdb) + httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(vcc.Log, options.usePassword, *options.UserName, options.Password, vdb) if err != nil { return instructions, err } - nmaRestartNewNodesOp := makeNMAStartNodeOpWithVDB(restartNodeInfo.HostsToRestart, vdb) - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(restartNodeInfo.HostsToRestart, + nmaRestartNewNodesOp := makeNMAStartNodeOpWithVDB(vcc.Log, restartNodeInfo.HostsToRestart, vdb) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(vcc.Log, restartNodeInfo.HostsToRestart, options.usePassword, *options.UserName, options.Password, options.StatePollingTimeout, RestartNodeCmd) if err != nil { return instructions, err @@ -291,7 +290,7 @@ func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VR ) if vdb.IsEon { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(options.Hosts, true, *options.UserName, options.Password) + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(vcc.Log, options.Hosts, true, *options.UserName, options.Password) if err != nil { return instructions, err } diff --git a/vclusterops/revive_db.go b/vclusterops/revive_db.go index faae1bb..ba67473 100644 --- a/vclusterops/revive_db.go +++ b/vclusterops/revive_db.go @@ -20,7 +20,6 @@ import ( "sort" "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) type VReviveDatabaseOptions struct { @@ -119,8 +118,7 @@ func (vcc *VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (d // part 1: produce instructions for getting terminated database info, and save the info to vdb preReviveDBInstructions, err := vcc.producePreReviveDBInstructions(options, &vdb) if err != nil { - vlog.LogPrintError("fail to produce pre-revive database instructions %v", err) - return dbInfo, err + return dbInfo, fmt.Errorf("fail to produce pre-revive database instructions %w", err) } // generate clusterOpEngine certs @@ -129,8 +127,7 @@ func (vcc *VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (d clusterOpEngine := MakeClusterOpEngine(preReviveDBInstructions, &certs) err = clusterOpEngine.Run() if err != nil { - vlog.LogPrintError("fail to collect the information of database in revive_db %v", err) - return dbInfo, err + return dbInfo, fmt.Errorf("fail to collect the information of database in revive_db %w", err) } if *options.DisplayOnly { @@ -139,18 +136,16 @@ func (vcc *VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (d } // part 2: produce instructions for reviving database using terminated database info - reviveDBInstructions, err := produceReviveDBInstructions(options, &vdb) + reviveDBInstructions, err := vcc.produceReviveDBInstructions(options, &vdb) if err != nil { - vlog.LogPrintError("fail to produce revive database instructions %v", err) - return dbInfo, err + return dbInfo, fmt.Errorf("fail to produce revive database instructions %w", err) } // feed revive db instructions to the VClusterOpEngine clusterOpEngine = MakeClusterOpEngine(reviveDBInstructions, &certs) err = clusterOpEngine.Run() if err != nil { - vlog.LogPrintError("fail to revive database %v", err) - return dbInfo, err + return dbInfo, fmt.Errorf("fail to revive database %w", err) } return dbInfo, nil } @@ -171,7 +166,7 @@ func (vcc *VClusterCommands) producePreReviveDBInstructions(options *VReviveData vdb *VCoordinationDatabase) ([]ClusterOp, error) { var instructions []ClusterOp - nmaHealthOp := makeNMAHealthOp(options.Hosts) + nmaHealthOp := makeNMAHealthOp(vcc.Log, options.Hosts) nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, options.Hosts, true) checkDBRunningOp, err := makeHTTPCheckRunningDBOp(vcc.Log, options.Hosts, false, /*use password auth*/ @@ -182,7 +177,7 @@ func (vcc *VClusterCommands) producePreReviveDBInstructions(options *VReviveData // use description file path as source file path sourceFilePath := options.getDescriptionFilePath() - nmaDownLoadFileOp, err := makeNMADownloadFileOpForRevive(options.Hosts, sourceFilePath, destinationFilePath, catalogPath, + nmaDownLoadFileOp, err := makeNMADownloadFileOpForRevive(vcc.Log, options.Hosts, sourceFilePath, destinationFilePath, catalogPath, options.ConfigurationParameters, vdb, *options.DisplayOnly, *options.IgnoreClusterLease) if err != nil { return instructions, err @@ -203,7 +198,7 @@ func (vcc *VClusterCommands) producePreReviveDBInstructions(options *VReviveData // - Prepare database directories for all the hosts // - Get network profiles for all the hosts // - Load remote catalog from communal storage on all the hosts -func produceReviveDBInstructions(options *VReviveDatabaseOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { +func (vcc *VClusterCommands) produceReviveDBInstructions(options *VReviveDatabaseOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { var instructions []ClusterOp newVDB, oldHosts, err := options.generateReviveVDB(vdb) @@ -232,14 +227,15 @@ func produceReviveDBInstructions(options *VReviveDatabaseOptions, vdb *VCoordina hostNodeMap[host] = vnode } // prepare all directories - nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(hostNodeMap, *options.ForceRemoval, true /*for db revive*/) + nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(vcc.Log, hostNodeMap, *options.ForceRemoval, true /*for db revive*/) if err != nil { return instructions, err } - nmaNetworkProfileOp := makeNMANetworkProfileOp(options.Hosts) + nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, options.Hosts) - nmaLoadRemoteCatalogOp := makeNMALoadRemoteCatalogOp(oldHosts, options.ConfigurationParameters, &newVDB, *options.LoadCatalogTimeout) + nmaLoadRemoteCatalogOp := makeNMALoadRemoteCatalogOp(vcc.Log, oldHosts, options.ConfigurationParameters, + &newVDB, *options.LoadCatalogTimeout) instructions = append(instructions, &nmaPrepareDirectoriesOp, diff --git a/vclusterops/start_db.go b/vclusterops/start_db.go index 76c7130..c026846 100644 --- a/vclusterops/start_db.go +++ b/vclusterops/start_db.go @@ -19,7 +19,6 @@ import ( "fmt" "github.com/vertica/vcluster/vclusterops/util" - "github.com/vertica/vcluster/vclusterops/vlog" ) // Normal strings are easier and safer to use in Go. @@ -134,7 +133,7 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro if isEon { if *options.CommunalStorageLocation != "" { - vdb, e := options.getVDBWhenDBIsDown() + vdb, e := options.getVDBWhenDBIsDown(vcc) if e != nil { return e } @@ -144,16 +143,15 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro } else { // When communal storage location is missing, we only log a warning message // because fail to read cluster_config.json will not affect start_db in most of the cases. - vlog.LogPrintWarningln("communal storage location is not specified for an eon database," + - " first start_db after revive_db could fail because we cannot retrieve the correct database information") + vcc.Log.PrintWarning("communal storage location is not specified for an eon database," + + " first start_db after revive_db could fail because we cannot retrieve the correct database information\n") } } // produce start_db instructions instructions, err := vcc.produceStartDBInstructions(options, pVDB) if err != nil { - err = fmt.Errorf("fail to production instructions: %w", err) - return err + return fmt.Errorf("fail to production instructions: %w", err) } // create a VClusterOpEngine, and add certs to the engine @@ -163,8 +161,7 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro // Give the instructions to the VClusterOpEngine to run runError := clusterOpEngine.Run() if runError != nil { - runError = fmt.Errorf("fail to start database: %w", runError) - return runError + return fmt.Errorf("fail to start database: %w", runError) } return nil @@ -186,11 +183,11 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { var instructions []ClusterOp - nmaHealthOp := makeNMAHealthOp(options.Hosts) + nmaHealthOp := makeNMAHealthOp(vcc.Log, options.Hosts) // require to have the same vertica version nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, options.Hosts, true) // need username for https operations - err := options.SetUsePassword() + err := options.SetUsePassword(vcc) if err != nil { return instructions, err } @@ -209,12 +206,12 @@ func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseO // When we cannot get db info from cluster_config.json, we will fetch it from NMA /nodes endpoint. if vdb == nil { vdb = new(VCoordinationDatabase) - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(options.Hosts, *options.DBName, *options.CatalogPrefix, vdb) + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(vcc.Log, options.Hosts, *options.DBName, *options.CatalogPrefix, vdb) instructions = append(instructions, &nmaGetNodesInfoOp) } // vdb here should contains only primary nodes - nmaReadCatalogEditorOp, err := makeNMAReadCatalogEditorOp(vdb) + nmaReadCatalogEditorOp, err := makeNMAReadCatalogEditorOp(vcc.Log, vdb) if err != nil { return instructions, err } @@ -230,13 +227,14 @@ func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseO // we use information from catalog editor operation to update the sourceConfHost value // after we find host with the highest catalog and hosts that need to synchronize the catalog // we will remove the nil parameters in VER-88401 by adding them in execContext - produceTransferConfigOps(&instructions, + produceTransferConfigOps(vcc.Log, + &instructions, nil, /*source hosts for transferring configuration files*/ options.Hosts, nil /*db configurations retrieved from a running db*/) - nmaStartNewNodesOp := makeNMAStartNodeOp(options.Hosts) - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(options.Hosts, + nmaStartNewNodesOp := makeNMAStartNodeOp(vcc.Log, options.Hosts) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(vcc.Log, options.Hosts, options.usePassword, *options.UserName, options.Password, options.StatePollingTimeout, StartDBCmd) if err != nil { return instructions, err @@ -248,7 +246,7 @@ func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseO ) if options.IsEon.ToBool() { - httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(options.Hosts, true, *options.UserName, options.Password) + httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(vcc.Log, options.Hosts, true, *options.UserName, options.Password) if err != nil { return instructions, err } diff --git a/vclusterops/stop_db.go b/vclusterops/stop_db.go index 406955d..a97de13 100644 --- a/vclusterops/stop_db.go +++ b/vclusterops/stop_db.go @@ -16,6 +16,8 @@ package vclusterops import ( + "fmt" + "github.com/vertica/vcluster/vclusterops/util" "github.com/vertica/vcluster/vclusterops/vlog" ) @@ -157,8 +159,7 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error instructions, err := vcc.produceStopDBInstructions(stopDBInfo, options) if err != nil { - vlog.LogPrintError("fail to produce instructions, %s", err) - return err + return fmt.Errorf("fail to production instructions: %w", err) } // Create a VClusterOpEngine, and add certs to the engine @@ -168,8 +169,7 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error // Give the instructions to the VClusterOpEngine to run runError := clusterOpEngine.Run() if runError != nil { - vlog.LogPrintError("fail to stop database, %s", runError) - return runError + return fmt.Errorf("fail to stop database: %w", runError) } return nil @@ -193,13 +193,13 @@ func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabase usePassword := false if stopDBInfo.Password != nil { usePassword = true - err := options.ValidateUserName() + err := options.ValidateUserName(vcc) if err != nil { return instructions, err } } - httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(stopDBInfo.DBName, stopDBInfo.Hosts, + httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(vcc.Log, stopDBInfo.DBName, stopDBInfo.Hosts, usePassword, *options.UserName, stopDBInfo.Password) if err != nil { return instructions, err @@ -207,7 +207,7 @@ func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabase instructions = append(instructions, &httpsGetUpNodesOp) if stopDBInfo.IsEon { - httpsSyncCatalogOp, e := makeHTTPSSyncCatalogOpWithoutHosts(usePassword, *options.UserName, stopDBInfo.Password) + httpsSyncCatalogOp, e := makeHTTPSSyncCatalogOpWithoutHosts(vcc.Log, usePassword, *options.UserName, stopDBInfo.Password) if e != nil { return instructions, e } @@ -216,7 +216,7 @@ func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabase vlog.LogPrintInfoln("Skipping sync catalog for an enterprise database") } - httpsStopDBOp, err := makeHTTPSStopDBOp(usePassword, *options.UserName, stopDBInfo.Password, stopDBInfo.DrainSeconds) + httpsStopDBOp, err := makeHTTPSStopDBOp(vcc.Log, usePassword, *options.UserName, stopDBInfo.Password, stopDBInfo.DrainSeconds) if err != nil { return instructions, err } diff --git a/vclusterops/vcluster_database_options.go b/vclusterops/vcluster_database_options.go index 26596e7..de57ee5 100644 --- a/vclusterops/vcluster_database_options.go +++ b/vclusterops/vcluster_database_options.go @@ -235,7 +235,7 @@ func (opt *DatabaseOptions) ParseHostList(hosts string) error { return nil } -func (opt *DatabaseOptions) ValidateUserName() error { +func (opt *DatabaseOptions) ValidateUserName(vcc *VClusterCommands) error { if *opt.UserName == "" { username, err := util.GetCurrentUsername() if err != nil { @@ -243,18 +243,18 @@ func (opt *DatabaseOptions) ValidateUserName() error { } *opt.UserName = username } - vlog.LogInfo("Current username is %s", *opt.UserName) + vcc.Log.Info("Current username", "username", *opt.UserName) return nil } -func (opt *DatabaseOptions) SetUsePassword() error { +func (opt *DatabaseOptions) SetUsePassword(vcc *VClusterCommands) error { // when password is specified, // we will use username/password to call https endpoints opt.usePassword = false if opt.Password != nil { opt.usePassword = true - err := opt.ValidateUserName() + err := opt.ValidateUserName(vcc) if err != nil { return err } @@ -425,7 +425,7 @@ func (opt *DatabaseOptions) normalizePaths() { } // getVDBWhenDBIsDown can retrieve db configurations from NMA /nodes endpoint and cluster_config.json when db is down -func (opt *DatabaseOptions) getVDBWhenDBIsDown() (vdb VCoordinationDatabase, err error) { +func (opt *DatabaseOptions) getVDBWhenDBIsDown(vcc *VClusterCommands) (vdb VCoordinationDatabase, err error) { /* * 1. Get node names for input hosts from NMA /nodes. * 2. Get other node information for input hosts from cluster_config.json. @@ -442,8 +442,8 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown() (vdb VCoordinationDatabase, err // this step can map input hosts with node names vdb1 := VCoordinationDatabase{} var instructions1 []ClusterOp - nmaHealthOp := makeNMAHealthOp(opt.Hosts) - nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(opt.Hosts, *opt.DBName, *opt.CatalogPrefix, &vdb1) + nmaHealthOp := makeNMAHealthOp(vcc.Log, opt.Hosts) + nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(vcc.Log, opt.Hosts, *opt.DBName, *opt.CatalogPrefix, &vdb1) instructions1 = append(instructions1, &nmaHealthOp, &nmaGetNodesInfoOp, @@ -461,7 +461,7 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown() (vdb VCoordinationDatabase, err vdb2 := VCoordinationDatabase{} var instructions2 []ClusterOp sourceFilePath := opt.getDescriptionFilePath() - nmaDownLoadFileOp, err := makeNMADownloadFileOp(opt.Hosts, sourceFilePath, destinationFilePath, catalogPath, + nmaDownLoadFileOp, err := makeNMADownloadFileOp(vcc.Log, opt.Hosts, sourceFilePath, destinationFilePath, catalogPath, opt.ConfigurationParameters, &vdb2) if err != nil { return vdb, err