void EnqueueAction(AsyncAction action, ProduceConsumerQueue queue, List <Exception> exceptions) { action.Completed += action_Completed; queue.EnqueueItem( () => { if (Cancelling) // don't start any more actions { return; } try { action.RunExternal(action.Session); } catch (Exception e) { Failure f = e as Failure; if (f != null && Connection != null && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { Failure.ParseRBACFailure(f, action.Connection, action.Session ?? action.Connection.Session); } exceptions.Add(e); // Record the first exception we come to. Though later if there are more than one we will replace this with non specific one. if (Exception == null) { Exception = e; } } }); }
protected override void RunSubActions(List <Exception> exceptions) { foreach (IXenConnection connection in actionsByConnection.Keys) { queuesByConnection[connection] = new ProduceConsumerQueue(Math.Min(maxNumberOfParallelActions, actionsByConnection[connection].Count)); foreach (AsyncAction subAction in actionsByConnection[connection]) { EnqueueAction(subAction, queuesByConnection[connection], exceptions); } } if (actionsWithNoConnection.Count > 0) { queueWithNoConnection = new ProduceConsumerQueue(Math.Min(maxNumberOfParallelActions, actionsWithNoConnection.Count)); } foreach (AsyncAction subAction in actionsWithNoConnection) { EnqueueAction(subAction, queueWithNoConnection, exceptions); } lock (_lock) { Monitor.Wait(_lock); } }
private void EnableAppropriateHostsNoWlb() { if (Stopped || DropDownItems.Count == 0) { return; } var firstItem = DropDownItems[0] as VMOperationToolStripMenuSubItem; if (firstItem == null) { return; } // API calls could happen in CanExecute(), 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). workerQueueWithoutWlb = new ProduceConsumerQueue(25); var selection = Command.GetSelection(); var connection = selection[0].Connection; var session = connection.DuplicateSession(); var affinityHost = connection.Resolve(((VM)selection[0].XenObject).affinity); EnqueueHostMenuItem(this, session, affinityHost, firstItem, true); var hostMenuItems = DropDownItems.OfType <VMOperationToolStripMenuSubItem>().ToList(); if (Stopped) { return; } foreach (VMOperationToolStripMenuSubItem item in hostMenuItems) { var host = item.Tag as Host; if (host != null) { var tempItem = item; EnqueueHostMenuItem(this, session, host, tempItem, false); } } }
protected override void OnDropDownOpening(EventArgs e) { base.DropDownItems.Clear(); _isDropDownClosed = false; // Work around bug in tool kit where disabled menu items show their dropdown menus if (!Enabled) { ToolStripMenuItem emptyMenuItem = new ToolStripMenuItem(Messages.HOST_MENU_EMPTY); emptyMenuItem.Font = Program.DefaultFont; emptyMenuItem.Enabled = false; base.DropDownItems.Add(emptyMenuItem); return; } VisualMenuItemAlignData.ParentStrip = this; IXenConnection connection = Command.GetSelection()[0].Connection; bool wlb = Helpers.WlbEnabled(connection); if (wlb) { base.DropDownItems.Add(new VMOperationToolStripMenuSubItem(Messages.WLB_OPT_MENU_OPTIMAL_SERVER, Images.StaticImages._000_ServerWlb_h32bit_16)); } else { base.DropDownItems.Add(new VMOperationToolStripMenuSubItem(Messages.HOME_SERVER_MENU_ITEM, Images.StaticImages._000_ServerHome_h32bit_16)); } workerQueueWithouWlb = new ProduceConsumerQueue(25); List <Host> hosts = new List <Host>(connection.Cache.Hosts); hosts.Sort(); foreach (Host host in hosts) { VMOperationToolStripMenuSubItem item = new VMOperationToolStripMenuSubItem(String.Format(Messages.MAINWINDOW_CONTEXT_UPDATING, host.name_label.EscapeAmpersands()), Images.StaticImages._000_ServerDisconnected_h32bit_16); item.Tag = host; base.DropDownItems.Add(item); } // start a new thread to evaluate which hosts can be used. ThreadPool.QueueUserWorkItem(delegate { SelectedItemCollection selection = Command.GetSelection(); Session session = selection[0].Connection.DuplicateSession(); if (Helpers.WlbEnabled(selection[0].Connection)) { WlbRecommendations recommendations = new WlbRecommendations(selection.AsXenObjects <VM>(), session); recommendations.Initialize(); if (recommendations.IsError) { EnableAppropriateHostsNoWlb(session); } else { EnableAppropriateHostsWlb(session, recommendations); } } else { EnableAppropriateHostsNoWlb(session); } }); }
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List <AsyncAction> subActions, int maxNumberOfParallelActions) : base(connection, title, startDescription, endDescription, subActions) { _queuePC = new ProduceConsumerQueue(Math.Min(maxNumberOfParallelActions, subActions.Count)); }
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List <AsyncAction> subActions) : base(connection, title, startDescription, endDescription, subActions) { _queuePC = new ProduceConsumerQueue(Math.Min(DEFAULT_MAX_NUMBER_OF_PARALLEL_ACTIONS, subActions.Count)); }
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List<AsyncAction> subActions) : base(connection, title, startDescription, endDescription, subActions) { _queuePC = new ProduceConsumerQueue(subActions.Count < numberOfSimultaneousActions ? subActions.Count : numberOfSimultaneousActions); }
void EnqueueAction(AsyncAction action, ProduceConsumerQueue queue, List<Exception> exceptions) { action.Completed += action_Completed; queue.EnqueueItem( () => { if (Cancelling) // don't start any more actions return; try { action.RunExternal(action.Session); } catch (Exception e) { Failure f = e as Failure; if (f != null && Connection != null && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { Failure.ParseRBACFailure(f, action.Connection, action.Session ?? action.Connection.Session); } exceptions.Add(e); // Record the first exception we come to. Though later if there are more than one we will replace this with non specific one. if (Exception == null) Exception = e; } }); }
protected override void RunSubActions(List<Exception> exceptions) { if (actionsCount == 0) return; foreach (IXenConnection connection in actionsByConnection.Keys) { queuesByConnection[connection] = new ProduceConsumerQueue(Math.Min(maxNumberOfParallelActions, actionsByConnection[connection].Count)); foreach (AsyncAction subAction in actionsByConnection[connection]) { EnqueueAction(subAction, queuesByConnection[connection], exceptions); } } if (actionsWithNoConnection.Count > 0) queueWithNoConnection = new ProduceConsumerQueue(Math.Min(maxNumberOfParallelActions, actionsWithNoConnection.Count)); foreach (AsyncAction subAction in actionsWithNoConnection) { EnqueueAction(subAction, queueWithNoConnection, exceptions); } lock (_lock) { Monitor.Wait(_lock); } }
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List<AsyncAction> subActions, int maxNumberOfParallelActions) : base(connection, title, startDescription, endDescription, subActions) { _queuePC = new ProduceConsumerQueue(Math.Min(maxNumberOfParallelActions, subActions.Count)); }
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List<AsyncAction> subActions) : base(connection, title, startDescription, endDescription, subActions) { _queuePC = new ProduceConsumerQueue(Math.Min(DEFAULT_MAX_NUMBER_OF_PARALLEL_ACTIONS, subActions.Count)); }
public ParallelAction(IXenConnection connection, string title, string startDescription, string endDescription, List <AsyncAction> subActions) : base(connection, title, startDescription, endDescription, subActions) { _queuePC = new ProduceConsumerQueue(subActions.Count < numberOfSimultaneousActions ? subActions.Count : numberOfSimultaneousActions); }