CA-189084: Control domain memory alerts not getting generated in Xencenter.

Dom0 memory alerts have to be configured in the other_config of the control domain (dom0) and not of the the host. This changeset implements this exception.

Signed-off-by: Gabor Apati-Nagy <gabor.apati-nagy@citrix.com>
This commit is contained in:
Gabor Apati-Nagy 2015-12-07 17:57:54 +00:00
parent 45dfd11dd1
commit 4baa36efab
3 changed files with 99 additions and 5 deletions

View File

@ -50,6 +50,8 @@ namespace XenAdmin.SettingsPanels
{
public partial class PerfmonAlertEditPage : UserControl, IEditPage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private IXenObject _XenObject;
private readonly ToolTip m_invalidParamToolTip;
@ -242,6 +244,7 @@ namespace XenAdmin.SettingsPanels
{
if (_XenObject == null)
return;
try
{
var perfmonDefinitions = PerfmonDefinition.GetPerfmonDefinitions(_XenObject);
@ -260,13 +263,40 @@ namespace XenAdmin.SettingsPanels
memoryAlert.Populate(perfmonDefinition);
else if (perfmonDefinition.IsSrUsage)
srAlert.Populate(perfmonDefinition);
else if (perfmonDefinition.IsDom0MemoryUsage)
dom0MemoryAlert.Populate(perfmonDefinition);
else if (perfmonDefinition.IsSrPhysicalUtilisation)
physicalUtilisationAlert.Populate(perfmonDefinition);
}
}
catch { }
// Dom0 memory usage is stored in the other_config of the Dom0 vm not on the host (or any other XenObject)
try
{
if (_XenObject is Host)
{
var controlDomain = (_XenObject as Host).ControlDomain;
if (controlDomain != null)
{
var controlDomainPerfmonDefinitions = PerfmonDefinition.GetPerfmonDefinitions(controlDomain);
if (controlDomainPerfmonDefinitions != null)
{
for (int ii = 0; ii < controlDomainPerfmonDefinitions.Length; ii++)
{
var def = controlDomainPerfmonDefinitions[ii];
if (def != null && def.IsDom0MemoryUsage)
dom0MemoryAlert.Populate(def);
}
}
}
}
}
catch (Exception ex)
{
log.Error("Unexpected error during populating controls for Dom0 Memory Usage alert. Leaving it as is.", ex);
}
}
public bool HasChanged
@ -436,9 +466,13 @@ namespace XenAdmin.SettingsPanels
{
Debug.Assert(XapiToGuiTriggerLevel != null && XapiToGuiTriggerPeriod != null && XapiToGuiAlertInterval != null);
m_checkBox.Checked = true;
m_upDownTriggerLevel.Value = XapiToGuiTriggerLevel(perfmon.AlarmTriggerLevel);
m_upDownTriggerPeriod.Value = XapiToGuiTriggerPeriod(perfmon.AlarmTriggerPeriod);
if (perfmon.HasValueSet)
{
m_checkBox.Checked = true;
m_upDownTriggerLevel.Value = XapiToGuiTriggerLevel(perfmon.AlarmTriggerLevel);
m_upDownTriggerPeriod.Value = XapiToGuiTriggerPeriod(perfmon.AlarmTriggerPeriod);
}
try
{
m_upDownAlertInterval.Value = XapiToGuiAlertInterval(perfmon.AlarmAutoInhibitPeriod);

View File

@ -36,6 +36,7 @@ using XenAPI;
using XenAdmin.Alerts;
using XenAdmin.Core;
using XenAdmin.Model;
using System.Linq;
namespace XenAdmin.Actions
@ -64,6 +65,59 @@ namespace XenAdmin.Actions
if (xo == null)
return;
// Dom0 Memory usage alert is an exception. While configuration for all the alerts (eg. related to the Host) have to be saved to this "xo",
// dom0 Memory usage's has to be in the Dom0's other config.
//
var dom0_memory_usage = perfmonDefinitions.FirstOrDefault(d => d.IsDom0MemoryUsage);
if (dom0_memory_usage != null)
{
perfmonDefinitions.Remove(dom0_memory_usage);
var dom0Vm = xo.Connection.Cache.VMs.FirstOrDefault(vm => vm.is_control_domain);
if (dom0Vm != null)
{
var dom0PerfmonDefinitions = PerfmonDefinition.GetPerfmonDefinitions(dom0Vm).ToList();
bool found = false;
for (int ii = 0; ii < dom0PerfmonDefinitions.Count; ii++)
{
var pmd = dom0PerfmonDefinitions[ii];
if (pmd != null && pmd.IsDom0MemoryUsage)
{
dom0PerfmonDefinitions[ii] = dom0_memory_usage;
found = true;
break;
}
}
if (!found)
{
dom0PerfmonDefinitions.Add(dom0_memory_usage);
}
string dom0PerfmonConfigXML = PerfmonDefinition.GetPerfmonDefinitionXML(dom0PerfmonDefinitions);
Helpers.SetOtherConfig(Session, dom0Vm, PerfmonDefinition.PERFMON_KEY_NAME, dom0PerfmonConfigXML);
}
}
else
{
var dom0Vm = xo.Connection.Cache.VMs.FirstOrDefault(vm => vm.is_control_domain);
if (dom0Vm != null)
{
var dom0PerfmonDefinitions = PerfmonDefinition.GetPerfmonDefinitions(dom0Vm).ToList();
int found = dom0PerfmonDefinitions.RemoveAll(d => d.IsDom0MemoryUsage);
if (found > 0)
{
string dom0PerfmonDefinitionsXml = PerfmonDefinition.GetPerfmonDefinitionXML(dom0PerfmonDefinitions);
Helpers.SetOtherConfig(Session, dom0Vm, PerfmonDefinition.PERFMON_KEY_NAME, dom0PerfmonDefinitionsXml);
}
}
}
if (dom0_memory_usage != null && perfmonDefinitions.Contains(dom0_memory_usage))
perfmonDefinitions.Remove(dom0_memory_usage);
if (perfmonDefinitions == null || perfmonDefinitions.Count == 0)
{
Helpers.RemoveFromOtherConfig(Session, xo, PerfmonDefinition.PERFMON_KEY_NAME);

View File

@ -82,12 +82,15 @@ namespace XenAdmin.Alerts
private readonly decimal alarmTriggerPeriod;
private readonly decimal alarmAutoInhibitPeriod;
public bool HasValueSet { private set; get; }
public PerfmonDefinition(string name, decimal alarmTriggerLevel, decimal alarmTriggerPeriod, decimal alarmAutoInhibitPeriod)
{
this.name = name;
this.alarmTriggerLevel = alarmTriggerLevel;
this.alarmTriggerPeriod = alarmTriggerPeriod;
this.alarmAutoInhibitPeriod = alarmAutoInhibitPeriod;
HasValueSet = true;
}
public bool IsCPUUsage
@ -184,6 +187,7 @@ namespace XenAdmin.Alerts
NumberStyles.Any,
CultureInfo.InvariantCulture,
out alarmTriggerLevel);
HasValueSet = HasValueSet || success;
}
else if (node.Name.Equals(ALARM_TRIGGER_PERIOD_ELEMENT_NAME))
{
@ -192,6 +196,7 @@ namespace XenAdmin.Alerts
NumberStyles.Any,
CultureInfo.InvariantCulture,
out alarmTriggerPeriod);
HasValueSet = HasValueSet || success;
}
else if (node.Name.Equals(ALARM_AUTO_INHIBIT_PERIOD_ELEMENT_NAME))
{
@ -200,6 +205,7 @@ namespace XenAdmin.Alerts
NumberStyles.Any,
CultureInfo.InvariantCulture,
out alarmAutoInhibitPeriod);
HasValueSet = HasValueSet || success;
}
if (!success)