public override void ExecuteCmdlet() { if (string.IsNullOrEmpty(Name)) { WriteExceptionError(new PSArgumentNullException("Name", "Name of server not specified")); } if (ShouldProcess(Name, Resources.UpdatingAnalysisServicesServer)) { AnalysisServicesServer currentServer = null; if (!AnalysisServicesClient.TestServer(ResourceGroupName, Name, out currentServer)) { throw new InvalidOperationException(string.Format(Properties.Resources.ServerDoesNotExist, Name)); } var location = currentServer.Location; if (Tag == null && currentServer.Tags != null) { Tag = TagsConversionHelper.CreateTagHashtable(currentServer.Tags); } AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer); if (PassThru.IsPresent) { WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(updatedServer)); } } }
public AnalysisServicesServer CreateOrUpdateServer( string resourceGroupName, string serverName, string location, string skuName = null, Hashtable customTags = null, string administrators = null, AnalysisServicesServer existingServer = null) { if (string.IsNullOrEmpty(resourceGroupName)) { resourceGroupName = GetResourceGroupByServer(serverName); } var tags = (customTags != null) ? TagsConversionHelper.CreateTagDictionary(customTags, true) : null; var adminList = new List <string>(); if (!string.IsNullOrEmpty(administrators)) { adminList.AddRange(administrators.Split(',')); if (adminList.Count == 0) { adminList.Add(_currentUser); } } AnalysisServicesServer newOrUpdatedServer = null; if (existingServer != null) { var updateParameters = new AnalysisServicesServerUpdateParameters() { Sku = existingServer.Sku, Tags = tags, AsAdministrators = new ServerAdministrators(adminList) }; newOrUpdatedServer = _client.Servers.Update(resourceGroupName, serverName, updateParameters); } else { newOrUpdatedServer = _client.Servers.Create( resourceGroupName, serverName, new AnalysisServicesServer() { AsAdministrators = new ServerAdministrators(adminList), Location = location, Sku = GetResourceSkuFromName(skuName), Tags = tags }); } return(newOrUpdatedServer); }
public AnalysisServicesServer CreateOrUpdateServer( string resourceGroupName, string serverName, string location, string skuName = null, Hashtable customTags = null, string administrators = null, AnalysisServicesServer existingServer = null) { if (string.IsNullOrEmpty(resourceGroupName)) { resourceGroupName = GetResourceGroupByServer(serverName); } var tags = (customTags != null) ? TagsConversionHelper.CreateTagDictionary(customTags, true) : null; var adminList = new List<string>(); if (!string.IsNullOrEmpty(administrators)) { adminList.AddRange(administrators.Split(',')); if (adminList.Count == 0) { adminList.Add(_currentUser); } } AnalysisServicesServer newOrUpdatedServer = null; if (existingServer != null) { var updateParameters = new AnalysisServicesServerUpdateParameters() { Sku = existingServer.Sku, Tags = tags, AsAdministrators = new ServerAdministrators(adminList) }; newOrUpdatedServer = _client.Servers.Update(resourceGroupName, serverName, updateParameters); } else { newOrUpdatedServer = _client.Servers.Create( resourceGroupName, serverName, new AnalysisServicesServer() { AsAdministrators = new ServerAdministrators(adminList), Location = location, Sku = GetResourceSkuFromName(skuName), Tags = tags }); } return newOrUpdatedServer; }
internal static AzureAnalysisServicesServer FromAnalysisServicesServer(AnalysisServicesServer server) { if (server == null) { return(null); } PsAzureAnalysisServicesFirewallConfig config = null; if (server.IpV4FirewallSettings != null) { List <PsAzureAnalysisServicesFirewallRule> rules = null; bool enablePowerBIService = false; if (server.IpV4FirewallSettings.FirewallRules != null) { rules = new List <PsAzureAnalysisServicesFirewallRule>(); foreach (var rule in server.IpV4FirewallSettings.FirewallRules) { rules.Add(new PsAzureAnalysisServicesFirewallRule(rule.FirewallRuleName, rule.RangeStart, rule.RangeEnd)); } } if (server.IpV4FirewallSettings.EnablePowerBIService != null) { enablePowerBIService = Convert.ToBoolean(server.IpV4FirewallSettings.EnablePowerBIService); } config = new PsAzureAnalysisServicesFirewallConfig(enablePowerBIService, rules); } ResourceIdentifier resourceIdentifier = new ResourceIdentifier(server.Id); return(new AzureAnalysisServicesServer() { AsAdministrators = server.AsAdministrators == null ? new List <string>() : new List <string>(server.AsAdministrators.Members), Location = server.Location, Name = server.Name, Type = server.Type, State = server.State, ProvisioningState = server.ProvisioningState, Id = server.Id, ServerFullName = server.ServerFullName, 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, ResourceGroupName = resourceIdentifier.ResourceGroupName, DefaultConnectionMode = server.QuerypoolConnectionMode.ToString(), FirewallConfig = config, GatewayInfo = server.GatewayDetails != null?ServerGateway.FromResourceGateway(server.GatewayDetails) : null }); }
public static AnalysisServicesServer GetDefaultAnalysisServicesResource() { AnalysisServicesServer defaultServer = new AnalysisServicesServer { Location = DefaultLocation, Tags = DefaultTags, Sku = DefaultSku, AsAdministrators = new ServerAdministrators(DefaultAdministrators), BackupBlobContainerUri = DefaultBackupBlobContainerUri }; return(defaultServer); }
private static void VerifyServersEqual(AnalysisServicesServer createdResource, AnalysisServicesServer referenceResource) { Assert.Equal(createdResource.Tags, referenceResource.Tags); Assert.Equal(createdResource.Sku, referenceResource.Sku); Assert.Equal(createdResource.Location, referenceResource.Location); Assert.Equal(createdResource.Name, referenceResource.Name); Assert.Equal(createdResource.Id, referenceResource.Id); Assert.Equal(createdResource.Type, referenceResource.Type); Assert.Equal(createdResource.ProvisioningState, referenceResource.ProvisioningState); Assert.Equal(createdResource.State, referenceResource.State); Assert.Equal(createdResource.ServerFullName, referenceResource.ServerFullName); Assert.Equal(createdResource.AsAdministrators, referenceResource.AsAdministrators); }
public static AnalysisServicesServer GetAnalysisServicesResourceWithGateway() { AnalysisServicesServer serverWithGateway = new AnalysisServicesServer { Location = DefaultLocation, Tags = DefaultTags, Sku = DefaultSku, AsAdministrators = new ServerAdministrators(GatewayAdministrators), BackupBlobContainerUri = DefaultBackupBlobContainerUri, GatewayDetails = new GatewayDetails(DefaultGatewayResourceId) }; return(serverWithGateway); }
public bool TestServer(string resourceGroupName, string serverName, out AnalysisServicesServer server) { try { server = GetServer(resourceGroupName, serverName); return(true); } catch (CloudException ex) { if ((ex.Response != null && ex.Response.StatusCode == HttpStatusCode.NotFound) || ex.Message.Contains(string.Format(Properties.Resources.FailedToDiscoverResourceGroup, serverName, _subscriptionId))) { server = null; return(false); } throw; } }
internal static AzureAnalysisServicesServer FromAnalysisServicesServer(AnalysisServicesServer server) { if (server == null) { return(null); } return(new AzureAnalysisServicesServer() { AsAdministrators = server.AsAdministrators == null ? new List <string>() : new List <string>(server.AsAdministrators.Members), Location = server.Location, Name = server.Name, Type = server.Type, ProvisioningState = server.ProvisioningState, Id = server.Id, Sku = ServerSku.FromResourceSku(server.Sku), Tag = new Dictionary <string, string>(server.Tags) }); }
public override void ExecuteCmdlet() { if (string.IsNullOrEmpty(Name)) { WriteExceptionError(new PSArgumentNullException("Name", "Name of server not specified")); } if (ShouldProcess(Name, Resources.UpdatingAnalysisServicesServer)) { AnalysisServicesServer currentServer = null; if (!AnalysisServicesClient.TestServer(ResourceGroupName, Name, out currentServer)) { throw new InvalidOperationException(string.Format(Properties.Resources.ServerDoesNotExist, Name)); } var availableSkus = AnalysisServicesClient.ListSkusForExisting(ResourceGroupName, Name); if (Sku != null && !availableSkus.Value.Any(v => v.Sku.Name == Sku)) { throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Sku.Name)))); } var location = currentServer.Location; if (Tag == null && currentServer.Tags != null) { Tag = TagsConversionHelper.CreateTagHashtable(currentServer.Tags); } if (DisableBackup.IsPresent) { BackupBlobContainerUri = "-"; } AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri); if (PassThru.IsPresent) { WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(updatedServer)); } } }
internal static AzureAnalysisServicesServer FromAnalysisServicesServer(AnalysisServicesServer server) { if (server == null) { return null; } return new AzureAnalysisServicesServer() { AsAdministrators = server.AsAdministrators == null ? new List<string>() : new List<string>(server.AsAdministrators.Members), Location = server.Location, Name = server.Name, Type = server.Type, ProvisioningState = server.ProvisioningState, Id = server.Id, ServerFullName = server.ServerFullName, Sku = server.Sku != null ? ServerSku.FromResourceSku(server.Sku) : new ServerSku(), Tag = server.Tags != null ? new Dictionary<string, string>(server.Tags) : new Dictionary<string, string>() }; }
public void ServerCreateSyncValidateMessage() { var acceptedResponse = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(AnalysisServicesTestUtilities.GetDefaultCreatedResponse("Provisioning", "Provisioning")) }; acceptedResponse.Headers.Add("x-ms-request-id", "1"); acceptedResponse.Headers.Add("Location", @"http://someLocationURL"); var okResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AnalysisServicesTestUtilities.GetDefaultCreatedResponse("Succeeded", "Succeeded")) }; var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { acceptedResponse, okResponse }); AnalysisServicesManagementClient client = AnalysisServicesTestUtilities.GetAnalysisServicesClient(handler); AnalysisServicesServer analysisServicesResource = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource(); var result = client.Servers.Create( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, analysisServicesResource ); // Validate headers - User-Agent for certs, Authorization for tokens Assert.Equal(HttpMethod.Put, handler.Requests[0].Method); Assert.NotNull(handler.Requests[0].Headers.GetValues("User-Agent")); // Validate result Assert.Equal(result.Location, AnalysisServicesTestUtilities.DefaultLocation); Assert.NotEmpty(result.ServerFullName); Assert.Equal("Succeeded", result.ProvisioningState); Assert.Equal("Succeeded", result.State); Assert.Equal(2, result.Tags.Count); Assert.Equal(result.BackupBlobContainerUri, AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri); }
public override void ExecuteCmdlet() { if (string.IsNullOrEmpty(Name)) { WriteExceptionError(new PSArgumentNullException("Name", "Name of server not specified")); } if (ShouldProcess(Name, Resources.ResumingAnalysisServicesServer)) { AnalysisServicesServer server = null; if (!AnalysisServicesClient.TestServer(ResourceGroupName, Name, out server)) { throw new InvalidOperationException(string.Format(Properties.Resources.ServerDoesNotExist, Name)); } AnalysisServicesClient.ResumeServer(ResourceGroupName, Name); if (PassThru.IsPresent) { WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(server)); } } }
internal static AzureAnalysisServicesServerDetail FromAnalysisServicesServer(AnalysisServicesServer server) { if (server == null) { return(null); } return(new AzureAnalysisServicesServerDetail() { AsAdministrators = server.AsAdministrators == null ? new List <string>() : new List <string>(server.AsAdministrators.Members), Location = server.Location, Name = server.Name, Type = server.Type, State = server.State, ProvisioningState = server.ProvisioningState, Id = server.Id, ServerFullName = server.ServerFullName, Sku = server.Sku != null?ServerSku.FromResourceSku(server.Sku) : new Dictionary <string, string>(), Tag = server.Tags != null ? new Dictionary <string, string>(server.Tags) : new Dictionary <string, string>(), BackupBlobContainerUri = server.BackupBlobContainerUri == null ? String.Empty : server.BackupBlobContainerUri }); }
public override void ExecuteCmdlet() { if (string.IsNullOrEmpty(Name)) { WriteExceptionError(new PSArgumentNullException("Name", "Name of server not specified")); } if (ShouldProcess(Name, Resources.UpdatingAnalysisServicesServer)) { AnalysisServicesServer currentServer = null; if (!AnalysisServicesClient.TestServer(ResourceGroupName, Name, out currentServer)) { throw new InvalidOperationException(string.Format(Properties.Resources.ServerDoesNotExist, Name)); } var availableSkus = AnalysisServicesClient.ListSkusForExisting(ResourceGroupName, Name); if (Sku != null && !availableSkus.Value.Any(v => v.Sku.Name == Sku)) { throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Sku.Name)))); } var location = currentServer.Location; if (Tag == null && currentServer.Tags != null) { Tag = TagsConversionHelper.CreateTagHashtable(currentServer.Tags); } if (DisableBackup.IsPresent) { BackupBlobContainerUri = "-"; } IPv4FirewallSettings setting = null; if (FirewallConfig != null) { setting = new IPv4FirewallSettings(new List <IPv4FirewallRule>(), "False"); setting.EnablePowerBIService = FirewallConfig.EnablePowerBIService.ToString(); if (FirewallConfig.FirewallRules != null) { foreach (var rule in FirewallConfig.FirewallRules) { setting.FirewallRules.Add(new IPv4FirewallRule() { FirewallRuleName = rule.FirewallRuleName, RangeStart = rule.RangeStart, RangeEnd = rule.RangeEnd }); } } } if (!MyInvocation.BoundParameters.ContainsKey("ReadonlyReplicaCount")) { ReadonlyReplicaCount = -1; } AnalysisServicesServer updatedServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, location, Sku, Tag, Administrator, currentServer, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting); if (PassThru.IsPresent) { WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(updatedServer)); } } }
/// <summary> /// Provisions the specified Analysis Services server based on the /// configuration specified in the request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the Azure Resource group of which a given Analysis Services /// server is part. This name must be at least 1 character in length, and no /// more than 90. /// </param> /// <param name='serverName'> /// The name of the Analysis Services server. It must be a minimum of 3 /// characters, and a maximum of 63. /// </param> /// <param name='serverParameters'> /// Contains the information used to provision the Analysis Services server. /// </param> public static AnalysisServicesServer Create(this IServersOperations operations, string resourceGroupName, string serverName, AnalysisServicesServer serverParameters) { return(operations.CreateAsync(resourceGroupName, serverName, serverParameters).GetAwaiter().GetResult()); }
public void FirewallTest() { string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location; HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords"); var s1SKU = "S1"; var sampleIPV4FirewallSetting = new IPv4FirewallSettings() { EnablePowerBIService = "True", FirewallRules = new List <IPv4FirewallRule>() { new IPv4FirewallRule() { FirewallRuleName = "rule1", RangeStart = "0.0.0.0", RangeEnd = "255.255.255.255" }, new IPv4FirewallRule() { FirewallRuleName = "rule2", RangeStart = "7.7.7.7", RangeEnd = "8.8.8.8" }, } }; using (var context = MockContext.Start(this.GetType())) { var client = this.GetAnalysisServicesClient(context); AnalysisServicesServer analysisServicesServer = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource(); SkuEnumerationForNewResourceResult skusListForNew = client.Servers.ListSkusForNew(); analysisServicesServer.Sku = skusListForNew.Value.Where((s) => s.Name == s1SKU).First(); analysisServicesServer.IpV4FirewallSettings = sampleIPV4FirewallSetting; AnalysisServicesServer resultCreate = null; try { Console.Out.Write(analysisServicesServer.Sku.Capacity); // Create a test server resultCreate = client.Servers.Create( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, analysisServicesServer); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Assert.Equal("Succeeded", resultCreate.ProvisioningState); Assert.Equal("Succeeded", resultCreate.State); // get the server and ensure that all the values are properly set. var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.NotEmpty(resultGet.ServerFullName); Assert.Equal(analysisServicesServer.Sku.Name, resultGet.Sku.Name); Assert.Equal(2, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("key1")); Assert.Equal(2, resultGet.AsAdministrators.Members.Count); Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type); Assert.Equal(sampleIPV4FirewallSetting.EnablePowerBIService, resultGet.IpV4FirewallSettings.EnablePowerBIService); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.Count(), resultGet.IpV4FirewallSettings.FirewallRules.Count()); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().FirewallRuleName, resultGet.IpV4FirewallSettings.FirewallRules.First().FirewallRuleName); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeStart, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeStart); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeEnd, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeEnd); // Confirm that the server creation did succeed Assert.True(resultGet.ProvisioningState == "Succeeded"); Assert.True(resultGet.State == "Succeeded"); // Update firewall and verify ResourceSku newSku = resultGet.Sku; sampleIPV4FirewallSetting.EnablePowerBIService = "False"; sampleIPV4FirewallSetting.FirewallRules = new List <IPv4FirewallRule>() { new IPv4FirewallRule() { FirewallRuleName = "rule3", RangeStart = "6.6.6.6", RangeEnd = "255.255.255.255" } }; AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters() { IpV4FirewallSettings = sampleIPV4FirewallSetting }; var resultUpdate = client.Servers.Update( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, updateParameters); Assert.Equal("Succeeded", resultUpdate.ProvisioningState); Assert.Equal("Succeeded", resultUpdate.State); // get the server and ensure that all the values are properly set. resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.NotEmpty(resultGet.ServerFullName); Assert.Equal(newSku.Name, resultGet.Sku.Name); Assert.Equal(newSku.Tier, resultGet.Sku.Tier); Assert.Equal(2, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("key1")); Assert.Equal(2, resultGet.AsAdministrators.Members.Count); Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type); Assert.Equal(1, resultGet.Sku.Capacity); Assert.Equal(sampleIPV4FirewallSetting.EnablePowerBIService, resultGet.IpV4FirewallSettings.EnablePowerBIService); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.Count(), resultGet.IpV4FirewallSettings.FirewallRules.Count()); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().FirewallRuleName, resultGet.IpV4FirewallSettings.FirewallRules.First().FirewallRuleName); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeStart, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeStart); Assert.Equal(sampleIPV4FirewallSetting.FirewallRules.First().RangeEnd, resultGet.IpV4FirewallSettings.FirewallRules.First().RangeEnd); // delete the server with its old name, which should also succeed. client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); } }
public void CreateGetUpdateDeleteTest() { string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location; HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords"); using (var context = MockContext.Start(this.GetType())) { var client = this.GetAnalysisServicesClient(context); AnalysisServicesServer analysisServicesServer = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource(); AnalysisServicesServer resultCreate = null; try { // Create a test server resultCreate = client.Servers.Create( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, analysisServicesServer); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Assert.Equal("Succeeded", resultCreate.ProvisioningState); Assert.Equal("Succeeded", resultCreate.State); // get the server and ensure that all the values are properly set. var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.NotEmpty(resultGet.ServerFullName); Assert.Equal(2, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("key1")); Assert.Equal(2, resultGet.AsAdministrators.Members.Count); Assert.Equal(AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri.Split('?')[0], resultGet.BackupBlobContainerUri); Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type); // Confirm that the server creation did succeed Assert.True(resultGet.ProvisioningState == "Succeeded"); Assert.True(resultGet.State == "Succeeded"); // List gateway status of the provisioned server will return error since no gateway is configured on the server. try { var listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); } catch (GatewayListStatusErrorException gatewayException) { Assert.Equal(HttpStatusCode.BadRequest, gatewayException.Response.StatusCode); var errorResponse = gatewayException.Body.Error; var expectedMessage = string.Format("A unified gateway is not associated with server {0}.", AnalysisServicesTestUtilities.DefaultServerName); Assert.Equal("GatewayNotAssociated", errorResponse.Code); Assert.Equal(expectedMessage, errorResponse.Message); } // List gateway status of non-existing server will return error since resource not found. const string notexistingServerName = "notexistingserver"; try { var listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup, notexistingServerName); } catch (GatewayListStatusErrorException gatewayException) { Assert.Equal(HttpStatusCode.NotFound, gatewayException.Response.StatusCode); var errorResponse = gatewayException.Body.Error; var expectedMessage = string.Format("The Resource 'Microsoft.AnalysisServices/servers/{0}' under resource group '{1}' was not found.", notexistingServerName, AnalysisServicesTestUtilities.DefaultResourceGroup); Assert.Equal("ResourceNotFound", errorResponse.Code); Assert.Equal(expectedMessage, errorResponse.Message); } // Update the server and confirm the updates make it in. Dictionary <string, string> updatedTags = new Dictionary <string, string> { { "updated1", "value1" } }; var updatedAdministrators = AnalysisServicesTestUtilities.DefaultAdministrators; updatedAdministrators.Add("*****@*****.**"); AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters() { Sku = resultGet.Sku, Tags = updatedTags, AsAdministrators = new ServerAdministrators(updatedAdministrators), BackupBlobContainerUri = AnalysisServicesTestUtilities.UpdatedBackupBlobContainerUri }; AnalysisServicesServer resultUpdate = null; try { resultUpdate = client.Servers.Update( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, updateParameters); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Assert.Equal("Succeeded", resultUpdate.ProvisioningState); Assert.Equal("Succeeded", resultUpdate.State); // get the server and ensure that all the values are properly set. resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.Equal(1, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("updated1")); Assert.Equal(3, resultGet.AsAdministrators.Members.Count); Assert.Equal(AnalysisServicesTestUtilities.UpdatedBackupBlobContainerUri.Split('?')[0], resultGet.BackupBlobContainerUri); // Create another server and ensure that list account returns both var secondServer = AnalysisServicesTestUtilities.DefaultServerName + '2'; resultCreate = client.Servers.Create( AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer, analysisServicesServer); resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); var listResponse = client.Servers.List(); // Assert that there are at least two servers in the list Assert.True(listResponse.Count() >= 2); // now list by resource group: listResponse = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup); // Assert that there are at least two servers in the list Assert.True(listResponse.Count() >= 2); // Suspend the server and confirm that it is deleted. client.Servers.Suspend(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); // get the server and ensure that all the values are properly set. resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); Assert.Equal("Paused", resultGet.ProvisioningState); Assert.Equal("Paused", resultGet.State); // Suspend the server and confirm that it is deleted. client.Servers.Resume(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); // get the server and ensure that all the values are properly set. resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); Assert.Equal("Succeeded", resultGet.ProvisioningState); Assert.Equal("Succeeded", resultGet.State); // Delete the server and confirm that it is deleted. client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); // delete the server again and make sure it continues to result in a succesful code. client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, secondServer); // delete the server with its old name, which should also succeed. client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // test that the server is gone // now list by resource group: listResponse = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup); // Assert that there are at least two accounts in the list Assert.True(listResponse.Count() >= 0); } }
public AnalysisServicesServer CreateOrUpdateServer( string resourceGroupName, string serverName, string location, string skuName = null, Hashtable customTags = null, string administrators = null, AnalysisServicesServer existingServer = null, string backupBlobContainerUri = null, int ReadonlyReplicaCount = 0, string DefaultConnectionMode = null, IPv4FirewallSettings setting = null) { if (string.IsNullOrEmpty(resourceGroupName)) { resourceGroupName = GetResourceGroupByServer(serverName); } var tags = (customTags != null) ? TagsConversionHelper.CreateTagDictionary(customTags, true) : null; var adminList = new List <string>(); if (!string.IsNullOrEmpty(administrators)) { adminList.AddRange(administrators.Split(',')); if (adminList.Count == 0) { adminList.Add(_currentUser); } } AnalysisServicesServer newOrUpdatedServer = null; if (existingServer != null) { var updateParameters = new AnalysisServicesServerUpdateParameters() { Sku = skuName == null ? existingServer.Sku : GetResourceSkuFromName(skuName), Tags = tags, }; if (adminList.Count > 0) { updateParameters.AsAdministrators = new ServerAdministrators(adminList); } if (backupBlobContainerUri != null) { updateParameters.BackupBlobContainerUri = backupBlobContainerUri; } if (ReadonlyReplicaCount != -1) { updateParameters.Sku.Capacity = ReadonlyReplicaCount + 1; } if (DefaultConnectionMode != null) { updateParameters.QuerypoolConnectionMode = (ConnectionMode)Enum.Parse(typeof(ConnectionMode), DefaultConnectionMode, true); } if (setting != null) { updateParameters.IpV4FirewallSettings = setting; } newOrUpdatedServer = _client.Servers.Update(resourceGroupName, serverName, updateParameters); } else { ConnectionMode?connectionMode = null; if (DefaultConnectionMode != null) { connectionMode = (ConnectionMode)Enum.Parse(typeof(ConnectionMode), DefaultConnectionMode, true); } newOrUpdatedServer = _client.Servers.Create( resourceGroupName, serverName, new AnalysisServicesServer() { AsAdministrators = new ServerAdministrators(adminList), BackupBlobContainerUri = backupBlobContainerUri, Location = location, Sku = GetResourceSkuFromName(skuName, ReadonlyReplicaCount + 1), Tags = tags, QuerypoolConnectionMode = connectionMode, IpV4FirewallSettings = setting }); } return(newOrUpdatedServer); }
private static void VerifyServerCreationSuccess(AnalysisServicesServer createdResource) { AnalysisServicesServer defaultResource = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource(); VerifyServersEqual(createdResource, defaultResource); }
public void ScaleOutTest() { string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location; HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords"); var defaultScaleOutCap = 2; var s1SKU = "S1"; using (var context = MockContext.Start(this.GetType())) { var client = this.GetAnalysisServicesClient(context); AnalysisServicesServer analysisServicesServer = AnalysisServicesTestUtilities.GetDefaultAnalysisServicesResource(); SkuEnumerationForNewResourceResult skusListForNew = client.Servers.ListSkusForNew(); analysisServicesServer.Sku = skusListForNew.Value.Where((s) => s.Name == s1SKU).First(); analysisServicesServer.Sku.Capacity = defaultScaleOutCap; AnalysisServicesServer resultCreate = null; try { // Create a test server resultCreate = client.Servers.Create( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, analysisServicesServer); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Assert.Equal("Succeeded", resultCreate.ProvisioningState); Assert.Equal("Succeeded", resultCreate.State); // get the server and ensure that all the values are properly set. var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.NotEmpty(resultGet.ServerFullName); Assert.Equal(analysisServicesServer.Sku.Name, resultGet.Sku.Name); Assert.Equal(2, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("key1")); Assert.Equal(2, resultGet.AsAdministrators.Members.Count); Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type); Assert.Equal(2, resultGet.Sku.Capacity); // Confirm that the server creation did succeed Assert.True(resultGet.ProvisioningState == "Succeeded"); Assert.True(resultGet.State == "Succeeded"); // Scale in the server and verify ResourceSku newSku = resultGet.Sku; newSku.Capacity = 1; AnalysisServicesServerUpdateParameters updateParameters = new AnalysisServicesServerUpdateParameters() { Sku = newSku }; var resultUpdate = client.Servers.Update( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, updateParameters); Assert.Equal("Succeeded", resultUpdate.ProvisioningState); Assert.Equal("Succeeded", resultUpdate.State); Assert.Equal(1, resultUpdate.Sku.Capacity); // get the server and ensure that all the values are properly set. resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.NotEmpty(resultGet.ServerFullName); Assert.Equal(newSku.Name, resultGet.Sku.Name); Assert.Equal(newSku.Tier, resultGet.Sku.Tier); Assert.Equal(2, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("key1")); Assert.Equal(2, resultGet.AsAdministrators.Members.Count); Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type); Assert.Equal(1, resultGet.Sku.Capacity); // delete the server with its old name, which should also succeed. client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); } }
private static void VerifyServerUpdated(AnalysisServicesServer updatedResource, Dictionary <string, string> newTags, ServerAdministrators serverAdministrators) { }
public void CreateServerWithGatewayTest() { string executingAssemblyPath = typeof(AnalysisServices.Tests.ScenarioTests.ServerOperationsTests).GetTypeInfo().Assembly.Location; HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords"); using (var context = MockContext.Start(this.GetType())) { var client = this.GetAnalysisServicesClient(context); AnalysisServicesServer analysisServicesServer = AnalysisServicesTestUtilities.GetAnalysisServicesResourceWithGateway(); AnalysisServicesServer resultCreate = null; try { // Create a test server resultCreate = client.Servers.Create( AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName, analysisServicesServer); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Assert.Equal("Succeeded", resultCreate.ProvisioningState); Assert.Equal("Succeeded", resultCreate.State); // get the server and ensure that all the values are properly set. var resultGet = client.Servers.GetDetails(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // validate the server creation process Assert.Equal(AnalysisServicesTestUtilities.DefaultLocation, resultGet.Location); Assert.Equal(AnalysisServicesTestUtilities.DefaultServerName, resultGet.Name); Assert.NotEmpty(resultGet.ServerFullName); Assert.Equal(2, resultGet.Tags.Count); Assert.True(resultGet.Tags.ContainsKey("key1")); Assert.Equal(1, resultGet.AsAdministrators.Members.Count); Assert.Equal(AnalysisServicesTestUtilities.DefaultBackupBlobContainerUri.Split('?')[0], resultGet.BackupBlobContainerUri); Assert.Equal("Microsoft.AnalysisServices/servers", resultGet.Type); // Confirm that the server creation did succeed Assert.True(resultGet.ProvisioningState == "Succeeded"); Assert.True(resultGet.State == "Succeeded"); // List gateway status. var listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); Assert.Equal(Status.Live, listGatewayStatus.Status); // Dissociate gateway. client.Servers.DissociateGateway(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // List gateway status again. try { listGatewayStatus = client.Servers.ListGatewayStatus(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); } catch (GatewayListStatusErrorException gatewayException) { Assert.Equal(HttpStatusCode.BadRequest, gatewayException.Response.StatusCode); var errorResponse = gatewayException.Body.Error; var expectedMessage = string.Format("A unified gateway is not associated with server {0}.", AnalysisServicesTestUtilities.DefaultServerName); Assert.Equal("GatewayNotAssociated", errorResponse.Code); Assert.Equal(expectedMessage, errorResponse.Message); } // delete the server with its old name, which should also succeed. client.Servers.Delete(AnalysisServicesTestUtilities.DefaultResourceGroup, AnalysisServicesTestUtilities.DefaultServerName); // test that the server is gone // now list by resource group: var listResponse = client.Servers.ListByResourceGroup(AnalysisServicesTestUtilities.DefaultResourceGroup); // Assert that there are at least two accounts in the list Assert.True(listResponse.Count() >= 0); } }
public bool TestServer(string resourceGroupName, string serverName, out AnalysisServicesServer server) { try { server = GetServer(resourceGroupName, serverName); return true; } catch (CloudException ex) { if ((ex.Response != null && ex.Response.StatusCode == HttpStatusCode.NotFound) || ex.Message.Contains(string.Format(Properties.Resources.FailedToDiscoverResourceGroup, serverName, _subscriptionId))) { server = null; return false; } throw; } }
public override void ExecuteCmdlet() { AnalysisServicesServer server = null; WriteObject(AnalysisServicesClient.TestServer(ResourceGroupName, Name, out server)); }
/// <summary> /// Provisions the specified Analysis Services server based on the /// configuration specified in the request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the Azure Resource group of which a given Analysis Services /// server is part. This name must be at least 1 character in length, and no /// more than 90. /// </param> /// <param name='serverName'> /// The name of the Analysis Services server. It must be a minimum of 3 /// characters, and a maximum of 63. /// </param> /// <param name='serverParameters'> /// Contains the information used to provision the Analysis Services server. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <AnalysisServicesServer> BeginCreateAsync(this IServersOperations operations, string resourceGroupName, string serverName, AnalysisServicesServer serverParameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, serverName, serverParameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }