diff --git a/opsmngr/checkpoints.go b/opsmngr/checkpoints.go index cd3276f..2575e2a 100644 --- a/opsmngr/checkpoints.go +++ b/opsmngr/checkpoints.go @@ -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. @@ -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") } @@ -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 @@ -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") } @@ -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 diff --git a/opsmngr/checkpoints_test.go b/opsmngr/checkpoints_test.go index b41fba9..8377a71 100644 --- a/opsmngr/checkpoints_test.go +++ b/opsmngr/checkpoints_test.go @@ -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 @@ -145,27 +144,27 @@ 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, }}, @@ -173,10 +172,10 @@ func TestCheckpoints_List(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, }}, @@ -184,9 +183,9 @@ func TestCheckpoints_List(t *testing.T) { { 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, }}, @@ -201,20 +200,20 @@ 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, }}, @@ -222,10 +221,10 @@ func TestCheckpoints_List(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-09T14:50:33Z", Increment: 2, }}, @@ -233,9 +232,9 @@ func TestCheckpoints_List(t *testing.T) { { 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, }}, @@ -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", @@ -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, }, @@ -350,10 +349,10 @@ 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, }}, @@ -361,9 +360,9 @@ func TestCheckpoints_Get(t *testing.T) { { 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, }}, diff --git a/opsmngr/continuous_restore_jobs.go b/opsmngr/continuous_restore_jobs.go index dcb2d1a..2f625f3 100644 --- a/opsmngr/continuous_restore_jobs.go +++ b/opsmngr/continuous_restore_jobs.go @@ -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 diff --git a/opsmngr/continuous_snapshots.go b/opsmngr/continuous_snapshots.go index 1ac5f77..297ad7f 100644 --- a/opsmngr/continuous_snapshots.go +++ b/opsmngr/continuous_snapshots.go @@ -37,6 +37,24 @@ type ( ContinuousSnapshot = atlas.ContinuousSnapshot ) +type Part struct { + 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"` +} + // List lists continuous snapshots for the given cluster // // See more: https://docs.opsmanager.mongodb.com/current/reference/api/snapshots/get-all-snapshots-for-one-cluster/ diff --git a/opsmngr/logs.go b/opsmngr/logs.go index f3eef22..0f70513 100644 --- a/opsmngr/logs.go +++ b/opsmngr/logs.go @@ -19,8 +19,6 @@ import ( "fmt" "io" "net/http" - - atlas "go.mongodb.org/atlas/mongodbatlas" ) const ( @@ -56,7 +54,7 @@ type LogsService interface { // LogsServiceOp handles communication with the Log Collection Jobs download method of the // MongoDB Ops Manager API. type LogsServiceOp struct { - Client atlas.GZipRequestDoer + Client GZipRequestDoer } var _ LogsService = &LogsServiceOp{} diff --git a/opsmngr/opsmngr.go b/opsmngr/opsmngr.go index 060ba38..102f911 100644 --- a/opsmngr/opsmngr.go +++ b/opsmngr/opsmngr.go @@ -48,10 +48,6 @@ type ( APIKey = atlas.APIKey APIKeyInput = atlas.APIKeyInput AssignAPIKey = atlas.AssignAPIKey - Part = atlas.Part - Checkpoint = atlas.Checkpoint - Checkpoints = atlas.Checkpoints - SnapshotTimestamp = atlas.SnapshotTimestamp IndexOptions = atlas.IndexOptions CollationOptions = atlas.CollationOptions Team = atlas.Team @@ -78,6 +74,23 @@ type HTTPClient interface { Do(req *http.Request) (*http.Response, error) } +// Doer basic interface of a client to be able to do a request. +type Doer interface { + Do(context.Context, *http.Request, interface{}) (*Response, error) +} + +// Completer interface for clients with callback. +type Completer interface { + OnRequestCompleted(RequestCompletionCallback) +} + +// GZipRequestDoer minimum interface for any service of the client that should handle gzip downloads. +type GZipRequestDoer interface { + Doer + Completer + NewGZipRequest(context.Context, string, string) (*http.Request, error) +} + // Client manages communication with Ops Manager API. type Client struct { client HTTPClient