Fix numerous Azure property issues (#511)

* Avoid crashing if azure edition is System.

* Add new Azure-specific options to the prototype and return through the service calls

* Send azure properties over database info request

* IsCloud should include Azure SQL DW
- Fixed references to this feature flag
- Updated edition handling to include ManagedInstance and removed AzureV1 check since it's never used and it's been retired.
This commit is contained in:
Kevin Cunnane
2017-10-19 22:08:33 -07:00
committed by Karl Burtram
parent 49f0221dc8
commit d222af7824
16 changed files with 145 additions and 79 deletions

View File

@@ -46,6 +46,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
internal const string FileGroup = "fileGroup";
internal const string InitialSize = "initialSize";
internal const string IsPrimaryFile = "isPrimaryFile";
internal const string AzureEdition = "azureEdition";
internal const string ServiceLevelObjective = "serviceLevelObjective";
internal static AdminServicesProviderOptions BuildAdminServicesProviderOptions()

View File

@@ -47,6 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
public ContainmentType databaseContainmentType;
public PageVerify pageVerify;
public AzureEdition azureEdition;
public string azureEditionDisplayValue;
public string configuredServiceLevelObjective;
public string currentServiceLevelObjective;
public DbSize maxSize;
@@ -151,6 +152,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
this.filestreamDirectoryName = String.Empty;
this.delayedDurability = DelayedDurability.Disabled;
this.azureEdition = AzureEdition.Standard;
this.azureEditionDisplayValue = AzureEdition.Standard.ToString();
this.configuredServiceLevelObjective = String.Empty;
this.currentServiceLevelObjective = String.Empty;
this.maxSize = new DbSize(0, DbSize.SizeUnits.MB);
@@ -264,6 +266,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
if (context.Server.ServerType == DatabaseEngineType.SqlAzureDatabase)
{ //These properties are only available for Azure DBs
this.azureEdition = AzureEdition.Standard;
this.azureEditionDisplayValue = azureEdition.ToString();
this.currentServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(this.azureEdition);
this.configuredServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(this.azureEdition);
this.maxSize = AzureSqlDbHelper.GetDatabaseDefaultSize(this.azureEdition);
@@ -585,6 +588,7 @@ WHERE do.database_id = @DbID
//Only fill in the Azure properties when connected to an Azure server
if (context.Server.ServerType == DatabaseEngineType.SqlAzureDatabase)
{
this.azureEditionDisplayValue = db.AzureEdition;
AzureEdition edition;
if (Enum.TryParse(db.AzureEdition, true, out edition))
{
@@ -592,8 +596,8 @@ WHERE do.database_id = @DbID
}
else
{
//Unknown Azure DB Edition so we can't continue
throw new Exception("CreateDatabaseOptionsSR.Error_UnknownAzureEdition(db.AzureEdition)");
// Unknown Azure DB Edition so we can't set a value, leave as default Standard
// Note that this is likely a
}
//Size is in MB, but if it's greater than a GB we want to display the size in GB
@@ -725,6 +729,7 @@ WHERE do.database_id = @DbID
this.targetRecoveryTime = other.targetRecoveryTime;
this.delayedDurability = other.delayedDurability;
this.azureEdition = other.azureEdition;
this.azureEditionDisplayValue = other.azureEditionDisplayValue;
this.configuredServiceLevelObjective = other.configuredServiceLevelObjective;
this.currentServiceLevelObjective = other.currentServiceLevelObjective;
this.legacyCardinalityEstimation = other.legacyCardinalityEstimation;
@@ -1915,7 +1920,7 @@ WHERE do.database_id = @DbID
if (!FileNameHelper.IsValidFilename(this.FilestreamDirectoryName))
{
string message = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"CreateDatabaseOptionsSR.Error_InvalidDirectoryName {0}",
SR.Error_InvalidDirectoryName,
this.FilestreamDirectoryName);
throw new ArgumentException(message);
}
@@ -1940,7 +1945,7 @@ WHERE do.database_id = @DbID
if (rowCount != 0)
{
string message = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"CreateDatabaseOptionsSR.Error_ExistingDirectoryName {0} {1}",
SR.Error_ExistingDirectoryName,
this.FilestreamDirectoryName, this.Name);
throw new ArgumentException(message);

View File

@@ -3,18 +3,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.ComponentModel;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Diagnostics;
using System.Globalization;
using System.Data.SqlClient;
using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition;
using Microsoft.SqlServer.Management.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition;
namespace Microsoft.SqlTools.ServiceLayer.Admin
{
@@ -102,10 +99,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
{
get
{
return AzureSqlDbHelper.GetAzureEditionDisplayName(this.currentState.azureEdition);
return this.currentState.azureEditionDisplayValue;
}
set
{
// TODO set from here should probably allow for the fact that System is a valid edition for
// actual system DBs. Not handling for now
AzureEdition edition;
if (AzureSqlDbHelper.TryGetAzureEditionFromDisplayName(value, out edition))
{
@@ -115,6 +114,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
}
this.currentState.azureEdition = edition;
this.currentState.azureEditionDisplayValue = value;
this.CurrentServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(edition);
this.MaxSize = AzureSqlDbHelper.GetDatabaseDefaultSize(edition).ToString();
this.NotifyObservers();

View File

@@ -150,9 +150,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsPrimaryFile, file.IsPrimaryFile);
}
AddAzureProperties(databaseInfo, prototype as DatabasePrototypeAzure);
return databaseInfo;
}
private static void AddAzureProperties(DatabaseInfo databaseInfo, DatabasePrototypeAzure prototype)
{
if (prototype == null) { return; }
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.AzureEdition, prototype.AzureEditionDisplay);
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.ServiceLevelObjective, prototype.CurrentServiceLevelObjective);
}
private static string GetBackupDate(DateTime backupDate)
{
if (backupDate == null