aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorKaren Feng <karenfeng.us@gmail.com>2013-07-11 14:56:37 -0700
committerKaren Feng <karenfeng.us@gmail.com>2013-07-11 14:56:37 -0700
commit11872888ca44d0c08c157973a8e35d344b0119e4 (patch)
tree519d73dcd342b54b0eeff4df9a0fda79be1ed4aa /core
parente3a3fcf61b117d63db33ee28928dfd77cfd935b8 (diff)
downloadspark-11872888ca44d0c08c157973a8e35d344b0119e4.tar.gz
spark-11872888ca44d0c08c157973a8e35d344b0119e4.tar.bz2
spark-11872888ca44d0c08c157973a8e35d344b0119e4.zip
Created getByteRange function for logs and log pages, removed lastNBytes function
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/spark/Utils.scala30
-rw-r--r--core/src/main/scala/spark/deploy/worker/ui/WorkerWebUI.scala45
2 files changed, 44 insertions, 31 deletions
diff --git a/core/src/main/scala/spark/Utils.scala b/core/src/main/scala/spark/Utils.scala
index 1da9c9574e..04041d1179 100644
--- a/core/src/main/scala/spark/Utils.scala
+++ b/core/src/main/scala/spark/Utils.scala
@@ -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.
*/
diff --git a/core/src/main/scala/spark/deploy/worker/ui/WorkerWebUI.scala b/core/src/main/scala/spark/deploy/worker/ui/WorkerWebUI.scala
index a3cbe4f5d3..f8ac682dbf 100644
--- a/core/src/main/scala/spark/deploy/worker/ui/WorkerWebUI.scala
+++ b/core/src/main/scala/spark/deploy/worker/ui/WorkerWebUI.scala
@@ -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() {