Skip to content
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

[CosmosDB] Bug Fixes and Enhancements #11505

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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.

10 changes: 9 additions & 1 deletion src/CosmosDB/CosmosDB/CosmosDBAccount/NewAzCosmosDBAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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 @@ -84,6 +84,9 @@ public class NewAzCosmosDBAccount : AzureCosmosDBCmdletBase
[PSArgumentCompleter("GlobalDocumentDB", "MongoDB", "Gremlin", "Cassandra", "Table")]
public string ApiKind { 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 Down Expand Up @@ -201,12 +204,17 @@ public override void ExecuteCmdlet()
IpRangeFilterAsString = string.Concat(IpRangeFilterAsString, ",", IpRangeFilter[i]);
}
}
else if (IpRangeFilter != null)
{
IpRangeFilterAsString = "";
}

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;

if (!string.IsNullOrEmpty(ApiKind))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class UpdateAzCosmosDBAccount : AzureCosmosDBCmdletBase
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 @@ -107,6 +110,7 @@ public override void ExecuteCmdlet()
databaseAccountUpdateParameters.EnableMultipleWriteLocations = EnableMultipleWriteLocations;
databaseAccountUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
databaseAccountUpdateParameters.EnableAutomaticFailover = EnableAutomaticFailover;
databaseAccountUpdateParameters.DisableKeyBasedMetadataWriteAccess = DisableKeyBasedMetadataWriteAccess;

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

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

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
3 changes: 2 additions & 1 deletion src/CosmosDB/CosmosDB/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ internal static class Constants
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 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
5 changes: 4 additions & 1 deletion src/CosmosDB/CosmosDB/help/Update-AzCosmosDBAccountRegion.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Update-AzCosmosDBAccountRegion [-Location <String[]>] [-LocationObject <PSLocati
```

## DESCRIPTION
Update Regions of a CosmosDB Account.
Update Regions of a CosmosDB Account. Location can be provided either as an object of type PSLocation or as strings of Location Name ordered by failover priority.
LocationObject parameter expects the list of current locations (failover prioritiies included) appended by the new LocationObjects corresponding to new locations to be added.
Location parameter expects the list of current location(ordered by failover priority) and the new locations.
Please note, we only support Addition of Regions. Please provide either Location or LocationObject.

## EXAMPLES

Expand Down