/// <exception cref="System.IO.IOException"/> public virtual string ReadTaskLog(TaskLog.LogName filter, TaskAttemptID taskId, bool isCleanup) { // string buffer to store task log StringBuilder result = new StringBuilder(); int res; // reads the whole tasklog into inputstream InputStream taskLogReader = new TaskLog.Reader(taskId, filter, 0, -1, isCleanup); // construct string log from inputstream. byte[] b = new byte[65536]; while (true) { res = taskLogReader.Read(b); if (res > 0) { result.Append(Sharpen.Runtime.GetStringForBytes(b)); } else { break; } } taskLogReader.Close(); // trim the string and return it string str = result.ToString(); str = str.Trim(); return(str); }
/// <exception cref="System.IO.IOException"/> private static TaskLog.LogFileDetail GetLogFileDetail(TaskAttemptID taskid, TaskLog.LogName filter, bool isCleanup) { FilePath indexFile = GetIndexFile(taskid, isCleanup); BufferedReader fis = new BufferedReader(new InputStreamReader(SecureIOUtils.OpenForRead (indexFile, ObtainLogDirOwner(taskid), null), Charsets.Utf8)); //the format of the index file is //LOG_DIR: <the dir where the task logs are really stored> //stdout:<start-offset in the stdout file> <length> //stderr:<start-offset in the stderr file> <length> //syslog:<start-offset in the syslog file> <length> TaskLog.LogFileDetail l = new TaskLog.LogFileDetail(); string str = null; try { str = fis.ReadLine(); if (str == null) { // the file doesn't have anything throw new IOException("Index file for the log of " + taskid + " doesn't exist."); } l.location = Sharpen.Runtime.Substring(str, str.IndexOf(TaskLog.LogFileDetail.Location ) + TaskLog.LogFileDetail.Location.Length); // special cases are the debugout and profile.out files. They are // guaranteed // to be associated with each task attempt since jvm reuse is disabled // when profiling/debugging is enabled if (filter.Equals(TaskLog.LogName.Debugout) || filter.Equals(TaskLog.LogName.Profile )) { l.length = new FilePath(l.location, filter.ToString()).Length(); l.start = 0; fis.Close(); return(l); } str = fis.ReadLine(); while (str != null) { // look for the exact line containing the logname if (str.Contains(filter.ToString())) { str = Sharpen.Runtime.Substring(str, filter.ToString().Length + 1); string[] startAndLen = str.Split(" "); l.start = long.Parse(startAndLen[0]); l.length = long.Parse(startAndLen[1]); break; } str = fis.ReadLine(); } fis.Close(); fis = null; } finally { IOUtils.Cleanup(Log, fis); } return(l); }
public static FilePath GetTaskLogFile(TaskAttemptID taskid, bool isCleanup, TaskLog.LogName filter) { if (GetMRv2LogDir() != null) { return(new FilePath(GetMRv2LogDir(), filter.ToString())); } else { return(new FilePath(GetAttemptDir(taskid, isCleanup), filter.ToString())); } }
internal static FilePath GetRealTaskLogFileLocation(TaskAttemptID taskid, bool isCleanup , TaskLog.LogName filter) { TaskLog.LogFileDetail l; try { l = GetLogFileDetail(taskid, filter, isCleanup); } catch (IOException ie) { Log.Error("getTaskLogFileDetail threw an exception " + ie); return(null); } return(new FilePath(l.location, filter.ToString())); }
/// <summary>Read a log file from start to end positions.</summary> /// <remarks> /// Read a log file from start to end positions. The offsets may be negative, /// in which case they are relative to the end of the file. For example, /// Reader(taskid, kind, 0, -1) is the entire file and /// Reader(taskid, kind, -4197, -1) is the last 4196 bytes. /// </remarks> /// <param name="taskid">the id of the task to read the log file for</param> /// <param name="kind">the kind of log to read</param> /// <param name="start">the offset to read from (negative is relative to tail)</param> /// <param name="end">the offset to read upto (negative is relative to tail)</param> /// <param name="isCleanup">whether the attempt is cleanup attempt or not</param> /// <exception cref="System.IO.IOException"/> public Reader(TaskAttemptID taskid, TaskLog.LogName kind, long start, long end, bool isCleanup) { // find the right log file TaskLog.LogFileDetail fileDetail = GetLogFileDetail(taskid, kind, isCleanup); // calculate the start and stop long size = fileDetail.length; if (start < 0) { start += size + 1; } if (end < 0) { end += size + 1; } start = Math.Max(0, Math.Min(start, size)); end = Math.Max(0, Math.Min(end, size)); start += fileDetail.start; end += fileDetail.start; bytesRemaining = end - start; string owner = ObtainLogDirOwner(taskid); file = SecureIOUtils.OpenForRead(new FilePath(fileDetail.location, kind.ToString( )), owner, null); // skip upto start long pos = 0; while (pos < start) { long result = file.Skip(start - pos); if (result < 0) { bytesRemaining = 0; break; } pos += result; } }
private static string GetTaskLogFile(TaskLog.LogName filter) { return(ApplicationConstants.LogDirExpansionVar + Path.Separator + filter.ToString ()); }