Skip to content

[Azure Analysis Services] Enable associate/dissociate gateway with AS. #6043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 11, 2018
1 change: 1 addition & 0 deletions src/ResourceManager/AnalysisServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Current Release
* Enable Gateway assocaite/disassociate operations on AS.

## Version 0.6.7
* Set minimum dependency of module to PowerShell 5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,13 @@ public void TestAnalysisServicesServerLoginWithSPN()
{
NewInstance.RunPsTest("Test-AnalysisServicesServerLoginWithSPN");
}

[Fact]
[Trait(Category.RunType, Category.LiveOnly)]
public void TestAnalysisServicesServerGateway()
{
NewInstance.RunPsTest("Test-AnalysisServicesServerGateway");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,40 @@ function Test-AnalysisServicesServerLoginWithSPN
{

}
}

<#
.SYNOPSIS
Tests Analysis Services server gateway scenarios (associate/dissociate).
The assocaited gateway is a unified gateway, which required pre-setup.
1. Install on-premise gateway on target host https://www.microsoft.com/en-us/download/details.aspx?id=53127
2. Follow installation instruction to create azure on-premise gateway resource associating to the host.
Afterward, use the gateway resource to associate with the AAS for testing.
#>
function Test-AnalysisServicesServerGateway
{
try
{
# Creating server
$location = Get-Location
$resourceGroupName = Get-ResourceGroupName
$serverName = Get-AnalysisServicesServerName
$gatewayName = $env:GATEWAY_NAME
$gateway = Get-AzureRmResource -ResourceName $gatewayName -ResourceGroupName $resourceGroupName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this test assumes that the gateway server already exists in the subscription/RG... Is it possible to create the gateway server as part of the test?

Otherwise some one (lets say a person in the PS team) would not be able to re-record the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This have to be a pre-setup azure resource, which requires user to install unified gateway on their on-premise server and generate an gateway azure resource associated on it. It is not possible to automate the procedure in few lines of powershell scripts. This is LiveOnly test.

Copy link
Contributor

@praries880 praries880 May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok... can you add a comment to the test case that describes what all needs to be done for one to be able to set up the gateway server , the documentation could be as simple as pointing the person to follow an online guide on how to get it done as well ;) )?
That way the person running the test will have the instructions to do so....

$serverCreated = New-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -Location $location -Sku S0 -GatewayResourceId $gateway.ResourceId -PassThru

Assert-True {$serverCreated.ProvisioningState -like "Succeeded"}
Assert-True {$serverCreated.State -like "Succeeded"}
Assert-AreEqual $gateway.ResourceId $serverCreated.GatewayDetails.GatewayResourceId

# Dissociate gateway from server
$serverUpdated = Set-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -DisassociateGateway -PassThru
Assert-True {[string]::IsNullOrEmpty($serverUpdated.GatewayDetails.GatewayResourceId)}
}
finally
{
# cleanup the resource group that was used in case it still exists. This is a best effort task, we ignore failures here.
Invoke-HandledCmdlet -Command {Remove-AzureRmAnalysisServicesServer -ResourceGroupName $resourceGroupName -Name $serverName -ErrorAction SilentlyContinue} -IgnoreFailures
Invoke-HandledCmdlet -Command {Remove-AzureRmResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue} -IgnoreFailures
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Models\PsAzureAnalysisServicesFirewallRule.cs" />
<Compile Include="Models\AzureAnalysisServicesServer.cs" />
<Compile Include="Models\ServerSku.cs" />
<Compile Include="Models\ServerGateway.cs" />
<Compile Include="Models\StringOrByteArrayInstance.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class NewAnalysisServicesServer : AnalysisServicesCmdletBase
HelpMessage = "Firewall configuration")]
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
HelpMessage = "Gateway resource ID")]
public string GatewayResourceId { get; set; }

public override void ExecuteCmdlet()
{
if (ShouldProcess(Name, Resources.CreateNewAnalysisServicesServer))
Expand Down Expand Up @@ -144,7 +148,7 @@ public override void ExecuteCmdlet()
ReadonlyReplicaCount = 0;
}

var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting);
var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, GatewayResourceId);
WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(createdServer));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SetAzureAnalysisServicesServer : AnalysisServicesCmdletBase
{
private const string ParamSetDefault = "Default";
private const string ParamSetDisableBackup = "DisableBackup";
private const string ParamSetDisassociatGateway = "DisassociateGateway";

[Parameter(ValueFromPipelineByPropertyName = true, Position = 0, Mandatory = true,
HelpMessage = "Name of the server.")]
Expand Down Expand Up @@ -88,6 +89,16 @@ public int ReadonlyReplicaCount
HelpMessage = "Firewall configuration")]
public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markcowl updated, please review again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be in separate parameter sets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markcowl updated

ParameterSetName = ParamSetDefault,
HelpMessage = "Gateway resource ID")]
public string GatewayResourceId { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false,
ParameterSetName = ParamSetDisassociatGateway,
HelpMessage = "Disassociate current gateway")]
public SwitchParameter DisassociateGateway { get; set; }

public override void ExecuteCmdlet()
{
if (string.IsNullOrEmpty(Name))
Expand Down Expand Up @@ -147,7 +158,12 @@ public override void ExecuteCmdlet()
ReadonlyReplicaCount = -1;
}

AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting);
if (DisassociateGateway.IsPresent)
{
GatewayResourceId = AnalysisServicesClient.DissasociateGateway;
}

AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, GatewayResourceId);

if(PassThru.IsPresent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AnalysisServicesClient
private readonly AnalysisServicesManagementClient _client;
private readonly Guid _subscriptionId;
private readonly string _currentUser;
public const string DissasociateGateway = "-";

public AnalysisServicesClient(IAzureContext context)
{
Expand Down Expand Up @@ -65,7 +66,8 @@ public AnalysisServicesServer CreateOrUpdateServer(
string backupBlobContainerUri = null,
int ReadonlyReplicaCount = 0,
string DefaultConnectionMode = null,
IPv4FirewallSettings setting = null)
IPv4FirewallSettings setting = null,
string gatewayResourceId = null)
{
if (string.IsNullOrEmpty(resourceGroupName))
{
Expand All @@ -87,6 +89,16 @@ public AnalysisServicesServer CreateOrUpdateServer(
}
}

GatewayDetails gatewayDetails = null;
if (gatewayResourceId == DissasociateGateway)
{
gatewayDetails = new GatewayDetails();
}
else if (gatewayResourceId != null)
{
gatewayDetails = new GatewayDetails(gatewayResourceId);
}

AnalysisServicesServer newOrUpdatedServer = null;
if (existingServer != null)
{
Expand Down Expand Up @@ -121,6 +133,11 @@ public AnalysisServicesServer CreateOrUpdateServer(
updateParameters.IpV4FirewallSettings = setting;
}

if (gatewayDetails != null)
{
updateParameters.GatewayDetails = gatewayDetails;
}

newOrUpdatedServer = _client.Servers.Update(resourceGroupName, serverName, updateParameters);
}
else
Expand All @@ -131,6 +148,11 @@ public AnalysisServicesServer CreateOrUpdateServer(
connectionMode = (ConnectionMode)Enum.Parse(typeof(ConnectionMode), DefaultConnectionMode, true);
}

if (adminList.Count == 0)
{
adminList.Add(_currentUser);
}

newOrUpdatedServer = _client.Servers.Create(
resourceGroupName,
serverName,
Expand All @@ -142,8 +164,9 @@ public AnalysisServicesServer CreateOrUpdateServer(
Sku = GetResourceSkuFromName(skuName, ReadonlyReplicaCount + 1),
Tags = tags,
QuerypoolConnectionMode = connectionMode,
IpV4FirewallSettings = setting
});
IpV4FirewallSettings = setting,
GatewayDetails = gatewayDetails
});
}

return newOrUpdatedServer;
Expand Down Expand Up @@ -264,5 +287,5 @@ public void ResumeServer(string resourceGroupName, string serverName)
}

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class AzureAnalysisServicesServer

public PsAzureAnalysisServicesFirewallConfig FirewallConfig { get; set; }

internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(AnalysisServicesServer server)
public ServerGateway GatewayInfo { get; set; }

internal static AzureAnalysisServicesServer FromAnalysisServicesServer(AnalysisServicesServer server)
{
if (server == null)
{
Expand Down Expand Up @@ -77,7 +79,7 @@ internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(Ana
config = new PsAzureAnalysisServicesFirewallConfig(enablePowerBIService, rules);
}

return new AzureAnalysisServicesServerDetail()
return new AzureAnalysisServicesServer()
{
AsAdministrators = server.AsAdministrators == null
? new List<string>()
Expand All @@ -89,29 +91,25 @@ internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(Ana
ProvisioningState = server.ProvisioningState,
Id = server.Id,
ServerFullName = server.ServerFullName,
Sku = server.Sku != null ? ServerSku.FromResourceSku(server.Sku) : new Dictionary<string, string>(),
Sku = server.Sku != null ? ServerSku.FromResourceSku(server.Sku) : new ServerSku(),
Tag = server.Tags != null ? new Dictionary<string, string>(server.Tags) : new Dictionary<string, string>(),
BackupBlobContainerUri = server.BackupBlobContainerUri == null ? String.Empty : server.BackupBlobContainerUri,
DefaultConnectionMode = server.QuerypoolConnectionMode.ToString(),
FirewallConfig = config
FirewallConfig = config,
GatewayInfo = server.GatewayDetails != null ? ServerGateway.FromResourceGateway(server.GatewayDetails) : null
};
}

internal static List<AzureAnalysisServicesServerDetail> FromAnalysisServicesServerCollection(List<AnalysisServicesServer> list)
internal static List<AzureAnalysisServicesServer> FromAnalysisServicesServerCollection(List<AnalysisServicesServer> list)
{
if (list == null)
{
return null;
}

var listAzureAnalysisServicesServer = new List<AzureAnalysisServicesServerDetail>();
var listAzureAnalysisServicesServer = new List<AzureAnalysisServicesServer>();
list.ForEach(server => listAzureAnalysisServicesServer.Add(FromAnalysisServicesServer(server)));
return listAzureAnalysisServicesServer;
}
}

public class AzureAnalysisServicesServerDetail : AzureAnalysisServicesServer
{
public new System.Collections.Generic.IDictionary<string, string> Sku { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Management.Analysis.Models;

namespace Microsoft.Azure.Commands.AnalysisServices.Models
{
public class ServerGateway
{
public string GatewayResourceId { get; set; }

public string GatewayObjectId { get; set; }

public string DmtsClusterUri { get; set; }

internal static ServerGateway FromResourceGateway(GatewayDetails resourceGateway)
{
return new ServerGateway()
{
GatewayResourceId = resourceGateway.GatewayResourceId,
GatewayObjectId = resourceGateway.GatewayObjectId != null ? resourceGateway.GatewayObjectId : null,
DmtsClusterUri = resourceGateway.DmtsClusterUri != null ? resourceGateway.DmtsClusterUri : null
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ public class ServerSku

public int Capacity { get; set; }

internal static Dictionary<string, string> FromResourceSku(ResourceSku resourceSku)
internal static ServerSku FromResourceSku(ResourceSku resourceSku)
{
Dictionary<string, string> sku = new Dictionary<string, string>();
sku["Name"] = resourceSku.Name;
sku["Tier"] = resourceSku.Tier;
sku["Capacity"] = resourceSku.Capacity == null ? "1" : resourceSku.Capacity.Value.ToString();
return sku;
return new ServerSku()
{
Name = resourceSku.Name,
Tier = resourceSku.Tier,
Capacity = resourceSku.Capacity == null ? 1 : resourceSku.Capacity.Value
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
Module Name: AzureRM.AnalysisServices
Module Guid: acace26c-1775-4100-85c0-20c4d71eaa21
Download Help Link: https://docs.microsoft.com/en-us/powershell/module/azurerm.analysisservices
Expand All @@ -14,6 +14,12 @@ This topic displays help topics for the Azure AnalysisServices cmdlets.
### [Get-AzureRmAnalysisServicesServer](Get-AzureRmAnalysisServicesServer.md)
Gets the details of an Analysis Services server.

### [New-AzureRmAnalysisServicesFirewallConfig](New-AzureRmAnalysisServicesFirewallConfig.md)
Creates a new Analysis Services firewall config

### [New-AzureRmAnalysisServicesFirewallRule](New-AzureRmAnalysisServicesFirewallRule.md)
Creates a new Analysis Services firewall rule

### [New-AzureRmAnalysisServicesServer](New-AzureRmAnalysisServicesServer.md)
Creates a new Analysis Services server

Expand All @@ -32,9 +38,3 @@ Suspends an instance of Analysis Services server
### [Test-AzureRmAnalysisServicesServer](Test-AzureRmAnalysisServicesServer.md)
Tests the existence of an instance of Analysis Services server

### [New-AzureRmAnalysisServicesFirewallConfig](New-AzureRmAnalysisServicesFirewallConfig.md)
Creates a new firewall config for Analysis Services server

### [New-AzureRmAnalysisServicesFirewallRule](New-AzureRmAnalysisServicesFirewallRule.md)
Creates a new firewall rule for Analysis Services server

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: Microsoft.Azure.Commands.AnalysisServices.dll-Help.xml
Module Name: AzureRM.AnalysisServices
online version: https://docs.microsoft.com/en-us/powershell/module/azurerm.analysisservices/get-azurermanalysisservicesserver
Expand Down
Loading