Skip to content

Commit

Permalink
enabling xdr
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed May 31, 2024
1 parent 0d2295e commit 32113b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
57 changes: 27 additions & 30 deletions asconfig/as_setconfig.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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]

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}

Expand All @@ -459,7 +457,6 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string {

return finalList
}
*/

func ValidConfigOperations() []OpType {
return []OpType{Add, Update, Remove}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions asconfig/as_setconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package asconfig
import (
"testing"

"github.com/go-logr/logr"
"github.com/stretchr/testify/suite"
"go.uber.org/mock/gomock"

Expand Down Expand Up @@ -62,19 +63,19 @@ 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))
})
}
}

/*
func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdListOrdered() {
testCases := []struct {
name string
Expand All @@ -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"},
},
Expand All @@ -114,7 +115,6 @@ func (s *AsSetConfigTestSuite) TestCreateSetConfigCmdListOrdered() {
})
}
}
*/

func TestAsSetConfigTestSuite(t *testing.T) {
suite.Run(t, new(AsSetConfigTestSuite))
Expand Down

0 comments on commit 32113b1

Please sign in to comment.