Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-58634: Add support for checkpoints in the Atlas client #65

Merged
merged 7 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ const (
backupCheckpoints = "groups/%s/clusters/%s/backupCheckpoints"
)

// AtlasCheckpointService is an interface for interfacing with the Checkpoint
// CheckpointService is an interface for interfacing with the Checkpoint
// endpoints of the MongoDB Atlas API.
type AtlasCheckpointService interface {
type CheckpointService interface {
List(context.Context, string, string, *ListOptions) (*Checkpoints, *Response, error)
Get(context.Context, string, string, string) (*Checkpoint, *Response, error)
}

// AtlasCheckpointsServiceOp handles communication with the checkpoint related methods of the
// CheckpointsServiceOp handles communication with the checkpoint related methods of the
// MongoDB Atlas API
type AtlasCheckpointsServiceOp struct {
type CheckpointsServiceOp struct {
Client RequestDoer
}

var _ AtlasCheckpointService = &AtlasCheckpointsServiceOp{}
var _ CheckpointService = &CheckpointsServiceOp{}

type Checkpoint struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, it's really nice, but could you add comments describing all the importing functions and structs to have coherency? Also, it avoids warnings in some editors for missing comments.

ClusterID string `json:"clusterId"`
Expand All @@ -37,14 +37,20 @@ type Checkpoint struct {
Timestamp string `json:"timestamp"`
}

// AtlasCheckpoints represents all the backup checkpoints related to a cluster.
type CheckpointPart struct {
ShardName string `json:"shardName"`
TokenDiscovered bool `json:"tokenDiscovered"`
TokenTimestamp SnapshotTimestamp `json:"tokenTimestamp"`
}

// Checkpoints represents all the backup checkpoints related to a cluster.
type Checkpoints struct {
Results []*Checkpoint `json:"results,omitempty"` // Includes one Checkpoint object for each item detailed in the results array section.
Links []*Link `json:"links,omitempty"` // One or more links to sub-resources and/or related resources.
TotalCount int `json:"totalCount,omitempty"` // Count of the total number of items in the result set. It may be greater than the number of objects in the results array if the entire result set is paginated.
}

func (s AtlasCheckpointsServiceOp) List(ctx context.Context, groupID, clusterName string, listOptions *ListOptions) (*Checkpoints, *Response, error) {
func (s CheckpointsServiceOp) List(ctx context.Context, groupID, clusterName string, listOptions *ListOptions) (*Checkpoints, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupId", "must be set")
}
Expand All @@ -65,7 +71,7 @@ func (s AtlasCheckpointsServiceOp) List(ctx context.Context, groupID, clusterNam
return root, resp, err
}

func (s AtlasCheckpointsServiceOp) Get(ctx context.Context, groupID, clusterName, checkpointID string) (*Checkpoint, *Response, error) {
func (s CheckpointsServiceOp) Get(ctx context.Context, groupID, clusterName, checkpointID string) (*Checkpoint, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupId", "must be set")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,33 +145,36 @@ func TestCheckpoints_List(t *testing.T) {
},
Parts: []*Part{
{
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
},
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
},
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 2,
},
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
CheckpointPart: CheckpointPart{
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 2,
}},
},
},
Restorable: true,
Expand All @@ -191,33 +194,36 @@ func TestCheckpoints_List(t *testing.T) {
},
Parts: []*Part{
{
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 1,
},
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 2,
},
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 2,
}},
},
{
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 4,
},
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
CheckpointPart: CheckpointPart{
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 4,
}},
},
},
Restorable: true,
Expand Down Expand Up @@ -315,34 +321,39 @@ func TestCheckpoints_Get(t *testing.T) {
},
},
Parts: []*Part{

{
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
},
},
},
{
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
},
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 2,
},
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
CheckpointPart: CheckpointPart{
TokenDiscovered: true,
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 2,
}},
},
},
Restorable: true,
Expand Down
28 changes: 15 additions & 13 deletions mongodbatlas/continuous_snaphots.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ type ContinuousSnapshot struct {
}

type Part struct {
ClusterID string `json:"clusterId,omitempty"`
CompressionSetting string `json:"compressionSetting,omitempty"`
DataSizeBytes int64 `json:"dataSizeBytes,omitempty"`
EncryptionEnabled bool `json:"encryptionEnabled,omitempty"`
FileSizeBytes int64 `json:"fileSizeBytes,omitempty"`
MasterKeyUUID string `json:"masterKeyUUID,omitempty"`
MongodVersion string `json:"mongodVersion,omitempty"`
ReplicaSetName string `json:"replicaSetName,omitempty"`
StorageSizeBytes int64 `json:"storageSizeBytes,omitempty"`
TypeName string `json:"typeName"`
ShardName string `json:"shardName,omitempty"`
TokenDiscovered bool `json:"tokenDiscovered,omitempty"`
TokenTimestamp SnapshotTimestamp `json:"tokenTimestamp,omitempty"`
ReplicaSetName string `json:"replicaSetName"`
TypeName string `json:"typeName"`
SnapshotPart
CheckpointPart
}

type SnapshotPart struct {
ClusterID string `json:"clusterId"`
CompressionSetting string `json:"compressionSetting"`
DataSizeBytes int64 `json:"dataSizeBytes"`
EncryptionEnabled bool `json:"encryptionEnabled"`
FileSizeBytes int64 `json:"fileSizeBytes"`
MasterKeyUUID string `json:"masterKeyUUID,omitempty"`
MongodVersion string `json:"mongodVersion"`
StorageSizeBytes int64 `json:"storageSizeBytes"`
}

type NamespaceFilter struct {
Expand Down
62 changes: 33 additions & 29 deletions mongodbatlas/continuous_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package mongodbatlas
import (
"encoding/json"
"fmt"
"github.com/mwielbut/pointy"
"net/http"
"testing"

"github.com/mwielbut/pointy"

"github.com/go-test/deep"
)

Expand Down Expand Up @@ -97,15 +98,16 @@ func TestContinuousSnapshots_List(t *testing.T) {
},
Parts: []*Part{
{
ClusterID: "7c2487d833e9e75286093696",
CompressionSetting: "GZIP",
DataSizeBytes: 4502,
EncryptionEnabled: false,
FileSizeBytes: 324760,
MongodVersion: "3.6.10",
ReplicaSetName: "Cluster0-shard-0",
StorageSizeBytes: 53248,
TypeName: "REPLICA_SET",
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
SnapshotPart: SnapshotPart{
ClusterID: "7c2487d833e9e75286093696",
CompressionSetting: "GZIP",
DataSizeBytes: 4502,
EncryptionEnabled: false,
FileSizeBytes: 324760,
MongodVersion: "3.6.10",
StorageSizeBytes: 53248},
},
},
},
Expand Down Expand Up @@ -190,15 +192,16 @@ func TestContinuousSnapshots_Get(t *testing.T) {
},
Parts: []*Part{
{
ClusterID: "7c2487d833e9e75286093696",
CompressionSetting: "GZIP",
DataSizeBytes: 4502,
EncryptionEnabled: false,
FileSizeBytes: 324760,
MongodVersion: "3.6.10",
ReplicaSetName: "Cluster0-shard-0",
StorageSizeBytes: 53248,
TypeName: "REPLICA_SET",
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
SnapshotPart: SnapshotPart{
ClusterID: "7c2487d833e9e75286093696",
CompressionSetting: "GZIP",
DataSizeBytes: 4502,
EncryptionEnabled: false,
FileSizeBytes: 324760,
MongodVersion: "3.6.10",
StorageSizeBytes: 53248},
},
},
}
Expand Down Expand Up @@ -302,16 +305,17 @@ func TestContinuousSnapshots_ChangeExpiry(t *testing.T) {
},
Parts: []*Part{
{
ClusterID: "57c2487d833e9e75286093696",
CompressionSetting: "GZIP",
DataSizeBytes: 4502,
EncryptionEnabled: false,
FileSizeBytes: 324760,
MongodVersion: "3.6.10",
ReplicaSetName: "Cluster0-shard-0",
StorageSizeBytes: 53248,
TypeName: "REPLICA_SET",
},
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
SnapshotPart: SnapshotPart{
ClusterID: "57c2487d833e9e75286093696",
CompressionSetting: "GZIP",
DataSizeBytes: 4502,
EncryptionEnabled: false,
FileSizeBytes: 324760,
MongodVersion: "3.6.10",
StorageSizeBytes: 53248,
}},
},
}

Expand Down
4 changes: 2 additions & 2 deletions mongodbatlas/mongodbatlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Client struct {
X509AuthDBUsers X509AuthDBUsersService
ContinuousSnapshots ContinuousSnapshotsService
ContinuousRestoreJobs ContinuousRestoreJobsService
AtlasCheckpoints AtlasCheckpointService
AtlasCheckpoints CheckpointService
gssbzn marked this conversation as resolved.
Show resolved Hide resolved

onRequestCompleted RequestCompletionCallback
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func NewClient(httpClient *http.Client) *Client {
c.PrivateEndpoints = &PrivateEndpointsServiceOp{Client: c}
c.X509AuthDBUsers = &X509AuthDBUsersServiceOp{Client: c}
c.ContinuousRestoreJobs = &ContinuousRestoreJobsServiceOp{Client: c}
c.AtlasCheckpoints = &AtlasCheckpointsServiceOp{Client: c}
c.AtlasCheckpoints = &CheckpointsServiceOp{Client: c}

return c
}
Expand Down