Ejemplo n.º 1
0
        /// <summary>
        /// Scan the JM stdout looking for the specified vertex; display the lines in the file view.
        /// Run in the background.
        /// </summary>
        /// <param name="vertex">Vertex to look for.</param>
        /// <returns>true if the information was found.</returns>
        /// <param name="logViewer">Viewer to use to display the logs.</param>
        /// <param name="stdout">Job standard output stream.</param>
        private static bool ScanJMStdout(ExecutedVertexInstance vertex, IClusterResidentObject stdout, LogViewer logViewer)
        {
            if (vertex == null || vertex.IsManager)
                return false;

            string vertexId = vertex.UniqueID;
            string name = string.Format(@"\s{0}.{1}\s", vertex.Number, vertex.Version); // the dot could match a space too.
            string regexstring = string.Format(@"vertex\s{0}\s(.*)\sv.{1}\s|", vertex.Number, vertex.Version);
            if (vertexId != "")
                regexstring += vertexId + "|";
            regexstring += name + "|"  + vertex.UniqueID;
            Regex regex = new Regex(regexstring, RegexOptions.Compiled);
            Trace.TraceInformation(regex.ToString());

            long length = stdout.Size;
            logViewer.Status("Looking for " + vertex.Name, StatusKind.LongOp);
            if (length == 0)
            {
                logViewer.Status("JM stdout is empty.", StatusKind.Error);
                logViewer.Done();
                return false;
            }

            ISharedStreamReader sr = stdout.GetStream();
            if (sr.Exception != null)
            {
                logViewer.Status("Error opening JM stdout: " + sr.Exception.Message, StatusKind.Error);
                logViewer.Done();
                return false;
            }

            try
            {
                long read = 0;
                long lines = 0;
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    read += line.Length;
                    if (regex.IsMatch(line))
                        logViewer.AddLine(stdout.ToString(), lines, line);
                    lines++;
                    if (lines % 100 == 0 && length > 0)
                    {
                        if (logViewer.Cancelled)
                            break;
                        logViewer.UpdateProgress(Math.Min((int)(read * 100 / length), 100)); // the length can grow while the file is being read
                    }
                }
                sr.Close();
            }
            finally
            {
                logViewer.Done();
            }
            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find mentions of the current vertex in the JM stdout.
        /// </summary>
        private void FindJMStdoutMentions()
        {
            LogViewer lv = new LogViewer(true, "JM on " + this.currentVertex);
            lv.Show();

            var item = new BackgroundWorkItem<bool>(
                m => ScanJMStdout(this.currentVertex, this.Job.ManagerVertex.StdoutFile, lv),
                (c, b) => { },
                "findStdout");
            this.Queue(item);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scan the JM logs looking for the specified vertex; display the lines in the file view.
        /// Run in the background.
        /// </summary>
        /// <param name="vertex">Vertex to look for.</param>
        /// <returns>true if the information was found.</returns>
        /// <param name="logViewer">Viewer used to display the logs.</param>
        private bool ScanJMLogs(ExecutedVertexInstance vertex, LogViewer logViewer)
        {
            if (vertex == null || this.Job.ManagerVertex == null)
                return false;
            if (vertex == this.Job.ManagerVertex)
                return false;

            string vertexId = vertex.UniqueID;
            Regex regex = new Regex(vertexId, RegexOptions.Compiled);
            Trace.TraceInformation(regex.ToString());
            IClusterResidentObject logdir = this.Job.ManagerVertex.LogDirectory;

            if (logdir.Exception != null)
            {
                this.Status(logdir.ToString(), StatusKind.Error);
                return false;
            }

            List<IClusterResidentObject> files = logdir.GetFilesAndFolders(this.Job.ManagerVertex.LogFilesPattern).ToList();
            if (files.Count == 0)
            {
                this.Status("No log files found", StatusKind.Error);
                return false;
            }

            try
            {
                long totalWork = 0;
                foreach (var file in files)
                {
                    if (totalWork >= 0 && file.Size >= 0)
                        totalWork += file.Size;
                }

                long done = 0;
                foreach (var file in files)
                {
                    ISharedStreamReader sr = file.GetStream();
                    if (sr.Exception != null)
                    {
                        logViewer.Status("Error opening file: " + sr.Exception.Message, StatusKind.Error);
                        continue;
                    }
                    logViewer.Status("Scanning " + file, StatusKind.LongOp);
                    long lineno = 0;
                    while (!sr.EndOfStream)
                    {
                        if (logViewer.Cancelled)
                            break;
                        string line = sr.ReadLine();
                        done += line.Length;
                        if (regex.IsMatch(line))
                        {
                            logViewer.AddLine(file.Name, lineno, line);
                        }
                        lineno++;
                        logViewer.UpdateProgress((int)(100 * done / totalWork));
                    }
                    sr.Close();
                    if (logViewer.Cancelled)
                        break;
                }
            }
            finally
            {
                logViewer.Done();
            }

            return true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Load the file in the log viewer.
 /// </summary>
 /// <param name="sender">Unused.</param>
 /// <param name="e">Unused.</param>
 private void loadFileInViewerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     LogViewer viewer = new LogViewer();
     viewer.Show();
     viewer.LoadFile(this.richtextBoxShownFile);
 }