-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ad21f1
commit 530a0da
Showing
11 changed files
with
343 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
(c) Copyright [2023-2024] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package commands | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/vertica/vcluster/vclusterops" | ||
"github.com/vertica/vcluster/vclusterops/vlog" | ||
) | ||
|
||
/* CmdCheckVClusterServerPid | ||
* | ||
* Implements ClusterCommand interface | ||
*/ | ||
type CmdCheckVClusterServerPid struct { | ||
checkPidOptions *vclusterops.VCheckVClusterServerPidOptions | ||
|
||
CmdBase | ||
} | ||
|
||
func makeCmdCheckVClusterServerPid() *cobra.Command { | ||
newCmd := &CmdCheckVClusterServerPid{} | ||
opt := vclusterops.VCheckVClusterServerPidOptionsFactory() | ||
newCmd.checkPidOptions = &opt | ||
|
||
cmd := makeBasicCobraCmd( | ||
newCmd, | ||
"check_pid", | ||
"Check VCluster server PID files", | ||
`Check VCluster server PID files in nodes to make sure that | ||
only one host is running the VCluster server`, | ||
[]string{hostsFlag}, | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func (c *CmdCheckVClusterServerPid) Parse(inputArgv []string, logger vlog.Printer) error { | ||
c.argv = inputArgv | ||
logger.LogArgParse(&c.argv) | ||
|
||
return c.validateParse(logger) | ||
} | ||
|
||
func (c *CmdCheckVClusterServerPid) validateParse(logger vlog.Printer) error { | ||
logger.Info("Called validateParse()") | ||
if !c.usePassword() { | ||
err := c.getCertFilesFromCertPaths(&c.checkPidOptions.DatabaseOptions) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return c.ValidateParseBaseOptions(&c.checkPidOptions.DatabaseOptions) | ||
} | ||
|
||
func (c *CmdCheckVClusterServerPid) Run(vcc vclusterops.ClusterCommands) error { | ||
vcc.V(1).Info("Called method Run()") | ||
|
||
hostsWithVclusterServerPid, err := vcc.VCheckVClusterServerPid(c.checkPidOptions) | ||
if err != nil { | ||
vcc.LogError(err, "failed to drop the database") | ||
return err | ||
} | ||
fmt.Printf("Hosts with VCluster server PID files: %+v\n", hostsWithVclusterServerPid) | ||
|
||
return nil | ||
} | ||
|
||
func (c *CmdCheckVClusterServerPid) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) { | ||
c.checkPidOptions.DatabaseOptions = *opt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
(c) Copyright [2023-2024] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vclusterops | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vertica/vcluster/vclusterops/util" | ||
"github.com/vertica/vcluster/vclusterops/vlog" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
type VCheckVClusterServerPidOptions struct { | ||
DatabaseOptions | ||
} | ||
|
||
func VCheckVClusterServerPidOptionsFactory() VCheckVClusterServerPidOptions { | ||
options := VCheckVClusterServerPidOptions{} | ||
// set default values to the params | ||
options.setDefaultValues() | ||
|
||
return options | ||
} | ||
|
||
func (options *VCheckVClusterServerPidOptions) setDefaultValues() { | ||
options.DatabaseOptions.setDefaultValues() | ||
} | ||
|
||
func (options *VCheckVClusterServerPidOptions) analyzeOptions() (err error) { | ||
// resolve RawHosts to be IP addresses | ||
if len(options.RawHosts) > 0 { | ||
options.Hosts, err = util.ResolveRawHostsToAddresses(options.RawHosts, options.IPv6) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (options *VCheckVClusterServerPidOptions) validateAnalyzeOptions(_ vlog.Printer) error { | ||
err := options.analyzeOptions() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (vcc VClusterCommands) VCheckVClusterServerPid( | ||
options *VCheckVClusterServerPidOptions) (hostsWithVclusterServerPid []string, err error) { | ||
// validate and analyze options | ||
err = options.validateAnalyzeOptions(vcc.Log) | ||
if err != nil { | ||
return hostsWithVclusterServerPid, err | ||
} | ||
|
||
// produce instructions of checking VCluster server PID files | ||
instructions, err := vcc.produceCheckVClusterServerPidInstructions(options) | ||
if err != nil { | ||
return hostsWithVclusterServerPid, fmt.Errorf("fail to produce instructions, %w", err) | ||
} | ||
|
||
// create a VClusterOpEngine, and add certs to the engine | ||
clusterOpEngine := makeClusterOpEngine(instructions, options) | ||
|
||
// give the instructions to the VClusterOpEngine to run | ||
runError := clusterOpEngine.run(vcc.Log) | ||
if runError != nil { | ||
return hostsWithVclusterServerPid, fmt.Errorf("fail to check VCluster server PID files: %w", runError) | ||
} | ||
|
||
hostsWithVclusterServerPid = clusterOpEngine.execContext.HostsWithVclusterServerPid | ||
slices.Sort(hostsWithVclusterServerPid) | ||
|
||
return hostsWithVclusterServerPid, nil | ||
} | ||
|
||
func (vcc VClusterCommands) produceCheckVClusterServerPidInstructions(options *VCheckVClusterServerPidOptions) ([]clusterOp, error) { | ||
var instructions []clusterOp | ||
|
||
nmaHealthOp := makeNMAHealthOpSkipUnreachable(options.Hosts) | ||
|
||
nmaCheckVClusterServerPidOp := makeNMACheckVClusterServerPidOp(options.Hosts) | ||
|
||
instructions = append(instructions, &nmaHealthOp, &nmaCheckVClusterServerPidOp) | ||
return instructions, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.