Skip to content

Commit 3230017

Browse files
authored
Add global cluster support for advanced cluster (#337)
1 parent 322c879 commit 3230017

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

mongodbatlas/global_clusters.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"net/http"
2121
)
2222

23-
const globalClustersBasePath = "api/atlas/v1.0/groups/%s/clusters/%s/globalWrites/%s"
23+
const globalClustersBasePath = "api/atlas/v1.5/groups/%s/clusters/%s/globalWrites/%s"
2424

2525
// GlobalClustersService is an interface for interfacing with the Global Clusters
2626
// endpoints of the MongoDB Atlas API.
@@ -53,6 +53,8 @@ type ManagedNamespace struct {
5353
CustomShardKey string `json:"customShardKey,omitempty"`
5454
IsCustomShardKeyHashed *bool `json:"isCustomShardKeyHashed,omitempty"` // Flag that specifies whether the custom shard key for the collection is hashed.
5555
IsShardKeyUnique *bool `json:"isShardKeyUnique,omitempty"` // Flag that specifies whether the underlying index enforces a unique constraint.
56+
NumInitialChunks int `json:"numInitialChunks,omitempty"`
57+
PresplitHashedZones *bool `json:"presplitHashedZones,omitempty"`
5658
}
5759

5860
// CustomZoneMappingsRequest represents the request related to add custom zone mappings to a global cluster.
@@ -71,10 +73,14 @@ type CustomZoneMapping struct {
7173
// See more: https://docs.atlas.mongodb.com/reference/api/global-clusters-retrieve-namespaces/
7274
func (s *GlobalClustersServiceOp) Get(ctx context.Context, groupID, clusterName string) (*GlobalCluster, *Response, error) {
7375
if clusterName == "" {
74-
return nil, nil, NewArgError("username", "must be set")
76+
return nil, nil, NewArgError("clusterName", "must be set")
7577
}
7678

77-
path := fmt.Sprintf("api/atlas/v1.0/groups/%s/clusters/%s/globalWrites", groupID, clusterName)
79+
if groupID == "" {
80+
return nil, nil, NewArgError("groupID", "must be set")
81+
}
82+
83+
path := fmt.Sprintf(globalClustersBasePath, groupID, clusterName, "")
7884

7985
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
8086
if err != nil {

mongodbatlas/global_clusters_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestGlobalClusters_Get(t *testing.T) {
3131
groupID := "1"
3232
clusterName := "appData"
3333

34-
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/globalWrites", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
34+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/globalWrites/", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
3535
testMethod(t, r, http.MethodGet)
3636
fmt.Fprint(w, ` {
3737
"customZoneMapping" : {
@@ -53,7 +53,9 @@ func TestGlobalClusters_Get(t *testing.T) {
5353
"customShardKey" : "city",
5454
"db" : "mydata",
5555
"isCustomShardKeyHashed" : true,
56-
"isShardKeyUnique" : true
56+
"isShardKeyUnique" : true,
57+
"numInitialChunks" : 4,
58+
"presplitHashedZones" : true
5759
},{
5860
"collection" : "stores",
5961
"customShardKey" : "store_number",
@@ -89,6 +91,8 @@ func TestGlobalClusters_Get(t *testing.T) {
8991
Db: "mydata",
9092
IsCustomShardKeyHashed: pointy.Bool(true),
9193
IsShardKeyUnique: pointy.Bool(true),
94+
NumInitialChunks: 4,
95+
PresplitHashedZones: pointy.Bool(true),
9296
}, {
9397
Collection: "stores",
9498
CustomShardKey: "store_number",
@@ -115,15 +119,19 @@ func TestGlobalClusters_AddManagedNamespace(t *testing.T) {
115119
CustomShardKey: "city",
116120
IsCustomShardKeyHashed: pointy.Bool(true),
117121
IsShardKeyUnique: pointy.Bool(true),
122+
NumInitialChunks: 4,
123+
PresplitHashedZones: pointy.Bool(true),
118124
}
119125

120-
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/globalWrites/managedNamespaces", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
126+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/globalWrites/managedNamespaces", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
121127
expectedRequest := map[string]interface{}{
122128
"db": "mydata",
123129
"collection": "publishers",
124130
"customShardKey": "city",
125131
"isCustomShardKeyHashed": true,
126132
"isShardKeyUnique": true,
133+
"numInitialChunks": float64(4),
134+
"presplitHashedZones": true,
127135
}
128136

129137
jsonBlob := `
@@ -209,7 +217,7 @@ func TestGlobalClusters_DeleteManagedNamespace(t *testing.T) {
209217
Collection: "distributors",
210218
}
211219

212-
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/globalWrites/managedNamespaces", groupID, name), func(w http.ResponseWriter, r *http.Request) {
220+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/globalWrites/managedNamespaces", groupID, name), func(w http.ResponseWriter, r *http.Request) {
213221
if collection := r.URL.Query().Get("collection"); collection != mn.Collection {
214222
t.Errorf("expected query param collection = '%s', received '%s'", mn.Collection, collection)
215223
}
@@ -305,7 +313,7 @@ func TestGlobalClusters_AddCustomZoneMappings(t *testing.T) {
305313
},
306314
}
307315

308-
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/globalWrites/customZoneMapping", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
316+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/globalWrites/customZoneMapping", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
309317
expectedRequest := map[string]interface{}{
310318
"customZoneMappings": []interface{}{
311319
map[string]interface{}{"location": "CA", "zone": "Zone 1"},
@@ -358,7 +366,7 @@ func TestGlobalClusters_DeleteCustomZoneMappings(t *testing.T) {
358366
groupID := "1"
359367
name := "appData"
360368

361-
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/globalWrites/customZoneMapping", groupID, name), func(w http.ResponseWriter, r *http.Request) {
369+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/globalWrites/customZoneMapping", groupID, name), func(w http.ResponseWriter, r *http.Request) {
362370
jsonBlob := `
363371
{
364372
"customZoneMapping" : { },

0 commit comments

Comments
 (0)