Skip to content

Commit

Permalink
Return command status for set-config commands
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Apr 12, 2024
1 parent b286c2d commit c7d631b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions deployment/aeroinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func SetMigrateFillDelay(log logr.Logger, policy *aero.ClientPolicy, allHosts []

// SetConfigCommandsOnHosts runs set config command for dynamic config on all the given cluster nodes
func SetConfigCommandsOnHosts(log logr.Logger, policy *aero.ClientPolicy, allHosts, selectedHosts []*HostConn,
cmds []string) error {
cmds []string) (map[string]bool, error) {
c, err := newCluster(log, policy, allHosts, selectedHosts)
if err != nil {
return fmt.Errorf("unable to create a cluster copy for running aeroinfo: %v", err)
return nil, fmt.Errorf("unable to create a cluster copy for running aeroinfo: %v", err)
}

return c.setConfigCommandsOnHosts(cmds, selectedHosts)
Expand Down
19 changes: 13 additions & 6 deletions deployment/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ func (c *cluster) setMigrateFillDelay(migrateFillDelay int, hosts []*HostConn) e

cmd := fmt.Sprintf("set-config:context=service;migrate-fill-delay=%d", migrateFillDelay)

if err := c.setConfigCommandsOnHosts([]string{cmd}, hosts); err != nil {
if _, err := c.setConfigCommandsOnHosts([]string{cmd}, hosts); err != nil {
return err
}

Expand All @@ -862,36 +862,43 @@ func (c *cluster) setMigrateFillDelay(migrateFillDelay int, hosts []*HostConn) e
}

// setConfigCommandsOnHosts runs the set-config commands on the hosts.
func (c *cluster) setConfigCommandsOnHosts(cmds []string, hosts []*HostConn) error {
func (c *cluster) setConfigCommandsOnHosts(cmds []string, hosts []*HostConn) (map[string]bool, error) {
hostIDs := getHostIDsFromHostConns(hosts)
cmdStatusMap := map[string]bool{}

log := c.log.WithValues("nodes", hostIDs)
log.V(1).Info("Running set-config")

// Run all set-config commands on all hosts
for _, cmd := range cmds {
// insert command in the status map
cmdStatusMap[cmd] = false

infoResults, iErr := c.infoOnHosts(hostIDs, cmd)
if iErr != nil {
return iErr
return cmdStatusMap, iErr
}

for id, info := range infoResults {
output, err := info.toString(cmd)
if err != nil {
return fmt.Errorf(
return cmdStatusMap, fmt.Errorf(
"ServerError: failed to execute set-config command %s on node %s: %v", cmd, id, err)
}

if !strings.EqualFold(output, "ok") {
return fmt.Errorf("ServerError: failed to execute set-config"+
return cmdStatusMap, fmt.Errorf("ServerError: failed to execute set-config"+
" command %s on node %s: %v", cmd, id, output)
}
}

// update command status in the status map
cmdStatusMap[cmd] = true
}

log.V(1).Info("Finished running set-config")

return nil
return cmdStatusMap, nil
}

func (c *cluster) findHost(hostID string) (*host, error) {
Expand Down
2 changes: 1 addition & 1 deletion test/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var PortStart = 10000
var IP = "127.0.0.1"
var WordDirAbs = "test/work"
var Image = "aerospike/aerospike-server-enterprise:7.0.0.2"
var ContainerPrefix = "aerospike_mgmt_lib_test_" //nolint:gosec // This is not a credential
var ContainerPrefix = "aerospike_mgmt_lib_test_"

Check failure on line 26 in test/containers.go

View workflow job for this annotation

GitHub Actions / lint

G101: Potential hardcoded credentials (gosec)
var User = "admin"
var Password = "admin"

Expand Down

0 comments on commit c7d631b

Please sign in to comment.