Add ServerPrototypes for different server versions to fix unsupported property errors (#2261)

This commit is contained in:
Cory Rivera
2023-10-04 10:36:40 -07:00
committed by GitHub
parent 5a8687219d
commit eb1116ce13
7 changed files with 1585 additions and 1490 deletions

View File

@@ -6,6 +6,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Management;
@@ -38,29 +39,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
ConnectionInfo connInfo = this.GetConnectionInfo(requestParams.ConnectionUri);
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
ServerPrototype prototype = new ServerPrototype(dataContainer);
ServerPrototype prototype = CreateServerPrototype(dataContainer.Server, dataContainer.ServerConnection);
if (prototype != null)
{
this.serverViewInfo.ObjectInfo = new ServerInfo()
var serverObjInfo = new ServerInfo()
{
Name = prototype.Name,
HardwareGeneration = prototype.HardwareGeneration,
Language = prototype.Language,
MemoryInMB = prototype.MemoryInMB,
OperatingSystem = prototype.OperatingSystem,
Platform = prototype.Platform,
Processors = prototype.Processors,
IsClustered = prototype.IsClustered,
IsHadrEnabled = prototype.IsHadrEnabled,
IsPolyBaseInstalled = prototype.IsPolyBaseInstalled,
IsXTPSupported = prototype.IsXTPSupported,
Product = prototype.Product,
ReservedStorageSizeMB = prototype.ReservedStorageSizeMB,
RootDirectory = prototype.RootDirectory,
ServerCollation = prototype.ServerCollation,
ServiceTier = prototype.ServiceTier,
StorageSpaceUsageInMB = prototype.StorageSpaceUsageInMB,
Version = prototype.Version,
MinServerMemory = prototype.MinServerMemory,
MaxServerMemory = prototype.MaxServerMemory,
@@ -89,6 +83,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
MaxDegreeParallelism = prototype.MaxDegreeParallelism,
QueryWait = prototype.QueryWait
};
if (prototype is ServerPrototypeMI sMI)
{
serverObjInfo.HardwareGeneration = sMI.HardwareGeneration;
serverObjInfo.ServiceTier = sMI.ServiceTier;
serverObjInfo.ReservedStorageSizeMB = sMI.ReservedStorageSizeMB;
serverObjInfo.StorageSpaceUsageInMB = sMI.StorageSpaceUsageInMB;
}
if (prototype is ServerPrototype140 s140)
{
serverObjInfo.OperatingSystem = s140.OperatingSystem;
serverObjInfo.Platform = s140.Platform;
}
if (prototype is ServerPrototype130 s130)
{
serverObjInfo.IsPolyBaseInstalled = s130.IsPolyBaseInstalled;
}
serverViewInfo.ObjectInfo = serverObjInfo;
serverViewInfo.LanguageOptions = (LanguageUtils.GetDefaultLanguageOptions(dataContainer)).Select(element => element.Language.Alias).ToArray();
serverViewInfo.FullTextUpgradeOptions = Enum.GetNames(typeof(FullTextCatalogUpgradeOption)).ToArray();
}
@@ -119,7 +131,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
try
{
ServerPrototype prototype = new ServerPrototype(dataContainer);
ServerPrototype prototype = CreateServerPrototype(dataContainer.Server, dataContainer.ServerConnection);
prototype.ApplyInfoToPrototype(serverInfo);
return ConfigureServer(dataContainer, ConfigAction.Update, runType, prototype);
}
@@ -149,5 +161,27 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
return sqlScript;
}
}
private ServerPrototype CreateServerPrototype(Server server, ServerConnection connection)
{
ServerPrototype prototype;
if (server.EngineEdition == Edition.SqlManagedInstance)
{
prototype = new ServerPrototypeMI(server, connection);
}
else if (server.VersionMajor >= 14)
{
prototype = new ServerPrototype140(server, connection);
}
else if (server.VersionMajor == 13)
{
prototype = new ServerPrototype130(server, connection);
}
else
{
prototype = new ServerPrototype(server, connection);
}
return prototype;
}
}
}

View File

@@ -14,7 +14,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
/// </summary>
public class ServerInfo : SqlObject
{
public string? HardwareGeneration { get; set; }
public string HardwareGeneration { get; set; }
public string Language { get; set; }
public int MemoryInMB { get; set; }
public string OperatingSystem { get; set; }
@@ -22,13 +22,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
public int Processors { get; set; }
public bool IsClustered { get; set; }
public bool IsHadrEnabled { get; set; }
public bool IsPolyBaseInstalled { get; set; }
public bool? IsPolyBaseInstalled { get; set; }
public bool? IsXTPSupported { get; set; }
public string Product { get; set; }
public int? ReservedStorageSizeMB { get; set; }
public string RootDirectory { get; set; }
public string ServerCollation { get; set; }
public string? ServiceTier { get; set; }
public string ServiceTier { get; set; }
public int? StorageSpaceUsageInMB { get; set; }
public string Version { get; set; }
public NumericServerProperty MaxServerMemory { get; set; }

View File

@@ -0,0 +1,34 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
internal class ServerPrototype130 : ServerPrototype
{
public ServerPrototype130(Server server, ServerConnection connection) : base(server, connection) { }
public bool IsPolyBaseInstalled
{
get
{
return this.currentState.IsPolyBaseInstalled;
}
set
{
this.currentState.IsPolyBaseInstalled = value;
}
}
public override void ApplyInfoToPrototype(ServerInfo serverInfo)
{
base.ApplyInfoToPrototype(serverInfo);
this.IsPolyBaseInstalled = serverInfo.IsPolyBaseInstalled.GetValueOrDefault();
}
}
}

View File

@@ -0,0 +1,47 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
internal class ServerPrototype140 : ServerPrototype130
{
public ServerPrototype140(Server server, ServerConnection connection) : base(server, connection) { }
public string OperatingSystem
{
get
{
return this.currentState.OperatingSystem;
}
set
{
this.currentState.OperatingSystem = value;
}
}
public string Platform
{
get
{
return this.currentState.Platform;
}
set
{
this.currentState.Platform = value;
}
}
public override void ApplyInfoToPrototype(ServerInfo serverInfo)
{
base.ApplyInfoToPrototype(serverInfo);
this.OperatingSystem = serverInfo.OperatingSystem;
this.Platform = serverInfo.Platform;
}
}
}

View File

@@ -0,0 +1,77 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
/// <summary>
/// Prototype for representing a manage instance server.
/// </summary>
internal class ServerPrototypeMI : ServerPrototype140
{
public ServerPrototypeMI(Server server, ServerConnection connection) : base(server, connection) { }
public string HardwareGeneration
{
get
{
return this.currentState.HardwareGeneration;
}
set
{
this.currentState.HardwareGeneration = value;
}
}
public string ServiceTier
{
get
{
return this.currentState.ServiceTier;
}
set
{
this.currentState.ServiceTier = value;
}
}
public int StorageSpaceUsageInMB
{
get
{
return this.currentState.StorageSpaceUsageInMB;
}
set
{
this.currentState.StorageSpaceUsageInMB = value;
}
}
public int ReservedStorageSizeMB
{
get
{
return this.currentState.ReservedStorageSizeMB;
}
set
{
this.currentState.ReservedStorageSizeMB = value;
}
}
public override void ApplyInfoToPrototype(ServerInfo serverInfo)
{
base.ApplyInfoToPrototype(serverInfo);
this.HardwareGeneration = serverInfo.HardwareGeneration;
this.ServiceTier = serverInfo.ServiceTier;
this.ReservedStorageSizeMB = serverInfo.ReservedStorageSizeMB.GetValueOrDefault();
this.StorageSpaceUsageInMB = serverInfo.StorageSpaceUsageInMB.GetValueOrDefault();
}
}
}