From 6f31867538a62e65e939950d8d226ad3ebfebdd5 Mon Sep 17 00:00:00 2001 From: Matt Spilchen Date: Tue, 28 Nov 2023 08:09:30 -0400 Subject: [PATCH] Sync from server repo (947a0b40484) --- commands/cmd_restart_node.go | 6 +- commands/cmd_scrutinize.go | 102 ++++++++++++++--- commands/scrutinize_test.go | 85 +++++++++++++- vclusterops/adapter_pool.go | 36 +++--- vclusterops/add_node.go | 14 +-- vclusterops/add_subcluster.go | 6 +- vclusterops/cluster_op.go | 108 +++++++++--------- vclusterops/cluster_op_engine.go | 8 +- vclusterops/cluster_op_engine_context.go | 12 +- vclusterops/cluster_op_engine_test.go | 20 ++-- vclusterops/cluster_op_test.go | 2 +- vclusterops/create_db.go | 20 ++-- vclusterops/drop_db.go | 8 +- vclusterops/fetch_node_state.go | 8 +- vclusterops/helpers.go | 14 +-- vclusterops/helpers_test.go | 18 +-- vclusterops/http_adapter.go | 46 ++++---- vclusterops/http_adapter_test.go | 8 +- vclusterops/http_request.go | 18 +-- vclusterops/http_request_dispatcher.go | 20 ++-- vclusterops/https_add_subcluster_op.go | 48 ++++---- vclusterops/https_check_db_running_op.go | 74 ++++++------ vclusterops/https_check_node_state_op.go | 26 ++--- vclusterops/https_check_subcluster_op.go | 62 +++++----- vclusterops/https_create_cluster_depot_op.go | 64 +++++------ vclusterops/https_create_node_op.go | 48 ++++---- vclusterops/https_create_nodes_depot_op.go | 46 ++++---- vclusterops/https_drop_node_op.go | 50 ++++---- vclusterops/https_drop_subcluster_op.go | 14 +-- vclusterops/https_find_subcluster_op.go | 34 +++--- vclusterops/https_get_cluster_info_op.go | 30 ++--- vclusterops/https_get_nodes_info_op.go | 20 ++-- vclusterops/https_get_up_nodes_op.go | 56 ++++----- vclusterops/https_install_packages_op.go | 46 ++++---- vclusterops/https_mark_design_ksafe_op.go | 60 +++++----- vclusterops/https_mark_nodes_ephemeral_op.go | 22 ++-- vclusterops/https_poll_node_state_op.go | 76 ++++++------ vclusterops/https_poll_node_state_op_test.go | 4 +- .../https_poll_subscription_state_op.go | 26 ++--- vclusterops/https_re_ip_op.go | 20 ++-- vclusterops/https_rebalance_cluster_op.go | 42 +++---- .../https_rebalance_subcluster_shards_op.go | 44 +++---- vclusterops/https_reload_spread_op.go | 44 +++---- vclusterops/https_spread_remove_node_op.go | 22 ++-- vclusterops/https_startup_command_op.go | 14 +-- vclusterops/https_stop_db_op.go | 42 +++---- vclusterops/https_sync_catalog_op.go | 24 ++-- vclusterops/network_adapter.go | 6 +- vclusterops/nma_bootstrap_catalog_op.go | 40 +++---- vclusterops/nma_delete_dir_op.go | 34 +++--- vclusterops/nma_download_config.go | 36 +++--- vclusterops/nma_download_file_op.go | 40 +++---- vclusterops/nma_download_file_op_test.go | 4 +- vclusterops/nma_get_healthy_nodes_op.go | 30 ++--- vclusterops/nma_get_nodes_info_op.go | 12 +- vclusterops/nma_get_scrutinize_tar_op.go | 18 +-- vclusterops/nma_health_op.go | 28 ++--- vclusterops/nma_load_remote_catalog_op.go | 14 +-- vclusterops/nma_network_profile_op.go | 36 +++--- vclusterops/nma_prepare_directories_op.go | 40 +++---- vclusterops/nma_re_ip_op.go | 40 +++---- vclusterops/nma_read_catalog_editor_op.go | 40 +++---- vclusterops/nma_spread_security_op.go | 16 +-- vclusterops/nma_stage_dc_tables_op.go | 20 ++-- vclusterops/nma_stage_error_report_op.go | 20 ++-- vclusterops/nma_stage_vertica_logs_op.go | 20 ++-- vclusterops/nma_start_node_op.go | 14 +-- vclusterops/nma_upload_config.go | 42 +++---- vclusterops/nma_vertica_version_op.go | 60 +++++----- vclusterops/nma_vertica_version_op_test.go | 24 ++-- vclusterops/node_info.go | 6 +- vclusterops/node_info_test.go | 14 +-- vclusterops/re_ip.go | 10 +- vclusterops/re_ip_test.go | 22 ++-- vclusterops/remove_node.go | 28 ++--- vclusterops/remove_subcluster.go | 14 +-- vclusterops/revive_db.go | 12 +- vclusterops/scrutinize.go | 6 +- vclusterops/scrutinize_op.go | 12 +- vclusterops/start_db.go | 16 +-- .../{restart_node.go => start_node.go} | 76 ++++++------ vclusterops/state_poller.go | 8 +- vclusterops/stop_db.go | 8 +- vclusterops/vcluster_database_options.go | 10 +- vclusterops/vcluster_version.go | 30 ++--- vclusterops/vcluster_version_test.go | 28 ++--- 86 files changed, 1350 insertions(+), 1201 deletions(-) rename vclusterops/{restart_node.go => start_node.go} (77%) diff --git a/commands/cmd_restart_node.go b/commands/cmd_restart_node.go index 3bb2fe1..a77a286 100644 --- a/commands/cmd_restart_node.go +++ b/commands/cmd_restart_node.go @@ -16,7 +16,7 @@ import ( */ type CmdRestartNodes struct { CmdBase - restartNodesOptions *vclusterops.VRestartNodesOptions + restartNodesOptions *vclusterops.VStartNodesOptions // Comma-separated list of vnode=host vnodeListStr *string @@ -28,7 +28,7 @@ func makeCmdRestartNodes() *CmdRestartNodes { // parser, used to parse command-line flags newCmd.parser = flag.NewFlagSet("restart_node", flag.ExitOnError) - restartNodesOptions := vclusterops.VRestartNodesOptionsFactory() + restartNodesOptions := vclusterops.VStartNodesOptionsFactory() // require flags restartNodesOptions.DBName = newCmd.parser.String("db-name", "", "The name of the database to restart nodes") @@ -114,7 +114,7 @@ func (c *CmdRestartNodes) Run(vcc vclusterops.VClusterCommands) error { options.Config = config // this is the instruction that will be used by both CLI and operator - err = vcc.VRestartNodes(options) + err = vcc.VStartNodes(options) if err != nil { return err } diff --git a/commands/cmd_scrutinize.go b/commands/cmd_scrutinize.go index 3638457..0bcc926 100644 --- a/commands/cmd_scrutinize.go +++ b/commands/cmd_scrutinize.go @@ -33,9 +33,14 @@ import ( ) const ( - // Environment variable names storing paths to PEM text. + // Environment variable names storing name of k8s secret that has NMA cert secretNameSpaceEnvVar = "NMA_SECRET_NAMESPACE" secretNameEnvVar = "NMA_SECRET_NAME" + + // Environment variable names for locating the NMA certs located in the file system + nmaRootCAPathEnvVar = "NMA_ROOTCA_PATH" + nmaCertPathEnvVar = "NMA_CERT_PATH" + nmaKeyPathEnvVar = "NMA_KEY_PATH" ) const ( @@ -137,8 +142,8 @@ func (c *CmdScrutinize) validateParse(logger vlog.Printer) error { func (c *CmdScrutinize) Analyze(logger vlog.Printer) error { logger.Info("Called method Analyze()") - // set cert/key values from env k8s - err := c.updateCertTextsFromk8s(logger) + // Read the NMA certs into the options struct + err := c.readNMACerts(logger) if err != nil { return err } @@ -224,12 +229,27 @@ func (k8sSecretRetrieverStruct) RetrieveSecret(namespace, secretName string) (ca return caCertVal, tlsCertVal, tlsKeyVal, nil } -// updateCertTextsFromk8s retrieves PEM-encoded text of CA certs, the server cert, and -// the server key from kubernetes. -func (c *CmdScrutinize) updateCertTextsFromk8s(logger vlog.Printer) error { +func (c *CmdScrutinize) readNMACerts(logger vlog.Printer) error { + loaderFuncs := []func(vlog.Printer) (bool, error){ + c.nmaCertLookupFromK8sSecret, + c.nmaCertLookupFromEnv, + } + for _, fnc := range loaderFuncs { + certsLoaded, err := fnc(logger) + if err != nil || certsLoaded { + return err + } + } + logger.Info("failed to retrieve the NMA certs from any source") + return nil +} + +// nmaCertLookupFromK8sSecret retrieves PEM-encoded text of CA certs, the server cert, and +// the server key directly from kubernetes secrets. +func (c *CmdScrutinize) nmaCertLookupFromK8sSecret(logger vlog.Printer) (bool, error) { _, portSet := os.LookupEnv(kubernetesPort) if !portSet { - return nil + return false, nil } logger.Info("K8s environment") secretNameSpace, nameSpaceSet := os.LookupEnv(secretNameSpaceEnvVar) @@ -237,32 +257,86 @@ func (c *CmdScrutinize) updateCertTextsFromk8s(logger vlog.Printer) error { // either secret namespace/name must be set, or none at all if !((nameSpaceSet && nameSet) || (!nameSpaceSet && !nameSet)) { - missingParamError := constructMissingParamsMsg([]bool{nameSpaceSet, nameSet}, []string{kubernetesPort, - secretNameSpaceEnvVar, secretNameEnvVar}) - return fmt.Errorf("all or none of the environment variables %s and %s must be set. %s", + missingParamError := constructMissingParamsMsg([]bool{nameSpaceSet, nameSet}, + []string{secretNameSpaceEnvVar, secretNameEnvVar}) + return false, fmt.Errorf("all or none of the environment variables %s and %s must be set. %s", secretNameSpaceEnvVar, secretNameEnvVar, missingParamError) } if !nameSpaceSet { logger.Info("Secret name not set in env. Failback to other cert retieval methods.") - return nil + return false, nil } caCert, cert, key, err := c.k8secretRetreiver.RetrieveSecret(secretNameSpace, secretName) if err != nil { - return fmt.Errorf("failed to read certs from k8s secret %s in namespace %s: %w", secretName, secretNameSpace, err) + return false, fmt.Errorf("failed to read certs from k8s secret %s in namespace %s: %w", secretName, secretNameSpace, err) } if len(caCert) != 0 && len(cert) != 0 && len(key) != 0 { logger.Info("Successfully read cert from k8s secret ", "secretName", secretName, "secretNameSpace", secretNameSpace) } else { - return fmt.Errorf("failed to read CA, cert or key (sizes = %d/%d/%d)", + return false, fmt.Errorf("failed to read CA, cert or key (sizes = %d/%d/%d)", len(caCert), len(cert), len(key)) } c.sOptions.CaCert = string(caCert) c.sOptions.Cert = string(cert) c.sOptions.Key = string(key) - return nil + return true, nil +} + +// nmaCertLookupFromEnv retrieves the NMA certs from plaintext file identified +// by an environment variable. +func (c *CmdScrutinize) nmaCertLookupFromEnv(logger vlog.Printer) (bool, error) { + rootCAPath, rootCAPathSet := os.LookupEnv(nmaRootCAPathEnvVar) + certPath, certPathSet := os.LookupEnv(nmaCertPathEnvVar) + keyPath, keyPathSet := os.LookupEnv(nmaKeyPathEnvVar) + + // either all env vars are set or none at all + if !((rootCAPathSet && certPathSet && keyPathSet) || (!rootCAPathSet && !certPathSet && !keyPathSet)) { + missingParamError := constructMissingParamsMsg([]bool{rootCAPathSet, certPathSet, keyPathSet}, + []string{nmaRootCAPathEnvVar, nmaCertPathEnvVar, nmaKeyPathEnvVar}) + return false, fmt.Errorf("all or none of the environment variables %s, %s and %s must be set. %s", + nmaRootCAPathEnvVar, nmaCertPathEnvVar, nmaKeyPathEnvVar, missingParamError) + } + + if !rootCAPathSet { + logger.Info("NMA cert location paths not set in env") + return false, nil + } + + var err error + + c.sOptions.CaCert, err = readNonEmptyFile(rootCAPath) + if err != nil { + return false, fmt.Errorf("failed to read root CA from %s: %w", rootCAPath, err) + } + + c.sOptions.Cert, err = readNonEmptyFile(certPath) + if err != nil { + return false, fmt.Errorf("failed to read cert from %s: %w", certPath, err) + } + + c.sOptions.Key, err = readNonEmptyFile(keyPath) + if err != nil { + return false, fmt.Errorf("failed to read key from %s: %w", keyPath, err) + } + + logger.Info("Successfully read certs from file", "rootCAPath", rootCAPath, "certPath", certPath, "keyPath", keyPath) + return true, nil +} + +// readNonEmptyFile is a helper that reads the contents of a file into a string. +// It returns an error if the file is empty. +func readNonEmptyFile(filename string) (string, error) { + contents, err := os.ReadFile(filename) + if err != nil { + return "", fmt.Errorf("failed to read from %s: %w", filename, err) + } + if len(contents) == 0 { + return "", fmt.Errorf("%s is empty", filename) + } + return string(contents), nil } // constructMissingParamsMsg builds a warning string listing each diff --git a/commands/scrutinize_test.go b/commands/scrutinize_test.go index 7ac17a8..dbcd00e 100644 --- a/commands/scrutinize_test.go +++ b/commands/scrutinize_test.go @@ -75,7 +75,7 @@ func TestScrutinCmd(t *testing.T) { assert.ErrorContains(t, err, "unable to get database name from environment variable") } -func TestUpdateCertTextsFromK8s(t *testing.T) { +func TestNMACertLookupFromK8sSecret(t *testing.T) { const randomBytes = "123" c := makeCmdScrutinize() c.k8secretRetreiver = TestK8sSecretRetriever{ @@ -92,8 +92,9 @@ func TestUpdateCertTextsFromK8s(t *testing.T) { // Case 2: when the certs are configured correctly - err := c.updateCertTextsFromk8s(vlog.Printer{}) + ok, err := c.nmaCertLookupFromK8sSecret(vlog.Printer{}) assert.NoError(t, err) + assert.True(t, ok) assert.Equal(t, "test cert 1", c.sOptions.CaCert) assert.Equal(t, "test cert 2", c.sOptions.Cert) assert.Equal(t, "test cert 3", c.sOptions.Key) @@ -106,19 +107,93 @@ func TestUpdateCertTextsFromK8s(t *testing.T) { cert: "test cert 2", key: "", // Missing } - err = c.updateCertTextsFromk8s(vlog.Printer{}) + ok, err = c.nmaCertLookupFromK8sSecret(vlog.Printer{}) assert.Error(t, err) + assert.False(t, ok) // Failure to retrieve the secret should fail the request c = makeCmdScrutinize() c.k8secretRetreiver = TestK8sSecretRetriever{success: false} - err = c.updateCertTextsFromk8s(vlog.Printer{}) + ok, err = c.nmaCertLookupFromK8sSecret(vlog.Printer{}) assert.Error(t, err) + assert.False(t, ok) // If the nma env vars aren't set, then we go onto the next retrieval method os.Clearenv() os.Setenv("KUBERNETES_PORT", randomBytes) c = makeCmdScrutinize() - err = c.updateCertTextsFromk8s(vlog.Printer{}) + ok, err = c.nmaCertLookupFromK8sSecret(vlog.Printer{}) assert.NoError(t, err) + assert.False(t, ok) +} + +func TestNMACertLookupFromEnv(t *testing.T) { + sampleRootCA := "== sample root CA ==" + sampleCert := "== sample cert ==" + sampleKey := "== sample key ==" + + frootCA, err := os.CreateTemp("", "root-ca-") + assert.NoError(t, err) + defer frootCA.Close() + defer os.Remove(frootCA.Name()) + _, err = frootCA.WriteString(sampleRootCA) + assert.NoError(t, err) + frootCA.Close() + + var fcert *os.File + fcert, err = os.CreateTemp("", "cert-") + assert.NoError(t, err) + defer fcert.Close() + defer os.Remove(fcert.Name()) + _, err = fcert.WriteString(sampleCert) + assert.NoError(t, err) + fcert.Close() + + var fkeyEmpty *os.File + fkeyEmpty, err = os.CreateTemp("", "key-") + assert.NoError(t, err) + // Omit writing any data to test code path + fkeyEmpty.Close() + defer os.Remove(fkeyEmpty.Name()) + + os.Setenv(nmaRootCAPathEnvVar, frootCA.Name()) + os.Setenv(nmaCertPathEnvVar, fcert.Name()) + // intentionally omit key path env var to test error path + + // Should fail because only 2 of 3 env vars are set + c := makeCmdScrutinize() + ok, err := c.nmaCertLookupFromEnv(vlog.Printer{}) + assert.Error(t, err) + assert.False(t, ok) + + // Set 3rd env var + os.Setenv(nmaKeyPathEnvVar, fkeyEmpty.Name()) + + // Should fail because one of the files is empty + c = makeCmdScrutinize() + ok, err = c.nmaCertLookupFromEnv(vlog.Printer{}) + assert.Error(t, err) + assert.False(t, ok) + + // Populate empty file with contents + var fkey *os.File + fkey, err = os.CreateTemp("", "key-") + assert.NoError(t, err) + defer fkey.Close() + defer os.Remove(fkey.Name()) + _, err = fkey.WriteString(sampleKey) + assert.NoError(t, err) + fkey.Close() + + // Point to key that is non-empty + os.Setenv(nmaKeyPathEnvVar, fkey.Name()) + + // Should succeed now as everything is setup properly + c = makeCmdScrutinize() + ok, err = c.nmaCertLookupFromEnv(vlog.Printer{}) + assert.NoError(t, err) + assert.True(t, ok) + assert.Equal(t, sampleRootCA, c.sOptions.CaCert) + assert.Equal(t, sampleCert, c.sOptions.Cert) + assert.Equal(t, sampleKey, c.sOptions.Key) } diff --git a/vclusterops/adapter_pool.go b/vclusterops/adapter_pool.go index 8b043d5..e4ff6f8 100644 --- a/vclusterops/adapter_pool.go +++ b/vclusterops/adapter_pool.go @@ -24,19 +24,19 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type AdapterPool struct { +type adapterPool struct { logger vlog.Printer // map from host to HTTPAdapter - connections map[string]Adapter + connections map[string]adapter } var ( - poolInstance AdapterPool + poolInstance adapterPool once sync.Once ) // return a singleton instance of the AdapterPool -func getPoolInstance(logger vlog.Printer) AdapterPool { +func getPoolInstance(logger vlog.Printer) adapterPool { /* if once.Do(f) is called multiple times, * only the first call will invoke f, * even if f has a different value in each invocation. @@ -49,43 +49,43 @@ func getPoolInstance(logger vlog.Printer) AdapterPool { return poolInstance } -func makeAdapterPool(logger vlog.Printer) AdapterPool { - newAdapterPool := AdapterPool{} - newAdapterPool.connections = make(map[string]Adapter) +func makeAdapterPool(logger vlog.Printer) adapterPool { + newAdapterPool := adapterPool{} + newAdapterPool.connections = make(map[string]adapter) newAdapterPool.logger = logger.WithName("AdapterPool") return newAdapterPool } type adapterToRequest struct { - adapter Adapter - request HostHTTPRequest + adapter adapter + request hostHTTPRequest } -func (pool *AdapterPool) sendRequest(clusterHTTPRequest *ClusterHTTPRequest) error { +func (pool *adapterPool) sendRequest(httpRequest *clusterHTTPRequest) error { // build a collection of adapter to request // we need this step as a host may not be in the pool // in that case, we should not proceed var adapterToRequestCollection []adapterToRequest - for host := range clusterHTTPRequest.RequestCollection { - request := clusterHTTPRequest.RequestCollection[host] - adapter, ok := pool.connections[host] + for host := range httpRequest.RequestCollection { + request := httpRequest.RequestCollection[host] + adpt, ok := pool.connections[host] if !ok { return fmt.Errorf("host %s is not found in the adapter pool", host) } - ar := adapterToRequest{adapter: adapter, request: request} + ar := adapterToRequest{adapter: adpt, request: request} adapterToRequestCollection = append(adapterToRequestCollection, ar) } hostCount := len(adapterToRequestCollection) // result channel to collect result from each host - resultChannel := make(chan HostHTTPResult, hostCount) + resultChannel := make(chan hostHTTPResult, hostCount) // only track the progress of HTTP requests for vcluster CLI if pool.logger.ForCli { // use context to check whether a step has completed ctx, cancelCtx := context.WithCancel(context.Background()) - go progressCheck(ctx, clusterHTTPRequest.Name) + go progressCheck(ctx, httpRequest.Name) // cancel the progress check context when the result channel is closed defer cancelCtx() } @@ -101,11 +101,11 @@ func (pool *AdapterPool) sendRequest(clusterHTTPRequest *ClusterHTTPRequest) err // handle results // we expect to receive the same number of results from the channel as the number of hosts // before proceeding to the next steps - clusterHTTPRequest.ResultCollection = make(map[string]HostHTTPResult) + httpRequest.ResultCollection = make(map[string]hostHTTPResult) for i := 0; i < hostCount; i++ { result, ok := <-resultChannel if ok { - clusterHTTPRequest.ResultCollection[result.host] = result + httpRequest.ResultCollection[result.host] = result } } close(resultChannel) diff --git a/vclusterops/add_node.go b/vclusterops/add_node.go index f8d9634..bbf1f20 100644 --- a/vclusterops/add_node.go +++ b/vclusterops/add_node.go @@ -189,7 +189,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa return vdb, fmt.Errorf("fail to produce add node instructions, %w", err) } - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) if runError := clusterOpEngine.run(vcc.Log); runError != nil { return vdb, fmt.Errorf("fail to complete add node operation, %w", runError) @@ -275,7 +275,7 @@ func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase, // pick any up host as intiator initiator := aliveHosts[:1] - var instructions []ClusterOp + var instructions []clusterOp // mark k-safety if len(aliveHosts) < ksafetyThreshold { @@ -298,7 +298,7 @@ func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase, instructions = append(instructions, &httpsDropNodeOp) } - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) err := clusterOpEngine.run(vcc.Log) if err != nil { @@ -333,8 +333,8 @@ func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase, // - Sync catalog // - Rebalance shards on subcluster (Eon mode only) func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDatabase, - options *VAddNodeOptions) ([]ClusterOp, error) { - var instructions []ClusterOp + options *VAddNodeOptions) ([]clusterOp, error) { + var instructions []clusterOp initiatorHost := []string{options.Initiator} newHosts := options.NewHosts allExistingHosts := util.SliceDiff(vdb.HostList, options.NewHosts) @@ -411,9 +411,9 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba func (vcc *VClusterCommands) prepareAdditionalEonInstructions(vdb *VCoordinationDatabase, options *VAddNodeOptions, - instructions []ClusterOp, + instructions []clusterOp, username string, usePassword bool, - initiatorHost, newHosts []string) ([]ClusterOp, error) { + initiatorHost, newHosts []string) ([]clusterOp, error) { if vdb.UseDepot { httpsCreateNodesDepotOp, err := makeHTTPSCreateNodesDepotOp(vcc.Log, vdb, newHosts, usePassword, username, options.Password) diff --git a/vclusterops/add_subcluster.go b/vclusterops/add_subcluster.go index 50da669..14635fc 100644 --- a/vclusterops/add_subcluster.go +++ b/vclusterops/add_subcluster.go @@ -210,7 +210,7 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro } // Create a VClusterOpEngine, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run @@ -234,8 +234,8 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro // - Check if the new subcluster is created in database through HTTPS call // - TODO: add new nodes to the subcluster func (vcc *VClusterCommands) produceAddSubclusterInstructions(addSubclusterInfo *VAddSubclusterInfo, - options *VAddSubclusterOptions) ([]ClusterOp, error) { - var instructions []ClusterOp + options *VAddSubclusterOptions) ([]clusterOp, error) { + var instructions []clusterOp // when password is specified, we will use username/password to call https endpoints usePassword := false diff --git a/vclusterops/cluster_op.go b/vclusterops/cluster_op.go index aaaaaa0..1b7abd8 100644 --- a/vclusterops/cluster_op.go +++ b/vclusterops/cluster_op.go @@ -33,16 +33,16 @@ import ( /* Op and host http result status */ -// ResultStatus is the data type for the status of -// ClusterOpResult and HostHTTPResult -type ResultStatus int +// resultStatus is the data type for the status of +// ClusterOpResult and hostHTTPResult +type resultStatus int var wrongCredentialErrMsg = []string{"Wrong password", "Wrong certificate"} const ( - SUCCESS ResultStatus = 0 - FAILURE ResultStatus = 1 - EXCEPTION ResultStatus = 2 + SUCCESS resultStatus = 0 + FAILURE resultStatus = 1 + EXCEPTION resultStatus = 2 ) const ( @@ -73,10 +73,10 @@ const ( InternalErrorCode = 500 ) -// HostHTTPResult is used to save result of an Adapter's sendRequest(...) function +// hostHTTPResult is used to save result of an Adapter's sendRequest(...) function // it is the element of the adapter pool's channel -type HostHTTPResult struct { - status ResultStatus +type hostHTTPResult struct { + status resultStatus statusCode int host string content string @@ -95,17 +95,17 @@ const respSuccStatusCode = 0 // 3. The local node has not yet joined the cluster; the HTTP server will accept connections once the node joins the cluster. // HTTPCheckDBRunningOp in create_db need to check all scenarios to see any HTTP running // For HTTPSPollNodeStateOp in start_db, it requires only handling the first and second scenarios -func (hostResult *HostHTTPResult) isUnauthorizedRequest() bool { +func (hostResult *hostHTTPResult) isUnauthorizedRequest() bool { return hostResult.statusCode == UnauthorizedCode } // isSuccess returns true if status code is 200 -func (hostResult *HostHTTPResult) isSuccess() bool { +func (hostResult *hostHTTPResult) isSuccess() bool { return hostResult.statusCode == SuccessCode } // check only password and certificate for start_db -func (hostResult *HostHTTPResult) isPasswordAndCertificateError(logger vlog.Printer) bool { +func (hostResult *hostHTTPResult) isPasswordAndCertificateError(logger vlog.Printer) bool { if !hostResult.isUnauthorizedRequest() { return false } @@ -119,30 +119,30 @@ func (hostResult *HostHTTPResult) isPasswordAndCertificateError(logger vlog.Prin return false } -func (hostResult *HostHTTPResult) isInternalError() bool { +func (hostResult *hostHTTPResult) isInternalError() bool { return hostResult.statusCode == InternalErrorCode } -func (hostResult *HostHTTPResult) isHTTPRunning() bool { +func (hostResult *hostHTTPResult) isHTTPRunning() bool { if hostResult.isPassing() || hostResult.isUnauthorizedRequest() || hostResult.isInternalError() { return true } return false } -func (hostResult *HostHTTPResult) isPassing() bool { +func (hostResult *hostHTTPResult) isPassing() bool { return hostResult.err == nil } -func (hostResult *HostHTTPResult) isFailing() bool { +func (hostResult *hostHTTPResult) isFailing() bool { return hostResult.status == FAILURE } -func (hostResult *HostHTTPResult) isException() bool { +func (hostResult *hostHTTPResult) isException() bool { return hostResult.status == EXCEPTION } -func (hostResult *HostHTTPResult) isTimeout() bool { +func (hostResult *hostHTTPResult) isTimeout() bool { if hostResult.err != nil { var netErr net.Error if errors.As(hostResult.err, &netErr) && netErr.Timeout() { @@ -153,7 +153,7 @@ func (hostResult *HostHTTPResult) isTimeout() bool { } // getStatusString converts ResultStatus to string -func (status ResultStatus) getStatusString() string { +func (status resultStatus) getStatusString() string { if status == FAILURE { return FailureResult } else if status == EXCEPTION { @@ -165,44 +165,44 @@ func (status ResultStatus) getStatusString() string { /* Cluster ops interface */ -// ClusterOp interface requires that all ops implements +// clusterOp interface requires that all ops implements // the following functions // log* implemented by embedding OpBase, but overrideable -type ClusterOp interface { +type clusterOp interface { getName() string - prepare(execContext *OpEngineExecContext) error - execute(execContext *OpEngineExecContext) error - finalize(execContext *OpEngineExecContext) error - processResult(execContext *OpEngineExecContext) error - logResponse(host string, result HostHTTPResult) + prepare(execContext *opEngineExecContext) error + execute(execContext *opEngineExecContext) error + finalize(execContext *opEngineExecContext) error + processResult(execContext *opEngineExecContext) error + logResponse(host string, result hostHTTPResult) logPrepare() logExecute() logFinalize() setupBasicInfo() - loadCertsIfNeeded(certs *HTTPSCerts, findCertsInOptions bool) error + loadCertsIfNeeded(certs *httpsCerts, findCertsInOptions bool) error isSkipExecute() bool } /* Cluster ops basic fields and functions */ -// OpBase defines base fields and implements basic functions +// opBase defines base fields and implements basic functions // for all ops -type OpBase struct { +type opBase struct { logger vlog.Printer name string hosts []string - clusterHTTPRequest ClusterHTTPRequest + clusterHTTPRequest clusterHTTPRequest skipExecute bool // This can be set during prepare if we determine no work is needed } -type OpResponseMap map[string]string +type opResponseMap map[string]string -func (op *OpBase) getName() string { +func (op *opBase) getName() string { return op.name } -func (op *OpBase) parseAndCheckResponse(host, responseContent string, responseObj any) error { +func (op *opBase) parseAndCheckResponse(host, responseContent string, responseObj any) error { err := util.GetJSONLogErrors(responseContent, &responseObj, op.name, op.logger) if err != nil { op.logger.Error(err, "fail to parse response on host, detail", "host", host) @@ -212,29 +212,29 @@ func (op *OpBase) parseAndCheckResponse(host, responseContent string, responseOb return nil } -func (op *OpBase) parseAndCheckMapResponse(host, responseContent string) (OpResponseMap, error) { - var responseObj OpResponseMap +func (op *opBase) parseAndCheckMapResponse(host, responseContent string) (opResponseMap, error) { + var responseObj opResponseMap err := op.parseAndCheckResponse(host, responseContent, &responseObj) return responseObj, err } -func (op *OpBase) setClusterHTTPRequestName() { +func (op *opBase) setClusterHTTPRequestName() { op.clusterHTTPRequest.Name = op.name } -func (op *OpBase) setVersionToSemVar() { - op.clusterHTTPRequest.SemVar = SemVer{Ver: "1.0.0"} +func (op *opBase) setVersionToSemVar() { + op.clusterHTTPRequest.SemVar = semVer{Ver: "1.0.0"} } -func (op *OpBase) setupBasicInfo() { - op.clusterHTTPRequest = ClusterHTTPRequest{} - op.clusterHTTPRequest.RequestCollection = make(map[string]HostHTTPRequest) +func (op *opBase) setupBasicInfo() { + op.clusterHTTPRequest = clusterHTTPRequest{} + op.clusterHTTPRequest.RequestCollection = make(map[string]hostHTTPRequest) op.setClusterHTTPRequestName() op.setVersionToSemVar() } -func (op *OpBase) logResponse(host string, result HostHTTPResult) { +func (op *opBase) logResponse(host string, result hostHTTPResult) { if result.err != nil { op.logger.PrintError("[%s] result from host %s summary %s, details: %+v", op.name, host, result.status.getStatusString(), result.err) @@ -244,20 +244,20 @@ func (op *OpBase) logResponse(host string, result HostHTTPResult) { } } -func (op *OpBase) logPrepare() { +func (op *opBase) logPrepare() { op.logger.Info("Prepare() called", "name", op.name) } -func (op *OpBase) logExecute() { +func (op *opBase) logExecute() { op.logger.Info("Execute() called", "name", op.name) op.logger.PrintInfo("[%s] is running", op.name) } -func (op *OpBase) logFinalize() { +func (op *opBase) logFinalize() { op.logger.Info("Finalize() called", "name", op.name) } -func (op *OpBase) runExecute(execContext *OpEngineExecContext) error { +func (op *opBase) runExecute(execContext *opEngineExecContext) error { err := execContext.dispatcher.sendRequest(&op.clusterHTTPRequest) if err != nil { op.logger.Error(err, "Fail to dispatch request, detail", "dispatch request", op.clusterHTTPRequest) @@ -267,7 +267,7 @@ func (op *OpBase) runExecute(execContext *OpEngineExecContext) error { } // 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 { +func (op *opBase) loadCertsIfNeeded(certs *httpsCerts, findCertsInOptions bool) error { if !findCertsInOptions { return nil } @@ -293,13 +293,13 @@ func (op *OpBase) loadCertsIfNeeded(certs *HTTPSCerts, findCertsInOptions bool) // they can only determine at runtime where the operation is needed. One // instance of this is the nma_upload_config.go. If all nodes already have the // latest catalog information, there is nothing to be done during execution. -func (op *OpBase) isSkipExecute() bool { +func (op *opBase) isSkipExecute() bool { return op.skipExecute } // hasQuorum checks if we have enough working primary nodes to maintain data integrity // quorumCount = (1/2 * number of primary nodes) + 1 -func (op *OpBase) hasQuorum(hostCount, primaryNodeCount uint) bool { +func (op *opBase) hasQuorum(hostCount, primaryNodeCount uint) bool { quorumCount := (primaryNodeCount + 1) / 2 if hostCount < quorumCount { op.logger.PrintError("[%s] Quorum check failed: "+ @@ -313,7 +313,7 @@ func (op *OpBase) hasQuorum(hostCount, primaryNodeCount uint) bool { } // checkResponseStatusCode will verify if the status code in https response is a successful code -func (op *OpBase) checkResponseStatusCode(resp httpsResponseStatus, host string) (err error) { +func (op *opBase) checkResponseStatusCode(resp httpsResponseStatus, host string) (err error) { if resp.StatusCode != respSuccStatusCode { err = fmt.Errorf(`[%s] fail to execute HTTPS request on host %s, status code in HTTPS response is %d`, op.name, host, resp.StatusCode) op.logger.Error(err, "fail to execute HTTPS request, detail") @@ -324,14 +324,14 @@ func (op *OpBase) checkResponseStatusCode(resp httpsResponseStatus, host string) /* Sensitive fields in request body */ -type SensitiveFields struct { +type sensitiveFields struct { DBPassword string `json:"db_password"` AWSAccessKeyID string `json:"aws_access_key_id"` AWSSecretAccessKey string `json:"aws_secret_access_key"` Parameters map[string]string `json:"parameters"` } -func (maskedData *SensitiveFields) maskSensitiveInfo() { +func (maskedData *sensitiveFields) maskSensitiveInfo() { const maskedValue = "******" sensitiveKeyParams := map[string]bool{ "awsauth": true, @@ -357,7 +357,7 @@ func (maskedData *SensitiveFields) maskSensitiveInfo() { * for the case where users do not specify a password, e.g., create db * we need the empty password "" string */ -type OpHTTPSBase struct { +type opHTTPSBase struct { useHTTPPassword bool httpsPassword *string userName string @@ -365,7 +365,7 @@ type OpHTTPSBase struct { // we may add some common functions for OpHTTPSBase here -func (opb *OpHTTPSBase) validateAndSetUsernameAndPassword(opName string, useHTTPPassword bool, +func (opb *opHTTPSBase) validateAndSetUsernameAndPassword(opName string, useHTTPPassword bool, userName string, httpsPassword *string) error { opb.useHTTPPassword = useHTTPPassword if opb.useHTTPPassword { diff --git a/vclusterops/cluster_op_engine.go b/vclusterops/cluster_op_engine.go index a101576..64a44a0 100644 --- a/vclusterops/cluster_op_engine.go +++ b/vclusterops/cluster_op_engine.go @@ -22,12 +22,12 @@ import ( ) type VClusterOpEngine struct { - instructions []ClusterOp - certs *HTTPSCerts - execContext *OpEngineExecContext + instructions []clusterOp + certs *httpsCerts + execContext *opEngineExecContext } -func makeClusterOpEngine(instructions []ClusterOp, certs *HTTPSCerts) VClusterOpEngine { +func makeClusterOpEngine(instructions []clusterOp, certs *httpsCerts) VClusterOpEngine { newClusterOpEngine := VClusterOpEngine{} newClusterOpEngine.instructions = instructions newClusterOpEngine.certs = certs diff --git a/vclusterops/cluster_op_engine_context.go b/vclusterops/cluster_op_engine_context.go index 2a7128e..5a79cf4 100644 --- a/vclusterops/cluster_op_engine_context.go +++ b/vclusterops/cluster_op_engine_context.go @@ -17,10 +17,10 @@ package vclusterops import "github.com/vertica/vcluster/vclusterops/vlog" -type OpEngineExecContext struct { - dispatcher HTTPRequestDispatcher - networkProfiles map[string]NetworkProfile - nmaVDatabase NmaVDatabase +type opEngineExecContext struct { + dispatcher requestDispatcher + networkProfiles map[string]networkProfile + nmaVDatabase nmaVDatabase upHosts []string // a sorted host list that contains all up nodes nodesInfo []NodeInfo defaultSCName string // store the default subcluster name of the database @@ -29,8 +29,8 @@ type OpEngineExecContext struct { dbInfo string // store the db info that retrieved from communal storage } -func makeOpEngineExecContext(logger vlog.Printer) OpEngineExecContext { - newOpEngineExecContext := OpEngineExecContext{} +func makeOpEngineExecContext(logger vlog.Printer) opEngineExecContext { + newOpEngineExecContext := opEngineExecContext{} newOpEngineExecContext.dispatcher = makeHTTPRequestDispatcher(logger) return newOpEngineExecContext diff --git a/vclusterops/cluster_op_engine_test.go b/vclusterops/cluster_op_engine_test.go index 8222751..aed7d2a 100644 --- a/vclusterops/cluster_op_engine_test.go +++ b/vclusterops/cluster_op_engine_test.go @@ -24,7 +24,7 @@ import ( ) type mockOp struct { - OpBase + opBase calledPrepare bool calledExecute bool calledFinalize bool @@ -32,14 +32,14 @@ type mockOp struct { func makeMockOp(skipExecute bool) mockOp { return mockOp{ - OpBase: OpBase{ + opBase: opBase{ name: fmt.Sprintf("skip-enabled-%v", skipExecute), skipExecute: skipExecute, }, } } -func (m *mockOp) prepare(_ *OpEngineExecContext) error { +func (m *mockOp) prepare(_ *opEngineExecContext) error { m.calledPrepare = true if !m.skipExecute { return m.setupClusterHTTPRequest([]string{"host1"}) @@ -47,24 +47,24 @@ func (m *mockOp) prepare(_ *OpEngineExecContext) error { return nil } -func (m *mockOp) execute(_ *OpEngineExecContext) error { +func (m *mockOp) execute(_ *opEngineExecContext) error { m.calledExecute = true return nil } -func (m *mockOp) finalize(_ *OpEngineExecContext) error { +func (m *mockOp) finalize(_ *opEngineExecContext) error { m.calledFinalize = true return nil } -func (m *mockOp) processResult(_ *OpEngineExecContext) error { +func (m *mockOp) processResult(_ *opEngineExecContext) error { return nil } func (m *mockOp) setupClusterHTTPRequest(hosts []string) error { - m.clusterHTTPRequest.RequestCollection = map[string]HostHTTPRequest{} + m.clusterHTTPRequest.RequestCollection = map[string]hostHTTPRequest{} for i := range hosts { - m.clusterHTTPRequest.RequestCollection[hosts[i]] = HostHTTPRequest{} + m.clusterHTTPRequest.RequestCollection[hosts[i]] = hostHTTPRequest{} } return nil } @@ -72,8 +72,8 @@ func (m *mockOp) setupClusterHTTPRequest(hosts []string) error { func TestSkipExecuteOp(t *testing.T) { opWithSkipEnabled := makeMockOp(true) opWithSkipDisabled := makeMockOp(false) - instructions := []ClusterOp{&opWithSkipDisabled, &opWithSkipEnabled} - certs := HTTPSCerts{key: "key", cert: "cert", caCert: "ca-cert"} + instructions := []clusterOp{&opWithSkipDisabled, &opWithSkipEnabled} + certs := httpsCerts{key: "key", cert: "cert", caCert: "ca-cert"} opEngn := makeClusterOpEngine(instructions, &certs) err := opEngn.run(vlog.Printer{}) assert.Equal(t, nil, err) diff --git a/vclusterops/cluster_op_test.go b/vclusterops/cluster_op_test.go index 6252613..8c797ed 100644 --- a/vclusterops/cluster_op_test.go +++ b/vclusterops/cluster_op_test.go @@ -22,7 +22,7 @@ import ( ) func TestHasQuorum(t *testing.T) { - op := OpBase{name: "test_op"} + op := opBase{name: "test_op"} // positive case 1: hostCount := uint(2) diff --git a/vclusterops/create_db.go b/vclusterops/create_db.go index 68e7931..6c88c2b 100644 --- a/vclusterops/create_db.go +++ b/vclusterops/create_db.go @@ -408,7 +408,7 @@ func (vcc *VClusterCommands) VCreateDatabase(options *VCreateDatabaseOptions) (V } // create a VClusterOpEngine, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run @@ -445,7 +445,7 @@ func (vcc *VClusterCommands) VCreateDatabase(options *VCreateDatabaseOptions) (V // - Sync catalog func (vcc *VClusterCommands) produceCreateDBInstructions( vdb *VCoordinationDatabase, - options *VCreateDatabaseOptions) ([]ClusterOp, error) { + options *VCreateDatabaseOptions) ([]clusterOp, error) { instructions, err := vcc.produceCreateDBBootstrapInstructions(vdb, options) if err != nil { return instructions, err @@ -470,8 +470,8 @@ func (vcc *VClusterCommands) produceCreateDBInstructions( // produceCreateDBBootstrapInstructions returns the bootstrap instructions for create_db. func (vcc *VClusterCommands) produceCreateDBBootstrapInstructions( vdb *VCoordinationDatabase, - options *VCreateDatabaseOptions) ([]ClusterOp, error) { - var instructions []ClusterOp + options *VCreateDatabaseOptions) ([]clusterOp, error) { + var instructions []clusterOp hosts := vdb.HostList initiator := getInitiator(hosts) @@ -487,7 +487,7 @@ func (vcc *VClusterCommands) produceCreateDBBootstrapInstructions( return instructions, err } - checkDBRunningOp, err := makeHTTPCheckRunningDBOp(vcc.Log, hosts, true, /* use password auth */ + checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(vcc.Log, hosts, true, /* use password auth */ *options.UserName, options.Password, CreateDB) if err != nil { return instructions, err @@ -550,8 +550,8 @@ func (vcc *VClusterCommands) produceCreateDBBootstrapInstructions( // produceCreateDBWorkerNodesInstructions returns the workder nodes' instructions for create_db. func (vcc *VClusterCommands) produceCreateDBWorkerNodesInstructions( vdb *VCoordinationDatabase, - options *VCreateDatabaseOptions) ([]ClusterOp, error) { - var instructions []ClusterOp + options *VCreateDatabaseOptions) ([]clusterOp, error) { + var instructions []clusterOp hosts := vdb.HostList bootstrapHost := options.bootstrapHost @@ -607,8 +607,8 @@ func (vcc *VClusterCommands) produceCreateDBWorkerNodesInstructions( // produceAdditionalCreateDBInstructions returns additional instruction necessary for create_db. func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordinationDatabase, - options *VCreateDatabaseOptions) ([]ClusterOp, error) { - var instructions []ClusterOp + options *VCreateDatabaseOptions) ([]clusterOp, error) { + var instructions []clusterOp hosts := vdb.HostList bootstrapHost := options.bootstrapHost @@ -657,7 +657,7 @@ func (vcc *VClusterCommands) produceAdditionalCreateDBInstructions(vdb *VCoordin return instructions, nil } -func (vcc *VClusterCommands) addEnableSpreadEncryptionOp(keyType string) ClusterOp { +func (vcc *VClusterCommands) addEnableSpreadEncryptionOp(keyType string) clusterOp { vcc.Log.Info("adding instruction to set key for spread encryption") op := makeNMASpreadSecurityOp(vcc.Log, keyType) return &op diff --git a/vclusterops/drop_db.go b/vclusterops/drop_db.go index 008322e..1b91655 100644 --- a/vclusterops/drop_db.go +++ b/vclusterops/drop_db.go @@ -101,7 +101,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} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // give the instructions to the VClusterOpEngine to run @@ -128,8 +128,8 @@ func (vcc *VClusterCommands) VDropDatabase(options *VDropDatabaseOptions) error // - Check NMA connectivity // - Check to see if any dbs running // - Delete directories -func (vcc *VClusterCommands) produceDropDBInstructions(vdb *VCoordinationDatabase, options *VDropDatabaseOptions) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceDropDBInstructions(vdb *VCoordinationDatabase, options *VDropDatabaseOptions) ([]clusterOp, error) { + var instructions []clusterOp hosts := vdb.HostList usePassword := false @@ -145,7 +145,7 @@ func (vcc *VClusterCommands) produceDropDBInstructions(vdb *VCoordinationDatabas // when checking the running database, // drop_db has the same checking items with create_db - checkDBRunningOp, err := makeHTTPCheckRunningDBOp(vcc.Log, hosts, usePassword, + checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(vcc.Log, hosts, usePassword, *options.UserName, options.Password, CreateDB) if err != nil { return instructions, err diff --git a/vclusterops/fetch_node_state.go b/vclusterops/fetch_node_state.go index 2dcfcb6..40823c6 100644 --- a/vclusterops/fetch_node_state.go +++ b/vclusterops/fetch_node_state.go @@ -69,7 +69,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} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run @@ -81,8 +81,8 @@ func (vcc *VClusterCommands) VFetchNodeState(options *VFetchNodeStateOptions) ([ // produceListAllNodesInstructions will build a list of instructions to execute for // the fetch node state operation. -func (vcc *VClusterCommands) produceListAllNodesInstructions(options *VFetchNodeStateOptions) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceListAllNodesInstructions(options *VFetchNodeStateOptions) ([]clusterOp, error) { + var instructions []clusterOp // get hosts hosts := options.Hosts @@ -97,7 +97,7 @@ func (vcc *VClusterCommands) produceListAllNodesInstructions(options *VFetchNode } } - httpsCheckNodeStateOp, err := makeHTTPCheckNodeStateOp(vcc.Log, hosts, + httpsCheckNodeStateOp, err := makeHTTPSCheckNodeStateOp(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 9825786..ff12df4 100644 --- a/vclusterops/helpers.go +++ b/vclusterops/helpers.go @@ -35,7 +35,7 @@ const ( // produceTransferConfigOps generates instructions to transfert some config // files from a sourceConfig node to target nodes. -func produceTransferConfigOps(logger vlog.Printer, instructions *[]ClusterOp, sourceConfigHost, +func produceTransferConfigOps(logger vlog.Printer, instructions *[]clusterOp, sourceConfigHost, targetHosts []string, vdb *VCoordinationDatabase) { var verticaConfContent string nmaDownloadVerticaConfigOp := makeNMADownloadConfigOp( @@ -56,7 +56,7 @@ func produceTransferConfigOps(logger vlog.Printer, instructions *[]ClusterOp, so } // Get catalog path after we have db information from /catalog/database endpoint -func updateCatalogPathMapFromCatalogEditor(hosts []string, nmaVDB *NmaVDatabase, catalogPathMap map[string]string) error { +func updateCatalogPathMapFromCatalogEditor(hosts []string, nmaVDB *nmaVDatabase, catalogPathMap map[string]string) error { if len(hosts) == 0 { return fmt.Errorf("[%s] fail to get host with highest catalog version", nmaVDB.Name) } @@ -75,7 +75,7 @@ func updateCatalogPathMapFromCatalogEditor(hosts []string, nmaVDB *NmaVDatabase, // The following structs will store hosts' necessary information for https_get_up_nodes_op, // https_get_nodes_information_from_running_db, and incoming operations. -type NodeStateInfo struct { +type nodeStateInfo struct { Address string `json:"address"` State string `json:"state"` Database string `json:"database"` @@ -85,8 +85,8 @@ type NodeStateInfo struct { Name string `json:"name"` } -type NodesStateInfo struct { - NodeList []NodeStateInfo `json:"node_list"` +type nodesStateInfo struct { + NodeList []nodeStateInfo `json:"node_list"` } // getInitiatorHost returns as initiator the first primary up node that is not @@ -119,10 +119,10 @@ func (vcc *VClusterCommands) getVDBFromRunningDB(vdb *VCoordinationDatabase, opt return fmt.Errorf("fail to produce httpsGetClusterInfo instructions while retrieving database configurations, %w", err) } - var instructions []ClusterOp + var instructions []clusterOp instructions = append(instructions, &httpsGetNodesInfoOp, &httpsGetClusterInfoOp) - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) err = clusterOpEngine.run(vcc.Log) if err != nil { diff --git a/vclusterops/helpers_test.go b/vclusterops/helpers_test.go index 7e9a8ed..c44787f 100644 --- a/vclusterops/helpers_test.go +++ b/vclusterops/helpers_test.go @@ -25,11 +25,11 @@ import ( // positive test case for updateCatalogPathMapFromCatalogEditor func TestForupdateCatalogPathMapFromCatalogEditorPositive(t *testing.T) { // prepare data for nmaVDB - mockNmaVNode1 := &NmaVNode{CatalogPath: "/data/test_db/v_test_db_node0001_catalog/Catalog", Address: "192.168.1.101"} - mockNmaVNode2 := &NmaVNode{CatalogPath: "/Catalog/data/test_db/v_test_db_node0002_catalog/Catalog", Address: "192.168.1.102"} - mockNmaVNode3 := &NmaVNode{CatalogPath: "/data/test_db/v_test_db_node0003_catalog/Catalog", Address: "192.168.1.103"} - mockHostNodeMap := map[string]*NmaVNode{"192.168.1.101": mockNmaVNode1, "192.168.1.102": mockNmaVNode2, "192.168.1.103": mockNmaVNode3} - mockNmaVDB := &NmaVDatabase{HostNodeMap: mockHostNodeMap} + mockNmaVNode1 := &nmaVNode{CatalogPath: "/data/test_db/v_test_db_node0001_catalog/Catalog", Address: "192.168.1.101"} + mockNmaVNode2 := &nmaVNode{CatalogPath: "/Catalog/data/test_db/v_test_db_node0002_catalog/Catalog", Address: "192.168.1.102"} + mockNmaVNode3 := &nmaVNode{CatalogPath: "/data/test_db/v_test_db_node0003_catalog/Catalog", Address: "192.168.1.103"} + mockHostNodeMap := map[string]*nmaVNode{"192.168.1.101": mockNmaVNode1, "192.168.1.102": mockNmaVNode2, "192.168.1.103": mockNmaVNode3} + mockNmaVDB := &nmaVDatabase{HostNodeMap: mockHostNodeMap} host := []string{"192.168.1.101", "192.168.1.102", "192.168.1.103"} mockCatalogPath := make(map[string]string) err := updateCatalogPathMapFromCatalogEditor(host, mockNmaVDB, mockCatalogPath) @@ -42,10 +42,10 @@ func TestForupdateCatalogPathMapFromCatalogEditorPositive(t *testing.T) { // negative test case for updateCatalogPathMapFromCatalogEditor func TestForupdateCatalogPathMapFromCatalogEditorNegative(t *testing.T) { // prepare data for nmaVDB - mockNmaVNode1 := &NmaVNode{CatalogPath: "/data/test_db/v_test_db_node0001_catalog/Catalog", Address: "192.168.1.101"} - mockNmaVNode2 := &NmaVNode{CatalogPath: "/data/test_db/v_test_db_node0002_catalog/Catalog", Address: "192.168.1.102"} - mockHostNodeMap := map[string]*NmaVNode{"192.168.1.101": mockNmaVNode1, "192.168.1.102": mockNmaVNode2} - mockNmaVDB := &NmaVDatabase{HostNodeMap: mockHostNodeMap} + mockNmaVNode1 := &nmaVNode{CatalogPath: "/data/test_db/v_test_db_node0001_catalog/Catalog", Address: "192.168.1.101"} + mockNmaVNode2 := &nmaVNode{CatalogPath: "/data/test_db/v_test_db_node0002_catalog/Catalog", Address: "192.168.1.102"} + mockHostNodeMap := map[string]*nmaVNode{"192.168.1.101": mockNmaVNode1, "192.168.1.102": mockNmaVNode2} + mockNmaVDB := &nmaVDatabase{HostNodeMap: mockHostNodeMap} host := []string{"192.168.1.101", "192.168.1.103"} mockCatalogPath := make(map[string]string) err := updateCatalogPathMapFromCatalogEditor(host, mockNmaVDB, mockCatalogPath) diff --git a/vclusterops/http_adapter.go b/vclusterops/http_adapter.go index c5ce070..7bdfa37 100644 --- a/vclusterops/http_adapter.go +++ b/vclusterops/http_adapter.go @@ -32,14 +32,14 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPAdapter struct { - OpBase +type httpAdapter struct { + opBase host string respBodyHandler responseBodyHandler } -func makeHTTPAdapter(logger vlog.Printer) HTTPAdapter { - newHTTPAdapter := HTTPAdapter{} +func makeHTTPAdapter(logger vlog.Printer) httpAdapter { + newHTTPAdapter := httpAdapter{} newHTTPAdapter.name = "HTTPAdapter" newHTTPAdapter.logger = logger.WithName(newHTTPAdapter.name) newHTTPAdapter.respBodyHandler = &responseBodyReader{} @@ -50,7 +50,7 @@ func makeHTTPAdapter(logger vlog.Printer) HTTPAdapter { // download a response body to a file via streaming read and // buffered write, rather than copying the body to memory. func makeHTTPDownloadAdapter(logger vlog.Printer, - destFilePath string) HTTPAdapter { + destFilePath string) httpAdapter { newHTTPAdapter := makeHTTPAdapter(logger) newHTTPAdapter.respBodyHandler = &responseBodyDownloader{ logger, @@ -85,7 +85,7 @@ type certificatePaths struct { caFile string } -func (adapter *HTTPAdapter) sendRequest(request *HostHTTPRequest, resultChannel chan<- HostHTTPResult) { +func (adapter *httpAdapter) sendRequest(request *hostHTTPRequest, resultChannel chan<- hostHTTPResult) { // build query params queryParams := buildQueryParamString(request.QueryParams) @@ -155,7 +155,7 @@ func (adapter *HTTPAdapter) sendRequest(request *HostHTTPRequest, resultChannel resultChannel <- adapter.generateResult(resp) } -func (adapter *HTTPAdapter) generateResult(resp *http.Response) HostHTTPResult { +func (adapter *httpAdapter) generateResult(resp *http.Response) hostHTTPResult { bodyString, err := adapter.respBodyHandler.readResponseBody(resp) if err != nil { return adapter.makeExceptionResult(err) @@ -196,10 +196,10 @@ func (downloader *responseBodyDownloader) downloadFile(resp *http.Response) (byt return io.Copy(file, resp.Body) } -// makeSuccessResult is a factory method for HostHTTPResult when a success +// makeSuccessResult is a factory method for hostHTTPResult when a success // response comes back from a REST endpoints. -func (adapter *HTTPAdapter) makeSuccessResult(content string, statusCode int) HostHTTPResult { - return HostHTTPResult{ +func (adapter *httpAdapter) makeSuccessResult(content string, statusCode int) hostHTTPResult { + return hostHTTPResult{ host: adapter.host, status: SUCCESS, statusCode: statusCode, @@ -207,22 +207,22 @@ func (adapter *HTTPAdapter) makeSuccessResult(content string, statusCode int) Ho } } -// makeExceptionResult is a factory method for HostHTTPResult when an error +// makeExceptionResult is a factory method for hostHTTPResult when an error // during the process of communicating with a REST endpoint. It won't refer to // the error received over the wire, but usually some error that occurred in the // process of communicating. -func (adapter *HTTPAdapter) makeExceptionResult(err error) HostHTTPResult { - return HostHTTPResult{ +func (adapter *httpAdapter) makeExceptionResult(err error) hostHTTPResult { + return hostHTTPResult{ host: adapter.host, status: EXCEPTION, err: err, } } -// makeFailResult is a factory method for HostHTTPResult when an error response +// makeFailResult is a factory method for hostHTTPResult when an error response // is received from a REST endpoint. -func (adapter *HTTPAdapter) makeFailResult(header http.Header, respBody string, statusCode int) HostHTTPResult { - return HostHTTPResult{ +func (adapter *httpAdapter) makeFailResult(header http.Header, respBody string, statusCode int) hostHTTPResult { + return hostHTTPResult{ host: adapter.host, status: FAILURE, statusCode: statusCode, @@ -234,14 +234,14 @@ func (adapter *HTTPAdapter) makeFailResult(header http.Header, respBody string, // extractErrorFromResponse is called when we get a failed response from a REST // call. We will look at the headers and response body to decide what error // object to create. -func (adapter *HTTPAdapter) extractErrorFromResponse(header http.Header, respBody string, statusCode int) error { +func (adapter *httpAdapter) extractErrorFromResponse(header http.Header, respBody string, statusCode int) error { if header.Get("Content-Type") == rfc7807.ContentType { return rfc7807.GenerateErrorFromResponse(respBody) } return fmt.Errorf("status code %d returned from host %s: %s", statusCode, adapter.host, respBody) } -func whetherUsePassword(request *HostHTTPRequest) (bool, error) { +func whetherUsePassword(request *hostHTTPRequest) (bool, error) { if request.IsNMACommand { return false, nil } @@ -270,7 +270,7 @@ func whetherUsePassword(request *HostHTTPRequest) (bool, error) { // this variable is for unit test, be careful to modify it var getCertFilePathsFn = getCertFilePaths -func (adapter *HTTPAdapter) buildCertsFromFile() (tls.Certificate, *x509.CertPool, error) { +func (adapter *httpAdapter) buildCertsFromFile() (tls.Certificate, *x509.CertPool, error) { certPaths, err := getCertFilePathsFn() if err != nil { return tls.Certificate{}, nil, fmt.Errorf("fail to get paths for certificates, details %w", err) @@ -291,7 +291,7 @@ func (adapter *HTTPAdapter) buildCertsFromFile() (tls.Certificate, *x509.CertPoo return cert, caCertPool, nil } -func (adapter *HTTPAdapter) buildCertsFromMemory(key, cert, caCert string) (tls.Certificate, *x509.CertPool, error) { +func (adapter *httpAdapter) buildCertsFromMemory(key, cert, caCert string) (tls.Certificate, *x509.CertPool, error) { certificate, err := tls.X509KeyPair([]byte(cert), []byte(key)) if err != nil { return certificate, nil, fmt.Errorf("fail to load HTTPS certificates, details %w", err) @@ -306,10 +306,10 @@ func (adapter *HTTPAdapter) buildCertsFromMemory(key, cert, caCert string) (tls. return certificate, caCertPool, nil } -func (adapter *HTTPAdapter) setupHTTPClient( - request *HostHTTPRequest, +func (adapter *httpAdapter) setupHTTPClient( + request *hostHTTPRequest, usePassword bool, - _ chan<- HostHTTPResult) (*http.Client, error) { + _ chan<- hostHTTPResult) (*http.Client, error) { var client *http.Client // set up request timeout diff --git a/vclusterops/http_adapter_test.go b/vclusterops/http_adapter_test.go index 288de79..179ce87 100644 --- a/vclusterops/http_adapter_test.go +++ b/vclusterops/http_adapter_test.go @@ -63,7 +63,7 @@ func getCertFilePathsMock() (certPaths certificatePaths, err error) { } func TestBuildCertsFromMemory(t *testing.T) { - adapter := HTTPAdapter{} + adapter := httpAdapter{} // get cert and cacert using buildCertsFromFile() originalFunc := getCertFilePaths @@ -130,7 +130,7 @@ func (m *MockReadCloser) Close() error { } func TestHandleSuccessResponseCodes(t *testing.T) { - adapter := HTTPAdapter{respBodyHandler: &responseBodyReader{}} + adapter := httpAdapter{respBodyHandler: &responseBodyReader{}} mockBodyReader := MockReadCloser{ body: []byte("success!"), } @@ -144,7 +144,7 @@ func TestHandleSuccessResponseCodes(t *testing.T) { } func TestHandleRFC7807Response(t *testing.T) { - adapter := HTTPAdapter{respBodyHandler: &responseBodyReader{}} + adapter := httpAdapter{respBodyHandler: &responseBodyReader{}} rfcErr := rfc7807.New(rfc7807.CommunalAccessError). WithDetail("Cannot access communal storage") b, err := json.Marshal(rfcErr) @@ -178,7 +178,7 @@ func TestHandleGenericErrorResponse(t *testing.T) { Header: http.Header{}, Body: &mockBodyReader, } - adapter := HTTPAdapter{respBodyHandler: &responseBodyReader{}} + adapter := httpAdapter{respBodyHandler: &responseBodyReader{}} result := adapter.generateResult(mockResp) assert.Equal(t, result.status, FAILURE) assert.NotEqual(t, result.err, nil) diff --git a/vclusterops/http_request.go b/vclusterops/http_request.go index 79116b3..b432479 100644 --- a/vclusterops/http_request.go +++ b/vclusterops/http_request.go @@ -15,7 +15,7 @@ package vclusterops -type HostHTTPRequest struct { +type hostHTTPRequest struct { Method string Endpoint string IsNMACommand bool @@ -28,29 +28,29 @@ type HostHTTPRequest struct { // optional, for calling NMA/Vertica HTTPS endpoints. If Username/Password is set, that takes precedence over this for HTTPS calls. UseCertsInOptions bool - Certs HTTPSCerts + Certs httpsCerts } -type HTTPSCerts struct { +type httpsCerts struct { key string cert string caCert string } -func (req *HostHTTPRequest) buildNMAEndpoint(url string) { +func (req *hostHTTPRequest) buildNMAEndpoint(url string) { req.IsNMACommand = true req.Endpoint = NMACurVersion + url } -func (req *HostHTTPRequest) buildHTTPSEndpoint(url string) { +func (req *hostHTTPRequest) buildHTTPSEndpoint(url string) { req.IsNMACommand = false req.Endpoint = HTTPCurVersion + url } // this is used as the "ATModuleBase" in Admintools -type ClusterHTTPRequest struct { - RequestCollection map[string]HostHTTPRequest - ResultCollection map[string]HostHTTPResult - SemVar SemVer +type clusterHTTPRequest struct { + RequestCollection map[string]hostHTTPRequest + ResultCollection map[string]hostHTTPResult + SemVar semVer Name string } diff --git a/vclusterops/http_request_dispatcher.go b/vclusterops/http_request_dispatcher.go index 90dfc66..3b235b0 100644 --- a/vclusterops/http_request_dispatcher.go +++ b/vclusterops/http_request_dispatcher.go @@ -17,13 +17,13 @@ package vclusterops import "github.com/vertica/vcluster/vclusterops/vlog" -type HTTPRequestDispatcher struct { - OpBase - pool AdapterPool +type requestDispatcher struct { + opBase + pool adapterPool } -func makeHTTPRequestDispatcher(logger vlog.Printer) HTTPRequestDispatcher { - newHTTPRequestDispatcher := HTTPRequestDispatcher{} +func makeHTTPRequestDispatcher(logger vlog.Printer) requestDispatcher { + newHTTPRequestDispatcher := requestDispatcher{} newHTTPRequestDispatcher.name = "HTTPRequestDispatcher" newHTTPRequestDispatcher.logger = logger.WithName(newHTTPRequestDispatcher.name) @@ -31,10 +31,10 @@ func makeHTTPRequestDispatcher(logger vlog.Printer) HTTPRequestDispatcher { } // set up the pool connection for each host -func (dispatcher *HTTPRequestDispatcher) setup(hosts []string) { +func (dispatcher *requestDispatcher) setup(hosts []string) { dispatcher.pool = getPoolInstance(dispatcher.logger) - dispatcher.pool.connections = make(map[string]Adapter) + dispatcher.pool.connections = make(map[string]adapter) for _, host := range hosts { adapter := makeHTTPAdapter(dispatcher.logger) adapter.host = host @@ -43,7 +43,7 @@ func (dispatcher *HTTPRequestDispatcher) setup(hosts []string) { } // set up the pool connection for each host to download a file -func (dispatcher *HTTPRequestDispatcher) setupForDownload(hosts []string, +func (dispatcher *requestDispatcher) setupForDownload(hosts []string, hostToFilePathsMap map[string]string) { dispatcher.pool = getPoolInstance(dispatcher.logger) @@ -54,7 +54,7 @@ func (dispatcher *HTTPRequestDispatcher) setupForDownload(hosts []string, } } -func (dispatcher *HTTPRequestDispatcher) sendRequest(clusterHTTPRequest *ClusterHTTPRequest) error { +func (dispatcher *requestDispatcher) sendRequest(httpRequest *clusterHTTPRequest) error { dispatcher.logger.Info("HTTP request dispatcher's sendRequest is called") - return dispatcher.pool.sendRequest(clusterHTTPRequest) + return dispatcher.pool.sendRequest(httpRequest) } diff --git a/vclusterops/https_add_subcluster_op.go b/vclusterops/https_add_subcluster_op.go index 2b26997..7866305 100644 --- a/vclusterops/https_add_subcluster_op.go +++ b/vclusterops/https_add_subcluster_op.go @@ -24,9 +24,9 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSAddSubclusterOp struct { - OpBase - OpHTTPSBase +type httpsAddSubclusterOp struct { + opBase + opHTTPSBase hostRequestBodyMap map[string]string scName string isSecondary bool @@ -34,24 +34,24 @@ type HTTPSAddSubclusterOp struct { } func makeHTTPSAddSubclusterOp(logger 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.logger = logger.WithName(httpsAddSubclusterOp.name) - httpsAddSubclusterOp.isSecondary = !isPrimary - httpsAddSubclusterOp.ctlSetSize = ctlSetSize - - httpsAddSubclusterOp.useHTTPPassword = useHTTPPassword + scName string, isPrimary bool, ctlSetSize int) (httpsAddSubclusterOp, error) { + op := httpsAddSubclusterOp{} + op.name = "HTTPSAddSubclusterOp" + op.scName = scName + op.logger = logger.WithName(op.name) + op.isSecondary = !isPrimary + op.ctlSetSize = ctlSetSize + + op.useHTTPPassword = useHTTPPassword if useHTTPPassword { - err := util.ValidateUsernameAndPassword(httpsAddSubclusterOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsAddSubclusterOp, err + return op, err } - httpsAddSubclusterOp.userName = userName - httpsAddSubclusterOp.httpsPassword = httpsPassword + op.userName = userName + op.httpsPassword = httpsPassword } - return httpsAddSubclusterOp, nil + return op, nil } type addSubclusterRequestData struct { @@ -59,7 +59,7 @@ type addSubclusterRequestData struct { CtlSetSize int `json:"control_set_size,omitempty"` } -func (op *HTTPSAddSubclusterOp) setupRequestBody(hosts []string) error { +func (op *httpsAddSubclusterOp) setupRequestBody(hosts []string) error { op.hostRequestBodyMap = make(map[string]string) for _, host := range hosts { @@ -78,9 +78,9 @@ func (op *HTTPSAddSubclusterOp) setupRequestBody(hosts []string) error { return nil } -func (op *HTTPSAddSubclusterOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsAddSubclusterOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("subclusters/" + op.scName) if op.useHTTPPassword { @@ -94,7 +94,7 @@ func (op *HTTPSAddSubclusterOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSAddSubclusterOp) prepare(execContext *OpEngineExecContext) 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) } @@ -109,7 +109,7 @@ func (op *HTTPSAddSubclusterOp) prepare(execContext *OpEngineExecContext) error return op.setupClusterHTTPRequest(hosts) } -func (op *HTTPSAddSubclusterOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsAddSubclusterOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -117,7 +117,7 @@ func (op *HTTPSAddSubclusterOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *HTTPSAddSubclusterOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsAddSubclusterOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -151,6 +151,6 @@ func (op *HTTPSAddSubclusterOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSAddSubclusterOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsAddSubclusterOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_check_db_running_op.go b/vclusterops/https_check_db_running_op.go index fb2c238..762a8ab 100644 --- a/vclusterops/https_check_db_running_op.go +++ b/vclusterops/https_check_db_running_op.go @@ -25,16 +25,16 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type OpType int +type opType int const ( - CreateDB OpType = iota + CreateDB opType = iota StopDB StartDB ReviveDB ) -func (op OpType) String() string { +func (op opType) String() string { switch op { case CreateDB: return "Create DB" @@ -48,36 +48,36 @@ func (op OpType) String() string { return "unknown operation" } -type HTTPCheckRunningDBOp struct { - OpBase - OpHTTPSBase - opType OpType +type httpsCheckRunningDBOp struct { + opBase + opHTTPSBase + opType opType } -func makeHTTPCheckRunningDBOp(logger vlog.Printer, hosts []string, +func makeHTTPSCheckRunningDBOp(logger vlog.Printer, hosts []string, useHTTPPassword bool, userName string, - httpsPassword *string, opType OpType, -) (HTTPCheckRunningDBOp, error) { - runningDBChecker := HTTPCheckRunningDBOp{} - runningDBChecker.name = "HTTPCheckDBRunningOp" - runningDBChecker.logger = logger.WithName(runningDBChecker.name) - runningDBChecker.hosts = hosts - runningDBChecker.useHTTPPassword = useHTTPPassword - - err := util.ValidateUsernameAndPassword(runningDBChecker.name, useHTTPPassword, userName) + httpsPassword *string, operationType opType, +) (httpsCheckRunningDBOp, error) { + op := httpsCheckRunningDBOp{} + op.name = "HTTPCheckDBRunningOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.useHTTPPassword = useHTTPPassword + + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return runningDBChecker, err + return op, err } - runningDBChecker.userName = userName - runningDBChecker.httpsPassword = httpsPassword - runningDBChecker.opType = opType - return runningDBChecker, nil + op.userName = userName + op.httpsPassword = httpsPassword + op.opType = operationType + return op, nil } -func (op *HTTPCheckRunningDBOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsCheckRunningDBOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("nodes") if op.useHTTPPassword { @@ -90,17 +90,17 @@ func (op *HTTPCheckRunningDBOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPCheckRunningDBOp) logPrepare() { +func (op *httpsCheckRunningDBOp) logPrepare() { op.logger.Info("prepare() called", "opType", op.opType) } -func (op *HTTPCheckRunningDBOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsCheckRunningDBOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -/* HTTPNodeStateResponse example: +/* httpsNodeStateResponse example: { "details": null, "node_list":[{ @@ -125,11 +125,11 @@ func (op *HTTPCheckRunningDBOp) prepare(execContext *OpEngineExecContext) error // or a message if the endpoint doesn't return a well-structured JSON, examples: // {"message": "Local node has not joined cluster yet, HTTP server will accept connections when the node has joined the cluster\n"} // {"message": "Wrong password\n"} -type NodeList []map[string]any -type HTTPNodeStateResponse map[string]NodeList +type nodeList []map[string]any +type httpsNodeStateResponse map[string]nodeList -func (op *HTTPCheckRunningDBOp) isDBRunningOnHost(host string, - responseObj HTTPNodeStateResponse) (running bool, msg string, err error) { +func (op *httpsCheckRunningDBOp) isDBRunningOnHost(host string, + responseObj httpsNodeStateResponse) (running bool, msg string, err error) { // parse and log the results msg = "" nodeList, ok := responseObj["node_list"] @@ -166,7 +166,7 @@ func (op *HTTPCheckRunningDBOp) isDBRunningOnHost(host string, // processResult will look at all of the results that come back from the hosts. // We don't return an error if all of the nodes are down. Otherwise, an error is // returned. -func (op *HTTPCheckRunningDBOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsCheckRunningDBOp) processResult(_ *opEngineExecContext) error { var allErrs error // golang doesn't have set data structure, // so use maps for caching distinct up and down hosts @@ -190,7 +190,7 @@ func (op *HTTPCheckRunningDBOp) processResult(_ *OpEngineExecContext) error { upHosts[host] = true // a passing result means that the db isn't down - var responseObj HTTPNodeStateResponse + var responseObj httpsNodeStateResponse err := op.parseAndCheckResponse(host, result.content, &responseObj) // don't return, as an error here could just mean a node not being up @@ -235,7 +235,7 @@ func (op *HTTPCheckRunningDBOp) processResult(_ *OpEngineExecContext) error { return errors.Join(allErrs, errors.New(msg)) } -func (op *HTTPCheckRunningDBOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsCheckRunningDBOp) execute(execContext *opEngineExecContext) error { op.logger.Info("Execute() called", "opType", op.opType) switch op.opType { case CreateDB, StartDB, ReviveDB: @@ -247,7 +247,7 @@ func (op *HTTPCheckRunningDBOp) execute(execContext *OpEngineExecContext) error return fmt.Errorf("unknown operation found in HTTPCheckRunningDBOp") } -func (op *HTTPCheckRunningDBOp) pollForDBDown(execContext *OpEngineExecContext) error { +func (op *httpsCheckRunningDBOp) pollForDBDown(execContext *opEngineExecContext) error { // start the polling startTime := time.Now() // for tests @@ -291,7 +291,7 @@ func (op *HTTPCheckRunningDBOp) pollForDBDown(execContext *OpEngineExecContext) return errors.New(msg) } -func (op *HTTPCheckRunningDBOp) checkDBConnection(execContext *OpEngineExecContext) error { +func (op *httpsCheckRunningDBOp) checkDBConnection(execContext *opEngineExecContext) error { err := execContext.dispatcher.sendRequest(&op.clusterHTTPRequest) if err != nil { return fmt.Errorf("fail to dispatch request %v: %w", op.clusterHTTPRequest, err) @@ -299,6 +299,6 @@ func (op *HTTPCheckRunningDBOp) checkDBConnection(execContext *OpEngineExecConte return op.processResult(execContext) } -func (op *HTTPCheckRunningDBOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsCheckRunningDBOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_check_node_state_op.go b/vclusterops/https_check_node_state_op.go index c251d38..080980c 100644 --- a/vclusterops/https_check_node_state_op.go +++ b/vclusterops/https_check_node_state_op.go @@ -23,17 +23,17 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPCheckNodeStateOp struct { - OpBase - OpHTTPSBase +type httpsCheckNodeStateOp struct { + opBase + opHTTPSBase } -func makeHTTPCheckNodeStateOp(logger vlog.Printer, hosts []string, +func makeHTTPSCheckNodeStateOp(logger vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, -) (HTTPCheckNodeStateOp, error) { - nodeStateChecker := HTTPCheckNodeStateOp{} +) (httpsCheckNodeStateOp, error) { + nodeStateChecker := httpsCheckNodeStateOp{} nodeStateChecker.logger = logger.WithName(nodeStateChecker.name) nodeStateChecker.name = "HTTPCheckNodeStateOp" // The hosts are the ones we are going to talk to. @@ -52,9 +52,9 @@ func makeHTTPCheckNodeStateOp(logger vlog.Printer, hosts []string, return nodeStateChecker, nil } -func (op *HTTPCheckNodeStateOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsCheckNodeStateOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("nodes") if op.useHTTPPassword { @@ -67,13 +67,13 @@ func (op *HTTPCheckNodeStateOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPCheckNodeStateOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsCheckNodeStateOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPCheckNodeStateOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsCheckNodeStateOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -81,7 +81,7 @@ func (op *HTTPCheckNodeStateOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *HTTPCheckNodeStateOp) processResult(execContext *OpEngineExecContext) error { +func (op *httpsCheckNodeStateOp) processResult(execContext *opEngineExecContext) error { var allErrs error respondingNodeCount := 0 @@ -110,7 +110,7 @@ func (op *HTTPCheckNodeStateOp) processResult(execContext *OpEngineExecContext) // parse the /nodes endpoint response respondingNodeCount++ - nodesInfo := NodesInfo{} + nodesInfo := nodesInfo{} err := op.parseAndCheckResponse(host, result.content, &nodesInfo) if err != nil { err = fmt.Errorf("[%s] fail to parse result on host %s: %w", @@ -139,6 +139,6 @@ func (op *HTTPCheckNodeStateOp) processResult(execContext *OpEngineExecContext) return allErrs } -func (op *HTTPCheckNodeStateOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsCheckNodeStateOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_check_subcluster_op.go b/vclusterops/https_check_subcluster_op.go index 811b4db..3d3b99e 100644 --- a/vclusterops/https_check_subcluster_op.go +++ b/vclusterops/https_check_subcluster_op.go @@ -22,38 +22,38 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSCheckSubclusterOp struct { - OpBase - OpHTTPSBase +type httpsCheckSubclusterOp struct { + opBase + opHTTPSBase scName string isSecondary bool ctlSetSize int } func makeHTTPSCheckSubclusterOp(logger vlog.Printer, useHTTPPassword bool, userName string, httpsPassword *string, - scName string, isPrimary bool, ctlSetSize int) (HTTPSCheckSubclusterOp, error) { - httpsCheckSubclusterOp := HTTPSCheckSubclusterOp{} - httpsCheckSubclusterOp.name = "HTTPSCheckSubclusterOp" - httpsCheckSubclusterOp.logger = logger.WithName(httpsCheckSubclusterOp.name) - httpsCheckSubclusterOp.scName = scName - httpsCheckSubclusterOp.isSecondary = !isPrimary - httpsCheckSubclusterOp.ctlSetSize = ctlSetSize - - httpsCheckSubclusterOp.useHTTPPassword = useHTTPPassword + scName string, isPrimary bool, ctlSetSize int) (httpsCheckSubclusterOp, error) { + op := httpsCheckSubclusterOp{} + op.name = "HTTPSCheckSubclusterOp" + op.logger = logger.WithName(op.name) + op.scName = scName + op.isSecondary = !isPrimary + op.ctlSetSize = ctlSetSize + + op.useHTTPPassword = useHTTPPassword if useHTTPPassword { - err := util.ValidateUsernameAndPassword(httpsCheckSubclusterOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsCheckSubclusterOp, err + return op, err } - httpsCheckSubclusterOp.userName = userName - httpsCheckSubclusterOp.httpsPassword = httpsPassword + op.userName = userName + op.httpsPassword = httpsPassword } - return httpsCheckSubclusterOp, nil + return op, nil } -func (op *HTTPSCheckSubclusterOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsCheckSubclusterOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("subclusters/" + op.scName) if op.useHTTPPassword { @@ -66,7 +66,7 @@ func (op *HTTPSCheckSubclusterOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *HTTPSCheckSubclusterOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsCheckSubclusterOp) prepare(execContext *opEngineExecContext) error { if len(execContext.upHosts) == 0 { return fmt.Errorf(`[%s] Cannot find any up hosts in OpEngineExecContext`, op.name) } @@ -75,7 +75,7 @@ func (op *HTTPSCheckSubclusterOp) prepare(execContext *OpEngineExecContext) erro return op.setupClusterHTTPRequest(execContext.upHosts) } -func (op *HTTPSCheckSubclusterOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsCheckSubclusterOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -84,13 +84,13 @@ func (op *HTTPSCheckSubclusterOp) execute(execContext *OpEngineExecContext) erro } // the following struct will store a subcluster's information for this op -type SCInfo struct { +type scInfo struct { SCName string `json:"subcluster_name"` IsSecondary bool `json:"is_secondary"` CtlSetSize int `json:"control_set_size"` } -func (op *HTTPSCheckSubclusterOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsCheckSubclusterOp) processResult(_ *opEngineExecContext) error { var err error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -117,23 +117,23 @@ func (op *HTTPSCheckSubclusterOp) processResult(_ *OpEngineExecContext) error { "sandbox": "" } */ - scInfo := SCInfo{} - err = op.parseAndCheckResponse(host, result.content, &scInfo) + subclusterInfo := scInfo{} + err = op.parseAndCheckResponse(host, result.content, &subclusterInfo) if err != nil { return fmt.Errorf(`[%s] fail to parse result on host %s, details: %w`, op.name, host, err) } - if scInfo.SCName != op.scName { - return fmt.Errorf(`[%s] new subcluster name should be '%s' but got '%s'`, op.name, op.scName, scInfo.SCName) + if subclusterInfo.SCName != op.scName { + return fmt.Errorf(`[%s] new subcluster name should be '%s' but got '%s'`, op.name, op.scName, subclusterInfo.SCName) } - if scInfo.IsSecondary != op.isSecondary { + if subclusterInfo.IsSecondary != op.isSecondary { if op.isSecondary { return fmt.Errorf(`[%s] new subcluster should be a secondary subcluster but got a primary subcluster`, op.name) } return fmt.Errorf(`[%s] new subcluster should be a primary subcluster but got a secondary subcluster`, op.name) } - if scInfo.CtlSetSize != op.ctlSetSize { - return fmt.Errorf(`[%s] new subcluster should have control set size as %d but got %d`, op.name, op.ctlSetSize, scInfo.CtlSetSize) + if subclusterInfo.CtlSetSize != op.ctlSetSize { + return fmt.Errorf(`[%s] new subcluster should have control set size as %d but got %d`, op.name, op.ctlSetSize, subclusterInfo.CtlSetSize) } return nil @@ -142,6 +142,6 @@ func (op *HTTPSCheckSubclusterOp) processResult(_ *OpEngineExecContext) error { return err } -func (op *HTTPSCheckSubclusterOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsCheckSubclusterOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_create_cluster_depot_op.go b/vclusterops/https_create_cluster_depot_op.go index d2bab70..c3cae9b 100644 --- a/vclusterops/https_create_cluster_depot_op.go +++ b/vclusterops/https_create_cluster_depot_op.go @@ -25,46 +25,46 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSCreateDepotOp struct { - OpBase - OpHTTPSBase +type httpsCreateDepotOp struct { + opBase + opHTTPSBase NodeDepotPaths map[string]string RequestParams map[string]string } func makeHTTPSCreateClusterDepotOp(logger vlog.Printer, vdb *VCoordinationDatabase, hosts []string, - useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSCreateDepotOp, error) { - httpsCreateDepotOp := HTTPSCreateDepotOp{} - httpsCreateDepotOp.name = "HTTPSCreateDepotOp" - httpsCreateDepotOp.logger = logger.WithName(httpsCreateDepotOp.name) - httpsCreateDepotOp.hosts = hosts - httpsCreateDepotOp.useHTTPPassword = useHTTPPassword + useHTTPPassword bool, userName string, httpsPassword *string) (httpsCreateDepotOp, error) { + op := httpsCreateDepotOp{} + op.name = "HTTPSCreateDepotOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.useHTTPPassword = useHTTPPassword // store nodeName-depotPath values for later http response verification - httpsCreateDepotOp.NodeDepotPaths = make(map[string]string) + op.NodeDepotPaths = make(map[string]string) for _, vnode := range vdb.HostNodeMap { - httpsCreateDepotOp.NodeDepotPaths[vnode.Name] = vnode.DepotPath + op.NodeDepotPaths[vnode.Name] = vnode.DepotPath } // set the query params, "path" is required, "size" is optional - httpsCreateDepotOp.RequestParams = make(map[string]string) - httpsCreateDepotOp.RequestParams["path"] = vdb.DepotPrefix + op.RequestParams = make(map[string]string) + op.RequestParams["path"] = vdb.DepotPrefix if vdb.DepotSize != "" { - httpsCreateDepotOp.RequestParams["size"] = vdb.DepotSize + op.RequestParams["size"] = vdb.DepotSize } - err := util.ValidateUsernameAndPassword(httpsCreateDepotOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsCreateDepotOp, err + return op, err } - httpsCreateDepotOp.userName = userName - httpsCreateDepotOp.httpsPassword = httpsPassword - return httpsCreateDepotOp, nil + op.userName = userName + op.httpsPassword = httpsPassword + return op, nil } -func (op *HTTPSCreateDepotOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsCreateDepotOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("cluster/depot") if op.useHTTPPassword { @@ -78,13 +78,13 @@ func (op *HTTPSCreateDepotOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSCreateDepotOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsCreateDepotOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSCreateDepotOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsCreateDepotOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -93,16 +93,16 @@ func (op *HTTPSCreateDepotOp) execute(execContext *OpEngineExecContext) error { } // this struct is for parsing http response -type CreateDepotNodeRsp struct { +type createDepotNodeRsp struct { NodeName string `json:"node"` DepotPath string `json:"depot_location"` } -type CreateDepotClusterRsp struct { - ClusterRsp []CreateDepotNodeRsp `json:"depots"` +type createDepotClusterRsp struct { + ClusterRsp []createDepotNodeRsp `json:"depots"` } -func (op *HTTPSCreateDepotOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsCreateDepotOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -131,8 +131,8 @@ func (op *HTTPSCreateDepotOp) processResult(_ *OpEngineExecContext) error { } ] } */ - createDepotClusterRsp := CreateDepotClusterRsp{} - err := op.parseAndCheckResponse(host, result.content, &createDepotClusterRsp) + response := createDepotClusterRsp{} + err := op.parseAndCheckResponse(host, result.content, &response) if err != nil { err = fmt.Errorf(`[%s] fail to parse result on host %s, details: %w`, op.name, host, err) allErrs = errors.Join(allErrs, err) @@ -141,7 +141,7 @@ func (op *HTTPSCreateDepotOp) processResult(_ *OpEngineExecContext) error { // verify if the node name and the depot location are correct for nodeName, depotPath := range op.NodeDepotPaths { - idx := slices.IndexFunc(createDepotClusterRsp.ClusterRsp, func(rsp CreateDepotNodeRsp) bool { + idx := slices.IndexFunc(response.ClusterRsp, func(rsp createDepotNodeRsp) bool { return rsp.NodeName == nodeName && rsp.DepotPath == depotPath }) if idx == -1 { @@ -151,7 +151,7 @@ func (op *HTTPSCreateDepotOp) processResult(_ *OpEngineExecContext) error { } } // verify if https response contains some nodes/depots not in the required ones - for _, nodeRsp := range createDepotClusterRsp.ClusterRsp { + for _, nodeRsp := range response.ClusterRsp { if depotPath, ok := op.NodeDepotPaths[nodeRsp.NodeName]; !ok || depotPath != nodeRsp.DepotPath { err = fmt.Errorf(`[%s] an unwanted depot %s gets created for node %s on host %s`, op.name, nodeRsp.DepotPath, nodeRsp.NodeName, host) @@ -164,6 +164,6 @@ func (op *HTTPSCreateDepotOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSCreateDepotOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsCreateDepotOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_create_node_op.go b/vclusterops/https_create_node_op.go index a900347..d0003f4 100644 --- a/vclusterops/https_create_node_op.go +++ b/vclusterops/https_create_node_op.go @@ -23,36 +23,36 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSCreateNodeOp struct { - OpBase - OpHTTPSBase +type httpsCreateNodeOp struct { + opBase + opHTTPSBase RequestParams map[string]string } func makeHTTPSCreateNodeOp(logger vlog.Printer, newNodeHosts []string, bootstrapHost []string, useHTTPPassword bool, userName string, httpsPassword *string, - vdb *VCoordinationDatabase, scName string) (HTTPSCreateNodeOp, error) { - createNodeOp := HTTPSCreateNodeOp{} - createNodeOp.name = "HTTPSCreateNodeOp" - createNodeOp.logger = logger.WithName(createNodeOp.name) - createNodeOp.hosts = bootstrapHost - createNodeOp.RequestParams = make(map[string]string) + vdb *VCoordinationDatabase, scName string) (httpsCreateNodeOp, error) { + op := httpsCreateNodeOp{} + op.name = "HTTPSCreateNodeOp" + op.logger = logger.WithName(op.name) + op.hosts = bootstrapHost + op.RequestParams = make(map[string]string) // HTTPS create node endpoint requires passing everything before node name - createNodeOp.RequestParams["catalog-prefix"] = vdb.CatalogPrefix + "/" + vdb.Name - createNodeOp.RequestParams["data-prefix"] = vdb.DataPrefix + "/" + vdb.Name - createNodeOp.RequestParams["hosts"] = util.ArrayToString(newNodeHosts, ",") + op.RequestParams["catalog-prefix"] = vdb.CatalogPrefix + "/" + vdb.Name + op.RequestParams["data-prefix"] = vdb.DataPrefix + "/" + vdb.Name + op.RequestParams["hosts"] = util.ArrayToString(newNodeHosts, ",") if scName != "" { - createNodeOp.RequestParams["subcluster"] = scName + op.RequestParams["subcluster"] = scName } - err := createNodeOp.validateAndSetUsernameAndPassword(createNodeOp.name, + err := op.validateAndSetUsernameAndPassword(op.name, useHTTPPassword, userName, httpsPassword) - return createNodeOp, err + return op, err } -func (op *HTTPSCreateNodeOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsCreateNodeOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod // note that this will be updated in Prepare() // because the endpoint only accept parameters in query @@ -68,7 +68,7 @@ func (op *HTTPSCreateNodeOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSCreateNodeOp) updateQueryParams(execContext *OpEngineExecContext) error { +func (op *httpsCreateNodeOp) updateQueryParams(execContext *opEngineExecContext) error { for _, host := range op.hosts { profile, ok := execContext.networkProfiles[host] if !ok { @@ -79,7 +79,7 @@ func (op *HTTPSCreateNodeOp) updateQueryParams(execContext *OpEngineExecContext) return nil } -func (op *HTTPSCreateNodeOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsCreateNodeOp) prepare(execContext *opEngineExecContext) error { err := op.updateQueryParams(execContext) if err != nil { return err @@ -90,7 +90,7 @@ func (op *HTTPSCreateNodeOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSCreateNodeOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsCreateNodeOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -98,13 +98,13 @@ func (op *HTTPSCreateNodeOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *HTTPSCreateNodeOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsCreateNodeOp) finalize(_ *opEngineExecContext) error { return nil } -type HTTPCreateNodeResponse map[string][]map[string]string +type httpsCreateNodeResponse map[string][]map[string]string -func (op *HTTPSCreateNodeOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsCreateNodeOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -114,7 +114,7 @@ func (op *HTTPSCreateNodeOp) processResult(_ *OpEngineExecContext) error { // The response object will be a dictionary, an example: // {'created_nodes': [{'name': 'v_running_db_node0002', 'catalog_path': '/data/v_running_db_node0002_catalog'}, // {'name': 'v_running_db_node0003', 'catalog_path': '/data/v_running_db_node0003_catalog'}]} - var responseObj HTTPCreateNodeResponse + var responseObj httpsCreateNodeResponse err := op.parseAndCheckResponse(host, result.content, &responseObj) if err != nil { diff --git a/vclusterops/https_create_nodes_depot_op.go b/vclusterops/https_create_nodes_depot_op.go index eb29648..0e73ac9 100644 --- a/vclusterops/https_create_nodes_depot_op.go +++ b/vclusterops/https_create_nodes_depot_op.go @@ -23,9 +23,9 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSCreateNodesDepotOp struct { - OpBase - OpHTTPSBase +type httpsCreateNodesDepotOp struct { + opBase + opHTTPSBase HostNodeMap vHostNodeMap DepotSize string } @@ -33,28 +33,28 @@ type HTTPSCreateNodesDepotOp struct { // makeHTTPSCreateNodesDepotOp will make an op that call vertica-http service to create depot for the new nodes func makeHTTPSCreateNodesDepotOp(logger vlog.Printer, vdb *VCoordinationDatabase, nodes []string, useHTTPPassword bool, userName string, httpsPassword *string, -) (HTTPSCreateNodesDepotOp, error) { - httpsCreateNodesDepotOp := HTTPSCreateNodesDepotOp{} - httpsCreateNodesDepotOp.name = "HTTPSCreateNodesDepotOp" - httpsCreateNodesDepotOp.logger = logger.WithName(httpsCreateNodesDepotOp.name) - httpsCreateNodesDepotOp.hosts = nodes - httpsCreateNodesDepotOp.useHTTPPassword = useHTTPPassword - httpsCreateNodesDepotOp.HostNodeMap = vdb.HostNodeMap - httpsCreateNodesDepotOp.DepotSize = vdb.DepotSize - - err := util.ValidateUsernameAndPassword(httpsCreateNodesDepotOp.name, useHTTPPassword, userName) +) (httpsCreateNodesDepotOp, error) { + op := httpsCreateNodesDepotOp{} + op.name = "HTTPSCreateNodesDepotOp" + op.logger = logger.WithName(op.name) + op.hosts = nodes + op.useHTTPPassword = useHTTPPassword + op.HostNodeMap = vdb.HostNodeMap + op.DepotSize = vdb.DepotSize + + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsCreateNodesDepotOp, err + return op, err } - httpsCreateNodesDepotOp.userName = userName - httpsCreateNodesDepotOp.httpsPassword = httpsPassword - return httpsCreateNodesDepotOp, nil + op.userName = userName + op.httpsPassword = httpsPassword + return op, nil } -func (op *HTTPSCreateNodesDepotOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsCreateNodesDepotOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod node := op.HostNodeMap[host] httpRequest.buildHTTPSEndpoint("nodes/" + node.Name + "/depot") @@ -72,13 +72,13 @@ func (op *HTTPSCreateNodesDepotOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *HTTPSCreateNodesDepotOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsCreateNodesDepotOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSCreateNodesDepotOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsCreateNodesDepotOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -86,7 +86,7 @@ func (op *HTTPSCreateNodesDepotOp) execute(execContext *OpEngineExecContext) err return op.processResult(execContext) } -func (op *HTTPSCreateNodesDepotOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsCreateNodesDepotOp) processResult(_ *opEngineExecContext) error { var allErrs error // every host needs to have a successful result, otherwise we fail this op @@ -126,6 +126,6 @@ func (op *HTTPSCreateNodesDepotOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSCreateNodesDepotOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsCreateNodesDepotOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_drop_node_op.go b/vclusterops/https_drop_node_op.go index 914ccc9..ea733af 100644 --- a/vclusterops/https_drop_node_op.go +++ b/vclusterops/https_drop_node_op.go @@ -22,9 +22,9 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSDropNodeOp struct { - OpBase - OpHTTPSBase +type httpsDropNodeOp struct { + opBase + opHTTPSBase targetHost string RequestParams map[string]string } @@ -34,31 +34,31 @@ func makeHTTPSDropNodeOp(logger vlog.Printer, vnode string, useHTTPPassword bool, userName string, httpsPassword *string, - isEon bool) (HTTPSDropNodeOp, error) { - dropNodeOp := HTTPSDropNodeOp{} - dropNodeOp.name = "HTTPSDropNodeOp" - dropNodeOp.logger = logger.WithName(dropNodeOp.name) - dropNodeOp.hosts = initiatorHost - dropNodeOp.targetHost = vnode - dropNodeOp.useHTTPPassword = useHTTPPassword - err := util.ValidateUsernameAndPassword(dropNodeOp.name, useHTTPPassword, userName) + isEon bool) (httpsDropNodeOp, error) { + op := httpsDropNodeOp{} + op.name = "HTTPSDropNodeOp" + op.logger = logger.WithName(op.name) + op.hosts = initiatorHost + op.targetHost = vnode + op.useHTTPPassword = useHTTPPassword + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return dropNodeOp, err + return op, err } - dropNodeOp.userName = userName - dropNodeOp.httpsPassword = httpsPassword - dropNodeOp.RequestParams = make(map[string]string) + op.userName = userName + op.httpsPassword = httpsPassword + op.RequestParams = make(map[string]string) if isEon { - dropNodeOp.RequestParams["cascade"] = "true" - return dropNodeOp, nil + op.RequestParams["cascade"] = "true" + return op, nil } - dropNodeOp.RequestParams["cascade"] = "false" - return dropNodeOp, nil + op.RequestParams["cascade"] = "false" + return op, nil } -func (op *HTTPSDropNodeOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsDropNodeOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("nodes/" + op.targetHost + "/drop") if op.useHTTPPassword { @@ -71,12 +71,12 @@ func (op *HTTPSDropNodeOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSDropNodeOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsDropNodeOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSDropNodeOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsDropNodeOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -84,7 +84,7 @@ func (op *HTTPSDropNodeOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *HTTPSDropNodeOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsDropNodeOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -98,6 +98,6 @@ func (op *HTTPSDropNodeOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSDropNodeOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsDropNodeOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_drop_subcluster_op.go b/vclusterops/https_drop_subcluster_op.go index bee229e..ac60753 100644 --- a/vclusterops/https_drop_subcluster_op.go +++ b/vclusterops/https_drop_subcluster_op.go @@ -23,8 +23,8 @@ import ( ) type httpsDropSubclusterOp struct { - OpBase - OpHTTPSBase + opBase + opHTTPSBase scName string } @@ -51,7 +51,7 @@ func makeHTTPSDropSubclusterOp(hosts []string, scName string, func (op *httpsDropSubclusterOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("subclusters/" + op.scName + "/drop") if op.useHTTPPassword { @@ -65,13 +65,13 @@ func (op *httpsDropSubclusterOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *httpsDropSubclusterOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsDropSubclusterOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *httpsDropSubclusterOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsDropSubclusterOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -79,7 +79,7 @@ func (op *httpsDropSubclusterOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *httpsDropSubclusterOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsDropSubclusterOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -101,6 +101,6 @@ func (op *httpsDropSubclusterOp) processResult(_ *OpEngineExecContext) error { return appendHTTPSFailureError(allErrs) } -func (op *httpsDropSubclusterOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsDropSubclusterOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_find_subcluster_op.go b/vclusterops/https_find_subcluster_op.go index 626d79e..3e5f465 100644 --- a/vclusterops/https_find_subcluster_op.go +++ b/vclusterops/https_find_subcluster_op.go @@ -22,9 +22,9 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSFindSubclusterOp struct { - OpBase - OpHTTPSBase +type httpsFindSubclusterOp struct { + opBase + opHTTPSBase scName string ignoreNotFound bool } @@ -36,8 +36,8 @@ type HTTPSFindSubclusterOp struct { func makeHTTPSFindSubclusterOp(logger vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, scName string, ignoreNotFound bool, -) (HTTPSFindSubclusterOp, error) { - op := HTTPSFindSubclusterOp{} +) (httpsFindSubclusterOp, error) { + op := httpsFindSubclusterOp{} op.name = "HTTPSFindSubclusterOp" op.logger = logger.WithName(op.name) op.hosts = hosts @@ -50,9 +50,9 @@ func makeHTTPSFindSubclusterOp(logger vlog.Printer, hosts []string, useHTTPPassw return op, err } -func (op *HTTPSFindSubclusterOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsFindSubclusterOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("subclusters") if op.useHTTPPassword { @@ -65,13 +65,13 @@ func (op *HTTPSFindSubclusterOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSFindSubclusterOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsFindSubclusterOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSFindSubclusterOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsFindSubclusterOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -80,16 +80,16 @@ func (op *HTTPSFindSubclusterOp) execute(execContext *OpEngineExecContext) error } // the following struct will store a subcluster's information for this op -type SubclusterInfo struct { +type subclusterInfo struct { SCName string `json:"subcluster_name"` IsDefault bool `json:"is_default"` } -type SCResp struct { - SCInfoList []SubclusterInfo `json:"subcluster_list"` +type scResp struct { + SCInfoList []subclusterInfo `json:"subcluster_list"` } -func (op *HTTPSFindSubclusterOp) processResult(execContext *OpEngineExecContext) error { +func (op *httpsFindSubclusterOp) processResult(execContext *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -127,8 +127,8 @@ func (op *HTTPSFindSubclusterOp) processResult(execContext *OpEngineExecContext) ] } */ - scResp := SCResp{} - err := op.parseAndCheckResponse(host, result.content, &scResp) + subclusterResp := scResp{} + err := op.parseAndCheckResponse(host, result.content, &subclusterResp) if err != nil { err = fmt.Errorf(`[%s] fail to parse result on host %s, details: %w`, op.name, host, err) allErrs = errors.Join(allErrs, err) @@ -140,7 +140,7 @@ func (op *HTTPSFindSubclusterOp) processResult(execContext *OpEngineExecContext) // 2. look for the default subcluster, error out if not found foundNamedSc := false foundDefaultSc := false - for _, scInfo := range scResp.SCInfoList { + for _, scInfo := range subclusterResp.SCInfoList { if scInfo.SCName == op.scName { foundNamedSc = true op.logger.Info(`subcluster exists in the database`, "subcluster", scInfo.SCName, "dbName", op.name) @@ -175,6 +175,6 @@ func (op *HTTPSFindSubclusterOp) processResult(execContext *OpEngineExecContext) return allErrs } -func (op *HTTPSFindSubclusterOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsFindSubclusterOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_get_cluster_info_op.go b/vclusterops/https_get_cluster_info_op.go index fff28ac..c5d8178 100644 --- a/vclusterops/https_get_cluster_info_op.go +++ b/vclusterops/https_get_cluster_info_op.go @@ -24,8 +24,8 @@ import ( ) type httpsGetClusterInfoOp struct { - OpBase - OpHTTPSBase + opBase + opHTTPSBase dbName string vdb *VCoordinationDatabase } @@ -55,7 +55,7 @@ func makeHTTPSGetClusterInfoOp(logger vlog.Printer, dbName string, hosts []strin func (op *httpsGetClusterInfoOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("cluster") if op.useHTTPPassword { @@ -69,13 +69,13 @@ func (op *httpsGetClusterInfoOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *httpsGetClusterInfoOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsGetClusterInfoOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *httpsGetClusterInfoOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsGetClusterInfoOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -83,13 +83,13 @@ func (op *httpsGetClusterInfoOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -type ClusterStateInfo struct { +type clusterStateInfo struct { IsEon bool `json:"is_eon"` DBName string `json:"db_name"` CommunalStorageLocations []string `json:"commnual_storage_locations"` } -func (op *httpsGetClusterInfoOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsGetClusterInfoOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -101,24 +101,24 @@ func (op *httpsGetClusterInfoOp) processResult(_ *OpEngineExecContext) error { if result.isPassing() { // unmarshal the response content - clusterStateInfo := ClusterStateInfo{} - err := op.parseAndCheckResponse(host, result.content, &clusterStateInfo) + clusterState := clusterStateInfo{} + err := op.parseAndCheckResponse(host, result.content, &clusterState) if err != nil { allErrs = errors.Join(allErrs, err) return appendHTTPSFailureError(allErrs) } // save cluster info to vdb - op.vdb.IsEon = clusterStateInfo.IsEon - op.vdb.UseDepot = clusterStateInfo.IsEon - op.vdb.Name = clusterStateInfo.DBName + op.vdb.IsEon = clusterState.IsEon + op.vdb.UseDepot = clusterState.IsEon + op.vdb.Name = clusterState.DBName if op.vdb.Name != op.dbName { err = fmt.Errorf(`[%s] database %s is running on host %s, rather than database %s`, op.name, op.vdb.Name, host, op.dbName) allErrs = errors.Join(allErrs, err) break } - if len(clusterStateInfo.CommunalStorageLocations) > 0 { - op.vdb.CommunalStorageLocation = clusterStateInfo.CommunalStorageLocations[0] + if len(clusterState.CommunalStorageLocations) > 0 { + op.vdb.CommunalStorageLocation = clusterState.CommunalStorageLocations[0] } return nil } @@ -127,6 +127,6 @@ func (op *httpsGetClusterInfoOp) processResult(_ *OpEngineExecContext) error { return appendHTTPSFailureError(allErrs) } -func (op *httpsGetClusterInfoOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsGetClusterInfoOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_get_nodes_info_op.go b/vclusterops/https_get_nodes_info_op.go index 7c888d1..b295867 100644 --- a/vclusterops/https_get_nodes_info_op.go +++ b/vclusterops/https_get_nodes_info_op.go @@ -25,8 +25,8 @@ import ( ) type httpsGetNodesInfoOp struct { - OpBase - OpHTTPSBase + opBase + opHTTPSBase dbName string vdb *VCoordinationDatabase } @@ -49,7 +49,7 @@ func makeHTTPSGetNodesInfoOp(logger vlog.Printer, dbName string, hosts []string, func (op *httpsGetNodesInfoOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("nodes") if op.useHTTPPassword { @@ -63,13 +63,13 @@ func (op *httpsGetNodesInfoOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *httpsGetNodesInfoOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsGetNodesInfoOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *httpsGetNodesInfoOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsGetNodesInfoOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -77,7 +77,7 @@ func (op *httpsGetNodesInfoOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsGetNodesInfoOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -89,8 +89,8 @@ func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error { if result.isPassing() { // parse the /nodes endpoint response - nodesStateInfo := NodesStateInfo{} - err := op.parseAndCheckResponse(host, result.content, &nodesStateInfo) + nodesStates := nodesStateInfo{} + err := op.parseAndCheckResponse(host, result.content, &nodesStates) if err != nil { allErrs = errors.Join(allErrs, err) break @@ -98,7 +98,7 @@ func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error { // save nodes info to vdb op.vdb.HostNodeMap = makeVHostNodeMap() op.vdb.HostList = []string{} - for _, node := range nodesStateInfo.NodeList { + for _, node := range nodesStates.NodeList { if node.Database != op.dbName { err = fmt.Errorf(`[%s] database %s is running on host %s, rather than database %s`, op.name, node.Database, host, op.dbName) allErrs = errors.Join(allErrs, err) @@ -137,6 +137,6 @@ func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error { return appendHTTPSFailureError(allErrs) } -func (op *httpsGetNodesInfoOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsGetNodesInfoOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_get_up_nodes_op.go b/vclusterops/https_get_up_nodes_op.go index bddd999..5482074 100644 --- a/vclusterops/https_get_up_nodes_op.go +++ b/vclusterops/https_get_up_nodes_op.go @@ -24,41 +24,41 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSGetUpNodesOp struct { - OpBase - OpHTTPSBase +type httpsGetUpNodesOp struct { + opBase + opHTTPSBase DBName string noUpHostsOk bool } func makeHTTPSGetUpNodesOp(logger vlog.Printer, dbName string, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, -) (HTTPSGetUpNodesOp, error) { - httpsGetUpNodesOp := HTTPSGetUpNodesOp{} - httpsGetUpNodesOp.name = "HTTPSGetUpNodesOp" - httpsGetUpNodesOp.logger = logger.WithName(httpsGetUpNodesOp.name) - httpsGetUpNodesOp.hosts = hosts - httpsGetUpNodesOp.useHTTPPassword = useHTTPPassword - httpsGetUpNodesOp.DBName = dbName +) (httpsGetUpNodesOp, error) { + op := httpsGetUpNodesOp{} + op.name = "HTTPSGetUpNodesOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.useHTTPPassword = useHTTPPassword + op.DBName = dbName if useHTTPPassword { - err := util.ValidateUsernameAndPassword(httpsGetUpNodesOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsGetUpNodesOp, err + return op, err } - httpsGetUpNodesOp.userName = userName - httpsGetUpNodesOp.httpsPassword = httpsPassword + op.userName = userName + op.httpsPassword = httpsPassword } - return httpsGetUpNodesOp, nil + return op, nil } -func (op *HTTPSGetUpNodesOp) allowNoUpHosts() { +func (op *httpsGetUpNodesOp) allowNoUpHosts() { op.noUpHostsOk = true } -func (op *HTTPSGetUpNodesOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsGetUpNodesOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("nodes") if op.useHTTPPassword { @@ -71,13 +71,13 @@ func (op *HTTPSGetUpNodesOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSGetUpNodesOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsGetUpNodesOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSGetUpNodesOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsGetUpNodesOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -85,7 +85,7 @@ func (op *HTTPSGetUpNodesOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -/* HTTPNodeStateResponse example: +/* httpsNodeStateResponse example: {'details':[] 'node_list':[{ 'name': 'v_test_db_running_node0001', 'node_id':'45035996273704982', @@ -110,7 +110,7 @@ func (op *HTTPSGetUpNodesOp) execute(execContext *OpEngineExecContext) error { } */ -func (op *HTTPSGetUpNodesOp) processResult(execContext *OpEngineExecContext) error { +func (op *httpsGetUpNodesOp) processResult(execContext *opEngineExecContext) error { var allErrs error // golang does not have set data structure, use a map to simulate it upHosts := make(map[string]struct{}) @@ -137,8 +137,8 @@ func (op *HTTPSGetUpNodesOp) processResult(execContext *OpEngineExecContext) err continue } - nodesStateInfo := NodesStateInfo{} - err := op.parseAndCheckResponse(host, result.content, &nodesStateInfo) + nodesStates := nodesStateInfo{} + err := op.parseAndCheckResponse(host, result.content, &nodesStates) if err != nil { err = fmt.Errorf(`[%s] fail to parse result on host %s, details: %w`, op.name, host, err) allErrs = errors.Join(allErrs, err) @@ -146,7 +146,7 @@ func (op *HTTPSGetUpNodesOp) processResult(execContext *OpEngineExecContext) err } // collect all the up hosts - for _, node := range nodesStateInfo.NodeList { + for _, node := range nodesStates.NodeList { if node.Database != op.DBName { err = fmt.Errorf(`[%s] database %s is running on host %s, rather than database %s`, op.name, node.Database, host, op.DBName) allErrs = errors.Join(allErrs, err) @@ -170,15 +170,15 @@ func (op *HTTPSGetUpNodesOp) processResult(execContext *OpEngineExecContext) err return errors.Join(allErrs, fmt.Errorf("no up nodes detected")) } -func (op *HTTPSGetUpNodesOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsGetUpNodesOp) finalize(_ *opEngineExecContext) error { return nil } // processHostLists stashes the up hosts, and if there are no up hosts, prints and logs // down or erratic hosts. Additionally, it determines if the op should fail or not. -func (op *HTTPSGetUpNodesOp) processHostLists(upHosts map[string]struct{}, +func (op *httpsGetUpNodesOp) processHostLists(upHosts map[string]struct{}, exceptionHosts, downHosts []string, - execContext *OpEngineExecContext) (ignoreErrors bool) { + execContext *opEngineExecContext) (ignoreErrors bool) { if len(upHosts) > 0 { for host := range upHosts { execContext.upHosts = append(execContext.upHosts, host) diff --git a/vclusterops/https_install_packages_op.go b/vclusterops/https_install_packages_op.go index 216cfca..45f18be 100644 --- a/vclusterops/https_install_packages_op.go +++ b/vclusterops/https_install_packages_op.go @@ -23,32 +23,32 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSInstallPackagesOp struct { - OpBase - OpHTTPSBase +type httpsInstallPackagesOp struct { + opBase + opHTTPSBase } func makeHTTPSInstallPackagesOp(logger vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, -) (HTTPSInstallPackagesOp, error) { - installPackagesOp := HTTPSInstallPackagesOp{} - installPackagesOp.name = "HTTPSInstallPackagesOp" - installPackagesOp.logger = logger.WithName(installPackagesOp.name) - installPackagesOp.hosts = hosts +) (httpsInstallPackagesOp, error) { + op := httpsInstallPackagesOp{} + op.name = "HTTPSInstallPackagesOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts - err := util.ValidateUsernameAndPassword(installPackagesOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return installPackagesOp, err + return op, err } - installPackagesOp.useHTTPPassword = useHTTPPassword - installPackagesOp.userName = userName - installPackagesOp.httpsPassword = httpsPassword - return installPackagesOp, nil + op.useHTTPPassword = useHTTPPassword + op.userName = userName + op.httpsPassword = httpsPassword + return op, nil } -func (op *HTTPSInstallPackagesOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsInstallPackagesOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("packages") if op.useHTTPPassword { @@ -61,13 +61,13 @@ func (op *HTTPSInstallPackagesOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *HTTPSInstallPackagesOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsInstallPackagesOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSInstallPackagesOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsInstallPackagesOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -75,12 +75,12 @@ func (op *HTTPSInstallPackagesOp) execute(execContext *OpEngineExecContext) erro return op.processResult(execContext) } -func (op *HTTPSInstallPackagesOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsInstallPackagesOp) finalize(_ *opEngineExecContext) error { return nil } /* - HTTPSInstallPackagesResponse example: + httpsInstallPackagesResponse example: {'packages': [ @@ -96,9 +96,9 @@ func (op *HTTPSInstallPackagesOp) finalize(_ *OpEngineExecContext) error { ] } */ -type HTTPSInstallPackagesResponse map[string][]map[string]string +type httpsInstallPackagesResponse map[string][]map[string]string -func (op *HTTPSInstallPackagesOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsInstallPackagesOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -109,7 +109,7 @@ func (op *HTTPSInstallPackagesOp) processResult(_ *OpEngineExecContext) error { continue } - var responseObj HTTPSInstallPackagesResponse + var responseObj httpsInstallPackagesResponse err := op.parseAndCheckResponse(host, result.content, &responseObj) if err != nil { diff --git a/vclusterops/https_mark_design_ksafe_op.go b/vclusterops/https_mark_design_ksafe_op.go index e429fb9..7bd0c8b 100644 --- a/vclusterops/https_mark_design_ksafe_op.go +++ b/vclusterops/https_mark_design_ksafe_op.go @@ -27,9 +27,9 @@ import ( const zeroSafeRspStr = "Marked design 0-safe" const oneSafeRspStr = "Marked design 1-safe" -type HTTPSMarkDesignKSafeOp struct { - OpBase - OpHTTPSBase +type httpsMarkDesignKSafeOp struct { + opBase + opHTTPSBase RequestParams map[string]string ksafeValue int } @@ -41,32 +41,32 @@ func makeHTTPSMarkDesignKSafeOp( userName string, httpsPassword *string, ksafeValue int, -) (HTTPSMarkDesignKSafeOp, error) { - httpsMarkDesignKSafeOp := HTTPSMarkDesignKSafeOp{} - httpsMarkDesignKSafeOp.name = "HTTPSMarkDesignKsafeOp" - httpsMarkDesignKSafeOp.logger = logger.WithName(httpsMarkDesignKSafeOp.name) - httpsMarkDesignKSafeOp.hosts = hosts - httpsMarkDesignKSafeOp.useHTTPPassword = useHTTPPassword +) (httpsMarkDesignKSafeOp, error) { + op := httpsMarkDesignKSafeOp{} + op.name = "HTTPSMarkDesignKsafeOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.useHTTPPassword = useHTTPPassword // set ksafeValue. Should be 1 or 0. // store directly for later response verification - httpsMarkDesignKSafeOp.ksafeValue = ksafeValue - httpsMarkDesignKSafeOp.RequestParams = make(map[string]string) - httpsMarkDesignKSafeOp.RequestParams["k"] = strconv.Itoa(ksafeValue) + op.ksafeValue = ksafeValue + op.RequestParams = make(map[string]string) + op.RequestParams["k"] = strconv.Itoa(ksafeValue) - err := util.ValidateUsernameAndPassword(httpsMarkDesignKSafeOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsMarkDesignKSafeOp, err + return op, err } - httpsMarkDesignKSafeOp.userName = userName - httpsMarkDesignKSafeOp.httpsPassword = httpsPassword - return httpsMarkDesignKSafeOp, nil + op.userName = userName + op.httpsPassword = httpsPassword + return op, nil } -func (op *HTTPSMarkDesignKSafeOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsMarkDesignKSafeOp) setupClusterHTTPRequest(hosts []string) error { // in practice, initiator only for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PutMethod httpRequest.buildHTTPSEndpoint("cluster/k-safety") if op.useHTTPPassword { @@ -80,13 +80,13 @@ func (op *HTTPSMarkDesignKSafeOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *HTTPSMarkDesignKSafeOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsMarkDesignKSafeOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSMarkDesignKSafeOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsMarkDesignKSafeOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -94,14 +94,14 @@ func (op *HTTPSMarkDesignKSafeOp) execute(execContext *OpEngineExecContext) erro return op.processResult(execContext) } -// MarkDesignKSafeRsp will be either +// markDesignKSafeRsp will be either // {"detail": "Marked design 0-safe"} OR // {"detail": "Marked design 1-safe"} -type MarkDesignKSafeRsp struct { +type markDesignKSafeRsp struct { Detail string `json:"detail"` } -func (op *HTTPSMarkDesignKSafeOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsMarkDesignKSafeOp) processResult(_ *opEngineExecContext) error { var allErrs error // in practice, just the initiator node @@ -115,8 +115,8 @@ func (op *HTTPSMarkDesignKSafeOp) processResult(_ *OpEngineExecContext) error { // The response object will be a dictionary, an example: // {"detail": "Marked design 0-safe"} - markDesignKSafeRsp := MarkDesignKSafeRsp{} - err := op.parseAndCheckResponse(host, result.content, &markDesignKSafeRsp) + markDesignKSafeResponse := markDesignKSafeRsp{} + err := op.parseAndCheckResponse(host, result.content, &markDesignKSafeResponse) if err != nil { err = fmt.Errorf(`[%s] fail to parse result on host %s, details: %w`, op.name, host, err) allErrs = errors.Join(allErrs, err) @@ -125,13 +125,13 @@ func (op *HTTPSMarkDesignKSafeOp) processResult(_ *OpEngineExecContext) error { // retrieve and verify the mark ksafety response var ksafeValue int - if markDesignKSafeRsp.Detail == zeroSafeRspStr { + if markDesignKSafeResponse.Detail == zeroSafeRspStr { ksafeValue = 0 - } else if markDesignKSafeRsp.Detail == oneSafeRspStr { + } else if markDesignKSafeResponse.Detail == oneSafeRspStr { ksafeValue = 1 } else { err = fmt.Errorf(`[%s] fail to parse the ksafety value information, detail: %s`, - op.name, markDesignKSafeRsp.Detail) + op.name, markDesignKSafeResponse.Detail) allErrs = errors.Join(allErrs, err) continue } @@ -151,6 +151,6 @@ func (op *HTTPSMarkDesignKSafeOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSMarkDesignKSafeOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsMarkDesignKSafeOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_mark_nodes_ephemeral_op.go b/vclusterops/https_mark_nodes_ephemeral_op.go index d56019d..a96e716 100644 --- a/vclusterops/https_mark_nodes_ephemeral_op.go +++ b/vclusterops/https_mark_nodes_ephemeral_op.go @@ -22,9 +22,9 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSMarkEphemeralNodeOp struct { - OpBase - OpHTTPSBase +type httpsMarkEphemeralNodeOp struct { + opBase + opHTTPSBase targetNodeName string } @@ -32,8 +32,8 @@ func makeHTTPSMarkEphemeralNodeOp(logger vlog.Printer, nodeName string, initiatorHost []string, useHTTPPassword bool, userName string, - httpsPassword *string) (HTTPSMarkEphemeralNodeOp, error) { - op := HTTPSMarkEphemeralNodeOp{} + httpsPassword *string) (httpsMarkEphemeralNodeOp, error) { + op := httpsMarkEphemeralNodeOp{} op.name = "HTTPSMarkEphemeralNodeOp" op.logger = logger.WithName(op.name) op.hosts = initiatorHost @@ -48,9 +48,9 @@ func makeHTTPSMarkEphemeralNodeOp(logger vlog.Printer, nodeName string, return op, nil } -func (op *HTTPSMarkEphemeralNodeOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsMarkEphemeralNodeOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("nodes/" + op.targetNodeName + "/ephemeral") if op.useHTTPPassword { @@ -62,12 +62,12 @@ func (op *HTTPSMarkEphemeralNodeOp) setupClusterHTTPRequest(hosts []string) erro return nil } -func (op *HTTPSMarkEphemeralNodeOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsMarkEphemeralNodeOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSMarkEphemeralNodeOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsMarkEphemeralNodeOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -75,7 +75,7 @@ func (op *HTTPSMarkEphemeralNodeOp) execute(execContext *OpEngineExecContext) er return op.processResult(execContext) } -func (op *HTTPSMarkEphemeralNodeOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsMarkEphemeralNodeOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -89,6 +89,6 @@ func (op *HTTPSMarkEphemeralNodeOp) processResult(_ *OpEngineExecContext) error return allErrs } -func (op *HTTPSMarkEphemeralNodeOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsMarkEphemeralNodeOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_poll_node_state_op.go b/vclusterops/https_poll_node_state_op.go index 0ca4804..4a89966 100644 --- a/vclusterops/https_poll_node_state_op.go +++ b/vclusterops/https_poll_node_state_op.go @@ -30,7 +30,7 @@ import ( const httpRequestTimeoutSeconds = 30 const ( StartDBCmd CmdType = iota - RestartNodeCmd + StartNodeCmd ) type CmdType int @@ -39,41 +39,41 @@ func (cmd CmdType) String() string { switch cmd { case StartDBCmd: return "start_db" - case RestartNodeCmd: + case StartNodeCmd: return "restart_node" } return "unknown_operation" } -type HTTPSPollNodeStateOp struct { - OpBase - OpHTTPSBase +type httpsPollNodeStateOp struct { + opBase + opHTTPSBase currentHost string timeout int cmdType CmdType } func makeHTTPSPollNodeStateOpHelper(logger vlog.Printer, hosts []string, - useHTTPPassword bool, userName string, httpsPassword *string) (HTTPSPollNodeStateOp, error) { - httpsPollNodeStateOp := HTTPSPollNodeStateOp{} - httpsPollNodeStateOp.name = "HTTPSPollNodeStateOp" - httpsPollNodeStateOp.logger = logger.WithName(httpsPollNodeStateOp.name) - httpsPollNodeStateOp.hosts = hosts - httpsPollNodeStateOp.useHTTPPassword = useHTTPPassword - - err := util.ValidateUsernameAndPassword(httpsPollNodeStateOp.name, useHTTPPassword, userName) + useHTTPPassword bool, userName string, httpsPassword *string) (httpsPollNodeStateOp, error) { + op := httpsPollNodeStateOp{} + op.name = "HTTPSPollNodeStateOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.useHTTPPassword = useHTTPPassword + + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsPollNodeStateOp, err + return op, err } - httpsPollNodeStateOp.userName = userName - httpsPollNodeStateOp.httpsPassword = httpsPassword + op.userName = userName + op.httpsPassword = httpsPassword - return httpsPollNodeStateOp, nil + return op, nil } func makeHTTPSPollNodeStateOpWithTimeoutAndCommand(logger vlog.Printer, hosts []string, useHTTPPassword bool, userName string, httpsPassword *string, - timeout int, cmdType CmdType) (HTTPSPollNodeStateOp, error) { + timeout int, cmdType CmdType) (httpsPollNodeStateOp, error) { op, err := makeHTTPSPollNodeStateOpHelper(logger, hosts, useHTTPPassword, userName, httpsPassword) if err != nil { return op, err @@ -85,27 +85,27 @@ func makeHTTPSPollNodeStateOpWithTimeoutAndCommand(logger vlog.Printer, hosts [] func makeHTTPSPollNodeStateOp(logger vlog.Printer, hosts []string, useHTTPPassword bool, userName string, - httpsPassword *string) (HTTPSPollNodeStateOp, error) { - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpHelper(logger, hosts, useHTTPPassword, userName, httpsPassword) + httpsPassword *string) (httpsPollNodeStateOp, error) { + op, err := makeHTTPSPollNodeStateOpHelper(logger, hosts, useHTTPPassword, userName, httpsPassword) if err != nil { - return httpsPollNodeStateOp, err + return op, err } timeoutSecondStr := util.GetEnv("NODE_STATE_POLLING_TIMEOUT", strconv.Itoa(StartupPollingTimeout)) timeoutSecond, err := strconv.Atoi(timeoutSecondStr) if err != nil { - return HTTPSPollNodeStateOp{}, err + return httpsPollNodeStateOp{}, err } - httpsPollNodeStateOp.timeout = timeoutSecond - return httpsPollNodeStateOp, nil + op.timeout = timeoutSecond + return op, nil } -func (op *HTTPSPollNodeStateOp) getPollingTimeout() int { +func (op *httpsPollNodeStateOp) getPollingTimeout() int { return op.timeout } -func (op *HTTPSPollNodeStateOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsPollNodeStateOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.Timeout = httpRequestTimeoutSeconds httpRequest.buildHTTPSEndpoint("nodes/" + host) @@ -120,13 +120,13 @@ func (op *HTTPSPollNodeStateOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSPollNodeStateOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsPollNodeStateOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSPollNodeStateOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsPollNodeStateOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -134,11 +134,11 @@ func (op *HTTPSPollNodeStateOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *HTTPSPollNodeStateOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsPollNodeStateOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *HTTPSPollNodeStateOp) processResult(execContext *OpEngineExecContext) error { +func (op *httpsPollNodeStateOp) processResult(execContext *opEngineExecContext) error { vlog.PrintWithIndent("[%s] expecting %d up host(s)", op.name, len(op.hosts)) err := pollState(op, execContext) @@ -152,7 +152,7 @@ func (op *HTTPSPollNodeStateOp) processResult(execContext *OpEngineExecContext) return nil } -func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { +func (op *httpsPollNodeStateOp) shouldStopPolling() (bool, error) { upNodeCount := 0 for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -169,7 +169,7 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { // We also need to let user know to wait until all nodes are up if result.isPasswordAndCertificateError(op.logger) { switch op.cmdType { - case StartDBCmd, RestartNodeCmd: + case StartDBCmd, StartNodeCmd: op.logger.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."+ @@ -180,8 +180,8 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { } if result.isPassing() { // parse the /nodes/{node} endpoint response - nodesInfo := NodesInfo{} - err := op.parseAndCheckResponse(host, result.content, &nodesInfo) + nodesInformation := nodesInfo{} + err := op.parseAndCheckResponse(host, result.content, &nodesInformation) if err != nil { op.logger.PrintError("[%s] fail to parse result on host %s, details: %s", op.name, host, err) @@ -190,8 +190,8 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { // check whether the node is up // the node list should only have one node info - if len(nodesInfo.NodeList) == 1 { - nodeInfo := nodesInfo.NodeList[0] + if len(nodesInformation.NodeList) == 1 { + nodeInfo := nodesInformation.NodeList[0] if nodeInfo.State == util.NodeUpState { upNodeCount++ } @@ -199,7 +199,7 @@ func (op *HTTPSPollNodeStateOp) shouldStopPolling() (bool, error) { // if NMA endpoint cannot function well on any of the hosts, we do not want to retry polling return true, fmt.Errorf("[%s] expect one node's information, but got %d nodes' information"+ " from NMA /v1/nodes/{node} endpoint on host %s", - op.name, len(nodesInfo.NodeList), host) + op.name, len(nodesInformation.NodeList), host) } } } diff --git a/vclusterops/https_poll_node_state_op_test.go b/vclusterops/https_poll_node_state_op_test.go index d52b1fe..19c29ed 100644 --- a/vclusterops/https_poll_node_state_op_test.go +++ b/vclusterops/https_poll_node_state_op_test.go @@ -23,7 +23,7 @@ import ( ) func TestTimeoutCase(t *testing.T) { - var instructions []ClusterOp + var instructions []clusterOp // use a non-existing IP to test the timeout error // 192.0.2.1 is one that is reserved for test purpose (by RFC 5737) hosts := []string{"192.0.2.1"} @@ -33,7 +33,7 @@ func TestTimeoutCase(t *testing.T) { assert.Nil(t, err) instructions = append(instructions, &httpsPollNodeStateOp) - certs := HTTPSCerts{} + certs := httpsCerts{} clusterOpEngine := makeClusterOpEngine(instructions, &certs) err = clusterOpEngine.run(vlog.Printer{}) assert.ErrorContains(t, err, "[HTTPSPollNodeStateOp] cannot connect to host 192.0.2.1, please check if the host is still alive") diff --git a/vclusterops/https_poll_subscription_state_op.go b/vclusterops/https_poll_subscription_state_op.go index 91e83f0..16bcb64 100644 --- a/vclusterops/https_poll_subscription_state_op.go +++ b/vclusterops/https_poll_subscription_state_op.go @@ -23,8 +23,8 @@ import ( ) type httpsPollSubscriptionStateOp struct { - OpBase - OpHTTPSBase + opBase + opHTTPSBase timeout int } @@ -53,7 +53,7 @@ func (op *httpsPollSubscriptionStateOp) getPollingTimeout() int { func (op *httpsPollSubscriptionStateOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.Timeout = httpRequestTimeoutSeconds httpRequest.buildHTTPSEndpoint("subscriptions") @@ -68,13 +68,13 @@ func (op *httpsPollSubscriptionStateOp) setupClusterHTTPRequest(hosts []string) return nil } -func (op *httpsPollSubscriptionStateOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsPollSubscriptionStateOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *httpsPollSubscriptionStateOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsPollSubscriptionStateOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -82,7 +82,7 @@ func (op *httpsPollSubscriptionStateOp) execute(execContext *OpEngineExecContext return op.processResult(execContext) } -func (op *httpsPollSubscriptionStateOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsPollSubscriptionStateOp) finalize(_ *opEngineExecContext) error { return nil } @@ -103,18 +103,18 @@ func (op *httpsPollSubscriptionStateOp) finalize(_ *OpEngineExecContext) error { ... ] */ -type SubscriptionList struct { - SubscriptionList []SubscriptionInfo `json:"subscription_list"` +type subscriptionList struct { + SubscriptionList []subscriptionInfo `json:"subscription_list"` } -type SubscriptionInfo struct { +type subscriptionInfo struct { Nodename string `json:"node_name"` ShardName string `json:"shard_name"` SubscriptionState string `json:"subscription_state"` IsPrimary bool `json:"is_primary"` } -func (op *httpsPollSubscriptionStateOp) processResult(execContext *OpEngineExecContext) error { +func (op *httpsPollSubscriptionStateOp) processResult(execContext *opEngineExecContext) error { err := pollState(op, execContext) if err != nil { return fmt.Errorf("not all subscriptions are ACTIVE, %w", err) @@ -124,7 +124,7 @@ func (op *httpsPollSubscriptionStateOp) processResult(execContext *OpEngineExecC } func (op *httpsPollSubscriptionStateOp) shouldStopPolling() (bool, error) { - var subscriptionList SubscriptionList + var subscriptList subscriptionList for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -135,7 +135,7 @@ func (op *httpsPollSubscriptionStateOp) shouldStopPolling() (bool, error) { } if result.isPassing() { - err := op.parseAndCheckResponse(host, result.content, &subscriptionList) + err := op.parseAndCheckResponse(host, result.content, &subscriptList) if err != nil { op.logger.PrintError("[%s] fail to parse result on host %s, details: %s", op.name, host, err) @@ -143,7 +143,7 @@ func (op *httpsPollSubscriptionStateOp) shouldStopPolling() (bool, error) { } // check whether all subscriptions are ACTIVE - for _, s := range subscriptionList.SubscriptionList { + for _, s := range subscriptList.SubscriptionList { if s.SubscriptionState != "ACTIVE" { return false, nil } diff --git a/vclusterops/https_re_ip_op.go b/vclusterops/https_re_ip_op.go index 590233c..b74b8da 100644 --- a/vclusterops/https_re_ip_op.go +++ b/vclusterops/https_re_ip_op.go @@ -23,10 +23,10 @@ import ( ) type httpsReIPOp struct { - OpBase - OpHTTPSBase + opBase + opHTTPSBase hostToReIP []string - reIPList map[string]ReIPInfo + reIPList map[string]reIPInfo nodeNamesList []string upHosts []string } @@ -54,7 +54,7 @@ func makeHTTPSReIPOp(nodeNamesList, hostToReIP []string, func (op *httpsReIPOp) setupClusterHTTPRequest(hosts []string) error { for i, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PutMethod nodesInfo, ok := op.reIPList[host] if !ok { @@ -76,8 +76,8 @@ func (op *httpsReIPOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *httpsReIPOp) prepare(execContext *OpEngineExecContext) error { - op.reIPList = make(map[string]ReIPInfo) +func (op *httpsReIPOp) prepare(execContext *opEngineExecContext) error { + op.reIPList = make(map[string]reIPInfo) // update reIPList from input node names and execContext.networkProfiles for i := 0; i < len(op.nodeNamesList); i++ { nodeNameToReIP := op.nodeNamesList[i] @@ -86,7 +86,7 @@ func (op *httpsReIPOp) prepare(execContext *OpEngineExecContext) error { if !ok { return fmt.Errorf("[%s] unable to find network profile for address %s", op.name, targetAddress) } - info := ReIPInfo{ + info := reIPInfo{ NodeName: nodeNameToReIP, TargetAddress: targetAddress, TargetControlAddress: profile.Address, @@ -101,7 +101,7 @@ func (op *httpsReIPOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.nodeNamesList) } -func (op *httpsReIPOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsReIPOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -109,7 +109,7 @@ func (op *httpsReIPOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *httpsReIPOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsReIPOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -150,6 +150,6 @@ func (op *httpsReIPOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *httpsReIPOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsReIPOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_rebalance_cluster_op.go b/vclusterops/https_rebalance_cluster_op.go index 89673e4..dac693b 100644 --- a/vclusterops/https_rebalance_cluster_op.go +++ b/vclusterops/https_rebalance_cluster_op.go @@ -26,32 +26,32 @@ import ( const RebalanceClusterSuccMsg = "REBALANCED" const RebalanceShardsSuccMsg = "REBALANCED SHARDS" -type HTTPSRebalanceClusterOp struct { - OpBase - OpHTTPSBase +type httpsRebalanceClusterOp struct { + opBase + opHTTPSBase } // makeHTTPSRebalanceClusterOp will make an op that call vertica-http service to rebalance the cluster func makeHTTPSRebalanceClusterOp(logger vlog.Printer, initiatorHost []string, useHTTPPassword bool, userName string, - httpsPassword *string) (HTTPSRebalanceClusterOp, error) { - httpsRBCOp := HTTPSRebalanceClusterOp{} - httpsRBCOp.name = "HTTPSRebalanceClusterOp" - httpsRBCOp.logger = logger.WithName(httpsRBCOp.name) - httpsRBCOp.hosts = initiatorHost - - httpsRBCOp.useHTTPPassword = useHTTPPassword - err := util.ValidateUsernameAndPassword(httpsRBCOp.name, useHTTPPassword, userName) + httpsPassword *string) (httpsRebalanceClusterOp, error) { + op := httpsRebalanceClusterOp{} + op.name = "HTTPSRebalanceClusterOp" + op.logger = logger.WithName(op.name) + op.hosts = initiatorHost + + op.useHTTPPassword = useHTTPPassword + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsRBCOp, err + return op, err } - httpsRBCOp.userName = userName - httpsRBCOp.httpsPassword = httpsPassword - return httpsRBCOp, nil + op.userName = userName + op.httpsPassword = httpsPassword + return op, nil } -func (op *HTTPSRebalanceClusterOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsRebalanceClusterOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("cluster/rebalance") if op.useHTTPPassword { @@ -63,12 +63,12 @@ func (op *HTTPSRebalanceClusterOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *HTTPSRebalanceClusterOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsRebalanceClusterOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSRebalanceClusterOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsRebalanceClusterOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -76,7 +76,7 @@ func (op *HTTPSRebalanceClusterOp) execute(execContext *OpEngineExecContext) err return op.processResult(execContext) } -func (op *HTTPSRebalanceClusterOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsRebalanceClusterOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -124,6 +124,6 @@ func (op *HTTPSRebalanceClusterOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSRebalanceClusterOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsRebalanceClusterOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_rebalance_subcluster_shards_op.go b/vclusterops/https_rebalance_subcluster_shards_op.go index 1de7a83..386db75 100644 --- a/vclusterops/https_rebalance_subcluster_shards_op.go +++ b/vclusterops/https_rebalance_subcluster_shards_op.go @@ -25,36 +25,36 @@ import ( const HTTPSSuccMsg = "REBALANCED SHARDS" -type HTTPSRebalanceSubclusterShardsOp struct { - OpBase - OpHTTPSBase +type httpsRebalanceSubclusterShardsOp struct { + opBase + opHTTPSBase scName string } // makeHTTPSRebalanceSubclusterShardsOp creates an op that calls vertica-http service to rebalance shards of a subcluster func makeHTTPSRebalanceSubclusterShardsOp(logger vlog.Printer, bootstrapHost []string, useHTTPPassword bool, userName string, - httpsPassword *string, scName string) (HTTPSRebalanceSubclusterShardsOp, error) { - httpsRBSCShardsOp := HTTPSRebalanceSubclusterShardsOp{} - httpsRBSCShardsOp.name = "HTTPSRebalanceSubclusterShardsOp" - httpsRBSCShardsOp.logger = logger.WithName(httpsRBSCShardsOp.name) - httpsRBSCShardsOp.hosts = bootstrapHost - httpsRBSCShardsOp.scName = scName - - httpsRBSCShardsOp.useHTTPPassword = useHTTPPassword + httpsPassword *string, scName string) (httpsRebalanceSubclusterShardsOp, error) { + op := httpsRebalanceSubclusterShardsOp{} + op.name = "HTTPSRebalanceSubclusterShardsOp" + op.logger = logger.WithName(op.name) + op.hosts = bootstrapHost + op.scName = scName + + op.useHTTPPassword = useHTTPPassword if useHTTPPassword { - err := util.ValidateUsernameAndPassword(httpsRBSCShardsOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsRBSCShardsOp, err + return op, err } - httpsRBSCShardsOp.userName = userName - httpsRBSCShardsOp.httpsPassword = httpsPassword + op.userName = userName + op.httpsPassword = httpsPassword } - return httpsRBSCShardsOp, nil + return op, nil } -func (op *HTTPSRebalanceSubclusterShardsOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsRebalanceSubclusterShardsOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("subclusters/" + op.scName + "/rebalance") if op.useHTTPPassword { @@ -67,7 +67,7 @@ func (op *HTTPSRebalanceSubclusterShardsOp) setupClusterHTTPRequest(hosts []stri return nil } -func (op *HTTPSRebalanceSubclusterShardsOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsRebalanceSubclusterShardsOp) prepare(execContext *opEngineExecContext) error { // rebalance shards on the default subcluster if scName isn't provided if op.scName == "" { if execContext.defaultSCName == "" { @@ -81,7 +81,7 @@ func (op *HTTPSRebalanceSubclusterShardsOp) prepare(execContext *OpEngineExecCon return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSRebalanceSubclusterShardsOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsRebalanceSubclusterShardsOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -89,7 +89,7 @@ func (op *HTTPSRebalanceSubclusterShardsOp) execute(execContext *OpEngineExecCon return op.processResult(execContext) } -func (op *HTTPSRebalanceSubclusterShardsOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsRebalanceSubclusterShardsOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -131,6 +131,6 @@ func (op *HTTPSRebalanceSubclusterShardsOp) processResult(_ *OpEngineExecContext return allErrs } -func (op *HTTPSRebalanceSubclusterShardsOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsRebalanceSubclusterShardsOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_reload_spread_op.go b/vclusterops/https_reload_spread_op.go index 609ec50..fe6e207 100644 --- a/vclusterops/https_reload_spread_op.go +++ b/vclusterops/https_reload_spread_op.go @@ -23,37 +23,37 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSReloadSpreadOp struct { - OpBase - OpHTTPSBase +type httpsReloadSpreadOp struct { + opBase + opHTTPSBase } func makeHTTPSReloadSpreadOpWithInitiator(logger vlog.Printer, initHosts []string, useHTTPPassword bool, - userName string, httpsPassword *string) (HTTPSReloadSpreadOp, error) { - httpsReloadSpreadOp := HTTPSReloadSpreadOp{} - httpsReloadSpreadOp.name = "HTTPSReloadSpreadOp" - httpsReloadSpreadOp.logger = logger.WithName(httpsReloadSpreadOp.name) - httpsReloadSpreadOp.hosts = initHosts - httpsReloadSpreadOp.useHTTPPassword = useHTTPPassword - - err := util.ValidateUsernameAndPassword(httpsReloadSpreadOp.name, useHTTPPassword, userName) + userName string, httpsPassword *string) (httpsReloadSpreadOp, error) { + op := httpsReloadSpreadOp{} + op.name = "HTTPSReloadSpreadOp" + op.logger = logger.WithName(op.name) + op.hosts = initHosts + op.useHTTPPassword = useHTTPPassword + + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsReloadSpreadOp, err + return op, err } - httpsReloadSpreadOp.userName = userName - httpsReloadSpreadOp.httpsPassword = httpsPassword - return httpsReloadSpreadOp, nil + op.userName = userName + op.httpsPassword = httpsPassword + return op, nil } func makeHTTPSReloadSpreadOp(logger vlog.Printer, useHTTPPassword bool, - userName string, httpsPassword *string) (HTTPSReloadSpreadOp, error) { + userName string, httpsPassword *string) (httpsReloadSpreadOp, error) { return makeHTTPSReloadSpreadOpWithInitiator(logger, nil, useHTTPPassword, userName, httpsPassword) } -func (op *HTTPSReloadSpreadOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsReloadSpreadOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("config/spread/reload") if op.useHTTPPassword { @@ -66,7 +66,7 @@ func (op *HTTPSReloadSpreadOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSReloadSpreadOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsReloadSpreadOp) prepare(execContext *opEngineExecContext) error { // If the host input is an empty string, we find up hosts to update the host input if len(op.hosts) == 0 { op.hosts = execContext.upHosts @@ -76,7 +76,7 @@ func (op *HTTPSReloadSpreadOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSReloadSpreadOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsReloadSpreadOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -84,7 +84,7 @@ func (op *HTTPSReloadSpreadOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *HTTPSReloadSpreadOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsReloadSpreadOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -115,6 +115,6 @@ func (op *HTTPSReloadSpreadOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSReloadSpreadOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsReloadSpreadOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_spread_remove_node_op.go b/vclusterops/https_spread_remove_node_op.go index 4026aae..c44d23e 100644 --- a/vclusterops/https_spread_remove_node_op.go +++ b/vclusterops/https_spread_remove_node_op.go @@ -23,15 +23,15 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSSpreadRemoveNodeOp struct { - OpBase - OpHTTPSBase +type httpsSpreadRemoveNodeOp struct { + opBase + opHTTPSBase RequestParams map[string]string } func makeHTTPSSpreadRemoveNodeOp(logger vlog.Printer, hostsToRemove []string, initiatorHost []string, useHTTPPassword bool, - userName string, httpsPassword *string, hostNodeMap vHostNodeMap) (HTTPSSpreadRemoveNodeOp, error) { - op := HTTPSSpreadRemoveNodeOp{} + userName string, httpsPassword *string, hostNodeMap vHostNodeMap) (httpsSpreadRemoveNodeOp, error) { + op := httpsSpreadRemoveNodeOp{} op.name = "HTTPSSpreadRemoveNodeOp" op.logger = logger.WithName(op.name) op.hosts = initiatorHost @@ -52,9 +52,9 @@ func makeHTTPSSpreadRemoveNodeOp(logger vlog.Printer, hostsToRemove []string, in return op, nil } -func (op *HTTPSSpreadRemoveNodeOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsSpreadRemoveNodeOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("config/spread/remove") if op.useHTTPPassword { @@ -67,12 +67,12 @@ func (op *HTTPSSpreadRemoveNodeOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *HTTPSSpreadRemoveNodeOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsSpreadRemoveNodeOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSSpreadRemoveNodeOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsSpreadRemoveNodeOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -80,7 +80,7 @@ func (op *HTTPSSpreadRemoveNodeOp) execute(execContext *OpEngineExecContext) err return op.processResult(execContext) } -func (op *HTTPSSpreadRemoveNodeOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsSpreadRemoveNodeOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -112,6 +112,6 @@ func (op *HTTPSSpreadRemoveNodeOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSSpreadRemoveNodeOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsSpreadRemoveNodeOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_startup_command_op.go b/vclusterops/https_startup_command_op.go index e042eae..21fb352 100644 --- a/vclusterops/https_startup_command_op.go +++ b/vclusterops/https_startup_command_op.go @@ -24,8 +24,8 @@ import ( ) type httpsStartUpCommandOp struct { - OpBase - OpHTTPSBase + opBase + opHTTPSBase vdb *VCoordinationDatabase } @@ -52,7 +52,7 @@ func makeHTTPSStartUpCommandOp(logger vlog.Printer, useHTTPPassword bool, userNa func (op *httpsStartUpCommandOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildHTTPSEndpoint("startup/commands") @@ -68,7 +68,7 @@ func (op *httpsStartUpCommandOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *httpsStartUpCommandOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsStartUpCommandOp) prepare(execContext *opEngineExecContext) error { // Use the /v1/startup/command endpoint for a primary Up host to view every start command of existing nodes var primaryUpHosts []string for host, vnode := range op.vdb.HostNodeMap { @@ -83,7 +83,7 @@ func (op *httpsStartUpCommandOp) prepare(execContext *OpEngineExecContext) error return op.setupClusterHTTPRequest(op.hosts) } -func (op *httpsStartUpCommandOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsStartUpCommandOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -91,7 +91,7 @@ func (op *httpsStartUpCommandOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *httpsStartUpCommandOp) processResult(execContext *OpEngineExecContext) error { +func (op *httpsStartUpCommandOp) processResult(execContext *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -152,6 +152,6 @@ func (op *httpsStartUpCommandOp) processResult(execContext *OpEngineExecContext) return nil } -func (op *httpsStartUpCommandOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsStartUpCommandOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_stop_db_op.go b/vclusterops/https_stop_db_op.go index c78e3be..86fd578 100644 --- a/vclusterops/https_stop_db_op.go +++ b/vclusterops/https_stop_db_op.go @@ -25,39 +25,39 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSStopDBOp struct { - OpBase - OpHTTPSBase +type httpsStopDBOp struct { + opBase + opHTTPSBase RequestParams map[string]string } func makeHTTPSStopDBOp(logger vlog.Printer, useHTTPPassword bool, userName string, - httpsPassword *string, timeout *int) (HTTPSStopDBOp, error) { - httpsStopDBOp := HTTPSStopDBOp{} - httpsStopDBOp.name = "HTTPSStopDBOp" - httpsStopDBOp.logger = logger.WithName(httpsStopDBOp.name) - httpsStopDBOp.useHTTPPassword = useHTTPPassword + httpsPassword *string, timeout *int) (httpsStopDBOp, error) { + op := httpsStopDBOp{} + op.name = "HTTPSStopDBOp" + op.logger = logger.WithName(op.name) + op.useHTTPPassword = useHTTPPassword // set the query params, "timeout" is optional - httpsStopDBOp.RequestParams = make(map[string]string) + op.RequestParams = make(map[string]string) if timeout != nil { - httpsStopDBOp.RequestParams["timeout"] = strconv.Itoa(*timeout) + op.RequestParams["timeout"] = strconv.Itoa(*timeout) } if useHTTPPassword { - err := util.ValidateUsernameAndPassword(httpsStopDBOp.name, useHTTPPassword, userName) + err := util.ValidateUsernameAndPassword(op.name, useHTTPPassword, userName) if err != nil { - return httpsStopDBOp, err + return op, err } - httpsStopDBOp.userName = userName - httpsStopDBOp.httpsPassword = httpsPassword + op.userName = userName + op.httpsPassword = httpsPassword } - return httpsStopDBOp, nil + return op, nil } -func (op *HTTPSStopDBOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsStopDBOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("cluster/shutdown") if op.useHTTPPassword { @@ -71,7 +71,7 @@ func (op *HTTPSStopDBOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSStopDBOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsStopDBOp) prepare(execContext *opEngineExecContext) error { if len(execContext.upHosts) == 0 { return fmt.Errorf(`[%s] Cannot find any up hosts in OpEngineExecContext`, op.name) } @@ -82,7 +82,7 @@ func (op *HTTPSStopDBOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(hosts) } -func (op *HTTPSStopDBOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsStopDBOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -90,7 +90,7 @@ func (op *HTTPSStopDBOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *HTTPSStopDBOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsStopDBOp) processResult(_ *opEngineExecContext) error { var allErrs error re := regexp.MustCompile(`Set subcluster \(.*\) to draining state.*`) @@ -135,6 +135,6 @@ func (op *HTTPSStopDBOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSStopDBOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsStopDBOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/https_sync_catalog_op.go b/vclusterops/https_sync_catalog_op.go index 1040f4a..775e7b2 100644 --- a/vclusterops/https_sync_catalog_op.go +++ b/vclusterops/https_sync_catalog_op.go @@ -24,14 +24,14 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type HTTPSSyncCatalogOp struct { - OpBase - OpHTTPSBase +type httpsSyncCatalogOp struct { + opBase + opHTTPSBase } func makeHTTPSSyncCatalogOp(logger vlog.Printer, hosts []string, useHTTPPassword bool, - userName string, httpsPassword *string) (HTTPSSyncCatalogOp, error) { - op := HTTPSSyncCatalogOp{} + userName string, httpsPassword *string) (httpsSyncCatalogOp, error) { + op := httpsSyncCatalogOp{} op.name = "HTTPSSyncCatalogOp" op.logger = logger.WithName(op.name) op.hosts = hosts @@ -48,13 +48,13 @@ func makeHTTPSSyncCatalogOp(logger vlog.Printer, hosts []string, useHTTPPassword } func makeHTTPSSyncCatalogOpWithoutHosts(logger vlog.Printer, useHTTPPassword bool, - userName string, httpsPassword *string) (HTTPSSyncCatalogOp, error) { + userName string, httpsPassword *string) (httpsSyncCatalogOp, error) { return makeHTTPSSyncCatalogOp(logger, nil, useHTTPPassword, userName, httpsPassword) } -func (op *HTTPSSyncCatalogOp) setupClusterHTTPRequest(hosts []string) error { +func (op *httpsSyncCatalogOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildHTTPSEndpoint("cluster/catalog/sync") httpRequest.QueryParams = make(map[string]string) @@ -69,7 +69,7 @@ func (op *HTTPSSyncCatalogOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *HTTPSSyncCatalogOp) prepare(execContext *OpEngineExecContext) error { +func (op *httpsSyncCatalogOp) prepare(execContext *opEngineExecContext) error { // If no hosts passed in, we will find the hosts from execute-context if len(op.hosts) == 0 { if len(execContext.upHosts) == 0 { @@ -83,7 +83,7 @@ func (op *HTTPSSyncCatalogOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *HTTPSSyncCatalogOp) execute(execContext *OpEngineExecContext) error { +func (op *httpsSyncCatalogOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -91,7 +91,7 @@ func (op *HTTPSSyncCatalogOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *HTTPSSyncCatalogOp) processResult(_ *OpEngineExecContext) error { +func (op *httpsSyncCatalogOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -119,6 +119,6 @@ func (op *HTTPSSyncCatalogOp) processResult(_ *OpEngineExecContext) error { return allErrs } -func (op *HTTPSSyncCatalogOp) finalize(_ *OpEngineExecContext) error { +func (op *httpsSyncCatalogOp) finalize(_ *opEngineExecContext) error { return nil } diff --git a/vclusterops/network_adapter.go b/vclusterops/network_adapter.go index b2ce727..020f9d7 100644 --- a/vclusterops/network_adapter.go +++ b/vclusterops/network_adapter.go @@ -17,7 +17,7 @@ package vclusterops import "net/http" -type Adapter interface { - sendRequest(*HostHTTPRequest, chan<- HostHTTPResult) - generateResult(*http.Response) HostHTTPResult +type adapter interface { + sendRequest(*hostHTTPRequest, chan<- hostHTTPResult) + generateResult(*http.Response) hostHTTPResult } diff --git a/vclusterops/nma_bootstrap_catalog_op.go b/vclusterops/nma_bootstrap_catalog_op.go index 2475b40..3955526 100644 --- a/vclusterops/nma_bootstrap_catalog_op.go +++ b/vclusterops/nma_bootstrap_catalog_op.go @@ -23,8 +23,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMABootstrapCatalogOp struct { - OpBase +type nmaBootstrapCatalogOp struct { + opBase hostRequestBodyMap map[string]bootstrapCatalogRequestData marshaledRequestBodyMap map[string]string } @@ -49,29 +49,29 @@ type bootstrapCatalogRequestData struct { CommunalStorageURL string `json:"communal_storage"` SuperuserName string `json:"superuser_name"` GenerateHTTPCerts bool `json:"generate_http_certs"` - SensitiveFields + sensitiveFields } func makeNMABootstrapCatalogOp( logger vlog.Printer, vdb *VCoordinationDatabase, options *VCreateDatabaseOptions, - bootstrapHosts []string) (NMABootstrapCatalogOp, error) { - nmaBootstrapCatalogOp := NMABootstrapCatalogOp{} - nmaBootstrapCatalogOp.name = "NMABootstrapCatalogOp" - nmaBootstrapCatalogOp.logger = logger.WithName(nmaBootstrapCatalogOp.name) + bootstrapHosts []string) (nmaBootstrapCatalogOp, error) { + op := nmaBootstrapCatalogOp{} + op.name = "NMABootstrapCatalogOp" + op.logger = logger.WithName(op.name) // usually, only one node need bootstrap catalog - nmaBootstrapCatalogOp.hosts = bootstrapHosts + op.hosts = bootstrapHosts - err := nmaBootstrapCatalogOp.setupRequestBody(vdb, options) + err := op.setupRequestBody(vdb, options) if err != nil { - return nmaBootstrapCatalogOp, err + return op, err } - return nmaBootstrapCatalogOp, nil + return op, nil } -func (op *NMABootstrapCatalogOp) setupRequestBody(vdb *VCoordinationDatabase, options *VCreateDatabaseOptions) error { +func (op *nmaBootstrapCatalogOp) setupRequestBody(vdb *VCoordinationDatabase, options *VCreateDatabaseOptions) error { op.hostRequestBodyMap = make(map[string]bootstrapCatalogRequestData) for _, host := range op.hosts { @@ -92,7 +92,7 @@ func (op *NMABootstrapCatalogOp) setupRequestBody(vdb *VCoordinationDatabase, op bootstrapData.Parameters = options.ConfigurationParameters // need to read network_profile info in execContext - // see execContext in NMABootstrapCatalogOp:prepare() + // see execContext in nmaBootstrapCatalogOp:prepare() bootstrapData.ControlAddr = vnode.Address bootstrapData.LicenseKey = vdb.LicensePathOnNode @@ -124,7 +124,7 @@ func (op *NMABootstrapCatalogOp) setupRequestBody(vdb *VCoordinationDatabase, op return nil } -func (op *NMABootstrapCatalogOp) updateRequestBody(execContext *OpEngineExecContext) error { +func (op *nmaBootstrapCatalogOp) updateRequestBody(execContext *opEngineExecContext) error { op.marshaledRequestBodyMap = make(map[string]string) maskedRequestBodyMap := make(map[string]bootstrapCatalogRequestData) @@ -151,10 +151,10 @@ func (op *NMABootstrapCatalogOp) updateRequestBody(execContext *OpEngineExecCont return nil } -func (op *NMABootstrapCatalogOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaBootstrapCatalogOp) setupClusterHTTPRequest(hosts []string) error { // usually, only one node need bootstrap catalog for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("catalog/bootstrap") httpRequest.RequestData = op.marshaledRequestBodyMap[host] @@ -164,7 +164,7 @@ func (op *NMABootstrapCatalogOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMABootstrapCatalogOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaBootstrapCatalogOp) prepare(execContext *opEngineExecContext) error { err := op.updateRequestBody(execContext) if err != nil { return err @@ -175,7 +175,7 @@ func (op *NMABootstrapCatalogOp) prepare(execContext *OpEngineExecContext) error return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMABootstrapCatalogOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaBootstrapCatalogOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -183,11 +183,11 @@ func (op *NMABootstrapCatalogOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *NMABootstrapCatalogOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaBootstrapCatalogOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMABootstrapCatalogOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaBootstrapCatalogOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/nma_delete_dir_op.go b/vclusterops/nma_delete_dir_op.go index b36b2a7..de1cb3a 100644 --- a/vclusterops/nma_delete_dir_op.go +++ b/vclusterops/nma_delete_dir_op.go @@ -9,8 +9,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMADeleteDirectoriesOp struct { - OpBase +type nmaDeleteDirectoriesOp struct { + opBase hostRequestBodyMap map[string]string } @@ -24,21 +24,21 @@ func makeNMADeleteDirectoriesOp( logger vlog.Printer, vdb *VCoordinationDatabase, forceDelete bool, -) (NMADeleteDirectoriesOp, error) { - nmaDeleteDirectoriesOp := NMADeleteDirectoriesOp{} - nmaDeleteDirectoriesOp.name = "NMADeleteDirectoriesOp" - nmaDeleteDirectoriesOp.logger = logger.WithName(nmaDeleteDirectoriesOp.name) - nmaDeleteDirectoriesOp.hosts = vdb.HostList +) (nmaDeleteDirectoriesOp, error) { + op := nmaDeleteDirectoriesOp{} + op.name = "NMADeleteDirectoriesOp" + op.logger = logger.WithName(op.name) + op.hosts = vdb.HostList - err := nmaDeleteDirectoriesOp.buildRequestBody(vdb, forceDelete) + err := op.buildRequestBody(vdb, forceDelete) if err != nil { - return nmaDeleteDirectoriesOp, err + return op, err } - return nmaDeleteDirectoriesOp, nil + return op, nil } -func (op *NMADeleteDirectoriesOp) buildRequestBody( +func (op *nmaDeleteDirectoriesOp) buildRequestBody( vdb *VCoordinationDatabase, forceDelete bool, ) error { @@ -77,9 +77,9 @@ func (op *NMADeleteDirectoriesOp) buildRequestBody( return nil } -func (op *NMADeleteDirectoriesOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaDeleteDirectoriesOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("directories/delete") httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -89,13 +89,13 @@ func (op *NMADeleteDirectoriesOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *NMADeleteDirectoriesOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaDeleteDirectoriesOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMADeleteDirectoriesOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaDeleteDirectoriesOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -103,11 +103,11 @@ func (op *NMADeleteDirectoriesOp) execute(execContext *OpEngineExecContext) erro return op.processResult(execContext) } -func (op *NMADeleteDirectoriesOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaDeleteDirectoriesOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMADeleteDirectoriesOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaDeleteDirectoriesOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/nma_download_config.go b/vclusterops/nma_download_config.go index ce8e96d..59f323c 100644 --- a/vclusterops/nma_download_config.go +++ b/vclusterops/nma_download_config.go @@ -23,8 +23,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMADownloadConfigOp struct { - OpBase +type nmaDownloadConfigOp struct { + opBase catalogPathMap map[string]string endpoint string fileContent *string @@ -38,21 +38,21 @@ func makeNMADownloadConfigOp( endpoint string, fileContent *string, vdb *VCoordinationDatabase, -) NMADownloadConfigOp { - nmaDownloadConfigOp := NMADownloadConfigOp{} - nmaDownloadConfigOp.name = opName - nmaDownloadConfigOp.logger = logger.WithName(nmaDownloadConfigOp.name) - nmaDownloadConfigOp.hosts = sourceConfigHost - nmaDownloadConfigOp.endpoint = endpoint - nmaDownloadConfigOp.fileContent = fileContent - nmaDownloadConfigOp.vdb = vdb - - return nmaDownloadConfigOp +) nmaDownloadConfigOp { + op := nmaDownloadConfigOp{} + op.name = opName + op.logger = logger.WithName(op.name) + op.hosts = sourceConfigHost + op.endpoint = endpoint + op.fileContent = fileContent + op.vdb = vdb + + return op } -func (op *NMADownloadConfigOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaDownloadConfigOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildNMAEndpoint(op.endpoint) @@ -68,7 +68,7 @@ func (op *NMADownloadConfigOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMADownloadConfigOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaDownloadConfigOp) prepare(execContext *opEngineExecContext) error { op.catalogPathMap = make(map[string]string) // vdb is built by calling /cluster and /nodes endpoints of a running db. // If nodes' info is not available in vdb, we will get the host from execContext.nmaVDatabase which is build by reading the catalog editor @@ -117,7 +117,7 @@ func (op *NMADownloadConfigOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMADownloadConfigOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaDownloadConfigOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -125,11 +125,11 @@ func (op *NMADownloadConfigOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMADownloadConfigOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaDownloadConfigOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMADownloadConfigOp) processResult(_ *OpEngineExecContext) error { +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 diff --git a/vclusterops/nma_download_file_op.go b/vclusterops/nma_download_file_op.go index 824f0d8..9acc51f 100644 --- a/vclusterops/nma_download_file_op.go +++ b/vclusterops/nma_download_file_op.go @@ -34,8 +34,8 @@ const ( expirationStringLayout = "2006-01-02 15:04:05.999999" ) -type NMADownloadFileOp struct { - OpBase +type nmaDownloadFileOp struct { + opBase hostRequestBodyMap map[string]string // vdb will be used to save downloaded file info for revive_db vdb *VCoordinationDatabase @@ -57,35 +57,35 @@ type downloadFileRequestData struct { // ClusterLeaseNotExpiredFailure is returned when an attempt is made to use a // communal storage before the lease for it has expired. -type ClusterLeaseNotExpiredError struct { +type clusterLeaseNotExpiredError struct { Expiration string } -func (e *ClusterLeaseNotExpiredError) Error() string { +func (e *clusterLeaseNotExpiredError) Error() string { return fmt.Sprintf("revive database cannot continue because the communal storage location might still be in use."+ " The cluster lease will expire at %s(UTC)."+ " Please ensure that the other cluster has stopped and try revive_db after the cluster lease expiration", e.Expiration) } -// ReviveDBNodeCountMismatchError is returned when the number of nodes in new cluster +// reviveDBNodeCountMismatchError is returned when the number of nodes in new cluster // does not match the number of nodes in original cluster -type ReviveDBNodeCountMismatchError struct { +type reviveDBNodeCountMismatchError struct { ReviveDBStep string FailureHost string NumOfNewNodes int NumOfOldNodes int } -func (e *ReviveDBNodeCountMismatchError) Error() string { +func (e *reviveDBNodeCountMismatchError) Error() string { return fmt.Sprintf(`[%s] nodes mismatch found on host %s: the number of the new nodes in --hosts is %d,`+ ` but the number of the old nodes in description file is %d`, e.ReviveDBStep, e.FailureHost, e.NumOfNewNodes, e.NumOfOldNodes) } func makeNMADownloadFileOp(logger vlog.Printer, newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, - configurationParameters map[string]string, vdb *VCoordinationDatabase) (NMADownloadFileOp, error) { - op := NMADownloadFileOp{} + configurationParameters map[string]string, vdb *VCoordinationDatabase) (nmaDownloadFileOp, error) { + op := nmaDownloadFileOp{} op.name = "NMADownloadFileOp" op.logger = logger.WithName(op.name) initiator := getInitiator(newNodes) @@ -114,7 +114,7 @@ func makeNMADownloadFileOp(logger vlog.Printer, newNodes []string, sourceFilePat } func makeNMADownloadFileOpForRevive(logger vlog.Printer, newNodes []string, sourceFilePath, destinationFilePath, catalogPath string, - configurationParameters map[string]string, vdb *VCoordinationDatabase, displayOnly, ignoreClusterLease bool) (NMADownloadFileOp, error) { + configurationParameters map[string]string, vdb *VCoordinationDatabase, displayOnly, ignoreClusterLease bool) (nmaDownloadFileOp, error) { op, err := makeNMADownloadFileOp(logger, newNodes, sourceFilePath, destinationFilePath, catalogPath, configurationParameters, vdb) if err != nil { @@ -127,9 +127,9 @@ func makeNMADownloadFileOpForRevive(logger vlog.Printer, newNodes []string, sour return op, nil } -func (op *NMADownloadFileOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaDownloadFileOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("vertica/download-file") httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -140,12 +140,12 @@ func (op *NMADownloadFileOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMADownloadFileOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaDownloadFileOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMADownloadFileOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaDownloadFileOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -153,7 +153,7 @@ func (op *NMADownloadFileOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMADownloadFileOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaDownloadFileOp) finalize(_ *opEngineExecContext) error { return nil } @@ -177,7 +177,7 @@ type fileContent struct { } `json:"StorageLocation"` } -func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) error { +func (op *nmaDownloadFileOp) processResult(execContext *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { @@ -221,7 +221,7 @@ func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) err } if len(descFileContent.NodeList) != len(op.newNodes) { - err := &ReviveDBNodeCountMismatchError{ + err := &reviveDBNodeCountMismatchError{ ReviveDBStep: op.name, FailureHost: host, NumOfNewNodes: len(op.newNodes), @@ -244,7 +244,7 @@ func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) err } // buildVDBFromClusterConfig can build a vdb using cluster_config.json -func (op *NMADownloadFileOp) buildVDBFromClusterConfig(descFileContent fileContent) error { +func (op *nmaDownloadFileOp) buildVDBFromClusterConfig(descFileContent fileContent) error { op.vdb.HostNodeMap = makeVHostNodeMap() for _, node := range descFileContent.NodeList { vNode := makeVCoordinationNode() @@ -287,7 +287,7 @@ func (op *NMADownloadFileOp) buildVDBFromClusterConfig(descFileContent fileConte return nil } -func (op *NMADownloadFileOp) clusterLeaseCheck(clusterLeaseExpiration string) error { +func (op *nmaDownloadFileOp) clusterLeaseCheck(clusterLeaseExpiration string) error { if op.ignoreClusterLease { op.logger.PrintWarning("Skipping cluster lease check\n") return nil @@ -302,7 +302,7 @@ func (op *NMADownloadFileOp) clusterLeaseCheck(clusterLeaseExpiration string) er // current time < expire time, it means that the cluster lease is not expired if utcNow.Before(utcExpiration) { - return &ClusterLeaseNotExpiredError{Expiration: clusterLeaseExpiration} + return &clusterLeaseNotExpiredError{Expiration: clusterLeaseExpiration} } op.logger.PrintInfo("Cluster lease check has passed. We proceed to revive the database") diff --git a/vclusterops/nma_download_file_op_test.go b/vclusterops/nma_download_file_op_test.go index 2e02eb5..7508ab1 100644 --- a/vclusterops/nma_download_file_op_test.go +++ b/vclusterops/nma_download_file_op_test.go @@ -24,7 +24,7 @@ import ( ) func TestClusteLeaseExpiryError(t *testing.T) { - op := NMADownloadFileOp{ + op := nmaDownloadFileOp{ ignoreClusterLease: false, } @@ -33,7 +33,7 @@ func TestClusteLeaseExpiryError(t *testing.T) { err := op.clusterLeaseCheck(fakeLeaseTime.Format(expirationStringLayout)) assert.Error(t, err) // Ensure we get a specific error type back - clusterLeaseErr := &ClusterLeaseNotExpiredError{} + clusterLeaseErr := &clusterLeaseNotExpiredError{} ok := errors.As(err, &clusterLeaseErr) assert.True(t, ok) assert.Contains(t, err.Error(), "The cluster lease will expire at") diff --git a/vclusterops/nma_get_healthy_nodes_op.go b/vclusterops/nma_get_healthy_nodes_op.go index f3f2336..2105f0d 100644 --- a/vclusterops/nma_get_healthy_nodes_op.go +++ b/vclusterops/nma_get_healthy_nodes_op.go @@ -25,25 +25,25 @@ import ( // don't block 6 minutes because of one down node. const healthRequestTimeoutSeconds = 20 -type NMAGetHealthyNodesOp struct { - OpBase +type nmaGetHealthyNodesOp struct { + opBase vdb *VCoordinationDatabase } func makeNMAGetHealthyNodesOp(logger vlog.Printer, hosts []string, - vdb *VCoordinationDatabase) NMAGetHealthyNodesOp { - nmaGetHealthyNodesOp := NMAGetHealthyNodesOp{} - nmaGetHealthyNodesOp.name = "NMAGetHealthyNodesOp" - nmaGetHealthyNodesOp.logger = logger.WithName(nmaGetHealthyNodesOp.name) - nmaGetHealthyNodesOp.hosts = hosts - nmaGetHealthyNodesOp.vdb = vdb - return nmaGetHealthyNodesOp + vdb *VCoordinationDatabase) nmaGetHealthyNodesOp { + op := nmaGetHealthyNodesOp{} + op.name = "NMAGetHealthyNodesOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.vdb = vdb + return op } -func (op *NMAGetHealthyNodesOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaGetHealthyNodesOp) setupClusterHTTPRequest(hosts []string) error { op.vdb.HostList = []string{} for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.Timeout = healthRequestTimeoutSeconds httpRequest.buildNMAEndpoint("health") @@ -53,13 +53,13 @@ func (op *NMAGetHealthyNodesOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMAGetHealthyNodesOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaGetHealthyNodesOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAGetHealthyNodesOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaGetHealthyNodesOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -67,11 +67,11 @@ func (op *NMAGetHealthyNodesOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *NMAGetHealthyNodesOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaGetHealthyNodesOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAGetHealthyNodesOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaGetHealthyNodesOp) processResult(_ *opEngineExecContext) error { for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) diff --git a/vclusterops/nma_get_nodes_info_op.go b/vclusterops/nma_get_nodes_info_op.go index d71556e..59c8e15 100644 --- a/vclusterops/nma_get_nodes_info_op.go +++ b/vclusterops/nma_get_nodes_info_op.go @@ -24,7 +24,7 @@ import ( // nmaGetNodesInfoOp get nodes info from the NMA /v1/nodes endpoint. // The result will be saved into a VCoordinationDatabase object. type nmaGetNodesInfoOp struct { - OpBase + opBase dbName string catalogPrefix string ignoreInternalErrors bool // e.g. in scrutinize, continue even if host has issues @@ -49,7 +49,7 @@ func makeNMAGetNodesInfoOp(logger vlog.Printer, hosts []string, func (op *nmaGetNodesInfoOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildNMAEndpoint("nodes") httpRequest.QueryParams = map[string]string{"db_name": op.dbName, "catalog_prefix": op.catalogPrefix} @@ -59,13 +59,13 @@ func (op *nmaGetNodesInfoOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *nmaGetNodesInfoOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaGetNodesInfoOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *nmaGetNodesInfoOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaGetNodesInfoOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -73,11 +73,11 @@ func (op *nmaGetNodesInfoOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *nmaGetNodesInfoOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaGetNodesInfoOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *nmaGetNodesInfoOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaGetNodesInfoOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) diff --git a/vclusterops/nma_get_scrutinize_tar_op.go b/vclusterops/nma_get_scrutinize_tar_op.go index 0044bc4..1767cc3 100644 --- a/vclusterops/nma_get_scrutinize_tar_op.go +++ b/vclusterops/nma_get_scrutinize_tar_op.go @@ -24,16 +24,16 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAGetScrutinizeTarOp struct { - ScrutinizeOpBase +type nmaGetScrutinizeTarOp struct { + scrutinizeOpBase } func makeNMAGetScrutinizeTarOp(logger vlog.Printer, id, batch string, hosts []string, - hostNodeNameMap map[string]string) (NMAGetScrutinizeTarOp, error) { + hostNodeNameMap map[string]string) (nmaGetScrutinizeTarOp, error) { // base members - op := NMAGetScrutinizeTarOp{} + op := nmaGetScrutinizeTarOp{} op.name = "NMAGetScrutinizeTarOp" op.logger = logger.WithName(op.name) op.hosts = hosts @@ -58,7 +58,7 @@ func makeNMAGetScrutinizeTarOp(logger vlog.Printer, // may also be created by this function. the "remote" subdirectory is created to // separate local scrutinize data staged by the NMA (placed in /tmp/scrutinize/) from // data gathered by vcluster from all reachable hosts. -func (op *NMAGetScrutinizeTarOp) createOutputDir() error { +func (op *nmaGetScrutinizeTarOp) createOutputDir() error { const OwnerReadWriteExecute = 0700 outputDir := fmt.Sprintf("%s/%s/", scrutinizeRemoteOutputPath, op.id) if err := os.MkdirAll(outputDir, OwnerReadWriteExecute); err != nil { @@ -74,7 +74,7 @@ func (op *NMAGetScrutinizeTarOp) createOutputDir() error { return nil } -func (op *NMAGetScrutinizeTarOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaGetScrutinizeTarOp) prepare(execContext *opEngineExecContext) error { hostToFilePathsMap := map[string]string{} for _, host := range op.hosts { hostToFilePathsMap[host] = fmt.Sprintf("%s/%s/%s-%s.tgz", @@ -88,7 +88,7 @@ func (op *NMAGetScrutinizeTarOp) prepare(execContext *OpEngineExecContext) error return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAGetScrutinizeTarOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaGetScrutinizeTarOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -96,11 +96,11 @@ func (op *NMAGetScrutinizeTarOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *NMAGetScrutinizeTarOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaGetScrutinizeTarOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAGetScrutinizeTarOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaGetScrutinizeTarOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/nma_health_op.go b/vclusterops/nma_health_op.go index eb0f441..bdb63aa 100644 --- a/vclusterops/nma_health_op.go +++ b/vclusterops/nma_health_op.go @@ -21,22 +21,22 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAHealthOp struct { - OpBase +type nmaHealthOp struct { + opBase } -func makeNMAHealthOp(logger vlog.Printer, hosts []string) NMAHealthOp { - nmaHealthOp := NMAHealthOp{} - nmaHealthOp.name = "NMAHealthOp" - nmaHealthOp.logger = logger.WithName(nmaHealthOp.name) - nmaHealthOp.hosts = hosts - return nmaHealthOp +func makeNMAHealthOp(logger vlog.Printer, hosts []string) nmaHealthOp { + op := nmaHealthOp{} + op.name = "NMAHealthOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + return op } // setupClusterHTTPRequest works as the module setup in Admintools -func (op *NMAHealthOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaHealthOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildNMAEndpoint("health") op.clusterHTTPRequest.RequestCollection[host] = httpRequest @@ -45,13 +45,13 @@ func (op *NMAHealthOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMAHealthOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaHealthOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAHealthOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaHealthOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -59,11 +59,11 @@ func (op *NMAHealthOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMAHealthOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaHealthOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAHealthOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaHealthOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) diff --git a/vclusterops/nma_load_remote_catalog_op.go b/vclusterops/nma_load_remote_catalog_op.go index 5f2f50d..a41f0c3 100644 --- a/vclusterops/nma_load_remote_catalog_op.go +++ b/vclusterops/nma_load_remote_catalog_op.go @@ -24,7 +24,7 @@ import ( ) type nmaLoadRemoteCatalogOp struct { - OpBase + opBase hostRequestBodyMap map[string]string configurationParameters map[string]string oldHosts []string @@ -68,7 +68,7 @@ func makeNMALoadRemoteCatalogOp(logger vlog.Printer, oldHosts []string, configur } // make https json data -func (op *nmaLoadRemoteCatalogOp) setupRequestBody(execContext *OpEngineExecContext) error { +func (op *nmaLoadRemoteCatalogOp) setupRequestBody(execContext *opEngineExecContext) error { if len(execContext.networkProfiles) != len(op.hosts) { return fmt.Errorf("[%s] the number of hosts in networkProfiles does not match"+ " the number of hosts that will load remote catalogs", op.name) @@ -112,7 +112,7 @@ func (op *nmaLoadRemoteCatalogOp) setupRequestBody(execContext *OpEngineExecCont func (op *nmaLoadRemoteCatalogOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("catalog/revive") httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -124,7 +124,7 @@ func (op *nmaLoadRemoteCatalogOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *nmaLoadRemoteCatalogOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaLoadRemoteCatalogOp) prepare(execContext *opEngineExecContext) error { err := op.setupRequestBody(execContext) if err != nil { return err @@ -134,7 +134,7 @@ func (op *nmaLoadRemoteCatalogOp) prepare(execContext *OpEngineExecContext) erro return op.setupClusterHTTPRequest(op.hosts) } -func (op *nmaLoadRemoteCatalogOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaLoadRemoteCatalogOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -142,11 +142,11 @@ func (op *nmaLoadRemoteCatalogOp) execute(execContext *OpEngineExecContext) erro return op.processResult(execContext) } -func (op *nmaLoadRemoteCatalogOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaLoadRemoteCatalogOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *nmaLoadRemoteCatalogOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaLoadRemoteCatalogOp) processResult(_ *opEngineExecContext) error { var allErrs error var successPrimaryNodeCount uint diff --git a/vclusterops/nma_network_profile_op.go b/vclusterops/nma_network_profile_op.go index 8f665b9..ed0298a 100644 --- a/vclusterops/nma_network_profile_op.go +++ b/vclusterops/nma_network_profile_op.go @@ -23,21 +23,21 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMANetworkProfileOp struct { - OpBase +type nmaNetworkProfileOp struct { + opBase } -func makeNMANetworkProfileOp(logger vlog.Printer, hosts []string) NMANetworkProfileOp { - nmaNetworkProfileOp := NMANetworkProfileOp{} - nmaNetworkProfileOp.name = "NMANetworkProfileOp" - nmaNetworkProfileOp.logger = logger.WithName(nmaNetworkProfileOp.name) - nmaNetworkProfileOp.hosts = hosts - return nmaNetworkProfileOp +func makeNMANetworkProfileOp(logger vlog.Printer, hosts []string) nmaNetworkProfileOp { + op := nmaNetworkProfileOp{} + op.name = "NMANetworkProfileOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + return op } -func (op *NMANetworkProfileOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaNetworkProfileOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildNMAEndpoint("network-profiles") httpRequest.QueryParams = map[string]string{"broadcast-hint": host} @@ -48,12 +48,12 @@ func (op *NMANetworkProfileOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMANetworkProfileOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaNetworkProfileOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMANetworkProfileOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaNetworkProfileOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -61,11 +61,11 @@ func (op *NMANetworkProfileOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMANetworkProfileOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaNetworkProfileOp) finalize(_ *opEngineExecContext) error { return nil } -type NetworkProfile struct { +type networkProfile struct { Name string Address string Subnet string @@ -73,10 +73,10 @@ type NetworkProfile struct { Broadcast string } -func (op *NMANetworkProfileOp) processResult(execContext *OpEngineExecContext) error { +func (op *nmaNetworkProfileOp) processResult(execContext *opEngineExecContext) error { var allErrs error - allNetProfiles := make(map[string]NetworkProfile) + allNetProfiles := make(map[string]networkProfile) for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -100,8 +100,8 @@ func (op *NMANetworkProfileOp) processResult(execContext *OpEngineExecContext) e return allErrs } -func (op *NMANetworkProfileOp) parseResponse(host, resultContent string) (NetworkProfile, error) { - var responseObj NetworkProfile +func (op *nmaNetworkProfileOp) parseResponse(host, resultContent string) (networkProfile, error) { + var responseObj networkProfile // the response_obj will be a dictionary like the following: // { diff --git a/vclusterops/nma_prepare_directories_op.go b/vclusterops/nma_prepare_directories_op.go index 4a732b6..e186dd3 100644 --- a/vclusterops/nma_prepare_directories_op.go +++ b/vclusterops/nma_prepare_directories_op.go @@ -24,8 +24,8 @@ import ( "golang.org/x/exp/maps" ) -type NMAPrepareDirectoriesOp struct { - OpBase +type nmaPrepareDirectoriesOp struct { + opBase hostRequestBodyMap map[string]string forceCleanup bool forRevive bool @@ -42,24 +42,24 @@ type prepareDirectoriesRequestData struct { } func makeNMAPrepareDirectoriesOp(logger vlog.Printer, hostNodeMap vHostNodeMap, - forceCleanup, forRevive bool) (NMAPrepareDirectoriesOp, error) { - nmaPrepareDirectoriesOp := NMAPrepareDirectoriesOp{} - nmaPrepareDirectoriesOp.name = "NMAPrepareDirectoriesOp" - nmaPrepareDirectoriesOp.logger = logger.WithName(nmaPrepareDirectoriesOp.name) - nmaPrepareDirectoriesOp.forceCleanup = forceCleanup - nmaPrepareDirectoriesOp.forRevive = forRevive - - err := nmaPrepareDirectoriesOp.setupRequestBody(hostNodeMap) + forceCleanup, forRevive bool) (nmaPrepareDirectoriesOp, error) { + op := nmaPrepareDirectoriesOp{} + op.name = "NMAPrepareDirectoriesOp" + op.logger = logger.WithName(op.name) + op.forceCleanup = forceCleanup + op.forRevive = forRevive + + err := op.setupRequestBody(hostNodeMap) if err != nil { - return nmaPrepareDirectoriesOp, err + return op, err } - nmaPrepareDirectoriesOp.hosts = maps.Keys(hostNodeMap) + op.hosts = maps.Keys(hostNodeMap) - return nmaPrepareDirectoriesOp, nil + return op, nil } -func (op *NMAPrepareDirectoriesOp) setupRequestBody(hostNodeMap vHostNodeMap) error { +func (op *nmaPrepareDirectoriesOp) setupRequestBody(hostNodeMap vHostNodeMap) error { op.hostRequestBodyMap = make(map[string]string) for host := range hostNodeMap { @@ -84,9 +84,9 @@ func (op *NMAPrepareDirectoriesOp) setupRequestBody(hostNodeMap vHostNodeMap) er return nil } -func (op *NMAPrepareDirectoriesOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaPrepareDirectoriesOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("directories/prepare") httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -96,12 +96,12 @@ func (op *NMAPrepareDirectoriesOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *NMAPrepareDirectoriesOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaPrepareDirectoriesOp) prepare(execContext *opEngineExecContext) error { execContext.dispatcher.setup(op.hosts) return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAPrepareDirectoriesOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaPrepareDirectoriesOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -109,11 +109,11 @@ func (op *NMAPrepareDirectoriesOp) execute(execContext *OpEngineExecContext) err return op.processResult(execContext) } -func (op *NMAPrepareDirectoriesOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaPrepareDirectoriesOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAPrepareDirectoriesOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaPrepareDirectoriesOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/nma_re_ip_op.go b/vclusterops/nma_re_ip_op.go index 2b166ba..2d9ffa4 100644 --- a/vclusterops/nma_re_ip_op.go +++ b/vclusterops/nma_re_ip_op.go @@ -23,9 +23,9 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAReIPOp struct { - OpBase - reIPList []ReIPInfo +type nmaReIPOp struct { + opBase + reIPList []reIPInfo vdb *VCoordinationDatabase primaryNodeCount uint hostRequestBodyMap map[string]string @@ -35,10 +35,10 @@ type NMAReIPOp struct { } func makeNMAReIPOp(logger vlog.Printer, - reIPList []ReIPInfo, + reIPList []reIPInfo, vdb *VCoordinationDatabase, - trimReIPData bool) NMAReIPOp { - op := NMAReIPOp{} + trimReIPData bool) nmaReIPOp { + op := nmaReIPOp{} op.name = "NMAReIPOp" op.logger = logger.WithName(op.name) op.reIPList = reIPList @@ -47,7 +47,7 @@ func makeNMAReIPOp(logger vlog.Printer, return op } -type ReIPInfo struct { +type reIPInfo struct { NodeName string `json:"node_name"` NodeAddress string `json:"-"` TargetAddress string `json:"address"` @@ -57,10 +57,10 @@ type ReIPInfo struct { type reIPParams struct { CatalogPath string `json:"catalog_path"` - ReIPInfoList []ReIPInfo `json:"re_ip_list"` + ReIPInfoList []reIPInfo `json:"re_ip_list"` } -func (op *NMAReIPOp) updateRequestBody(_ *OpEngineExecContext) error { +func (op *nmaReIPOp) updateRequestBody(_ *opEngineExecContext) error { op.hostRequestBodyMap = make(map[string]string) for _, host := range op.hosts { @@ -79,9 +79,9 @@ func (op *NMAReIPOp) updateRequestBody(_ *OpEngineExecContext) error { return nil } -func (op *NMAReIPOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaReIPOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PutMethod httpRequest.buildNMAEndpoint("catalog/re-ip") httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -93,7 +93,7 @@ func (op *NMAReIPOp) setupClusterHTTPRequest(hosts []string) error { } // updateReIPList is used for the vcluster CLI to update node names -func (op *NMAReIPOp) updateReIPList(execContext *OpEngineExecContext) error { +func (op *nmaReIPOp) updateReIPList(execContext *opEngineExecContext) error { hostNodeMap := execContext.nmaVDatabase.HostNodeMap for i := 0; i < len(op.reIPList); i++ { @@ -128,14 +128,14 @@ func (op *NMAReIPOp) updateReIPList(execContext *OpEngineExecContext) error { // trimReIPList removes nodes, based on catalog editor info, // which are not among the nodes with latest catalog -func (op *NMAReIPOp) trimReIPList(execContext *OpEngineExecContext) error { +func (op *nmaReIPOp) trimReIPList(execContext *opEngineExecContext) error { nodeNamesWithLatestCatalog := make(map[string]struct{}) for i := range execContext.nmaVDatabase.Nodes { vnode := execContext.nmaVDatabase.Nodes[i] nodeNamesWithLatestCatalog[vnode.Name] = struct{}{} } - var trimmedReIPList []ReIPInfo + var trimmedReIPList []reIPInfo nodesToTrim := make(map[string]string) for _, reIPInfo := range op.reIPList { if _, exist := nodeNamesWithLatestCatalog[reIPInfo.NodeName]; exist { @@ -163,7 +163,7 @@ func (op *NMAReIPOp) trimReIPList(execContext *OpEngineExecContext) error { // whetherSkipReIP decides whether skip calling the re-ip endpoint; skip it in case that // the target addresses in the re-ip list match the node addresses in catalog. // Return true if skip. -func (op *NMAReIPOp) whetherSkipReIP(execContext *OpEngineExecContext) bool { +func (op *nmaReIPOp) whetherSkipReIP(execContext *opEngineExecContext) bool { // node name to address map retrieved from catalog nodeAddressMap := make(map[string]string) for h, n := range execContext.nmaVDatabase.HostNodeMap { @@ -186,7 +186,7 @@ func (op *NMAReIPOp) whetherSkipReIP(execContext *OpEngineExecContext) bool { return true } -func (op *NMAReIPOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaReIPOp) prepare(execContext *opEngineExecContext) error { // build mapHostToNodeName and catalogPathMap from vdb op.mapHostToNodeName = make(map[string]string) op.mapHostToCatalogPath = make(map[string]string) @@ -252,7 +252,7 @@ func (op *NMAReIPOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAReIPOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaReIPOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -260,18 +260,18 @@ func (op *NMAReIPOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMAReIPOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaReIPOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAReIPOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaReIPOp) processResult(_ *opEngineExecContext) error { var allErrs error var successCount uint for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) if result.isPassing() { - var reIPResult []ReIPInfo + var reIPResult []reIPInfo err := op.parseAndCheckResponse(host, result.content, &reIPResult) if err != nil { err = fmt.Errorf("[%s] fail to parse result on host %s, details: %w", diff --git a/vclusterops/nma_read_catalog_editor_op.go b/vclusterops/nma_read_catalog_editor_op.go index 7755794..08a91ca 100644 --- a/vclusterops/nma_read_catalog_editor_op.go +++ b/vclusterops/nma_read_catalog_editor_op.go @@ -24,8 +24,8 @@ import ( "golang.org/x/exp/maps" ) -type NMAReadCatalogEditorOp struct { - OpBase +type nmaReadCatalogEditorOp struct { + opBase initiator []string // used when creating new nodes vdb *VCoordinationDatabase catalogPathMap map[string]string @@ -37,8 +37,8 @@ func makeNMAReadCatalogEditorOpWithInitiator( logger vlog.Printer, initiator []string, vdb *VCoordinationDatabase, -) (NMAReadCatalogEditorOp, error) { - op := NMAReadCatalogEditorOp{} +) (nmaReadCatalogEditorOp, error) { + op := nmaReadCatalogEditorOp{} op.name = "NMAReadCatalogEditorOp" op.logger = logger.WithName(op.name) op.initiator = initiator @@ -47,13 +47,13 @@ func makeNMAReadCatalogEditorOpWithInitiator( } // makeNMAReadCatalogEditorOp creates an op to read catalog editor info. -func makeNMAReadCatalogEditorOp(logger vlog.Printer, vdb *VCoordinationDatabase) (NMAReadCatalogEditorOp, error) { +func makeNMAReadCatalogEditorOp(logger vlog.Printer, vdb *VCoordinationDatabase) (nmaReadCatalogEditorOp, error) { return makeNMAReadCatalogEditorOpWithInitiator(logger, []string{}, vdb) } -func (op *NMAReadCatalogEditorOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaReadCatalogEditorOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildNMAEndpoint("catalog/database") @@ -71,7 +71,7 @@ func (op *NMAReadCatalogEditorOp) setupClusterHTTPRequest(hosts []string) error return nil } -func (op *NMAReadCatalogEditorOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaReadCatalogEditorOp) prepare(execContext *opEngineExecContext) error { // build a map from host to catalog path // if the initiator host(s) are given, only build map for these hosts op.catalogPathMap = make(map[string]string) @@ -97,7 +97,7 @@ func (op *NMAReadCatalogEditorOp) prepare(execContext *OpEngineExecContext) erro return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAReadCatalogEditorOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaReadCatalogEditorOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -105,11 +105,11 @@ func (op *NMAReadCatalogEditorOp) execute(execContext *OpEngineExecContext) erro return op.processResult(execContext) } -func (op *NMAReadCatalogEditorOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaReadCatalogEditorOp) finalize(_ *opEngineExecContext) error { return nil } -type NmaVersions struct { +type nmaVersions struct { Global json.Number `json:"global"` Local json.Number `json:"local"` Session json.Number `json:"session"` @@ -118,7 +118,7 @@ type NmaVersions struct { TwoPhaseID json.Number `json:"two_phase_id"` } -type NmaVNode struct { +type nmaVNode struct { Address string `json:"address"` AddressFamily string `json:"address_family"` CatalogPath string `json:"catalog_path"` @@ -152,12 +152,12 @@ type NmaVNode struct { } `json:"sc_details"` } -type NmaVDatabase struct { +type nmaVDatabase struct { Name string `json:"name"` - Versions NmaVersions `json:"versions"` - Nodes []NmaVNode `json:"nodes"` + Versions nmaVersions `json:"versions"` + Nodes []nmaVNode `json:"nodes"` // this map will not be unmarshaled but will be used in NMAStartNodeOp - HostNodeMap map[string]*NmaVNode `json:",omitempty"` + HostNodeMap map[string]*nmaVNode `json:",omitempty"` ControlMode string `json:"control_mode"` WillUpgrade bool `json:"will_upgrade"` SpreadEncryption string `json:"spread_encryption"` @@ -166,16 +166,16 @@ type NmaVDatabase struct { PrimaryNodeCount uint `json:",omitempty"` } -func (op *NMAReadCatalogEditorOp) processResult(execContext *OpEngineExecContext) error { +func (op *nmaReadCatalogEditorOp) processResult(execContext *opEngineExecContext) error { var allErrs error var hostsWithLatestCatalog []string var maxGlobalVersion int64 - var latestNmaVDB NmaVDatabase + var latestNmaVDB nmaVDatabase for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) if result.isPassing() { - nmaVDB := NmaVDatabase{} + nmaVDB := nmaVDatabase{} err := op.parseAndCheckResponse(host, result.content, &nmaVDB) if err != nil { err = fmt.Errorf("[%s] fail to parse result on host %s, details: %w", @@ -186,7 +186,7 @@ func (op *NMAReadCatalogEditorOp) processResult(execContext *OpEngineExecContext var primaryNodeCount uint // build host to node map for NMAStartNodeOp - hostNodeMap := make(map[string]*NmaVNode) + hostNodeMap := make(map[string]*nmaVNode) for i := 0; i < len(nmaVDB.Nodes); i++ { n := nmaVDB.Nodes[i] hostNodeMap[n.Address] = &n diff --git a/vclusterops/nma_spread_security_op.go b/vclusterops/nma_spread_security_op.go index ae3f534..e464ba4 100644 --- a/vclusterops/nma_spread_security_op.go +++ b/vclusterops/nma_spread_security_op.go @@ -26,7 +26,7 @@ import ( ) type nmaSpreadSecurityOp struct { - OpBase + opBase catalogPathMap map[string]string keyType string } @@ -45,7 +45,7 @@ func makeNMASpreadSecurityOp( keyType string, ) nmaSpreadSecurityOp { return nmaSpreadSecurityOp{ - OpBase: OpBase{ + opBase: opBase{ logger: logger.WithName("NMASpreadSecurityOp"), name: "NMASpreadSecurityOp", hosts: nil, // We always set this at runtime from read catalog editor @@ -90,7 +90,7 @@ func (op *nmaSpreadSecurityOp) setupRequestBody() (map[string]string, error) { func (op *nmaSpreadSecurityOp) setupClusterHTTPRequest(hostRequestBodyMap map[string]string) error { for host, requestBody := range hostRequestBodyMap { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("catalog/spread-security") httpRequest.RequestData = requestBody @@ -100,7 +100,7 @@ func (op *nmaSpreadSecurityOp) setupClusterHTTPRequest(hostRequestBodyMap map[st return nil } -func (op *nmaSpreadSecurityOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaSpreadSecurityOp) prepare(execContext *opEngineExecContext) error { if err := op.setRuntimeParms(execContext); err != nil { return err } @@ -113,7 +113,7 @@ func (op *nmaSpreadSecurityOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(hostRequestBodyMap) } -func (op *nmaSpreadSecurityOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaSpreadSecurityOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -121,11 +121,11 @@ func (op *nmaSpreadSecurityOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *nmaSpreadSecurityOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaSpreadSecurityOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *nmaSpreadSecurityOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaSpreadSecurityOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -141,7 +141,7 @@ func (op *nmaSpreadSecurityOp) processResult(_ *OpEngineExecContext) error { } // setRuntimeParms will set options based on runtime context. -func (op *nmaSpreadSecurityOp) setRuntimeParms(execContext *OpEngineExecContext) error { +func (op *nmaSpreadSecurityOp) setRuntimeParms(execContext *opEngineExecContext) error { // Always pull the hosts at runtime using the node with the latest catalog. // Need to use the ones with the latest catalog because those are the hosts // that we copy the spread.conf from during start db. diff --git a/vclusterops/nma_stage_dc_tables_op.go b/vclusterops/nma_stage_dc_tables_op.go index 94a9043..2439d4b 100644 --- a/vclusterops/nma_stage_dc_tables_op.go +++ b/vclusterops/nma_stage_dc_tables_op.go @@ -22,8 +22,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAStageDCTablesOp struct { - ScrutinizeOpBase +type nmaStageDCTablesOp struct { + scrutinizeOpBase } type stageDCTablesRequestData struct { @@ -38,9 +38,9 @@ func makeNMAStageDCTablesOp(logger vlog.Printer, id string, hosts []string, hostNodeNameMap map[string]string, - hostCatPathMap map[string]string) (NMAStageDCTablesOp, error) { + hostCatPathMap map[string]string) (nmaStageDCTablesOp, error) { // base members - op := NMAStageDCTablesOp{} + op := nmaStageDCTablesOp{} op.name = "NMAStageDCTablesOp" op.logger = logger.WithName(op.name) op.hosts = hosts @@ -58,7 +58,7 @@ func makeNMAStageDCTablesOp(logger vlog.Printer, return op, err } -func (op *NMAStageDCTablesOp) setupRequestBody(hosts []string) error { +func (op *nmaStageDCTablesOp) setupRequestBody(hosts []string) error { op.hostRequestBodyMap = make(map[string]string, len(hosts)) for _, host := range hosts { stageDCTablesData := stageDCTablesRequestData{} @@ -75,7 +75,7 @@ func (op *NMAStageDCTablesOp) setupRequestBody(hosts []string) error { return nil } -func (op *NMAStageDCTablesOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaStageDCTablesOp) prepare(execContext *opEngineExecContext) error { err := op.setupRequestBody(op.hosts) if err != nil { return err @@ -85,7 +85,7 @@ func (op *NMAStageDCTablesOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAStageDCTablesOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaStageDCTablesOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -93,11 +93,11 @@ func (op *NMAStageDCTablesOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMAStageDCTablesOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaStageDCTablesOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAStageDCTablesOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaStageDCTablesOp) processResult(_ *opEngineExecContext) error { fileList := make([]stageDCTablesResponseData, 0) - return processStagedFilesResult(&op.ScrutinizeOpBase, fileList) + return processStagedFilesResult(&op.scrutinizeOpBase, fileList) } diff --git a/vclusterops/nma_stage_error_report_op.go b/vclusterops/nma_stage_error_report_op.go index a54dcec..ea67e94 100644 --- a/vclusterops/nma_stage_error_report_op.go +++ b/vclusterops/nma_stage_error_report_op.go @@ -22,8 +22,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAStageErrorReportOp struct { - ScrutinizeOpBase +type nmaStageErrorReportOp struct { + scrutinizeOpBase } type stageErrorReportRequestData struct { @@ -40,9 +40,9 @@ func makeNMAStageErrorReportOp(logger vlog.Printer, id string, hosts []string, hostNodeNameMap map[string]string, - hostCatPathMap map[string]string) (NMAStageErrorReportOp, error) { + hostCatPathMap map[string]string) (nmaStageErrorReportOp, error) { // base members - op := NMAStageErrorReportOp{} + op := nmaStageErrorReportOp{} op.name = "NMAStageErrorReportOp" op.logger = logger.WithName(op.name) op.hosts = hosts @@ -60,7 +60,7 @@ func makeNMAStageErrorReportOp(logger vlog.Printer, return op, err } -func (op *NMAStageErrorReportOp) setupRequestBody(hosts []string) error { +func (op *nmaStageErrorReportOp) setupRequestBody(hosts []string) error { op.hostRequestBodyMap = make(map[string]string, len(hosts)) for _, host := range hosts { stageErrorReportData := stageErrorReportRequestData{} @@ -77,7 +77,7 @@ func (op *NMAStageErrorReportOp) setupRequestBody(hosts []string) error { return nil } -func (op *NMAStageErrorReportOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaStageErrorReportOp) prepare(execContext *opEngineExecContext) error { err := op.setupRequestBody(op.hosts) if err != nil { return err @@ -87,7 +87,7 @@ func (op *NMAStageErrorReportOp) prepare(execContext *OpEngineExecContext) error return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAStageErrorReportOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaStageErrorReportOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -95,11 +95,11 @@ func (op *NMAStageErrorReportOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *NMAStageErrorReportOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaStageErrorReportOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAStageErrorReportOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaStageErrorReportOp) processResult(_ *opEngineExecContext) error { fileList := make([]stageErrorReportResponseData, 0) - return processStagedFilesResult(&op.ScrutinizeOpBase, fileList) + return processStagedFilesResult(&op.scrutinizeOpBase, fileList) } diff --git a/vclusterops/nma_stage_vertica_logs_op.go b/vclusterops/nma_stage_vertica_logs_op.go index e7014da..5da767c 100644 --- a/vclusterops/nma_stage_vertica_logs_op.go +++ b/vclusterops/nma_stage_vertica_logs_op.go @@ -22,8 +22,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAStageVerticaLogsOp struct { - ScrutinizeOpBase +type nmaStageVerticaLogsOp struct { + scrutinizeOpBase logSizeLimitBytes int64 logAgeHours int // The maximum age of archieved logs in hours to retrieve } @@ -46,9 +46,9 @@ func makeNMAStageVerticaLogsOp(logger vlog.Printer, hostNodeNameMap map[string]string, hostCatPathMap map[string]string, logSizeLimitBytes int64, - logAgeHours int) (NMAStageVerticaLogsOp, error) { + logAgeHours int) (nmaStageVerticaLogsOp, error) { // base members - op := NMAStageVerticaLogsOp{} + op := nmaStageVerticaLogsOp{} op.name = "NMAStageVerticaLogsOp" op.logger = logger.WithName(op.name) op.hosts = hosts @@ -70,7 +70,7 @@ func makeNMAStageVerticaLogsOp(logger vlog.Printer, return op, err } -func (op *NMAStageVerticaLogsOp) setupRequestBody(hosts []string) error { +func (op *nmaStageVerticaLogsOp) setupRequestBody(hosts []string) error { op.hostRequestBodyMap = make(map[string]string, len(hosts)) for _, host := range hosts { stageVerticaLogsData := stageVerticaLogsRequestData{} @@ -89,7 +89,7 @@ func (op *NMAStageVerticaLogsOp) setupRequestBody(hosts []string) error { return nil } -func (op *NMAStageVerticaLogsOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaStageVerticaLogsOp) prepare(execContext *opEngineExecContext) error { err := op.setupRequestBody(op.hosts) if err != nil { return err @@ -99,7 +99,7 @@ func (op *NMAStageVerticaLogsOp) prepare(execContext *OpEngineExecContext) error return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAStageVerticaLogsOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaStageVerticaLogsOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -107,11 +107,11 @@ func (op *NMAStageVerticaLogsOp) execute(execContext *OpEngineExecContext) error return op.processResult(execContext) } -func (op *NMAStageVerticaLogsOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaStageVerticaLogsOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAStageVerticaLogsOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaStageVerticaLogsOp) processResult(_ *opEngineExecContext) error { fileList := make([]stageVerticaLogsResponseData, 0) - return processStagedFilesResult(&op.ScrutinizeOpBase, fileList) + return processStagedFilesResult(&op.scrutinizeOpBase, fileList) } diff --git a/vclusterops/nma_start_node_op.go b/vclusterops/nma_start_node_op.go index 1755e33..57f42e2 100644 --- a/vclusterops/nma_start_node_op.go +++ b/vclusterops/nma_start_node_op.go @@ -24,7 +24,7 @@ import ( ) type nmaStartNodeOp struct { - OpBase + opBase hostRequestBodyMap map[string]string vdb *VCoordinationDatabase } @@ -44,7 +44,7 @@ func makeNMAStartNodeOpWithVDB(logger vlog.Printer, hosts []string, vdb *VCoordi return startNodeOp } -func (op *nmaStartNodeOp) updateRequestBody(execContext *OpEngineExecContext) error { +func (op *nmaStartNodeOp) updateRequestBody(execContext *opEngineExecContext) error { op.hostRequestBodyMap = make(map[string]string) // If the execContext.StartUpCommand is nil, we will use startup command information from NMA Read Catalog Editor. // This case is used for certain operations (e.g., start_db, create_db) when the database is down, @@ -99,7 +99,7 @@ func (op *nmaStartNodeOp) updateHostRequestBodyMapFromNodeStartCommand(host stri func (op *nmaStartNodeOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint("nodes/start") httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -109,7 +109,7 @@ func (op *nmaStartNodeOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *nmaStartNodeOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaStartNodeOp) prepare(execContext *opEngineExecContext) error { err := op.updateRequestBody(execContext) if err != nil { return err @@ -120,7 +120,7 @@ func (op *nmaStartNodeOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *nmaStartNodeOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaStartNodeOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -128,7 +128,7 @@ func (op *nmaStartNodeOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *nmaStartNodeOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaStartNodeOp) finalize(_ *opEngineExecContext) error { return nil } @@ -137,7 +137,7 @@ type startNodeResponse struct { ReturnCode int `json:"return_code"` } -func (op *nmaStartNodeOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaStartNodeOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/nma_upload_config.go b/vclusterops/nma_upload_config.go index 663a284..201ea40 100644 --- a/vclusterops/nma_upload_config.go +++ b/vclusterops/nma_upload_config.go @@ -24,8 +24,8 @@ import ( "github.com/vertica/vcluster/vclusterops/vlog" ) -type NMAUploadConfigOp struct { - OpBase +type nmaUploadConfigOp struct { + opBase catalogPathMap map[string]string endpoint string fileContent *string @@ -57,21 +57,21 @@ func makeNMAUploadConfigOp( endpoint string, fileContent *string, vdb *VCoordinationDatabase, -) NMAUploadConfigOp { - nmaUploadConfigOp := NMAUploadConfigOp{} - nmaUploadConfigOp.name = opName - nmaUploadConfigOp.logger = logger.WithName(nmaUploadConfigOp.name) - nmaUploadConfigOp.endpoint = endpoint - nmaUploadConfigOp.fileContent = fileContent - nmaUploadConfigOp.catalogPathMap = make(map[string]string) - nmaUploadConfigOp.sourceConfigHost = sourceConfigHost - nmaUploadConfigOp.destHosts = targetHosts - nmaUploadConfigOp.vdb = vdb - - return nmaUploadConfigOp +) nmaUploadConfigOp { + op := nmaUploadConfigOp{} + op.name = opName + op.logger = logger.WithName(op.name) + op.endpoint = endpoint + op.fileContent = fileContent + op.catalogPathMap = make(map[string]string) + op.sourceConfigHost = sourceConfigHost + op.destHosts = targetHosts + op.vdb = vdb + + return op } -func (op *NMAUploadConfigOp) setupRequestBody(hosts []string) error { +func (op *nmaUploadConfigOp) setupRequestBody(hosts []string) error { op.hostRequestBodyMap = make(map[string]string) for _, host := range hosts { @@ -90,9 +90,9 @@ func (op *NMAUploadConfigOp) setupRequestBody(hosts []string) error { return nil } -func (op *NMAUploadConfigOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaUploadConfigOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = PostMethod httpRequest.buildNMAEndpoint(op.endpoint) httpRequest.RequestData = op.hostRequestBodyMap[host] @@ -102,7 +102,7 @@ func (op *NMAUploadConfigOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMAUploadConfigOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaUploadConfigOp) prepare(execContext *opEngineExecContext) error { op.catalogPathMap = make(map[string]string) // If any node's info is available, we set catalogPathMap from node's info. // This case is used for restarting nodes operation. @@ -152,7 +152,7 @@ func (op *NMAUploadConfigOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAUploadConfigOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaUploadConfigOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -160,11 +160,11 @@ func (op *NMAUploadConfigOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMAUploadConfigOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaUploadConfigOp) finalize(_ *opEngineExecContext) error { return nil } -func (op *NMAUploadConfigOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaUploadConfigOp) processResult(_ *opEngineExecContext) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/nma_vertica_version_op.go b/vclusterops/nma_vertica_version_op.go index f1a1cc8..41cb9bd 100644 --- a/vclusterops/nma_vertica_version_op.go +++ b/vclusterops/nma_vertica_version_op.go @@ -28,54 +28,54 @@ const ( DefaultSC = "default_subcluster" ) -type HostVersionMap map[string]string +type hostVersionMap map[string]string -type NMAVerticaVersionOp struct { - OpBase +type nmaVerticaVersionOp struct { + opBase IsEon bool RequireSameVersion bool HasIncomingSCNames bool - SCToHostVersionMap map[string]HostVersionMap + SCToHostVersionMap map[string]hostVersionMap vdb *VCoordinationDatabase } -func makeHostVersionMap() HostVersionMap { - return make(HostVersionMap) +func makeHostVersionMap() hostVersionMap { + return make(hostVersionMap) } -func makeSCToHostVersionMap() map[string]HostVersionMap { - return make(map[string]HostVersionMap) +func makeSCToHostVersionMap() map[string]hostVersionMap { + return make(map[string]hostVersionMap) } // makeNMAVerticaVersionOp is used when db has not been created -func makeNMAVerticaVersionOp(logger vlog.Printer, hosts []string, sameVersion, isEon bool) NMAVerticaVersionOp { - nmaVerticaVersionOp := NMAVerticaVersionOp{} - nmaVerticaVersionOp.name = "NMAVerticaVersionOp" - nmaVerticaVersionOp.logger = logger.WithName(nmaVerticaVersionOp.name) - nmaVerticaVersionOp.hosts = hosts - nmaVerticaVersionOp.RequireSameVersion = sameVersion - nmaVerticaVersionOp.IsEon = isEon - nmaVerticaVersionOp.SCToHostVersionMap = makeSCToHostVersionMap() - return nmaVerticaVersionOp +func makeNMAVerticaVersionOp(logger vlog.Printer, hosts []string, sameVersion, isEon bool) nmaVerticaVersionOp { + op := nmaVerticaVersionOp{} + op.name = "NMAVerticaVersionOp" + op.logger = logger.WithName(op.name) + op.hosts = hosts + op.RequireSameVersion = sameVersion + op.IsEon = isEon + op.SCToHostVersionMap = makeSCToHostVersionMap() + return op } // makeNMAVerticaVersionOpWithoutHosts is used when db is down -func makeNMAVerticaVersionOpWithoutHosts(logger vlog.Printer, sameVersion bool) NMAVerticaVersionOp { +func makeNMAVerticaVersionOpWithoutHosts(logger vlog.Printer, sameVersion bool) nmaVerticaVersionOp { // We set hosts to nil and isEon to false temporarily, and they will get the correct value from execute context in prepare() return makeNMAVerticaVersionOp(logger, nil /*hosts*/, sameVersion, false /*isEon*/) } // makeNMAVerticaVersionOpWithVDB is used when db is up -func makeNMAVerticaVersionOpWithVDB(logger vlog.Printer, sameVersion bool, vdb *VCoordinationDatabase) NMAVerticaVersionOp { +func makeNMAVerticaVersionOpWithVDB(logger vlog.Printer, sameVersion bool, vdb *VCoordinationDatabase) nmaVerticaVersionOp { // We set hosts to nil temporarily, and it will get the correct value from vdb in prepare() op := makeNMAVerticaVersionOp(logger, nil /*hosts*/, sameVersion, vdb.IsEon) op.vdb = vdb return op } -func (op *NMAVerticaVersionOp) setupClusterHTTPRequest(hosts []string) error { +func (op *nmaVerticaVersionOp) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = GetMethod httpRequest.buildNMAEndpoint("vertica/version") op.clusterHTTPRequest.RequestCollection[host] = httpRequest @@ -84,7 +84,7 @@ func (op *NMAVerticaVersionOp) setupClusterHTTPRequest(hosts []string) error { return nil } -func (op *NMAVerticaVersionOp) prepare(execContext *OpEngineExecContext) error { +func (op *nmaVerticaVersionOp) prepare(execContext *opEngineExecContext) error { /* * Initialize SCToHostVersionMap in three cases: * - when db is up, we initialize SCToHostVersionMap using vdb content (from Vertica https service) @@ -150,7 +150,7 @@ func (op *NMAVerticaVersionOp) prepare(execContext *OpEngineExecContext) error { return op.setupClusterHTTPRequest(op.hosts) } -func (op *NMAVerticaVersionOp) execute(execContext *OpEngineExecContext) error { +func (op *nmaVerticaVersionOp) execute(execContext *opEngineExecContext) error { if err := op.runExecute(execContext); err != nil { return err } @@ -158,17 +158,17 @@ func (op *NMAVerticaVersionOp) execute(execContext *OpEngineExecContext) error { return op.processResult(execContext) } -func (op *NMAVerticaVersionOp) finalize(_ *OpEngineExecContext) error { +func (op *nmaVerticaVersionOp) finalize(_ *opEngineExecContext) error { return nil } -type NMAVerticaVersionOpResponse map[string]string +type nmaVerticaVersionOpResponse map[string]string -func (op *NMAVerticaVersionOp) parseAndCheckResponse(host, resultContent string) error { +func (op *nmaVerticaVersionOp) parseAndCheckResponse(host, resultContent string) error { // each result is a pair {"vertica_version": } // example result: // {"vertica_version": "Vertica Analytic Database v12.0.3"} - var responseObj NMAVerticaVersionOpResponse + var responseObj nmaVerticaVersionOpResponse err := util.GetJSONLogErrors(resultContent, &responseObj, op.name, op.logger) if err != nil { return err @@ -190,7 +190,7 @@ func (op *NMAVerticaVersionOp) parseAndCheckResponse(host, resultContent string) return nil } -func (op *NMAVerticaVersionOp) logResponseCollectVersions() error { +func (op *nmaVerticaVersionOp) logResponseCollectVersions() error { for host, result := range op.clusterHTTPRequest.ResultCollection { op.logResponse(host, result) @@ -208,7 +208,7 @@ func (op *NMAVerticaVersionOp) logResponseCollectVersions() error { return nil } -func (op *NMAVerticaVersionOp) logCheckVersionMatch() error { +func (op *nmaVerticaVersionOp) logCheckVersionMatch() error { /* An example of SCToHostVersionMap: { "default_subcluster" : {"192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0"}, @@ -247,7 +247,7 @@ func (op *NMAVerticaVersionOp) logCheckVersionMatch() error { return nil } -func (op *NMAVerticaVersionOp) processResult(_ *OpEngineExecContext) error { +func (op *nmaVerticaVersionOp) processResult(_ *opEngineExecContext) error { err := op.logResponseCollectVersions() if err != nil { return err diff --git a/vclusterops/nma_vertica_version_op_test.go b/vclusterops/nma_vertica_version_op_test.go index adfd971..63f28ab 100644 --- a/vclusterops/nma_vertica_version_op_test.go +++ b/vclusterops/nma_vertica_version_op_test.go @@ -29,7 +29,7 @@ func TestLogCheckVersionMatch(t *testing.T) { // case 1. one subcluster (enterprise db is one example of this case) // positive test - op.SCToHostVersionMap[""] = HostVersionMap{ + op.SCToHostVersionMap[""] = hostVersionMap{ "192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0", "192.168.0.103": "Vertica Analytic Database v24.1.0", @@ -38,7 +38,7 @@ func TestLogCheckVersionMatch(t *testing.T) { assert.NoError(t, err) // negative test op.SCToHostVersionMap = makeSCToHostVersionMap() - op.SCToHostVersionMap["default_subcluster"] = HostVersionMap{ + op.SCToHostVersionMap["default_subcluster"] = hostVersionMap{ "192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0", "192.168.0.103": "Vertica Analytic Database v23.4.0", @@ -55,17 +55,17 @@ func TestLogCheckVersionMatch(t *testing.T) { // case 2. multiple subclusters // positive test op.SCToHostVersionMap = makeSCToHostVersionMap() - op.SCToHostVersionMap["default_subcluster"] = HostVersionMap{ + op.SCToHostVersionMap["default_subcluster"] = hostVersionMap{ "192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0", "192.168.0.103": "Vertica Analytic Database v24.1.0", } - op.SCToHostVersionMap["sc1"] = HostVersionMap{ + op.SCToHostVersionMap["sc1"] = hostVersionMap{ "192.168.0.104": "Vertica Analytic Database v23.4.0", "192.168.0.105": "Vertica Analytic Database v23.4.0", "192.168.0.106": "Vertica Analytic Database v23.4.0", } - op.SCToHostVersionMap["sc2"] = HostVersionMap{ + op.SCToHostVersionMap["sc2"] = hostVersionMap{ "192.168.0.107": "Vertica Analytic Database v23.3.0", "192.168.0.108": "Vertica Analytic Database v23.3.0", "192.168.0.109": "Vertica Analytic Database v23.3.0", @@ -74,17 +74,17 @@ func TestLogCheckVersionMatch(t *testing.T) { assert.NoError(t, err) // negative test 1 op.SCToHostVersionMap = makeSCToHostVersionMap() - op.SCToHostVersionMap["default_subcluster"] = HostVersionMap{ + op.SCToHostVersionMap["default_subcluster"] = hostVersionMap{ "192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0", "192.168.0.103": "Vertica Analytic Database v24.1.0", } - op.SCToHostVersionMap["sc1"] = HostVersionMap{ + op.SCToHostVersionMap["sc1"] = hostVersionMap{ "192.168.0.104": "Vertica Analytic Database v23.4.0", "192.168.0.105": "Vertica Analytic Database v23.4.0", "192.168.0.106": "Vertica Analytic Database v23.4.0", } - op.SCToHostVersionMap["sc2"] = HostVersionMap{ + op.SCToHostVersionMap["sc2"] = hostVersionMap{ "192.168.0.107": "Vertica Analytic Database v23.4.0", "192.168.0.108": "Vertica Analytic Database v23.3.0", "192.168.0.109": "Vertica Analytic Database v23.4.0", @@ -101,12 +101,12 @@ func TestLogCheckVersionMatch(t *testing.T) { // case 3: no version found in the nodes // no version found for one node op.SCToHostVersionMap = makeSCToHostVersionMap() - op.SCToHostVersionMap["default_subcluster"] = HostVersionMap{ + op.SCToHostVersionMap["default_subcluster"] = hostVersionMap{ "192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0", "192.168.0.103": "", } - op.SCToHostVersionMap["sc1"] = HostVersionMap{ + op.SCToHostVersionMap["sc1"] = hostVersionMap{ "192.168.0.104": "Vertica Analytic Database v23.4.0", "192.168.0.105": "Vertica Analytic Database v23.4.0", "192.168.0.106": "Vertica Analytic Database v23.4.0", @@ -115,12 +115,12 @@ func TestLogCheckVersionMatch(t *testing.T) { assert.ErrorContains(t, err, "No version collected for host [192.168.0.103] in subcluster [default_subcluster]") // no version found for all the nodes in a subcluster op.SCToHostVersionMap = makeSCToHostVersionMap() - op.SCToHostVersionMap["default_subcluster"] = HostVersionMap{ + op.SCToHostVersionMap["default_subcluster"] = hostVersionMap{ "192.168.0.101": "Vertica Analytic Database v24.1.0", "192.168.0.102": "Vertica Analytic Database v24.1.0", "192.168.0.103": "Vertica Analytic Database v24.1.0", } - op.SCToHostVersionMap["sc1"] = HostVersionMap{} + op.SCToHostVersionMap["sc1"] = hostVersionMap{} err = op.logCheckVersionMatch() assert.ErrorContains(t, err, "No version collected for all hosts in subcluster [sc1]") } diff --git a/vclusterops/node_info.go b/vclusterops/node_info.go index 41cf5de..8aafc76 100644 --- a/vclusterops/node_info.go +++ b/vclusterops/node_info.go @@ -26,17 +26,17 @@ type NodeInfo struct { CatalogPath string `json:"catalog_path"` } -type NodesInfo struct { +type nodesInfo struct { NodeList []NodeInfo `json:"node_list"` } // findHosts looks for hosts in a list of NodesInfo. // If found, return true; if not found, return false. -func (nodesInfo *NodesInfo) findHosts(hosts []string) bool { +func (info *nodesInfo) findHosts(hosts []string) bool { inputHostSet := mapset.NewSet(hosts...) nodeAddrSet := mapset.NewSet[string]() - for _, n := range nodesInfo.NodeList { + for _, n := range info.NodeList { nodeAddrSet.Add(n.Address) } diff --git a/vclusterops/node_info_test.go b/vclusterops/node_info_test.go index 163977f..55a0462 100644 --- a/vclusterops/node_info_test.go +++ b/vclusterops/node_info_test.go @@ -23,31 +23,31 @@ import ( ) func TestFindHosts(t *testing.T) { - var nodesInfo NodesInfo + var nodesInformation nodesInfo for i := 1; i <= 3; i++ { var n NodeInfo n.Address = fmt.Sprintf("vnode%d", i) - nodesInfo.NodeList = append(nodesInfo.NodeList, n) + nodesInformation.NodeList = append(nodesInformation.NodeList, n) } // positive case: single input - found := nodesInfo.findHosts([]string{"vnode3"}) + found := nodesInformation.findHosts([]string{"vnode3"}) assert.True(t, found) // positive case: input multiple hosts - found = nodesInfo.findHosts([]string{"vnode3", "vnode4"}) + found = nodesInformation.findHosts([]string{"vnode3", "vnode4"}) assert.True(t, found) // negative case - found = nodesInfo.findHosts([]string{"vnode4"}) + found = nodesInformation.findHosts([]string{"vnode4"}) assert.False(t, found) // negative case: input multiple hosts - found = nodesInfo.findHosts([]string{"vnode4", "vnode5"}) + found = nodesInformation.findHosts([]string{"vnode4", "vnode5"}) assert.False(t, found) // negative case: empty input - found = nodesInfo.findHosts([]string{}) + found = nodesInformation.findHosts([]string{}) assert.False(t, found) } diff --git a/vclusterops/re_ip.go b/vclusterops/re_ip.go index 3652279..26809de 100644 --- a/vclusterops/re_ip.go +++ b/vclusterops/re_ip.go @@ -29,7 +29,7 @@ type VReIPOptions struct { DatabaseOptions // re-ip list - ReIPList []ReIPInfo + ReIPList []reIPInfo /* hidden option */ @@ -152,7 +152,7 @@ func (vcc *VClusterCommands) VReIP(options *VReIPOptions) error { } // create a VClusterOpEngine, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // give the instructions to the VClusterOpEngine to run @@ -170,8 +170,8 @@ func (vcc *VClusterCommands) VReIP(options *VReIPOptions) error { // - Read database info from catalog editor // (now we should know which hosts have the latest catalog) // - Run re-ip on the target nodes -func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceReIPInstructions(options *VReIPOptions, vdb *VCoordinationDatabase) ([]clusterOp, error) { + var instructions []clusterOp if len(options.ReIPList) == 0 { return instructions, errors.New("the re-ip information is not provided") @@ -274,7 +274,7 @@ func (opt *VReIPOptions) ReadReIPFile(path string) error { ipv6 := opt.Ipv6.ToBool() for _, row := range reIPRows { - var info ReIPInfo + var info reIPInfo info.NodeAddress = row.CurrentAddress if e := addressCheck(row.CurrentAddress, ipv6); e != nil { return e diff --git a/vclusterops/re_ip_test.go b/vclusterops/re_ip_test.go index d90c21f..fab06bb 100644 --- a/vclusterops/re_ip_test.go +++ b/vclusterops/re_ip_test.go @@ -39,7 +39,7 @@ func TestReIPOptions(t *testing.T) { err = opt.validateAnalyzeOptions(vlog.Printer{}) assert.ErrorContains(t, err, "the re-ip list is not provided") - var info ReIPInfo + var info reIPInfo info.NodeAddress = "192.168.1.102" info.TargetAddress = "192.168.1.103" opt.ReIPList = append(opt.ReIPList, info) @@ -73,27 +73,27 @@ func TestReadReIPFile(t *testing.T) { func TestTrimReIPList(t *testing.T) { // build a stub exec context log := vlog.Printer{} - var op NMAReIPOp + var op nmaReIPOp execContext := makeOpEngineExecContext(log) // build a stub NmaVDatabase - nmaVDatabase := NmaVDatabase{} + nmaVDB := nmaVDatabase{} for i := 0; i < 3; i++ { - vnode := NmaVNode{} + vnode := nmaVNode{} vnode.Address = fmt.Sprintf("vnode%d", i+1) vnode.Name = fmt.Sprintf("v_%s_node000%d", dbName, i+1) - nmaVDatabase.Nodes = append(nmaVDatabase.Nodes, vnode) + nmaVDB.Nodes = append(nmaVDB.Nodes, vnode) } - execContext.nmaVDatabase = nmaVDatabase + execContext.nmaVDatabase = nmaVDB // build a stub re-ip list // which has an extra node compared to the actual NmaVDatabase for i := 0; i < 4; i++ { - var reIPInfo ReIPInfo - reIPInfo.NodeName = fmt.Sprintf("v_%s_node000%d", dbName, i+1) - reIPInfo.NodeAddress = fmt.Sprintf("vnode%d", i+1) - reIPInfo.TargetAddress = fmt.Sprintf("vnode_new_%d", i+1) - op.reIPList = append(op.reIPList, reIPInfo) + var info reIPInfo + info.NodeName = fmt.Sprintf("v_%s_node000%d", dbName, i+1) + info.NodeAddress = fmt.Sprintf("vnode%d", i+1) + info.TargetAddress = fmt.Sprintf("vnode_new_%d", i+1) + op.reIPList = append(op.reIPList, info) } // re-ip list before trimming diff --git a/vclusterops/remove_node.go b/vclusterops/remove_node.go index dace2e8..5fb4ae0 100644 --- a/vclusterops/remove_node.go +++ b/vclusterops/remove_node.go @@ -171,7 +171,7 @@ func (vcc *VClusterCommands) VRemoveNode(options *VRemoveNodeOptions) (VCoordina remainingHosts := util.SliceDiff(vdb.HostList, options.HostsToRemove) - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) if runError := clusterOpEngine.run(vcc.Log); runError != nil { // If the machines of the to-be-removed nodes crashed or get killed, @@ -228,7 +228,7 @@ func (o *VRemoveNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) erro vdb.DepotPrefix = *o.DepotPrefix hostNodeMap := makeVHostNodeMap() // we set the depot path manually because there is not yet an https endpoint for - // that(VER-88122). This is useful for NMADeleteDirectoriesOp. + // that(VER-88122). This is useful for nmaDeleteDirectoriesOp. for h, vnode := range vdb.HostNodeMap { vnode.DepotPath = vdb.genDepotPath(vnode.Name) hostNodeMap[h] = vnode @@ -251,8 +251,8 @@ func (o *VRemoveNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) erro // - Reload spread // - Delete catalog and data directories // - Sync catalog (eon only) -func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDatabase, options *VRemoveNodeOptions) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDatabase, options *VRemoveNodeOptions) ([]clusterOp, error) { + var instructions []clusterOp var initiatorHost []string initiatorHost = append(initiatorHost, options.Initiator) @@ -296,13 +296,13 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat } instructions = append(instructions, &httpsPollSubscriptionStateOp) } else { - var httpsRebalanceClusterOp HTTPSRebalanceClusterOp - httpsRebalanceClusterOp, err = makeHTTPSRebalanceClusterOp(vcc.Log, initiatorHost, usePassword, username, + var httpsRBCOp httpsRebalanceClusterOp + httpsRBCOp, err = makeHTTPSRebalanceClusterOp(vcc.Log, initiatorHost, usePassword, username, password) if err != nil { return instructions, err } - instructions = append(instructions, &httpsRebalanceClusterOp) + instructions = append(instructions, &httpsRBCOp) } // only remove secondary nodes from spread @@ -344,7 +344,7 @@ func (vcc *VClusterCommands) produceRemoveNodeInstructions(vdb *VCoordinationDat // produceMarkEphemeralNodeOps gets a slice of target hosts and for each of them // produces an HTTPSMarkEphemeralNodeOp. -func (vcc *VClusterCommands) 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 { @@ -360,7 +360,7 @@ func (vcc *VClusterCommands) produceMarkEphemeralNodeOps(instructions *[]Cluster // produceRebalanceSubclusterShardsOps gets a slice of subclusters and for each of them // produces an HTTPSRebalanceSubclusterShardsOp. -func (vcc *VClusterCommands) 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(vcc.Log, @@ -376,7 +376,7 @@ func (vcc *VClusterCommands) produceRebalanceSubclusterShardsOps(instructions *[ // produceDropNodeOps produces an HTTPSDropNodeOp for each node to drop. // This is because we must drop node one by one to avoid losing quorum. -func (vcc *VClusterCommands) 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 { @@ -393,7 +393,7 @@ func (vcc *VClusterCommands) produceDropNodeOps(instructions *[]ClusterOp, targe // produceSpreadRemoveNodeOp calls HTTPSSpreadRemoveNodeOp // when there is at least one secondary node to remove -func (vcc *VClusterCommands) 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 @@ -444,14 +444,14 @@ func (vcc *VClusterCommands) findRemovedNodesInCatalog(options *VRemoveNodeOptio fetchNodeStateOpt.Password = options.Password *fetchNodeStateOpt.HonorUserInput = true - var nodesInfo NodesInfo + var nodesInformation nodesInfo res, err := vcc.VFetchNodeState(&fetchNodeStateOpt) if err != nil { vcc.Log.PrintWarning("Fail to fetch states of the nodes, detail: %v", err) return false } - nodesInfo.NodeList = res + nodesInformation.NodeList = res // return true if the target (to-be-removed) nodes are still in catalog - return nodesInfo.findHosts(options.HostsToRemove) + return nodesInformation.findHosts(options.HostsToRemove) } diff --git a/vclusterops/remove_subcluster.go b/vclusterops/remove_subcluster.go index f710fcb..ee40588 100644 --- a/vclusterops/remove_subcluster.go +++ b/vclusterops/remove_subcluster.go @@ -166,11 +166,11 @@ func (vcc *VClusterCommands) VRemoveSubcluster(removeScOpt *VRemoveScOptions) (V return vdb, nil } -type RemoveDefaultSubclusterError struct { +type removeDefaultSubclusterError struct { Name string } -func (e *RemoveDefaultSubclusterError) Error() string { +func (e *removeDefaultSubclusterError) Error() string { return fmt.Sprintf("cannot remove the default subcluster '%s'", e.Name) } @@ -207,12 +207,12 @@ func (vcc *VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, option preCheckErrMsg, err) } - var instructions []ClusterOp + var instructions []clusterOp instructions = append(instructions, &httpsFindSubclusterOp, ) - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) err = clusterOpEngine.run(vcc.Log) if err != nil { @@ -227,7 +227,7 @@ func (vcc *VClusterCommands) removeScPreCheck(vdb *VCoordinationDatabase, option // the default subcluster should not be removed if *options.SubclusterToRemove == clusterOpEngine.execContext.defaultSCName { - return hostsToRemove, &RemoveDefaultSubclusterError{Name: *options.SubclusterToRemove} + return hostsToRemove, &removeDefaultSubclusterError{Name: *options.SubclusterToRemove} } // get nodes of the to-be-removed subcluster @@ -259,10 +259,10 @@ func (vcc *VClusterCommands) dropSubcluster(vdb *VCoordinationDatabase, options return err } - var instructions []ClusterOp + var instructions []clusterOp instructions = append(instructions, &httpsDropScOp) - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) err = clusterOpEngine.run(vcc.Log) if err != nil { diff --git a/vclusterops/revive_db.go b/vclusterops/revive_db.go index 3b6b04f..0db4ac5 100644 --- a/vclusterops/revive_db.go +++ b/vclusterops/revive_db.go @@ -128,7 +128,7 @@ func (vcc *VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (d } // generate clusterOpEngine certs - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} // feed the pre-revive db instructions to the VClusterOpEngine clusterOpEngine := makeClusterOpEngine(preReviveDBInstructions, &certs) err = clusterOpEngine.run(vcc.Log) @@ -168,12 +168,12 @@ func (vcc *VClusterCommands) VReviveDatabase(options *VReviveDatabaseOptions) (d // - Check any DB running on the hosts // - Download and read the description file from communal storage on the initiator func (vcc *VClusterCommands) producePreReviveDBInstructions(options *VReviveDatabaseOptions, - vdb *VCoordinationDatabase) ([]ClusterOp, error) { - var instructions []ClusterOp + vdb *VCoordinationDatabase) ([]clusterOp, error) { + var instructions []clusterOp nmaHealthOp := makeNMAHealthOp(vcc.Log, options.Hosts) - checkDBRunningOp, err := makeHTTPCheckRunningDBOp(vcc.Log, options.Hosts, false, /*use password auth*/ + checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(vcc.Log, options.Hosts, false, /*use password auth*/ "" /*username for https call*/, nil /*password for https call*/, ReviveDB) if err != nil { return instructions, err @@ -201,8 +201,8 @@ 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 (vcc *VClusterCommands) produceReviveDBInstructions(options *VReviveDatabaseOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceReviveDBInstructions(options *VReviveDatabaseOptions, vdb *VCoordinationDatabase) ([]clusterOp, error) { + var instructions []clusterOp newVDB, oldHosts, err := options.generateReviveVDB(vdb) if err != nil { diff --git a/vclusterops/scrutinize.go b/vclusterops/scrutinize.go index a6a6e43..91a1f60 100644 --- a/vclusterops/scrutinize.go +++ b/vclusterops/scrutinize.go @@ -199,7 +199,7 @@ func (options *VScrutinizeOptions) getVDBForScrutinize(logger vlog.Printer, vdb *VCoordinationDatabase) error { // get nodes where NMA is running and only use those for NMA ops nmaGetHealthyNodesOp := makeNMAGetHealthyNodesOp(logger, options.Hosts, vdb) - err := options.runClusterOpEngine(logger, []ClusterOp{&nmaGetHealthyNodesOp}) + err := options.runClusterOpEngine(logger, []clusterOp{&nmaGetHealthyNodesOp}) if err != nil { return err } @@ -207,7 +207,7 @@ func (options *VScrutinizeOptions) getVDBForScrutinize(logger vlog.Printer, // get map of host to node name and fully qualified catalog path nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(logger, vdb.HostList, *options.DBName, *options.CatalogPrefix, true /* ignore internal errors */, vdb) - err = options.runClusterOpEngine(logger, []ClusterOp{&nmaGetNodesInfoOp}) + err = options.runClusterOpEngine(logger, []clusterOp{&nmaGetNodesInfoOp}) if err != nil { return err } @@ -241,7 +241,7 @@ func (options *VScrutinizeOptions) getVDBForScrutinize(logger vlog.Printer, // - TODO (If applicable) Poll for system table staging completion on task node // - TODO (If applicable) Tar and retrieve system tables from task node (batch system_tables) func (vcc *VClusterCommands) produceScrutinizeInstructions(options *VScrutinizeOptions, - vdb *VCoordinationDatabase) (instructions []ClusterOp, err error) { + vdb *VCoordinationDatabase) (instructions []clusterOp, err error) { // extract needed info from vdb hostNodeNameMap, hostCatPathMap, err := getNodeInfoForScrutinize(options.Hosts, vdb) if err != nil { diff --git a/vclusterops/scrutinize_op.go b/vclusterops/scrutinize_op.go index 5642f3b..e4f8e4f 100644 --- a/vclusterops/scrutinize_op.go +++ b/vclusterops/scrutinize_op.go @@ -23,10 +23,10 @@ import ( // top level handler for scrutinize operations const scrutinizeURLPrefix = "scrutinize/" -// ScrutinizeOpBase, in addition to embedding the standard OpBase, wraps some +// scrutinizeOpBase, in addition to embedding the standard OpBase, wraps some // common data and functionality for scrutinize-specific ops -type ScrutinizeOpBase struct { - OpBase +type scrutinizeOpBase struct { + opBase id string batch string urlSuffix string @@ -36,11 +36,11 @@ type ScrutinizeOpBase struct { hostRequestBodyMap map[string]string // should be nil if not used } -func (op *ScrutinizeOpBase) setupClusterHTTPRequest(hosts []string) error { +func (op *scrutinizeOpBase) setupClusterHTTPRequest(hosts []string) error { for _, host := range hosts { nodeName := op.hostNodeNameMap[host] - httpRequest := HostHTTPRequest{} + httpRequest := hostHTTPRequest{} httpRequest.Method = op.httpMethod httpRequest.buildNMAEndpoint(scrutinizeURLPrefix + op.id + "/" + nodeName + "/" + op.batch + op.urlSuffix) if op.hostRequestBodyMap != nil { @@ -54,7 +54,7 @@ func (op *ScrutinizeOpBase) setupClusterHTTPRequest(hosts []string) error { // processeStagedFilesResult is a parameterized function which contains common logic // for processing the results of staging various types of files, e.g. vertica.log -func processStagedFilesResult[T any](op *ScrutinizeOpBase, fileList []T) error { +func processStagedFilesResult[T any](op *scrutinizeOpBase, fileList []T) error { var allErrs error for host, result := range op.clusterHTTPRequest.ResultCollection { diff --git a/vclusterops/start_db.go b/vclusterops/start_db.go index b68de54..8204a2b 100644 --- a/vclusterops/start_db.go +++ b/vclusterops/start_db.go @@ -172,7 +172,7 @@ func (vcc *VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) erro } // create a VClusterOpEngine for start_db instructions, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run @@ -192,7 +192,7 @@ func (vcc *VClusterCommands) runStartDBPrecheck(options *VStartDatabaseOptions, } // create a VClusterOpEngine for pre-check, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(preInstructions, &certs) runError := clusterOpEngine.run(vcc.Log) if runError != nil { @@ -231,8 +231,8 @@ func (vcc *VClusterCommands) runStartDBPrecheck(options *VStartDatabaseOptions, // - Check NMA connectivity // - Check to see if any dbs run // - Get nodes' information by calling the NMA /nodes endpoint -func (vcc *VClusterCommands) produceStartDBPreCheck(options *VStartDatabaseOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceStartDBPreCheck(options *VStartDatabaseOptions, vdb *VCoordinationDatabase) ([]clusterOp, error) { + var instructions []clusterOp nmaHealthOp := makeNMAHealthOp(vcc.Log, options.Hosts) // need username for https operations @@ -241,7 +241,7 @@ func (vcc *VClusterCommands) produceStartDBPreCheck(options *VStartDatabaseOptio return instructions, err } - checkDBRunningOp, err := makeHTTPCheckRunningDBOp(vcc.Log, options.Hosts, + checkDBRunningOp, err := makeHTTPSCheckRunningDBOp(vcc.Log, options.Hosts, options.usePassword, *options.UserName, options.Password, StartDB) if err != nil { return instructions, err @@ -272,8 +272,8 @@ func (vcc *VClusterCommands) produceStartDBPreCheck(options *VStartDatabaseOptio // - Start all nodes of the database // - Poll node startup // - Sync catalog (Eon mode only) -func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseOptions, vdb *VCoordinationDatabase) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseOptions, vdb *VCoordinationDatabase) ([]clusterOp, error) { + var instructions []clusterOp // vdb here should contains only primary nodes nmaReadCatalogEditorOp, err := makeNMAReadCatalogEditorOp(vcc.Log, vdb) @@ -326,7 +326,7 @@ func (vcc *VClusterCommands) produceStartDBInstructions(options *VStartDatabaseO return instructions, nil } -func (vcc *VClusterCommands) setOrRotateEncryptionKey(keyType string) ClusterOp { +func (vcc *VClusterCommands) setOrRotateEncryptionKey(keyType string) clusterOp { vcc.Log.Info("adding instruction to set or rotate the key for spread encryption") op := makeNMASpreadSecurityOp(vcc.Log, keyType) return &op diff --git a/vclusterops/restart_node.go b/vclusterops/start_node.go similarity index 77% rename from vclusterops/restart_node.go rename to vclusterops/start_node.go index 282b467..b85b08a 100644 --- a/vclusterops/restart_node.go +++ b/vclusterops/start_node.go @@ -23,39 +23,39 @@ import ( ) // Normal strings are easier and safer to use in Go. -type VRestartNodesOptions struct { +type VStartNodesOptions struct { // basic db info DatabaseOptions - // A set of nodes(nodename - host) that we want to restart in the database + // A set of nodes(nodename - host) that we want to start in the database Nodes map[string]string - // timeout for polling nodes that we want to restart in HTTPSPollNodeStateOp + // timeout for polling nodes that we want to start in httpsPollNodeStateOp StatePollingTimeout int } -type VRestartNodesInfo struct { +type VStartNodesInfo struct { // The IP address that we intend to re-IP can be obtained from a set of nodes provided as input - // within VRestartNodesOptions struct + // within VStartNodesOptions struct ReIPList []string - // The node names that we intend to restart can be acquired from a set of nodes provided as input - // within the VRestartNodesOptions struct - NodeNamesToRestart []string - // the hosts that we want to restart - HostsToRestart []string + // The node names that we intend to start can be acquired from a set of nodes provided as input + // within the VStartNodesOptions struct + NodeNamesToStart []string + // the hosts that we want to start + HostsToStart []string } -func VRestartNodesOptionsFactory() VRestartNodesOptions { - opt := VRestartNodesOptions{} +func VStartNodesOptionsFactory() VStartNodesOptions { + opt := VStartNodesOptions{} // set default values to the params opt.setDefaultValues() return opt } -func (options *VRestartNodesOptions) setDefaultValues() { +func (options *VStartNodesOptions) setDefaultValues() { options.DatabaseOptions.setDefaultValues() } -func (options *VRestartNodesOptions) validateRequiredOptions(logger vlog.Printer) error { +func (options *VStartNodesOptions) validateRequiredOptions(logger vlog.Printer) error { err := options.validateBaseOptions("restart_node", logger) if err != nil { return err @@ -67,12 +67,12 @@ func (options *VRestartNodesOptions) validateRequiredOptions(logger vlog.Printer return nil } -func (options *VRestartNodesOptions) validateParseOptions(logger vlog.Printer) error { +func (options *VStartNodesOptions) validateParseOptions(logger vlog.Printer) error { return options.validateRequiredOptions(logger) } // analyzeOptions will modify some options based on what is chosen -func (options *VRestartNodesOptions) analyzeOptions() (err error) { +func (options *VStartNodesOptions) analyzeOptions() (err error) { // we analyze host names when HonorUserInput is set, otherwise we use hosts in yaml config if *options.HonorUserInput { // resolve RawHosts to be IP addresses @@ -86,7 +86,7 @@ func (options *VRestartNodesOptions) analyzeOptions() (err error) { // ParseNodesList builds and returns a map from a comma-separated list of nodes. // Ex: vnodeName1=host1,vnodeName2=host2 ---> map[string]string{vnodeName1: host1, vnodeName2: host2} -func (options *VRestartNodesOptions) ParseNodesList(nodeListStr string) error { +func (options *VStartNodesOptions) ParseNodesList(nodeListStr string) error { nodes, err := util.ParseKeyValueListStr(nodeListStr, "restart") if err != nil { return err @@ -102,17 +102,17 @@ func (options *VRestartNodesOptions) ParseNodesList(nodeListStr string) error { return nil } -func (options *VRestartNodesOptions) validateAnalyzeOptions(logger vlog.Printer) error { +func (options *VStartNodesOptions) validateAnalyzeOptions(logger vlog.Printer) error { if err := options.validateParseOptions(logger); err != nil { return err } return options.analyzeOptions() } -// VRestartNodes will restart the given nodes for a cluster that hasn't yet lost +// VStartNodes will start the given nodes for a cluster that has not yet lost // cluster quorum. This will handle updating of the nodes IP in the vertica // catalog if necessary. Use VStartDatabase if cluster quorum is lost. -func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error { +func (vcc *VClusterCommands) VStartNodes(options *VStartNodesOptions) error { /* * - Produce Instructions * - Create a VClusterOpEngine @@ -148,7 +148,7 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error var hostsNoNeedToReIP []string hostNodeNameMap := make(map[string]string) - restartNodeInfo := new(VRestartNodesInfo) + restartNodeInfo := new(VStartNodesInfo) for _, vnode := range vdb.HostNodeMap { hostNodeNameMap[vnode.Name] = vnode.Address } @@ -161,8 +161,8 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error // if the IP that is given is different than the IP in the catalog, a re-ip is necessary if oldIP != newIP { restartNodeInfo.ReIPList = append(restartNodeInfo.ReIPList, newIP) - restartNodeInfo.NodeNamesToRestart = append(restartNodeInfo.NodeNamesToRestart, nodename) - vcc.Log.Info("the nodes need to be re-IP", "nodeNames", restartNodeInfo.NodeNamesToRestart, "IPs", restartNodeInfo.ReIPList) + restartNodeInfo.NodeNamesToStart = append(restartNodeInfo.NodeNamesToStart, nodename) + vcc.Log.Info("the nodes need to be re-IP", "nodeNames", restartNodeInfo.NodeNamesToStart, "IPs", restartNodeInfo.ReIPList) } else { // otherwise, we don't need to re-ip hostsNoNeedToReIP = append(hostsNoNeedToReIP, newIP) @@ -170,17 +170,17 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error } // we can proceed to restart both nodes with and without IP changes - restartNodeInfo.HostsToRestart = append(restartNodeInfo.HostsToRestart, restartNodeInfo.ReIPList...) - restartNodeInfo.HostsToRestart = append(restartNodeInfo.HostsToRestart, hostsNoNeedToReIP...) + restartNodeInfo.HostsToStart = append(restartNodeInfo.HostsToStart, restartNodeInfo.ReIPList...) + restartNodeInfo.HostsToStart = append(restartNodeInfo.HostsToStart, hostsNoNeedToReIP...) // produce restart_node instructions - instructions, err := vcc.produceRestartNodesInstructions(restartNodeInfo, options, &vdb) + instructions, err := vcc.produceStartNodesInstructions(restartNodeInfo, options, &vdb) if err != nil { return fmt.Errorf("fail to produce instructions, %w", err) } // create a VClusterOpEngine, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run @@ -191,7 +191,7 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error return nil } -// produceRestartNodesInstructions will build a list of instructions to execute for +// produceStartNodesInstructions will build a list of instructions to execute for // the restart_node command. // // The generated instructions will later perform the following operations necessary @@ -210,9 +210,9 @@ func (vcc *VClusterCommands) VRestartNodes(options *VRestartNodesOptions) error // - restart nodes // - Poll node start up // - sync catalog -func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VRestartNodesInfo, options *VRestartNodesOptions, - vdb *VCoordinationDatabase) ([]ClusterOp, error) { - var instructions []ClusterOp +func (vcc *VClusterCommands) produceStartNodesInstructions(startNodeInfo *VStartNodesInfo, options *VStartNodesOptions, + vdb *VCoordinationDatabase) ([]clusterOp, error) { + var instructions []clusterOp nmaHealthOp := makeNMAHealthOp(vcc.Log, options.Hosts) // need username for https operations @@ -233,9 +233,9 @@ 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(vcc.Log, restartNodeInfo.ReIPList) - httpsReIPOp, e := makeHTTPSReIPOp(restartNodeInfo.NodeNamesToRestart, restartNodeInfo.ReIPList, + if len(startNodeInfo.ReIPList) != 0 { + nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, startNodeInfo.ReIPList) + httpsReIPOp, e := makeHTTPSReIPOp(startNodeInfo.NodeNamesToStart, startNodeInfo.ReIPList, options.usePassword, *options.UserName, options.Password) if e != nil { return instructions, e @@ -271,16 +271,16 @@ func (vcc *VClusterCommands) produceRestartNodesInstructions(restartNodeInfo *VR produceTransferConfigOps(vcc.Log, &instructions, nil, /*source hosts for transferring configuration files*/ - restartNodeInfo.HostsToRestart, + startNodeInfo.HostsToStart, vdb) httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(vcc.Log, options.usePassword, *options.UserName, options.Password, vdb) if err != nil { return instructions, err } - nmaRestartNewNodesOp := makeNMAStartNodeOpWithVDB(vcc.Log, restartNodeInfo.HostsToRestart, vdb) - httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(vcc.Log, restartNodeInfo.HostsToRestart, - options.usePassword, *options.UserName, options.Password, options.StatePollingTimeout, RestartNodeCmd) + nmaRestartNewNodesOp := makeNMAStartNodeOpWithVDB(vcc.Log, startNodeInfo.HostsToStart, vdb) + httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOpWithTimeoutAndCommand(vcc.Log, startNodeInfo.HostsToStart, + options.usePassword, *options.UserName, options.Password, options.StatePollingTimeout, StartNodeCmd) if err != nil { return instructions, err } diff --git a/vclusterops/state_poller.go b/vclusterops/state_poller.go index ec9684e..4dfe37a 100644 --- a/vclusterops/state_poller.go +++ b/vclusterops/state_poller.go @@ -28,14 +28,14 @@ const ( PollingInterval = 3 * OneSecond ) -type StatePoller interface { +type statePoller interface { getPollingTimeout() int shouldStopPolling() (bool, error) - runExecute(execContext *OpEngineExecContext) error + runExecute(execContext *opEngineExecContext) error } -// pollState is a helper function to poll state for all ops that implement the StatePoller interface -func pollState(poller StatePoller, execContext *OpEngineExecContext) error { +// pollState is a helper function to poll state for all ops that implement the statePoller interface +func pollState(poller statePoller, execContext *opEngineExecContext) error { startTime := time.Now() timeout := poller.getPollingTimeout() duration := time.Duration(timeout) * time.Second diff --git a/vclusterops/stop_db.go b/vclusterops/stop_db.go index 72602a0..fc7d673 100644 --- a/vclusterops/stop_db.go +++ b/vclusterops/stop_db.go @@ -166,7 +166,7 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error } // Create a VClusterOpEngine, and add certs to the engine - certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} + certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run @@ -189,8 +189,8 @@ func (vcc *VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error // - Check there is not any database running func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabaseInfo, options *VStopDatabaseOptions, -) ([]ClusterOp, error) { - var instructions []ClusterOp +) ([]clusterOp, error) { + var instructions []clusterOp // when password is specified, we will use username/password to call https endpoints usePassword := false @@ -224,7 +224,7 @@ func (vcc *VClusterCommands) produceStopDBInstructions(stopDBInfo *VStopDatabase return instructions, err } - httpsCheckDBRunningOp, err := makeHTTPCheckRunningDBOp(vcc.Log, stopDBInfo.Hosts, + httpsCheckDBRunningOp, err := makeHTTPSCheckRunningDBOp(vcc.Log, stopDBInfo.Hosts, usePassword, *options.UserName, stopDBInfo.Password, StopDB) if err != nil { return instructions, err diff --git a/vclusterops/vcluster_database_options.go b/vclusterops/vcluster_database_options.go index 4d2507f..ed119fd 100644 --- a/vclusterops/vcluster_database_options.go +++ b/vclusterops/vcluster_database_options.go @@ -447,7 +447,7 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown(vcc *VClusterCommands) (vdb VCoor // step 1: get node names by calling NMA /nodes on input hosts // this step can map input hosts with node names vdb1 := VCoordinationDatabase{} - var instructions1 []ClusterOp + var instructions1 []clusterOp nmaHealthOp := makeNMAHealthOp(vcc.Log, opt.Hosts) nmaGetNodesInfoOp := makeNMAGetNodesInfoOp(vcc.Log, opt.Hosts, *opt.DBName, *opt.CatalogPrefix, false /* report all errors */, &vdb1) @@ -456,7 +456,7 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown(vcc *VClusterCommands) (vdb VCoor &nmaGetNodesInfoOp, ) - certs := HTTPSCerts{key: opt.Key, cert: opt.Cert, caCert: opt.CaCert} + certs := httpsCerts{key: opt.Key, cert: opt.Cert, caCert: opt.CaCert} clusterOpEngine := makeClusterOpEngine(instructions1, &certs) err = clusterOpEngine.run(vcc.Log) if err != nil { @@ -466,7 +466,7 @@ func (opt *DatabaseOptions) getVDBWhenDBIsDown(vcc *VClusterCommands) (vdb VCoor // step 2: get node details from cluster_config.json vdb2 := VCoordinationDatabase{} - var instructions2 []ClusterOp + var instructions2 []clusterOp sourceFilePath := opt.getDescriptionFilePath() nmaDownLoadFileOp, err := makeNMADownloadFileOp(vcc.Log, opt.Hosts, sourceFilePath, destinationFilePath, catalogPath, opt.ConfigurationParameters, &vdb2) @@ -534,9 +534,9 @@ func (opt *DatabaseOptions) isSpreadEncryptionEnabled() (enabled bool, encryptio return false, "" } -func (opt *DatabaseOptions) runClusterOpEngine(log vlog.Printer, instructions []ClusterOp) error { +func (opt *DatabaseOptions) runClusterOpEngine(log vlog.Printer, instructions []clusterOp) error { // Create a VClusterOpEngine, and add certs to the engine - certs := HTTPSCerts{key: opt.Key, cert: opt.Cert, caCert: opt.CaCert} + certs := httpsCerts{key: opt.Key, cert: opt.Cert, caCert: opt.CaCert} clusterOpEngine := makeClusterOpEngine(instructions, &certs) // Give the instructions to the VClusterOpEngine to run diff --git a/vclusterops/vcluster_version.go b/vclusterops/vcluster_version.go index b2e211b..731054d 100644 --- a/vclusterops/vcluster_version.go +++ b/vclusterops/vcluster_version.go @@ -22,7 +22,7 @@ import ( "strings" ) -type SemVer struct { +type semVer struct { Ver string `json:"ver"` Major string `json:"-"` Minor string `json:"-"` @@ -31,28 +31,28 @@ type SemVer struct { type VclusterOpVersion struct { Origin string `json:"origin"` - SemVer SemVer + SemVer semVer } -func (semVer *SemVer) parseComponentsIfNecessary() error { - cleanSize := strings.TrimSpace(semVer.Ver) +func (semVersion *semVer) parseComponentsIfNecessary() error { + cleanSize := strings.TrimSpace(semVersion.Ver) r := regexp.MustCompile(`^(\d+)\.(\d+).(\d+)$`) matches := r.FindAllStringSubmatch(cleanSize, -1) if len(matches) != 1 { - return fmt.Errorf("parse error for version %s: It is not a valid version", semVer.Ver) + return fmt.Errorf("parse error for version %s: It is not a valid version", semVersion.Ver) } - semVer.Major = matches[0][1] - semVer.Minor = matches[0][2] - semVer.Patch = matches[0][3] + semVersion.Major = matches[0][1] + semVersion.Minor = matches[0][2] + semVersion.Patch = matches[0][3] return nil } -func (semVer *SemVer) incompatibleVersion(otherVer *SemVer) (bool, error) { - err := semVer.parseComponentsIfNecessary() +func (semVersion *semVer) incompatibleVersion(otherVer *semVer) (bool, error) { + err := semVersion.parseComponentsIfNecessary() if err != nil { return false, err } - majorStr := semVer.Major + majorStr := semVersion.Major err = otherVer.parseComponentsIfNecessary() if err != nil { return false, err @@ -61,8 +61,8 @@ func (semVer *SemVer) incompatibleVersion(otherVer *SemVer) (bool, error) { return majorStr == majorOtherVerStr, nil } -func (semVer *SemVer) equalVersion(otherVer *SemVer) bool { - return otherVer.Ver == semVer.Ver +func (semVersion *semVer) equalVersion(otherVer *semVer) bool { + return otherVer.Ver == semVersion.Ver } func (opVersion *VclusterOpVersion) equalVclusterVersion(otherVer *VclusterOpVersion) bool { @@ -70,7 +70,7 @@ func (opVersion *VclusterOpVersion) equalVclusterVersion(otherVer *VclusterOpVer } func (opVersion *VclusterOpVersion) convertVclusterVersionToJSON() (string, error) { - SemVer := &SemVer{Ver: opVersion.SemVer.Ver} + SemVer := &semVer{Ver: opVersion.SemVer.Ver} vclusterVersionData := map[string]any{ "origin": opVersion.Origin, "semver": SemVer, @@ -89,5 +89,5 @@ func vclusterVersionFromDict(vclusterVersionDict map[string]string) (VclusterOpV return VclusterOpVersion{}, fmt.Errorf("%s is missing one or more required fields", vclusterVersionDict) } } - return VclusterOpVersion{Origin: vclusterVersionDict["origin"], SemVer: SemVer{Ver: vclusterVersionDict["semver"]}}, nil + return VclusterOpVersion{Origin: vclusterVersionDict["origin"], SemVer: semVer{Ver: vclusterVersionDict["semver"]}}, nil } diff --git a/vclusterops/vcluster_version_test.go b/vclusterops/vcluster_version_test.go index 8fcf1db..979621c 100644 --- a/vclusterops/vcluster_version_test.go +++ b/vclusterops/vcluster_version_test.go @@ -23,7 +23,7 @@ import ( ) func TestForVersionEquality(t *testing.T) { - v1 := &SemVer{Ver: "1.5.3"} + v1 := &semVer{Ver: "1.5.3"} _ = v1.parseComponentsIfNecessary() assert.Equal(t, v1.Major, "1") assert.Equal(t, v1.Minor, "5") @@ -31,50 +31,50 @@ func TestForVersionEquality(t *testing.T) { } func TestForIncompatibleVersion(t *testing.T) { - v1 := &SemVer{Ver: "2.1.0"} - v2 := &SemVer{Ver: "1.9.0"} + v1 := &semVer{Ver: "2.1.0"} + v2 := &semVer{Ver: "1.9.0"} result, err := v1.incompatibleVersion(v2) assert.NoError(t, err) assert.Equal(t, result, false) } func TestForDifferentButCompatibleVersion(t *testing.T) { - v1 := &SemVer{Ver: "1.5.4"} - v2 := &SemVer{Ver: "1.5.3"} + v1 := &semVer{Ver: "1.5.4"} + v2 := &semVer{Ver: "1.5.3"} result, err := v1.incompatibleVersion(v2) assert.NoError(t, err) assert.Equal(t, result, true) } func TestForEqualVersion(t *testing.T) { - v1 := &SemVer{Ver: "1.5.3"} - v2 := &SemVer{Ver: "1.5.3"} + v1 := &semVer{Ver: "1.5.3"} + v2 := &semVer{Ver: "1.5.3"} result := v1.equalVersion(v2) assert.Equal(t, result, true) } func TestForVclusterVersionEquality(t *testing.T) { - v1 := &VclusterOpVersion{Origin: "root", SemVer: SemVer{Ver: "1.0.0"}} + v1 := &VclusterOpVersion{Origin: "root", SemVer: semVer{Ver: "1.0.0"}} assert.NotEqual(t, v1, "blah") - v2 := &VclusterOpVersion{Origin: "root", SemVer: SemVer{Ver: "1.0.1"}} + v2 := &VclusterOpVersion{Origin: "root", SemVer: semVer{Ver: "1.0.1"}} result := v1.equalVclusterVersion(v2) assert.Equal(t, result, false) - v3 := &VclusterOpVersion{Origin: "root", SemVer: SemVer{Ver: "1.0.0"}} + v3 := &VclusterOpVersion{Origin: "root", SemVer: semVer{Ver: "1.0.0"}} result = v3.equalVclusterVersion(v1) assert.Equal(t, result, true) } func TestForVclusterVersionJSON(t *testing.T) { - v1 := &VclusterOpVersion{Origin: "root", SemVer: SemVer{Ver: "1.0.0"}} + v1 := &VclusterOpVersion{Origin: "root", SemVer: semVer{Ver: "1.0.0"}} result, err := v1.convertVclusterVersionToJSON() assert.NoError(t, err) data := VclusterOpVersion{} _ = json.Unmarshal([]byte(result), &data) assert.Equal(t, data.Origin, "root") - assert.Equal(t, data.SemVer, SemVer{Ver: "1.0.0"}) + assert.Equal(t, data.SemVer, semVer{Ver: "1.0.0"}) } func TestForConvertVclusterVersionToJSONString(t *testing.T) { - v1 := &VclusterOpVersion{Origin: "root", SemVer: SemVer{Ver: "1.0.0"}} + v1 := &VclusterOpVersion{Origin: "root", SemVer: semVer{Ver: "1.0.0"}} result, err := v1.convertVclusterVersionToJSON() assert.NoError(t, err) assert.Equal(t, result, "{\"origin\":\"root\",\"semver\":{\"ver\":\"1.0.0\"}}") @@ -83,7 +83,7 @@ func TestForConvertVclusterVersionToJSONString(t *testing.T) { func TestForVclusterVersionDict(t *testing.T) { VclusterVersionDict := map[string]string{"origin": "root", "semver": "1.0.0"} v1, _ := vclusterVersionFromDict(VclusterVersionDict) - expectedVer := VclusterOpVersion{Origin: "root", SemVer: SemVer{Ver: "1.0.0"}} + expectedVer := VclusterOpVersion{Origin: "root", SemVer: semVer{Ver: "1.0.0"}} result := v1.equalVclusterVersion(&expectedVer) assert.Equal(t, result, true) // negative case - missing semver field