Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/CosmosDB/CosmosDB.Test/CosmosDB.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.1" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.0.2-preview" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@ public void TestSqlThroughputCmdlets()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlThroughputCmdlets");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSqlMigrateThroughputCmdlets()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlMigrateThroughputCmdlets");
}
}
}
53 changes: 53 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,57 @@ function Test-SqlThroughputCmdlets
Remove-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName2 -Name $ContainerName2
Remove-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName2
}
}

<#
.SYNOPSIS
Test SQL throughput cmdlets using all parameter sets
#>
function Test-SqlMigrateThroughputCmdlets
{
$AccountName = "cosmosdb9921232812"
$rgName = "rgtest9921232812"
$DatabaseName = "dbName4"
$ContainerName = "containerName"

$PartitionKeyPathValue = "/foo/bar"
$PartitionKeyKindValue = "Hash"

$ThroughputValue = 1200

$ContainerThroughputValue = 800

$Autoscale = "Autoscale"
$Manual = "Manual"

Try{
$NewDatabase = New-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName -Throughput $ThroughputValue
$Throughput = Get-AzCosmosDBSqlDatabaseThroughput -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName
Assert-AreEqual $Throughput.Throughput $ThroughputValue
Assert-AreEqual $Throughput.AutoscaleSettings.MaxThroughput 0

$AutoscaleThroughput = Migrate-AzCosmosDBSqlDatabaseThroughput -InputObject $NewDatabase -ThroughputType $Autoscale
Assert-NotEqual $UpdatedThroughput.AutoscaleSettings.MaxThroughput 0

$CosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $rgName -Name $AccountName #get parent object
$ManualThroughput = Migrate-AzCosmosDBSqlDatabaseThroughput -ParentObject $CosmosDBAccount -Name $DatabaseName -ThroughputType $Manual
Assert-AreEqual $ManualThroughput.AutoscaleSettings.MaxThroughput 0

$NewContainer = New-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Throughput $ContainerThroughputValue -Name $ContainerName -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue
$ContainerThroughput = Get-AzCosmosDBSqlContainerThroughput -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerName
Assert-AreEqual $ContainerThroughput.Throughput $ContainerThroughputValue

$AutoscaledContainerThroughput = Migrate-AzCosmosDBSqlContainerThroughput -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerName -ThroughputType $Autoscale
Assert-NotEqual $UpdatedContainerThroughput.AutoscaleSettings.MaxThroughput 0

$ManualContainerThroughput = Migrate-AzCosmosDBSqlContainerThroughput -InputObject $NewContainer -ThroughputType $Manual
Assert-AreEqual $UpdatedContainerThroughput.AutoscaleSettings.MaxThroughput 0

Remove-AzCosmosDBSqlContainer -InputObject $NewContainer
Remove-AzCosmosDBSqlDatabase -InputObject $NewDatabase
}
Finally{
Remove-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerName
Remove-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName
}
}
11 changes: 10 additions & 1 deletion src/CosmosDB/CosmosDB/Az.CosmosDB.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ CmdletsToExport = 'Get-AzCosmosDBSqlContainer',
'Update-AzCosmosDBTableThroughput',
'Update-AzCosmosDBMongoDBCollection',
'Update-AzCosmosDBMongoDBDatabase',
'New-AzCosmosDBMongoDBCollection', 'New-AzCosmosDBMongoDBDatabase'
'New-AzCosmosDBMongoDBCollection', 'New-AzCosmosDBMongoDBDatabase',
'Migrate-AzCosmosDBSqlContainerThroughput',
'Migrate-AzCosmosDBSqlDatabaseThroughput',
'Migrate-AzCosmosDBMongoDBCollectionThroughput',
'Migrate-AzCosmosDBMongoDBDatabaseThroughput',
'Migrate-AzCosmosDBGremlinGraphThroughput',
'Migrate-AzCosmosDBGremlinDatabaseThroughput',
'Migrate-AzCosmosDBCassandraTableThroughput',
'Migrate-AzCosmosDBCassandraKeyspaceThroughput',
'Migrate-AzCosmosDBTableThroughput'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.CosmosDB.Models;
using Microsoft.Azure.Management.CosmosDB.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Management.CosmosDB;

namespace Microsoft.Azure.Commands.CosmosDB
{
[Cmdlet("Migrate", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBCassandraKeyspaceThroughput", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSThroughputSettingsGetResults))]
public class MigrateAzCosmosDBCassandraKeyspaceThroughput : MigrateAzCosmosDBThroughput
{
[Parameter(Mandatory = false, HelpMessage = Constants.KeyspaceNameHelpMessage)]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParentObjectParameterSet, HelpMessage = Constants.AccountObjectHelpMessage)]
[ValidateNotNull]
public PSDatabaseAccountGetResults ParentObject { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.CassandraKeyspaceObjectHelpMessage)]
[ValidateNotNull]
public PSCassandraKeyspaceGetResults InputObject { get; set; }

public override void PopulateFromParentObject()
{
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
AccountName = resourceIdentifier.ResourceName;
}

public override void PopulateFromInputObject()
{
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
Name = resourceIdentifier.ResourceName;
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
}

public override void MigrateToAutoscaleSDKMethod()
{
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Keyspace throughput to Autoscale Provisioning Policy."))
{
ThroughputSettingsGetResults throughputSettingsGetResults =
CosmosDBManagementClient.CassandraResources.MigrateCassandraKeyspaceToAutoscale(
ResourceGroupName,
AccountName,
Name);

WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}

public override void MigrateToManualSDKMethod()
{
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Keyspace throughput to Manual Provisioning Policy."))
{
ThroughputSettingsGetResults throughputSettingsGetResults =
CosmosDBManagementClient.CassandraResources.MigrateCassandraKeyspaceToManualThroughput(
ResourceGroupName,
AccountName,
Name);

WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.CosmosDB.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.CosmosDB.Models;
using Microsoft.Azure.Management.CosmosDB;

namespace Microsoft.Azure.Commands.CosmosDB
{
[Cmdlet("Migrate", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBCassandraTableThroughput", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSThroughputSettingsGetResults))]
public class MigrateAzCosmosDBCassandraTableThroughput : MigrateAzCosmosDBThroughput
{
[Parameter(Mandatory = true, ParameterSetName = NameParameterSet, HelpMessage = Constants.KeyspaceNameHelpMessage)]
[ValidateNotNullOrEmpty]
public string KeyspaceName { get; set; }

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

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParentObjectParameterSet, HelpMessage = Constants.CassandraKeyspaceObjectHelpMessage)]
[ValidateNotNull]
public PSCassandraKeyspaceGetResults ParentObject { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.CassandraTableObjectHelpMessage)]
[ValidateNotNull]
public PSCassandraTableGetResults InputObject { get; set; }

public override void PopulateFromParentObject()
{
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
KeyspaceName = resourceIdentifier.ResourceName;
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
}

public override void PopulateFromInputObject()
{
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
Name = resourceIdentifier.ResourceName;
KeyspaceName = ResourceIdentifierExtensions.GetCassandraKeyspaceName(resourceIdentifier);
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
}

public override void MigrateToAutoscaleSDKMethod()
{
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Table throughput to Autoscale Provisioning Policy."))
{
ThroughputSettingsGetResults throughputSettingsGetResults =
CosmosDBManagementClient.CassandraResources.MigrateCassandraTableToAutoscale(
ResourceGroupName,
AccountName,
KeyspaceName,
Name);

WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}

public override void MigrateToManualSDKMethod()
{
if (ShouldProcess(Name, "Migrating the CosmosDB Cassandra Table throughput to Manual Provisioning Policy."))
{
ThroughputSettingsGetResults throughputSettingsGetResults =
CosmosDBManagementClient.CassandraResources.MigrateCassandraTableToManualThroughput(
ResourceGroupName,
AccountName,
KeyspaceName,
Name);

WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}
}
}
2 changes: 1 addition & 1 deletion src/CosmosDB/CosmosDB/CosmosDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<Import Project="$(MSBuildThisFileDirectory)..\..\Az.props" />
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.2.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using Microsoft.Azure.Commands.CosmosDB.Models;
using Microsoft.Azure.Management.CosmosDB.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Management.CosmosDB;

namespace Microsoft.Azure.Commands.CosmosDB
{
[Cmdlet("Migrate", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGremlinDatabaseThroughput", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSThroughputSettingsGetResults))]
public class MigrateAzCosmosDBGremlinDatabaseThroughput : MigrateAzCosmosDBThroughput
{
[Parameter(Mandatory = false, HelpMessage = Constants.DatabaseNameHelpMessage)]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParentObjectParameterSet, HelpMessage = Constants.AccountObjectHelpMessage)]
[ValidateNotNull]
public PSDatabaseAccountGetResults ParentObject { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ObjectParameterSet, HelpMessage = Constants.GremlinDatabaseObjectHelpMessage)]
[ValidateNotNull]
public PSGremlinDatabaseGetResults InputObject { get; set; }

public override void PopulateFromParentObject()
{
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
AccountName = resourceIdentifier.ResourceName;
}

public override void PopulateFromInputObject()
{
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
ResourceGroupName = resourceIdentifier.ResourceGroupName;
Name = resourceIdentifier.ResourceName;
AccountName = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);

}

public override void MigrateToAutoscaleSDKMethod()
{
if (ShouldProcess(Name, "Migrating the CosmosDB Gremlin Database throughput to Autoscale Provisioning Policy."))
{
ThroughputSettingsGetResults throughputSettingsGetResults =
CosmosDBManagementClient.GremlinResources.MigrateGremlinDatabaseToAutoscale(
ResourceGroupName,
AccountName,
Name);

WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}

public override void MigrateToManualSDKMethod()
{
if (ShouldProcess(Name, "Migrating the CosmosDB Gremlin Database throughput to Manual Provisioning Policy."))
{
ThroughputSettingsGetResults throughputSettingsGetResults =
CosmosDBManagementClient.GremlinResources.MigrateGremlinDatabaseToManualThroughput(
ResourceGroupName,
AccountName,
Name);

WriteObject(new PSThroughputSettingsGetResults(throughputSettingsGetResults));
}
}

}
}
Loading