Update memory settings and implement ServerPrototype (#2126)

This commit is contained in:
Barbara Valdez
2023-07-06 17:25:45 -07:00
committed by GitHub
parent b9277c3830
commit 4c4d6584b3
9 changed files with 1154 additions and 47 deletions

View File

@@ -12946,6 +12946,11 @@ namespace Microsoft.SqlTools.ServiceLayer
return Keys.GetString(Keys.ServiceNotFound, serviceName);
}
public static string PropertyNotInitialized(string propertyName)
{
return Keys.GetString(Keys.PropertyNotInitialized, propertyName);
}
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Keys
{
@@ -17898,6 +17903,9 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string HyperscaleAzureEdition = "HyperscaleAzureEdition";
public const string PropertyNotInitialized = "PropertyNotInitialized";
private Keys()
{ }

View File

@@ -6802,4 +6802,9 @@ The Query Processor estimates that implementing the following index could improv
<value>Hyperscale</value>
<comment></comment>
</data>
<data name="PropertyNotInitialized" xml:space="preserve">
<value>Property &apos;{0}&apos; was set before initialization.</value>
<comment>.
Parameters: 0 - propertyName (string) </comment>
</data>
</root>

View File

@@ -2815,3 +2815,9 @@ GeneralPurposeAzureEdition = General Purpose
BusinessCriticalAzureEdition = Business Critical
ErrorInvalidEdition = Edition value is not valid
HyperscaleAzureEdition = Hyperscale
#############################################################################
# Server Properties
############################################################################
PropertyNotInitialized(string propertyName) = Property '{0}' was set before initialization.

View File

@@ -8321,6 +8321,12 @@ The Query Processor estimates that implementing the following index could improv
<target state="new">None</target>
<note></note>
</trans-unit>
<trans-unit id="PropertyNotInitialized">
<source>Property '{0}' was set before initialization.</source>
<target state="new">Property '{0}' was set before initialization.</target>
<note>.
Parameters: 0 - propertyName (string) </note>
</trans-unit>
<trans-unit id="TableDesignerCreateTablePermissionDenied">
<source>CREATE TABLE permission denied in database '{0}'.</source>
<target state="new">CREATE TABLE permission denied in database '{0}'.</target>

View File

@@ -0,0 +1,40 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.ServiceLayer.Management;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
internal class ServerActions : ManagementActionBase
{
#region Variables
private ServerPrototype serverData;
private ConfigAction configAction;
#endregion
#region Constructor
public ServerActions(
CDataContainer context,
ServerPrototype server,
ConfigAction configAction)
{
this.DataContainer = context;
this.serverData = server;
this.configAction = configAction;
}
#endregion
/// <summary>
/// called on background thread by the framework to execute the action
/// </summary>
/// <param name="node"></param>
public override void OnRunNow(object sender)
{
this.serverData.SendDataToServer();
}
}
}

View File

@@ -0,0 +1,971 @@
//
// 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 Microsoft.SqlTools.ServiceLayer.Management;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
internal class ServerPrototype
{
#region Members
/// <summary>
/// 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
/// </summary>
private CDataContainer dataContainer;
private ServerConnection sqlConnection;
private ServerConfigService configService;
private ServerPrototypeData currentState;
private ServerPrototypeData originalState;
private ConfigProperty serverMinMemoryProperty;
private ConfigProperty serverMaxMemoryProperty;
#endregion
#region Trace support
private const string componentName = "Server";
public string ComponentName
{
get
{
return componentName;
}
}
#endregion
#region Properties
public string Name
{
get
{
return this.currentState.ServerName;
}
set
{
this.currentState.ServerName = value;
}
}
public string Product
{
get
{
return this.currentState.Product;
}
set
{
this.currentState.Product = value;
}
}
public string OperatingSystem
{
get
{
return this.currentState.OperatingSystem;
}
set
{
this.currentState.OperatingSystem = value;
}
}
public string Version
{
get
{
return this.currentState.Version;
}
set
{
this.currentState.Version = value;
}
}
public string Language
{
get
{
return this.currentState.Language;
}
set
{
this.currentState.Language = value;
}
}
public string Platform
{
get
{
return this.currentState.Platform;
}
set
{
this.currentState.Platform = value;
}
}
public int MemoryInMB
{
get
{
return this.currentState.MemoryInMB;
}
set
{
this.currentState.MemoryInMB = value;
}
}
public int Processors
{
get
{
return this.currentState.Processors;
}
set
{
this.currentState.Processors = value;
}
}
public string RootDirectory
{
get
{
return this.currentState.RootDirectory;
}
set
{
this.currentState.RootDirectory = value;
}
}
public string ServerCollation
{
get
{
return this.currentState.ServerCollation;
}
set
{
this.currentState.ServerCollation = value;
}
}
public bool IsClustered
{
get
{
return this.currentState.IsClustered;
}
set
{
this.currentState.IsClustered = value;
}
}
public bool IsHadrEnabled
{
get
{
return this.currentState.IsHadrEnabled;
}
set
{
this.currentState.IsHadrEnabled = value;
}
}
public bool IsXTPSupported
{
get
{
return this.currentState.IsXTPSupported;
}
set
{
this.currentState.IsXTPSupported = value;
}
}
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 int MaxServerMemory
{
get
{
return this.currentState.MaxMemory;
}
set
{
this.currentState.MaxMemory = value;
}
}
public int MinServerMemory
{
get
{
return this.currentState.MinMemory;
}
set
{
this.currentState.MinMemory = value;
}
}
#endregion
#region Constructors / Dispose
/// <summary>
/// ServerPrototype for editing an existing server
/// </summary>
public ServerPrototype(CDataContainer context)
{
this.dataContainer = context;
this.sqlConnection = context.ServerConnection;
this.configService = new ServerConfigService();
this.currentState = new ServerPrototypeData(context, context.Server, this.configService);
this.originalState = (ServerPrototypeData)this.currentState.Clone();
this.serverMaxMemoryProperty = this.configService.GetServerSmoConfig(context.Server, this.configService.MaxServerMemoryPropertyNumber);
this.serverMinMemoryProperty = this.configService.GetServerSmoConfig(context.Server, this.configService.MinServerMemoryPropertyNumber);
}
#endregion
#region Implementation: SendDataToServer()
/// <summary>
/// SendDataToServer
///
/// here we talk with server via smo and do the actual data changing
/// </summary>
public void SendDataToServer()
{
if (this.dataContainer.Server != null)
{
Microsoft.SqlServer.Management.Smo.Server server = this.dataContainer.Server;
bool changesMade = false;
changesMade = UpdateMemoryValues(this.dataContainer.Server);
if (changesMade)
{
server.Configuration.Alter(true);
}
}
}
public bool UpdateMemoryValues(Microsoft.SqlServer.Management.Smo.Server server)
{
bool changesMade = false;
if (this.currentState.MinMemory != this.originalState.MinMemory)
{
changesMade = true;
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MinServerMemoryPropertyNumber);
serverConfig.ConfigValue = this.currentState.MinMemory;
}
if (this.currentState.MaxMemory != this.originalState.MaxMemory)
{
changesMade = true;
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
serverConfig.ConfigValue = this.currentState.MaxMemory;
}
return changesMade;
}
#endregion
public void ApplyInfoToPrototype(ServerInfo serverInfo)
{
this.Name = serverInfo.Name;
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.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;
}
/// <summary>
/// Private class encapsulating the data that is changed by the UI.
/// </summary>
/// <remarks>
/// Isolating this data allows for an easy implementation of Reset() and
/// simplifies difference detection when committing changes to the server.
/// </remarks>
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 int minMemory = 0;
private int maxMemory = 0;
private bool initialized = false;
private Server server;
private CDataContainer context;
private ServerConfigService configService;
private bool isYukonOrLater = false;
ConfigProperty serverMaxMemoryProperty;
ConfigProperty serverMinMemoryProperty;
#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 int MinMemory
{
get
{
if (!this.initialized)
{
LoadData();
}
return this.minMemory;
}
set
{
if (this.initialized)
{
Logger.Error(SR.PropertyNotInitialized("MinMemory"));
}
this.minMemory = value;
}
}
public int MaxMemory
{
get
{
if (!this.initialized)
{
LoadData();
}
return this.maxMemory;
}
set
{
if (this.initialized)
{
Logger.Error(SR.PropertyNotInitialized("MaxMemory"));
}
this.maxMemory = value;
}
}
public Microsoft.SqlServer.Management.Smo.Server Server
{
get
{
return this.server;
}
}
public bool IsYukonOrLater
{
get
{
return this.isYukonOrLater;
}
}
#endregion
/// <summary>
/// private default constructor - used by Clone()
/// </summary>
private ServerPrototypeData()
{
}
/// <summary>
/// constructor
/// </summary>
/// <param name="context">The context in which we are modifying an existing server</param>
/// <param name="server">The server we are modifying</param>
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.serverMaxMemoryProperty = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
this.serverMinMemoryProperty = this.configService.GetServerSmoConfig(server, this.configService.MinServerMemoryPropertyNumber);
LoadData();
}
/// <summary>
/// Create a clone of this ServerRolePrototypeData object
/// </summary>
/// <returns>The clone ServerRolePrototypeData object</returns>
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.server = this.server;
return result;
}
private void LoadData()
{
this.initialized = true;
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;
this.maxMemory = serverMaxMemoryProperty.ConfigValue;
this.minMemory = serverMinMemoryProperty.ConfigValue;
}
}
}
}

View File

@@ -5,13 +5,11 @@
using System;
using System.Threading.Tasks;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Management;
using Microsoft.SqlTools.ServiceLayer.ObjectManagement.Contracts;
using Microsoft.SqlTools.ServiceLayer.ObjectManagement.ObjectTypes.Server;
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
@@ -22,7 +20,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{
private ServerViewInfo serverViewInfo = new ServerViewInfo();
private ServerConfigService configService = new ServerConfigService();
private Server server = null;
public ServerHandler(ConnectionService connectionService) : base(connectionService)
{
@@ -36,45 +33,47 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
public override Task<InitializeViewResult> InitializeObjectView(InitializeViewRequestParams requestParams)
{
ConnectionInfo connInfo = this.GetConnectionInfo(requestParams.ConnectionUri);
ServerConnection serverConnection = ConnectionService.OpenServerConnection(connInfo, ObjectManagementService.ApplicationName);
using (var context = new ServerViewContext(requestParams, serverConnection))
using (var context = new ServerViewContext(requestParams, ConnectionService.OpenServerConnection(connInfo, ObjectManagementService.ApplicationName)))
{
this.server = new Server(context.Connection);
if (this.server != null)
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
ServerPrototype prototype = new ServerPrototype(dataContainer);
if (prototype != null)
{
this.serverViewInfo.ObjectInfo = new ServerInfo()
{
Name = server.Name,
HardwareGeneration = server.HardwareGeneration,
Language = server.Language,
MemoryInMB = server.PhysicalMemory,
OperatingSystem = server.HostDistribution,
Platform = server.HostPlatform,
Processors = server.Processors,
IsClustered = server.IsClustered,
IsHadrEnabled = server.IsHadrEnabled,
IsPolyBaseInstalled = server.IsPolyBaseInstalled,
IsXTPSupported = server.IsXTPSupported,
Product = server.Product,
ReservedStorageSizeMB = server.ReservedStorageSizeMB,
RootDirectory = server.RootDirectory,
ServerCollation = server.Collation,
ServiceTier = server.ServiceTier,
StorageSpaceUsageInGB = (int)ByteConverter.ConvertMbtoGb(server.UsedStorageSizeMB),
Version = server.Version.ToString(),
MinServerMemory = GetServerMinMemory(),
MaxServerMemory = GetServerMaxMemory()
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
};
}
return Task.FromResult(new InitializeViewResult { ViewInfo = this.serverViewInfo, Context = context });
}
}
public override Task Save(ServerViewContext context, ServerInfo serverInfo)
public override Task Save(ServerViewContext context, ServerInfo obj)
{
throw new NotSupportedException("ServerHandler does not support Save method");
UpdateServerProperties(context.Parameters, obj);
return Task.CompletedTask;
}
public override Task<string> Script(ServerViewContext context, ServerInfo obj)
@@ -82,14 +81,30 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
throw new NotSupportedException("ServerHandler does not support Script method");
}
private int GetServerMaxMemory()
private void UpdateServerProperties(InitializeViewRequestParams viewParams, ServerInfo serverInfo)
{
return configService.GetServerSmoConfig(server, configService.MaxServerMemoryPropertyNumber).ConfigValue;
if (viewParams != null)
{
ConnectionInfo connInfo = this.GetConnectionInfo(viewParams.ConnectionUri);
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo);
ServerPrototype prototype = new ServerPrototype(dataContainer);
prototype.ApplyInfoToPrototype(serverInfo);
ConfigureServer(dataContainer, ConfigAction.Update, RunType.RunNow, prototype);
}
}
private int GetServerMinMemory()
private void ConfigureServer(CDataContainer dataContainer, ConfigAction configAction, RunType runType, ServerPrototype prototype)
{
return configService.GetServerSmoConfig(server, configService.MinServerMemoryPropertyNumber).ConfigValue;
using (var actions = new ServerActions(dataContainer, prototype, configAction))
{
var executionHandler = new ExecutonHandler(actions);
executionHandler.RunNow(runType, this);
if (executionHandler.ExecutionResult == ExecutionMode.Failure)
{
throw executionHandler.ExecutionFailureException;
}
}
}
}
}

View File

@@ -26,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
public string RootDirectory { get; set; }
public string ServerCollation { get; set; }
public string? ServiceTier { get; set; }
public int? StorageSpaceUsageInGB { get; set; }
public int? StorageSpaceUsageInMB { get; set; }
public string Version { get; set; }
public int MaxServerMemory { get; set; }
public int MinServerMemory { get; set; }

View File

@@ -9,11 +9,13 @@ using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.ObjectManagement;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlServer.Management.Smo;
using NUnit.Framework;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Server = Microsoft.SqlServer.Management.Smo.Server;
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
{
/// <summary>
@@ -47,5 +49,59 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
Assert.That(((ServerInfo)result.ViewInfo.ObjectInfo).IsPolyBaseInstalled, Is.Not.Null, $"Server isPolyBaseInstalled property should not be null");
}
}
/// <summary>
/// Test SetMemoryProperties for Sql Server
/// </summary>
[Test]
public async Task SetMemoryProperties()
{
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", serverType: TestServerType.OnPrem);
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connectionResult.ConnectionInfo))
{
var server = new Server(new ServerConnection(sqlConn));
var serverHandler = new ServerHandler(ConnectionService.Instance);
var serverConfig = new ServerConfigService();
var requestParams = ObjectManagementTestUtils.GetInitializeViewRequestParams(connectionResult.ConnectionInfo.OwnerUri, "master", true, SqlObjectType.Server, "", "");
var result = (ServerInfo)(await serverHandler.InitializeObjectView(requestParams)).ViewInfo.ObjectInfo;
ServerInfo serverInfo = new ServerInfo()
{
Name = result.Name,
HardwareGeneration = result.HardwareGeneration,
Language = result.Language,
MemoryInMB = result.MemoryInMB,
OperatingSystem = result.OperatingSystem,
Platform = result.Platform,
Processors = result.Processors,
IsClustered = result.IsClustered,
IsHadrEnabled = result.IsHadrEnabled,
IsPolyBaseInstalled = result.IsPolyBaseInstalled,
IsXTPSupported = result.IsXTPSupported,
Product = result.Product,
ReservedStorageSizeMB = result.ReservedStorageSizeMB,
RootDirectory = result.RootDirectory,
ServerCollation = result.ServerCollation,
ServiceTier = result.ServiceTier,
StorageSpaceUsageInMB = result.StorageSpaceUsageInMB,
Version = result.Version,
MinServerMemory = result.MinServerMemory,
MaxServerMemory = result.MaxServerMemory
};
// Change memory settings
serverInfo.MinServerMemory = 10;
serverInfo.MaxServerMemory = 500;
Assert.AreNotEqual(result.MinServerMemory, serverInfo.MinServerMemory, "Server property should not be equal after update");
Assert.AreNotEqual(result.MaxServerMemory, serverInfo.MaxServerMemory, "Server property should not be equal after update");
await ObjectManagementTestUtils.SaveObject(requestParams, serverInfo);
result = (ServerInfo)(await serverHandler.InitializeObjectView(requestParams)).ViewInfo.ObjectInfo;
Assert.IsNotNull(result);
Assert.AreEqual(result.MinServerMemory, serverInfo.MinServerMemory, "Server property should not be different after update");
Assert.AreEqual(result.MaxServerMemory, serverInfo.MaxServerMemory, "Server property should not be different after update");
}
}
}
}