From a244c864774703836aea59acea33fe74b7216a8f Mon Sep 17 00:00:00 2001 From: Alex Ma Date: Tue, 3 Oct 2023 11:46:25 -0700 Subject: [PATCH 1/6] [Loc] update to XLFs for 10-2-2023 (#2260) --- src/Microsoft.SqlTools.ServiceLayer/Localization/sr.de.resx | 3 +++ src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx | 3 +++ src/Microsoft.SqlTools.ServiceLayer/Localization/sr.fr.resx | 3 +++ src/Microsoft.SqlTools.ServiceLayer/Localization/sr.it.resx | 3 +++ src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ja.resx | 3 +++ src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ko.resx | 3 +++ .../Localization/sr.pt-br.resx | 3 +++ src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ru.resx | 3 +++ .../Localization/sr.zh-Hans.resx | 3 +++ .../Localization/sr.zh-Hant.resx | 3 +++ .../Localization/transXliff/sr.de.xlf | 6 ++++++ .../Localization/transXliff/sr.es.xlf | 6 ++++++ .../Localization/transXliff/sr.fr.xlf | 6 ++++++ .../Localization/transXliff/sr.it.xlf | 6 ++++++ .../Localization/transXliff/sr.ja.xlf | 6 ++++++ .../Localization/transXliff/sr.ko.xlf | 6 ++++++ .../Localization/transXliff/sr.pt-br.xlf | 6 ++++++ .../Localization/transXliff/sr.ru.xlf | 6 ++++++ .../Localization/transXliff/sr.zh-hans.xlf | 6 ++++++ .../Localization/transXliff/sr.zh-hant.xlf | 6 ++++++ 20 files changed, 90 insertions(+) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.de.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.de.resx index 5cf8ad829b..cb715bed69 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.de.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.de.resx @@ -4483,4 +4483,7 @@ Der Abfrageprozessor schätzt, dass durch das Implementieren des folgenden Index 7 Tage + + Ungültiger Wert für Datenbankschemaanbieter: "{0}"; Erwartet wurde das Format "Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider". + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx index 06c74eb4c6..638037c7e5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.es.resx @@ -4483,4 +4483,7 @@ El procesador de consultas estima que la implementación del siguiente índice p 7 días + + Valor no válido para el proveedor de esquema de base de datos: ''{0}''; se esperaba tener el formato ''Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider''. + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.fr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.fr.resx index 00a4cdd590..d7b01a7619 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.fr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.fr.resx @@ -4483,4 +4483,7 @@ Le processeur de requêtes estime que l'implémentation de l'index suivant peut 7 jours + + Valeur non valide pour le fournisseur de schéma de base de données : « {0} » ; devrait être sous la forme « Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider ». + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.it.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.it.resx index 86307ea899..74fb2f1360 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.it.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.it.resx @@ -4483,4 +4483,7 @@ Query Processor stima che l'implementazione del seguente indice potrebbe miglior 7 giorni + + Valore non valido per il provider dello schema del database: '{0}'; il formato previsto è 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ja.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ja.resx index 60558130b0..f33044545e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ja.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ja.resx @@ -4483,4 +4483,7 @@ 7 日 + + データベース スキーマ プロバイダー '{0}' の値が無効です。'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider' の形式である必要があります。 + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ko.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ko.resx index 9f1cfddd9f..5548e5d514 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ko.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ko.resx @@ -4483,4 +4483,7 @@ 7일 + + 데이터베이스 스키마 공급자의 값 '{0}'이(가) 잘못되었습니다. 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider' 형식이어야 합니다. + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.pt-br.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.pt-br.resx index fcc9ca56de..3975820235 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.pt-br.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.pt-br.resx @@ -4483,4 +4483,7 @@ O Processador de Consultas estima que a implementação do índice a seguir pode 7 dias + + Valor inválido para o Provedor de Esquema de Banco de Dados: espera-se que '{0}'; que esteja no formato 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ru.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ru.resx index 54f365e752..6e64083d0e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ru.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.ru.resx @@ -4483,4 +4483,7 @@ 7 дней + + Недопустимое значение поставщика схемы базы данных: '{0}'; должно быть 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hans.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hans.resx index 74b7e43580..24492c8955 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hans.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hans.resx @@ -4483,4 +4483,7 @@ 7 天 + + 数据库架构提供程序“{0}”的值无效; 应采用“Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider”格式。 + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hant.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hant.resx index 9f900e324b..ed03ab4ba2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hant.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.zh-Hant.resx @@ -4483,4 +4483,7 @@ 7 天 + + 資料庫架構提供者的值無效: '{0}';格式必須是 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'。 + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.de.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.de.xlf index 805af6863a..65cab21eb1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.de.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.de.xlf @@ -7364,6 +7364,12 @@ Der Abfrageprozessor schätzt, dass durch das Implementieren des folgenden Index 7 Tage + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + Ungültiger Wert für Datenbankschemaanbieter: "{0}"; Erwartet wurde das Format "Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider". + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.es.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.es.xlf index 22e618fd5f..875329b809 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.es.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.es.xlf @@ -7364,6 +7364,12 @@ El procesador de consultas estima que la implementación del siguiente índice p 7 días + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + Valor no válido para el proveedor de esquema de base de datos: ''{0}''; se esperaba tener el formato ''Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider''. + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.fr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.fr.xlf index 1f27ed3097..79ef341b85 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.fr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.fr.xlf @@ -7364,6 +7364,12 @@ Le processeur de requêtes estime que l'implémentation de l'index suivant peut 7 jours + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + Valeur non valide pour le fournisseur de schéma de base de données : « {0} » ; devrait être sous la forme « Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider ». + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.it.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.it.xlf index 7636a0c410..ad71b3daa0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.it.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.it.xlf @@ -7364,6 +7364,12 @@ Query Processor stima che l'implementazione del seguente indice potrebbe miglior 7 giorni + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + Valore non valido per il provider dello schema del database: '{0}'; il formato previsto è 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ja.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ja.xlf index 659536ec78..1fb1acc0c5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ja.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ja.xlf @@ -7364,6 +7364,12 @@ The Query Processor estimates that implementing the following index could improv 7 日 + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + データベース スキーマ プロバイダー '{0}' の値が無効です。'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider' の形式である必要があります。 + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ko.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ko.xlf index 0359649a3e..43cb0c2cb8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ko.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ko.xlf @@ -7364,6 +7364,12 @@ The Query Processor estimates that implementing the following index could improv 7일 + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + 데이터베이스 스키마 공급자의 값 '{0}'이(가) 잘못되었습니다. 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider' 형식이어야 합니다. + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.pt-br.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.pt-br.xlf index 15e61171e8..318528a200 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.pt-br.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.pt-br.xlf @@ -7364,6 +7364,12 @@ O Processador de Consultas estima que a implementação do índice a seguir pode 7 dias + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + Valor inválido para o Provedor de Esquema de Banco de Dados: espera-se que '{0}'; que esteja no formato 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ru.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ru.xlf index 3e0ec01423..6f9eea5860 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ru.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.ru.xlf @@ -7364,6 +7364,12 @@ The Query Processor estimates that implementing the following index could improv 7 дней + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + Недопустимое значение поставщика схемы базы данных: '{0}'; должно быть 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hans.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hans.xlf index cb183678ac..971b9015c6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hans.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hans.xlf @@ -7364,6 +7364,12 @@ The Query Processor estimates that implementing the following index could improv 7 天 + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + 数据库架构提供程序“{0}”的值无效; 应采用“Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider”格式。 + . + Parameters: 0 - dsp (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hant.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hant.xlf index 4b087f8c51..c7ff95f5b0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hant.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/transXliff/sr.zh-hant.xlf @@ -7364,6 +7364,12 @@ The Query Processor estimates that implementing the following index could improv 7 天 + + Invalid value for Database Schema Provider: '{0}'; expected to be in the form 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'. + 資料庫架構提供者的值無效: '{0}';格式必須是 'Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider'。 + . + Parameters: 0 - dsp (string) + \ No newline at end of file From 5a8687219d1ed678c988499fb3f1dbc93c1a46ad Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Tue, 3 Oct 2023 20:25:22 -0700 Subject: [PATCH 2/6] Only opening connections when access token is provided (#2262) * Only opening connections when connection string is provided * undoing change * Adding comment for context * Adding comment for context * Formatting file * Fixing comment --- .../ObjectExplorer/StatelessObjectExplorer.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.SqlTools.SqlCore/ObjectExplorer/StatelessObjectExplorer.cs b/src/Microsoft.SqlTools.SqlCore/ObjectExplorer/StatelessObjectExplorer.cs index 0cc9e32454..af3ad70677 100644 --- a/src/Microsoft.SqlTools.SqlCore/ObjectExplorer/StatelessObjectExplorer.cs +++ b/src/Microsoft.SqlTools.SqlCore/ObjectExplorer/StatelessObjectExplorer.cs @@ -38,10 +38,18 @@ public static async Task Expand(string connectionString, SecurityTok { using (SqlConnection conn = new SqlConnection(connectionString)) { - conn.AccessToken = accessToken?.Token; - conn.Open(); + // In case of access token based connections, we need to open the sql connection first before creating the server connection + // Not doing so will result in an exception when trying to call 'Connect' on the server connection + if (accessToken != null) + { + conn.AccessToken = accessToken.Token; + await conn.OpenAsync(); + } ServerConnection connection = new ServerConnection(conn); - connection.AccessToken = accessToken as IRenewableToken; + if (accessToken != null) + { + connection.AccessToken = accessToken as IRenewableToken; + } return await Expand(connection, accessToken, nodePath, serverInfo, options, filters); } } @@ -98,7 +106,7 @@ public static async Task Expand(ServerConnection serverConnection, S } } - + /// /// Expands the given node and returns the child nodes. /// @@ -120,10 +128,11 @@ public static async Task ExpandTreeNode(TreeNode node, ObjectExplore { SmoQueryContext nodeContext = node.GetContextAs() ?? throw new ArgumentException("Node does not have a valid context"); - if(options.GroupBySchemaFlagGetter != null) + if (options.GroupBySchemaFlagGetter != null) { nodeContext.GroupBySchemaFlag = options.GroupBySchemaFlagGetter; } + if (!nodeContext.Server.ConnectionContext.IsOpen && securityToken != null) { var underlyingSqlConnection = nodeContext.Server.ConnectionContext.SqlConnectionObject; From eb1116ce13f67524793c6d3fb47b9a7260ce51c3 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Wed, 4 Oct 2023 10:36:40 -0700 Subject: [PATCH 3/6] Add ServerPrototypes for different server versions to fix unsupported property errors (#2261) --- .../ObjectTypes/Server/ServerData.cs | 1357 +++++++++++++++ .../ObjectTypes/Server/ServerHandler.cs | 54 +- .../ObjectTypes/Server/ServerInfo.cs | 6 +- .../ObjectTypes/Server/ServerPrototype.cs | 1500 +---------------- .../ObjectTypes/Server/ServerPrototype130.cs | 34 + .../ObjectTypes/Server/ServerPrototype140.cs | 47 + .../ObjectTypes/Server/ServerPrototypeMI.cs | 77 + 7 files changed, 1585 insertions(+), 1490 deletions(-) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype130.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs new file mode 100644 index 0000000000..b491ab1323 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs @@ -0,0 +1,1357 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using Microsoft.SqlServer.Management.Smo; +using SMO = Microsoft.SqlServer.Management.Smo; +using Microsoft.SqlTools.ServiceLayer.ServerConfigurations; +using Microsoft.SqlTools.Utility; +using System.Collections.Generic; +using Microsoft.SqlTools.ServiceLayer.ObjectManagement.ObjectTypes.Server; +using Microsoft.SqlTools.ServiceLayer.Utility; + +namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement +{ + /// + /// Represents a collection of server properties for a SQL Server instance. + /// + /// + /// Isolating this data allows for an easy implementation of Reset() and + /// simplifies difference detection when committing changes to the server. + /// + internal class ServerData : ICloneable + { + #region data members + private string serverName = string.Empty; + private string hardwareGeneration = string.Empty; + private string language = string.Empty; + private int memoryInMB = 0; + private string operatingSystem = string.Empty; + private string platform = string.Empty; + private int processors = 0; + private bool isClustered = false; + private bool isHadrEnabled = false; + private bool isPolyBaseInstalled = false; + private bool? isXTPSupported; + private string product = String.Empty; + private string rootDirectory = String.Empty; + private string serverCollation = String.Empty; + private string version = String.Empty; + private string serviceTier = String.Empty; + private int reservedStorageSizeMB = 0; + private int storageSpaceUsageInMB = 0; + private NumericServerProperty minMemory; + private NumericServerProperty maxMemory; + private bool autoProcessorAffinityMaskForAll = false; + private bool autoProcessorAffinityIOMaskForAll = false; + private List numaNodes = new List(); + private ServerLoginMode authenticationMode = ServerLoginMode.Integrated; + private AuditLevel loginAuditing = AuditLevel.None; + private bool checkCompressBackup = false; + private bool checkBackupChecksum = false; + private string dataLocation = String.Empty; + private string logLocation = String.Empty; + private string backupLocation = String.Empty; + private bool allowTriggerToFireOthers = false; + private NumericServerProperty blockedProcThreshold; + private NumericServerProperty cursorThreshold; + private string defaultFullTextLanguage = String.Empty; + private string defaultLanguage = String.Empty; + private string fullTextUpgradeOption = String.Empty; + private NumericServerProperty maxTextReplicationSize; + private bool optimizeAdHocWorkloads = false; + private bool scanStartupProcs = false; + private int twoDigitYearCutoff = 0; + private NumericServerProperty costThresholdParallelism; + private NumericServerProperty locks; + private NumericServerProperty maxDegreeParallelism; + private NumericServerProperty queryWait; + private bool initialized = false; + private Server server; + private ServerConfigService configService; + private AffinityManager affinityManagerIOMask; + private AffinityManager affinityManagerProcessorMask; + + private bool isYukonOrLater = false; + private bool isSqlServer64Bit; + private bool isIOAffinitySupported = false; + #endregion + + #region Properties + + // General properties + + public string ServerName + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.serverName; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("ServerName")); + } + this.serverName = value; + } + } + + public string HardwareGeneration + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.hardwareGeneration; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("HardwareGeneration")); + } + this.hardwareGeneration = value; + } + } + + public string Language + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.language; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("Language")); + } + this.language = value; + } + } + + public int MemoryInMB + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.memoryInMB; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("MemoryInMB")); + } + this.memoryInMB = value; + } + } + + public string OperatingSystem + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.operatingSystem; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("OperatingSystem")); + } + this.operatingSystem = value; + } + } + + public string Platform + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.platform; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("Platform")); + } + this.platform = value; + } + } + + public int Processors + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.processors; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("Processors")); + } + this.processors = value; + } + } + + public bool IsClustered + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.isClustered; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("IsClustered")); + } + this.isClustered = value; + } + } + + public bool IsHadrEnabled + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.isHadrEnabled; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("IsHadrEnabled")); + } + this.isHadrEnabled = value; + } + } + + public bool IsPolyBaseInstalled + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.isPolyBaseInstalled; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("IsPolyBaseInstalled")); + } + this.isPolyBaseInstalled = value; + } + } + + public bool? IsXTPSupported + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.isXTPSupported; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("IsXTPSupported")); + } + this.isXTPSupported = value; + } + } + + + public string Product + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.product; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("Product")); + } + this.product = value; + } + } + + public string RootDirectory + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.rootDirectory; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("RootDirectory")); + } + this.rootDirectory = value; + } + } + + public string ServerCollation + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.serverCollation; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("ServerCollation")); + } + this.serverCollation = value; + } + } + + public string Version + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.version; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("Version")); + } + this.version = value; + } + } + + public string ServiceTier + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.serviceTier; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("ServiceTier")); + } + this.serviceTier = value; + } + } + + public int StorageSpaceUsageInMB + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.storageSpaceUsageInMB; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("StorageSpaceUsageInMB")); + } + this.storageSpaceUsageInMB = value; + } + } + + + public int ReservedStorageSizeMB + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.reservedStorageSizeMB; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("ReservedStorageSizeMB")); + } + this.reservedStorageSizeMB = value; + } + } + + + public NumericServerProperty MinMemory + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.minMemory; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("MinMemory")); + } + + this.minMemory = value; + } + } + + public NumericServerProperty MaxMemory + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.maxMemory; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("MaxMemory")); + } + + this.maxMemory = value; + } + } + + public bool AutoProcessorAffinityMaskForAll + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.autoProcessorAffinityMaskForAll; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("AutoProcessorAffinityMaskForAll")); + } + + this.autoProcessorAffinityMaskForAll = value; + } + } + + public bool AutoProcessorAffinityIOMaskForAll + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.autoProcessorAffinityIOMaskForAll; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("AutoProcessorAffinityIOMaskForAll")); + } + + this.autoProcessorAffinityIOMaskForAll = value; + } + } + + public List NumaNodes + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.numaNodes; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("NumaNodes")); + } + + this.numaNodes = value; + } + } + + public ServerLoginMode AuthenticationMode + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.authenticationMode; + } + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("AuthenticationMode")); + } + + this.authenticationMode = value; + } + } + + public AuditLevel LoginAuditing + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.loginAuditing; + } + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("LoginAuditing")); + } + + this.loginAuditing = value; + } + } + + public AffinityManager AffinityManagerIOMask + { + get + { + return this.affinityManagerIOMask; + } + + set + { + this.affinityManagerIOMask = value; + } + } + + public AffinityManager AffinityManagerProcessorMask + { + get + { + return this.affinityManagerProcessorMask; + } + + set + { + this.affinityManagerProcessorMask = value; + } + } + + public bool CheckBackupChecksum + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.checkBackupChecksum; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("CheckBackupChecksum")); + } + this.checkBackupChecksum = value; + } + } + + public bool CheckCompressBackup + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.checkCompressBackup; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("CheckCompressBackup")); + } + this.checkCompressBackup = value; + } + } + + public string DataLocation + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.dataLocation; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("DataLocation")); + } + this.dataLocation = value; + } + } + + public string LogLocation + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.logLocation; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("LogLocation")); + } + this.logLocation = value; + } + } + + public string BackupLocation + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.backupLocation; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("BackupLocation")); + } + this.backupLocation = value; + } + } + + public bool AllowTriggerToFireOthers + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.allowTriggerToFireOthers; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("AllowTriggerToFireOthers")); + } + this.allowTriggerToFireOthers = value; + } + } + + public NumericServerProperty BlockedProcThreshold + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.blockedProcThreshold; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("BlockedProcThreshold")); + } + + this.blockedProcThreshold = value; + } + } + + public NumericServerProperty CursorThreshold + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.cursorThreshold; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("CursorThreshold")); + } + + this.cursorThreshold = value; + } + } + + public string DefaultFullTextLanguage + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.defaultFullTextLanguage; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("DefaultFullTextLanguage")); + } + this.defaultFullTextLanguage = value; + } + } + + public string DefaultLanguage + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.defaultLanguage; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("DefaultLanguage")); + } + this.defaultLanguage = value; + } + } + + public string FullTextUpgradeOption + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.fullTextUpgradeOption; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("FullTextUpgradeOption")); + } + this.fullTextUpgradeOption = value; + } + } + + public NumericServerProperty MaxTextReplicationSize + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.maxTextReplicationSize; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("MaxTextReplicationSize")); + } + + this.maxTextReplicationSize = value; + } + } + + public bool OptimizeAdHocWorkloads + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.optimizeAdHocWorkloads; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("OptimizeAdHocWorkloads")); + } + this.optimizeAdHocWorkloads = value; + } + } + + public bool ScanStartupProcs + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.scanStartupProcs; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("ScanStartupProcs")); + } + this.scanStartupProcs = value; + } + } + + public int TwoDigitYearCutoff + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.twoDigitYearCutoff; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("TwoDigitYearCutoff")); + } + this.twoDigitYearCutoff = value; + } + } + + public NumericServerProperty CostThresholdParallelism + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.costThresholdParallelism; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("CostThresholdParallelism")); + } + this.costThresholdParallelism = value; + } + } + + public NumericServerProperty Locks + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.locks; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("Locks")); + } + this.locks = value; + } + } + + public NumericServerProperty MaxDegreeParallelism + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.maxDegreeParallelism; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("MaxDegreeParallelism")); + } + this.maxDegreeParallelism = value; + } + } + + public NumericServerProperty QueryWait + { + get + { + if (!this.initialized) + { + LoadData(); + } + + return this.queryWait; + } + + set + { + if (this.initialized) + { + Logger.Error(SR.PropertyNotInitialized("QueryWait")); + } + this.queryWait = value; + } + } + + #endregion + + /// + /// private default constructor - used by Clone() + /// + private ServerData() + { + } + + + /// + /// constructor + /// + /// The context in which we are modifying an existing server + /// The server we are modifying + public ServerData(Server server, ServerConfigService service) + { + this.server = server; + this.configService = service; + this.isYukonOrLater = (this.server.Information.Version.Major >= 9); + this.isSqlServer64Bit = (this.server.Edition.Contains("(64 - bit)")); + this.affinityManagerIOMask = new AffinityManager(); + this.affinityManagerProcessorMask = new AffinityManager(); + this.minMemory = new NumericServerProperty(); + this.maxMemory = new NumericServerProperty(); + this.blockedProcThreshold = new NumericServerProperty(); + this.cursorThreshold = new NumericServerProperty(); + this.maxTextReplicationSize = new NumericServerProperty(); + this.costThresholdParallelism = new NumericServerProperty(); + this.locks = new NumericServerProperty(); + this.maxDegreeParallelism = new NumericServerProperty(); + this.queryWait = new NumericServerProperty(); + this.NumaNodes = new List(); + LoadData(); + } + + /// + /// Create a clone of this ServerRolePrototypeData object + /// + /// The clone ServerRolePrototypeData object + public object Clone() + { + ServerData result = new ServerData(); + result.serverName = this.serverName; + result.initialized = this.initialized; + result.hardwareGeneration = this.hardwareGeneration; + result.language = this.language; + result.memoryInMB = this.memoryInMB; + result.operatingSystem = this.operatingSystem; + result.platform = this.platform; + result.processors = this.processors; + result.isClustered = this.isClustered; + result.isHadrEnabled = this.isHadrEnabled; + result.isPolyBaseInstalled = this.isPolyBaseInstalled; + result.isXTPSupported = this.isXTPSupported; + result.product = this.product; + result.reservedStorageSizeMB = this.reservedStorageSizeMB; + result.rootDirectory = this.rootDirectory; + result.serverCollation = this.serverCollation; + result.serviceTier = this.serviceTier; + result.storageSpaceUsageInMB = this.storageSpaceUsageInMB; + result.version = this.version; + result.maxMemory = this.maxMemory; + result.minMemory = this.minMemory; + result.autoProcessorAffinityMaskForAll = this.autoProcessorAffinityMaskForAll; + result.autoProcessorAffinityIOMaskForAll = this.autoProcessorAffinityIOMaskForAll; + result.numaNodes = this.numaNodes; + result.authenticationMode = this.authenticationMode; + result.loginAuditing = this.loginAuditing; + result.checkBackupChecksum = this.checkBackupChecksum; + result.checkCompressBackup = this.checkCompressBackup; + result.dataLocation = this.dataLocation; + result.logLocation = this.logLocation; + result.backupLocation = this.backupLocation; + result.allowTriggerToFireOthers = this.allowTriggerToFireOthers; + result.blockedProcThreshold = this.blockedProcThreshold; + result.cursorThreshold = this.cursorThreshold; + result.defaultFullTextLanguage = this.defaultFullTextLanguage; + result.defaultLanguage = this.defaultLanguage; + result.fullTextUpgradeOption = this.fullTextUpgradeOption; + result.maxTextReplicationSize = this.maxTextReplicationSize; + result.optimizeAdHocWorkloads = this.optimizeAdHocWorkloads; + result.scanStartupProcs = this.scanStartupProcs; + result.twoDigitYearCutoff = this.twoDigitYearCutoff; + result.costThresholdParallelism = this.costThresholdParallelism; + result.locks = this.locks; + result.maxDegreeParallelism = this.maxDegreeParallelism; + result.queryWait = this.queryWait; + result.server = this.server; + return result; + } + + private void LoadData() + { + this.initialized = true; + LoadGeneralProperties(); + LoadMemoryProperties(); + LoadProcessorsProperties(); + LoadSecurityProperties(); + LoadDBSettingsProperties(); + LoadAdvancedProperties(); + } + + private void LoadGeneralProperties() + { + this.serverName = server.Name; + this.language = server.Language; + this.memoryInMB = server.PhysicalMemory; + this.processors = server.Processors; + this.isClustered = server.IsClustered; + this.isHadrEnabled = server.IsHadrEnabled; + this.isPolyBaseInstalled = server.IsPolyBaseInstalled; + + this.product = server.Product; + this.rootDirectory = server.RootDirectory; + this.serverCollation = server.Collation; + this.version = server.VersionString; + if (server.EngineEdition == Edition.SqlManagedInstance) + { + this.hardwareGeneration = server.HardwareGeneration; + this.serviceTier = server.ServiceTier; + this.reservedStorageSizeMB = server.ReservedStorageSizeMB; + this.storageSpaceUsageInMB = server.UsedStorageSizeMB; + } + else + { + this.isXTPSupported = server.IsXTPSupported; + } + if (server.VersionMajor >= 14) + { + this.operatingSystem = server.HostDistribution; + this.platform = server.HostPlatform; + } + if (server.VersionMajor >= 13) + { + this.isPolyBaseInstalled = server.IsPolyBaseInstalled; + } + } + + private void LoadMemoryProperties() + { + this.maxMemory.Value = server.Configuration.MaxServerMemory.ConfigValue; + this.maxMemory.MaximumValue = server.Configuration.MaxServerMemory.Maximum; + this.maxMemory.MinimumValue = server.Configuration.MaxServerMemory.Minimum; + + this.minMemory.Value = server.Configuration.MinServerMemory.ConfigValue; + this.minMemory.MaximumValue = server.Configuration.MinServerMemory.Maximum; + this.minMemory.MinimumValue = server.Configuration.MinServerMemory.Minimum; + } + + private void LoadProcessorsProperties() + { + try + { + this.affinityManagerIOMask.InitializeAffinity(this.server.Configuration.AffinityIOMask, this.server.Configuration.Affinity64IOMask); + this.isIOAffinitySupported = true; + } + catch + { + this.isIOAffinitySupported = false; + } + this.affinityManagerProcessorMask.InitializeAffinity(this.server.Configuration.AffinityMask, this.server.Configuration.Affinity64Mask); + + this.numaNodes = GetNumaNodes(); + GetAutoProcessorsAffinity(); + } + + private void LoadSecurityProperties() + { + this.authenticationMode = server.LoginMode; + this.loginAuditing = server.AuditLevel; + } + + private void LoadDBSettingsProperties() + { + this.checkBackupChecksum = server.Configuration.DefaultBackupChecksum.ConfigValue == 1; + this.checkCompressBackup = server.Configuration.DefaultBackupCompression.ConfigValue == 1; + this.dataLocation = server.Settings.DefaultFile; + this.logLocation = server.Settings.DefaultLog; + this.backupLocation = server.Settings.BackupDirectory; + } + + private void LoadAdvancedProperties() + { + this.allowTriggerToFireOthers = server.Configuration.NestedTriggers.ConfigValue == 1; + this.blockedProcThreshold.Value = server.Configuration.BlockedProcessThreshold.ConfigValue; + this.blockedProcThreshold.MinimumValue = server.Configuration.BlockedProcessThreshold.Minimum; + this.blockedProcThreshold.MaximumValue = server.Configuration.BlockedProcessThreshold.Maximum; + this.cursorThreshold.Value = server.Configuration.CursorThreshold.ConfigValue; + this.cursorThreshold.MinimumValue = server.Configuration.CursorThreshold.Minimum; + this.cursorThreshold.MaximumValue = server.Configuration.CursorThreshold.Maximum; + this.defaultFullTextLanguage = LanguageUtils.GetLanguageChoiceAlias(server, server.Configuration.DefaultFullTextLanguage.ConfigValue).alias; + var defaultLanguageLcid = LanguageUtils.GetLcidFromLangId(server, server.Configuration.DefaultLanguage.ConfigValue); + this.defaultLanguage = (LanguageUtils.GetLanguageChoiceAlias(server, defaultLanguageLcid)).ToString(); + this.maxTextReplicationSize.Value = server.Configuration.ReplicationMaxTextSize.ConfigValue; + this.maxTextReplicationSize.MinimumValue = server.Configuration.ReplicationMaxTextSize.Minimum; + this.maxTextReplicationSize.MaximumValue = server.Configuration.ReplicationMaxTextSize.Maximum; + this.optimizeAdHocWorkloads = server.Configuration.OptimizeAdhocWorkloads.ConfigValue == 1; + this.scanStartupProcs = server.Configuration.ScanForStartupProcedures.ConfigValue == 1; + this.twoDigitYearCutoff = server.Configuration.TwoDigitYearCutoff.ConfigValue; + this.costThresholdParallelism.Value = server.Configuration.CostThresholdForParallelism.ConfigValue; + this.costThresholdParallelism.MinimumValue = server.Configuration.CostThresholdForParallelism.Minimum; + this.costThresholdParallelism.MaximumValue = server.Configuration.CostThresholdForParallelism.Maximum; + this.locks.Value = server.Configuration.Locks.ConfigValue; + this.locks.MinimumValue = server.Configuration.Locks.Minimum; + this.locks.MaximumValue = server.Configuration.Locks.Maximum; + this.maxDegreeParallelism.Value = server.Configuration.MaxDegreeOfParallelism.ConfigValue; + this.maxDegreeParallelism.MinimumValue = server.Configuration.MaxDegreeOfParallelism.Minimum; + this.maxDegreeParallelism.MaximumValue = server.Configuration.MaxDegreeOfParallelism.Maximum; + this.queryWait.Value = server.Configuration.QueryWait.ConfigValue; + this.queryWait.MinimumValue = server.Configuration.QueryWait.Minimum; + this.queryWait.MaximumValue = server.Configuration.QueryWait.Maximum; + try + { + this.fullTextUpgradeOption = server.FullTextService.CatalogUpgradeOption.ToString(); + } + catch + { + this.fullTextUpgradeOption = String.Empty; + } + } + + /// + /// Get affinity masks for first 32 and next 32 processors (total 64 processors) if the + /// processor masks have been modified after being read from the server. + /// + /// returns the affinity for first 32 processors. null if not changed + /// return the affinity for CPUs 33-64. null if not changed. + private List GetNumaNodes() + { + List results = new List(); + foreach (SMO.NumaNode node in this.server.AffinityInfo.NumaNodes) + { + var processors = new List(); + foreach (SMO.Cpu cpu in node.Cpus) + { + if (cpu.GroupID == 0) + { + var affinityIO = this.AffinityManagerIOMask.GetAffinity(cpu.ID, true); + if (!cpu.AffinityMask && this.isIOAffinitySupported && affinityIO) // if it's false then check if io affinity is checked + { + this.AffinityManagerIOMask.initialIOAffinityArray[cpu.ID] = true; + } + + // get affinityIO info if group id is 0 + processors.Add(new ProcessorAffinity() { ProcessorId = cpu.ID.ToString(), Affinity = cpu.AffinityMask, IOAffinity = affinityIO }); + } + } + var result = new NumaNode() { NumaNodeId = node.ID.ToString(), Processors = processors }; + results.Add(result); + } + return results; + } + + private void GetAutoProcessorsAffinity() + { + if (this.server.AffinityInfo.AffinityType == Microsoft.SqlServer.Management.Smo.AffinityType.Auto) + { + this.autoProcessorAffinityMaskForAll = this.autoProcessorAffinityIOMaskForAll = true; + } + else + { + this.autoProcessorAffinityMaskForAll = this.autoProcessorAffinityIOMaskForAll = false; + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs index 551d15cc67..b3b1522ca8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs @@ -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 @@ public override Task InitializeObjectView(InitializeViewRe 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 @@ public override Task InitializeObjectView(InitializeViewRe 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 @@ private string UpdateServerProperties(InitializeViewRequestParams viewParams, Se { 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 @@ private string ConfigureServer(CDataContainer dataContainer, ConfigAction config 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; + } } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerInfo.cs index 130fe3a525..98eb6b4704 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerInfo.cs @@ -14,7 +14,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement /// 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 @@ public class ServerInfo : SqlObject 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; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs index 7e773fa155..4d62b3e6e1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs @@ -6,10 +6,8 @@ using System; using Microsoft.SqlServer.Management.Smo; using SMO = Microsoft.SqlServer.Management.Smo; -using Microsoft.SqlTools.ServiceLayer.Management; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlTools.ServiceLayer.ServerConfigurations; -using Microsoft.SqlTools.Utility; using System.Collections.Generic; using Microsoft.SqlTools.ServiceLayer.ObjectManagement.ObjectTypes.Server; using System.Linq; @@ -22,29 +20,12 @@ internal class ServerPrototype { #region Members - /// - /// data container member that contains data specific information like - /// connection infor, SMO server object or an AMO server object as well - /// as a hash table where one can manipulate custom data - /// - private CDataContainer dataContainer; + private Server server; private ServerConnection sqlConnection; private ServerConfigService configService; - private ServerPrototypeData currentState; - private ServerPrototypeData originalState; - #endregion - - #region Trace support - private const string componentName = "Server"; - - public string ComponentName - { - get - { - return componentName; - } - } + protected ServerData currentState; + private ServerData originalState; #endregion #region Properties @@ -72,18 +53,6 @@ public string Product } } - public string OperatingSystem - { - get - { - return this.currentState.OperatingSystem; - } - set - { - this.currentState.OperatingSystem = value; - } - } - public string Version { get @@ -108,18 +77,6 @@ public string Language } } - public string Platform - { - get - { - return this.currentState.Platform; - } - set - { - this.currentState.Platform = value; - } - } - public int MemoryInMB { get @@ -192,7 +149,7 @@ public bool IsHadrEnabled } } - public bool IsXTPSupported + public bool? IsXTPSupported { get { @@ -204,69 +161,6 @@ public bool IsXTPSupported } } - public bool IsPolyBaseInstalled - { - get - { - return this.currentState.IsPolyBaseInstalled; - } - set - { - this.currentState.IsPolyBaseInstalled = value; - } - } - - - 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 NumericServerProperty MaxServerMemory { get @@ -605,13 +499,13 @@ public NumericServerProperty QueryWait /// /// ServerPrototype for editing an existing server /// - public ServerPrototype(CDataContainer context) + public ServerPrototype(Server server, ServerConnection connection) { - this.dataContainer = context; - this.sqlConnection = context.ServerConnection; + this.server = server; + this.sqlConnection = connection; this.configService = new ServerConfigService(); - this.currentState = new ServerPrototypeData(context, context.Server, this.configService); - this.originalState = (ServerPrototypeData)this.currentState.Clone(); + this.currentState = new ServerData(server, this.configService); + this.originalState = (ServerData)this.currentState.Clone(); } #endregion @@ -624,38 +518,38 @@ public ServerPrototype(CDataContainer context) /// public void SendDataToServer() { - if (this.dataContainer.Server != null) + if (this.server != null) { - Server server = this.dataContainer.Server; + Server server = this.server; - if (UpdateMemoryValues(this.dataContainer.Server)) + if (UpdateMemoryValues(this.server)) { server.Configuration.Alter(true); } - UpdateProcessorsValues(this.dataContainer.Server); + UpdateProcessorsValues(this.server); - if (UpdateSecurityValues(this.dataContainer.Server)) + if (UpdateSecurityValues(this.server)) { server.Alter(); } - if (UpdateDBSettingsValues(this.dataContainer.Server)) + if (UpdateDBSettingsValues(this.server)) { server.Settings.Alter(); } - if (UpdateBackupConfig(this.dataContainer.Server)) + if (UpdateBackupConfig(this.server)) { server.Configuration.Alter(); } - if (UpdateAdvancedValues(this.dataContainer.Server)) + if (UpdateAdvancedValues(this.server)) { server.Configuration.Alter(); } - if (UpdateFullTextService(this.dataContainer.Server)) + if (UpdateFullTextService(this.server)) { server.FullTextService.Alter(); } @@ -914,8 +808,9 @@ private bool CheckIOAffinityBeforeCPU(SMO.Server smoServer) } return false; } + /// - /// This will send data for KJ specific things + /// This will send data for Kilimanjaro specific things /// Also Checks if Alter needs to be generated /// private void SendDataForKJ(SMO.Server smoServer) @@ -1024,26 +919,20 @@ private bool CheckIOAffinityTsqlGenerated(SMO.Server smoServer) } #endregion - public void ApplyInfoToPrototype(ServerInfo serverInfo) + public virtual void ApplyInfoToPrototype(ServerInfo serverInfo) { - this.Name = serverInfo.Name; + this.Name = serverInfo.Name ?? string.Empty; this.Language = serverInfo.Language; this.MemoryInMB = serverInfo.MemoryInMB; - this.OperatingSystem = serverInfo.OperatingSystem; - this.Platform = serverInfo.Platform; this.Version = serverInfo.Version; this.Processors = serverInfo.Processors; this.Version = serverInfo.Version; this.IsClustered = serverInfo.IsClustered; this.IsHadrEnabled = serverInfo.IsHadrEnabled; - this.IsPolyBaseInstalled = serverInfo.IsPolyBaseInstalled; - this.IsXTPSupported = (bool)(serverInfo.IsXTPSupported); + this.IsXTPSupported = serverInfo.IsXTPSupported.GetValueOrDefault(); this.Product = serverInfo.Product; - this.ReservedStorageSizeMB = (int)(serverInfo.ReservedStorageSizeMB); this.RootDirectory = serverInfo.RootDirectory; this.ServerCollation = serverInfo.ServerCollation; - this.ServiceTier = serverInfo.ServiceTier; - this.StorageSpaceUsageInMB = (int)(serverInfo.StorageSpaceUsageInMB); this.MaxServerMemory = serverInfo.MaxServerMemory; this.MinServerMemory = serverInfo.MinServerMemory; this.AutoProcessorAffinityMaskForAll = serverInfo.AutoProcessorAffinityMaskForAll; @@ -1071,1348 +960,5 @@ public void ApplyInfoToPrototype(ServerInfo serverInfo) this.MaxDegreeParallelism = serverInfo.MaxDegreeParallelism; this.QueryWait = serverInfo.QueryWait; } - - /// - /// Private class encapsulating the data that is changed by the UI. - /// - /// - /// Isolating this data allows for an easy implementation of Reset() and - /// simplifies difference detection when committing changes to the server. - /// - private class ServerPrototypeData : ICloneable - { - #region data members - private string serverName = string.Empty; - private string hardwareGeneration = String.Empty; - private string language = String.Empty; - private int memoryInMB = 0; - private string operatingSystem = String.Empty; - private string platform = String.Empty; - private int processors = 0; - private bool isClustered = false; - private bool isHadrEnabled = false; - private bool isPolyBaseInstalled = false; - private bool isXTPSupported = false; - private string product = String.Empty; - private string rootDirectory = String.Empty; - private string serverCollation = String.Empty; - private string version = String.Empty; - private string serviceTier = String.Empty; - private int reservedStorageSizeMB = 0; - private int storageSpaceUsageInMB = 0; - private NumericServerProperty minMemory; - private NumericServerProperty maxMemory; - private bool autoProcessorAffinityMaskForAll = false; - private bool autoProcessorAffinityIOMaskForAll = false; - private List numaNodes = new List(); - private ServerLoginMode authenticationMode = ServerLoginMode.Integrated; - private AuditLevel loginAuditing = AuditLevel.None; - private bool checkCompressBackup = false; - private bool checkBackupChecksum = false; - private string dataLocation = String.Empty; - private string logLocation = String.Empty; - private string backupLocation = String.Empty; - private bool allowTriggerToFireOthers = false; - private NumericServerProperty blockedProcThreshold; - private NumericServerProperty cursorThreshold; - private string defaultFullTextLanguage = String.Empty; - private string defaultLanguage = String.Empty; - private string fullTextUpgradeOption = String.Empty; - private NumericServerProperty maxTextReplicationSize; - private bool optimizeAdHocWorkloads = false; - private bool scanStartupProcs = false; - private int twoDigitYearCutoff = 0; - private NumericServerProperty costThresholdParallelism; - private NumericServerProperty locks; - private NumericServerProperty maxDegreeParallelism; - private NumericServerProperty queryWait; - private bool initialized = false; - private Server server; - private CDataContainer context; - private ServerConfigService configService; - private AffinityManager affinityManagerIOMask; - private AffinityManager affinityManagerProcessorMask; - - private bool isYukonOrLater = false; - private bool isSqlServer64Bit; - private bool isIOAffinitySupported = false; - #endregion - - #region Properties - - // General properties - - - public string ServerName - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.serverName; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("ServerName")); - } - this.serverName = value; - } - } - - public string HardwareGeneration - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.hardwareGeneration; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("HardwareGeneration")); - } - this.hardwareGeneration = value; - } - } - - public string Language - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.language; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("Language")); - } - this.language = value; - } - } - - public int MemoryInMB - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.memoryInMB; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("MemoryInMB")); - } - this.memoryInMB = value; - } - } - - public string OperatingSystem - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.operatingSystem; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("OperatingSystem")); - } - this.operatingSystem = value; - } - } - - public string Platform - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.platform; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("Platform")); - } - this.platform = value; - } - } - - public int Processors - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.processors; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("Processors")); - } - this.processors = value; - } - } - - public bool IsClustered - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.isClustered; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("IsClustered")); - } - this.isClustered = value; - } - } - - public bool IsHadrEnabled - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.isHadrEnabled; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("IsHadrEnabled")); - } - this.isHadrEnabled = value; - } - } - - public bool IsPolyBaseInstalled - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.isPolyBaseInstalled; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("IsPolyBaseInstalled")); - } - this.isPolyBaseInstalled = value; - } - } - - public bool IsXTPSupported - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.isXTPSupported; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("IsXTPSupported")); - } - this.isXTPSupported = value; - } - } - - - public string Product - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.product; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("Product")); - } - this.product = value; - } - } - - public string RootDirectory - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.rootDirectory; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("RootDirectory")); - } - this.rootDirectory = value; - } - } - - public string ServerCollation - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.serverCollation; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("ServerCollation")); - } - this.serverCollation = value; - } - } - - public string Version - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.version; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("Version")); - } - this.version = value; - } - } - - public string ServiceTier - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.serviceTier; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("ServiceTier")); - } - this.serviceTier = value; - } - } - - public int StorageSpaceUsageInMB - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.storageSpaceUsageInMB; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("StorageSpaceUsageInMB")); - } - this.storageSpaceUsageInMB = value; - } - } - - - public int ReservedStorageSizeMB - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.reservedStorageSizeMB; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("ReservedStorageSizeMB")); - } - this.reservedStorageSizeMB = value; - } - } - - - public NumericServerProperty MinMemory - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.minMemory; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("MinMemory")); - } - - this.minMemory = value; - } - } - - public NumericServerProperty MaxMemory - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.maxMemory; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("MaxMemory")); - } - - this.maxMemory = value; - } - } - - public bool AutoProcessorAffinityMaskForAll - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.autoProcessorAffinityMaskForAll; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("AutoProcessorAffinityMaskForAll")); - } - - this.autoProcessorAffinityMaskForAll = value; - } - } - - public bool AutoProcessorAffinityIOMaskForAll - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.autoProcessorAffinityIOMaskForAll; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("AutoProcessorAffinityIOMaskForAll")); - } - - this.autoProcessorAffinityIOMaskForAll = value; - } - } - - public List NumaNodes - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.numaNodes; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("NumaNodes")); - } - - this.numaNodes = value; - } - } - - public ServerLoginMode AuthenticationMode - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.authenticationMode; - } - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("AuthenticationMode")); - } - - this.authenticationMode = value; - } - } - - public AuditLevel LoginAuditing - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.loginAuditing; - } - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("LoginAuditing")); - } - - this.loginAuditing = value; - } - } - - public Microsoft.SqlServer.Management.Smo.Server Server - { - get - { - return this.server; - } - } - - public bool IsYukonOrLater - { - get - { - return this.isYukonOrLater; - } - } - - public AffinityManager AffinityManagerIOMask - { - get - { - return this.affinityManagerIOMask; - } - - set - { - this.affinityManagerIOMask = value; - } - } - - public AffinityManager AffinityManagerProcessorMask - { - get - { - return this.affinityManagerProcessorMask; - } - - set - { - this.affinityManagerProcessorMask = value; - } - } - public bool CheckBackupChecksum - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.checkBackupChecksum; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("CheckBackupChecksum")); - } - this.checkBackupChecksum = value; - } - } - public bool CheckCompressBackup - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.checkCompressBackup; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("CheckCompressBackup")); - } - this.checkCompressBackup = value; - } - } - - public string DataLocation - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.dataLocation; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("DataLocation")); - } - this.dataLocation = value; - } - } - - public string LogLocation - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.logLocation; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("LogLocation")); - } - this.logLocation = value; - } - } - - public string BackupLocation - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.backupLocation; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("BackupLocation")); - } - this.backupLocation = value; - } - } - - public bool AllowTriggerToFireOthers - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.allowTriggerToFireOthers; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("AllowTriggerToFireOthers")); - } - this.allowTriggerToFireOthers = value; - } - } - - public NumericServerProperty BlockedProcThreshold - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.blockedProcThreshold; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("BlockedProcThreshold")); - } - - this.blockedProcThreshold = value; - } - } - - public NumericServerProperty CursorThreshold - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.cursorThreshold; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("CursorThreshold")); - } - - this.cursorThreshold = value; - } - } - - public string DefaultFullTextLanguage - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.defaultFullTextLanguage; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("DefaultFullTextLanguage")); - } - this.defaultFullTextLanguage = value; - } - } - - public string DefaultLanguage - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.defaultLanguage; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("DefaultLanguage")); - } - this.defaultLanguage = value; - } - } - - public string FullTextUpgradeOption - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.fullTextUpgradeOption; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("FullTextUpgradeOption")); - } - this.fullTextUpgradeOption = value; - } - } - - public NumericServerProperty MaxTextReplicationSize - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.maxTextReplicationSize; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("MaxTextReplicationSize")); - } - - this.maxTextReplicationSize = value; - } - } - - public bool OptimizeAdHocWorkloads - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.optimizeAdHocWorkloads; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("OptimizeAdHocWorkloads")); - } - this.optimizeAdHocWorkloads = value; - } - } - - public bool ScanStartupProcs - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.scanStartupProcs; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("ScanStartupProcs")); - } - this.scanStartupProcs = value; - } - } - - public int TwoDigitYearCutoff - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.twoDigitYearCutoff; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("TwoDigitYearCutoff")); - } - this.twoDigitYearCutoff = value; - } - } - - public NumericServerProperty CostThresholdParallelism - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.costThresholdParallelism; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("CostThresholdParallelism")); - } - this.costThresholdParallelism = value; - } - } - - public NumericServerProperty Locks - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.locks; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("Locks")); - } - this.locks = value; - } - } - - public NumericServerProperty MaxDegreeParallelism - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.maxDegreeParallelism; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("MaxDegreeParallelism")); - } - this.maxDegreeParallelism = value; - } - } - - public NumericServerProperty QueryWait - { - get - { - if (!this.initialized) - { - LoadData(); - } - - return this.queryWait; - } - - set - { - if (this.initialized) - { - Logger.Error(SR.PropertyNotInitialized("QueryWait")); - } - this.queryWait = value; - } - } - - #endregion - - /// - /// private default constructor - used by Clone() - /// - private ServerPrototypeData() - { - } - - - /// - /// constructor - /// - /// The context in which we are modifying an existing server - /// The server we are modifying - public ServerPrototypeData(CDataContainer context, Server server, ServerConfigService service) - { - this.server = context.Server; - this.context = context; - this.configService = service; - this.isYukonOrLater = (this.server.Information.Version.Major >= 9); - this.isSqlServer64Bit = (this.server.Edition.Contains("(64 - bit)")); - this.affinityManagerIOMask = new AffinityManager(); - this.affinityManagerProcessorMask = new AffinityManager(); - this.minMemory = new NumericServerProperty(); - this.maxMemory = new NumericServerProperty(); - this.blockedProcThreshold = new NumericServerProperty(); - this.cursorThreshold = new NumericServerProperty(); - this.maxTextReplicationSize = new NumericServerProperty(); - this.costThresholdParallelism = new NumericServerProperty(); - this.locks = new NumericServerProperty(); - this.maxDegreeParallelism = new NumericServerProperty(); - this.queryWait = new NumericServerProperty(); - this.NumaNodes = new List(); - LoadData(); - } - - /// - /// Create a clone of this ServerRolePrototypeData object - /// - /// The clone ServerRolePrototypeData object - public object Clone() - { - ServerPrototypeData result = new ServerPrototypeData(); - result.serverName = this.serverName; - result.initialized = this.initialized; - result.hardwareGeneration = this.hardwareGeneration; - result.language = this.language; - result.memoryInMB = this.memoryInMB; - result.operatingSystem = this.operatingSystem; - result.platform = this.platform; - result.processors = this.processors; - result.isClustered = this.isClustered; - result.isHadrEnabled = this.isHadrEnabled; - result.isPolyBaseInstalled = this.isPolyBaseInstalled; - result.isXTPSupported = this.isXTPSupported; - result.product = this.product; - result.reservedStorageSizeMB = this.reservedStorageSizeMB; - result.rootDirectory = this.rootDirectory; - result.serverCollation = this.serverCollation; - result.serviceTier = this.serviceTier; - result.storageSpaceUsageInMB = this.storageSpaceUsageInMB; - result.version = this.version; - result.maxMemory = this.maxMemory; - result.minMemory = this.minMemory; - result.autoProcessorAffinityMaskForAll = this.autoProcessorAffinityMaskForAll; - result.autoProcessorAffinityIOMaskForAll = this.autoProcessorAffinityIOMaskForAll; - result.numaNodes = this.numaNodes; - result.authenticationMode = this.authenticationMode; - result.loginAuditing = this.loginAuditing; - result.checkBackupChecksum = this.checkBackupChecksum; - result.checkCompressBackup = this.checkCompressBackup; - result.dataLocation = this.dataLocation; - result.logLocation = this.logLocation; - result.backupLocation = this.backupLocation; - result.allowTriggerToFireOthers = this.allowTriggerToFireOthers; - result.blockedProcThreshold = this.blockedProcThreshold; - result.cursorThreshold = this.cursorThreshold; - result.defaultFullTextLanguage = this.defaultFullTextLanguage; - result.defaultLanguage = this.defaultLanguage; - result.fullTextUpgradeOption = this.fullTextUpgradeOption; - result.maxTextReplicationSize = this.maxTextReplicationSize; - result.optimizeAdHocWorkloads = this.optimizeAdHocWorkloads; - result.scanStartupProcs = this.scanStartupProcs; - result.twoDigitYearCutoff = this.twoDigitYearCutoff; - result.costThresholdParallelism = this.costThresholdParallelism; - result.locks = this.locks; - result.maxDegreeParallelism = this.maxDegreeParallelism; - result.queryWait = this.queryWait; - result.server = this.server; - return result; - } - - private void LoadData() - { - this.initialized = true; - LoadGeneralProperties(); - LoadMemoryProperties(); - LoadProcessorsProperties(); - LoadSecurityProperties(); - LoadDBSettingsProperties(); - LoadAdvancedProperties(); - } - - private void LoadGeneralProperties() - { - this.serverName = server.Name; - this.hardwareGeneration = server.HardwareGeneration; - this.language = server.Language; - this.memoryInMB = server.PhysicalMemory; - this.operatingSystem = server.HostDistribution; - this.platform = server.HostPlatform; - this.processors = server.Processors; - this.isClustered = server.IsClustered; - this.isHadrEnabled = server.IsHadrEnabled; - this.isPolyBaseInstalled = server.IsPolyBaseInstalled; - this.isXTPSupported = server.IsXTPSupported; - this.product = server.Product; - this.rootDirectory = server.RootDirectory; - this.serverCollation = server.Collation; - this.version = server.VersionString; - this.reservedStorageSizeMB = server.ReservedStorageSizeMB; - this.serviceTier = server.ServiceTier; - this.storageSpaceUsageInMB = server.UsedStorageSizeMB; - } - private void LoadMemoryProperties() - { - this.maxMemory.Value = server.Configuration.MaxServerMemory.ConfigValue; - this.maxMemory.MaximumValue = server.Configuration.MaxServerMemory.Maximum; - this.maxMemory.MinimumValue = server.Configuration.MaxServerMemory.Minimum; - - this.minMemory.Value = server.Configuration.MinServerMemory.ConfigValue; - this.minMemory.MaximumValue = server.Configuration.MinServerMemory.Maximum; - this.minMemory.MinimumValue = server.Configuration.MinServerMemory.Minimum; - } - - private void LoadProcessorsProperties() - { - try - { - this.affinityManagerIOMask.InitializeAffinity(this.server.Configuration.AffinityIOMask, this.server.Configuration.Affinity64IOMask); - this.isIOAffinitySupported = true; - } - catch - { - this.isIOAffinitySupported = false; - } - this.affinityManagerProcessorMask.InitializeAffinity(this.server.Configuration.AffinityMask, this.server.Configuration.Affinity64Mask); - - this.numaNodes = GetNumaNodes(); - GetAutoProcessorsAffinity(); - } - - private void LoadSecurityProperties() - { - this.authenticationMode = server.LoginMode; - this.loginAuditing = server.AuditLevel; - } - - private void LoadDBSettingsProperties() - { - this.checkBackupChecksum = server.Configuration.DefaultBackupChecksum.ConfigValue == 1; - this.checkCompressBackup = server.Configuration.DefaultBackupCompression.ConfigValue == 1; - this.dataLocation = server.Settings.DefaultFile; - this.logLocation = server.Settings.DefaultLog; - this.backupLocation = server.Settings.BackupDirectory; - } - - private void LoadAdvancedProperties() - { - this.allowTriggerToFireOthers = server.Configuration.NestedTriggers.ConfigValue == 1; - this.blockedProcThreshold.Value = server.Configuration.BlockedProcessThreshold.ConfigValue; - this.blockedProcThreshold.MinimumValue = server.Configuration.BlockedProcessThreshold.Minimum; - this.blockedProcThreshold.MaximumValue = server.Configuration.BlockedProcessThreshold.Maximum; - this.cursorThreshold.Value = server.Configuration.CursorThreshold.ConfigValue; - this.cursorThreshold.MinimumValue = server.Configuration.CursorThreshold.Minimum; - this.cursorThreshold.MaximumValue = server.Configuration.CursorThreshold.Maximum; - this.defaultFullTextLanguage = LanguageUtils.GetLanguageChoiceAlias(server, server.Configuration.DefaultFullTextLanguage.ConfigValue).alias; - var defaultLanguageLcid = LanguageUtils.GetLcidFromLangId(server, server.Configuration.DefaultLanguage.ConfigValue); - this.defaultLanguage = (LanguageUtils.GetLanguageChoiceAlias(server, defaultLanguageLcid)).ToString(); - this.maxTextReplicationSize.Value = server.Configuration.ReplicationMaxTextSize.ConfigValue; - this.maxTextReplicationSize.MinimumValue = server.Configuration.ReplicationMaxTextSize.Minimum; - this.maxTextReplicationSize.MaximumValue = server.Configuration.ReplicationMaxTextSize.Maximum; - this.optimizeAdHocWorkloads = server.Configuration.OptimizeAdhocWorkloads.ConfigValue == 1; - this.scanStartupProcs = server.Configuration.ScanForStartupProcedures.ConfigValue == 1; - this.twoDigitYearCutoff = server.Configuration.TwoDigitYearCutoff.ConfigValue; - this.costThresholdParallelism.Value = server.Configuration.CostThresholdForParallelism.ConfigValue; - this.costThresholdParallelism.MinimumValue = server.Configuration.CostThresholdForParallelism.Minimum; - this.costThresholdParallelism.MaximumValue = server.Configuration.CostThresholdForParallelism.Maximum; - this.locks.Value = server.Configuration.Locks.ConfigValue; - this.locks.MinimumValue = server.Configuration.Locks.Minimum; - this.locks.MaximumValue = server.Configuration.Locks.Maximum; - this.maxDegreeParallelism.Value = server.Configuration.MaxDegreeOfParallelism.ConfigValue; - this.maxDegreeParallelism.MinimumValue = server.Configuration.MaxDegreeOfParallelism.Minimum; - this.maxDegreeParallelism.MaximumValue = server.Configuration.MaxDegreeOfParallelism.Maximum; - this.queryWait.Value = server.Configuration.QueryWait.ConfigValue; - this.queryWait.MinimumValue = server.Configuration.QueryWait.Minimum; - this.queryWait.MaximumValue = server.Configuration.QueryWait.Maximum; - try - { - this.fullTextUpgradeOption = server.FullTextService.CatalogUpgradeOption.ToString(); - } - catch - { - this.fullTextUpgradeOption = String.Empty; - } - } - - /// - /// Get affinity masks for first 32 and next 32 processors (total 64 processors) if the - /// processor masks have been modified after being read from the server. - /// - /// returns the affinity for first 32 processors. null if not changed - /// return the affinity for CPUs 33-64. null if not changed. - private List GetNumaNodes() - { - List results = new List(); - foreach (SMO.NumaNode node in this.server.AffinityInfo.NumaNodes) - { - var processors = new List(); - foreach (SMO.Cpu cpu in node.Cpus) - { - if (cpu.GroupID == 0) - { - var affinityIO = this.AffinityManagerIOMask.GetAffinity(cpu.ID, true); - if (!cpu.AffinityMask && this.isIOAffinitySupported && affinityIO) // if it's false then check if io affinity is checked - { - this.AffinityManagerIOMask.initialIOAffinityArray[cpu.ID] = true; - } - - // get affinityIO info if group id is 0 - processors.Add(new ProcessorAffinity() { ProcessorId = cpu.ID.ToString(), Affinity = cpu.AffinityMask, IOAffinity = affinityIO }); - } - } - var result = new NumaNode() { NumaNodeId = node.ID.ToString(), Processors = processors }; - results.Add(result); - } - return results; - } - - private void GetAutoProcessorsAffinity() - { - if (this.server.AffinityInfo.AffinityType == Microsoft.SqlServer.Management.Smo.AffinityType.Auto) - { - this.autoProcessorAffinityMaskForAll = this.autoProcessorAffinityIOMaskForAll = true; - } - else - { - this.autoProcessorAffinityMaskForAll = this.autoProcessorAffinityIOMaskForAll = false; - } - } - } } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype130.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype130.cs new file mode 100644 index 0000000000..67dba6cc5b --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype130.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs new file mode 100644 index 0000000000..6a41d26b6a --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs new file mode 100644 index 0000000000..bb2de9614a --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs @@ -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 +{ + /// + /// Prototype for representing a manage instance server. + /// + 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(); + } + } +} \ No newline at end of file From be8e3f4fe3b87bed9c87b16d689e9117d6078e70 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Wed, 4 Oct 2023 13:44:29 -0700 Subject: [PATCH 4/6] Use original file paths when getting associated DB files (#2263) --- .../DisasterRecovery/CommonUtilities.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs index bfafd08c83..8b9a94def1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs @@ -14,7 +14,6 @@ using Microsoft.SqlServer.Management.Smo; using SMO = Microsoft.SqlServer.Management.Smo; using Microsoft.SqlTools.ServiceLayer.Management; -using System.IO; namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery { @@ -376,12 +375,9 @@ public static string[] GetAssociatedFilePaths(ServerConnection connection, strin foreach (DataRow currentRow in dataTable.Rows) { - var primaryFolder = Path.GetDirectoryName(primaryFilePath); - var originalPath = (string)currentRow["FileName"]; - var originalFileName = Path.GetFileName(originalPath); - var filePath = Path.Join(primaryFolder, originalFileName); + var filePath = (string)currentRow["FileName"]; - // Check if file exists with the constructed path. + // Check if file exists with the provided path. // If it's an XI (XStore Integration) path, then assume it exists, otherwise retrieve info for the file to check if it exists. var exists = true; var isXIPath = PathWrapper.IsXIPath(primaryFilePath); From dacddd250c1a3338ac8f1042e5a69d2bbcb9bab5 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Fri, 6 Oct 2023 13:24:22 -0700 Subject: [PATCH 5/6] Improve how server OS and Platform are displayed (#2264) * Also fixed versioning issues with how isPolybaseEnabled and isXTPSupported properties are accessed. --- .../ObjectTypes/Security/NetStandardUtils.cs | 11 +---- .../ObjectTypes/Server/ServerData.cs | 15 ++++-- .../ObjectTypes/Server/ServerHandler.cs | 13 ++--- .../ObjectTypes/Server/ServerPrototype.cs | 27 +++++++++++ .../ObjectTypes/Server/ServerPrototype140.cs | 47 ------------------- .../ObjectTypes/Server/ServerPrototypeMI.cs | 2 +- 6 files changed, 43 insertions(+), 72 deletions(-) delete mode 100644 src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Security/NetStandardUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Security/NetStandardUtils.cs index b912a07860..eb69ce085d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Security/NetStandardUtils.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Security/NetStandardUtils.cs @@ -111,18 +111,11 @@ public static bool IsSql13SP1OrLater(Version version) public static bool IsXTPSupportedOnServer(SMO.Server server) { - if(server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand) + if (server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand) { return false; } - bool isXTPSupported = false; - - if (server.ConnectionContext.ExecuteScalar("SELECT SERVERPROPERTY('IsXTPSupported')") != DBNull.Value) - { - isXTPSupported = server.IsXTPSupported; - } - - return isXTPSupported; + return server.IsSupportedProperty(nameof(server.IsXTPSupported)) && server.IsXTPSupported; } public static bool IsPolybasedInstalledOnServer(SMO.Server server) diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs index b491ab1323..881ea6165b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerData.cs @@ -1199,7 +1199,6 @@ private void LoadGeneralProperties() this.processors = server.Processors; this.isClustered = server.IsClustered; this.isHadrEnabled = server.IsHadrEnabled; - this.isPolyBaseInstalled = server.IsPolyBaseInstalled; this.product = server.Product; this.rootDirectory = server.RootDirectory; @@ -1212,19 +1211,25 @@ private void LoadGeneralProperties() this.reservedStorageSizeMB = server.ReservedStorageSizeMB; this.storageSpaceUsageInMB = server.UsedStorageSizeMB; } - else + if (server.VersionMajor < 14 || server.HostPlatform == null) { - this.isXTPSupported = server.IsXTPSupported; + this.platform = server.Platform; + this.operatingSystem = "Microsoft Windows NT " + + Convert.ToString(server.OSVersion, System.Globalization.CultureInfo.InvariantCulture); } - if (server.VersionMajor >= 14) + else { - this.operatingSystem = server.HostDistribution; this.platform = server.HostPlatform; + this.operatingSystem = $"{server.HostDistribution} ({server.HostRelease})"; } if (server.VersionMajor >= 13) { this.isPolyBaseInstalled = server.IsPolyBaseInstalled; } + if (Utils.IsXTPSupportedOnServer(server)) + { + this.isXTPSupported = server.IsXTPSupported; + } } private void LoadMemoryProperties() diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs index b3b1522ca8..492d72e021 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerHandler.cs @@ -48,6 +48,8 @@ public override Task InitializeObjectView(InitializeViewRe Name = prototype.Name, Language = prototype.Language, MemoryInMB = prototype.MemoryInMB, + OperatingSystem = prototype.OperatingSystem, + Platform = prototype.Platform, Processors = prototype.Processors, IsClustered = prototype.IsClustered, IsHadrEnabled = prototype.IsHadrEnabled, @@ -90,11 +92,6 @@ public override Task InitializeObjectView(InitializeViewRe 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; @@ -169,11 +166,7 @@ private ServerPrototype CreateServerPrototype(Server server, ServerConnection co { prototype = new ServerPrototypeMI(server, connection); } - else if (server.VersionMajor >= 14) - { - prototype = new ServerPrototype140(server, connection); - } - else if (server.VersionMajor == 13) + else if (server.VersionMajor >= 13) { prototype = new ServerPrototype130(server, connection); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs index 4d62b3e6e1..a6a331dfe2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype.cs @@ -53,6 +53,19 @@ public string Product } } + + public string OperatingSystem + { + get + { + return this.currentState.OperatingSystem; + } + set + { + this.currentState.OperatingSystem = value; + } + } + public string Version { get @@ -77,6 +90,18 @@ public string Language } } + public string Platform + { + get + { + return this.currentState.Platform; + } + set + { + this.currentState.Platform = value; + } + } + public int MemoryInMB { get @@ -924,6 +949,8 @@ public virtual void ApplyInfoToPrototype(ServerInfo serverInfo) this.Name = serverInfo.Name ?? string.Empty; this.Language = serverInfo.Language; this.MemoryInMB = serverInfo.MemoryInMB; + this.OperatingSystem = serverInfo.OperatingSystem; + this.Platform = serverInfo.Platform; this.Version = serverInfo.Version; this.Processors = serverInfo.Processors; this.Version = serverInfo.Version; diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs deleted file mode 100644 index 6a41d26b6a..0000000000 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototype140.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -// 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; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs index bb2de9614a..94ed738687 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypes/Server/ServerPrototypeMI.cs @@ -11,7 +11,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement /// /// Prototype for representing a manage instance server. /// - internal class ServerPrototypeMI : ServerPrototype140 + internal class ServerPrototypeMI : ServerPrototype130 { public ServerPrototypeMI(Server server, ServerConnection connection) : base(server, connection) { } From f0d3a0d546509dfb56587f8b6b249d15b2dc7daf Mon Sep 17 00:00:00 2001 From: Christopher Suh Date: Mon, 9 Oct 2023 11:18:51 -0700 Subject: [PATCH 6/6] Transfer URI Correctly (#2265) * transfer uri regardless of queryrunner presence * remove extra space --- .../Connection/ConnectionService.cs | 1 + .../QueryExecution/QueryExecutionService.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index f6e0217dcb..0a0b66092e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -925,6 +925,7 @@ public bool ReplaceUri(string originalOwnerUri, string newOwnerUri) { return false; } + info.OwnerUri = newOwnerUri; OwnerToConnectionMap.Remove(originalOwnerUri); OwnerToConnectionMap.Add(newOwnerUri, info); return true; diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs index e9c4bd3af6..32bf7a67e8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs @@ -363,13 +363,13 @@ internal Task HandleConnectionUriChangedNotification(ConnectionUriChangedParams { string OriginalOwnerUri = changeUriParams.OriginalOwnerUri; string NewOwnerUri = changeUriParams.NewOwnerUri; + ConnectionService.ReplaceUri(OriginalOwnerUri, NewOwnerUri); // Attempt to load the query Query query; if (!ActiveQueries.TryRemove(OriginalOwnerUri, out query)) { throw new Exception("Uri: " + OriginalOwnerUri + " is not associated with an active query."); } - ConnectionService.ReplaceUri(OriginalOwnerUri, NewOwnerUri); query.ConnectionOwnerURI = NewOwnerUri; ActiveQueries.TryAdd(NewOwnerUri, query); return Task.FromResult(true);