Skip to content
Snippets Groups Projects
Commit 11872888 authored by Karen Feng's avatar Karen Feng
Browse files

Created getByteRange function for logs and log pages, removed lastNBytes function

parent e3a3fcf6
No related branches found
No related tags found
No related merge requests found
......@@ -621,6 +621,29 @@ private object Utils extends Logging {
callSiteInfo.firstUserLine)
}
/** Determine the byte range for a log or log page. */
def getByteRange(path: String, offset: Option[String], byteLength: Option[String])
: (Long, Long, Long, Int) = {
val defaultBytes = 10000
val maxBytes = 1024 * 1024
val file = new File(path)
val logLength = file.length()
val getOffset = offset.map(_.toLong).getOrElse(logLength-defaultBytes)
val fixedOffset =
if (getOffset < 0) 0L
else if (getOffset > logLength) logLength
else getOffset
val getByteLength = byteLength.map(_.toInt).getOrElse(defaultBytes)
val logPageLength = math.min(getByteLength, maxBytes)
val endOffset = math.min(fixedOffset+logPageLength, logLength)
(fixedOffset, endOffset, logLength, logPageLength)
}
/** Return a string containing part of a file from byte 'start' to 'end'. */
def offsetBytes(path: String, start: Long, end: Long): String = {
val file = new File(path)
......@@ -636,13 +659,6 @@ private object Utils extends Logging {
Source.fromBytes(buff).mkString
}
/** Return a string containing the last `n` bytes of a file. */
def lastNBytes(path: String, n: Int): String = {
val file = new File(path)
val length = file.length()
offsetBytes(path, length-n, length)
}
/**
* Clone an object using a Spark serializer.
*/
......
......@@ -57,41 +57,39 @@ class WorkerWebUI(val worker: Worker, val workDir: File, requestedPort: Option[I
val appId = request.getParameter("appId")
val executorId = request.getParameter("executorId")
val logType = request.getParameter("logType")
val offset = Option(request.getParameter("offset"))
val byteLength = Option(request.getParameter("byteLength"))
val path = "%s/%s/%s/%s".format(workDir.getPath, appId, executorId, logType)
val maxBytes = 1024 * 1024 // Guard against OOM
val defaultBytes = 100 * 1024
val numBytes = Option(request.getParameter("numBytes"))
.flatMap(s => Some(s.toInt)).getOrElse(defaultBytes)
val offsetBytes = Utils.getByteRange(path, offset, byteLength)
val fixedOffset = offsetBytes._1
val endOffset = offsetBytes._2
val logLength = offsetBytes._3
val path = "%s/%s/%s/%s".format(workDir.getPath, appId, executorId, logType)
val pre = "==== Last %s bytes of %s/%s/%s ====\n".format(numBytes, appId, executorId, logType)
pre + Utils.lastNBytes(path, math.min(numBytes, maxBytes))
val pre = "==== Bytes %s-%s of %s of %s/%s/%s ====\n"
.format(fixedOffset, endOffset, logLength, appId, executorId, logType)
pre + Utils.offsetBytes(path, fixedOffset, endOffset)
}
def logPage(request: HttpServletRequest): Seq[scala.xml.Node] = {
val appId = request.getParameter("appId")
val executorId = request.getParameter("executorId")
val logType = request.getParameter("logType")
val maxBytes = 1024 * 1024
val defaultBytes = 10000
val byteLength = Option(request.getParameter("byteLength")).map(_.toInt).getOrElse(defaultBytes)
val offset = Option(request.getParameter("offset"))
val byteLength = Option(request.getParameter("byteLength"))
val path = "%s/%s/%s/%s".format(workDir.getPath, appId, executorId, logType)
val logLength = new File(path).length()
val offset = Option(request.getParameter("offset")).map(_.toLong).getOrElse(logLength-10000)
val logPageLength = math.min(byteLength, maxBytes)
val fixedOffset =
if (offset < 0) 0
else if (offset > logLength) logLength
else offset
val offsetBytes = Utils.getByteRange(path, offset, byteLength)
val fixedOffset = offsetBytes._1
val endOffset = offsetBytes._2
val logLength = offsetBytes._3
val logPageLength = offsetBytes._4
val endOffset = math.min(fixedOffset+logPageLength, logLength)
val logText = <node>{Utils.offsetBytes(path, fixedOffset, endOffset)}</node>
val linkToMaster = <p><a href={worker.masterWebUiUrl}>Back to Master</a></p>
val range = <span>Bytes {fixedOffset.toString} - {(endOffset).toString} of {logLength}</span>
val range = <span>Bytes {fixedOffset.toString} - {endOffset.toString} of {logLength}</span>
val backButton =
if (fixedOffset > 0) {
......@@ -116,8 +114,6 @@ class WorkerWebUI(val worker: Worker, val workDir: File, requestedPort: Option[I
<button disabled="disabled">Next 0 Bytes</button>
}
val logText = <node>{Utils.offsetBytes(path, fixedOffset, endOffset)}</node>
val content =
<html>
<body>
......@@ -134,7 +130,8 @@ class WorkerWebUI(val worker: Worker, val workDir: File, requestedPort: Option[I
</div>
</body>
</html>
UIUtils.basicSparkPage(content, logType + " log page for " + appId)
UIUtils.basicSparkPage(content, request.getParameter("logType") + " log page for " +
request.getParameter("appId"))
}
def stop() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment