Skip to content

Commit 21ed968

Browse files
author
Meha Kaushik
committed
Migration support for throughput + sql tests
1 parent cc86dd2 commit 21ed968

16 files changed

+923
-3
lines changed

src/CosmosDB/CosmosDB.Test/CosmosDB.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
66
<ItemGroup>
7-
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.0" />
7+
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.1" />
88
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.0.2-preview" />
99
</ItemGroup>
1010
</Project>

src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,12 @@ public void TestSqlThroughputCmdlets()
4747
{
4848
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlThroughputCmdlets");
4949
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void TestSqlMigrateThroughputCmdlets()
54+
{
55+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlMigrateThroughputCmdlets");
56+
}
5057
}
5158
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,57 @@ function Test-SqlThroughputCmdlets
569569
Remove-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName2 -Name $ContainerName2
570570
Remove-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName2
571571
}
572+
}
573+
574+
<#
575+
.SYNOPSIS
576+
Test SQL throughput cmdlets using all parameter sets
577+
#>
578+
function Test-SqlMigrateThroughputCmdlets
579+
{
580+
$AccountName = "cosmosdb9921232812"
581+
$rgName = "rgtest9921232812"
582+
$DatabaseName = "dbName4"
583+
$ContainerName = "containerName"
584+
585+
$PartitionKeyPathValue = "/foo/bar"
586+
$PartitionKeyKindValue = "Hash"
587+
588+
$ThroughputValue = 1200
589+
590+
$ContainerThroughputValue = 800
591+
592+
$Autoscale = "Autoscale"
593+
$Manual = "Manual"
594+
595+
Try{
596+
$NewDatabase = New-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName -Throughput $ThroughputValue
597+
$Throughput = Get-AzCosmosDBSqlDatabaseThroughput -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName
598+
Assert-AreEqual $Throughput.Throughput $ThroughputValue
599+
Assert-AreEqual $Throughput.AutoscaleSettings.MaxThroughput 0
600+
601+
$AutoscaleThroughput = Migrate-AzCosmosDBSqlDatabaseThroughput -InputObject $NewDatabase -ThroughputType $Autoscale
602+
Assert-NotEqual $UpdatedThroughput.AutoscaleSettings.MaxThroughput 0
603+
604+
$CosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $rgName -Name $AccountName #get parent object
605+
$ManualThroughput = Migrate-AzCosmosDBSqlDatabaseThroughput -ParentObject $CosmosDBAccount -Name $DatabaseName -ThroughputType $Manual
606+
Assert-AreEqual $ManualThroughput.AutoscaleSettings.MaxThroughput 0
607+
608+
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Throughput $ContainerThroughputValue -Name $ContainerName -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue
609+
$ContainerThroughput = Get-AzCosmosDBSqlContainerThroughput -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerName
610+
Assert-AreEqual $ContainerThroughput.Throughput $ContainerThroughputValue
611+
612+
$AutoscaledContainerThroughput = Migrate-AzCosmosDBSqlContainerThroughput -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerName -ThroughputType $Autoscale
613+
Assert-NotEqual $UpdatedContainerThroughput.AutoscaleSettings.MaxThroughput 0
614+
615+
$ManualContainerThroughput = Migrate-AzCosmosDBSqlContainerThroughput -InputObject $NewContainer -ThroughputType $Manual
616+
Assert-AreEqual $UpdatedContainerThroughput.AutoscaleSettings.MaxThroughput 0
617+
618+
Remove-AzCosmosDBSqlContainer -InputObject $NewContainer
619+
Remove-AzCosmosDBSqlDatabase -InputObject $NewDatabase
620+
}
621+
Finally{
622+
Remove-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerName
623+
Remove-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName
624+
}
572625
}

src/CosmosDB/CosmosDB/Az.CosmosDB.psd1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,16 @@ CmdletsToExport = 'Get-AzCosmosDBSqlContainer',
146146
'Update-AzCosmosDBTableThroughput',
147147
'Update-AzCosmosDBMongoDBCollection',
148148
'Update-AzCosmosDBMongoDBDatabase',
149-
'New-AzCosmosDBMongoDBCollection', 'New-AzCosmosDBMongoDBDatabase'
149+
'New-AzCosmosDBMongoDBCollection', 'New-AzCosmosDBMongoDBDatabase',
150+
'Migrate-AzCosmosDBSqlContainerThroughput',
151+
'Migrate-AzCosmosDBSqlDatabaseThroughput',
152+
'Migrate-AzCosmosDBMongoDBCollectionThroughput',
153+
'Migrate-AzCosmosDBMongoDBDatabaseThroughput',
154+
'Migrate-AzCosmosDBGremlinGraphThroughput',
155+
'Migrate-AzCosmosDBGremlinDatabaseThroughput',
156+
'Migrate-AzCosmosDBCassandraTableThroughput',
157+
'Migrate-AzCosmosDBCassandraKeyspaceThroughput',
158+
'Migrate-AzCosmosDBTableThroughput'
150159

151160
# Variables to export from this module
152161
# VariablesToExport = @()
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.CosmosDB.Models;
18+
using Microsoft.Azure.Management.CosmosDB.Models;
19+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
20+
using Microsoft.Azure.Commands.CosmosDB.Helpers;
21+
using Microsoft.Azure.Management.CosmosDB;
22+
23+
namespace Microsoft.Azure.Commands.CosmosDB
24+
{
25+
[Cmdlet("Migrate", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBCassandraKeyspaceThroughput", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSThroughputSettingsGetResults))]
26+
public class MigrateAzCosmosDBCassandraKeyspaceThroughput : MigrateAzCosmosDBThroughput
27+
{
28+
[Parameter(Mandatory = false, HelpMessage = Constants.KeyspaceNameHelpMessage)]
29+
[ValidateNotNullOrEmpty]
30+
public string Name { get; set; }
31+
32+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParentObjectParameterSet, HelpMessage = Constants.AccountObjectHelpMessage)]
33+
[ValidateNotNull]
34+
public PSDatabaseAccountGetResults ParentObject { get; set; }
35+
36+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.CassandraKeyspaceObjectHelpMessage)]
37+
[ValidateNotNull]
38+
public PSCassandraKeyspaceGetResults InputObject { get; set; }
39+
40+
public override void PopulateFromParentObject()
41+
{
42+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
43+
ResourceGroupName = resourceIdentifier.ResourceGroupName;
44+
AccountName = resourceIdentifier.ResourceName;
45+
}
46+
47+
public override void PopulateFromInputObject()
48+
{
49+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
50+
ResourceGroupName = resourceIdentifier.ResourceGroupName;
51+
Name = resourceIdentifier.ResourceName;
52+
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
53+
}
54+
55+
public override void MigrateToAutoscaleSDKMethod()
56+
{
57+
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Keyspace throughput to Autoscale Provisioning Policy."))
58+
{
59+
ThroughputSettingsGetResults throughputSettingsGetResults =
60+
CosmosDBManagementClient.CassandraResources.MigrateCassandraKeyspaceToAutoscale(
61+
ResourceGroupName,
62+
AccountName,
63+
Name);
64+
65+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
66+
}
67+
}
68+
69+
public override void MigrateToManualSDKMethod()
70+
{
71+
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Keyspace throughput to Manual Provisioning Policy."))
72+
{
73+
ThroughputSettingsGetResults throughputSettingsGetResults =
74+
CosmosDBManagementClient.CassandraResources.MigrateCassandraKeyspaceToManualThroughput(
75+
ResourceGroupName,
76+
AccountName,
77+
Name);
78+
79+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
80+
}
81+
}
82+
83+
}
84+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.CosmosDB.Models;
18+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
19+
using Microsoft.Azure.Commands.CosmosDB.Helpers;
20+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
21+
using Microsoft.Azure.Management.CosmosDB.Models;
22+
using Microsoft.Azure.Management.CosmosDB;
23+
24+
namespace Microsoft.Azure.Commands.CosmosDB
25+
{
26+
[Cmdlet("Migrate", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBCassandraTableThroughput", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSThroughputSettingsGetResults))]
27+
public class MigrateAzCosmosDBCassandraTableThroughput : MigrateAzCosmosDBThroughput
28+
{
29+
[Parameter(Mandatory = true, ParameterSetName = NameParameterSet, HelpMessage = Constants.KeyspaceNameHelpMessage)]
30+
[ValidateNotNullOrEmpty]
31+
public string KeyspaceName { get; set; }
32+
33+
[Parameter(Mandatory = false, HelpMessage = Constants.CassandraTableNameHelpMessage)]
34+
[ValidateNotNullOrEmpty]
35+
public string Name { get; set; }
36+
37+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParentObjectParameterSet, HelpMessage = Constants.CassandraKeyspaceObjectHelpMessage)]
38+
[ValidateNotNull]
39+
public PSCassandraKeyspaceGetResults ParentObject { get; set; }
40+
41+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.CassandraTableObjectHelpMessage)]
42+
[ValidateNotNull]
43+
public PSCassandraTableGetResults InputObject { get; set; }
44+
45+
public override void PopulateFromParentObject()
46+
{
47+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
48+
ResourceGroupName = resourceIdentifier.ResourceGroupName;
49+
KeyspaceName = resourceIdentifier.ResourceName;
50+
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
51+
}
52+
53+
public override void PopulateFromInputObject()
54+
{
55+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
56+
ResourceGroupName = resourceIdentifier.ResourceGroupName;
57+
Name = resourceIdentifier.ResourceName;
58+
KeyspaceName = ResourceIdentifierExtensions.GetCassandraKeyspaceName(resourceIdentifier);
59+
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
60+
}
61+
62+
public override void MigrateToAutoscaleSDKMethod()
63+
{
64+
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Table throughput to Autoscale Provisioning Policy."))
65+
{
66+
ThroughputSettingsGetResults throughputSettingsGetResults =
67+
CosmosDBManagementClient.CassandraResources.MigrateCassandraTableToAutoscale(
68+
ResourceGroupName,
69+
AccountName,
70+
KeyspaceName,
71+
Name);
72+
73+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
74+
}
75+
}
76+
77+
public override void MigrateToManualSDKMethod()
78+
{
79+
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Table throughput to Manual Provisioning Policy."))
80+
{
81+
ThroughputSettingsGetResults throughputSettingsGetResults =
82+
CosmosDBManagementClient.CassandraResources.MigrateCassandraTableToManualThroughput(
83+
ResourceGroupName,
84+
AccountName,
85+
KeyspaceName,
86+
Name);
87+
88+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
89+
}
90+
}
91+
}
92+
}

src/CosmosDB/CosmosDB/CosmosDB.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.props" />
88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.0" />
9+
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.1" />
1010
</ItemGroup>
1111

1212
</Project>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.CosmosDB.Models;
17+
using Microsoft.Azure.Management.CosmosDB.Models;
18+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
19+
using Microsoft.Azure.Commands.CosmosDB.Helpers;
20+
using Microsoft.Azure.Management.CosmosDB;
21+
22+
namespace Microsoft.Azure.Commands.CosmosDB
23+
{
24+
[Cmdlet("Migrate", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGremlinDatabaseThroughput", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSThroughputSettingsGetResults))]
25+
public class MigrateAzCosmosDBGremlinDatabaseThroughput : MigrateAzCosmosDBThroughput
26+
{
27+
[Parameter(Mandatory = false, HelpMessage = Constants.DatabaseNameHelpMessage)]
28+
[ValidateNotNullOrEmpty]
29+
public string Name { get; set; }
30+
31+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParentObjectParameterSet, HelpMessage = Constants.AccountObjectHelpMessage)]
32+
[ValidateNotNull]
33+
public PSDatabaseAccountGetResults ParentObject { get; set; }
34+
35+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.GremlinDatabaseObjectHelpMessage)]
36+
[ValidateNotNull]
37+
public PSGremlinDatabaseGetResults InputObject { get; set; }
38+
39+
public override void PopulateFromParentObject()
40+
{
41+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
42+
ResourceGroupName = resourceIdentifier.ResourceGroupName;
43+
AccountName = resourceIdentifier.ResourceName;
44+
}
45+
46+
public override void PopulateFromInputObject()
47+
{
48+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
49+
ResourceGroupName = resourceIdentifier.ResourceGroupName;
50+
Name = resourceIdentifier.ResourceName;
51+
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
52+
53+
}
54+
55+
public override void MigrateToAutoscaleSDKMethod()
56+
{
57+
if (ShouldProcess(Name, "Migrating the CosmosDB Gremlin Database throughput to Autoscale Provisioning Policy."))
58+
{
59+
ThroughputSettingsGetResults throughputSettingsGetResults =
60+
CosmosDBManagementClient.GremlinResources.MigrateGremlinDatabaseToAutoscale(
61+
ResourceGroupName,
62+
AccountName,
63+
Name);
64+
65+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
66+
}
67+
}
68+
69+
public override void MigrateToManualSDKMethod()
70+
{
71+
if (ShouldProcess(Name, "Migrating the CosmosDB Gremlin Database throughput to Manual Provisioning Policy."))
72+
{
73+
ThroughputSettingsGetResults throughputSettingsGetResults =
74+
CosmosDBManagementClient.GremlinResources.MigrateGremlinDatabaseToManualThroughput(
75+
ResourceGroupName,
76+
AccountName,
77+
Name);
78+
79+
WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
80+
}
81+
}
82+
83+
}
84+
}

0 commit comments

Comments
 (0)