Skip to content

Commit 0b42521

Browse files
author
unknown
committed
[AppGW] Adding probe, multisite, URL routing
1 parent b5a5fe3 commit 0b42521

File tree

12 files changed

+1348
-4670
lines changed

12 files changed

+1348
-4670
lines changed

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ApplicationGatewayTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Commands.Network.Test.ScenarioTests
2020
{
2121
public class ApplicationGatewayTests : RMTestBase
2222
{
23-
[Fact(Skip = "Rerecord tests")]
23+
[Fact]
2424
[Trait(Category.AcceptanceType, Category.CheckIn)]
2525
public void TestApplicationGatewayCRUD()
2626
{

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ApplicationGatewayTests.ps1

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,70 @@ function Test-ApplicationGatewayCRUD
2020
{
2121
# Setup
2222

23-
$rgname = Get-ResourceGroupName
24-
$rname = Get-ResourceName
25-
$domainNameLabel = Get-ResourceName
26-
$vnetName = Get-ResourceName
27-
$publicIpName = Get-ResourceName
28-
$vnetGatewayConfigName = Get-ResourceName
2923
$rglocation = Get-ProviderLocation ResourceManagement
3024
$resourceTypeParent = "Microsoft.Network/applicationgateways"
3125
$location = Get-ProviderLocation $resourceTypeParent
3226

33-
$gipconfigname = Get-ResourceName
34-
$fipconfigName = Get-ResourceName
35-
$poolName = Get-ResourceName
36-
$poolSettingName = Get-ResourceName
37-
$frontendPortName = Get-ResourceName
38-
$listenerName = Get-ResourceName
39-
$ruleName = Get-ResourceName
40-
$appgwName = Get-ResourceName
27+
$rgname = "kagarg"
28+
$vnetName = "vnet01"
29+
$subnetName = "subnet01"
30+
$publicIpName = "publicip01" 
31+
$gipconfigname = "gatewayip01"
32+
$fipconfigName = "frontendip01"
33+
$poolName = "pool01"
34+
$frontendPort01Name = "frontendport01"
35+
$frontendPort02Name = "frontendport02"
36+
$poolSetting01Name = "setting01"
37+
$poolSetting02Name = "setting02"
38+
$probeName ="probe01"
39+
$listener01Name = "listener01"
40+
$listener02Name = "listener02"
41+
$rule01Name = "rule01"
42+
$rule02Name = "rule02"
43+
$appgwName = "appgw01"
4144

4245
try
4346
{
4447
# Create the resource group
45-
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"}
46-
48+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $location -Tags @{Name = "testtag"; Value = "PS testing app gw"}
49+
      
4750
# Create the Virtual Network
48-
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
51+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24
4952
$vnet = New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
5053
$vnet = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
51-
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet
52-
53-
# Create the Application Gateway
54+
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
55+
 
56+
# Create public ip
57+
$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic 
58+
 
59+
# Create application gateway configuration
5460
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration -Name $gipconfigname -Subnet $subnet
55-
$pool = New-AzureRmApplicationGatewayBackendAddressPool -Name $poolName -BackendIPAddresses 1.1.1.1, 2.2.2.2, 3.3.3.3
56-
$poolSetting = New-AzureRmApplicationGatewayBackendHttpSettings -Name $poolSettingName -Port 80 -Protocol HTTP -CookieBasedAffinity Disabled
57-
$fp = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPortName -Port 80
5861
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig -Name $fipconfigName -PublicIPAddress $publicip
59-
$listener = New-AzureRmApplicationGatewayHttpListener -Name $listenerName -Protocol http -FrontendIPConfiguration $fipconfig -FrontendPort $fp
60-
$rule = New-AzureRmApplicationGatewayRequestRoutingRule -Name $ruleName -RuleType basic -BackendHttpSettings $poolSetting -HttpListener $listener -BackendAddressPool $pool
62+
$pool = New-AzureRmApplicationGatewayBackendAddressPool -Name $poolName -BackendIPAddresses 1.1.1.1, 2.2.2.2, 3.3.3.3
63+
$fp01 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort01Name  -Port 80
64+
$fp02 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort02Name  -Port 8080
65+
$probe = New-AzureRmApplicationGatewayProbeConfig -Name $probeName -Protocol Http -HostName "probe.com" -Path "/path/path.htm" -Interval 89 -Timeout 88 -UnhealthyThreshold 8
66+
$poolSetting01 = New-AzureRmApplicationGatewayBackendHttpSettings -Name $poolSetting01Name -Port 80 -Protocol HTTP -CookieBasedAffinity Disabled -Probe $probe -RequestTimeout 66
67+
$poolSetting02 = New-AzureRmApplicationGatewayBackendHttpSettings -Name $poolSetting02Name -Port 80 -Protocol HTTP -CookieBasedAffinity Disabled
68+
$listener01 = New-AzureRmApplicationGatewayHttpListener -Name $listener01Name -Protocol http -FrontendIPConfiguration $fipconfig -FrontendPort $fp01
69+
$listener02 = New-AzureRmApplicationGatewayHttpListener -Name $listener02Name -Protocol http -FrontendIPConfiguration $fipconfig -FrontendPort $fp02
70+
$rule01 = New-AzureRmApplicationGatewayRequestRoutingRule -Name $rule01Name -RuleType basic -BackendHttpSettings $poolSetting01 -HttpListener $listener01 -BackendAddressPool $pool
71+
$rule02 = New-AzureRmApplicationGatewayRequestRoutingRule -Name $rule02Name -RuleType basic -BackendHttpSettings $poolSetting02 -HttpListener $listener02 -BackendAddressPool $pool
6172
$sku = New-AzureRmApplicationGatewaySku -Name Standard_Small -Tier Standard -Capacity 2
6273

63-
$actual = New-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Location $location -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp -HttpListeners $listener -RequestRoutingRules $rule -Sku $sku
64-
$expected = Get-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname
65-
Compare-AzureRmApplicationGateway $actual $expected
66-
67-
Stop-AzureRmApplicationGateway -ApplicationGateway $expected
74+
# Create Application Gateway
75+
$appgw = New-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Location $location -BackendAddressPools $pool -Probes $probe -BackendHttpSettingsCollection $poolSetting01, $poolSetting02 -FrontendIpConfigurations $fipconfig  -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01, $fp02 -HttpListeners $listener01, $listener02 -RequestRoutingRules $rule01, $rule02 -Sku $sku
76+
 
77+
# Get Application Gateway
78+
$getgw =  Get-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname
79+
 
80+
# Start Application Gateway
81+
Start-AzureRmApplicationGateway -ApplicationGateway $getgw
82+
83+
# Stop Application Gateway
84+
Stop-AzureRmApplicationGateway -ApplicationGateway $getgw
85+
 
86+
# Delete Application Gateway
6887
Remove-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Force
6988
}
7089
finally

src/ResourceManager/Network/Commands.Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.ApplicationGatewayTests/TestApplicationGatewayCRUD.json

Lines changed: 1136 additions & 4615 deletions
Large diffs are not rendered by default.

src/ResourceManager/Network/Commands.Network/ApplicationGateway/ApplicationGatewayChildResourceHelper.cs

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,29 @@ public static void NormalizeChildResourcesId(PSApplicationGateway applicationGat
114114
}
115115
}
116116

117+
// Normalize Probe
118+
if (applicationGateway.Probes != null)
119+
{
120+
foreach (var probe in applicationGateway.Probes)
121+
{
122+
probe.Id = string.Empty;
123+
}
124+
}
125+
117126
// Normalize BackendHttpSettings
118127
if (applicationGateway.BackendHttpSettingsCollection != null)
119128
{
120129
foreach (var backendHttpSettings in applicationGateway.BackendHttpSettingsCollection)
121130
{
122131
backendHttpSettings.Id = string.Empty;
132+
133+
if (null != backendHttpSettings.Probe)
134+
{
135+
backendHttpSettings.Probe.Id = NormalizeApplicationGatewayNameChildResourceIds(
136+
backendHttpSettings.Probe.Id,
137+
applicationGateway.ResourceGroupName,
138+
applicationGateway.Name);
139+
}
123140
}
124141
}
125142

@@ -153,6 +170,38 @@ public static void NormalizeChildResourcesId(PSApplicationGateway applicationGat
153170
}
154171
}
155172

173+
// Normalize UrlPathMap
174+
if (applicationGateway.UrlPathMaps != null)
175+
{
176+
foreach (var urlPathMap in applicationGateway.UrlPathMaps)
177+
{
178+
urlPathMap.Id = string.Empty;
179+
180+
urlPathMap.DefaultBackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
181+
urlPathMap.DefaultBackendAddressPool.Id,
182+
applicationGateway.ResourceGroupName,
183+
applicationGateway.Name);
184+
185+
urlPathMap.DefaultBackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
186+
urlPathMap.DefaultBackendHttpSettings.Id,
187+
applicationGateway.ResourceGroupName,
188+
applicationGateway.Name);
189+
190+
foreach (var pathRule in urlPathMap.PathRules)
191+
{
192+
pathRule.BackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
193+
pathRule.BackendAddressPool.Id,
194+
applicationGateway.ResourceGroupName,
195+
applicationGateway.Name);
196+
197+
pathRule.BackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
198+
pathRule.BackendHttpSettings.Id,
199+
applicationGateway.ResourceGroupName,
200+
applicationGateway.Name);
201+
}
202+
}
203+
}
204+
156205
// Normalize RequestRoutingRule
157206
if (applicationGateway.RequestRoutingRules != null)
158207
{
@@ -165,15 +214,29 @@ public static void NormalizeChildResourcesId(PSApplicationGateway applicationGat
165214
applicationGateway.ResourceGroupName,
166215
applicationGateway.Name);
167216

168-
requestRoutingRule.BackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
169-
requestRoutingRule.BackendAddressPool.Id,
217+
if (null != requestRoutingRule.BackendAddressPool)
218+
{
219+
requestRoutingRule.BackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
220+
requestRoutingRule.BackendAddressPool.Id,
221+
applicationGateway.ResourceGroupName,
222+
applicationGateway.Name);
223+
}
224+
225+
if (null != requestRoutingRule.BackendHttpSettings)
226+
{
227+
requestRoutingRule.BackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
228+
requestRoutingRule.BackendHttpSettings.Id,
170229
applicationGateway.ResourceGroupName,
171230
applicationGateway.Name);
231+
}
172232

173-
requestRoutingRule.BackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
174-
requestRoutingRule.BackendHttpSettings.Id,
233+
if (null != requestRoutingRule.UrlPathMap)
234+
{
235+
requestRoutingRule.UrlPathMap.Id = NormalizeApplicationGatewayNameChildResourceIds(
236+
requestRoutingRule.UrlPathMap.Id,
175237
applicationGateway.ResourceGroupName,
176238
applicationGateway.Name);
239+
}
177240
}
178241
}
179242
}

src/ResourceManager/Network/Commands.Network/ApplicationGateway/BackendHttpSettings/AzureApplicationGatewayBackendHttpSettingsBase.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,32 @@ public class AzureApplicationGatewayBackendHttpSettingsBase : NetworkBaseCmdlet
4747
[ValidateNotNullOrEmpty]
4848
public string CookieBasedAffinity { get; set; }
4949

50-
[Parameter(
51-
HelpMessage = "Request Timeout")]
50+
[Parameter(
51+
Mandatory = false,
52+
HelpMessage = "Request Timeout. Default value 30 seconds.")]
5253
[ValidateNotNullOrEmpty]
5354
public uint RequestTimeout { get; set; }
5455

5556
[Parameter(
56-
ParameterSetName = "SetByResourceId",
57-
HelpMessage = "ID of the application gateway Probe")]
57+
Mandatory = false,
58+
HelpMessage = "ID of the application gateway Probe")]
5859
[ValidateNotNullOrEmpty]
5960
public string ProbeId { get; set; }
6061

6162
[Parameter(
62-
ParameterSetName = "SetByResource",
63-
HelpMessage = "Application gateway Probe")]
63+
Mandatory = false,
64+
HelpMessage = "Application gateway Probe")]
6465
[ValidateNotNullOrEmpty]
6566
public PSApplicationGatewayProbe Probe { get; set; }
6667

6768
public override void ExecuteCmdlet()
6869
{
6970
base.ExecuteCmdlet();
7071

71-
if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
72+
if (Probe != null)
7273
{
73-
if (Probe != null)
74-
{
75-
this.ProbeId = this.Probe.Id;
76-
}
77-
}
74+
this.ProbeId = this.Probe.Id;
75+
}
7876
}
7977
public PSApplicationGatewayBackendHttpSettings NewObject()
8078
{
@@ -83,7 +81,14 @@ public PSApplicationGatewayBackendHttpSettings NewObject()
8381
backendHttpSettings.Port = this.Port;
8482
backendHttpSettings.Protocol = this.Protocol;
8583
backendHttpSettings.CookieBasedAffinity = this.CookieBasedAffinity;
86-
backendHttpSettings.RequestTimeout = this.RequestTimeout;
84+
if (0 == this.RequestTimeout)
85+
{
86+
backendHttpSettings.RequestTimeout = 30;
87+
}
88+
else
89+
{
90+
backendHttpSettings.RequestTimeout = this.RequestTimeout;
91+
}
8792
if (!string.IsNullOrEmpty(this.ProbeId))
8893
{
8994
backendHttpSettings.Probe = new PSResourceId();

src/ResourceManager/Network/Commands.Network/ApplicationGateway/NewAzureApplicationGatewayCommand.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public class NewAzureApplicationGatewayCommand : ApplicationGatewayBaseCmdlet
8181
HelpMessage = "The list of frontend port")]
8282
public List<PSApplicationGatewayFrontendPort> FrontendPorts { get; set; }
8383

84+
[Parameter(
85+
Mandatory = false,
86+
ValueFromPipelineByPropertyName = true,
87+
HelpMessage = "The list of probe")]
88+
public List<PSApplicationGatewayProbe> Probes { get; set; }
89+
8490
[Parameter(
8591
Mandatory = true,
8692
ValueFromPipelineByPropertyName = true,
@@ -99,6 +105,12 @@ public class NewAzureApplicationGatewayCommand : ApplicationGatewayBaseCmdlet
99105
HelpMessage = "The list of http listener")]
100106
public List<PSApplicationGatewayHttpListener> HttpListeners { get; set; }
101107

108+
[Parameter(
109+
Mandatory = false,
110+
ValueFromPipelineByPropertyName = true,
111+
HelpMessage = "The list of UrlPathMap")]
112+
public List<PSApplicationGatewayUrlPathMap> UrlPathMaps { get; set; }
113+
102114
[Parameter(
103115
Mandatory = true,
104116
ValueFromPipelineByPropertyName = true,
@@ -171,6 +183,12 @@ private PSApplicationGateway CreateApplicationGateway()
171183
applicationGateway.FrontendPorts = this.FrontendPorts;
172184
}
173185

186+
if (this.Probes != null)
187+
{
188+
applicationGateway.Probes = new List<PSApplicationGatewayProbe>();
189+
applicationGateway.Probes = this.Probes;
190+
}
191+
174192
if (this.BackendAddressPools != null)
175193
{
176194
applicationGateway.BackendAddressPools = new List<PSApplicationGatewayBackendAddressPool>();
@@ -189,6 +207,12 @@ private PSApplicationGateway CreateApplicationGateway()
189207
applicationGateway.HttpListeners = this.HttpListeners;
190208
}
191209

210+
if (this.UrlPathMaps != null)
211+
{
212+
applicationGateway.UrlPathMaps = new List<PSApplicationGatewayUrlPathMap>();
213+
applicationGateway.UrlPathMaps = this.UrlPathMaps;
214+
}
215+
192216
if (this.RequestRoutingRules != null)
193217
{
194218
applicationGateway.RequestRoutingRules = new List<PSApplicationGatewayRequestRoutingRule>();

src/ResourceManager/Network/Commands.Network/ApplicationGateway/Probe/AzureApplicationGatewayProbeConfigBase.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,11 @@ public class AzureApplicationGatewayProbeConfigBase : NetworkBaseCmdlet
5858
[ValidateNotNullOrEmpty]
5959
public uint Timeout { get; set; }
6060

61-
[Parameter(
62-
Mandatory = true,
63-
HelpMessage = "Frontend port")]
64-
[ValidateNotNullOrEmpty]
65-
public uint UnhealthyThreshold { get; set; }
66-
6761
[Parameter(
6862
Mandatory = true,
6963
HelpMessage = "Probe retry count. Backend server is marked down after consecutive probe failure count reaches UnhealthyThreshold")]
7064
[ValidateNotNullOrEmpty]
71-
public string ProvisioningState { get; set; }
65+
public uint UnhealthyThreshold { get; set; }
7266

7367
public PSApplicationGatewayProbe NewObject()
7468
{

src/ResourceManager/Network/Commands.Network/ApplicationGateway/RequestRoutingRule/AzureApplicationGatewayRequestRoutingRuleBase.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public class AzureApplicationGatewayRequestRoutingRuleBase : NetworkBaseCmdlet
6969
HelpMessage = "Application gateway BackendAddressPool")]
7070
[ValidateNotNullOrEmpty]
7171
public PSApplicationGatewayBackendAddressPool BackendAddressPool { get; set; }
72+
73+
[Parameter(
74+
ParameterSetName = "SetByResourceId",
75+
HelpMessage = "ID of the application gateway UrlPathMap")]
76+
[ValidateNotNullOrEmpty]
77+
public string UrlPathMapId { get; set; }
78+
79+
[Parameter(
80+
ParameterSetName = "SetByResource",
81+
HelpMessage = "Application gateway UrlPathMap")]
82+
[ValidateNotNullOrEmpty]
83+
public PSApplicationGatewayUrlPathMap UrlPathMap { get; set; }
7284
public override void ExecuteCmdlet()
7385
{
7486
base.ExecuteCmdlet();
@@ -87,6 +99,10 @@ public override void ExecuteCmdlet()
8799
{
88100
this.HttpListenerId = this.HttpListener.Id;
89101
}
102+
if (UrlPathMap != null)
103+
{
104+
this.UrlPathMapId = this.UrlPathMap.Id;
105+
}
90106
}
91107
}
92108

@@ -112,6 +128,11 @@ public PSApplicationGatewayRequestRoutingRule NewObject()
112128
requestRoutingRule.BackendAddressPool = new PSResourceId();
113129
requestRoutingRule.BackendAddressPool.Id = this.BackendAddressPoolId;
114130
}
131+
if (!string.IsNullOrEmpty(this.UrlPathMapId))
132+
{
133+
requestRoutingRule.UrlPathMap = new PSResourceId();
134+
requestRoutingRule.UrlPathMap.Id = this.UrlPathMapId;
135+
}
115136

116137
requestRoutingRule.Id = ApplicationGatewayChildResourceHelper.GetResourceNotSetId(
117138
this.NetworkClient.NetworkManagementClient.SubscriptionId,

0 commit comments

Comments
 (0)