Skip to content

Commit

Permalink
enabling xdr config dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Apr 12, 2024
1 parent 779149c commit 0110ff0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
24 changes: 10 additions & 14 deletions asconfig/as_setconfig.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package asconfig

import (
"container/list"
"fmt"
"strings"

aero "github.com/aerospike/aerospike-client-go/v7"
"github.com/aerospike/aerospike-management-lib/deployment"
"github.com/aerospike/aerospike-management-lib/info"
"github.com/go-logr/logr"
)

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 @@ -251,7 +253,6 @@ func createLogSetCmdList(tokens []string, operationValueMap map[Operation][]stri
return cmdList, nil
}

/*
// createSetConfigXDRCmdList creates set-config commands for XDR context.
func createSetConfigXDRCmdList(tokens []string, operationValueMap map[Operation][]string) []string {
cmdList := make([]string, 0, len(operationValueMap))
Expand Down Expand Up @@ -316,15 +317,15 @@ func createSetConfigXDRCmdList(tokens []string, operationValueMap map[Operation]

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 @@ -343,11 +344,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 @@ -365,7 +363,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 @@ -463,4 +460,3 @@ func rearrangeConfigMap(log logr.Logger, configMap DynamicConfigMap) []string {

return finalList
}
*/
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
11 changes: 5 additions & 6 deletions asconfig/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package asconfig
import (
"encoding/json"
"fmt"
"github.com/aerospike/aerospike-management-lib/info"
"os"
"path/filepath"
"reflect"
Expand All @@ -12,8 +13,6 @@ import (

sets "github.com/deckarep/golang-set/v2"
"github.com/go-logr/logr"

"github.com/aerospike/aerospike-management-lib/info"
)

// map of version to schema
Expand Down Expand Up @@ -200,12 +199,12 @@ func IsDynamicConfig(log logr.Logger, dynamic sets.Set[string], conf string,
baseKey := tokens[len(tokens)-1]
context := tokens[0]

if context == info.ConfigXDRContext {
// XDR context is always considered static.
return false
if baseKey == "replication-factor" || baseKey == keyNodeAddressPorts {
return true
}

if baseKey == "replication-factor" {
// Name key for XDR context is considered as dynamic, as both DCs and Namespaces in DCs can be added dynamically.
if context == info.ConfigXDRContext && baseKey == KeyName {
return true
}

Expand Down

0 comments on commit 0110ff0

Please sign in to comment.