From ba0a060e061f9bc805db0b3b81c6fbe20e4d3ebb Mon Sep 17 00:00:00 2001 From: Sharath Babu Date: Tue, 29 Mar 2016 04:32:56 +0000 Subject: [PATCH 1/6] CA-198956: VM.set_snapshot_schedule throws exception "Object deleted:VMSS" in xapi XAPI expects "OpaqueRef:NULL" in the value field to unassign a VM from a particular policy, however XC is sending an empty string "". As a fix the empty string is replaced with Helper.NullOpaqueRef. Signed-off-by: Sharath Babu --- XenModel/XenAPI/VM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XenModel/XenAPI/VM.cs b/XenModel/XenAPI/VM.cs index cd8adb10d..0d1afded9 100644 --- a/XenModel/XenAPI/VM.cs +++ b/XenModel/XenAPI/VM.cs @@ -3590,7 +3590,7 @@ namespace XenAPI /// The value public static void set_snapshot_schedule(Session session, string _vm, string _value) { - session.proxy.vm_set_snapshot_schedule(session.uuid, (_vm != null) ? _vm : "", (_value != null) ? _value : "").parse(); + session.proxy.vm_set_snapshot_schedule(session.uuid, (_vm != null) ? _vm : "", (_value != null) ? _value : Helper.NullOpaqueRef).parse(); } /// From 74c6242d560ea738d44c25685a965d4e2d98e728 Mon Sep 17 00:00:00 2001 From: Sharath Babu Date: Tue, 29 Mar 2016 05:54:53 +0000 Subject: [PATCH 2/6] CP-16192: [Performance] xapi vmss object should have recentAlerts, like vmpp Significant improvements has been done in "schedule snapshot" policy wizard for loading messages, hence we do not require recentAlerts field. Signed-off-by: Sharath Babu --- .../VMProtectionPoliciesDialog.cs | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs b/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs index 3d9c067f6..6ebd5ba19 100644 --- a/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs +++ b/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs @@ -201,43 +201,54 @@ namespace XenAdmin.Dialogs.VMPolicies dataGridView1.SuspendLayout(); var selectedPolicy = currentSelected; dataGridView1.Rows.Clear(); + var policyList = VMGroup.VMPolicies(Pool.Connection.Cache); + + /* creating a dictionary to hold (policy_uuid, message list) */ + + Dictionary> policyMessage = new Dictionary>(); + + /* populate the dictionary with policy uuid */ + + foreach (var policy in policyList) + { + policy.PolicyAlerts.Clear(); + List messageList = new List(); + 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 vmssMessages = new List(); if (!VMGroup.isVMPolicyVMPP) { var messages = Pool.Connection.Cache.Messages; + List value = new List(); + foreach (var message in messages) { if (message.cls == cls.VMSS) { - vmssMessages.Add(message); - } - } - } - foreach (var policy in VMGroup.VMPolicies(Pool.Connection.Cache)) - { - if (!VMGroup.isVMPolicyVMPP) - { - policy.PolicyAlerts.Clear(); - List processedMessages = new List(); - /*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) + if (policyMessage.TryGetValue(message.obj_uuid, out value)) { - policy.PolicyAlerts.Add(new PolicyAlert(message.priority, message.name, message.timestamp)); - processedMessages.Add(message); + value.Add(message); } - } - vmssMessages.RemoveAll(message => processedMessages.Contains(message)); - } - if (dataGridView1.ColumnCount > 0) - dataGridView1.Rows.Add(new PolicyRow(policy)); + } + } } - RefreshButtons(); + + /* add only 10 messages for each policy and referesh the rows*/ + + foreach (var policy in policyList) + { + for (int messageCount = 0; messageCount < 10 && messageCount < policyMessage[policy.uuid].Count; messageCount++) + { + policy.PolicyAlerts.Add(new PolicyAlert(policyMessage[policy.uuid][messageCount].priority, policyMessage[policy.uuid][messageCount].name, policyMessage[policy.uuid][messageCount].timestamp)); + } + if (dataGridView1.ColumnCount > 0) + dataGridView1.Rows.Add(new PolicyRow(policy)); + } + + RefreshButtons(); if (selectedPolicy != null) { foreach (PolicyRow row in dataGridView1.Rows) From 026b19c3fadf352a19305d3264f5552939a3a93e Mon Sep 17 00:00:00 2001 From: Sharath Babu Date: Tue, 29 Mar 2016 07:19:07 +0000 Subject: [PATCH 3/6] CAR-2146: Improved policy wizard loading time Removing redundant code to improve performance as suggested by Miheala. Signed-off-by: Sharath Babu --- XenModel/XenAPI-Extensions/VMSS.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/XenModel/XenAPI-Extensions/VMSS.cs b/XenModel/XenAPI-Extensions/VMSS.cs index 1ada6b1c2..0d37cdfef 100644 --- a/XenModel/XenAPI-Extensions/VMSS.cs +++ b/XenModel/XenAPI-Extensions/VMSS.cs @@ -306,11 +306,6 @@ namespace XenAPI { get { - foreach (var recent in _alerts) - { - if (!_alerts.Contains(recent)) - _alerts.Add(recent); - } return _alerts; } set { _alerts = value; } From 81563c65b89345549257210d6972c0199b426b8f Mon Sep 17 00:00:00 2001 From: Sharath Babu Date: Tue, 29 Mar 2016 07:52:48 +0000 Subject: [PATCH 4/6] CA-204328: VMSS policy wizard not filtering out messages accordingly Added filter functionality for filtering messages in policy wizard. Signed-off-by: Sharath Babu --- .../VMProtectionRecovery/PolicyHistory.cs | 8 ++++- XenModel/Actions/VMSS/GetVMSSAlertsAction.cs | 34 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs b/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs index 5a0aa0eb4..547fe7376 100644 --- a/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs +++ b/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs @@ -169,7 +169,13 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery if (_policy != null) { if (comboBox1.SelectedIndex == 0) - RefreshGrid(_policy.PolicyAlerts); + { + dataGridView1.Rows.Clear(); + panelLoading.Visible = true; + PureAsyncAction action = _policy.getAlertsAction(_policy, 0) ; + action.Completed += action_Completed; + action.RunAsync(); + } else if (comboBox1.SelectedIndex == 1) { dataGridView1.Rows.Clear(); diff --git a/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs b/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs index fafb29e83..1c3625848 100644 --- a/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs +++ b/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs @@ -54,16 +54,38 @@ namespace XenAdmin.Actions var now = DateTime.Now; var messages = Pool.Connection.Cache.Messages; var listAlerts = new List(); + 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)); + } + } + } VMSS.Alerts = new List(listAlerts); Debug.WriteLine(string.Format("GetAlerts took: {0}", DateTime.Now - now)); From 18289192b7b6050e41dc7551d20b3d4dc2318365 Mon Sep 17 00:00:00 2001 From: Sharath Babu Date: Wed, 6 Apr 2016 04:08:11 +0000 Subject: [PATCH 5/6] Incorporating review comments. Signed-off-by: Sharath Babu --- .../VMProtectionRecovery/PolicyHistory.cs | 60 ++++++++++++------- .../VMProtectionPoliciesDialog.cs | 15 +++-- XenModel/Actions/VMSS/GetVMSSAlertsAction.cs | 8 ++- XenModel/XenAPI/VM.cs | 2 +- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs b/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs index 547fe7376..9373e5f48 100644 --- a/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs +++ b/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs @@ -83,6 +83,22 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery else { comboBox1.Enabled = true; + int 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(); RefreshGrid(_policy.PolicyAlerts); } @@ -168,30 +184,30 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery { if (_policy != null) { - if (comboBox1.SelectedIndex == 0) - { - dataGridView1.Rows.Clear(); - panelLoading.Visible = true; - PureAsyncAction action = _policy.getAlertsAction(_policy, 0) ; - action.Completed += action_Completed; - action.RunAsync(); - } - else if (comboBox1.SelectedIndex == 1) + /* 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 */ + + int hoursFromNow = 0 ; + + switch (comboBox1.SelectedIndex) { - 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(); + case 0: /* default value*/ + break; + case 1: + hoursFromNow = 24; + break; + case 2: + hoursFromNow = 7 * 24; + break; } + + dataGridView1.Rows.Clear(); + panelLoading.Visible = true; + PureAsyncAction action = _policy.getAlertsAction(_policy, hoursFromNow); + action.Completed += action_Completed; + action.RunAsync(); } } diff --git a/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs b/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs index 6ebd5ba19..ec1a46fd1 100644 --- a/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs +++ b/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs @@ -44,7 +44,7 @@ using XenAdmin.Core; using XenAdmin.Dialogs.VMProtectionRecovery; using XenCenterLib; using XenAdmin.Alerts; - +using System.Linq; namespace XenAdmin.Dialogs.VMProtection_Recovery { @@ -237,15 +237,18 @@ namespace XenAdmin.Dialogs.VMPolicies } /* add only 10 messages for each policy and referesh the rows*/ - + foreach (var policy in policyList) { - for (int messageCount = 0; messageCount < 10 && messageCount < policyMessage[policy.uuid].Count; messageCount++) + /* 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(policyMessage[policy.uuid][messageCount].priority, policyMessage[policy.uuid][messageCount].name, policyMessage[policy.uuid][messageCount].timestamp)); + policy.PolicyAlerts.Add(new PolicyAlert(messageListSorted[messageCount].priority, messageListSorted[messageCount].name, messageListSorted[messageCount].timestamp)); } - if (dataGridView1.ColumnCount > 0) - dataGridView1.Rows.Add(new PolicyRow(policy)); + if (dataGridView1.ColumnCount > 0) + dataGridView1.Rows.Add(new PolicyRow(policy)); } RefreshButtons(); diff --git a/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs b/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs index 1c3625848..4daedbac5 100644 --- a/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs +++ b/XenModel/Actions/VMSS/GetVMSSAlertsAction.cs @@ -35,6 +35,7 @@ using System.Text; using XenAdmin.Alerts; using XenAPI; using System.Diagnostics; +using System.Linq; namespace XenAdmin.Actions { @@ -52,7 +53,7 @@ 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(); DateTime currentTime = DateTime.Now; DateTime offset = currentTime.Add(new TimeSpan(- _hoursFromNow, 0, 0)); @@ -84,6 +85,11 @@ namespace XenAdmin.Actions { 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; } } diff --git a/XenModel/XenAPI/VM.cs b/XenModel/XenAPI/VM.cs index 0d1afded9..cd8adb10d 100644 --- a/XenModel/XenAPI/VM.cs +++ b/XenModel/XenAPI/VM.cs @@ -3590,7 +3590,7 @@ namespace XenAPI /// The value public static void set_snapshot_schedule(Session session, string _vm, string _value) { - session.proxy.vm_set_snapshot_schedule(session.uuid, (_vm != null) ? _vm : "", (_value != null) ? _value : Helper.NullOpaqueRef).parse(); + session.proxy.vm_set_snapshot_schedule(session.uuid, (_vm != null) ? _vm : "", (_value != null) ? _value : "").parse(); } /// From 07128eb9b46b3e9e5d3d27abab2681cd191bfe11 Mon Sep 17 00:00:00 2001 From: Sharath Babu Date: Thu, 7 Apr 2016 03:20:14 +0000 Subject: [PATCH 6/6] Incorporating review comments. Signed-off-by: Sharath Babu --- .../VMProtectionRecovery/PolicyHistory.cs | 68 ++++++++----------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs b/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs index 9373e5f48..fefdd2cf7 100644 --- a/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs +++ b/XenAdmin/Dialogs/VMProtectionRecovery/PolicyHistory.cs @@ -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,23 +108,7 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery else { comboBox1.Enabled = true; - int 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(); - RefreshGrid(_policy.PolicyAlerts); + StartRefreshTab(); } } @@ -184,30 +193,7 @@ namespace XenAdmin.Dialogs.VMProtectionRecovery { if (_policy != null) { - /* 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 */ - - int hoursFromNow = 0 ; - - switch (comboBox1.SelectedIndex) - { - case 0: /* default value*/ - break; - case 1: - hoursFromNow = 24; - break; - case 2: - hoursFromNow = 7 * 24; - break; - } - - dataGridView1.Rows.Clear(); - panelLoading.Visible = true; - PureAsyncAction action = _policy.getAlertsAction(_policy, hoursFromNow); - action.Completed += action_Completed; - action.RunAsync(); + StartRefreshTab(); } }