Example #1
0
        /// <exception cref="System.IO.IOException"/>
        private bool ReadContainerLogs(HtmlBlock.Block html, AggregatedLogFormat.ContainerLogsReader
                                       logReader, AggregatedLogsBlock.LogLimits logLimits, string desiredLogType, long
                                       logUpLoadTime)
        {
            int bufferSize = 65536;

            char[] cbuf     = new char[bufferSize];
            bool   foundLog = false;
            string logType  = logReader.NextLog();

            while (logType != null)
            {
                if (desiredLogType == null || desiredLogType.IsEmpty() || desiredLogType.Equals(logType
                                                                                                ))
                {
                    long logLength = logReader.GetCurrentLogLength();
                    if (foundLog)
                    {
                        html.Pre().("\n\n").();
                    }
                    html.P().("Log Type: " + logType).();
                    html.P().("Log Upload Time: " + Times.Format(logUpLoadTime)).();
                    html.P().("Log Length: " + System.Convert.ToString(logLength)).();
                    long start = logLimits.start < 0 ? logLength + logLimits.start : logLimits.start;
                    start = start < 0 ? 0 : start;
                    start = start > logLength ? logLength : start;
                    long end = logLimits.end < 0 ? logLength + logLimits.end : logLimits.end;
                    end = end < 0 ? 0 : end;
                    end = end > logLength ? logLength : end;
                    end = end < start ? start : end;
                    long toRead = end - start;
                    if (toRead < logLength)
                    {
                        html.P().("Showing " + toRead + " bytes of " + logLength + " total. Click ").A(Url
                                                                                                           ("logs", $(YarnWebParams.NmNodename), $(YarnWebParams.ContainerId), $(YarnWebParams
                                                                                                                                                                                 .EntityString), $(YarnWebParams.AppOwner), logType, "?start=0"), "here").(" for the full log."
                                                                                                                                                                                                                                                           ).();
                    }
                    long totalSkipped = 0;
                    while (totalSkipped < start)
                    {
                        long ret = logReader.Skip(start - totalSkipped);
                        if (ret == 0)
                        {
                            //Read one byte
                            int nextByte = logReader.Read();
                            // Check if we have reached EOF
                            if (nextByte == -1)
                            {
                                throw new IOException("Premature EOF from container log");
                            }
                            ret = 1;
                        }
                        totalSkipped += ret;
                    }
                    int len           = 0;
                    int currentToRead = toRead > bufferSize ? bufferSize : (int)toRead;
                    Hamlet.PRE <Org.Apache.Hadoop.Yarn.Webapp.Hamlet.Hamlet> pre = html.Pre();
                    while (toRead > 0 && (len = logReader.Read(cbuf, 0, currentToRead)) > 0)
                    {
                        pre.(new string(cbuf, 0, len));
                        toRead        = toRead - len;
                        currentToRead = toRead > bufferSize ? bufferSize : (int)toRead;
                    }
                    pre.();
                    foundLog = true;
                }
                logType = logReader.NextLog();
            }
            return(foundLog);
        }