Skip to content

Commit 2e7ac09

Browse files
authored
Merge pull request Azure#11388 from MehaKaushik/20200317
[CosmosDB] Allow Account creation with ApiKind in Cassandra, Gremlin, Table + Bug Fixes
2 parents 624fd79 + 3c67155 commit 2e7ac09

10 files changed

+89
-42
lines changed

src/CosmosDB/CosmosDB/Cassandra/GetAzCosmosDBCassandraTableThroughput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override void ExecuteCmdlet()
5858
}
5959

6060
ThroughputSettingsGetResults throughputSettingsGetResults = CosmosDBManagementClient.CassandraResources.GetCassandraTableThroughputWithHttpMessagesAsync(ResourceGroupName, AccountName, KeyspaceName, Name).GetAwaiter().GetResult().Body;
61-
WriteObject(throughputSettingsGetResults);
61+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
6262

6363
return;
6464
}

src/CosmosDB/CosmosDB/ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Allowing Account Creation for API Types: Gremlin, Cassandra and Table.
23+
* Bug Fixes
24+
25+
## Version 0.1.2
26+
* Updated the Azure.Management.CosmosDB Sdk Version to 1.0.2
27+
-Fix bugs related to https://github.com/Azure/azure-sdk-for-net/issues/10639
2228

2329
## Version 0.1.2
2430
* Updated the Azure.Management.CosmosDB Sdk Version to 1.0.2

src/CosmosDB/CosmosDB/CosmosDBAccount/NewAzCosmosDBAccount.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class NewAzCosmosDBAccount : AzureCosmosDBCmdletBase
8181
public PSVirtualNetworkRule[] VirtualNetworkRuleObject { get; set; }
8282

8383
[Parameter(Mandatory = false, HelpMessage = Constants.ApiKindHelpMessage)]
84-
[PSArgumentCompleter("GlobalDocumentDB", "MongoDB", "Others")]
84+
[PSArgumentCompleter("GlobalDocumentDB", "MongoDB", "Gremlin", "Cassandra", "Table")]
8585
public string ApiKind { get; set; }
8686

8787
[Parameter(Mandatory = false, HelpMessage = Constants.AsJobHelpMessage)]
@@ -121,18 +121,6 @@ public override void ExecuteCmdlet()
121121
}
122122
}
123123

124-
if(!string.IsNullOrEmpty(ApiKind))
125-
{
126-
if (!ApiKind.Equals("GlobalDocumentDB", StringComparison.OrdinalIgnoreCase) && !ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
127-
{
128-
WriteWarning("Gremlin, Cassandra and Table account creation not supported" +
129-
"in Azure Powershell");
130-
return;
131-
}
132-
}
133-
else
134-
ApiKind = "GlobalDocumentDB";
135-
136124
string writeLocation = null;
137125
Collection<Location> LocationCollection = new Collection<Location>();
138126

@@ -185,15 +173,15 @@ public override void ExecuteCmdlet()
185173
}
186174

187175
Collection<VirtualNetworkRule> virtualNetworkRule = new Collection<VirtualNetworkRule>();
188-
if ((VirtualNetworkRule != null && VirtualNetworkRule.Length > 0) ||
189-
(VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0))
176+
if (VirtualNetworkRule != null && VirtualNetworkRule.Length > 0)
190177
{
191-
192178
foreach (string id in VirtualNetworkRule)
193179
{
194180
virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
195181
}
196-
182+
}
183+
if(VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0)
184+
{
197185
foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
198186
{
199187
virtualNetworkRule.Add(PSVirtualNetworkRule.ConvertPSVirtualNetworkRuleToVirtualNetworkRule(psVirtualNetworkRule));
@@ -214,12 +202,38 @@ public override void ExecuteCmdlet()
214202
}
215203
}
216204

217-
DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations:LocationCollection, location: writeLocation, name:Name, kind:ApiKind, consistencyPolicy:consistencyPolicy, tags:tags, ipRangeFilter:IpRangeFilterAsString);
205+
DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations:LocationCollection, location: writeLocation, name:Name, consistencyPolicy:consistencyPolicy, tags:tags, ipRangeFilter:IpRangeFilterAsString);
218206
databaseAccountCreateUpdateParameters.EnableMultipleWriteLocations = EnableMultipleWriteLocations;
219207
databaseAccountCreateUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
220208
databaseAccountCreateUpdateParameters.EnableAutomaticFailover = EnableAutomaticFailover;
221209
databaseAccountCreateUpdateParameters.VirtualNetworkRules = virtualNetworkRule;
222210

211+
if (!string.IsNullOrEmpty(ApiKind))
212+
{
213+
if (!ApiKind.Equals("GlobalDocumentDB", StringComparison.OrdinalIgnoreCase) && !ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
214+
{
215+
switch (ApiKind)
216+
{
217+
case "Cassandra":
218+
databaseAccountCreateUpdateParameters.Capabilities = new List<Capability> { new Capability { Name = "EnableCassandra" } };
219+
break;
220+
case "Gremlin":
221+
databaseAccountCreateUpdateParameters.Capabilities = new List<Capability> { new Capability { Name = "EnableGremlin" } };
222+
break;
223+
case "Table":
224+
databaseAccountCreateUpdateParameters.Capabilities = new List<Capability> { new Capability { Name = "EnableTable" } };
225+
break;
226+
}
227+
228+
ApiKind = null;
229+
}
230+
}
231+
else
232+
{
233+
ApiKind = "GlobalDocumentDB";
234+
}
235+
databaseAccountCreateUpdateParameters.Kind = ApiKind;
236+
223237
if (ShouldProcess(Name, "Creating Database Account"))
224238
{
225239
DatabaseAccountGetResults cosmosDBAccount = CosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, Name, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;

src/CosmosDB/CosmosDB/CosmosDBAccount/UpdateAzCosmosDBAccount.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,23 @@ public override void ExecuteCmdlet()
152152
databaseAccountUpdateParameters.Tags = tags;
153153
}
154154

155-
if ( ( VirtualNetworkRule != null && VirtualNetworkRule.Length > 0) ||
156-
(VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0))
155+
if (VirtualNetworkRule != null || VirtualNetworkRuleObject != null)
157156
{
158157
Collection<VirtualNetworkRule> virtualNetworkRule = new Collection<VirtualNetworkRule>();
159-
160-
foreach (string id in VirtualNetworkRule)
158+
if (VirtualNetworkRule != null && VirtualNetworkRule.Length > 0)
161159
{
162-
virtualNetworkRule.Add(new VirtualNetworkRule(id:id));
160+
foreach (string id in VirtualNetworkRule)
161+
{
162+
virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
163+
}
163164
}
164-
165-
foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
165+
if (VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0)
166166
{
167-
virtualNetworkRule.Add(PSVirtualNetworkRule.ConvertPSVirtualNetworkRuleToVirtualNetworkRule(psVirtualNetworkRule));
167+
foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
168+
{
169+
virtualNetworkRule.Add(PSVirtualNetworkRule.ConvertPSVirtualNetworkRuleToVirtualNetworkRule(psVirtualNetworkRule));
170+
}
168171
}
169-
170172
databaseAccountUpdateParameters.VirtualNetworkRules = virtualNetworkRule;
171173
}
172174

src/CosmosDB/CosmosDB/CosmosDBAccount/UpdateAzCosmosDBAccountRegion.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class UpdateAzCosmosDBAccountRegion : AzureCosmosDBCmdletBase
4646
[ValidateNotNullOrEmpty]
4747
public string ResourceId { get; set; }
4848

49-
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.ResourceIdHelpMessage)]
49+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.AccountObjectHelpMessage)]
5050
[ValidateNotNull]
5151
public PSDatabaseAccount InputObject { get; set; }
5252

@@ -72,18 +72,21 @@ public override void ExecuteCmdlet()
7272
}
7373

7474
List<Location> locations = new List<Location>();
75-
76-
if( (Location != null && Location.Length > 0) ||
77-
(LocationObject != null && LocationObject.Length > 0))
75+
if (Location != null || LocationObject != null)
7876
{
79-
foreach (string location in Location)
77+
if (Location != null && Location.Length > 0)
8078
{
81-
locations.Add(new Location(location));
79+
foreach (string location in Location)
80+
{
81+
locations.Add(new Location(location));
82+
}
8283
}
83-
84-
foreach (PSLocation psLocation in LocationObject)
84+
if (LocationObject != null && LocationObject.Length > 0)
8585
{
86-
locations.Add(PSLocation.ConvertPSLocationToLocation(psLocation));
86+
foreach (PSLocation psLocation in LocationObject)
87+
{
88+
locations.Add(PSLocation.ConvertPSLocationToLocation(psLocation));
89+
}
8790
}
8891
}
8992
else

src/CosmosDB/CosmosDB/Helpers/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal static class Constants
2626
public const string AccountKeyKindHelpMessage = "The access key to regenerate. Accepted values: primary, primaryReadonly, secondary, secondaryReadonly ";
2727
public const string AccountFailoverPolicyHelpMessage = "Array of strings having region names, ordered by failover priority. E.g eastus, westus";
2828
public const string AccountObjectHelpMessage = "CosmosDB Account object";
29-
public const string AccountUpdateLocationHelpMessage = "Name of the location to be added.";
29+
public const string AccountUpdateLocationHelpMessage = "The georeplication location to be enabled for the Cosmos DB account, can be a single string or an array of strings.";
3030
public const string DefaultConsistencyLevelHelpMessage = "Default consistency level of the Cosmos DB database account. Accepted values: BoundedStaleness, ConsistentPrefix, Eventual, Session, Strong. Default is Session.";
3131
public const string EnableAutomaticFailoverHelpMessage = "Enables automatic failover of the write region in the rare event that the region is unavailable due to an outage. Automatic failover will result" +
3232
" in a new write region for the account and is chosen based on the failover priorities configured for the account. Accepted values: false, true ";

src/CosmosDB/CosmosDB/Models/PSCassandraSchema.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ public PSCassandraSchema()
2525

2626
public PSCassandraSchema(CassandraSchema cassandraSchema)
2727
{
28+
Columns = new List<PSColumn>();
29+
foreach (Column column in cassandraSchema.Columns)
30+
{
31+
Columns.Add(new PSColumn(column));
32+
}
33+
34+
PartitionKeys = new List<PSCassandraPartitionKey>();
35+
foreach (CassandraPartitionKey cassandraPartitionKey in cassandraSchema.PartitionKeys)
36+
{
37+
PartitionKeys.Add(new PSCassandraPartitionKey(cassandraPartitionKey));
38+
}
39+
40+
ClusterKeys = new List<PSClusterKey>();
41+
foreach (ClusterKey clusterKey in cassandraSchema.ClusterKeys)
42+
{
43+
ClusterKeys.Add(new PSClusterKey(clusterKey));
44+
}
2845
}
2946

3047
//

src/CosmosDB/CosmosDB/Models/PSMongoDBCollectionGetPropertiesResource.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public class PSMongoDBCollectionGetPropertiesResource
2121
{
2222
public PSMongoDBCollectionGetPropertiesResource(MongoDBCollectionGetPropertiesResource mongoDBCollectionGetPropertiesResource)
2323
{
24+
Id = mongoDBCollectionGetPropertiesResource.Id;
25+
if (mongoDBCollectionGetPropertiesResource.ShardKey != null)
26+
{
27+
ShardKey = new Dictionary<string, string>(mongoDBCollectionGetPropertiesResource.ShardKey);
28+
}
2429
List<PSMongoIndex> psMongoIndex = new List<PSMongoIndex>();
2530
if (mongoDBCollectionGetPropertiesResource.Indexes != null)
2631
{

src/CosmosDB/CosmosDB/help/Get-AzCosmosDBAccount.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ FailoverPolicies : {databaseAccountName-region1}
3939
ReadLocations : {databaseAccountName-region1}
4040
WriteLocations : {databaseAccountName-region1}
4141
Capabilities : {}
42-
ConsistencyPolicy : Microsoft.Azure.Management.CosmosDB.Fluent.Models.ConsistencyPolicy
42+
ConsistencyPolicy : Microsoft.Azure.Management.CosmosDB.Models.ConsistencyPolicy
4343
EnableAutomaticFailover : False
4444
IsVirtualNetworkFilterEnabled : False
4545
IpRangeFilter :

src/CosmosDB/CosmosDB/help/New-AzCosmosDBAccount.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
external help file: Microsoft.Azure.PowerShell.Cmdlets.CosmosDB.dll-Help.xml
33
Module Name: Az.CosmosDB
4-
online version: https://docs.microsoft.com/en-us/powershell/module/az.cosmosdb/new-azcosmosdbaccountkey
4+
online version: https://docs.microsoft.com/en-us/powershell/module/az.cosmosdb/new-azcosmosdbaccount
55
schema: 2.0.0
66
---
77

@@ -37,7 +37,7 @@ DatabaseAccountOfferType : Standard
3737
IpRangeFilter :
3838
IsVirtualNetworkFilterEnabled : False
3939
EnableAutomaticFailover : False
40-
ConsistencyPolicy : Microsoft.Azure.Management.CosmosDB.Fluent.Models.ConsistencyPolicy
40+
ConsistencyPolicy : Microsoft.Azure.Management.CosmosDB.Models.ConsistencyPolicy
4141
Capabilities : {}
4242
WriteLocations : {databaseAccountName-eastus}
4343
ReadLocations : {databaseAccountName-eastus}
@@ -57,7 +57,7 @@ A new CosmosDB Account with name databaseAccountName is created in the ResourceG
5757

5858
### -ApiKind
5959
The type of Cosmos DB database account to create.
60-
Accepted values: GlobalDocumentDB, Sql, MongoDB, Gremlin, Table, Cassandra.
60+
Accepted values: GlobalDocumentDB, MongoDB, Gremlin, Table, Cassandra.
6161
Default value: GlobalDocumentDB
6262

6363
```yaml

0 commit comments

Comments
 (0)