From 1f08c1778a76b3b3da82c343e684b6d125b9966e Mon Sep 17 00:00:00 2001 From: releng Date: Fri, 27 Sep 2024 05:53:47 -0400 Subject: [PATCH] Sync from server repo (a0662278500) --- vclusterops/fetch_database.go | 1 + vclusterops/nma_read_catalog_editor_op.go | 9 +++-- vclusterops/nma_save_restore_points_op.go | 49 ++++++++++++----------- vclusterops/save_restore_points.go | 15 ++++++- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/vclusterops/fetch_database.go b/vclusterops/fetch_database.go index 3a26523..40db0c3 100644 --- a/vclusterops/fetch_database.go +++ b/vclusterops/fetch_database.go @@ -129,6 +129,7 @@ func (vcc VClusterCommands) VFetchCoordinationDatabase(options *VFetchCoordinati vnode.Subcluster = n.Subcluster.Name vnode.StorageLocations = n.StorageLocations vnode.IsPrimary = n.IsPrimary + vnode.Sandbox = n.Subcluster.SandboxName } return vdb, runError diff --git a/vclusterops/nma_read_catalog_editor_op.go b/vclusterops/nma_read_catalog_editor_op.go index b7dd35c..4b28824 100644 --- a/vclusterops/nma_read_catalog_editor_op.go +++ b/vclusterops/nma_read_catalog_editor_op.go @@ -169,10 +169,11 @@ type nmaVNode struct { StorageLocations []string `json:"storage_locations"` Tag json.Number `json:"tag"` Subcluster struct { - Name string `json:"sc_name"` - IsPrimary bool `json:"is_primary_sc"` - IsDefault bool `json:"is_default"` - IsSandbox bool `json:"sandbox"` + Name string `json:"sc_name"` + IsPrimary bool `json:"is_primary_sc"` + IsDefault bool `json:"is_default"` + IsSandbox bool `json:"sandbox"` + SandboxName string `json:"sandbox_name"` } `json:"sc_details"` } diff --git a/vclusterops/nma_save_restore_points_op.go b/vclusterops/nma_save_restore_points_op.go index a549226..e64b9b0 100644 --- a/vclusterops/nma_save_restore_points_op.go +++ b/vclusterops/nma_save_restore_points_op.go @@ -20,48 +20,49 @@ import ( "errors" "fmt" + "github.com/vertica/vcluster/vclusterops/util" "github.com/vertica/vcluster/vclusterops/vlog" ) type nmaSaveRestorePointsOp struct { opBase - dbName string - username string - archiveName string - sandbox string + saveRestorePointsRequestData + sandbox string } type saveRestorePointsRequestData struct { - DBName string `json:"dbname"` - ArchiveName string `json:"archive_name"` - UserName string `json:"username"` + DBName string `json:"dbname"` + ArchiveName string `json:"archive_name"` + UserName string `json:"username"` + Password *string `json:"password"` } // This op is used to save restore points in a database -func makeNMASaveRestorePointsOp(logger vlog.Printer, hosts []string, dbName, username string, - archiveName string, sandbox string) nmaSaveRestorePointsOp { - return nmaSaveRestorePointsOp{ - opBase: opBase{ - name: "NMASaveRestorePointsOp", - description: "Run save restore point query", - logger: logger.WithName("NMASaveRestorePointsOp"), - hosts: hosts, - }, - dbName: dbName, - username: username, - archiveName: archiveName, - sandbox: sandbox, +func makeNMASaveRestorePointsOp(logger vlog.Printer, hosts []string, + saveRestorepointrequestData *saveRestorePointsRequestData, sandbox string, + usePassword bool) (nmaSaveRestorePointsOp, error) { + op := nmaSaveRestorePointsOp{} + op.name = "NMASaveRestorePointsOp" + op.description = "Run save restore point query" + op.logger = logger.WithName("NMASaveRestorePointsOp") + op.hosts = hosts + op.saveRestorePointsRequestData = *saveRestorepointrequestData + op.sandbox = sandbox + + if usePassword { + err := util.ValidateUsernameAndPassword(op.name, usePassword, op.UserName) + if err != nil { + return op, err + } } + return op, nil } // make https json data func (op *nmaSaveRestorePointsOp) setupRequestBody() (map[string]string, error) { hostRequestBodyMap := make(map[string]string, len(op.hosts)) for _, host := range op.hosts { - requestData := saveRestorePointsRequestData{} - requestData.DBName = op.dbName - requestData.ArchiveName = op.archiveName - requestData.UserName = op.username + requestData := op.saveRestorePointsRequestData dataBytes, err := json.Marshal(requestData) if err != nil { diff --git a/vclusterops/save_restore_points.go b/vclusterops/save_restore_points.go index 4cd7f6e..b7582c4 100644 --- a/vclusterops/save_restore_points.go +++ b/vclusterops/save_restore_points.go @@ -107,6 +107,9 @@ func (options *VSaveRestorePointOptions) validateAnalyzeOptions(logger vlog.Prin if err := options.validateUserName(logger); err != nil { return err } + if err := options.setUsePassword(logger); err != nil { + return err + } return options.analyzeOptions() } @@ -162,9 +165,17 @@ func (vcc VClusterCommands) produceSaveRestorePointsInstructions(options *VSaveR hosts = vdb.filterUpHostlist(hosts, options.Sandbox) bootstrapHost := []string{getInitiator(hosts)} - nmaSaveRestorePointOp := makeNMASaveRestorePointsOp(vcc.Log, bootstrapHost, - options.DBName, options.UserName, options.ArchiveName, options.Sandbox) + requestData := saveRestorePointsRequestData{} + requestData.ArchiveName = options.ArchiveName + requestData.DBName = options.DBName + requestData.UserName = options.UserName + requestData.Password = options.Password + nmaSaveRestorePointOp, err := makeNMASaveRestorePointsOp(vcc.Log, bootstrapHost, + &requestData, options.Sandbox, options.usePassword) + if err != nil { + return instructions, err + } instructions = append(instructions, &nmaHealthOp, &nmaSaveRestorePointOp)