Skip to content

Commit

Permalink
Sync from server repo (1a5574c7a21)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchen-vertica committed Jul 11, 2024
1 parent 6951dc4 commit b307ec4
Show file tree
Hide file tree
Showing 42 changed files with 152 additions and 148 deletions.
1 change: 1 addition & 0 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
saveRpFlag = "save-restore-point"
isolateMetadataFlag = "isolate-metadata"
createStorageLocationsFlag = "create-storage-locations"
forUpgradeFlag = "for-upgrade"
sandboxKey = "sandbox"
connFlag = "conn"
connKey = "conn"
Expand Down
18 changes: 12 additions & 6 deletions commands/cmd_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ func makeCmdSandboxSubcluster() *cobra.Command {
`Sandboxes a secondary subcluster in an Eon Mode database.
All hosts in the subcluster must be up.
When you sandbox a subcluster, its hosts immediately shut down and restart;
the subcluster becomes sandboxed after the hosts start back up.
A sandbox can contain multiple subclusters, and subclusters in the sandbox can
interact with each other. If you want to isolate subclusters, they must
A sandbox can contain multiple subclusters, and subclusters in the sandbox can
interact with each other. If you want to isolate subclusters, they must
be in separate sandboxes.
Subcluster sandboxing should be used for testing changes or upgrades in safe, isolated
environment and should not be used for production subclusters. For example, you can
Subcluster sandboxing should be used for testing changes or upgrades in safe, isolated
environment and should not be used for production subclusters. For example, you can
create sandboxes and then upgrade Vertica in those sandboxes.
Examples:
# Sandbox a subcluster with config file
vcluster sandbox_subcluster --subcluster sc1 --sandbox sand \
Expand Down Expand Up @@ -117,6 +117,12 @@ func (c *CmdSandboxSubcluster) setLocalFlags(cmd *cobra.Command) {
false,
"The sandbox can create its own storage locations.",
)
cmd.Flags().BoolVar(
&c.sbOptions.ForUpgrade,
forUpgradeFlag,
false,
"The sandbox is to be used for online upgrade",
)
}

func (c *CmdSandboxSubcluster) Parse(inputArgv []string, logger vlog.Printer) error {
Expand Down
5 changes: 5 additions & 0 deletions rfc7807/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ var (
"Failed to write file",
http.StatusInternalServerError,
)
MessageQueueFull = newProblemID(
path.Join(errorEndpointsPrefix, "message-queue-full"),
"Message queue is full",
http.StatusInternalServerError,
)
)
6 changes: 2 additions & 4 deletions vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ func (vcc VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDat
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)
clusterOpEngine := makeClusterOpEngine(instructions, options)
if runError := clusterOpEngine.run(vcc.Log); runError != nil {
return vdb, fmt.Errorf("fail to complete add node operation, %w", runError)
}
Expand Down Expand Up @@ -316,8 +315,7 @@ func (vcc VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase,
instructions = append(instructions, &httpsDropNodeOp)
}

certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
clusterOpEngine := makeClusterOpEngine(instructions, options)
err := clusterOpEngine.run(vcc.Log)
if err != nil {
vcc.Log.Error(err, "fail to trim nodes from catalog, %v")
Expand Down
5 changes: 1 addition & 4 deletions vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ func (options *VAddSubclusterOptions) validateAnalyzeOptions(logger vlog.Printer

// VAddSubcluster adds to a running database a new subcluster with provided options.
// It returns any error encountered.
//
//nolint:dupl
func (vcc VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) error {
/*
* - Validate Options
Expand All @@ -175,8 +173,7 @@ func (vcc VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) error
}

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

// Give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/alter_subcluster_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func (vcc VClusterCommands) VAlterSubclusterType(options *VAlterSubclusterTypeOp
}

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

// give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
Expand Down
18 changes: 11 additions & 7 deletions vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ type clusterOp interface {
logExecute()
logFinalize()
setupBasicInfo()
loadCertsIfNeeded(certs *httpsCerts, findCertsInOptions bool) error
loadCertsIfNeeded(tlsOptions opTLSOptions) error
isSkipExecute() bool
filterUnreachableHosts(execContext *opEngineExecContext)
}
Expand Down Expand Up @@ -382,9 +382,14 @@ func (op *opBase) runExecute(execContext *opEngineExecContext) error {
return nil
}

type opTLSOptions interface {
hasCerts() bool
getCerts() *httpsCerts
}

// if found certs in the options, we add the certs to http requests of each instruction
func (op *opBase) loadCertsIfNeeded(certs *httpsCerts, findCertsInOptions bool) error {
if !findCertsInOptions {
func (op *opBase) loadCertsIfNeeded(tlsOptions opTLSOptions) error {
if tlsOptions == nil || !tlsOptions.hasCerts() {
return nil
}

Expand All @@ -393,16 +398,15 @@ func (op *opBase) loadCertsIfNeeded(certs *httpsCerts, findCertsInOptions bool)
return fmt.Errorf("[%s] clusterHTTPRequest.RequestCollection is empty", op.name)
}

// retrieve certs once to avoid extra copies
certs := tlsOptions.getCerts()
if certs == nil {
return fmt.Errorf("[%s] is trying to use certificates, but none are set", op.name)
}

for host := range op.clusterHTTPRequest.RequestCollection {
request := op.clusterHTTPRequest.RequestCollection[host]
request.UseCertsInOptions = true
request.Certs.key = certs.key
request.Certs.cert = certs.cert
request.Certs.caCert = certs.caCert
request.setCerts(certs)
op.clusterHTTPRequest.RequestCollection[host] = request
}
return nil
Expand Down
18 changes: 6 additions & 12 deletions vclusterops/cluster_op_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@ import (

type VClusterOpEngine struct {
instructions []clusterOp
certs *httpsCerts
tlsOptions opTLSOptions
execContext *opEngineExecContext
}

func makeClusterOpEngine(instructions []clusterOp, certs *httpsCerts) VClusterOpEngine {
func makeClusterOpEngine(instructions []clusterOp, tlsOptions opTLSOptions) VClusterOpEngine {
newClusterOpEngine := VClusterOpEngine{}
newClusterOpEngine.instructions = instructions
newClusterOpEngine.certs = certs
newClusterOpEngine.tlsOptions = tlsOptions
return newClusterOpEngine
}

func (opEngine *VClusterOpEngine) shouldGetCertsFromOptions() bool {
return (opEngine.certs.key != "" && opEngine.certs.cert != "")
}

func (opEngine *VClusterOpEngine) run(logger vlog.Printer) error {
execContext := makeOpEngineExecContext(logger)
opEngine.execContext = &execContext
Expand All @@ -46,10 +42,8 @@ func (opEngine *VClusterOpEngine) run(logger vlog.Printer) error {
}

func (opEngine *VClusterOpEngine) runWithExecContext(logger vlog.Printer, execContext *opEngineExecContext) error {
findCertsInOptions := opEngine.shouldGetCertsFromOptions()

for _, op := range opEngine.instructions {
err := opEngine.runInstruction(logger, execContext, op, findCertsInOptions)
err := opEngine.runInstruction(logger, execContext, op)
if err != nil {
return err
}
Expand All @@ -66,7 +60,7 @@ func (opEngine *VClusterOpEngine) runWithExecContext(logger vlog.Printer, execCo

func (opEngine *VClusterOpEngine) runInstruction(
logger vlog.Printer, execContext *opEngineExecContext,
op clusterOp, findCertsInOptions bool) error {
op clusterOp) error {
op.setLogger(logger)
op.setupBasicInfo()
op.setupSpinner()
Expand All @@ -84,7 +78,7 @@ func (opEngine *VClusterOpEngine) runInstruction(
// start the progress spinner
op.startSpinner()

err = op.loadCertsIfNeeded(opEngine.certs, findCertsInOptions)
err = op.loadCertsIfNeeded(opEngine.tlsOptions)
if err != nil {
// here we do not return an error as the spinner error does not
// affect the functionality
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/cluster_op_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func TestSkipExecuteOp(t *testing.T) {
opWithSkipEnabled := makeMockOp(true)
opWithSkipDisabled := makeMockOp(false)
instructions := []clusterOp{&opWithSkipDisabled, &opWithSkipEnabled}
certs := httpsCerts{key: "key", cert: "cert", caCert: "ca-cert"}
opEngn := makeClusterOpEngine(instructions, &certs)
opEngn := makeClusterOpEngine(instructions, nil)
err := opEngn.run(vlog.Printer{})
assert.Equal(t, nil, err)
assert.True(t, opWithSkipDisabled.calledPrepare)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ func (vcc VClusterCommands) VCreateDatabase(options *VCreateDatabaseOptions) (VC
}

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

// Give the instructions to the VClusterOpEngine to run
err = clusterOpEngine.run(vcc.Log)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/drop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ func (vcc VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error {
}

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

// give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/fetch_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func (vcc VClusterCommands) VFetchCoordinationDatabase(options *VFetchCoordinati
}

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

// Give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/fetch_node_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ func (vcc VClusterCommands) VFetchNodeState(options *VFetchNodeStateOptions) ([]
}

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

// give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/fetch_nodes_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ func (vcc VClusterCommands) VFetchNodesDetails(options *VFetchNodesDetailsOption
return nodesDetails, fmt.Errorf("fail to produce instructions: %w", err)
}

certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
clusterOpEngine := makeClusterOpEngine(instructions, options)

err = clusterOpEngine.run(vcc.Log)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/get_config_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func (vcc VClusterCommands) VGetConfigurationParameters(options *VGetConfigurati
}

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

// Give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
Expand Down
12 changes: 4 additions & 8 deletions vclusterops/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ func (vcc VClusterCommands) getVDBFromRunningDBImpl(vdb *VCoordinationDatabase,
instructions = append(instructions, &httpsUpdateNodeState)
}

certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
clusterOpEngine := makeClusterOpEngine(instructions, options)
err = clusterOpEngine.run(vcc.Log)
if err != nil {
return fmt.Errorf("fail to retrieve database configurations, %w", err)
Expand All @@ -291,8 +290,7 @@ func (vcc VClusterCommands) getClusterInfoFromRunningDB(vdb *VCoordinationDataba
var instructions []clusterOp
instructions = append(instructions, &httpsGetClusterInfoOp)

certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
clusterOpEngine := makeClusterOpEngine(instructions, options)
err = clusterOpEngine.run(vcc.Log)
if err != nil {
return fmt.Errorf("fail to retrieve cluster configurations, %w", err)
Expand Down Expand Up @@ -460,8 +458,7 @@ func (vcc *VClusterCommands) doReIP(options *DatabaseOptions, scName string,
}
instructions = append(instructions, &httpsReloadSpreadOp)
}
certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := makeClusterOpEngine(instructions, &certs)
clusterOpEngine := makeClusterOpEngine(instructions, options)
err = clusterOpEngine.run(vcc.Log)
if err != nil {
return fmt.Errorf("failed to re-ip nodes of subcluster %q: %w", scName, err)
Expand All @@ -474,8 +471,7 @@ func (vcc *VClusterCommands) getUnreachableHosts(options *DatabaseOptions, hosts
var nmaHealthInstructions []clusterOp
nmaHealthOp := makeNMAHealthOpSkipUnreachable(hosts)
nmaHealthInstructions = []clusterOp{&nmaHealthOp}
certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
opEng := makeClusterOpEngine(nmaHealthInstructions, &certs)
opEng := makeClusterOpEngine(nmaHealthInstructions, options)
err := opEng.run(vcc.Log)
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions vclusterops/http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ type httpsCerts struct {
caCert string
}

func (req *hostHTTPRequest) setCerts(certs *httpsCerts) {
req.UseCertsInOptions = true
req.Certs.key = certs.key
req.Certs.cert = certs.cert
req.Certs.caCert = certs.caCert
}

func (req *hostHTTPRequest) buildNMAEndpoint(url string) {
req.IsNMACommand = true
req.Endpoint = NMACurVersion + url
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/https_add_subcluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (op *httpsAddSubclusterOp) setupClusterHTTPRequest(hosts []string) error {

func (op *httpsAddSubclusterOp) prepare(execContext *opEngineExecContext) error {
if len(execContext.upHosts) == 0 {
return fmt.Errorf(`[%s] Cannot find any up hosts in OpEngineExecContext`, op.name)
return fmt.Errorf(`[%s] Cannot find any main cluster up hosts in OpEngineExecContext`, op.name)
}
// use first up host to execute https post request, this host will be the initiator
hosts := []string{execContext.upHosts[0]}
Expand Down
Loading

0 comments on commit b307ec4

Please sign in to comment.