mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-12-23 00:46:03 +01:00
Merge pull request #916 from geosharath/VMSS
CA-198956: VM.set_snapshot_schedule throws exception "Object deleted: VMSS" in xapi
This commit is contained in:
commit
a8d52960b5
@ -72,6 +72,31 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery
|
||||
}
|
||||
|
||||
private IVMPolicy _policy;
|
||||
public void StartRefreshTab()
|
||||
{
|
||||
/* hoursFromNow has 3 possible values:
|
||||
1) 0 -> top 10 messages (default)
|
||||
2) 24 -> messages from past 24 Hrs
|
||||
3) 7 * 24 -> messages from lst 7 days */
|
||||
|
||||
var hoursFromNow = 0;
|
||||
switch (comboBox1.SelectedIndex)
|
||||
{
|
||||
case 0: /* default value*/
|
||||
break;
|
||||
case 1:
|
||||
hoursFromNow = 24;
|
||||
break;
|
||||
case 2:
|
||||
hoursFromNow = 7 * 24;
|
||||
break;
|
||||
}
|
||||
|
||||
PureAsyncAction action = _policy.getAlertsAction(_policy, hoursFromNow);
|
||||
action.Completed += action_Completed;
|
||||
action.RunAsync();
|
||||
}
|
||||
|
||||
public void RefreshTab(IVMPolicy policy)
|
||||
{
|
||||
_policy = policy;
|
||||
@ -83,7 +108,7 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery
|
||||
else
|
||||
{
|
||||
comboBox1.Enabled = true;
|
||||
RefreshGrid(_policy.PolicyAlerts);
|
||||
StartRefreshTab();
|
||||
}
|
||||
|
||||
}
|
||||
@ -168,24 +193,7 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery
|
||||
{
|
||||
if (_policy != null)
|
||||
{
|
||||
if (comboBox1.SelectedIndex == 0)
|
||||
RefreshGrid(_policy.PolicyAlerts);
|
||||
else if (comboBox1.SelectedIndex == 1)
|
||||
{
|
||||
dataGridView1.Rows.Clear();
|
||||
panelLoading.Visible = true;
|
||||
PureAsyncAction action = _policy.getAlertsAction(_policy, 24) ;
|
||||
action.Completed += action_Completed;
|
||||
action.RunAsync();
|
||||
}
|
||||
else if (comboBox1.SelectedIndex == 2)
|
||||
{
|
||||
dataGridView1.Rows.Clear();
|
||||
panelLoading.Visible = true;
|
||||
PureAsyncAction action = _policy.getAlertsAction(_policy, 7 * 24);
|
||||
action.Completed += action_Completed;
|
||||
action.RunAsync();
|
||||
}
|
||||
StartRefreshTab();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ using XenAdmin.Core;
|
||||
using XenAdmin.Dialogs.VMProtectionRecovery;
|
||||
using XenCenterLib;
|
||||
using XenAdmin.Alerts;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace XenAdmin.Dialogs.VMProtection_Recovery
|
||||
{
|
||||
@ -201,43 +201,57 @@ namespace XenAdmin.Dialogs.VMPolicies
|
||||
dataGridView1.SuspendLayout();
|
||||
var selectedPolicy = currentSelected;
|
||||
dataGridView1.Rows.Clear();
|
||||
var policyList = VMGroup<T>.VMPolicies(Pool.Connection.Cache);
|
||||
|
||||
/* creating a dictionary to hold (policy_uuid, message list) */
|
||||
|
||||
Dictionary<string, List<XenAPI.Message>> policyMessage = new Dictionary<string, List<XenAPI.Message>>();
|
||||
|
||||
/* populate the dictionary with policy uuid */
|
||||
|
||||
foreach (var policy in policyList)
|
||||
{
|
||||
policy.PolicyAlerts.Clear();
|
||||
List<XenAPI.Message> messageList = new List<XenAPI.Message>();
|
||||
policyMessage.Add(policy.uuid, messageList);
|
||||
}
|
||||
|
||||
/* iterate through all messages and populate the dictionary with message list */
|
||||
|
||||
/* filter out the messages for VMSS as the VMSS does not have recent alerts and that need to be populated below*/
|
||||
List<XenAPI.Message> vmssMessages = new List<XenAPI.Message>();
|
||||
if (!VMGroup<T>.isVMPolicyVMPP)
|
||||
{
|
||||
var messages = Pool.Connection.Cache.Messages;
|
||||
List<XenAPI.Message> value = new List<XenAPI.Message>();
|
||||
|
||||
foreach (var message in messages)
|
||||
{
|
||||
if (message.cls == cls.VMSS)
|
||||
{
|
||||
vmssMessages.Add(message);
|
||||
if (policyMessage.TryGetValue(message.obj_uuid, out value))
|
||||
{
|
||||
value.Add(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var policy in VMGroup<T>.VMPolicies(Pool.Connection.Cache))
|
||||
{
|
||||
if (!VMGroup<T>.isVMPolicyVMPP)
|
||||
{
|
||||
policy.PolicyAlerts.Clear();
|
||||
List<XenAPI.Message> processedMessages = new List<XenAPI.Message>();
|
||||
/*for VMSS: Populate the alerts from Messages by filtering out the alerts for this schedule
|
||||
This is not required in VMPP as the VMPP record itself has the recentAlerts */
|
||||
foreach (var message in vmssMessages)
|
||||
{
|
||||
if (message.obj_uuid == policy.uuid)
|
||||
{
|
||||
policy.PolicyAlerts.Add(new PolicyAlert(message.priority, message.name, message.timestamp));
|
||||
processedMessages.Add(message);
|
||||
}
|
||||
}
|
||||
vmssMessages.RemoveAll(message => processedMessages.Contains(message));
|
||||
}
|
||||
|
||||
/* add only 10 messages for each policy and referesh the rows*/
|
||||
|
||||
foreach (var policy in policyList)
|
||||
{
|
||||
/* message list need not be always sorted */
|
||||
|
||||
var messageListSorted = policyMessage[policy.uuid].OrderByDescending(message => message.timestamp).ToList();
|
||||
for (int messageCount = 0; messageCount < 10 && messageCount < messageListSorted.Count; messageCount++)
|
||||
{
|
||||
policy.PolicyAlerts.Add(new PolicyAlert(messageListSorted[messageCount].priority, messageListSorted[messageCount].name, messageListSorted[messageCount].timestamp));
|
||||
}
|
||||
if (dataGridView1.ColumnCount > 0)
|
||||
dataGridView1.Rows.Add(new PolicyRow(policy));
|
||||
}
|
||||
RefreshButtons();
|
||||
|
||||
RefreshButtons();
|
||||
if (selectedPolicy != null)
|
||||
{
|
||||
foreach (PolicyRow row in dataGridView1.Rows)
|
||||
|
@ -35,6 +35,7 @@ using System.Text;
|
||||
using XenAdmin.Alerts;
|
||||
using XenAPI;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace XenAdmin.Actions
|
||||
{
|
||||
@ -52,18 +53,45 @@ namespace XenAdmin.Actions
|
||||
protected override void Run()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var messages = Pool.Connection.Cache.Messages;
|
||||
var messages = Pool.Connection.Cache.Messages.OrderByDescending(message => message.timestamp).ToList();
|
||||
var listAlerts = new List<PolicyAlert>();
|
||||
DateTime currentTime = DateTime.Now;
|
||||
DateTime offset = currentTime.Add(new TimeSpan(- _hoursFromNow, 0, 0));
|
||||
|
||||
/* _hoursFromNow has 3 possible values:
|
||||
1) 0 -> top 10 messages
|
||||
2) 24 -> messages from past 24 Hrs
|
||||
3) 7 * 24 -> messages from lst 7 days */
|
||||
|
||||
/*for VMSS: Populate the alerts from Messages by filtering out the alerts for this schedule
|
||||
This is not required in VMPP as the VMPP record itself has the recentAlerts */
|
||||
foreach (var message in messages)
|
||||
if (_hoursFromNow == 0)
|
||||
{
|
||||
if (message.cls == cls.VMSS && message.obj_uuid == VMSS.uuid)
|
||||
int messageCounter = 0;
|
||||
foreach (var message in messages)
|
||||
{
|
||||
listAlerts.Add(new PolicyAlert(message.priority, message.name, message.timestamp));
|
||||
if (message.cls == cls.VMSS && message.obj_uuid == VMSS.uuid && messageCounter < 10)
|
||||
{
|
||||
listAlerts.Add(new PolicyAlert(message.priority, message.name, message.timestamp));
|
||||
messageCounter++;
|
||||
}
|
||||
else if (messageCounter >= 10)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var message in messages)
|
||||
{
|
||||
if (message.cls == cls.VMSS && message.obj_uuid == VMSS.uuid && message.timestamp > offset)
|
||||
{
|
||||
listAlerts.Add(new PolicyAlert(message.priority, message.name, message.timestamp));
|
||||
}
|
||||
|
||||
/* since the messages are sorted on timestamp you need not scan the entire message list */
|
||||
|
||||
else if (message.timestamp < offset)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VMSS.Alerts = new List<PolicyAlert>(listAlerts);
|
||||
Debug.WriteLine(string.Format("GetAlerts took: {0}", DateTime.Now - now));
|
||||
|
@ -306,11 +306,6 @@ namespace XenAPI
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var recent in _alerts)
|
||||
{
|
||||
if (!_alerts.Contains(recent))
|
||||
_alerts.Add(recent);
|
||||
}
|
||||
return _alerts;
|
||||
}
|
||||
set { _alerts = value; }
|
||||
|
Loading…
Reference in New Issue
Block a user