Skip to content

Commit 6666142

Browse files
committed
Merge branch 'taiwu-gw-march' into taiwu-gw-424
2 parents 1a87746 + c65f394 commit 6666142

File tree

9 files changed

+175
-28
lines changed

9 files changed

+175
-28
lines changed

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Test/ScenarioTests/AsTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,13 @@ public void TestAnalysisServicesServerLoginWithSPN()
9393
{
9494
NewInstance.RunPsTest("Test-AnalysisServicesServerLoginWithSPN");
9595
}
96+
97+
[Fact]
98+
[Trait(Category.RunType, Category.LiveOnly)]
99+
public void TestAnalysisServicesServerGateway()
100+
{
101+
NewInstance.RunPsTest("Test-AnalysisServicesServerGateway");
102+
}
103+
96104
}
97105
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Test/ScenarioTests/AsTests.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,31 @@ function Test-AnalysisServicesServerLoginWithSPN
611611
{
612612

613613
}
614+
}
615+
616+
<#
617+
.SYNOPSIS
618+
Tests Analysis Services server lifecycle Failure scenarios (Create, Update, Get, Delete).
619+
#>
620+
function Test-AnalysisServicesServerGateway
621+
{
622+
try
623+
{
624+
625+
# Updating server
626+
$tagsToUpdate = @{"TestTag" = "TestUpdate"}
627+
#$serverUpdated = Set-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -Tag $tagsToUpdate -GatewayName 'azsdktest' -GatewayResourceGroupName 'TestRG' -GatewaySubscriptionId 'ba59a556-5034-4bbb-80b4-4c37cf1083e9' -PassThru
628+
$serverUpdated = Set-AzureRmAnalysisServicesServer -ResourceGroupName 'TestRG' -Name 'azsdktest0309' -Tag $tagsToUpdate -DisassociateGateway -PassThru
629+
Assert-NotNull $serverUpdated.Tag "Tag do not exists"
630+
Assert-NotNull $serverUpdated.Tag["TestTag"] "The updated tag 'TestTag' does not exist"
631+
Assert-AreEqual $serverUpdated.AsAdministrators.Count 2
632+
Assert-AreEqual 1 $serverUpdated.Sku.Capacity
633+
634+
}
635+
finally
636+
{
637+
# cleanup the resource group that was used in case it still exists. This is a best effort task, we ignore failures here.
638+
Invoke-HandledCmdlet -Command {Remove-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -ErrorAction SilentlyContinue} -IgnoreFailures
639+
Invoke-HandledCmdlet -Command {Remove-AzureRmResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue} -IgnoreFailures
640+
}
614641
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Commands.AnalysisServices.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="Models\PsAzureAnalysisServicesFirewallRule.cs" />
5656
<Compile Include="Models\AzureAnalysisServicesServer.cs" />
5757
<Compile Include="Models\ServerSku.cs" />
58+
<Compile Include="Models\ServerGateway.cs" />
5859
<Compile Include="Models\StringOrByteArrayInstance.cs" />
5960
<Compile Include="Properties\AssemblyInfo.cs" />
6061
<Compile Include="Properties\Resources.Designer.cs">

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Commands/NewAzureRmAnalysisServicesServer.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,19 @@ public class NewAnalysisServicesServer : AnalysisServicesCmdletBase
8282
HelpMessage = "Firewall configuration")]
8383
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }
8484

85-
public override void ExecuteCmdlet()
85+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
86+
HelpMessage = "Gateway resource name")]
87+
public string GatewayName { get; set; }
88+
89+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
90+
HelpMessage = "Gateway resource group name")]
91+
public string GatewayResourceGroupName { get; set; }
92+
93+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
94+
HelpMessage = "Gateway subscription Id")]
95+
public string GatewaySubscriptionId { get; set; }
96+
97+
public override void ExecuteCmdlet()
8698
{
8799
if (ShouldProcess(Name, Resources.CreateNewAnalysisServicesServer))
88100
{
@@ -144,7 +156,14 @@ public override void ExecuteCmdlet()
144156
ReadonlyReplicaCount = 0;
145157
}
146158

147-
var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting);
159+
if (string.IsNullOrEmpty(GatewayResourceGroupName))
160+
{
161+
GatewayResourceGroupName = ResourceGroupName;
162+
}
163+
164+
string gatewayId = AnalysisServicesClient.GetGatewayResourceId(GatewayName, GatewayResourceGroupName, GatewaySubscriptionId);
165+
166+
var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, gatewayId);
148167
WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(createdServer));
149168
}
150169
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Commands/SetAzureRmAnalysisServicesServer.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,23 @@ public int ReadonlyReplicaCount
8888
HelpMessage = "Firewall configuration")]
8989
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }
9090

91-
public override void ExecuteCmdlet()
91+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
92+
HelpMessage = "Gateway resource name")]
93+
public string GatewayName { get; set; }
94+
95+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
96+
HelpMessage = "Gateway resource group name")]
97+
public string GatewayResourceGroupName { get; set; }
98+
99+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
100+
HelpMessage = "Gateway subscription Id")]
101+
public string GatewaySubscriptionId { get; set; }
102+
103+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
104+
HelpMessage = "Disassociate current gateway")]
105+
public SwitchParameter DisassociateGateway { get; set; }
106+
107+
public override void ExecuteCmdlet()
92108
{
93109
if (string.IsNullOrEmpty(Name))
94110
{
@@ -147,7 +163,22 @@ public override void ExecuteCmdlet()
147163
ReadonlyReplicaCount = -1;
148164
}
149165

150-
AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting);
166+
if (string.IsNullOrEmpty(GatewayResourceGroupName))
167+
{
168+
GatewayResourceGroupName = ResourceGroupName;
169+
}
170+
171+
string gatewayResourceId = null;
172+
if (DisassociateGateway.IsPresent)
173+
{
174+
gatewayResourceId = "-";
175+
}
176+
else
177+
{
178+
gatewayResourceId = AnalysisServicesClient.GetGatewayResourceId(GatewayName, GatewayResourceGroupName, GatewaySubscriptionId);
179+
}
180+
181+
AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, gatewayResourceId);
151182

152183
if(PassThru.IsPresent)
153184
{

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Models/AnalysisServicesClient.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AnalysisServicesClient
3333
private readonly AnalysisServicesManagementClient _client;
3434
private readonly Guid _subscriptionId;
3535
private readonly string _currentUser;
36+
public const string gatewayResourceIdFormat = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Web/connectionGateways/{2}";
3637

3738
public AnalysisServicesClient(IAzureContext context)
3839
{
@@ -65,7 +66,8 @@ public AnalysisServicesServer CreateOrUpdateServer(
6566
string backupBlobContainerUri = null,
6667
int ReadonlyReplicaCount = 0,
6768
string DefaultConnectionMode = null,
68-
IPv4FirewallSettings setting = null)
69+
IPv4FirewallSettings setting = null,
70+
string gatewayId = null)
6971
{
7072
if (string.IsNullOrEmpty(resourceGroupName))
7173
{
@@ -87,7 +89,17 @@ public AnalysisServicesServer CreateOrUpdateServer(
8789
}
8890
}
8991

90-
AnalysisServicesServer newOrUpdatedServer = null;
92+
GatewayDetails gatewayDetails = null;
93+
if (gatewayId == "-")
94+
{
95+
gatewayDetails = new GatewayDetails("", "", "");
96+
}
97+
else
98+
{
99+
gatewayDetails = new GatewayDetails(gatewayId);
100+
}
101+
102+
AnalysisServicesServer newOrUpdatedServer = null;
91103
if (existingServer != null)
92104
{
93105
var updateParameters = new AnalysisServicesServerUpdateParameters()
@@ -121,6 +133,11 @@ public AnalysisServicesServer CreateOrUpdateServer(
121133
updateParameters.IpV4FirewallSettings = setting;
122134
}
123135

136+
if (gatewayId != null && gatewayId != "-")
137+
{
138+
updateParameters.GatewayDetails = gatewayDetails;
139+
}
140+
124141
newOrUpdatedServer = _client.Servers.Update(resourceGroupName, serverName, updateParameters);
125142
}
126143
else
@@ -142,8 +159,9 @@ public AnalysisServicesServer CreateOrUpdateServer(
142159
Sku = GetResourceSkuFromName(skuName, ReadonlyReplicaCount + 1),
143160
Tags = tags,
144161
QuerypoolConnectionMode = connectionMode,
145-
IpV4FirewallSettings = setting
146-
});
162+
IpV4FirewallSettings = setting,
163+
GatewayDetails = gatewayDetails
164+
});
147165
}
148166

149167
return newOrUpdatedServer;
@@ -263,6 +281,22 @@ public void ResumeServer(string resourceGroupName, string serverName)
263281
_client.Servers.Resume(resourceGroupName, serverName);
264282
}
265283

266-
#endregion
267-
}
284+
public string GetGatewayResourceId(string gatewayName, string resourceGroupName, string subscriptionId)
285+
{
286+
string resourcdId = null;
287+
if (!string.IsNullOrEmpty(gatewayName))
288+
{
289+
if (string.IsNullOrEmpty(subscriptionId))
290+
{
291+
subscriptionId = _client.SubscriptionId;
292+
}
293+
294+
resourcdId = string.Format(gatewayResourceIdFormat, subscriptionId, resourceGroupName, gatewayName);
295+
}
296+
297+
return resourcdId;
298+
}
299+
300+
#endregion
301+
}
268302
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Models/AzureAnalysisServicesServer.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public class AzureAnalysisServicesServer
4747

4848
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }
4949

50-
internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(AnalysisServicesServer server)
50+
public ServerGateway GatewayInfo { get; set; }
51+
52+
internal static AzureAnalysisServicesServer FromAnalysisServicesServer(AnalysisServicesServer server)
5153
{
5254
if (server == null)
5355
{
@@ -77,7 +79,7 @@ internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(Ana
7779
config = new PsAzureAnalysisServicesFirewallConfig(enablePowerBIService, rules);
7880
}
7981

80-
return new AzureAnalysisServicesServerDetail()
82+
return new AzureAnalysisServicesServer()
8183
{
8284
AsAdministrators = server.AsAdministrators == null
8385
? new List<string>()
@@ -89,29 +91,25 @@ internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(Ana
8991
ProvisioningState = server.ProvisioningState,
9092
Id = server.Id,
9193
ServerFullName = server.ServerFullName,
92-
Sku = server.Sku != null ? ServerSku.FromResourceSku(server.Sku) : new Dictionary<string, string>(),
94+
Sku = server.Sku != null ? ServerSku.FromResourceSku(server.Sku) : new ServerSku(),
9395
Tag = server.Tags != null ? new Dictionary<string, string>(server.Tags) : new Dictionary<string, string>(),
9496
BackupBlobContainerUri = server.BackupBlobContainerUri == null ? String.Empty : server.BackupBlobContainerUri,
9597
DefaultConnectionMode = server.QuerypoolConnectionMode.ToString(),
96-
FirewallConfig = config
98+
FirewallConfig = config,
99+
GatewayInfo = server.GatewayDetails != null ? ServerGateway.FromResourceGateway(server.GatewayDetails) : null
97100
};
98101
}
99102

100-
internal static List<AzureAnalysisServicesServerDetail> FromAnalysisServicesServerCollection(List<AnalysisServicesServer> list)
103+
internal static List<AzureAnalysisServicesServer> FromAnalysisServicesServerCollection(List<AnalysisServicesServer> list)
101104
{
102105
if (list == null)
103106
{
104107
return null;
105108
}
106109

107-
var listAzureAnalysisServicesServer = new List<AzureAnalysisServicesServerDetail>();
110+
var listAzureAnalysisServicesServer = new List<AzureAnalysisServicesServer>();
108111
list.ForEach(server => listAzureAnalysisServicesServer.Add(FromAnalysisServicesServer(server)));
109112
return listAzureAnalysisServicesServer;
110113
}
111114
}
112-
113-
public class AzureAnalysisServicesServerDetail : AzureAnalysisServicesServer
114-
{
115-
public new System.Collections.Generic.IDictionary<string, string> Sku { get; set; }
116-
}
117115
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.Management.Analysis.Models;
7+
8+
namespace Microsoft.Azure.Commands.AnalysisServices.Models
9+
{
10+
public class ServerGateway
11+
{
12+
public string GatewayResourceId { get; set; }
13+
14+
public string GatewayObjectId { get; set; }
15+
16+
public string DmtsClusterUri { get; set; }
17+
18+
internal static ServerGateway FromResourceGateway(GatewayDetails resourceGateway)
19+
{
20+
return new ServerGateway()
21+
{
22+
GatewayResourceId = resourceGateway.GatewayResourceId,
23+
GatewayObjectId = resourceGateway.GatewayObjectId != null ? resourceGateway.GatewayObjectId : null,
24+
DmtsClusterUri = resourceGateway.DmtsClusterUri != null ? resourceGateway.DmtsClusterUri : null
25+
};
26+
}
27+
}
28+
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Models/ServerSku.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ public class ServerSku
1515

1616
public int Capacity { get; set; }
1717

18-
internal static Dictionary<string, string> FromResourceSku(ResourceSku resourceSku)
19-
{
20-
Dictionary<string, string> sku = new Dictionary<string, string>();
21-
sku["Name"] = resourceSku.Name;
22-
sku["Tier"] = resourceSku.Tier;
23-
sku["Capacity"] = resourceSku.Capacity == null ? "1" : resourceSku.Capacity.Value.ToString();
24-
return sku;
18+
internal static ServerSku FromResourceSku(ResourceSku resourceSku)
19+
{
20+
return new ServerSku()
21+
{
22+
Name = resourceSku.Name,
23+
Tier = resourceSku.Tier,
24+
Capacity = resourceSku.Capacity == null ? 1 : resourceSku.Capacity.Value
25+
};
2526
}
2627
}
2728
}

0 commit comments

Comments
 (0)