예제 #1
0
 private static void AddBottomSpacing(CustomListRow header)
 {
     if (header.Children.Count != 0)
     {
         header.AddChild(new CustomListRow(header.BackColor, 5));
     }
 }
예제 #2
0
        private static CustomListRow AddRow <T>(CustomListRow parent, string key, T obj, ToStringDelegate <T> del, bool valueBold) where T : IEquatable <T>
        {
            CustomListRow newChild = CreateNewRow(key + ": ", new ToStringWrapper <T>(obj, del), valueBold);

            parent.AddChild(newChild);
            return(newChild);
        }
예제 #3
0
        private CustomListRow AddRow(CustomListRow parent, string key, string value, bool valueBold)
        {
            CustomListRow row = CreateNewRow(key + ": ", value, valueBold);

            parent.AddChild(row);
            return(row);
        }
예제 #4
0
        private void generatePoolHABox(Pool pool)
        {
            Host master = Helpers.GetMaster(pool.Connection);

            if (master == null || master.RestrictHAOrlando)
            {
                // Don't generate the box at all
                return;
            }

            if (!pool.ha_enabled)
            {
                return;
            }

            // 'High Availability' heading
            CustomListRow header = CreateHeader(Messages.HA_CONFIGURATION_TITLE);

            customListPanel.AddRow(header);
            AddRow(header, GetFriendlyName("pool.ha_enabled"), pool, getPoolHAStatus, false);
            {
                // ntol row. May be red and bold.
                bool redBold = pool.ha_host_failures_to_tolerate == 0;

                CustomListRow newChild = CreateNewRow(Messages.HA_CONFIGURED_CAPACITY, new ToStringWrapper <Pool>(pool, getNtol), redBold);
                header.AddChild(newChild);

                if (redBold)
                {
                    newChild.Items[1].ForeColor = Color.Red;
                    ToolStripMenuItem editHa = new ToolStripMenuItem(Messages.CONFIGURE_HA_ELLIPSIS);
                    editHa.Click += delegate { EditHA(pool); };
                    newChild.MenuItems.Add(editHa);
                    newChild.DefaultMenuItem = editHa;
                }
                else
                {
                    newChild.Items[1].ForeColor = BaseTabPage.ItemValueForeColor;
                }
            }

            {
                // plan_exists_for row needs some special work: the text may be red and bold
                bool          redBold  = haStatusRed(pool);
                CustomListRow newChild = CreateNewRow(Messages.HA_CURRENT_CAPACITY, new ToStringWrapper <Pool>(pool, getPlanExistsFor), redBold);
                header.AddChild(newChild);

                if (redBold)
                {
                    newChild.Items[1].ForeColor = Color.Red;
                    ToolStripMenuItem editHa = new ToolStripMenuItem(Messages.CONFIGURE_HA_ELLIPSIS);
                    editHa.Click += delegate { EditHA(pool); };
                    newChild.MenuItems.Add(editHa);
                    newChild.DefaultMenuItem = editHa;
                }
                else
                {
                    newChild.Items[1].ForeColor = BaseTabPage.ItemValueForeColor;
                }
            }
            AddBottomSpacing(header);

            // 'Heartbeating status' heading
            header = CreateHeader(Messages.HEARTBEATING_STATUS);
            customListPanel.AddRow(header);

            // Now build the heartbeat target health table

            List <SR> heartbeatSRs = pool.GetHAHeartbeatSRs();

            // Sort heartbeat SRs using NaturalCompare
            heartbeatSRs.Sort((Comparison <SR>) delegate(SR a, SR b)
            {
                return(StringUtility.NaturalCompare(a.Name, b.Name));
            });

            List <Host> members = new List <Host>(pool.Connection.Cache.Hosts);

            // Sort pool members using NaturalCompare
            members.Sort((Comparison <Host>) delegate(Host a, Host b)
            {
                return(StringUtility.NaturalCompare(a.Name, b.Name));
            });
            int numCols = 1 + 2 + (2 * heartbeatSRs.Count); // Hostnames col, then 2 each for each HB target (network + SRs)
            int numRows = 1 + members.Count;

            // Create rows and cols
            tableLatencies.SuspendLayout();
            tableLatencies.ColumnCount = numCols;
            tableLatencies.ColumnStyles.Clear();
            for (int i = 0; i < numCols; i++)
            {
                tableLatencies.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            }
            tableLatencies.RowCount = numRows;
            tableLatencies.RowStyles.Clear();
            for (int i = 0; i < numRows; i++)
            {
                tableLatencies.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            }

            {
                // Network icon
                PictureBox p = new PictureBox();
                p.Image    = Images.GetImage16For(Icons.Network);
                p.SizeMode = PictureBoxSizeMode.AutoSize;
                p.Padding  = new Padding(0);
                tableLatencies.Controls.Add(p);
                tableLatencies.SetCellPosition(p, new TableLayoutPanelCellPosition(1, 0));
                // Network text
                Label l = new Label();
                l.Padding   = new Padding(0, 5, 5, 5);
                l.Font      = BaseTabPage.ItemLabelFont;
                l.ForeColor = BaseTabPage.ItemLabelForeColor;
                l.AutoSize  = true;
                l.Text      = Messages.NETWORK;
                tableLatencies.Controls.Add(l);
                tableLatencies.SetCellPosition(l, new TableLayoutPanelCellPosition(2, 0));
            }

            for (int i = 0; i < heartbeatSRs.Count; i++)
            {
                // SR icon
                PictureBox p = new PictureBox();
                p.Image    = Images.GetImage16For(heartbeatSRs[i].GetIcon);
                p.SizeMode = PictureBoxSizeMode.AutoSize;
                p.Padding  = new Padding(0);
                tableLatencies.Controls.Add(p);
                tableLatencies.SetCellPosition(p, new TableLayoutPanelCellPosition((2 * i) + 3, 0));
                // SR name
                Label l = new Label();
                l.Padding      = new Padding(0, 5, 5, 5);
                l.Font         = BaseTabPage.ItemLabelFont;
                l.ForeColor    = BaseTabPage.ItemLabelForeColor;
                l.AutoSize     = false;
                l.Size         = new Size(200, 25);
                l.AutoEllipsis = true;
                l.Text         = heartbeatSRs[i].Name;
                tableLatencies.Controls.Add(l);
                tableLatencies.SetCellPosition(l, new TableLayoutPanelCellPosition((2 * i) + 4, 0));
            }

            for (int i = 0; i < members.Count; i++)
            {
                // Server name label
                Label l = new Label();
                l.Padding   = new Padding(5);
                l.Font      = BaseTabPage.ItemLabelFont;
                l.ForeColor = BaseTabPage.ItemLabelForeColor;
                l.AutoSize  = true;
                l.Text      = members[i].Name.Ellipsise(30);
                tableLatencies.Controls.Add(l);
                tableLatencies.SetCellPosition(l, new TableLayoutPanelCellPosition(0, i + 1));

                // Network HB status
                l          = new Label();
                l.Padding  = new Padding(0, 5, 0, 5);
                l.Font     = BaseTabPage.ItemValueFont;
                l.AutoSize = true;
                if (members[i].ha_network_peers.Length == members.Count)
                {
                    l.ForeColor = Color.Green;
                }
                else
                {
                    l.ForeColor = BaseTabPage.ItemValueForeColor;
                }

                if (members[i].ha_network_peers.Length == 0)
                {
                    l.Text = Messages.HA_HEARTBEAT_UNHEALTHY;
                }
                else if (members[i].ha_network_peers.Length == members.Count)
                {
                    l.Text = Messages.HA_HEARTBEAT_HEALTHY;
                }
                else
                {
                    l.Text = string.Format(Messages.HA_HEARTBEAT_SERVERS, members[i].ha_network_peers.Length, members.Count);
                }
                tableLatencies.Controls.Add(l);
                tableLatencies.SetCellPosition(l, new TableLayoutPanelCellPosition(1, i + 1));
                tableLatencies.SetColumnSpan(l, 2);

                // For each heartbeat SR, show health from this host's perspective
                for (int j = 0; j < heartbeatSRs.Count; j++)
                {
                    l           = new Label();
                    l.Padding   = new Padding(0, 5, 0, 5);
                    l.Font      = BaseTabPage.ItemValueFont;
                    l.ForeColor = BaseTabPage.ItemValueForeColor;
                    l.AutoSize  = true;
                    l.Text      = Messages.HA_HEARTBEAT_UNHEALTHY;
                    foreach (string opaqueRef in members[i].ha_statefiles)
                    {
                        XenRef <VDI> vdiRef = new XenRef <VDI>(opaqueRef);
                        VDI          vdi    = pool.Connection.Resolve(vdiRef);
                        if (vdi == null)
                        {
                            continue;
                        }
                        SR sr = pool.Connection.Resolve(vdi.SR);
                        if (sr == null)
                        {
                            continue;
                        }
                        if (sr == heartbeatSRs[j])
                        {
                            l.ForeColor = Color.Green;
                            l.Text      = Messages.HA_HEARTBEAT_HEALTHY;
                            break;
                        }
                    }
                    tableLatencies.Controls.Add(l);
                    tableLatencies.SetCellPosition(l, new TableLayoutPanelCellPosition((2 * j) + 2, i + 1));
                    tableLatencies.SetColumnSpan(l, 2);
                }
            }

            tableLatencies.ResumeLayout();
            tableLatencies.PerformLayout();
        }