From 32113b10c8b9845d2931aa7484e29868ce924199 Mon Sep 17 00:00:00 2001 From: Tanmay Jain Date: Fri, 31 May 2024 12:53:05 +0530 Subject: [PATCH] enabling xdr --- asconfig/as_setconfig.go | 57 +++++++++++++++++------------------ asconfig/as_setconfig_test.go | 8 ++--- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/asconfig/as_setconfig.go b/asconfig/as_setconfig.go index 6045d09..a97c0ee 100644 --- a/asconfig/as_setconfig.go +++ b/asconfig/as_setconfig.go @@ -1,9 +1,12 @@ package asconfig import ( + "container/list" "fmt" "strings" + "github.com/go-logr/logr" + aero "github.com/aerospike/aerospike-client-go/v7" "github.com/aerospike/aerospike-management-lib/deployment" "github.com/aerospike/aerospike-management-lib/info" @@ -13,9 +16,9 @@ const ( cmdSetConfigNetwork = "set-config:context=network;" // ConfigNetwork cmdSetConfigService = "set-config:context=service;" // ConfigService cmdSetConfigNamespace = "set-config:context=namespace;id=" // ConfigNamespace - // cmdSetConfigXDR = "set-config:context=xdr" // ConfigXDR - cmdSetConfigSecurity = "set-config:context=security;" // ConfigSecurity - cmdSetLogging = "log-set:id=" // ConfigLogging + cmdSetConfigXDR = "set-config:context=xdr" // ConfigXDR + cmdSetConfigSecurity = "set-config:context=security;" // ConfigSecurity + cmdSetLogging = "log-set:id=" // ConfigLogging ) // convertValueToString converts the value of a config to a string. @@ -191,10 +194,14 @@ func createSetConfigNamespaceCmdList(tokens []string, operationValueMap map[OpTy cmd += strings.Trim(token, "{}") } } else { - if prevToken == "index-type" || prevToken == "sindex-type" { + switch prevToken { + case "index-type", "sindex-type": cmd += fmt.Sprintf(";%s.%s", prevToken, token) prevToken = "" - } else { + case "geo2dsphere-within": + cmd += fmt.Sprintf(";%s-%s", prevToken, token) + prevToken = "" + default: prevToken = token } } @@ -247,7 +254,6 @@ func createLogSetCmdList(tokens []string, operationValueMap map[OpType][]string, return cmdList, nil } -/* // createSetConfigXDRCmdList creates set-config commands for XDR context. func createSetConfigXDRCmdList(tokens []string, operationValueMap map[OpType][]string) []string { cmdList := make([]string, 0, len(operationValueMap)) @@ -312,15 +318,15 @@ func createSetConfigXDRCmdList(tokens []string, operationValueMap map[OpType][]s return cmdList } -*/ // CreateSetConfigCmdList creates set-config commands for given config. -func CreateSetConfigCmdList(configMap DynamicConfigMap, conn deployment.ASConnInterface, +func CreateSetConfigCmdList(log logr.Logger, configMap DynamicConfigMap, conn deployment.ASConnInterface, aerospikePolicy *aero.ClientPolicy, ) ([]string, error) { cmdList := make([]string, 0, len(configMap)) - for c := range configMap { + orderedConfList := rearrangeConfigMap(log, configMap) + for _, c := range orderedConfList { tokens := strings.Split(c, sep) context := tokens[0] @@ -339,11 +345,8 @@ func CreateSetConfigCmdList(configMap DynamicConfigMap, conn deployment.ASConnIn case info.ConfigNamespaceContext: cmdList = append(cmdList, createSetConfigNamespaceCmdList(tokens, val)...) - /* - Commenting out XDR context for now because of ordering issues. - case info.ConfigXDRContext: - cmdList = append(cmdList, createSetConfigXDRCmdList(tokens, val)...) - */ + case info.ConfigXDRContext: + cmdList = append(cmdList, createSetConfigXDRCmdList(tokens, val)...) case info.ConfigLoggingContext: cmds, err := createLogSetCmdList(tokens, val, conn, aerospikePolicy) @@ -361,7 +364,6 @@ func CreateSetConfigCmdList(configMap DynamicConfigMap, conn deployment.ASConnIn return cmdList, nil } -/* // Returns a list of config keys in the order in which they should be applied. // The order is as follows: // 1. Removed Namespaces -- If user has to change some of the DC direct fields, they will have to remove the namespace @@ -397,7 +399,7 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string { // If namespace is removed, directly add it to the final list finalList = append(finalList, k) } else { - // If namespace is added, add it after all DCs and their direct fields + // If namespace is added, add it after all DCs and their direct configs if lastDCConfig == nil { if lastDC != nil { rearrangedConfigMap.InsertAfter(k, lastDC) @@ -418,23 +420,19 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string { // Handle DC direct fields if tokens[len(tokens)-3] == info.ConfigDCContext { var nap *list.Element - // Check if the key is related to 'node-address-ports' - isNodeAddressPortsKey := strings.HasSuffix(k, sep+keyNodeAddressPorts) - - if isNodeAddressPortsKey { + // Check if the key is 'node-address-ports' + if strings.HasSuffix(k, sep+keyNodeAddressPorts) { if _, ok := v[Remove]; ok { dc := rearrangedConfigMap.PushFront(k) if lastDC == nil { lastDC = dc } continue - } else { - if lastDCConfig != nil { - // Add 'node-address-ports' after all DC direct fields - // There are certain fields that must be set before 'node-address-ports', for example, 'tls-name'. - lastDCConfig = rearrangedConfigMap.InsertAfter(k, lastDCConfig) - continue - } + } else if lastDCConfig != nil { + // Add 'node-address-ports' after all DC direct fields + // There are certain fields that must be set before 'node-address-ports', for example, 'tls-name'. + lastDCConfig = rearrangedConfigMap.InsertAfter(k, lastDCConfig) + continue } } @@ -459,7 +457,6 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string { return finalList } -*/ func ValidConfigOperations() []OpType { return []OpType{Add, Update, Remove} @@ -522,7 +519,7 @@ func CreateConfigSetCmdsUsingPatch( return nil, fmt.Errorf("static field has been changed, cannot change config dynamically") } - return CreateSetConfigCmdList(asConfChange, conn, aerospikePolicy) + return CreateSetConfigCmdList(logr.Logger{}, asConfChange, conn, aerospikePolicy) } func CreateConfigSetCmdsUsingOperation( @@ -559,5 +556,5 @@ func CreateConfigSetCmdsUsingOperation( return nil, fmt.Errorf("static field has been changed, cannot change config dynamically") } - return CreateSetConfigCmdList(asConfChange, conn, aerospikePolicy) + return CreateSetConfigCmdList(logr.Logger{}, asConfChange, conn, aerospikePolicy) } diff --git a/asconfig/as_setconfig_test.go b/asconfig/as_setconfig_test.go index 9774c6b..98fd57d 100644 --- a/asconfig/as_setconfig_test.go +++ b/asconfig/as_setconfig_test.go @@ -3,6 +3,7 @@ package asconfig import ( "testing" + "github.com/go-logr/logr" "github.com/stretchr/testify/suite" "go.uber.org/mock/gomock" @@ -62,11 +63,12 @@ func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdList() { for _, tc := range testCases { s.Run(tc.name, func() { + logger := logr.Discard() policy := &aero.ClientPolicy{} s.mockASConn.EXPECT().RunInfo(gomock.Any(), gomock.Any()).Return(map[string]string{ "logs": "0:stderr"}, nil).AnyTimes() - result, err := CreateSetConfigCmdList(tc.inputConf, s.mockASConn, policy) + result, err := CreateSetConfigCmdList(logger, tc.inputConf, s.mockASConn, policy) s.Assert().Nil(err) s.Assert().True(gomock.InAnyOrder(result).Matches(tc.expected)) @@ -74,7 +76,6 @@ func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdList() { } } -/* func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdListOrdered() { testCases := []struct { name string @@ -87,7 +88,7 @@ func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdListOrdered() { "xdr.dcs.{DC1}.namespaces.{ns1}.bin-policy": {Update: "no-bins"}, "xdr.dcs.{DC3}.name": {Add: "DC3"}, "xdr.dcs.{DC1}.namespaces.{ns2}.name": {Remove: "ns2"}, - "xdr.dcs.{DC1}.node-address-ports": {Add: []string{"1.1.1.1:3000:tls-name"}, + "xdr.dcs.{DC1}.node-address-ports": {Add: []string{"1.1.1.1:3000:tls-name"}}, "xdr.dcs.{DC1}.namespaces.{ns1}.name": {Add: "ns1"}, "xdr.dcs.{DC1}.tls-name": {Update: "tls-name"}, }, @@ -114,7 +115,6 @@ func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdListOrdered() { }) } } -*/ func TestAsSetConfigTestSuite(t *testing.T) { suite.Run(t, new(AsSetConfigTestSuite))