Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions cfn-resources/cloud-backup-restore-jobs/cmd/resource/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 87 additions & 19 deletions cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"time"

admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
"go.mongodb.org/atlas-sdk/v20250312013/admin"

"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
Expand Down Expand Up @@ -105,7 +105,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
currentModel.Id = serverless.Id
} else {
params := paramsServer(currentModel)
server, resp, err := client.Atlas20231115014.CloudBackupsApi.CreateBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, params).Execute()
server, resp, err := client.AtlasSDK.CloudBackupsApi.CreateBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, params).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
}, nil
}

_, resp, err := client.Atlas20231115014.CloudBackupsApi.CancelBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, *currentModel.Id).Execute()
resp, err := client.AtlasSDK.CloudBackupsApi.CancelBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, *currentModel.Id).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
}
}
} else {
server, resp, err := client.Atlas20231115014.CloudBackupsApi.ListBackupRestoreJobs(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute()
server, resp, err := client.AtlasSDK.CloudBackupsApi.ListBackupRestoreJobs(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute()
if err != nil {
return progressevent.GetFailedEventByResponse(err.Error(), resp), nil
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func updateModel(client *util.MongoDBClient, model *Model, checkFinish bool) *ha
}
updateModelServerless(model, serverless)
} else {
server, resp, err := client.Atlas20231115014.CloudBackupsApi.GetBackupRestoreJob(context.Background(), *model.ProjectId, *model.InstanceName, *model.Id).Execute()
server, resp, err := client.AtlasSDK.CloudBackupsApi.GetBackupRestoreJob(context.Background(), *model.ProjectId, *model.InstanceName, *model.Id).Execute()
if err != nil {
pe := progressevent.GetFailedEventByResponse(err.Error(), resp)
return &pe
Expand All @@ -372,38 +372,49 @@ func updateModel(client *util.MongoDBClient, model *Model, checkFinish bool) *ha
return nil
}

func updateModelServerless(model *Model, job *admin20231115014.ServerlessBackupRestoreJob) {
model.TargetClusterName = &job.TargetClusterName
func updateModelServer(model *Model, job *admin.DiskBackupSnapshotRestoreJob) {
model.TargetClusterName = job.TargetClusterName
model.DeliveryType = &job.DeliveryType
model.ExpiresAt = util.TimePtrToStringPtr(job.ExpiresAt)
model.Id = job.Id
model.FinishedAt = util.TimePtrToStringPtr(job.FinishedAt)
model.SnapshotId = job.SnapshotId
model.TargetProjectId = &job.TargetGroupId
model.TargetProjectId = job.TargetGroupId
model.Timestamp = util.TimePtrToStringPtr(job.Timestamp)
model.Cancelled = job.Cancelled
model.Failed = job.Failed
model.Expired = job.Expired
model.DeliveryUrl = job.GetDeliveryUrl()
model.Links = flattenLinks(job.GetLinks())
model.DesiredTimestamp = flattenDesiredTimestamp(job.DesiredTimestamp)
model.PrivateDownloadDeliveryUrls = flattenPrivateDownloadDeliveryUrls(job.PrivateDownloadDeliveryUrls)
model.Components = flattenComponents(job.Components)
}

func updateModelServer(model *Model, job *admin20231115014.DiskBackupSnapshotRestoreJob) {
model.TargetClusterName = job.TargetClusterName
func updateModelServerless(model *Model, job *admin20231115014.ServerlessBackupRestoreJob) {
if job.TargetClusterName != "" {
model.TargetClusterName = &job.TargetClusterName
}
model.DeliveryType = &job.DeliveryType
model.ExpiresAt = util.TimePtrToStringPtr(job.ExpiresAt)
model.Id = job.Id
model.FinishedAt = util.TimePtrToStringPtr(job.FinishedAt)
model.SnapshotId = job.SnapshotId
model.TargetProjectId = job.TargetGroupId
if job.TargetGroupId != "" {
model.TargetProjectId = &job.TargetGroupId
}
model.Timestamp = util.TimePtrToStringPtr(job.Timestamp)
model.Cancelled = job.Cancelled
model.Failed = job.Failed
model.Expired = job.Expired
model.DeliveryUrl = job.GetDeliveryUrl()
model.Links = flattenLinks(job.GetLinks())
model.Links = flattenLinksV20231115014(job.GetLinks())
model.DesiredTimestamp = nil
model.PrivateDownloadDeliveryUrls = nil
model.Components = nil
}

func flattenLinks(linksResult []admin20231115014.Link) []Links {
func flattenLinks(linksResult []admin.Link) []Links {
links := make([]Links, 0)
for _, link := range linksResult {
var lin Links
Expand All @@ -414,8 +425,60 @@ func flattenLinks(linksResult []admin20231115014.Link) []Links {
return links
}

func paramsServer(model *Model) *admin20231115014.DiskBackupSnapshotRestoreJob {
return &admin20231115014.DiskBackupSnapshotRestoreJob{
func flattenLinksV20231115014(linksResult []admin20231115014.Link) []Links {
links := make([]Links, 0)
for _, link := range linksResult {
var lin Links
lin.Href = link.Href
lin.Rel = link.Rel
links = append(links, lin)
}
return links
}

func flattenDesiredTimestamp(timestamp *admin.ApiBSONTimestamp) *DesiredTimestamp {
if timestamp == nil {
return nil
}
return &DesiredTimestamp{
Date: util.TimePtrToStringPtr(timestamp.Date),
Increment: timestamp.Increment,
}
}

func flattenPrivateDownloadDeliveryUrls(urls *[]admin.ApiPrivateDownloadDeliveryUrl) []PrivateDownloadDeliveryUrl {
if urls == nil || len(*urls) == 0 {
return nil
}

result := make([]PrivateDownloadDeliveryUrl, 0, len(*urls))
for _, url := range *urls {
result = append(result, PrivateDownloadDeliveryUrl{
DeliveryUrl: url.DeliveryUrl,
EndpointId: url.EndpointId,
})
}
return result
}

func flattenComponents(components *[]admin.DiskBackupRestoreMember) []Component {
if components == nil || len(*components) == 0 {
return nil
}

result := make([]Component, 0, len(*components))
for _, comp := range *components {
result = append(result, Component{
DownloadUrl: comp.DownloadUrl,
ReplicaSetName: comp.ReplicaSetName,
PrivateDownloadDeliveryUrls: flattenPrivateDownloadDeliveryUrls(comp.PrivateDownloadDeliveryUrls),
})
}
return result
}

func paramsServer(model *Model) *admin.DiskBackupSnapshotRestoreJob {
return &admin.DiskBackupSnapshotRestoreJob{
SnapshotId: model.SnapshotId,
DeliveryType: *model.DeliveryType,
TargetClusterName: model.TargetClusterName,
Expand All @@ -427,13 +490,18 @@ func paramsServer(model *Model) *admin20231115014.DiskBackupSnapshotRestoreJob {
}

func paramsServerless(model *Model) *admin20231115014.ServerlessBackupRestoreJob {
return &admin20231115014.ServerlessBackupRestoreJob{
params := &admin20231115014.ServerlessBackupRestoreJob{
SnapshotId: model.SnapshotId,
DeliveryType: *model.DeliveryType,
TargetClusterName: *model.TargetClusterName,
TargetGroupId: *model.TargetProjectId,
OplogTs: util.StrPtrToIntPtr(model.OpLogTs),
OplogInc: util.StrPtrToIntPtr(model.OpLogInc),
PointInTimeUTCSeconds: model.PointInTimeUtcSeconds,
}
if model.TargetClusterName != nil {
params.TargetClusterName = *model.TargetClusterName
}
if model.TargetProjectId != nil {
params.TargetGroupId = *model.TargetProjectId
}
return params
}
12 changes: 12 additions & 0 deletions cfn-resources/cloud-backup-restore-jobs/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ Timestamp in ISO 8601 date and time format in UTC when the snapshot associated t

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

#### DesiredTimestamp

BSON timestamp that indicates when the checkpoint token entry in the oplog occurred.

#### PrivateDownloadDeliveryUrls

One or more URLs that point to the compressed snapshot files for manual download via private endpoints.

#### Components

Information on the restore job for each replica set in the sharded cluster.

57 changes: 57 additions & 0 deletions cfn-resources/cloud-backup-restore-jobs/docs/component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# MongoDB::Atlas::CloudBackUpRestoreJobs Component

Information on the restore job for each replica set in the sharded cluster.

## Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

### JSON

<pre>
{
"<a href="#downloadurl" title="DownloadUrl">DownloadUrl</a>" : <i>String</i>,
"<a href="#replicasetname" title="ReplicaSetName">ReplicaSetName</a>" : <i>String</i>,
"<a href="#privatedownloaddeliveryurls" title="PrivateDownloadDeliveryUrls">PrivateDownloadDeliveryUrls</a>" : <i>[ <a href="privatedownloaddeliveryurl.md">PrivateDownloadDeliveryUrl</a>, ... ]</i>
}
</pre>

### YAML

<pre>
<a href="#downloadurl" title="DownloadUrl">DownloadUrl</a>: <i>String</i>
<a href="#replicasetname" title="ReplicaSetName">ReplicaSetName</a>: <i>String</i>
<a href="#privatedownloaddeliveryurls" title="PrivateDownloadDeliveryUrls">PrivateDownloadDeliveryUrls</a>: <i>
- <a href="privatedownloaddeliveryurl.md">PrivateDownloadDeliveryUrl</a></i>
</pre>

## Properties

#### DownloadUrl

One URL that points to the compressed snapshot files for this replica set.

_Required_: No

_Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### ReplicaSetName

Human-readable label that identifies the replica set.

_Required_: No

_Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### PrivateDownloadDeliveryUrls

_Required_: No

_Type_: List of <a href="privatedownloaddeliveryurl.md">PrivateDownloadDeliveryUrl</a>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# MongoDB::Atlas::CloudBackUpRestoreJobs DesiredTimestamp

BSON timestamp that indicates when the checkpoint token entry in the oplog occurred.

## Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

### JSON

<pre>
{
"<a href="#date" title="Date">Date</a>" : <i>String</i>,
"<a href="#increment" title="Increment">Increment</a>" : <i>Integer</i>
}
</pre>

### YAML

<pre>
<a href="#date" title="Date">Date</a>: <i>String</i>
<a href="#increment" title="Increment">Increment</a>: <i>Integer</i>
</pre>

## Properties

#### Date

Date and time when the oplog recorded this database operation.

_Required_: No

_Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### Increment

Order of the database operation that the oplog recorded at specific date and time.

_Required_: No

_Type_: Integer

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

Loading
Loading