Skip to content

Commit 9a25b3a

Browse files
author
Maddie Clayton
authored
Merge pull request #5762 from payiAzure/azure-powershell-br1
Add new cmdlet, update commands.Sql and tests for 'List database operation' and 'List/Cancel elastic pool operation'
2 parents 443db7d + 84ddbc9 commit 9a25b3a

17 files changed

+3828
-13
lines changed

src/ResourceManager/Sql/AzureRM.Sql.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ CmdletsToExport = 'Get-AzureRmSqlDatabaseTransparentDataEncryption',
188188
'Remove-AzureRmSqlServerVirtualNetworkRule',
189189
'Stop-AzureRmSqlDatabaseActivity', 'Get-AzureRmSqlServerDnsAlias',
190190
'Remove-AzureRmSqlServerDnsAlias', 'New-AzureRmSqlServerDnsAlias',
191-
'Set-AzureRmSqlServerDnsAlias'
191+
'Set-AzureRmSqlServerDnsAlias',
192+
'Stop-AzureRmSqlElasticPoolActivity'
192193

193194
# Variables to export from this module
194195
# VariablesToExport = @()

src/ResourceManager/Sql/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Add new cmdlet 'Stop-AzureRmSqlElasticPoolActivity' to support canceling the asynchronous operations on elastic pool
22+
* Update the response for cmdlets Get-AzureRmSqlDatabaseActivity and Get-AzureRmSqlElasticPoolActivity to reflect more information in the response
2123
* Updated to the latest version of the Azure ClientRuntime
2224

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

183185
## Version 2.3.0
186+

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@
734734
</None>
735735
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ElasticPoolCrudTests\TestElasticPoolUpdateWithZoneRedundancy.json">
736736
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
737+
</None>
738+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ElasticPoolCrudTests\TestElasticPoolCancelOperation.json">
739+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
737740
</None>
738741
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverGroupTests\TestCreateFailoverGroup_AutomaticPolicy.json">
739742
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DatabaseCrudTests.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,17 @@ function Test-CancelDatabaseOperation
563563
.SYNOPSIS
564564
Tests listing and cancelling a database operation
565565
#>
566-
function Test-CancelDatabaseOperationInternal ($location = "westcentralus")
566+
function Test-CancelDatabaseOperationInternal
567567
{
568568
# Setup
569-
$rg = Create-ResourceGroupForTest
569+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
570+
$rg = Create-ResourceGroupForTest $location
570571
$server = Create-ServerForTest $rg $location
571572

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

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

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

588589
# list and cancel a database operation
589590
$dbactivity = Get-AzureRmSqlDatabaseActivity -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/ElasticPoolCrudTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,12 @@ public void TestElasticPoolRemove()
7373
{
7474
RunPowerShellTest("Test-RemoveElasticPool");
7575
}
76+
77+
[Fact]
78+
[Trait(Category.AcceptanceType, Category.CheckIn)]
79+
public void TestElasticPoolCancelOperation()
80+
{
81+
RunPowerShellTest("Test-ListAndCancelElasticPoolOperation");
82+
}
7683
}
7784
}

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/ElasticPoolCrudTests.ps1

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,91 @@ function Test-RemoveElasticPool
297297
{
298298
Remove-ResourceGroupForTest $rg
299299
}
300+
}
301+
302+
<#
303+
.SYNOPSIS
304+
Test listing and cancelling a elastic pool operation
305+
#>
306+
function Test-ListAndCancelElasticPoolOperation
307+
{
308+
# Setup
309+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
310+
$rg = Create-ResourceGroupForTest $location
311+
$server = Create-ServerForTest $rg $location
312+
313+
$poolName = Get-ElasticPoolName
314+
$ep1 = New-AzureRmSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName `
315+
-ElasticPoolName $poolName -Edition Premium -Dtu 125 -DatabaseDtuMin 0 -DatabaseDtuMax 50
316+
Assert-NotNull $ep1
317+
318+
$poolName = Get-ElasticPoolName
319+
$ep2 = $server | New-AzureRmSqlElasticPool -ElasticPoolName $poolName -Edition Premium -Dtu 250 -DatabaseDtuMin 0 `
320+
-DatabaseDtuMax 50
321+
Assert-NotNull $ep2
322+
323+
# Elastic pool will be Premium with DTU 125
324+
325+
try
326+
{
327+
# Update the elastic pool ep1 to premium with 250 Dtu
328+
$ep1update = Set-AzureRmSqlElasticPool -ResourceGroupName $ep1.ResourceGroupName -ServerName $ep1.ServerName -ElasticPoolName $ep1.ElasticPoolName `
329+
-Edition Premium -Dtu 250 -DatabaseDtuMin 25 -DatabaseDtuMax 125
330+
Assert-AreEqual $ep1.ElasticPoolName $ep1update.ElasticPoolName
331+
Assert-AreEqual Premium $ep1update.Edition
332+
Assert-AreEqual 250 $ep1update.Dtu
333+
334+
# List and Cancel the elastic pool update operation
335+
$epactivity = Get-AzureRmSqlElasticPoolActivity -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -ElasticPoolName $ep1update.ElasticPoolName
336+
$epactivityId
337+
338+
For($i=0; $i -lt $epactivity.Length; $i++) {
339+
if($epactivity[$i].Operation -eq "UPDATE"){
340+
$epactivityId = $epactivity[$i].OperationId
341+
}
342+
}
343+
344+
try
345+
{
346+
# cancel a pool update operation with all values
347+
$activityCancel = Stop-AzureRmSqlElasticPoolActivity -ResourceGroupName $ep1.ResourceGroupName -ServerName $ep1.ServerName -ElasticPoolName $ep1.ElasticPoolName -OperationId $epactivityId
348+
}
349+
Catch
350+
{
351+
$ErrorMessage = $_.Exception.Message
352+
Assert-AreEqual True $ErrorMessage.Contains("Cannot cancel management operation '" + $epactivityId + "' in the current state") $ErrorMessage
353+
}
354+
355+
# piping test on related pool operations
356+
# Update ep2 tp Premium with 500 Dtu
357+
$ep2update = Set-AzureRmSqlElasticPool -ResourceGroupName $ep2.ResourceGroupName -ServerName $ep2.ServerName -ElasticPoolName $ep2.ElasticPoolName `
358+
-Edition Premium -Dtu 500 -DatabaseDtuMin 25 -DatabaseDtuMax 250
359+
Assert-AreEqual $ep2.ElasticPoolName $ep2update.ElasticPoolName
360+
Assert-AreEqual Premium $ep2update.Edition
361+
Assert-AreEqual 500 $ep2update.Dtu
362+
363+
$epactivity = $ep2update | Get-AzureRmSqlElasticPoolActivity
364+
For($i=0; $i -lt $epactivity.Length; $i++) {
365+
if($epactivity[$i].Operation -eq "UPDATE"){
366+
$epactivityId = $epactivity[$i].OperationId
367+
}
368+
}
369+
370+
$epactivity = $ep2update | Get-AzureRmSqlElasticPoolActivity -OperationId $epactivityId
371+
372+
try
373+
{
374+
# cancel a pool update operation using piping
375+
$activityCancel = $epactivity | Stop-AzureRmSqlElasticPoolActivity
376+
}
377+
Catch
378+
{
379+
$ErrorMessage = $_.Exception.Message
380+
Assert-AreEqual True $ErrorMessage.Contains("Cannot cancel management operation '" + $epactivityId + "' in the current state") $ErrorMessage
381+
}
382+
}
383+
finally
384+
{
385+
Remove-ResourceGroupForTest $rg
386+
}
300387
}

src/ResourceManager/Sql/Commands.Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ElasticPoolCrudTests/TestElasticPoolCancelOperation.json

Lines changed: 3332 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<Compile Include="Database\Cmdlet\StopAzureSqlDatabaseActivity.cs" />
7171
<Compile Include="Database\Model\DatabaseReadScale.cs" />
7272
<Compile Include="Database\Model\AzureSqlDatabaseCreateOrUpdateModel.cs" />
73+
<Compile Include="Elastic Pools\Cmdlet\StopAzureSqlElasticPoolActivity.cs" />
7374
<Compile Include="Failover Group\Cmdlet\AddAzureSqlDatabaseToFailoverGroup.cs" />
7475
<Compile Include="Failover Group\Cmdlet\AzureSqlFailoverGroupCmdletBase.cs" />
7576
<Compile Include="Failover Group\Cmdlet\GetAzureSqlFailoverGroup.cs" />

src/ResourceManager/Sql/Commands.Sql/Database/Model/AzureSqlDatabaseActivityModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,20 @@ public class DatabaseState
9797
/// Gets or sets the state of the properties associated with the request
9898
/// </summary>
9999
public DatabaseState Properties { get; set; }
100+
101+
/// <summary>
102+
/// Gets or sets the estimated the completion time of the database operation
103+
/// </summary>
104+
public DateTime? EstimatedCompletionTime { get; set; }
105+
106+
/// <summary>
107+
/// Gets or sets the detailed description of the database operation
108+
/// </summary>
109+
public string Description { get; set; }
110+
111+
/// <summary>
112+
/// Gets or sets the value to indicate if the database operation can be cancelled
113+
/// </summary>
114+
public bool? IsCancellable { get; set; }
100115
}
101116
}

src/ResourceManager/Sql/Commands.Sql/Database/Services/AzureSqlDatabaseAdapter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ internal IEnumerable<AzureSqlDatabaseActivityModel> ListDatabaseActivity(string
306306
{
307307
Current = new Dictionary<string, string>(),
308308
Requested = new Dictionary<string, string>()
309-
}
309+
},
310+
EstimatedCompletionTime = r.EstimatedCompletionTime,
311+
Description = r.Description,
312+
IsCancellable = r.IsCancellable
310313
};
311314
});
312315

src/ResourceManager/Sql/Commands.Sql/Elastic Pools/Cmdlet/AzureSqlElasticPoolActivityCmdletBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Commands.Sql.Common;
1818
using Microsoft.Azure.Commands.Sql.ElasticPool.Model;
1919
using Microsoft.Azure.Commands.Sql.ElasticPool.Services;
20+
using System;
2021
using System.Collections.Generic;
2122
using System.Management.Automation;
2223

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

48+
/// <summary>
49+
/// Gets or sets the operation id to use.
50+
/// </summary>
51+
[Parameter(Mandatory = false,
52+
ValueFromPipelineByPropertyName = true,
53+
HelpMessage = "The ID of the operation to retrieve.")]
54+
[ValidateNotNullOrEmpty]
55+
public Guid? OperationId { get; set; }
56+
4757
/// <summary>
4858
/// Initializes the adapter
4959
/// </summary>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 Microsoft.Azure.Commands.Sql.ElasticPool.Model;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
19+
namespace Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet
20+
{
21+
[Cmdlet(VerbsLifecycle.Stop, "AzureRmSqlElasticPoolActivity", SupportsShouldProcess = true), OutputType(typeof(AzureSqlElasticPoolActivityModel))]
22+
public class StopAzureSqlElasticPoolActivity : AzureSqlElasticPoolActivityCmdletBase
23+
{
24+
/// <summary>
25+
/// Defines whether the cmdlets will successfully returned at the end of its execution
26+
/// </summary>
27+
[Parameter(Mandatory = false)]
28+
public SwitchParameter PassThru { get; set; }
29+
30+
/// <summary>
31+
/// Gets elastic pool activity
32+
/// </summary>
33+
/// <returns>List of elastic pool activies</returns>
34+
protected override IEnumerable<AzureSqlElasticPoolActivityModel> GetEntity()
35+
{
36+
return ModelAdapter.GetElasticPoolActivity(this.ResourceGroupName, this.ServerName, this.ElasticPoolName);
37+
}
38+
39+
/// <summary>
40+
/// No user input to apply to model
41+
/// </summary>
42+
/// <param name="model">Model retrieved from service</param>
43+
/// <returns>The model that was passed in</returns>
44+
protected override IEnumerable<AzureSqlElasticPoolActivityModel> ApplyUserInputToModel(IEnumerable<AzureSqlElasticPoolActivityModel> model)
45+
{
46+
return model;
47+
}
48+
49+
/// <summary>
50+
/// No changes to persist to server
51+
/// </summary>
52+
/// <param name="entity">The output of apply user input to model</param>
53+
/// <returns>The input entity</returns>
54+
protected override IEnumerable<AzureSqlElasticPoolActivityModel> PersistChanges(IEnumerable<AzureSqlElasticPoolActivityModel> entity)
55+
{
56+
return ModelAdapter.CancelElasticPoolActivity(this.ResourceGroupName, this.ServerName, this.ElasticPoolName, this.OperationId);
57+
}
58+
59+
/// <summary>
60+
/// Returns true if the model object that was constructed by this cmdlet should be written out
61+
/// </summary>
62+
/// <returns>True if the model object should be written out, False otherwise</returns>
63+
protected override bool WriteResult() { return PassThru; }
64+
}
65+
}

src/ResourceManager/Sql/Commands.Sql/Elastic Pools/Model/AzureSqlElasticPoolActivityModel.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public class AzureSqlElasticPoolActivityModel
3636
/// </summary>
3737
public string ElasticPoolName { get; set; }
3838

39+
/// <summary>
40+
/// Gets or sets the name of the resource group
41+
/// </summary>
42+
public string ResourceGroupName { get; set; }
43+
3944
/// <summary>
4045
/// Gets or sets the state
4146
/// </summary>
@@ -100,5 +105,20 @@ public class AzureSqlElasticPoolActivityModel
100105
/// Gets or sets the requested storage limit in GB
101106
/// </summary>
102107
public long? RequestedStorageLimitInGB { get; set; }
108+
109+
/// <summary>
110+
/// Gets or sets the estimated completion time of the elastic pool operation
111+
/// </summary>
112+
public DateTime? EstimatedCompletionTime { get; set; }
113+
114+
/// <summary>
115+
/// Gets or sets the description of the elastic pool operation
116+
/// </summary>
117+
public string Description { get; set; }
118+
119+
/// <summary>
120+
/// Gets or sets the value to indicate if the elastic pool operation can be cancelled
121+
/// </summary>
122+
public bool? IsCancellable { get; set; }
103123
}
104124
}

0 commit comments

Comments
 (0)