Skip to content

Commit 5d141e7

Browse files
feat: CLOUDP-380504 Update Cloud Backup Restorejobs resource
1 parent 8543dfa commit 5d141e7

9 files changed

Lines changed: 376 additions & 43 deletions

File tree

cfn-resources/cloud-backup-restore-jobs/cmd/resource/model.go

Lines changed: 44 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"fmt"
2121
"time"
2222

23-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
24-
2523
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2624
"github.com/aws/aws-sdk-go-v2/aws"
2725
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
26+
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
27+
"go.mongodb.org/atlas-sdk/v20250312013/admin"
2828

2929
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
3030
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
@@ -105,7 +105,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
105105
currentModel.Id = serverless.Id
106106
} else {
107107
params := paramsServer(currentModel)
108-
server, resp, err := client.Atlas20231115014.CloudBackupsApi.CreateBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, params).Execute()
108+
server, resp, err := client.AtlasSDK.CloudBackupsApi.CreateBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, params).Execute()
109109
if err != nil {
110110
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
111111
}
@@ -205,7 +205,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
205205
}, nil
206206
}
207207

208-
_, resp, err := client.Atlas20231115014.CloudBackupsApi.CancelBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, *currentModel.Id).Execute()
208+
resp, err := client.AtlasSDK.CloudBackupsApi.CancelBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, *currentModel.Id).Execute()
209209
if err != nil {
210210
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
211211
}
@@ -250,7 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
250250
}
251251
}
252252
} else {
253-
server, resp, err := client.Atlas20231115014.CloudBackupsApi.ListBackupRestoreJobs(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute()
253+
server, resp, err := client.AtlasSDK.CloudBackupsApi.ListBackupRestoreJobs(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute()
254254
if err != nil {
255255
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
256256
}
@@ -362,7 +362,7 @@ func updateModel(client *util.MongoDBClient, model *Model, checkFinish bool) *ha
362362
}
363363
updateModelServerless(model, serverless)
364364
} else {
365-
server, resp, err := client.Atlas20231115014.CloudBackupsApi.GetBackupRestoreJob(context.Background(), *model.ProjectId, *model.InstanceName, *model.Id).Execute()
365+
server, resp, err := client.AtlasSDK.CloudBackupsApi.GetBackupRestoreJob(context.Background(), *model.ProjectId, *model.InstanceName, *model.Id).Execute()
366366
if err != nil {
367367
pe := progressevent.GetFailedEventByResponse(err.Error(), resp)
368368
return &pe
@@ -372,38 +372,49 @@ func updateModel(client *util.MongoDBClient, model *Model, checkFinish bool) *ha
372372
return nil
373373
}
374374

375-
func updateModelServerless(model *Model, job *admin20231115014.ServerlessBackupRestoreJob) {
376-
model.TargetClusterName = &job.TargetClusterName
375+
func updateModelServer(model *Model, job *admin.DiskBackupSnapshotRestoreJob) {
376+
model.TargetClusterName = job.TargetClusterName
377377
model.DeliveryType = &job.DeliveryType
378378
model.ExpiresAt = util.TimePtrToStringPtr(job.ExpiresAt)
379379
model.Id = job.Id
380380
model.FinishedAt = util.TimePtrToStringPtr(job.FinishedAt)
381381
model.SnapshotId = job.SnapshotId
382-
model.TargetProjectId = &job.TargetGroupId
382+
model.TargetProjectId = job.TargetGroupId
383383
model.Timestamp = util.TimePtrToStringPtr(job.Timestamp)
384384
model.Cancelled = job.Cancelled
385+
model.Failed = job.Failed
385386
model.Expired = job.Expired
386387
model.DeliveryUrl = job.GetDeliveryUrl()
387388
model.Links = flattenLinks(job.GetLinks())
389+
model.DesiredTimestamp = flattenDesiredTimestamp(job.DesiredTimestamp)
390+
model.PrivateDownloadDeliveryUrls = flattenPrivateDownloadDeliveryUrls(job.PrivateDownloadDeliveryUrls)
391+
model.Components = flattenComponents(job.Components)
388392
}
389393

390-
func updateModelServer(model *Model, job *admin20231115014.DiskBackupSnapshotRestoreJob) {
391-
model.TargetClusterName = job.TargetClusterName
394+
func updateModelServerless(model *Model, job *admin20231115014.ServerlessBackupRestoreJob) {
395+
if job.TargetClusterName != "" {
396+
model.TargetClusterName = &job.TargetClusterName
397+
}
392398
model.DeliveryType = &job.DeliveryType
393399
model.ExpiresAt = util.TimePtrToStringPtr(job.ExpiresAt)
394400
model.Id = job.Id
395401
model.FinishedAt = util.TimePtrToStringPtr(job.FinishedAt)
396402
model.SnapshotId = job.SnapshotId
397-
model.TargetProjectId = job.TargetGroupId
403+
if job.TargetGroupId != "" {
404+
model.TargetProjectId = &job.TargetGroupId
405+
}
398406
model.Timestamp = util.TimePtrToStringPtr(job.Timestamp)
399407
model.Cancelled = job.Cancelled
400408
model.Failed = job.Failed
401409
model.Expired = job.Expired
402410
model.DeliveryUrl = job.GetDeliveryUrl()
403-
model.Links = flattenLinks(job.GetLinks())
411+
model.Links = flattenLinksV20231115014(job.GetLinks())
412+
model.DesiredTimestamp = nil
413+
model.PrivateDownloadDeliveryUrls = nil
414+
model.Components = nil
404415
}
405416

406-
func flattenLinks(linksResult []admin20231115014.Link) []Links {
417+
func flattenLinks(linksResult []admin.Link) []Links {
407418
links := make([]Links, 0)
408419
for _, link := range linksResult {
409420
var lin Links
@@ -414,8 +425,60 @@ func flattenLinks(linksResult []admin20231115014.Link) []Links {
414425
return links
415426
}
416427

417-
func paramsServer(model *Model) *admin20231115014.DiskBackupSnapshotRestoreJob {
418-
return &admin20231115014.DiskBackupSnapshotRestoreJob{
428+
func flattenLinksV20231115014(linksResult []admin20231115014.Link) []Links {
429+
links := make([]Links, 0)
430+
for _, link := range linksResult {
431+
var lin Links
432+
lin.Href = link.Href
433+
lin.Rel = link.Rel
434+
links = append(links, lin)
435+
}
436+
return links
437+
}
438+
439+
func flattenDesiredTimestamp(timestamp *admin.ApiBSONTimestamp) *DesiredTimestamp {
440+
if timestamp == nil {
441+
return nil
442+
}
443+
return &DesiredTimestamp{
444+
Date: util.TimePtrToStringPtr(timestamp.Date),
445+
Increment: timestamp.Increment,
446+
}
447+
}
448+
449+
func flattenPrivateDownloadDeliveryUrls(urls *[]admin.ApiPrivateDownloadDeliveryUrl) []PrivateDownloadDeliveryUrl {
450+
if urls == nil || len(*urls) == 0 {
451+
return nil
452+
}
453+
454+
result := make([]PrivateDownloadDeliveryUrl, 0, len(*urls))
455+
for _, url := range *urls {
456+
result = append(result, PrivateDownloadDeliveryUrl{
457+
DeliveryUrl: url.DeliveryUrl,
458+
EndpointId: url.EndpointId,
459+
})
460+
}
461+
return result
462+
}
463+
464+
func flattenComponents(components *[]admin.DiskBackupRestoreMember) []Component {
465+
if components == nil || len(*components) == 0 {
466+
return nil
467+
}
468+
469+
result := make([]Component, 0, len(*components))
470+
for _, comp := range *components {
471+
result = append(result, Component{
472+
DownloadUrl: comp.DownloadUrl,
473+
ReplicaSetName: comp.ReplicaSetName,
474+
PrivateDownloadDeliveryUrls: flattenPrivateDownloadDeliveryUrls(comp.PrivateDownloadDeliveryUrls),
475+
})
476+
}
477+
return result
478+
}
479+
480+
func paramsServer(model *Model) *admin.DiskBackupSnapshotRestoreJob {
481+
return &admin.DiskBackupSnapshotRestoreJob{
419482
SnapshotId: model.SnapshotId,
420483
DeliveryType: *model.DeliveryType,
421484
TargetClusterName: model.TargetClusterName,
@@ -427,13 +490,18 @@ func paramsServer(model *Model) *admin20231115014.DiskBackupSnapshotRestoreJob {
427490
}
428491

429492
func paramsServerless(model *Model) *admin20231115014.ServerlessBackupRestoreJob {
430-
return &admin20231115014.ServerlessBackupRestoreJob{
493+
params := &admin20231115014.ServerlessBackupRestoreJob{
431494
SnapshotId: model.SnapshotId,
432495
DeliveryType: *model.DeliveryType,
433-
TargetClusterName: *model.TargetClusterName,
434-
TargetGroupId: *model.TargetProjectId,
435496
OplogTs: util.StrPtrToIntPtr(model.OpLogTs),
436497
OplogInc: util.StrPtrToIntPtr(model.OpLogInc),
437498
PointInTimeUTCSeconds: model.PointInTimeUtcSeconds,
438499
}
500+
if model.TargetClusterName != nil {
501+
params.TargetClusterName = *model.TargetClusterName
502+
}
503+
if model.TargetProjectId != nil {
504+
params.TargetGroupId = *model.TargetProjectId
505+
}
506+
return params
439507
}

cfn-resources/cloud-backup-restore-jobs/docs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,15 @@ Timestamp in ISO 8601 date and time format in UTC when the snapshot associated t
229229

230230
One or more links to sub-resources and/or related resources.
231231

232+
#### DesiredTimestamp
233+
234+
BSON timestamp that indicates when the checkpoint token entry in the oplog occurred.
235+
236+
#### PrivateDownloadDeliveryUrls
237+
238+
One or more URLs that point to the compressed snapshot files for manual download via private endpoints.
239+
240+
#### Components
241+
242+
Information on the restore job for each replica set in the sharded cluster.
243+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# MongoDB::Atlas::CloudBackUpRestoreJobs Component
2+
3+
Information on the restore job for each replica set in the sharded cluster.
4+
5+
## Syntax
6+
7+
To declare this entity in your AWS CloudFormation template, use the following syntax:
8+
9+
### JSON
10+
11+
<pre>
12+
{
13+
"<a href="#downloadurl" title="DownloadUrl">DownloadUrl</a>" : <i>String</i>,
14+
"<a href="#replicasetname" title="ReplicaSetName">ReplicaSetName</a>" : <i>String</i>,
15+
"<a href="#privatedownloaddeliveryurls" title="PrivateDownloadDeliveryUrls">PrivateDownloadDeliveryUrls</a>" : <i>[ <a href="privatedownloaddeliveryurl.md">PrivateDownloadDeliveryUrl</a>, ... ]</i>
16+
}
17+
</pre>
18+
19+
### YAML
20+
21+
<pre>
22+
<a href="#downloadurl" title="DownloadUrl">DownloadUrl</a>: <i>String</i>
23+
<a href="#replicasetname" title="ReplicaSetName">ReplicaSetName</a>: <i>String</i>
24+
<a href="#privatedownloaddeliveryurls" title="PrivateDownloadDeliveryUrls">PrivateDownloadDeliveryUrls</a>: <i>
25+
- <a href="privatedownloaddeliveryurl.md">PrivateDownloadDeliveryUrl</a></i>
26+
</pre>
27+
28+
## Properties
29+
30+
#### DownloadUrl
31+
32+
One URL that points to the compressed snapshot files for this replica set.
33+
34+
_Required_: No
35+
36+
_Type_: String
37+
38+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
39+
40+
#### ReplicaSetName
41+
42+
Human-readable label that identifies the replica set.
43+
44+
_Required_: No
45+
46+
_Type_: String
47+
48+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
49+
50+
#### PrivateDownloadDeliveryUrls
51+
52+
_Required_: No
53+
54+
_Type_: List of <a href="privatedownloaddeliveryurl.md">PrivateDownloadDeliveryUrl</a>
55+
56+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
57+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# MongoDB::Atlas::CloudBackUpRestoreJobs DesiredTimestamp
2+
3+
BSON timestamp that indicates when the checkpoint token entry in the oplog occurred.
4+
5+
## Syntax
6+
7+
To declare this entity in your AWS CloudFormation template, use the following syntax:
8+
9+
### JSON
10+
11+
<pre>
12+
{
13+
"<a href="#date" title="Date">Date</a>" : <i>String</i>,
14+
"<a href="#increment" title="Increment">Increment</a>" : <i>Integer</i>
15+
}
16+
</pre>
17+
18+
### YAML
19+
20+
<pre>
21+
<a href="#date" title="Date">Date</a>: <i>String</i>
22+
<a href="#increment" title="Increment">Increment</a>: <i>Integer</i>
23+
</pre>
24+
25+
## Properties
26+
27+
#### Date
28+
29+
Date and time when the oplog recorded this database operation.
30+
31+
_Required_: No
32+
33+
_Type_: String
34+
35+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
36+
37+
#### Increment
38+
39+
Order of the database operation that the oplog recorded at specific date and time.
40+
41+
_Required_: No
42+
43+
_Type_: Integer
44+
45+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
46+

0 commit comments

Comments
 (0)