Skip to content

Commit be2b5e4

Browse files
committed
feat: adding support for version for essentials databases
1 parent 93a5193 commit be2b5e4

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

fixed_database_test.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,89 @@ func TestFixedDatabase_Create(t *testing.T) {
9696
assert.Equal(t, 51055029, actual)
9797
}
9898

99+
func TestFixedDatabase_Create_with_RedisVersion(t *testing.T) {
100+
server := httptest.NewServer(
101+
testServer(
102+
"apiKey",
103+
"secret",
104+
postRequest(
105+
t,
106+
"/fixed/subscriptions/111728/databases",
107+
`{
108+
"name": "my-redis-essentials-db",
109+
"protocol": "redis",
110+
"redisVersion": "7.4",
111+
"dataPersistence": "none",
112+
"dataEvictionPolicy": "noeviction",
113+
"replication": false,
114+
"alerts": []
115+
}`,
116+
`{
117+
"taskId": "784299af-17ea-4ed6-b08f-dd643238c8dd",
118+
"commandType": "fixedDatabaseCreateRequest",
119+
"status": "received",
120+
"description": "Task request received and is being queued for processing.",
121+
"timestamp": "2024-05-10T14:14:14.736763484Z",
122+
"links": [
123+
{
124+
"rel": "task",
125+
"type": "GET",
126+
"href": "https://api-staging.qa.redislabs.com/v1/tasks/784299af-17ea-4ed6-b08f-dd643238c8dd"
127+
}
128+
]
129+
}`,
130+
),
131+
getRequest(
132+
t,
133+
"/tasks/784299af-17ea-4ed6-b08f-dd643238c8dd",
134+
`{
135+
"taskId": "784299af-17ea-4ed6-b08f-dd643238c8dd",
136+
"commandType": "fixedDatabaseCreateRequest",
137+
"status": "processing-completed",
138+
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
139+
"timestamp": "2024-05-10T14:14:34.153537279Z",
140+
"response": {
141+
"resourceId": 51055030,
142+
"additionalResourceId": 111728
143+
},
144+
"links": [
145+
{
146+
"rel": "resource",
147+
"type": "GET",
148+
"href": "https://api-staging.qa.redislabs.com/v1/fixed/subscriptions/111728/databases/51055030"
149+
},
150+
{
151+
"rel": "self",
152+
"type": "GET",
153+
"href": "https://api-staging.qa.redislabs.com/v1/tasks/784299af-17ea-4ed6-b08f-dd643238c8dd"
154+
}
155+
]
156+
}`,
157+
),
158+
),
159+
)
160+
161+
subject, err := clientFromTestServer(server, "apiKey", "secret")
162+
require.NoError(t, err)
163+
164+
actual, err := subject.FixedDatabases.Create(
165+
context.TODO(),
166+
111728,
167+
fixedDatabases.CreateFixedDatabase{
168+
Name: redis.String("my-redis-essentials-db"),
169+
Protocol: redis.String("redis"),
170+
RedisVersion: redis.String("7.4"),
171+
DataPersistence: redis.String("none"),
172+
DataEvictionPolicy: redis.String("noeviction"),
173+
Replication: redis.Bool(false),
174+
Alerts: &[]*databases.Alert{},
175+
},
176+
)
177+
178+
require.NoError(t, err)
179+
assert.Equal(t, 51055030, actual)
180+
}
181+
99182
func TestFixedDatabase_List(t *testing.T) {
100183
server := httptest.NewServer(
101184
testServer(
@@ -546,3 +629,67 @@ func TestFixedDatabase_Delete(t *testing.T) {
546629
require.NoError(t, err)
547630

548631
}
632+
633+
func TestFixedDatabase_UpgradeRedisVersion(t *testing.T) {
634+
server := httptest.NewServer(
635+
testServer(
636+
"apiKey",
637+
"secret",
638+
postRequest(
639+
t,
640+
"/fixed/subscriptions/112119/databases/51056892/upgrade",
641+
`{ "targetRedisVersion": "7.4" }`,
642+
`{
643+
"taskId": "upgrade-task-uuid",
644+
"commandType": "fixedDatabaseUpgradeRequest",
645+
"status": "received",
646+
"description": "Task request received and is being queued for processing.",
647+
"timestamp": "2024-05-15T14:55:04.008723915Z",
648+
"links": [
649+
{
650+
"rel": "task",
651+
"type": "GET",
652+
"href": "https://api-staging.qa.redislabs.com/v1/tasks/upgrade-task-uuid"
653+
}
654+
]
655+
}`,
656+
),
657+
getRequest(
658+
t,
659+
"/tasks/upgrade-task-uuid",
660+
`{
661+
"taskId": "upgrade-task-uuid",
662+
"commandType": "fixedDatabaseUpgradeRequest",
663+
"status": "processing-completed",
664+
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
665+
"timestamp": "2024-05-15T14:55:06.538386979Z",
666+
"response": {
667+
"resourceId": 51056892,
668+
"additionalResourceId": 112119
669+
},
670+
"links": [
671+
{
672+
"rel": "self",
673+
"type": "GET",
674+
"href": "https://api-staging.qa.redislabs.com/v1/tasks/upgrade-task-uuid"
675+
}
676+
]
677+
}`,
678+
),
679+
),
680+
)
681+
682+
subject, err := clientFromTestServer(server, "apiKey", "secret")
683+
require.NoError(t, err)
684+
685+
err = subject.FixedDatabases.UpgradeRedisVersion(
686+
context.TODO(),
687+
112119,
688+
51056892,
689+
fixedDatabases.UpgradeFixedDatabaseRedisVersion{
690+
TargetRedisVersion: redis.String("7.4"),
691+
},
692+
)
693+
694+
require.NoError(t, err)
695+
}

service/fixed/databases/model.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
type CreateFixedDatabase struct {
1212
Name *string `json:"name,omitempty"`
1313
Protocol *string `json:"protocol,omitempty"`
14+
RedisVersion *string `json:"redisVersion,omitempty"`
1415
MemoryLimitInGB *float64 `json:"memoryLimitInGb,omitempty"`
1516
DatasetSizeInGB *float64 `json:"datasetSizeInGb,omitempty"`
1617
SupportOSSClusterAPI *bool `json:"supportOSSClusterApi,omitempty"`
@@ -186,6 +187,10 @@ func (f *NotFound) Error() string {
186187
return fmt.Sprintf("fixed database %d in subscription %d not found", f.dbId, f.subId)
187188
}
188189

190+
type UpgradeFixedDatabaseRedisVersion struct {
191+
TargetRedisVersion *string `json:"targetRedisVersion,omitempty"`
192+
}
193+
189194
func ProtocolValues() []string {
190195
return []string{
191196
"redis",

service/fixed/databases/service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ func (a *API) Import(ctx context.Context, subscription int, database int, reques
124124
return a.taskWaiter.Wait(ctx, *task.ID)
125125
}
126126

127+
// UpgradeRedisVersion will upgrade the Redis version of an existing fixed database.
128+
func (a *API) UpgradeRedisVersion(ctx context.Context, subscription int, database int, upgradeVersion UpgradeFixedDatabaseRedisVersion) error {
129+
var task internal.TaskResponse
130+
err := a.client.Post(ctx, fmt.Sprintf("upgrade fixed database %d version for subscription %d", database, subscription), fmt.Sprintf("/fixed/subscriptions/%d/databases/%d/upgrade", subscription, database), upgradeVersion, &task)
131+
if err != nil {
132+
return err
133+
}
134+
135+
a.logger.Printf("Waiting for fixed database %d for subscription %d to finish being upgraded", database, subscription)
136+
137+
return a.taskWaiter.Wait(ctx, *task.ID)
138+
}
139+
127140
type ListFixedDatabase struct {
128141
client HttpClient
129142
subscription int

0 commit comments

Comments
 (0)