-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathDeleteClusterARM.ps1
67 lines (61 loc) · 2.17 KB
/
DeleteClusterARM.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
[CmdletBinding(PositionalBinding=$True)]
Param(
[Parameter(Mandatory = $true)]
[ValidatePattern("^[a-zA-Z0-9-]*$")]
[ValidateLength(8,64)]
[String]$ResourceGroupName, # required needs to be alphanumeric or "-"
[Parameter(Mandatory = $true)]
[ValidatePattern("^[a-z0-9-]*$")]
[ValidateLength(8,64)]
[String]$ClusterName # required needs to be alphanumeric or "-"
)
###########################################################
# Start - Initialization - Invocation, Logging etc
###########################################################
$VerbosePreference = "SilentlyContinue"
$ErrorActionPreference = "Stop"
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path $scriptPath
& "$scriptDir\..\..\init.ps1"
if(-not $?)
{
throw "Initialization failure."
exit -9999
}
###########################################################
# End - Initialization - Invocation, Logging etc
###########################################################
Write-InfoLog "Deleting Azure HDInsight cluster: $ClusterName from Resource Group: $ResourceGroupName" (Get-ScriptName) (Get-ScriptLineNumber)
try
{
$cluster = Get-AzureRmHDInsightCluster -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName
if ($cluster)
{
try
{
Remove-AzureRmHDInsightCluster -ResourceGroupName $ResourceGroupName -ClusterName $ClusterName
}
catch
{
Write-ErrorLog "Failed to delete HDInsight cluster: $ClusterName" (Get-ScriptName) (Get-ScriptLineNumber) $_
throw
}
}
}
catch
{
if ($_.Exception.Error.Code -eq "ResourceNotFound")
{
Write-InfoLog "Success! HDInsight cluster not found: $ClusterName" (Get-ScriptName) (Get-ScriptLineNumber) $_
}
elseif ($_.Exception.Error.Code -eq "ParentResourceNotFound")
{
Write-WarnLog "An unexpected error occured while deleting the HDInsight cluster: $ClusterName" (Get-ScriptName) (Get-ScriptLineNumber) $_
throw
}
else
{
Write-ErrorLog "Could not get details for HDInsight cluster: $ClusterName" (Get-ScriptName) (Get-ScriptLineNumber) $_
throw
}
}