@@ -24,14 +24,15 @@ import (
2424type ChangeStatus string
2525
2626const (
27- ChangeStatusApplied ChangeStatus = "APPLIED"
28- ChangeStatusPending ChangeStatus = "PENDING"
27+ ChangeStatusApplied ChangeStatus = "APPLIED"
28+ ChangeStatusPending ChangeStatus = "PENDING"
29+ clustersPath = "groups/%s/clusters"
30+ sampleDatasetLoadPath = "groups/%s/sampleDatasetLoad"
2931)
3032
31- const clustersPath = "groups/%s/clusters"
32-
3333// ClustersService is an interface for interfacing with the Clusters
3434// endpoints of the MongoDB Atlas API.
35+ //
3536// See more: https://docs.atlas.mongodb.com/reference/api/clusters/
3637type ClustersService interface {
3738 List (ctx context.Context , groupID string , options * ListOptions ) ([]Cluster , * Response , error )
@@ -42,6 +43,8 @@ type ClustersService interface {
4243 UpdateProcessArgs (ctx context.Context , groupID , clusterName string , args * ProcessArgs ) (* ProcessArgs , * Response , error )
4344 GetProcessArgs (ctx context.Context , groupID , clusterName string ) (* ProcessArgs , * Response , error )
4445 Status (ctx context.Context , groupID , clusterName string ) (ClusterStatus , * Response , error )
46+ LoadSampleDataset (ctx context.Context , groupID , clusterName string ) (* SampleDatasetJob , * Response , error )
47+ GetSampleDatasetStatus (ctx context.Context , groupID , id string ) (* SampleDatasetJob , * Response , error )
4548}
4649
4750// ClustersServiceOp handles communication with the Cluster related methods
@@ -182,6 +185,16 @@ type clustersResponse struct {
182185 TotalCount int `json:"totalCount,omitempty"`
183186}
184187
188+ // SampleDatasetJob represents a sample dataset job
189+ type SampleDatasetJob struct {
190+ ClusterName string `json:"clusterName"`
191+ CompleteDate string `json:"completeDate,omitempty"`
192+ CreateDate string `json:"createDate,omitempty"`
193+ ErrorMessage string `json:"errorMessage,omitempty"`
194+ ID string `json:"_id"`
195+ State string `json:"state"`
196+ }
197+
185198// DefaultDiskSizeGB represents the Tier and the default disk size for each one
186199// it can be use like: DefaultDiskSizeGB["AWS"]["M10"]
187200var DefaultDiskSizeGB = map [string ]map [string ]float64 {
@@ -238,6 +251,7 @@ var DefaultDiskSizeGB = map[string]map[string]float64{
238251}
239252
240253// List all clusters in the project associated to {GROUP-ID}.
254+ //
241255// See more: https://docs.atlas.mongodb.com/reference/api/clusters-get-all/
242256func (s * ClustersServiceOp ) List (ctx context.Context , groupID string , listOptions * ListOptions ) ([]Cluster , * Response , error ) {
243257 path := fmt .Sprintf (clustersPath , groupID )
@@ -267,6 +281,7 @@ func (s *ClustersServiceOp) List(ctx context.Context, groupID string, listOption
267281}
268282
269283// Get gets the cluster specified to {ClUSTER-NAME} from the project associated to {GROUP-ID}.
284+ //
270285// See more: https://docs.atlas.mongodb.com/reference/api/clusters-get-one/
271286func (s * ClustersServiceOp ) Get (ctx context.Context , groupID , clusterName string ) (* Cluster , * Response , error ) {
272287 if err := checkClusterNameParam (clusterName ); err != nil {
@@ -292,6 +307,7 @@ func (s *ClustersServiceOp) Get(ctx context.Context, groupID, clusterName string
292307}
293308
294309// Create adds a cluster to the project associated to {GROUP-ID}.
310+ //
295311// See more: https://docs.atlas.mongodb.com/reference/api/clusters-create-one/
296312func (s * ClustersServiceOp ) Create (ctx context.Context , groupID string , createRequest * Cluster ) (* Cluster , * Response , error ) {
297313 if createRequest == nil {
@@ -315,6 +331,7 @@ func (s *ClustersServiceOp) Create(ctx context.Context, groupID string, createRe
315331}
316332
317333// Update a cluster in the project associated to {GROUP-ID}
334+ //
318335// See more: https://docs.atlas.mongodb.com/reference/api/clusters-modify-one/
319336func (s * ClustersServiceOp ) Update (ctx context.Context , groupID , clusterName string , updateRequest * Cluster ) (* Cluster , * Response , error ) {
320337 if updateRequest == nil {
@@ -339,6 +356,7 @@ func (s *ClustersServiceOp) Update(ctx context.Context, groupID, clusterName str
339356}
340357
341358// Delete the cluster specified to {CLUSTER-NAME} from the project associated to {GROUP-ID}.
359+ //
342360// See more: https://docs.atlas.mongodb.com/reference/api/clusters-delete-one/
343361func (s * ClustersServiceOp ) Delete (ctx context.Context , groupID , clusterName string ) (* Response , error ) {
344362 if clusterName == "" {
@@ -360,6 +378,7 @@ func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName str
360378}
361379
362380// UpdateProcessArgs Modifies Advanced Configuration Options for One Cluster
381+ //
363382// See more: https://docs.atlas.mongodb.com/reference/api/clusters-modify-advanced-configuration-options/
364383func (s * ClustersServiceOp ) UpdateProcessArgs (ctx context.Context , groupID , clusterName string , updateRequest * ProcessArgs ) (* ProcessArgs , * Response , error ) {
365384 if updateRequest == nil {
@@ -384,6 +403,7 @@ func (s *ClustersServiceOp) UpdateProcessArgs(ctx context.Context, groupID, clus
384403}
385404
386405// GetProcessArgs gets the Advanced Configuration Options for One Cluster
406+ //
387407// See more: https://docs.atlas.mongodb.com/reference/api/clusters-get-advanced-configuration-options/#get-advanced-configuration-options-for-one-cluster
388408func (s * ClustersServiceOp ) GetProcessArgs (ctx context.Context , groupID , clusterName string ) (* ProcessArgs , * Response , error ) {
389409 if err := checkClusterNameParam (clusterName ); err != nil {
@@ -408,6 +428,53 @@ func (s *ClustersServiceOp) GetProcessArgs(ctx context.Context, groupID, cluster
408428 return root , resp , err
409429}
410430
431+ // LoadSampleDataset loads the sample dataset into your cluster.
432+ //
433+ // See more: https://docs.atlas.mongodb.com/reference/api/cluster/load-dataset/
434+ func (s * ClustersServiceOp ) LoadSampleDataset (ctx context.Context , groupID , clusterName string ) (* SampleDatasetJob , * Response , error ) {
435+ if err := checkClusterNameParam (clusterName ); err != nil {
436+ return nil , nil , err
437+ }
438+
439+ basePath := fmt .Sprintf (sampleDatasetLoadPath , groupID )
440+ escapedEntry := url .PathEscape (clusterName )
441+ path := fmt .Sprintf ("%s/%s" , basePath , escapedEntry )
442+
443+ req , err := s .Client .NewRequest (ctx , http .MethodPost , path , nil )
444+ if err != nil {
445+ return nil , nil , err
446+ }
447+
448+ root := new (SampleDatasetJob )
449+ resp , err := s .Client .Do (ctx , req , root )
450+ if err != nil {
451+ return nil , resp , err
452+ }
453+
454+ return root , resp , err
455+ }
456+
457+ // GetSampleDatasetStatus gets the Sample Dataset job
458+ //
459+ // See more: https://docs.atlas.mongodb.com/reference/api/cluster/check-dataset-status/
460+ func (s * ClustersServiceOp ) GetSampleDatasetStatus (ctx context.Context , groupID , id string ) (* SampleDatasetJob , * Response , error ) {
461+ basePath := fmt .Sprintf (sampleDatasetLoadPath , groupID )
462+ path := fmt .Sprintf ("%s/%s" , basePath , id )
463+
464+ req , err := s .Client .NewRequest (ctx , http .MethodGet , path , nil )
465+ if err != nil {
466+ return nil , nil , err
467+ }
468+
469+ root := new (SampleDatasetJob )
470+ resp , err := s .Client .Do (ctx , req , root )
471+ if err != nil {
472+ return nil , resp , err
473+ }
474+
475+ return root , resp , err
476+ }
477+
411478// Status gets the status of the operation on the Cluster.
412479//
413480// See more: https://docs.atlas.mongodb.com/reference/api/clusters-check-operation-status/
0 commit comments