Skip to content

[CosmosDB] Bug Fixes and Enhancements #11513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@ public void TestAccountRelatedCmdletsUsingObject()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingObject");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAddRegionOperation()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AddRegionOperation");
}
}
}
19 changes: 19 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,23 @@ function Test-AccountRelatedCmdletsUsingObject

$IsAccountDeleted = Remove-AzCosmosDBAccount -InputObject $cosmosDBAccount -PassThru
Assert-AreEqual $IsAccountDeleted true
}

function Test-AddRegionOperation
{
$rgName = "CosmosDBResourceGroup2"
$location = "East US"
$locationlist = "East US", "West US"
$cosmosDBAccountName = "testupdateregion"
$resourceGroup = New-AzResourceGroup -ResourceGroupName $rgName -Location $location

$cosmosDBAccount = New-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName -Location $location -EnableMultipleWriteLocations -EnableAutomaticFailover
do
{
$cosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName
} while ($cosmosDBAccount.ProvisioningState -ne "Succeeded")

$updatedCosmosDBAccount = Update-AzCosmosDBAccountRegion -ResourceGroupName $rgName -Name $cosmosDBAccountName -Location $locationlist
$updatedCosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName
Assert-AreEqual $cosmosDBAccount.Locations.Count $updatedCosmosDBAccount.Locations.Count - 1
}

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/CosmosDB/CosmosDB/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
-->

## Upcoming Release
* Changes in New-AzCosmosDBAccount and Update-AzCosmosDBAccount
- Allows empty string as a value for IpRangeFilter
- Renamed ApiKind value GlobalDocumentDB to Sql.
- Added parameter DisableKeyBasedMetadataWriteAccess
* Introduces cmdlets to update throughput for Sql Database and Container, Cassandra Keyspace and Table, MongoDB Database and Collection, Gremlin Database and Graph and Table.
- Update-AzCosmosDBSqlContainerThroughput, Update-AzCosmosDBSqlDatabaseThroughput,
Update-AzCosmosDBMongoDBCollectionThroughput, Update-AzCosmosDBMongoDBDatabaseThroughput,
Update-AzCosmosDBGremlinGraphThroughput, Update-AzCosmosDBGremlinDatabaseThroughput,
Update-AzCosmosDBCassandraTableThroughput, Update-AzCosmosDBCassandraKeyspaceThroughput,
Update-AzCosmosDBTableThroughput

- Update-AzCosmosDBSqlContainerThroughput, Update-AzCosmosDBSqlDatabaseThroughput,
Update-AzCosmosDBMongoDBCollectionThroughput, Update-AzCosmosDBMongoDBDatabaseThroughput,
Update-AzCosmosDBGremlinGraphThroughput, Update-AzCosmosDBGremlinDatabaseThroughput,
Update-AzCosmosDBCassandraTableThroughput, Update-AzCosmosDBCassandraKeyspaceThroughput,
Update-AzCosmosDBTableThroughput
## Version 0.1.3
* Allowing Account Creation for API Types: Gremlin, Cassandra and Table.
* Bug Fixes
Expand Down
24 changes: 12 additions & 12 deletions src/CosmosDB/CosmosDB/CosmosDBAccount/NewAzCosmosDBAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Commands.CosmosDB.Models;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class NewAzCosmosDBAccount : AzureCosmosDBCmdletBase
public SwitchParameter EnableVirtualNetwork { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.IpRangeFilterHelpMessage)]
[ValidateNotNullOrEmpty]
[ValidateNotNull]
public string[] IpRangeFilter { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.LocationHelpMessage)]
Expand Down Expand Up @@ -81,9 +82,12 @@ public class NewAzCosmosDBAccount : AzureCosmosDBCmdletBase
public PSVirtualNetworkRule[] VirtualNetworkRuleObject { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.ApiKindHelpMessage)]
[PSArgumentCompleter("GlobalDocumentDB", "MongoDB", "Gremlin", "Cassandra", "Table")]
[PSArgumentCompleter("Sql", "MongoDB", "Gremlin", "Cassandra", "Table")]
public string ApiKind { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.DisableKeyBasedMetadataWriteAccessHelpMessage)]
public SwitchParameter DisableKeyBasedMetadataWriteAccess { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.AsJobHelpMessage)]
public SwitchParameter AsJob { get; set; }

Expand Down Expand Up @@ -191,26 +195,20 @@ public override void ExecuteCmdlet()
string IpRangeFilterAsString = null;
if (IpRangeFilter != null && IpRangeFilter.Length > 0)
{
for (int i = 0; i < IpRangeFilter.Length; i++)
{
if (i == 0)
{
IpRangeFilterAsString = IpRangeFilter[0];
}
else
IpRangeFilterAsString = string.Concat(IpRangeFilterAsString, ",", IpRangeFilter[i]);
}
IpRangeFilterAsString = IpRangeFilter?.Aggregate(string.Empty, (output, next) => string.Concat(output, (!string.IsNullOrWhiteSpace(output) && !string.IsNullOrWhiteSpace(next) ? "," : string.Empty), next)) ?? string.Empty;
}

DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations:LocationCollection, location: writeLocation, name:Name, consistencyPolicy:consistencyPolicy, tags:tags, ipRangeFilter:IpRangeFilterAsString);
databaseAccountCreateUpdateParameters.EnableMultipleWriteLocations = EnableMultipleWriteLocations;
databaseAccountCreateUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
databaseAccountCreateUpdateParameters.EnableAutomaticFailover = EnableAutomaticFailover;
databaseAccountCreateUpdateParameters.VirtualNetworkRules = virtualNetworkRule;
databaseAccountCreateUpdateParameters.DisableKeyBasedMetadataWriteAccess = DisableKeyBasedMetadataWriteAccess;
databaseAccountCreateUpdateParameters.IpRangeFilter = IpRangeFilterAsString;

if (!string.IsNullOrEmpty(ApiKind))
{
if (!ApiKind.Equals("GlobalDocumentDB", StringComparison.OrdinalIgnoreCase) && !ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
if (!ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
{
switch (ApiKind)
{
Expand All @@ -223,6 +221,8 @@ public override void ExecuteCmdlet()
case "Table":
databaseAccountCreateUpdateParameters.Capabilities = new List<Capability> { new Capability { Name = "EnableTable" } };
break;
case "Sql":
break;
}

ApiKind = null;
Expand Down
47 changes: 26 additions & 21 deletions src/CosmosDB/CosmosDB/CosmosDBAccount/UpdateAzCosmosDBAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public class UpdateAzCosmosDBAccount : AzureCosmosDBCmdletBase
public string DefaultConsistencyLevel { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.EnableAutomaticFailoverHelpMessage)]
public bool EnableAutomaticFailover { get; set; }
public bool? EnableAutomaticFailover { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.EnableMultipleWriteLocationsHelpMessage)]
public bool EnableMultipleWriteLocations { get; set; }
public bool? EnableMultipleWriteLocations { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.EnableVirtualNetworkHelpMessage)]
public bool EnableVirtualNetwork { get; set; }
public bool? EnableVirtualNetwork { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.IpRangeFilterHelpMessage)]
[ValidateNotNullOrEmpty]
[ValidateNotNull]
public string[] IpRangeFilter { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.MaxStalenessIntervalInSecondsHelpMessage)]
Expand All @@ -81,6 +81,9 @@ public class UpdateAzCosmosDBAccount : AzureCosmosDBCmdletBase
[ValidateNotNullOrEmpty]
public PSVirtualNetworkRule[] VirtualNetworkRuleObject { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.DisableKeyBasedMetadataWriteAccessHelpMessage)]
public bool? DisableKeyBasedMetadataWriteAccess { get; set; }

[Parameter(Mandatory = false, HelpMessage = Constants.AsJobHelpMessage)]
public SwitchParameter AsJob { get; set; }

Expand All @@ -103,10 +106,23 @@ public override void ExecuteCmdlet()

DatabaseAccountGetResults readDatabase = CosmosDBManagementClient.DatabaseAccounts.GetWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult().Body;

DatabaseAccountUpdateParameters databaseAccountUpdateParameters = new DatabaseAccountUpdateParameters(locations: readDatabase.ReadLocations, location: readDatabase.WriteLocations.ElementAt(0).LocationName);
databaseAccountUpdateParameters.EnableMultipleWriteLocations = EnableMultipleWriteLocations;
databaseAccountUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
databaseAccountUpdateParameters.EnableAutomaticFailover = EnableAutomaticFailover;
DatabaseAccountUpdateParameters databaseAccountUpdateParameters = new DatabaseAccountUpdateParameters(locations: readDatabase.Locations, location: readDatabase.WriteLocations.ElementAt(0).LocationName);
if (EnableMultipleWriteLocations != null)
{
databaseAccountUpdateParameters.EnableMultipleWriteLocations = EnableMultipleWriteLocations;
}
if (EnableVirtualNetwork != null)
{
databaseAccountUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
}
if (EnableAutomaticFailover != null)
{
databaseAccountUpdateParameters.EnableAutomaticFailover = EnableAutomaticFailover;
}
if (DisableKeyBasedMetadataWriteAccess != null)
{
databaseAccountUpdateParameters.DisableKeyBasedMetadataWriteAccess = DisableKeyBasedMetadataWriteAccess;
}

if (!string.IsNullOrEmpty(DefaultConsistencyLevel))
{
Expand Down Expand Up @@ -172,20 +188,9 @@ public override void ExecuteCmdlet()
databaseAccountUpdateParameters.VirtualNetworkRules = virtualNetworkRule;
}

if (IpRangeFilter != null && IpRangeFilter.Length > 0)
if (IpRangeFilter != null)
{
string IpRangeFilterAsString = null;

for (int i = 0; i < IpRangeFilter.Length; i++)
{
if(i==0)
{
IpRangeFilterAsString = IpRangeFilter[0];
}
else
IpRangeFilterAsString = string.Concat(IpRangeFilterAsString, ",", IpRangeFilter[i]);
}

string IpRangeFilterAsString = IpRangeFilter?.Aggregate(string.Empty, (output, next) => string.Concat(output, (!string.IsNullOrWhiteSpace(output) && !string.IsNullOrWhiteSpace(next) ? "," : string.Empty), next)) ?? string.Empty;
databaseAccountUpdateParameters.IpRangeFilter = IpRangeFilterAsString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public override void ExecuteCmdlet()
{
if (Location != null && Location.Length > 0)
{
int failoverPriority = 0;
foreach (string location in Location)
{
locations.Add(new Location(location));
locations.Add(new Location(locationName: location, failoverPriority: failoverPriority));
failoverPriority++;
}
}
if (LocationObject != null && LocationObject.Length > 0)
Expand Down
5 changes: 3 additions & 2 deletions src/CosmosDB/CosmosDB/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ internal static class Constants
public const string VirtualNetworkRuleObjectHelpMessage = "Array of PSVirtualNetworkRuleObjects for virtual network.";
public const string VirtualNetworkRuleIdHelpMessage = "Resource ID of a subnet, for example: /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}";
public const string IgnoreMissingVNetServiceEndpointHelpMessage = "Boolean to indicate if to create firewall rule before the virtual network has vnet service endpoint enabled.";
public const string ApiKindHelpMessage = "The type of Cosmos DB database account to create. Accepted values: GlobalDocumentDB, Sql, MongoDB, Gremlin, Table, Cassandra. Default value: GlobalDocumentDB ";
public const string ApiKindHelpMessage = "The type of Cosmos DB database account to create. Accepted values: Sql, MongoDB, Gremlin, Table, Cassandra. Default value: Sql ";
public const string AccountKeyTypeHelpMessage = "Value from: {ConnectionStrings, Keys, ReadOnlyKeys}. Default is Keys.";

public const string DisableKeyBasedMetadataWriteAccessHelpMessage = "Disable write operations on metadata resources (databases, containers, throughput) via account keys";

//Sql cmdlets help messages
public const string DatabaseNameHelpMessage = "Database name.";
public const string ContainerNameHelpMessage = "Container name.";
Expand Down
1 change: 1 addition & 0 deletions src/CosmosDB/CosmosDB/Models/PSDatabaseAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public PSDatabaseAccount(DatabaseAccountGetResults databaseAccountGetResults)
Location = databaseAccountGetResults.Location;
EnableCassandraConnector = databaseAccountGetResults.EnableCassandraConnector;
FailoverPolicies = databaseAccountGetResults.FailoverPolicies;
Locations = databaseAccountGetResults.Locations;
ReadLocations = databaseAccountGetResults.ReadLocations;
WriteLocations = databaseAccountGetResults.WriteLocations;
Capabilities = databaseAccountGetResults.Capabilities;
Expand Down
12 changes: 6 additions & 6 deletions src/CosmosDB/CosmosDB/Models/PSIndexingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public PSIndexingPolicy()

public PSIndexingPolicy(IndexingPolicy indexingPolicy)
{
Automatic = indexingPolicy.Automatic;
IndexingMode = indexingPolicy.IndexingMode;
Automatic = indexingPolicy?.Automatic;
IndexingMode = indexingPolicy?.IndexingMode;

if (indexingPolicy.IncludedPaths != null)
if (indexingPolicy?.IncludedPaths != null)
{
IncludedPaths = new List<PSIncludedPath>();
foreach (IncludedPath includedPath in indexingPolicy.IncludedPaths)
Expand All @@ -37,7 +37,7 @@ public PSIndexingPolicy(IndexingPolicy indexingPolicy)
}
}

if (indexingPolicy.ExcludedPaths != null)
if (indexingPolicy?.ExcludedPaths != null)
{
ExcludedPaths = new List<PSExcludedPath>();
foreach (ExcludedPath excludedPath in indexingPolicy.ExcludedPaths)
Expand All @@ -46,7 +46,7 @@ public PSIndexingPolicy(IndexingPolicy indexingPolicy)
}
}

if (indexingPolicy.CompositeIndexes != null)
if (indexingPolicy?.CompositeIndexes != null)
{
CompositeIndexes = new List<IList<PSCompositePath>>();
foreach (IList<CompositePath> compositePathList in indexingPolicy.CompositeIndexes)
Expand All @@ -60,7 +60,7 @@ public PSIndexingPolicy(IndexingPolicy indexingPolicy)
}
}

if (indexingPolicy.SpatialIndexes != null)
if (indexingPolicy?.SpatialIndexes != null)
{
SpatialIndexes = new List<PSSpatialSpec>();
foreach (SpatialSpec spatialSpec in indexingPolicy.SpatialIndexes)
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDB/CosmosDB/Models/PSUniqueKeyPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PSUniqueKeyPolicy()
public PSUniqueKeyPolicy(UniqueKeyPolicy uniqueKey)
{
UniqueKeys = new List<PSUniqueKey>();
if (uniqueKey.UniqueKeys != null)
if (uniqueKey?.UniqueKeys != null)
{
foreach (UniqueKey key in uniqueKey.UniqueKeys)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDB/CosmosDB/SQL/GetAzCosmosDBSqlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override void ExecuteCmdlet()
if (Detailed)
{
ThroughputSettingsGetResults throughputSettingsGetResults = CosmosDBManagementClient.SqlResources.GetSqlContainerThroughputWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, Name).GetAwaiter().GetResult().Body;
WriteObject(throughputSettingsGetResults);
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}
else
Expand Down
19 changes: 17 additions & 2 deletions src/CosmosDB/CosmosDB/help/New-AzCosmosDBAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ New-AzCosmosDBAccount -ResourceGroupName <String> -Name <String> [-DefaultConsis
[-EnableAutomaticFailover] [-EnableMultipleWriteLocations] [-EnableVirtualNetwork] [-IpRangeFilter <String[]>]
[-Location <String[]>] [-LocationObject <PSLocation[]>] [-MaxStalenessIntervalInSeconds <Int32>]
[-MaxStalenessPrefix <Int32>] [-Tag <Hashtable>] [-VirtualNetworkRule <String[]>]
[-VirtualNetworkRuleObject <PSVirtualNetworkRule[]>] [-ApiKind <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-VirtualNetworkRuleObject <PSVirtualNetworkRule[]>] [-ApiKind <String>] [-DisableKeyBasedMetadataWriteAccess]
[-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -133,6 +133,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -DisableKeyBasedMetadataWriteAccess
Disable write operations on metadata resources (databases, containers, throughput) via account keys

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableAutomaticFailover
Enables automatic failover of the write region in the rare event that the region is unavailable due to an outage.
Automatic failover will result in a new write region for the account and is chosen based on the failover priorities configured for the account.
Expand Down
Loading