Skip to content

Commit b3a3ece

Browse files
idear1203Dongwei Wang
andauthored
[Synapse] - Supports -Force parameter for Remove-* cmdlets (#13445)
* Remove cmdlets should support -Force and Confirmation message * Update help doc * Update ChangeLog * Address comments * Fix test failure Co-authored-by: Dongwei Wang <[email protected]>
1 parent 38898b9 commit b3a3ece

33 files changed

+570
-150
lines changed

src/Synapse/Synapse.Test/ScenarioTests/FirewallTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Test-SynapseFirewall
4747
Assert-AreEqual $NewEndIpAddress $firewallUpdate.EndIpAddress
4848

4949
# Delete firewall
50-
Assert-True {Remove-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $firewallRuleName -PassThru} "Remove firewall rule failed"
50+
Assert-True {Remove-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $firewallRuleName -PassThru -Force} "Remove firewall rule failed"
5151
}
5252
finally
5353
{

src/Synapse/Synapse.Test/ScenarioTests/SparkPoolTests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ function Test-SynapseSparkPool
125125
Assert-True {$found -eq 1} "SparkPool created earlier is not found when listing all in resource group: $resourceGroupName."
126126

127127
# Delete SparkPool
128-
Assert-True {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolName -PassThru} "Remove SparkPool failed."
129-
Assert-True {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolNameForAutoScale -PassThru} "Remove SparkPool failed."
128+
Assert-True {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolName -PassThru -Force} "Remove SparkPool failed."
129+
Assert-True {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolNameForAutoScale -PassThru -Force} "Remove SparkPool failed."
130130

131131
# Verify that it is gone by trying to get it again
132132
Assert-Throws {Get-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolName}
133133
}
134134
finally
135135
{
136136
# cleanup the spark pool that was used in case it still exists. This is a best effort task, we ignore failures here.
137-
Invoke-HandledCmdlet -Command {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolName -ErrorAction SilentlyContinue} -IgnoreFailures
138-
Invoke-HandledCmdlet -Command {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolNameForAutoScale -ErrorAction SilentlyContinue} -IgnoreFailures
137+
Invoke-HandledCmdlet -Command {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolName -ErrorAction SilentlyContinue -Force} -IgnoreFailures
138+
Invoke-HandledCmdlet -Command {Remove-AzSynapseSparkPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sparkPoolNameForAutoScale -ErrorAction SilentlyContinue -Force} -IgnoreFailures
139139
}
140140
}

src/Synapse/Synapse.Test/ScenarioTests/SqlDatabaseTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Test-SynapseSqlDatabase
5858
Assert-True {$found -eq 1} "SqlDatabase created earlier is not found when listing all in resource group: $resourceGroupName."
5959

6060
# Delete SqlDatabase
61-
Assert-True {Remove-AzSynapseSqlDatabase -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $SqlDatabaseName -PassThru} "Remove SqlDatabase failed."
61+
Assert-True {Remove-AzSynapseSqlDatabase -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $SqlDatabaseName -PassThru -Force} "Remove SqlDatabase failed."
6262

6363
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(180000)
6464

@@ -68,6 +68,6 @@ function Test-SynapseSqlDatabase
6868
finally
6969
{
7070
# cleanup the SQL pool that was used in case it still exists. This is a best effort task, we ignore failures here.
71-
Invoke-HandledCmdlet -Command {Remove-AzSynapseSqlDatabase -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $SqlDatabaseName -ErrorAction SilentlyContinue} -IgnoreFailures
71+
Invoke-HandledCmdlet -Command {Remove-AzSynapseSqlDatabase -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $SqlDatabaseName -ErrorAction SilentlyContinue -Force} -IgnoreFailures
7272
}
7373
}

src/Synapse/Synapse.Test/ScenarioTests/SqlPoolTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function Test-SynapseSqlPool
8787
Assert-True {$found -eq 1} "SqlPool created earlier is not found when listing all in resource group: $resourceGroupName."
8888

8989
# Delete SqlPool
90-
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -PassThru} "Remove SqlPool failed."
90+
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -PassThru -Force} "Remove SqlPool failed."
9191

9292
# Verify that it is gone by trying to get it again
9393
Assert-Throws {Get-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName}
@@ -115,11 +115,11 @@ function Test-SynapseSqlPool
115115
Assert-AreEqual "Online" $sqlPoolResumed.Status
116116

117117
# Delete SqlPool
118-
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -PassThru} "Remove SqlPool failed."
118+
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -PassThru -Force} "Remove SqlPool failed."
119119
}
120120
finally
121121
{
122122
# cleanup the SQL pool that was used in case it still exists. This is a best effort task, we ignore failures here.
123-
Invoke-HandledCmdlet -Command {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -ErrorAction SilentlyContinue} -IgnoreFailures
123+
Invoke-HandledCmdlet -Command {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -ErrorAction SilentlyContinue -Force} -IgnoreFailures
124124
}
125125
}

src/Synapse/Synapse.Test/ScenarioTests/SqlPoolV3Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function Test-SynapseSqlPoolV3
8686
Assert-True {$found -eq 1} "SqlPool created earlier is not found when listing all in resource group: $resourceGroupName."
8787

8888
# Delete SqlPool
89-
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -Version 3 -PassThru} "Remove SqlPool failed."
89+
Assert-True {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -Version 3 -PassThru -Force} "Remove SqlPool failed."
9090

9191
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(180000)
9292

@@ -96,6 +96,6 @@ function Test-SynapseSqlPoolV3
9696
finally
9797
{
9898
# cleanup the SQL pool that was used in case it still exists. This is a best effort task, we ignore failures here.
99-
Invoke-HandledCmdlet -Command {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -Version 3 -ErrorAction SilentlyContinue} -IgnoreFailures
99+
Invoke-HandledCmdlet -Command {Remove-AzSynapseSqlPool -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $sqlPoolName -Version 3 -ErrorAction SilentlyContinue -Force} -IgnoreFailures
100100
}
101101
}

src/Synapse/Synapse.Test/ScenarioTests/WorkspaceTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ function Test-SynapseWorkspace
114114
Assert-True {$found -eq 1} "Workspace created earlier is not found when listing all in subscription."
115115

116116
# Delete workspace
117-
Assert-True {Remove-AzSynapseWorkspace -ResourceGroupName $resourceGroupName -Name $workspaceName -PassThru} "Remove Workspace failed."
117+
Assert-True {Remove-AzSynapseWorkspace -ResourceGroupName $resourceGroupName -Name $workspaceName -PassThru -Force} "Remove Workspace failed."
118118

119119
# Verify that it is gone by trying to get it again
120120
Assert-Throws {Get-AzSynapseWorkspace -ResourceGroupName $resourceGroupName -Name $workspaceName}
121121
}
122122
finally
123123
{
124124
# cleanup the resource group that was used in case it still exists. This is a best effort task, we ignore failures here.
125-
Invoke-HandledCmdlet -Command {Remove-AzSynapseWorkspace -ResourceGroupName $resourceGroupName -Name $workspaceName -ErrorAction SilentlyContinue} -IgnoreFailures
125+
Invoke-HandledCmdlet -Command {Remove-AzSynapseWorkspace -ResourceGroupName $resourceGroupName -Name $workspaceName -ErrorAction SilentlyContinue -Force} -IgnoreFailures
126126
Invoke-HandledCmdlet -Command {Remove-AzResourceGroup -Name $resourceGroupName -Force -ErrorAction SilentlyContinue} -IgnoreFailures
127127
}
128128
}

src/Synapse/Synapse/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Add `-Force` to all Remove cmdlets
2122

2223
## Version 0.3.0
2324
* Added support for operation of Synapse LinkedService

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/DataFlows/RemoveAzureSynapseDataFlow.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class RemoveAzureSynapseDataFlow : SynapseArtifactsCmdletBase
4747
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
4848
public SwitchParameter AsJob { get; set; }
4949

50+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
51+
public SwitchParameter Force { get; set; }
52+
5053
public override void ExecuteCmdlet()
5154
{
5255
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -60,14 +63,19 @@ public override void ExecuteCmdlet()
6063
this.Name = this.InputObject.Name;
6164
}
6265

63-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapseDataFlow, this.Name, this.WorkspaceName)))
64-
{
65-
SynapseAnalyticsClient.DeleteDataFlow(this.Name);
66-
if (PassThru)
66+
ConfirmAction(
67+
Force.IsPresent,
68+
string.Format(Resources.RemoveSynapseDataFlow, Name),
69+
string.Format(Resources.RemovingSynapseDataFlow, this.Name, this.WorkspaceName),
70+
Name,
71+
() =>
6772
{
68-
WriteObject(true);
69-
}
70-
}
73+
SynapseAnalyticsClient.DeleteDataFlow(this.Name);
74+
if (PassThru)
75+
{
76+
WriteObject(true);
77+
}
78+
});
7179
}
7280
}
7381
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Datasets/RemoveAzureSynapseDataset.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class RemoveAzureSynapseDataset : SynapseArtifactsCmdletBase
4949
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
5050
public SwitchParameter AsJob { get; set; }
5151

52+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
53+
public SwitchParameter Force { get; set; }
54+
5255
public override void ExecuteCmdlet()
5356
{
5457
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -62,14 +65,19 @@ public override void ExecuteCmdlet()
6265
this.Name = this.InputObject.Name;
6366
}
6467

65-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapseDataset, this.Name, this.WorkspaceName)))
66-
{
67-
SynapseAnalyticsClient.DeleteDataset(this.Name);
68-
if (PassThru)
68+
ConfirmAction(
69+
Force.IsPresent,
70+
string.Format(Resources.RemoveSynapseDataset, Name),
71+
string.Format(Resources.RemovingSynapseDataset, this.Name, this.WorkspaceName),
72+
Name,
73+
() =>
6974
{
70-
WriteObject(true);
71-
}
72-
}
75+
SynapseAnalyticsClient.DeleteDataset(this.Name);
76+
if (PassThru)
77+
{
78+
WriteObject(true);
79+
}
80+
});
7381
}
7482
}
7583
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/LinkedServices/RemoveAzureSynapseLinkedService.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class RemoveAzureSynapseLinkedService : SynapseArtifactsCmdletBase
4747
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
4848
public SwitchParameter AsJob { get; set; }
4949

50+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
51+
public SwitchParameter Force { get; set; }
52+
5053
public override void ExecuteCmdlet()
5154
{
5255
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -60,14 +63,19 @@ public override void ExecuteCmdlet()
6063
this.Name = this.InputObject.Name;
6164
}
6265

63-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapseLinkedService, this.Name, this.WorkspaceName)))
64-
{
65-
SynapseAnalyticsClient.DeleteLinkedService(this.Name);
66-
if (PassThru)
66+
ConfirmAction(
67+
Force.IsPresent,
68+
string.Format(Resources.RemoveSynapseLinkedService, Name),
69+
string.Format(Resources.RemovingSynapseLinkedService, this.Name, this.WorkspaceName),
70+
Name,
71+
() =>
6772
{
68-
WriteObject(true);
69-
}
70-
}
73+
SynapseAnalyticsClient.DeleteLinkedService(this.Name);
74+
if (PassThru)
75+
{
76+
WriteObject(true);
77+
}
78+
});
7179
}
7280
}
7381
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Notebooks/RemoveAzureSynapseNotebook.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.Azure.Commands.Synapse.Models;
44
using Microsoft.Azure.Commands.Synapse.Properties;
55
using Microsoft.WindowsAzure.Commands.Utilities.Common;
6-
using System;
76
using System.Management.Automation;
87

98
namespace Microsoft.Azure.Commands.Synapse
@@ -47,6 +46,9 @@ public class RemoveAzureSynapseNotebook : SynapseArtifactsCmdletBase
4746
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
4847
public SwitchParameter AsJob { get; set; }
4948

49+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
50+
public SwitchParameter Force { get; set; }
51+
5052
public override void ExecuteCmdlet()
5153
{
5254
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -60,14 +62,19 @@ public override void ExecuteCmdlet()
6062
this.Name = this.InputObject.Name;
6163
}
6264

63-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapseNotebook, this.Name, this.WorkspaceName)))
64-
{
65-
SynapseAnalyticsClient.DeleteNotebook(this.Name);
66-
if (PassThru)
65+
ConfirmAction(
66+
Force.IsPresent,
67+
string.Format(Resources.RemoveSynapseNotebook, Name),
68+
string.Format(Resources.RemovingSynapseNotebook, this.Name, this.WorkspaceName),
69+
Name,
70+
() =>
6771
{
68-
WriteObject(true);
69-
}
70-
}
72+
SynapseAnalyticsClient.DeleteNotebook(this.Name);
73+
if (PassThru)
74+
{
75+
WriteObject(true);
76+
}
77+
});
7178
}
7279
}
7380
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Pipelines/RemoveAzureSynapsePipeline.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class RemoveAzureSynapsePipeline : SynapseArtifactsCmdletBase
4444
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
4545
public SwitchParameter AsJob { get; set; }
4646

47+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
48+
public SwitchParameter Force { get; set; }
49+
4750
public override void ExecuteCmdlet()
4851
{
4952
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -57,14 +60,19 @@ public override void ExecuteCmdlet()
5760
this.Name = this.InputObject.Name;
5861
}
5962

60-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapsePipeline, this.Name, this.WorkspaceName)))
61-
{
62-
SynapseAnalyticsClient.DeletePipeline(this.Name);
63-
if (PassThru)
63+
ConfirmAction(
64+
Force.IsPresent,
65+
string.Format(Resources.RemoveSynapsePipeline, Name),
66+
string.Format(Resources.RemovingSynapsePipeline, this.Name, this.WorkspaceName),
67+
Name,
68+
() =>
6469
{
65-
WriteObject(true);
66-
}
67-
}
70+
SynapseAnalyticsClient.DeletePipeline(this.Name);
71+
if (PassThru)
72+
{
73+
WriteObject(true);
74+
}
75+
});
6876
}
6977
}
7078
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Triggers/RemoveAzureSynapseTrigger.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class RemoveAzureSynapseTrigger : SynapseArtifactsCmdletBase
4747
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
4848
public SwitchParameter AsJob { get; set; }
4949

50+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
51+
public SwitchParameter Force { get; set; }
52+
5053
public override void ExecuteCmdlet()
5154
{
5255
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -60,14 +63,19 @@ public override void ExecuteCmdlet()
6063
this.Name = this.InputObject.Name;
6164
}
6265

63-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapseTrigger, this.Name, this.WorkspaceName)))
64-
{
65-
SynapseAnalyticsClient.DeleteTrigger(this.Name);
66-
if (PassThru)
66+
ConfirmAction(
67+
Force.IsPresent,
68+
string.Format(Resources.RemoveSynapseTrigger, Name),
69+
string.Format(Resources.RemovingSynapseTrigger, this.Name, this.WorkspaceName),
70+
Name,
71+
() =>
6772
{
68-
WriteObject(true);
69-
}
70-
}
73+
SynapseAnalyticsClient.DeleteTrigger(this.Name);
74+
if (PassThru)
75+
{
76+
WriteObject(true);
77+
}
78+
});
7179
}
7280
}
7381
}

src/Synapse/Synapse/Commands/DataPlaneCommands/Artifact/Triggers/RemoveAzureSynapseTriggerSubscription.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class RemoveAzureSynapseTriggerSubscription : SynapseArtifactsCmdletBase
4747
[Parameter(Mandatory = false, HelpMessage = HelpMessages.AsJob)]
4848
public SwitchParameter AsJob { get; set; }
4949

50+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.Force)]
51+
public SwitchParameter Force { get; set; }
52+
5053
public override void ExecuteCmdlet()
5154
{
5255
if (this.IsParameterBound(c => c.WorkspaceObject))
@@ -60,14 +63,19 @@ public override void ExecuteCmdlet()
6063
this.Name = this.InputObject.Name;
6164
}
6265

63-
if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.RemovingSynapseTriggerSubscription, this.Name)))
64-
{
65-
SynapseAnalyticsClient.StartUnsubscribeTriggerFromEvents(this.Name);
66-
if (PassThru)
66+
ConfirmAction(
67+
Force.IsPresent,
68+
string.Format(Resources.RemoveSynapseTriggerSubscription, Name),
69+
string.Format(Resources.RemovingSynapseTriggerSubscription, this.Name),
70+
Name,
71+
() =>
6772
{
68-
WriteObject(true);
69-
}
70-
}
73+
SynapseAnalyticsClient.StartUnsubscribeTriggerFromEvents(this.Name);
74+
if (PassThru)
75+
{
76+
WriteObject(true);
77+
}
78+
});
7179
}
7280
}
7381
}

0 commit comments

Comments
 (0)