mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Send min and max values for server properties (#2130)
This commit is contained in:
@@ -68,43 +68,43 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
return Task.FromResult(new InitializeViewResult { ViewInfo = this.serverViewInfo, Context = context });
|
return Task.FromResult(new InitializeViewResult { ViewInfo = this.serverViewInfo, Context = context });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override Task Save(ServerViewContext context, ServerInfo obj)
|
|
||||||
{
|
|
||||||
UpdateServerProperties(context.Parameters, obj);
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task<string> Script(ServerViewContext context, ServerInfo obj)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException("ServerHandler does not support Script method");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateServerProperties(InitializeViewRequestParams viewParams, ServerInfo serverInfo)
|
|
||||||
{
|
|
||||||
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 void ConfigureServer(CDataContainer dataContainer, ConfigAction configAction, RunType runType, ServerPrototype prototype)
|
public override Task Save(ServerViewContext context, ServerInfo obj)
|
||||||
{
|
|
||||||
using (var actions = new ServerActions(dataContainer, prototype, configAction))
|
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(actions);
|
UpdateServerProperties(context.Parameters, obj);
|
||||||
executionHandler.RunNow(runType, this);
|
return Task.CompletedTask;
|
||||||
if (executionHandler.ExecutionResult == ExecutionMode.Failure)
|
}
|
||||||
|
|
||||||
|
public override Task<string> Script(ServerViewContext context, ServerInfo obj)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("ServerHandler does not support Script method");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateServerProperties(InitializeViewRequestParams viewParams, ServerInfo serverInfo)
|
||||||
|
{
|
||||||
|
if (viewParams != null)
|
||||||
{
|
{
|
||||||
throw executionHandler.ExecutionFailureException;
|
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 void ConfigureServer(CDataContainer dataContainer, ConfigAction configAction, RunType runType, ServerPrototype prototype)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
public string? ServiceTier { get; set; }
|
public string? ServiceTier { get; set; }
|
||||||
public int? StorageSpaceUsageInMB { get; set; }
|
public int? StorageSpaceUsageInMB { get; set; }
|
||||||
public string Version { get; set; }
|
public string Version { get; set; }
|
||||||
public int MaxServerMemory { get; set; }
|
public NumericServerProperty MaxServerMemory { get; set; }
|
||||||
public int MinServerMemory { get; set; }
|
public NumericServerProperty MinServerMemory { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericServerProperty
|
||||||
|
{
|
||||||
|
public int MaximumValue { get; set; }
|
||||||
|
public int MinimumValue { get; set; }
|
||||||
|
public int Value { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
private ServerConnection sqlConnection;
|
private ServerConnection sqlConnection;
|
||||||
private ServerConfigService configService;
|
private ServerConfigService configService;
|
||||||
|
|
||||||
|
|
||||||
private ServerPrototypeData currentState;
|
private ServerPrototypeData currentState;
|
||||||
private ServerPrototypeData originalState;
|
private ServerPrototypeData originalState;
|
||||||
|
|
||||||
@@ -264,7 +263,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MaxServerMemory
|
|
||||||
|
public NumericServerProperty MaxServerMemory
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -276,7 +276,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MinServerMemory
|
public NumericServerProperty MinServerMemory
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -334,19 +334,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
public bool UpdateMemoryValues(Microsoft.SqlServer.Management.Smo.Server server)
|
public bool UpdateMemoryValues(Microsoft.SqlServer.Management.Smo.Server server)
|
||||||
{
|
{
|
||||||
bool changesMade = false;
|
bool changesMade = false;
|
||||||
|
if (this.currentState.MinMemory.Value != this.originalState.MinMemory.Value)
|
||||||
if (this.currentState.MinMemory != this.originalState.MinMemory)
|
|
||||||
{
|
{
|
||||||
changesMade = true;
|
changesMade = true;
|
||||||
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MinServerMemoryPropertyNumber);
|
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MinServerMemoryPropertyNumber);
|
||||||
serverConfig.ConfigValue = this.currentState.MinMemory;
|
serverConfig.ConfigValue = this.currentState.MinMemory.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentState.MaxMemory != this.originalState.MaxMemory)
|
if (this.currentState.MaxMemory.Value != this.originalState.MaxMemory.Value)
|
||||||
{
|
{
|
||||||
changesMade = true;
|
changesMade = true;
|
||||||
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
|
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
|
||||||
serverConfig.ConfigValue = this.currentState.MaxMemory;
|
serverConfig.ConfigValue = this.currentState.MaxMemory.Value;
|
||||||
}
|
}
|
||||||
return changesMade;
|
return changesMade;
|
||||||
}
|
}
|
||||||
@@ -404,9 +403,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
private string serviceTier = String.Empty;
|
private string serviceTier = String.Empty;
|
||||||
private int reservedStorageSizeMB = 0;
|
private int reservedStorageSizeMB = 0;
|
||||||
private int storageSpaceUsageInMB = 0;
|
private int storageSpaceUsageInMB = 0;
|
||||||
private int minMemory = 0;
|
|
||||||
private int maxMemory = 0;
|
|
||||||
|
|
||||||
|
private NumericServerProperty minMemory;
|
||||||
|
private NumericServerProperty maxMemory;
|
||||||
private bool initialized = false;
|
private bool initialized = false;
|
||||||
private Server server;
|
private Server server;
|
||||||
private CDataContainer context;
|
private CDataContainer context;
|
||||||
@@ -821,7 +820,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int MinMemory
|
public NumericServerProperty MinMemory
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -836,7 +835,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (this.initialized)
|
if (this.initialized)
|
||||||
{
|
{
|
||||||
Logger.Error(SR.PropertyNotInitialized("MinMemory"));
|
Logger.Error(SR.PropertyNotInitialized("MinMemory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -844,7 +843,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MaxMemory
|
public NumericServerProperty MaxMemory
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -907,6 +906,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
this.isYukonOrLater = (this.server.Information.Version.Major >= 9);
|
this.isYukonOrLater = (this.server.Information.Version.Major >= 9);
|
||||||
this.serverMaxMemoryProperty = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
|
this.serverMaxMemoryProperty = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
|
||||||
this.serverMinMemoryProperty = this.configService.GetServerSmoConfig(server, this.configService.MinServerMemoryPropertyNumber);
|
this.serverMinMemoryProperty = this.configService.GetServerSmoConfig(server, this.configService.MinServerMemoryPropertyNumber);
|
||||||
|
this.minMemory = new NumericServerProperty();
|
||||||
|
this.maxMemory = new NumericServerProperty();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -963,8 +964,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
this.reservedStorageSizeMB = server.ReservedStorageSizeMB;
|
this.reservedStorageSizeMB = server.ReservedStorageSizeMB;
|
||||||
this.serviceTier = server.ServiceTier;
|
this.serviceTier = server.ServiceTier;
|
||||||
this.storageSpaceUsageInMB = server.UsedStorageSizeMB;
|
this.storageSpaceUsageInMB = server.UsedStorageSizeMB;
|
||||||
this.maxMemory = serverMaxMemoryProperty.ConfigValue;
|
LoadMemoryProperties();
|
||||||
this.minMemory = serverMinMemoryProperty.ConfigValue;
|
}
|
||||||
|
|
||||||
|
private void LoadMemoryProperties()
|
||||||
|
{
|
||||||
|
this.maxMemory.Value = serverMaxMemoryProperty.ConfigValue;
|
||||||
|
this.maxMemory.MaximumValue = serverMaxMemoryProperty.Maximum;
|
||||||
|
this.maxMemory.MinimumValue = serverMaxMemoryProperty.Minimum;
|
||||||
|
|
||||||
|
this.minMemory.Value = serverMinMemoryProperty.ConfigValue;
|
||||||
|
this.minMemory.MaximumValue = serverMinMemoryProperty.Maximum;
|
||||||
|
this.minMemory.MinimumValue = serverMinMemoryProperty.Minimum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,6 @@ using NUnit.Framework;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
|
||||||
using Server = Microsoft.SqlServer.Management.Smo.Server;
|
using Server = Microsoft.SqlServer.Management.Smo.Server;
|
||||||
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
||||||
{
|
{
|
||||||
@@ -61,7 +60,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
|||||||
{
|
{
|
||||||
var server = new Server(new ServerConnection(sqlConn));
|
var server = new Server(new ServerConnection(sqlConn));
|
||||||
var serverHandler = new ServerHandler(ConnectionService.Instance);
|
var serverHandler = new ServerHandler(ConnectionService.Instance);
|
||||||
var serverConfig = new ServerConfigService();
|
|
||||||
|
|
||||||
var requestParams = ObjectManagementTestUtils.GetInitializeViewRequestParams(connectionResult.ConnectionInfo.OwnerUri, "master", true, SqlObjectType.Server, "", "");
|
var requestParams = ObjectManagementTestUtils.GetInitializeViewRequestParams(connectionResult.ConnectionInfo.OwnerUri, "master", true, SqlObjectType.Server, "", "");
|
||||||
var result = (ServerInfo)(await serverHandler.InitializeObjectView(requestParams)).ViewInfo.ObjectInfo;
|
var result = (ServerInfo)(await serverHandler.InitializeObjectView(requestParams)).ViewInfo.ObjectInfo;
|
||||||
@@ -90,17 +88,18 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Change memory settings
|
// Change memory settings
|
||||||
serverInfo.MinServerMemory = 10;
|
serverInfo.MinServerMemory.Value = 10;
|
||||||
serverInfo.MaxServerMemory = 500;
|
serverInfo.MaxServerMemory.Value = 500;
|
||||||
|
|
||||||
Assert.AreNotEqual(result.MinServerMemory, serverInfo.MinServerMemory, "Server property should not be equal after update");
|
Assert.That(result.MinServerMemory.Value, Is.Not.EqualTo(serverInfo.MinServerMemory.Value), "Server property should not be equal after update");
|
||||||
Assert.AreNotEqual(result.MaxServerMemory, serverInfo.MaxServerMemory, "Server property should not be equal after update");
|
Assert.That(result.MaxServerMemory.Value, Is.Not.EqualTo(serverInfo.MaxServerMemory.Value), "Server property should not be equal after update");
|
||||||
|
|
||||||
await ObjectManagementTestUtils.SaveObject(requestParams, serverInfo);
|
await ObjectManagementTestUtils.SaveObject(requestParams, serverInfo);
|
||||||
result = (ServerInfo)(await serverHandler.InitializeObjectView(requestParams)).ViewInfo.ObjectInfo;
|
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.That(result, Is.Not.Null);
|
||||||
Assert.AreEqual(result.MaxServerMemory, serverInfo.MaxServerMemory, "Server property should not be different after update");
|
Assert.That(result.MinServerMemory.Value, Is.EqualTo(serverInfo.MinServerMemory.Value), "Server property should be equal after update");
|
||||||
|
Assert.That(result.MaxServerMemory.Value, Is.EqualTo(serverInfo.MaxServerMemory.Value), "Server property should be equal after update");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user