Example #1
0
        private void flickerFreeListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            HostWithStatus host = flickerFreeListBox1.Items[e.Index] as HostWithStatus;

            using (SolidBrush backBrush = new SolidBrush(flickerFreeListBox1.BackColor))
            {
                e.Graphics.FillRectangle(backBrush, e.Bounds);
            }
            e.Graphics.DrawImage(Images.GetImage16For(host.Host), new Rectangle(e.Bounds.Location, new Size(e.Bounds.Height, e.Bounds.Height)));
            int width = Drawing.MeasureText(host.StatusString, flickerFreeListBox1.Font).Width;

            Drawing.DrawText(e.Graphics, host.ToString(), flickerFreeListBox1.Font, new Rectangle(e.Bounds.Left + Properties.Resources._000_Server_h32bit_16.Width, e.Bounds.Top, e.Bounds.Right - (width + Properties.Resources._000_Server_h32bit_16.Width), e.Bounds.Height), flickerFreeListBox1.ForeColor, TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
            if (host.Status == HostStatus.queued)
            {
                Drawing.DrawText(e.Graphics, host.StatusString, flickerFreeListBox1.Font, new Rectangle(e.Bounds.Right - width, e.Bounds.Top, width, e.Bounds.Height), flickerFreeListBox1.ForeColor, flickerFreeListBox1.BackColor);
            }
            else if (host.Status == HostStatus.compiling || host.Status == HostStatus.downloading)
            {
                Drawing.DrawText(e.Graphics, host.StatusString, flickerFreeListBox1.Font, new Rectangle(e.Bounds.Right - width, e.Bounds.Top, width, e.Bounds.Height), Color.Blue, flickerFreeListBox1.BackColor);
            }
            else if (host.Status == HostStatus.succeeded)
            {
                Drawing.DrawText(e.Graphics, host.StatusString, flickerFreeListBox1.Font, new Rectangle(e.Bounds.Right - width, e.Bounds.Top, width, e.Bounds.Height), Color.Green, flickerFreeListBox1.BackColor);
            }
            if (host.Status == HostStatus.failed)
            {
                Drawing.DrawText(e.Graphics, host.StatusString, flickerFreeListBox1.Font, new Rectangle(e.Bounds.Right - width, e.Bounds.Top, width, e.Bounds.Height), Color.Red, flickerFreeListBox1.BackColor);
            }
        }
Example #2
0
        private void RunAction(List <Capability> capabilities, List <Host> hosts)
        {
            OnPageUpdated();
            _hostList.Clear();
            flickerFreeListBox1.Items.Clear();
            label1.Text = "";
            long size = 0;

            foreach (Capability c in capabilities)
            {
                if (c.Key != "client-logs")
                {
                    size += c.MinSize;
                }
            }
            foreach (Host host in hosts)
            {
                HostWithStatus hostWithStatus = new HostWithStatus(host, size);
                _hostList.Add(hostWithStatus);
                flickerFreeListBox1.Items.Add(hostWithStatus);
            }
            List <string> strings = new List <string>();

            foreach (Capability c in capabilities)
            {
                strings.Add(c.Key);
            }
            _action            = new SystemStatusAction(_hostList, strings);
            _action.Changed   += _action_Changed;
            _action.Completed += _action_Completed;
            _action.RunAsync();
        }
Example #3
0
 public SingleHostStatusAction(HostWithStatus h, List<string> e, string path, string time)
     : base(h.Host.Connection, string.Format(Messages.ACTION_SYSTEM_STATUS_COMPILING, Helpers.GetName(h.Host)), null, true)
 {
     host = h;
     entries = e.ToArray();
     filepath = path;
     timestring = time;
 }
        public void RunBugtool(IXenConnection connection, Session session)
        {
            if (connection == null || session == null)
            {
                return;
            }

            // Fetch the common capabilities of all hosts.
            Dictionary <Host, List <string> > hostCapabilities = new Dictionary <Host, List <string> >();

            foreach (Host host in connection.Cache.Hosts)
            {
                GetSystemStatusCapabilities action = new GetSystemStatusCapabilities(host);
                action.RunExternal(session);
                if (!action.Succeeded)
                {
                    return;
                }

                List <string> keys = new List <string>();
                XmlDocument   doc  = new XmlDocument();
                doc.LoadXml(action.Result);
                foreach (XmlNode node in doc.GetElementsByTagName("capability"))
                {
                    foreach (XmlAttribute a in node.Attributes)
                    {
                        if (a.Name == "key")
                        {
                            keys.Add(a.Value);
                        }
                    }
                }
                hostCapabilities[host] = keys;
            }

            List <string> combination = null;

            foreach (List <string> capabilities in hostCapabilities.Values)
            {
                if (capabilities == null)
                {
                    continue;
                }

                if (combination == null)
                {
                    combination = capabilities;
                    continue;
                }

                combination = Helpers.ListsCommonItems <string>(combination, capabilities);
            }

            if (combination == null || combination.Count <= 0)
            {
                return;
            }

            // The list of the reports which are required in Health Check Report.
            List <string> reportIncluded = combination.Except(reportExcluded).ToList();

            // Verbosity works for xen-bugtool since Dundee.
            if (Helpers.DundeeOrGreater(connection))
            {
                List <string> verbReport = new List <string>(reportWithVerbosity.Keys);
                int           idx        = -1;
                for (int x = 0; x < verbReport.Count; x++)
                {
                    idx = reportIncluded.IndexOf(verbReport[x]);
                    if (idx >= 0)
                    {
                        reportIncluded[idx] = reportIncluded[idx] + ":" + reportWithVerbosity[verbReport[x]].ToString();
                    }
                }
            }

            // Ensure downloaded filenames are unique even for hosts with the same hostname: append a counter to the timestring
            string filepath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            if (Directory.Exists(filepath))
            {
                Directory.Delete(filepath);
            }
            Directory.CreateDirectory(filepath);

            string timestring = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");

            // Collect all master/slave information to output as a separate text file with the report
            List <string> mastersInfo = new List <string>();

            int  i = 0;
            Pool p = Helpers.GetPool(connection);

            foreach (Host host in connection.Cache.Hosts)
            {
                // master/slave information
                if (p == null)
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a stand alone server",
                                                  host.Name));
                }
                else
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a {1} of pool '{2}'",
                                                  host.Name,
                                                  p.master.opaque_ref == host.opaque_ref ? "master" : "slave",
                                                  p.Name));
                }

                HostWithStatus         hostWithStatus = new HostWithStatus(host, 0);
                SingleHostStatusAction statAction     = new SingleHostStatusAction(hostWithStatus, reportIncluded, filepath, timestring + "-" + ++i);
                statAction.RunExternal(session);
            }

            // output the slave/master info
            string mastersDestination = string.Format("{0}\\{1}-Masters.txt", filepath, timestring);

            WriteExtraInfoToFile(mastersInfo, mastersDestination);

            // output the XenCenter metadata
            var    metadata            = XenAdminConfigManager.Provider.GetXenCenterMetadata(false);
            string metadataDestination = string.Format("{0}\\{1}-Metadata.json", filepath, timestring);

            WriteExtraInfoToFile(new List <string> {
                metadata
            }, metadataDestination);

            // Finish the collection of logs with bugtool.
            // Start to zip the files.
            ZipStatusReportAction zipAction = new ZipStatusReportAction(filepath, outputFile);

            zipAction.RunExternal(session);
            log.InfoFormat("Server Status Report is collected: {0}", outputFile);
        }
        public void RunBugtool(IXenConnection connection, Session session)
        {
            if (connection == null || session == null)
                return;

            // Fetch the common capabilities of all hosts.
            Dictionary<Host, List<string>> hostCapabilities = new Dictionary<Host, List<string>>();
            foreach (Host host in connection.Cache.Hosts)
            {
                GetSystemStatusCapabilities action = new GetSystemStatusCapabilities(host);
                action.RunExternal(session);
                if (!action.Succeeded)
                    return;

                List<string> keys = new List<string>();
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(action.Result);
                foreach (XmlNode node in doc.GetElementsByTagName("capability"))
                {
                    foreach (XmlAttribute a in node.Attributes)
                    {
                        if (a.Name == "key")
                            keys.Add(a.Value);
                    }
                }
                hostCapabilities[host] = keys;
            }

            List<string> combination = null;
            foreach (List<string> capabilities in hostCapabilities.Values)
            {
                if (capabilities == null)
                    continue;

                if (combination == null)
                {
                    combination = capabilities;
                    continue;
                }

                combination = Helpers.ListsCommonItems<string>(combination, capabilities);
            }

            if (combination == null || combination.Count <= 0)
               return;

            // The list of the reports which are required in Health Check Report.
            List<string> reportIncluded = combination.Except(reportExcluded).ToList();

            // Verbosity works for xen-bugtool since Dundee.
            if (Helpers.DundeeOrGreater(connection))
            {
                List<string> verbReport = new List<string>(reportWithVerbosity.Keys);
                int idx = -1;
                for (int x = 0; x < verbReport.Count; x++)
                {
                    idx = reportIncluded.IndexOf(verbReport[x]);
                    if (idx >= 0)
                    {
                        reportIncluded[idx] = reportIncluded[idx] + ":" + reportWithVerbosity[verbReport[x]].ToString();
                    }
                }
            }

            // Ensure downloaded filenames are unique even for hosts with the same hostname: append a counter to the timestring
            string filepath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            if (Directory.Exists(filepath))
                Directory.Delete(filepath);
            Directory.CreateDirectory(filepath);

            string timestring = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");

            // Collect all master/slave information to output as a separate text file with the report
            List<string> mastersInfo = new List<string>();

            int i = 0;
            Pool p = Helpers.GetPool(connection);
            foreach (Host host in connection.Cache.Hosts)
            {
                // master/slave information
                if (p == null)
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a stand alone server",
                        host.Name));
                }
                else
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a {1} of pool '{2}'",
                        host.Name,
                        p.master.opaque_ref == host.opaque_ref ? "master" : "slave",
                        p.Name));
                }

                HostWithStatus hostWithStatus = new HostWithStatus(host, 0);
                SingleHostStatusAction statAction = new SingleHostStatusAction(hostWithStatus, reportIncluded, filepath, timestring + "-" + ++i);
                statAction.RunExternal(session);
            }

            string mastersDestination = string.Format("{0}\\{1}-Masters.txt", filepath, timestring);
            if (File.Exists(mastersDestination))
                File.Delete(mastersDestination);

            StreamWriter sw = null;
            try
            {
                sw = new StreamWriter(mastersDestination);
                foreach (string s in mastersInfo)
                    sw.WriteLine(s);

                sw.Flush();
            }
            catch (Exception e)
            {
                log.ErrorFormat("Exception while writing masters file: {0}", e);
            }
            finally
            {
                if (sw != null)
                    sw.Close();
            }

            // Finish the collection of logs with bugtool.
            // Start to zip the files.
            ZipStatusReportAction zipAction = new ZipStatusReportAction(filepath, outputFile);
            zipAction.RunExternal(session);
            log.InfoFormat("Server Status Report is collected: {0}", outputFile);
        }
 private void RunAction(List<Capability> capabilities, List<Host> hosts)
 {
     OnPageUpdated();
     _hostList.Clear();
     flickerFreeListBox1.Items.Clear();
     label1.Text = "";
     long size = 0;
     foreach (Capability c in capabilities)
         if (c.Key != "client-logs")
             size += c.MinSize;
     foreach(Host host in hosts)
     {
         HostWithStatus hostWithStatus = new HostWithStatus(host,size);
         _hostList.Add(hostWithStatus);
         flickerFreeListBox1.Items.Add(hostWithStatus);
     }
     List<string> strings = new List<string>();
     foreach(Capability c in capabilities)
             strings.Add(c.Key);
     _action = new SystemStatusAction(_hostList, strings);
     _action.Changed += new EventHandler<EventArgs>(_action_Changed);
     _action.Completed += new EventHandler<EventArgs>(_action_Completed);
     _action.RunAsync();
 }
        public void RunBugtool(IXenConnection connection, Session session)
        {
            if (connection == null || session == null)
                return;

            // Ensure downloaded filenames are unique even for hosts with the same hostname: append a counter to the timestring
            string filepath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            if (Directory.Exists(filepath))
                Directory.Delete(filepath);
            Directory.CreateDirectory(filepath);

            string timestring = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");

            // Collect all master/slave information to output as a separate text file with the report
            List<string> mastersInfo = new List<string>();

            int i = 0;
            Pool p = Helpers.GetPool(connection);
            foreach (Host host in connection.Cache.Hosts)
            {
                // master/slave information
                if (p == null)
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a stand alone server",
                        host.Name));
                }
                else
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a {1} of pool '{2}'",
                        host.Name,
                        p.master.opaque_ref == host.opaque_ref ? "master" : "slave",
                        p.Name));
                }

                HostWithStatus hostWithStatus = new HostWithStatus(host, 0);
                SingleHostStatusAction statAction = new SingleHostStatusAction(hostWithStatus, bugtoolParam, filepath, timestring + "-" + ++i);
                statAction.RunExternal(session);
            }

            string mastersDestination = string.Format("{0}\\{1}-Masters.txt", filepath, timestring);
            if (File.Exists(mastersDestination))
                File.Delete(mastersDestination);

            StreamWriter sw = null;
            try
            {
                sw = new StreamWriter(mastersDestination);
                foreach (string s in mastersInfo)
                    sw.WriteLine(s);

                sw.Flush();
            }
            catch (Exception e)
            {
                log.ErrorFormat("Exception while writing masters file: {0}", e);
            }
            finally
            {
                if (sw != null)
                    sw.Close();
            }

            // Finish the collection of logs with bugtool.
            // Start to zip the files.
            ZipStatusReportAction zipAction = new ZipStatusReportAction(filepath, outputFile);
            zipAction.RunExternal(session);
            log.InfoFormat("Server Status Report is collected: {0}", outputFile);
        }
Example #8
0
        public void RunBugtool(IXenConnection connection, Session session)
        {
            if (connection == null || session == null)
            {
                return;
            }

            // Ensure downloaded filenames are unique even for hosts with the same hostname: append a counter to the timestring
            string filepath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            if (Directory.Exists(filepath))
            {
                Directory.Delete(filepath);
            }
            Directory.CreateDirectory(filepath);

            string timestring = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");

            // Collect all master/slave information to output as a separate text file with the report
            List <string> mastersInfo = new List <string>();

            int  i = 0;
            Pool p = Helpers.GetPool(connection);

            foreach (Host host in connection.Cache.Hosts)
            {
                // master/slave information
                if (p == null)
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a stand alone server",
                                                  host.Name));
                }
                else
                {
                    mastersInfo.Add(string.Format("Server '{0}' is a {1} of pool '{2}'",
                                                  host.Name,
                                                  p.master.opaque_ref == host.opaque_ref ? "master" : "slave",
                                                  p.Name));
                }

                HostWithStatus         hostWithStatus = new HostWithStatus(host, 0);
                SingleHostStatusAction statAction     = new SingleHostStatusAction(hostWithStatus, bugtoolParam, filepath, timestring + "-" + ++i);
                statAction.RunExternal(session);
            }

            string mastersDestination = string.Format("{0}\\{1}-Masters.txt", filepath, timestring);

            if (File.Exists(mastersDestination))
            {
                File.Delete(mastersDestination);
            }

            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(mastersDestination);
                foreach (string s in mastersInfo)
                {
                    sw.WriteLine(s);
                }

                sw.Flush();
            }
            catch (Exception e)
            {
                log.ErrorFormat("Exception while writing masters file: {0}", e);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }

            // Finish the collection of logs with bugtool.
            // Start to zip the files.
            ZipStatusReportAction zipAction = new ZipStatusReportAction(filepath, outputFile);

            zipAction.RunExternal(session);
            log.InfoFormat("Server Status Report is collected: {0}", outputFile);
        }