tasklog.jsp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <%@ page
  2. contentType="text/html; charset=UTF-8"
  3. import="javax.servlet.*"
  4. import="javax.servlet.http.*"
  5. import="java.io.*"
  6. %>
  7. <%
  8. long logOffset = -1, logLength = -1;
  9. boolean tailLog = false;
  10. long tailSize = 1024;
  11. int tailWindow = 1;
  12. boolean entireLog = false;
  13. String taskId = request.getParameter("taskid");
  14. if (taskId == null) {
  15. out.println("<h2>Missing 'taskid' for fetching logs!</h2>");
  16. return;
  17. }
  18. String sLogOff = request.getParameter("off");
  19. if (sLogOff != null) {
  20. logOffset = Long.valueOf(sLogOff).longValue();
  21. }
  22. String sLogLen = request.getParameter("len");
  23. if (sLogLen != null) {
  24. logLength = Long.valueOf(sLogLen).longValue();
  25. }
  26. String sEntireLog = request.getParameter("all");
  27. if (sEntireLog != null) {
  28. entireLog = Boolean.valueOf(sEntireLog);
  29. }
  30. String sTail = request.getParameter("tail");
  31. if (sTail != null) {
  32. tailLog = Boolean.valueOf(sTail);
  33. }
  34. String sTailLen = request.getParameter("tailsize");
  35. if (sTailLen != null) {
  36. tailSize = Long.valueOf(sTailLen).longValue();
  37. }
  38. String sTailWindow = request.getParameter("tailwindow");
  39. if (sTailWindow != null) {
  40. tailWindow = Integer.valueOf(sTailWindow).intValue();
  41. }
  42. if (logOffset == -1 || logLength == -1) {
  43. tailLog = true;
  44. tailWindow = 1;
  45. }
  46. if (entireLog) {
  47. tailLog = false;
  48. }
  49. %>
  50. <html>
  51. <title><%= taskId %> Task Logs</title>
  52. <body>
  53. <h1><%= taskId %> Task Logs</h1><br>
  54. <h2>Task Logs</h2>
  55. <pre>
  56. <%
  57. boolean gotRequiredData = true;
  58. try {
  59. TaskLog.Reader taskLogReader = new TaskLog.Reader(taskId);
  60. byte[] b = null;
  61. int bytesRead = 0;
  62. int targetLength = 0;
  63. if (entireLog) {
  64. b = taskLogReader.fetchAll();
  65. targetLength = bytesRead = b.length;
  66. } else {
  67. if (tailLog) {
  68. b = new byte[(int)tailSize];
  69. targetLength = (int)tailSize;
  70. bytesRead = taskLogReader.tail(b, 0, b.length, tailSize, tailWindow);
  71. } else {
  72. b = new byte[(int)logLength];
  73. targetLength = (int)logLength;
  74. bytesRead = taskLogReader.read(b, 0, b.length, logOffset, logLength);
  75. }
  76. }
  77. if (bytesRead != targetLength &&
  78. targetLength <= taskLogReader.getTotalLogSize()) {
  79. out.println("<b>Warning: Could not fetch " + targetLength +
  80. " bytes from the task-logs; probably purged!</b><br/>");
  81. gotRequiredData = false;
  82. }
  83. String logData = new String(b, 0, bytesRead);
  84. out.println(logData);
  85. } catch (IOException ioe) {
  86. out.println("Failed to retrieve logs for task: " + taskId);
  87. }
  88. %>
  89. </pre>
  90. <%
  91. if (!entireLog) {
  92. if (tailLog) {
  93. if (gotRequiredData) {
  94. out.println("<a href='/tasklog.jsp?taskid=" + taskId +
  95. "&tail=true&tailsize=" + tailSize + "&tailwindow=" + (tailWindow+1) +
  96. "'>Earlier</a>");
  97. }
  98. if (tailWindow > 1) {
  99. out.println("<a href='/tasklog.jsp?taskid=" + taskId +
  100. "&tail=true&tailsize=" + tailSize + "&tailwindow=" + (tailWindow-1)
  101. + "'>Later</a>");
  102. }
  103. } else {
  104. if (gotRequiredData) {
  105. out.println("<a href='/tasklog.jsp?taskid=" + taskId +
  106. "&tail=false&off=" + Math.max(0, (logOffset-logLength)) +
  107. "&len=" + logLength + "'>Earlier</a>");
  108. }
  109. out.println("<a href='/tasklog.jsp?taskid=" + taskId +
  110. "&tail=false&off=" + (logOffset+logLength) +
  111. "&len=" + logLength + "'>Later</a>");
  112. }
  113. }
  114. %>
  115. <hr>
  116. <a href="http://lucene.apache.org/hadoop">Hadoop</a>, 2006.<br>
  117. </body>
  118. </html>