Skip to content

Add new cmdlet, update commands.Sql and tests for 'List database operation' and 'List/Cancel elastic pool operation' #5762

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 18 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
96f5092
Add new powershell cmdlet for cancel pool operation. Added tests for …
payiAzure Mar 15, 2018
e8f1c77
update help file for the new cmdlet Stop-AzureRmSqlElasticPoolActivity.
payiAzure Mar 16, 2018
48c69b5
typo and help file update
payiAzure Mar 19, 2018
11aaa3c
address comments. Use 'Get Location' common function in test. Update …
payiAzure Mar 19, 2018
cfbbe6e
update Stop-AzureRmSqlElasticPoolActivity.md from remote
payiAzure Mar 19, 2018
d8c84ba
Update ChangeLog.md
payiAzure Mar 19, 2018
6ba28ec
add OutputType and implement PassThru for the new added cmdlet
payiAzure Mar 20, 2018
b72223a
merge with upstream/preview and resolve conflict
payiAzure Mar 20, 2018
f869848
address comments. fix indents and help file update
payiAzure Mar 20, 2018
4afb998
enable piping scenario and test piping scenario
payiAzure Mar 21, 2018
f4fca17
address comments on help files
payiAzure Mar 22, 2018
3ed7616
Merge branch 'preview' of https://github.com/Azure/azure-powershell i…
payiAzure Mar 26, 2018
ec192f2
address comments. Update helper file, project references, and changel…
payiAzure Mar 26, 2018
5c43815
update package.config for Sql and Sql.Test project to use new version…
payiAzure Mar 28, 2018
bcc9e03
merge with azure-powershell preview
payiAzure Mar 28, 2018
d118ee9
add record for test TestElasticPoolCancelOperation.json
payiAzure Mar 28, 2018
a9eb9fd
update test records for cancel pool operation test
payiAzure Mar 28, 2018
84ddbc9
resolve conflict
payiAzure Mar 29, 2018
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
3 changes: 2 additions & 1 deletion src/ResourceManager/Sql/AzureRM.Sql.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ CmdletsToExport = 'Get-AzureRmSqlDatabaseTransparentDataEncryption',
'Remove-AzureRmSqlServerVirtualNetworkRule',
'Stop-AzureRmSqlDatabaseActivity', 'Get-AzureRmSqlServerDnsAlias',
'Remove-AzureRmSqlServerDnsAlias', 'New-AzureRmSqlServerDnsAlias',
'Set-AzureRmSqlServerDnsAlias'
'Set-AzureRmSqlServerDnsAlias',
'Stop-AzureRmSqlElasticPoolActivity'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
3 changes: 3 additions & 0 deletions src/ResourceManager/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Current Release
* Add new cmdlet 'Stop-AzureRmSqlElasticPoolActivity' to support canceling the asynchronous operations on elastic pool
* Update the response for cmdlets Get-AzureRmSqlDatabaseActivity and Get-AzureRmSqlElasticPoolActivity to reflect more information in the response
* Updated to the latest version of the Azure ClientRuntime

## Version 4.3.1
Expand Down Expand Up @@ -181,3 +183,4 @@
- To configure ReadScale, user simply specify "ReadScale" paramter with "Enabled/Disabled" at database creation with New-AzureRmSqlDatabase cmdlet,

## Version 2.3.0

Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ElasticPoolCrudTests\TestElasticPoolUpdateWithZoneRedundancy.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ElasticPoolCrudTests\TestElasticPoolCancelOperation.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverGroupTests\TestCreateFailoverGroup_AutomaticPolicy.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,16 +563,17 @@ function Test-CancelDatabaseOperation
.SYNOPSIS
Tests listing and cancelling a database operation
#>
function Test-CancelDatabaseOperationInternal ($location = "westcentralus")
function Test-CancelDatabaseOperationInternal
{
# Setup
$rg = Create-ResourceGroupForTest
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
$rg = Create-ResourceGroupForTest $location
$server = Create-ServerForTest $rg $location

$databaseName = Get-DatabaseName
$db = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName `
-Edition Standard -MaxSizeBytes 250GB -RequestedServiceObjectiveName S0
Assert-AreEqual $db.DatabaseName $databaseName
Assert-AreEqual $db.DatabaseName $databaseName 'Create database failed.'

# Database will be Standard s0 with maxsize: 268435456000 (250GB)

Expand All @@ -581,9 +582,9 @@ function Test-CancelDatabaseOperationInternal ($location = "westcentralus")
# Alter all properties
$db1 = Set-AzureRmSqlDatabase -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName `
-Edition Standard -RequestedServiceObjectiveName S1
Assert-AreEqual $db1.DatabaseName $db.DatabaseName
Assert-AreEqual $db1.Edition Standard
Assert-AreEqual $db1.CurrentServiceObjectiveName S1
Assert-AreEqual $db1.DatabaseName $db.DatabaseName 'Alter db name not equal'
Assert-AreEqual $db1.Edition Standard 'Alter db edition not equal'
Assert-AreEqual $db1.CurrentServiceObjectiveName S1 'Alter db slo not equal'

# list and cancel a database operation
$dbactivity = Get-AzureRmSqlDatabaseActivity -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,12 @@ public void TestElasticPoolRemove()
{
RunPowerShellTest("Test-RemoveElasticPool");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolCancelOperation()
{
RunPowerShellTest("Test-ListAndCancelElasticPoolOperation");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,91 @@ function Test-RemoveElasticPool
{
Remove-ResourceGroupForTest $rg
}
}

<#
.SYNOPSIS
Test listing and cancelling a elastic pool operation
#>
function Test-ListAndCancelElasticPoolOperation
{
# Setup
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
$rg = Create-ResourceGroupForTest $location
$server = Create-ServerForTest $rg $location

$poolName = Get-ElasticPoolName
$ep1 = New-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
-ElasticPoolName $poolName -Edition Premium -Dtu 125 -DatabaseDtuMin 0 -DatabaseDtuMax 50
Assert-NotNull $ep1

$poolName = Get-ElasticPoolName
$ep2 = $server | New-AzureRmSqlElasticPool -ElasticPoolName $poolName -Edition Premium -Dtu 250 -DatabaseDtuMin 0 `
-DatabaseDtuMax 50
Assert-NotNull $ep2

# Elastic pool will be Premium with DTU 125

try
{
# Update the elastic pool ep1 to premium with 250 Dtu
$ep1update = Set-AzureRmSqlElasticPool -ResourceGroupName $ep1.ResourceGroupName -ServerName $ep1.ServerName -ElasticPoolName $ep1.ElasticPoolName `
-Edition Premium -Dtu 250 -DatabaseDtuMin 25 -DatabaseDtuMax 125
Assert-AreEqual $ep1.ElasticPoolName $ep1update.ElasticPoolName
Assert-AreEqual Premium $ep1update.Edition
Assert-AreEqual 250 $ep1update.Dtu

# List and Cancel the elastic pool update operation
$epactivity = Get-AzureRmSqlElasticPoolActivity -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -ElasticPoolName $ep1update.ElasticPoolName
$epactivityId

For($i=0; $i -lt $epactivity.Length; $i++) {
if($epactivity[$i].Operation -eq "UPDATE"){
$epactivityId = $epactivity[$i].OperationId
}
}

try
{
# cancel a pool update operation with all values
$activityCancel = Stop-AzureRmSqlElasticPoolActivity -ResourceGroupName $ep1.ResourceGroupName -ServerName $ep1.ServerName -ElasticPoolName $ep1.ElasticPoolName -OperationId $epactivityId
}
Catch
{
$ErrorMessage = $_.Exception.Message
Assert-AreEqual True $ErrorMessage.Contains("Cannot cancel management operation '" + $epactivityId + "' in the current state") $ErrorMessage
}

# piping test on related pool operations
# Update ep2 tp Premium with 500 Dtu
$ep2update = Set-AzureRmSqlElasticPool -ResourceGroupName $ep2.ResourceGroupName -ServerName $ep2.ServerName -ElasticPoolName $ep2.ElasticPoolName `
-Edition Premium -Dtu 500 -DatabaseDtuMin 25 -DatabaseDtuMax 250
Assert-AreEqual $ep2.ElasticPoolName $ep2update.ElasticPoolName
Assert-AreEqual Premium $ep2update.Edition
Assert-AreEqual 500 $ep2update.Dtu

$epactivity = $ep2update | Get-AzureRmSqlElasticPoolActivity
For($i=0; $i -lt $epactivity.Length; $i++) {
if($epactivity[$i].Operation -eq "UPDATE"){
$epactivityId = $epactivity[$i].OperationId
}
}

$epactivity = $ep2update | Get-AzureRmSqlElasticPoolActivity -OperationId $epactivityId

try
{
# cancel a pool update operation using piping
$activityCancel = $epactivity | Stop-AzureRmSqlElasticPoolActivity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@payiAzure since we always expect this to error out, we should change this to the following:

Assert-Throws { $ep2update | Get-AzureRmSqlElasticPoolActivity -OperationId $epactivityId }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cormacpayne I'd like to keep it with try-catch for now. We're adding other support services for cancel operations and will update it in future if needed.

}
Catch
{
$ErrorMessage = $_.Exception.Message
Assert-AreEqual True $ErrorMessage.Contains("Cannot cancel management operation '" + $epactivityId + "' in the current state") $ErrorMessage
}
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Compile Include="Database\Cmdlet\StopAzureSqlDatabaseActivity.cs" />
<Compile Include="Database\Model\DatabaseReadScale.cs" />
<Compile Include="Database\Model\AzureSqlDatabaseCreateOrUpdateModel.cs" />
<Compile Include="Elastic Pools\Cmdlet\StopAzureSqlElasticPoolActivity.cs" />
<Compile Include="Failover Group\Cmdlet\AddAzureSqlDatabaseToFailoverGroup.cs" />
<Compile Include="Failover Group\Cmdlet\AzureSqlFailoverGroupCmdletBase.cs" />
<Compile Include="Failover Group\Cmdlet\GetAzureSqlFailoverGroup.cs" />
Expand Down Expand Up @@ -452,8 +453,6 @@
<Project>{04B53727-16E6-4EF0-9116-04C7F1C33842}</Project>
<Name>SqlManagement</Name>
</ProjectReference>
<!--<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.3.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>-->
<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.13.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,20 @@ public class DatabaseState
/// Gets or sets the state of the properties associated with the request
/// </summary>
public DatabaseState Properties { get; set; }

/// <summary>
/// Gets or sets the estimated the completion time of the database operation
/// </summary>
public DateTime? EstimatedCompletionTime { get; set; }

/// <summary>
/// Gets or sets the detailed description of the database operation
/// </summary>
public string Description { get; set; }

/// <summary>
/// Gets or sets the value to indicate if the database operation can be cancelled
/// </summary>
public bool? IsCancellable { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ internal IEnumerable<AzureSqlDatabaseActivityModel> ListDatabaseActivity(string
{
Current = new Dictionary<string, string>(),
Requested = new Dictionary<string, string>()
}
},
EstimatedCompletionTime = r.EstimatedCompletionTime,
Description = r.Description,
IsCancellable = r.IsCancellable
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Azure.Commands.Sql.Common;
using Microsoft.Azure.Commands.Sql.ElasticPool.Model;
using Microsoft.Azure.Commands.Sql.ElasticPool.Services;
using System;
using System.Collections.Generic;
using System.Management.Automation;

Expand Down Expand Up @@ -44,6 +45,15 @@ public abstract class AzureSqlElasticPoolActivityCmdletBase : AzureSqlCmdletBase
[ValidateNotNullOrEmpty]
public string ElasticPoolName { get; set; }

/// <summary>
/// Gets or sets the operation id to use.
/// </summary>
[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The ID of the operation to retrieve.")]
[ValidateNotNullOrEmpty]
public Guid? OperationId { get; set; }

/// <summary>
/// Initializes the adapter
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// ----------------------------------------------------------------------------------
//
// 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 Microsoft.Azure.Commands.Sql.ElasticPool.Model;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet
{
[Cmdlet(VerbsLifecycle.Stop, "AzureRmSqlElasticPoolActivity", SupportsShouldProcess = true), OutputType(typeof(AzureSqlElasticPoolActivityModel))]
public class StopAzureSqlElasticPoolActivity : AzureSqlElasticPoolActivityCmdletBase
{
/// <summary>
/// Defines whether the cmdlets will successfully returned at the end of its execution
/// </summary>
[Parameter(Mandatory = false)]
public SwitchParameter PassThru { get; set; }

/// <summary>
/// Gets elastic pool activity
/// </summary>
/// <returns>List of elastic pool activies</returns>
protected override IEnumerable<AzureSqlElasticPoolActivityModel> GetEntity()
{
return ModelAdapter.GetElasticPoolActivity(this.ResourceGroupName, this.ServerName, this.ElasticPoolName);
}

/// <summary>
/// No user input to apply to model
/// </summary>
/// <param name="model">Model retrieved from service</param>
/// <returns>The model that was passed in</returns>
protected override IEnumerable<AzureSqlElasticPoolActivityModel> ApplyUserInputToModel(IEnumerable<AzureSqlElasticPoolActivityModel> model)
{
return model;
}

/// <summary>
/// No changes to persist to server
/// </summary>
/// <param name="entity">The output of apply user input to model</param>
/// <returns>The input entity</returns>
protected override IEnumerable<AzureSqlElasticPoolActivityModel> PersistChanges(IEnumerable<AzureSqlElasticPoolActivityModel> entity)
{
return ModelAdapter.CancelElasticPoolActivity(this.ResourceGroupName, this.ServerName, this.ElasticPoolName, this.OperationId);
}

/// <summary>
/// Returns true if the model object that was constructed by this cmdlet should be written out
/// </summary>
/// <returns>True if the model object should be written out, False otherwise</returns>
protected override bool WriteResult() { return PassThru; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class AzureSqlElasticPoolActivityModel
/// </summary>
public string ElasticPoolName { get; set; }

/// <summary>
/// Gets or sets the name of the resource group
/// </summary>
public string ResourceGroupName { get; set; }

/// <summary>
/// Gets or sets the state
/// </summary>
Expand Down Expand Up @@ -100,5 +105,20 @@ public class AzureSqlElasticPoolActivityModel
/// Gets or sets the requested storage limit in GB
/// </summary>
public long? RequestedStorageLimitInGB { get; set; }

/// <summary>
/// Gets or sets the estimated completion time of the elastic pool operation
/// </summary>
public DateTime? EstimatedCompletionTime { get; set; }

/// <summary>
/// Gets or sets the description of the elastic pool operation
/// </summary>
public string Description { get; set; }

/// <summary>
/// Gets or sets the value to indicate if the elastic pool operation can be cancelled
/// </summary>
public bool? IsCancellable { get; set; }
}
}
Loading