From c7d631bbfa438482e875cbfb6d703086dd5b0788 Mon Sep 17 00:00:00 2001 From: Abhisek Dwivedi Date: Fri, 12 Apr 2024 09:57:41 +0530 Subject: [PATCH 1/3] Return command status for set-config commands --- deployment/aeroinfo.go | 4 ++-- deployment/cluster.go | 19 +++++++++++++------ test/containers.go | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/deployment/aeroinfo.go b/deployment/aeroinfo.go index 0157489..16f7deb 100644 --- a/deployment/aeroinfo.go +++ b/deployment/aeroinfo.go @@ -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) diff --git a/deployment/cluster.go b/deployment/cluster.go index 9370630..f2e31c5 100644 --- a/deployment/cluster.go +++ b/deployment/cluster.go @@ -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 } @@ -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) { diff --git a/test/containers.go b/test/containers.go index e0b4664..543c493 100644 --- a/test/containers.go +++ b/test/containers.go @@ -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_" var User = "admin" var Password = "admin" From 304061698847e2642e2521aa35d38bf7cea89696 Mon Sep 17 00:00:00 2001 From: Abhisek Dwivedi Date: Fri, 12 Apr 2024 14:19:25 +0530 Subject: [PATCH 2/3] revert golanci-lint changes --- test/containers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/containers.go b/test/containers.go index 543c493..e0b4664 100644 --- a/test/containers.go +++ b/test/containers.go @@ -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_" +var ContainerPrefix = "aerospike_mgmt_lib_test_" //nolint:gosec // This is not a credential var User = "admin" var Password = "admin" From e5daad1c37875cbbedfff543e20c90af557b5306 Mon Sep 17 00:00:00 2001 From: Abhisek Dwivedi Date: Fri, 12 Apr 2024 18:26:18 +0530 Subject: [PATCH 3/3] Incorporate review comments --- deployment/aeroinfo.go | 2 +- deployment/cluster.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/deployment/aeroinfo.go b/deployment/aeroinfo.go index 16f7deb..5ab0b0e 100644 --- a/deployment/aeroinfo.go +++ b/deployment/aeroinfo.go @@ -61,7 +61,7 @@ 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) (map[string]bool, error) { + cmds []string) ([]string, error) { c, err := newCluster(log, policy, allHosts, selectedHosts) if err != nil { return nil, fmt.Errorf("unable to create a cluster copy for running aeroinfo: %v", err) diff --git a/deployment/cluster.go b/deployment/cluster.go index f2e31c5..9c6c2aa 100644 --- a/deployment/cluster.go +++ b/deployment/cluster.go @@ -862,43 +862,39 @@ 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) (map[string]bool, error) { +func (c *cluster) setConfigCommandsOnHosts(cmds []string, hosts []*HostConn) ([]string, error) { hostIDs := getHostIDsFromHostConns(hosts) - cmdStatusMap := map[string]bool{} + succeededCmds := make([]string, 0, len(cmds)) 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 cmdStatusMap, iErr + return succeededCmds, iErr } for id, info := range infoResults { output, err := info.toString(cmd) if err != nil { - return cmdStatusMap, fmt.Errorf( + return succeededCmds, fmt.Errorf( "ServerError: failed to execute set-config command %s on node %s: %v", cmd, id, err) } if !strings.EqualFold(output, "ok") { - return cmdStatusMap, fmt.Errorf("ServerError: failed to execute set-config"+ + return succeededCmds, 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 + succeededCmds = append(succeededCmds, cmd) } log.V(1).Info("Finished running set-config") - return cmdStatusMap, nil + return succeededCmds, nil } func (c *cluster) findHost(hostID string) (*host, error) {