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-252326: Remove Atlas Dependency Phase 2 #232

Merged
merged 1 commit into from
Jun 21, 2024
Merged
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
41 changes: 33 additions & 8 deletions opsmngr/checkpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,45 @@ import (
"context"
"fmt"
"net/http"

atlas "go.mongodb.org/atlas/mongodbatlas"
)

const (
checkpoints = "api/public/v1.0/groups/%s/clusters/%s/checkpoints"
)

// Checkpoint represents MongoDB Checkpoint.
type Checkpoint struct {
ClusterID string `json:"clusterId"`
Completed string `json:"completed,omitempty"`
GroupID string `json:"groupId"`
ID string `json:"id,omitempty"` // Unique identifier of the checkpoint.
Links []*Link `json:"links,omitempty"` // One or more links to sub-resources and/or related resources.
Parts []*Part `json:"parts,omitempty"`
Restorable bool `json:"restorable"`
Started string `json:"started"`
Timestamp string `json:"timestamp"`
}

// CheckpointPart represents the individual parts that comprise the complete checkpoint.
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.
}

// CheckpointsService provides access to the backup related functions in the Ops Manager API.
//
// See more: https://docs.opsmanager.mongodb.com/current/reference/api/checkpoints/
type CheckpointsService interface {
List(context.Context, string, string, *ListOptions) (*atlas.Checkpoints, *Response, error)
Get(context.Context, string, string, string) (*atlas.Checkpoint, *Response, error)
List(context.Context, string, string, *ListOptions) (*Checkpoints, *Response, error)
Get(context.Context, string, string, string) (*Checkpoint, *Response, error)
}

// CheckpointsServiceOp provides an implementation of the CheckpointsService interface.
Expand All @@ -42,7 +67,7 @@ var _ CheckpointsService = &CheckpointsServiceOp{}
// List lists checkpoints.
//
// See https://docs.opsmanager.mongodb.com/current/reference/api/checkpoints/#get-all-checkpoints
func (s *CheckpointsServiceOp) List(ctx context.Context, groupID, clusterName string, listOptions *ListOptions) (*atlas.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 @@ -61,7 +86,7 @@ func (s *CheckpointsServiceOp) List(ctx context.Context, groupID, clusterName st
return nil, nil, err
}

root := new(atlas.Checkpoints)
root := new(Checkpoints)
resp, err := s.Client.Do(ctx, req, root)

return root, resp, err
Expand All @@ -70,7 +95,7 @@ func (s *CheckpointsServiceOp) List(ctx context.Context, groupID, clusterName st
// Get gets a checkpoint.
//
// See https://docs.opsmanager.mongodb.com/current/reference/api/checkpoints/#get-one-checkpoint
func (s *CheckpointsServiceOp) Get(ctx context.Context, groupID, clusterID, checkpointID string) (*atlas.Checkpoint, *Response, error) {
func (s *CheckpointsServiceOp) Get(ctx context.Context, groupID, clusterID, checkpointID string) (*Checkpoint, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupId", "must be set")
}
Expand All @@ -89,7 +114,7 @@ func (s *CheckpointsServiceOp) Get(ctx context.Context, groupID, clusterID, chec
return nil, nil, err
}

root := new(atlas.Checkpoint)
root := new(Checkpoint)
resp, err := s.Client.Do(ctx, req, root)

return root, resp, err
Expand Down
57 changes: 28 additions & 29 deletions opsmngr/checkpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

"github.com/go-test/deep"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const clusterID = "6b8cd61180eef547110159d9" //nolint:gosec // not a credential
Expand Down Expand Up @@ -145,48 +144,48 @@ func TestCheckpoints_List(t *testing.T) {
t.Fatalf("Checkpoints.List returned error: %v", err)
}

expected := &atlas.Checkpoints{
Results: []*atlas.Checkpoint{
expected := &Checkpoints{
Results: []*Checkpoint{
{
ClusterID: clusterID,
Completed: "2018-02-08T23:20:25Z",
GroupID: projectID,
ID: "5a7cdb3980eef53de5bffdcf",
Links: []*atlas.Link{
Links: []*Link{
{
Rel: "self",
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5c8100bcf2a30b12ff88258f/clusters/Cluster0/checkpoints",
},
},
Parts: []*atlas.Part{
Parts: []*Part{
{
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 2,
}},
Expand All @@ -201,41 +200,41 @@ func TestCheckpoints_List(t *testing.T) {
Completed: "2018-02-09T14:50:33Z",
GroupID: projectID,
ID: "5a7db53987d9d64fe298ff46",
Links: []*atlas.Link{
Links: []*Link{
{
Rel: "self",
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5c8100bcf2a30b12ff88258f/clusters/Cluster0/checkpoints?pretty=true",
},
},
Parts: []*atlas.Part{
Parts: []*Part{
{
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 2,
}},
},
{
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-09T14:50:33Z",
Increment: 4,
}},
Expand All @@ -246,7 +245,7 @@ func TestCheckpoints_List(t *testing.T) {
Timestamp: "2018-02-09T14:50:18Z",
},
},
Links: []*atlas.Link{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5c8100bcf2a30b12ff88258f/clusters/Cluster0/checkpoints?pageNum=1&itemsPerPage=100",
Rel: "self",
Expand Down Expand Up @@ -322,26 +321,26 @@ func TestCheckpoints_Get(t *testing.T) {
t.Fatalf("Checkpoints.Get returned error: %v", err)
}

expected := &atlas.Checkpoint{
expected := &Checkpoint{
ClusterID: clusterID,
Completed: "2018-02-08T23:20:25Z",
GroupID: projectID,
ID: "5a7cdb3980eef53de5bffdcf",
Links: []*atlas.Link{
Links: []*Link{
{
Rel: "self",
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5c8100bcf2a30b12ff88258f/clusters/Cluster0/checkpoints",
},
},
Parts: []*atlas.Part{
Parts: []*Part{

{
ReplicaSetName: "Cluster0-shard-1",
TypeName: "REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-1",
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
},
Expand All @@ -350,20 +349,20 @@ func TestCheckpoints_Get(t *testing.T) {
{
ReplicaSetName: "Cluster0-shard-0",
TypeName: "REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
ShardName: "Cluster0-shard-0",
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 1,
}},
},
{
ReplicaSetName: "Cluster0-config-0",
TypeName: "CONFIG_SERVER_REPLICA_SET",
CheckpointPart: atlas.CheckpointPart{
CheckpointPart: CheckpointPart{
TokenDiscovered: true,
TokenTimestamp: atlas.SnapshotTimestamp{
TokenTimestamp: SnapshotTimestamp{
Date: "2018-02-08T23:20:25Z",
Increment: 2,
}},
Expand Down
5 changes: 5 additions & 0 deletions opsmngr/continuous_restore_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type (
ContinuousJobRequest = atlas.ContinuousJobRequest
)

type SnapshotTimestamp struct {
Date string `json:"date"`
Increment int64 `json:"increment"`
}

var _ atlas.ContinuousRestoreJobsService = &ContinuousRestoreJobsServiceOp{}

// List lists all continuous backup jobs in Atlas
Expand Down
70 changes: 63 additions & 7 deletions opsmngr/continuous_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,80 @@ import (
"context"
"fmt"
"net/http"

atlas "go.mongodb.org/atlas/mongodbatlas"
)

const (
continuousSnapshotsBasePath = "api/public/v1.0/groups/%s/clusters/%s/snapshots"
)

// ContinuousSnapshotsService is an interface for interfacing with the Continuous Snapshots.
type ContinuousSnapshotsService interface {
List(context.Context, string, string, *ListOptions) (*ContinuousSnapshots, *Response, error)
Get(context.Context, string, string, string) (*ContinuousSnapshot, *Response, error)
ChangeExpiry(context.Context, string, string, string, *ContinuousSnapshot) (*ContinuousSnapshot, *Response, error)
Delete(context.Context, string, string, string) (*Response, error)
}

// ContinuousSnapshotsServiceOp handles communication with the Continuous Snapshots related methods of the
// MongoDB Ops Manager API.
type ContinuousSnapshotsServiceOp service

var _ atlas.ContinuousSnapshotsService = &ContinuousSnapshotsServiceOp{}
// ContinuousSnapshot represents a cloud provider snapshot.
type ContinuousSnapshot struct {
ClusterID string `json:"clusterId,omitempty"`
Complete bool `json:"complete,omitempty"`
Created *SnapshotTimestamp `json:"created,omitempty"`
DoNotDelete *bool `json:"doNotDelete,omitempty"`
Expires string `json:"expires,omitempty"`
GroupID string `json:"groupId,omitempty"`
ID string `json:"id,omitempty"` // Unique identifier of the snapshot.
IsPossiblyInconsistent *bool `json:"isPossiblyInconsistent,omitempty"`
LastOplogAppliedTimestamp *SnapshotTimestamp `json:"lastOplogAppliedTimestamp,omitempty"`
Links []*Link `json:"links,omitempty"` // One or more links to sub-resources and/or related resources.
NamespaceFilterList *NamespaceFilter `json:"namespaceFilterList,omitempty"`
MissingShards []*MissingShard `json:"missingShards,omitempty"`
Parts []*Part `json:"parts,omitempty"`
}

type (
ContinuousSnapshots = atlas.ContinuousSnapshots
ContinuousSnapshot = atlas.ContinuousSnapshot
)
// ContinuousSnapshots represents all cloud provider snapshots.
type ContinuousSnapshots struct {
Results []*ContinuousSnapshot `json:"results,omitempty"` // Includes one ContinuousSnapshots 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.
}

type Part struct {
ReplicaSetName string `json:"replicaSetName"`
TypeName string `json:"typeName"`
SnapshotPart
CheckpointPart
}

type NamespaceFilter struct {
FilterList []string `json:"filterList"`
FilterType string `json:"filterType"`
}

type MissingShard struct {
ID string `json:"id"`
GroupID string `json:"groupId"`
TypeName string `json:"typeName"`
ClusterName string `json:"clusterName,omitempty"`
ShardName string `json:"shardName,omitempty"`
ReplicaSetName string `json:"replicaSetName"`
LastHeartbeat string `json:"lastHeartbeat"`
}

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"` //nolint:all
MongodVersion string `json:"mongodVersion"`
StorageSizeBytes int64 `json:"storageSizeBytes"`
}

// List lists continuous snapshots for the given cluster
//
Expand Down
Loading