From 3c9b5ea6cbcb339eedbb90b1144b75761b0204ff Mon Sep 17 00:00:00 2001 From: Anton Korotkov <106995168+korotkov-aerospike@users.noreply.github.com> Date: Sun, 5 Nov 2023 15:44:07 +0200 Subject: [PATCH] APPS-963 Use array to store request's bin list (#44) * use array for bin list * use array for nodes list * use array for nodes list * set node_list * set node_list * add annotations --- docs/swagger.json | 21 +++++++++++++++++++-- docs/swagger.yaml | 15 +++++++++++++-- pkg/model/config.go | 11 ++++++++--- pkg/shared/backup.go | 20 +++++++++++++++++--- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/docs/swagger.json b/docs/swagger.json index 50ee6e94..9a7046a7 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -693,7 +693,10 @@ "type": "integer" }, "bin_list": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } }, "file_limit": { "type": "integer" @@ -732,7 +735,10 @@ "type": "boolean" }, "node_list": { - "type": "string" + "type": "array", + "items": { + "$ref": "#/definitions/model.Node" + } }, "parallel": { "type": "integer" @@ -852,6 +858,17 @@ } } }, + "model.Node": { + "type": "object", + "properties": { + "ip": { + "type": "string" + }, + "port": { + "type": "integer" + } + } + }, "model.RateLimiterConfig": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9e73d80d..a1781961 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -34,7 +34,9 @@ definitions: bandwidth: type: integer bin_list: - type: string + items: + type: string + type: array file_limit: type: integer filter_exp: @@ -60,7 +62,9 @@ definitions: no_udfs: type: boolean node_list: - type: string + items: + $ref: '#/definitions/model.Node' + type: array parallel: type: integer partition_list: @@ -139,6 +143,13 @@ definitions: rate: $ref: '#/definitions/model.RateLimiterConfig' type: object + model.Node: + properties: + ip: + type: string + port: + type: integer + type: object model.RateLimiterConfig: properties: size: diff --git a/pkg/model/config.go b/pkg/model/config.go index 9b506787..f951cab5 100644 --- a/pkg/model/config.go +++ b/pkg/model/config.go @@ -120,9 +120,9 @@ type BackupPolicy struct { Storage *string `yaml:"storage,omitempty" json:"storage,omitempty"` Namespace *string `yaml:"namespace,omitempty" json:"namespace,omitempty"` Parallel *int32 `yaml:"parallel,omitempty" json:"parallel,omitempty"` - SetList *[]string `yaml:"set_list,omitempty" json:"set_list,omitempty"` - NodeList *string `yaml:"node_list,omitempty" json:"node_list,omitempty"` - BinList *string `yaml:"bin_list,omitempty" json:"bin_list,omitempty"` + SetList []string `yaml:"set_list,omitempty" json:"set_list,omitempty"` + BinList []string `yaml:"bin_list,omitempty" json:"bin_list,omitempty"` + NodeList []Node `yaml:"node_list,omitempty" json:"node_list,omitempty"` SocketTimeout *uint32 `yaml:"socket_timeout,omitempty" json:"socket_timeout,omitempty"` TotalTimeout *uint32 `yaml:"total_timeout,omitempty" json:"total_timeout,omitempty"` MaxRetries *uint32 `yaml:"max_retries,omitempty" json:"max_retries,omitempty"` @@ -154,6 +154,11 @@ func (p *BackupPolicy) Clone() *BackupPolicy { return &clone } +type Node struct { + IP string `yaml:"ip" json:"ip"` + Port int `yaml:"port" json:"port"` +} + // GetName returns the name of the BackupPolicy. func (p *BackupPolicy) GetName() *string { return p.Name diff --git a/pkg/shared/backup.go b/pkg/shared/backup.go index fe1c9619..e8b89dfc 100644 --- a/pkg/shared/backup.go +++ b/pkg/shared/backup.go @@ -25,6 +25,7 @@ import ( "log/slog" "github.com/aerospike/backup/pkg/model" + "github.com/aws/smithy-go/ptr" ) // BackupShared implements the Backup interface. @@ -61,9 +62,13 @@ func (b *BackupShared) BackupRun(backupPolicy *model.BackupPolicy, cluster *mode setCString(&backupConfig.password, cluster.GetPassword()) setCString(&backupConfig.auth_mode, cluster.AuthMode) - parseSetList(&backupConfig.set_list, backupPolicy.SetList) - setCString(&backupConfig.bin_list, backupPolicy.BinList) - + parseSetList(&backupConfig.set_list, &backupPolicy.SetList) + if backupPolicy.BinList != nil { + setCString(&backupConfig.bin_list, ptr.String(strings.Join(backupPolicy.BinList, ","))) + } + if backupPolicy.NodeList != nil { + setCString(&backupConfig.node_list, printNodes(backupPolicy.NodeList)) + } setCUint(&backupConfig.socket_timeout, backupPolicy.SocketTimeout) setCUint(&backupConfig.total_timeout, backupPolicy.TotalTimeout) setCUint(&backupConfig.max_retries, backupPolicy.MaxRetries) @@ -146,3 +151,12 @@ func getIncrementalPath(storage *model.BackupStorage) *string { func timeSuffix() string { return strconv.FormatInt(time.Now().Unix(), 10) } + +func printNodes(nodes []model.Node) *string { + nodeStrings := make([]string, 0, len(nodes)) + for _, node := range nodes { + nodeStrings = append(nodeStrings, fmt.Sprintf("%s:%d", node.IP, node.Port)) + } + concatenated := strings.Join(nodeStrings, ",") + return &concatenated +}