CP-36392: Move vms null and Count checks outside of WlbRecommendations.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

damni

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-11-15 09:51:38 +00:00
parent 396bcb0e35
commit 1acce3638c
No known key found for this signature in database
GPG Key ID: 0C48542619080FD4
2 changed files with 11 additions and 12 deletions

View File

@ -33,12 +33,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using XenAdmin.Controls;
using XenAPI;
using XenAdmin.Core;
using XenAdmin.Actions;
using XenAdmin.Actions.Wlb;
using XenAdmin.Controls;
using XenAdmin.Core;
using XenAdmin.Network;
using XenAPI;
namespace XenAdmin.Commands
@ -112,7 +111,7 @@ namespace XenAdmin.Commands
// Adds the migrate wizard button, do this before the enable checks on the other items
AddAdditionalMenuItems(selection);
UpdateHostList();
}
@ -163,6 +162,9 @@ namespace XenAdmin.Commands
if (Helpers.WlbEnabled(connection))
{
var vms = selection.AsXenObjects<VM>();
if (vms == null || vms.Count == 0)
return;
var retrieveVmRecommendationsAction = new WlbRetrieveVmRecommendationsAction(connection, vms);
retrieveVmRecommendationsAction.Completed += delegate
{
@ -243,7 +245,7 @@ namespace XenAdmin.Commands
var firstItem = DropDownItems[0] as VMOperationToolStripMenuSubItem;
if (firstItem == null)
return;
// API calls could happen in CanRun(), which take time to wait. So a Producer-Consumer-Queue with size 25 is used here to :
// 1. Make API calls for different menu items happen in parallel;
// 2. Limit the count of concurrent threads (now it's 25).
@ -253,7 +255,7 @@ namespace XenAdmin.Commands
var connection = selection[0].Connection;
var session = connection.DuplicateSession();
var affinityHost = connection.Resolve(((VM) selection[0].XenObject).affinity);
var affinityHost = connection.Resolve(((VM)selection[0].XenObject).affinity);
EnqueueHostMenuItem(this, session, affinityHost, firstItem, true);
@ -278,7 +280,7 @@ namespace XenAdmin.Commands
workerQueueWithoutWlb.EnqueueItem(() =>
{
var selection = menu.Command.GetSelection();
var cmd = isHomeServer
var cmd = isHomeServer
? new VMOperationHomeServerCommand(menu.Command.MainWindowCommandInterface, selection, menu._operation, session)
: new VMOperationHostCommand(menu.Command.MainWindowCommandInterface, selection, delegate { return host; }, host.Name().EscapeAmpersands(), menu._operation, session);
@ -320,7 +322,7 @@ namespace XenAdmin.Commands
}
});
}
#endregion
/// <summary>

View File

@ -54,9 +54,6 @@ namespace XenAdmin.Commands
/// <param name="recommendations"></param>
public WlbRecommendations(List<VM> vms, Dictionary<VM, Dictionary<XenRef<Host>, string[]>> recommendations)
{
if (vms == null || vms.Count == 0)
throw new ArgumentException("Parameter cannot be null or empty", nameof(vms));
_vms = new ReadOnlyCollection<VM>(vms);
_recommendations = recommendations;
_isError = recommendations == null;