Skip to content

Commit ba8ef9d

Browse files
committed
Update gateway association using resource id
1 parent 89febba commit ba8ef9d

File tree

4 files changed

+30
-70
lines changed

4 files changed

+30
-70
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,21 @@ function Test-AnalysisServicesServerGateway
621621
{
622622
try
623623
{
624+
# Creating server
625+
$location = Get-Location
626+
$resourceGroupName = Get-ResourceGroupName
627+
$serverName = Get-AnalysisServicesServerName
628+
$gatewayName = $env:GATEWAY_NAME
629+
$gateway = Get-AzureRmResource -ResourceName $gatewayName -ResourceGroupName $resourceGroupName
630+
$serverCreated = New-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -Location $location -Sku S0 -GatewayResourceId $gateway.ResourceId -PassThru
624631

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
632+
Assert-True {$serverCreated.ProvisioningState -like "Succeeded"}
633+
Assert-True {$serverCreated.State -like "Succeeded"}
634+
Assert-AreEqual $gateway.ResourceId $serverCreated.GatewayDetails.GatewayResourceId
633635

636+
# Dissociate gateway from server
637+
$serverUpdated = Set-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -DisassociateGateway -PassThru
638+
Assert-True {[string]::IsNullOrEmpty($serverUpdated.GatewayDetails.GatewayResourceId)}
634639
}
635640
finally
636641
{

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,8 @@ public class NewAnalysisServicesServer : AnalysisServicesCmdletBase
8383
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }
8484

8585
[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; }
86+
HelpMessage = "Gateway resource ID")]
87+
public string GatewayResourceId { get; set; }
9688

9789
public override void ExecuteCmdlet()
9890
{
@@ -156,14 +148,7 @@ public override void ExecuteCmdlet()
156148
ReadonlyReplicaCount = 0;
157149
}
158150

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);
151+
var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, GatewayResourceId);
167152
WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(createdServer));
168153
}
169154
}

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,8 @@ public int ReadonlyReplicaCount
8989
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }
9090

9191
[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; }
92+
HelpMessage = "Gateway resource ID")]
93+
public string GatewayResourceId { get; set; }
10294

10395
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
10496
HelpMessage = "Disassociate current gateway")]
@@ -163,22 +155,12 @@ public override void ExecuteCmdlet()
163155
ReadonlyReplicaCount = -1;
164156
}
165157

166-
if (string.IsNullOrEmpty(GatewayResourceGroupName))
167-
{
168-
GatewayResourceGroupName = ResourceGroupName;
169-
}
170-
171-
string gatewayResourceId = null;
172158
if (DisassociateGateway.IsPresent)
173159
{
174-
gatewayResourceId = "-";
175-
}
176-
else
177-
{
178-
gatewayResourceId = AnalysisServicesClient.GetGatewayResourceId(GatewayName, GatewayResourceGroupName, GatewaySubscriptionId);
160+
GatewayResourceId = "-";
179161
}
180162

181-
AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, gatewayResourceId);
163+
AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, GatewayResourceId);
182164

183165
if(PassThru.IsPresent)
184166
{

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ 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}";
3736

3837
public AnalysisServicesClient(IAzureContext context)
3938
{
@@ -67,7 +66,7 @@ public AnalysisServicesServer CreateOrUpdateServer(
6766
int ReadonlyReplicaCount = 0,
6867
string DefaultConnectionMode = null,
6968
IPv4FirewallSettings setting = null,
70-
string gatewayId = null)
69+
string gatewayResourceId = null)
7170
{
7271
if (string.IsNullOrEmpty(resourceGroupName))
7372
{
@@ -90,13 +89,13 @@ public AnalysisServicesServer CreateOrUpdateServer(
9089
}
9190

9291
GatewayDetails gatewayDetails = null;
93-
if (gatewayId == "-")
92+
if (gatewayResourceId == "-")
9493
{
9594
gatewayDetails = new GatewayDetails();
9695
}
97-
else
96+
else if (gatewayResourceId != null)
9897
{
99-
gatewayDetails = new GatewayDetails(gatewayId);
98+
gatewayDetails = new GatewayDetails(gatewayResourceId);
10099
}
101100

102101
AnalysisServicesServer newOrUpdatedServer = null;
@@ -133,7 +132,7 @@ public AnalysisServicesServer CreateOrUpdateServer(
133132
updateParameters.IpV4FirewallSettings = setting;
134133
}
135134

136-
if (gatewayId != null)
135+
if (gatewayDetails != null)
137136
{
138137
updateParameters.GatewayDetails = gatewayDetails;
139138
}
@@ -148,6 +147,11 @@ public AnalysisServicesServer CreateOrUpdateServer(
148147
connectionMode = (ConnectionMode)Enum.Parse(typeof(ConnectionMode), DefaultConnectionMode, true);
149148
}
150149

150+
if (adminList.Count == 0)
151+
{
152+
adminList.Add(_currentUser);
153+
}
154+
151155
newOrUpdatedServer = _client.Servers.Create(
152156
resourceGroupName,
153157
serverName,
@@ -281,22 +285,6 @@ public void ResumeServer(string resourceGroupName, string serverName)
281285
_client.Servers.Resume(resourceGroupName, serverName);
282286
}
283287

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-
300288
#endregion
301289
}
302290
}

0 commit comments

Comments
 (0)