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 5 commits
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
97 changes: 97 additions & 0 deletions mongodbatlas/checkpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package mongodbatlas

import (
"context"
"fmt"
"net/http"
)

const (
backupCheckpoints = "groups/%s/clusters/%s/backupCheckpoints"
)

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

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

var _ CheckpointsService = &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"`
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"`
}

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 CheckpointsServiceOp) List(ctx context.Context, groupID, clusterName string, listOptions *ListOptions) (*Checkpoints, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupId", "must be set")
}
if clusterName == "" {
return nil, nil, NewArgError("clusterName", "must be set")
}

path := fmt.Sprintf(backupCheckpoints, groupID, clusterName)

req, err := s.Client.NewRequest(ctx, http.MethodGet, path, listOptions)
if err != nil {
return nil, nil, err
}

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

return root, resp, err
}

func (s CheckpointsServiceOp) Get(ctx context.Context, groupID, clusterName, checkpointID string) (*Checkpoint, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupId", "must be set")
}
if clusterName == "" {
return nil, nil, NewArgError("clusterName", "must be set")
}
if checkpointID == "" {
return nil, nil, NewArgError("checkpointID", "must be set")
}

basePath := fmt.Sprintf(backupCheckpoints, groupID, clusterName)
path := fmt.Sprintf("%s/%s", basePath, checkpointID)
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)

if err != nil {
return nil, nil, err
}

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

return root, resp, err
}