Skip to content

Commit d1d99e3

Browse files
Merge pull request #200 from RedisLabs/feat/active-active-regions
API call for regions of an active active subscription
2 parents a10b8fc + af2f499 commit d1d99e3

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

service/subscriptions/model.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ type listSubscriptionResponse struct {
278278
Subscriptions []*Subscription `json:"subscriptions"`
279279
}
280280

281+
type ListSubscriptionRegionsResponse struct {
282+
SubscriptionId *int `json:"subscriptionId,omitempty"`
283+
Regions []*ActiveActiveRegion `json:"regions"`
284+
}
285+
286+
// have to redeclare these here (copied from regions model) to avoid an import cycle
287+
type ActiveActiveRegion struct {
288+
RegionId *int `json:"regionId,omitempty"`
289+
Region *string `json:"region,omitempty"`
290+
DeploymentCIDR *string `json:"deploymentCIDR,omitempty"`
291+
VpcId *string `json:"vpcId,omitempty"`
292+
Databases []ActiveActiveDatabase `json:"databases,omitempty"`
293+
}
294+
type ActiveActiveDatabase struct {
295+
DatabaseId *int `json:"databaseId,omitempty"`
296+
DatabaseName *string `json:"databaseName,omitempty"`
297+
ReadOperationsPerSecond *int `json:"readOperationsPerSecond,omitempty"`
298+
WriteOperationsPerSecond *int `json:"writeOperationsPerSecond,omitempty"`
299+
}
300+
281301
type NotFound struct {
282302
ID int
283303
}

service/subscriptions/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ func (a *API) DeleteActiveActiveVPCPeering(ctx context.Context, subscription int
238238
return a.taskWaiter.Wait(ctx, *task.ID)
239239
}
240240

241+
func (a *API) ListActiveActiveRegions(ctx context.Context, subscription int) ([]*ActiveActiveRegion, error) {
242+
var response ListSubscriptionRegionsResponse
243+
err := a.client.Get(ctx, "list regions", fmt.Sprintf("/subscriptions/%d/regions", subscription), &response)
244+
245+
if err != nil {
246+
return nil, err
247+
}
248+
249+
return response.Regions, nil
250+
}
251+
241252
func wrap404Error(id int, err error) error {
242253
if v, ok := err.(*internal.HTTPError); ok && v.StatusCode == http.StatusNotFound {
243254
return &NotFound{ID: id}

subscription_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,95 @@ func TestSubscription_DeleteVPCPeering(t *testing.T) {
792792
err = subject.Subscription.DeleteVPCPeering(context.TODO(), 2, 20)
793793
require.NoError(t, err)
794794
}
795+
796+
func TestSubscription_ListActiveActiveRegions(t *testing.T) {
797+
s := httptest.NewServer(testServer("apiKey", "secret", getRequest(t, "/subscriptions/1986/regions",
798+
`
799+
{
800+
"subscriptionId": 1986,
801+
"regions": [
802+
{
803+
"regionId": 12,
804+
"region": "us-east-1",
805+
"deploymentCidr": "192.169.0.0/24",
806+
"vpcId": "vpc-0e828cd5c0c580389",
807+
"databases": [
808+
{
809+
"databaseId": 645,
810+
"databaseName": "database-name",
811+
"readOperationsPerSecond": 1000,
812+
"writeOperationsPerSecond": 1000,
813+
"respVersion": "resp3",
814+
"links": []
815+
}
816+
],
817+
"links": []
818+
},
819+
{
820+
"regionId": 19,
821+
"region": "us-east-2",
822+
"deploymentCidr": "11.0.1.0/24",
823+
"vpcId": "vpc-0aecab539b31057a5",
824+
"databases": [
825+
{
826+
"databaseId": 645,
827+
"databaseName": "database-name",
828+
"readOperationsPerSecond": 1000,
829+
"writeOperationsPerSecond": 1000,
830+
"respVersion": "resp3",
831+
"links": []
832+
}
833+
],
834+
"links": []
835+
}
836+
],
837+
"links": [
838+
{
839+
"href": "https://api-staging.qa.redislabs.com/v1/subscriptions/118802/regions",
840+
"type": "GET",
841+
"rel": "self"
842+
}
843+
]
844+
}
845+
`)))
846+
847+
subject, err := clientFromTestServer(s, "apiKey", "secret")
848+
require.NoError(t, err)
849+
850+
actual, err := subject.Subscription.ListActiveActiveRegions(context.TODO(), 1986)
851+
require.NoError(t, err)
852+
853+
var expected = listRegionsExpected()
854+
assert.Equal(t, expected, actual)
855+
856+
}
857+
858+
func listRegionsExpected() []*subscriptions.ActiveActiveRegion {
859+
860+
// Initialize databases
861+
database := subscriptions.ActiveActiveDatabase{
862+
DatabaseId: redis.Int(645),
863+
DatabaseName: redis.String("database-name"),
864+
ReadOperationsPerSecond: redis.Int(1000),
865+
WriteOperationsPerSecond: redis.Int(1000),
866+
}
867+
868+
// Initialize regions
869+
region1Struct := &subscriptions.ActiveActiveRegion{
870+
RegionId: redis.Int(12),
871+
Region: redis.String("us-east-1"),
872+
DeploymentCIDR: redis.String("192.169.0.0/24"),
873+
VpcId: redis.String("vpc-0e828cd5c0c580389"),
874+
Databases: []subscriptions.ActiveActiveDatabase{database},
875+
}
876+
877+
region2Struct := &subscriptions.ActiveActiveRegion{
878+
RegionId: redis.Int(19),
879+
Region: redis.String("us-east-2"),
880+
DeploymentCIDR: redis.String("11.0.1.0/24"),
881+
VpcId: redis.String("vpc-0aecab539b31057a5"),
882+
Databases: []subscriptions.ActiveActiveDatabase{database},
883+
}
884+
885+
return []*subscriptions.ActiveActiveRegion{region1Struct, region2Struct}
886+
}

0 commit comments

Comments
 (0)