Skip to content

Commit

Permalink
Add database settings tab (#2201)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbaravaldez authored Aug 31, 2023
1 parent 5f17826 commit 3ba514c
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public override Task<InitializeViewResult> InitializeObjectView(InitializeViewRe
AutoProcessorAffinityIOMaskForAll = prototype.AutoProcessorAffinityIOMaskForAll,
NumaNodes = prototype.NumaNodes,
AuthenticationMode = prototype.AuthenticationMode,
LoginAuditing = prototype.LoginAuditing
LoginAuditing = prototype.LoginAuditing,
CheckCompressBackup = prototype.CheckCompressBackup,
CheckBackupChecksum = prototype.CheckBackupChecksum,
DataLocation = prototype.DataLocation,
LogLocation = prototype.LogLocation,
BackupLocation = prototype.BackupLocation
};
}
var context = new ServerViewContext(requestParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class ServerInfo : SqlObject
public List<NumaNode> NumaNodes { get; set; }
public ServerLoginMode AuthenticationMode { get; set; }
public AuditLevel LoginAuditing { get; set; }
public bool CheckCompressBackup { get; set; }
public bool CheckBackupChecksum { get; set; }
public string DataLocation { get; set; }
public string LogLocation { get; set; }
public string BackupLocation { get; set; }
}

public class NumericServerProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,66 @@ public AuditLevel LoginAuditing
{
this.currentState.LoginAuditing = value;
}
}

public bool CheckBackupChecksum
{
get
{
return this.currentState.CheckBackupChecksum;
}
set
{
this.currentState.CheckBackupChecksum = value;
}
}

public bool CheckCompressBackup
{
get
{
return this.currentState.CheckCompressBackup;
}
set
{
this.currentState.CheckCompressBackup = value;
}
}

public string DataLocation
{
get
{
return this.currentState.DataLocation;
}
set
{
this.currentState.DataLocation = value;
}
}

public string LogLocation
{
get
{
return this.currentState.LogLocation;
}
set
{
this.currentState.LogLocation = value;
}
}

public string BackupLocation
{
get
{
return this.currentState.BackupLocation;
}
set
{
this.currentState.BackupLocation = value;
}
}
#endregion

Expand Down Expand Up @@ -431,6 +490,16 @@ public void SendDataToServer()
{
server.Alter();
}

if (UpdateDBSettingsValues(this.dataContainer.Server))
{
server.Settings.Alter();
}

if (UpdateBackupConfig(this.dataContainer.Server))
{
server.Configuration.Alter();
}
}
}

Expand Down Expand Up @@ -472,6 +541,48 @@ public bool UpdateSecurityValues(Server server)
return alterServer;
}

public bool UpdateBackupConfig(Server server)
{
bool alterServer = false;
if (this.currentState.CheckBackupChecksum != this.originalState.CheckBackupChecksum)
{
server.Configuration.DefaultBackupChecksum.ConfigValue = this.currentState.CheckBackupChecksum ? 1 : 0;
alterServer = true;
}

if (this.currentState.CheckCompressBackup != this.originalState.CheckCompressBackup)
{
server.Configuration.DefaultBackupCompression.ConfigValue = this.currentState.CheckCompressBackup ? 1 : 0;
alterServer = true;
}

return alterServer;
}

public bool UpdateDBSettingsValues(Server server)
{
bool alterServer = false;

if (this.currentState.DataLocation != this.originalState.DataLocation)
{
server.Settings.DefaultFile = this.currentState.DataLocation;
alterServer = true;
}

if (this.currentState.LogLocation != this.originalState.LogLocation)
{
server.Settings.DefaultLog = this.currentState.LogLocation;
alterServer = true;
}

if (this.currentState.BackupLocation != this.originalState.BackupLocation)
{
server.Settings.BackupDirectory = this.currentState.BackupLocation;
alterServer = true;
}
return alterServer;
}

private bool CheckCPUAffinityBeforeIO(SMO.Server smoServer)
{
for (int i = 0; i < this.NumaNodes.Count; i++)
Expand Down Expand Up @@ -650,6 +761,11 @@ public void ApplyInfoToPrototype(ServerInfo serverInfo)
this.NumaNodes = serverInfo.NumaNodes.ToList();
this.AuthenticationMode = serverInfo.AuthenticationMode;
this.LoginAuditing = serverInfo.LoginAuditing;
this.CheckBackupChecksum = serverInfo.CheckBackupChecksum;
this.CheckCompressBackup = serverInfo.CheckCompressBackup;
this.DataLocation = serverInfo.DataLocation;
this.LogLocation = serverInfo.LogLocation;
this.BackupLocation = serverInfo.BackupLocation;
}

/// <summary>
Expand Down Expand Up @@ -687,6 +803,11 @@ private class ServerPrototypeData : ICloneable
private List<NumaNode> numaNodes = new List<NumaNode>();
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 initialized = false;
private Server server;
Expand Down Expand Up @@ -1307,7 +1428,114 @@ public AffinityManager AffinityManagerProcessorMask
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;
}
}
#endregion

/// <summary>
Expand Down Expand Up @@ -1337,7 +1565,6 @@ public ServerPrototypeData(CDataContainer context, Server server, ServerConfigSe
this.minMemory = new NumericServerProperty();
this.maxMemory = new NumericServerProperty();
this.NumaNodes = new List<NumaNode>();

LoadData();
}

Expand Down Expand Up @@ -1374,6 +1601,11 @@ public object Clone()
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.server = this.server;
return result;
}
Expand Down Expand Up @@ -1415,6 +1647,11 @@ private void LoadData()
GetAutoProcessorsAffinity();
this.authenticationMode = server.LoginMode;
this.loginAuditing = server.AuditLevel;
this.checkBackupChecksum = this.configService.GetServerSmoConfig(server, this.configService.BackupChecksumDefaultPropertyNumber).ConfigValue == 1;
this.checkCompressBackup = this.configService.GetServerSmoConfig(server, this.configService.BackupCompressionDefaultPropertyNumber).ConfigValue == 1;
this.dataLocation = server.Settings.DefaultFile;
this.logLocation = server.Settings.DefaultLog;
this.backupLocation = server.Settings.BackupDirectory;
}

private void LoadMemoryProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ServerConfigService
private static readonly Lazy<ServerConfigService> instance = new Lazy<ServerConfigService>(() => new ServerConfigService());
public readonly int MaxServerMemoryPropertyNumber = 1544;
public readonly int MinServerMemoryPropertyNumber = 1543;
public readonly int BackupCompressionDefaultPropertyNumber = 1579;
public readonly int BackupChecksumDefaultPropertyNumber = 1584;

/// <summary>
/// Gets the singleton instance object
Expand Down

0 comments on commit 3ba514c

Please sign in to comment.