Send min and max values for server properties (#2130)

This commit is contained in:
Barbara Valdez
2023-07-07 13:03:25 -07:00
committed by GitHub
parent 8dfd50ff50
commit e14828e0d4
4 changed files with 75 additions and 58 deletions

View File

@@ -68,43 +68,43 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
}
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)
{
using (var actions = new ServerActions(dataContainer, prototype, configAction))
public override Task Save(ServerViewContext context, ServerInfo obj)
{
var executionHandler = new ExecutonHandler(actions);
executionHandler.RunNow(runType, this);
if (executionHandler.ExecutionResult == ExecutionMode.Failure)
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)
{
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;
}
}
}
}
}
}

View File

@@ -28,7 +28,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
public string? ServiceTier { get; set; }
public int? StorageSpaceUsageInMB { get; set; }
public string Version { get; set; }
public int MaxServerMemory { get; set; }
public int MinServerMemory { get; set; }
public NumericServerProperty MaxServerMemory { 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; }
}
}

View File

@@ -25,7 +25,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
private ServerConnection sqlConnection;
private ServerConfigService configService;
private ServerPrototypeData currentState;
private ServerPrototypeData originalState;
@@ -264,7 +263,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
}
}
public int MaxServerMemory
public NumericServerProperty MaxServerMemory
{
get
{
@@ -276,7 +276,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
}
}
public int MinServerMemory
public NumericServerProperty MinServerMemory
{
get
{
@@ -334,19 +334,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
public bool UpdateMemoryValues(Microsoft.SqlServer.Management.Smo.Server server)
{
bool changesMade = false;
if (this.currentState.MinMemory != this.originalState.MinMemory)
if (this.currentState.MinMemory.Value != this.originalState.MinMemory.Value)
{
changesMade = true;
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;
ConfigProperty serverConfig = this.configService.GetServerSmoConfig(server, this.configService.MaxServerMemoryPropertyNumber);
serverConfig.ConfigValue = this.currentState.MaxMemory;
serverConfig.ConfigValue = this.currentState.MaxMemory.Value;
}
return changesMade;
}
@@ -404,9 +403,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
private string serviceTier = String.Empty;
private int reservedStorageSizeMB = 0;
private int storageSpaceUsageInMB = 0;
private int minMemory = 0;
private int maxMemory = 0;
private NumericServerProperty minMemory;
private NumericServerProperty maxMemory;
private bool initialized = false;
private Server server;
private CDataContainer context;
@@ -821,7 +820,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
}
public int MinMemory
public NumericServerProperty MinMemory
{
get
{
@@ -844,7 +843,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
}
}
public int MaxMemory
public NumericServerProperty MaxMemory
{
get
{
@@ -907,6 +906,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
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);
this.minMemory = new NumericServerProperty();
this.maxMemory = new NumericServerProperty();
LoadData();
}
@@ -963,8 +964,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
this.reservedStorageSizeMB = server.ReservedStorageSizeMB;
this.serviceTier = server.ServiceTier;
this.storageSpaceUsageInMB = server.UsedStorageSizeMB;
this.maxMemory = serverMaxMemoryProperty.ConfigValue;
this.minMemory = serverMinMemoryProperty.ConfigValue;
LoadMemoryProperties();
}
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;
}
}
}

View File

@@ -14,7 +14,6 @@ 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
{
@@ -61,7 +60,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
{
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;
@@ -90,17 +88,18 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
};
// Change memory settings
serverInfo.MinServerMemory = 10;
serverInfo.MaxServerMemory = 500;
serverInfo.MinServerMemory.Value = 10;
serverInfo.MaxServerMemory.Value = 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");
Assert.That(result.MinServerMemory.Value, Is.Not.EqualTo(serverInfo.MinServerMemory.Value), "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);
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");
Assert.That(result, Is.Not.Null);
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");
}
}
}