azkaban-uncached

Added ajaxFetchJobSummary handler; currently just returns

11/18/2013 7:38:20 AM

Details

diff --git a/src/java/azkaban/webapp/servlet/ExecutorServlet.java b/src/java/azkaban/webapp/servlet/ExecutorServlet.java
index 2aa7da2..151b59e 100644
--- a/src/java/azkaban/webapp/servlet/ExecutorServlet.java
+++ b/src/java/azkaban/webapp/servlet/ExecutorServlet.java
@@ -303,6 +303,9 @@ public class ExecutorServlet extends LoginAbstractAzkabanServlet {
 				else if (ajaxName.equals("fetchExecJobLogs")) {
 					ajaxFetchJobLogs(req, resp, ret, session.getUser(), exFlow);
 				}
+				else if (ajaxName.equals("fetchExecJobSummary")) {
+					ajaxFetchJobSummary(req, resp, ret, session.getUser(), exFlow);
+				}
 				else if (ajaxName.equals("retryFailedJobs")) {
 					ajaxRestartFailed(req, resp, ret, session.getUser(), exFlow);
 				}
@@ -483,6 +486,51 @@ public class ExecutorServlet extends LoginAbstractAzkabanServlet {
 			throw new ServletException(e);
 		}
 	}
+	
+	/**
+	 * Gets the job summary.
+	 * 
+	 * @param req
+	 * @param resp
+	 * @param user
+	 * @param exFlow
+	 * @throws ServletException
+	 */
+	private void ajaxFetchJobSummary(HttpServletRequest req, HttpServletResponse resp, HashMap<String, Object> ret, User user, ExecutableFlow exFlow) throws ServletException {
+		Project project = getProjectAjaxByPermission(ret, exFlow.getProjectId(), user, Type.READ);
+		if (project == null) {
+			return;
+		}
+		
+		int offset = this.getIntParam(req, "offset");
+		int length = this.getIntParam(req, "length");
+		
+		String jobId = this.getParam(req, "jobId");
+		resp.setCharacterEncoding("utf-8");
+
+		try {
+			ExecutableNode node = exFlow.getExecutableNode(jobId);
+			if (node == null) {
+				ret.put("error", "Job " + jobId + " doesn't exist in " + exFlow.getExecutionId());
+				return;
+			}
+			
+			int attempt = this.getIntParam(req, "attempt", node.getAttempt());
+			LogData data = executorManager.getExecutionJobLog(exFlow, jobId, offset, length, attempt);
+			if (data == null) {
+				ret.put("length", 0);
+				ret.put("offset", offset);
+				ret.put("data", "");
+			}
+			else {
+				ret.put("length", data.getLength());
+				ret.put("offset", data.getOffset());
+				ret.put("data", data.getData());
+			}
+		} catch (ExecutorManagerException e) {
+			throw new ServletException(e);
+		}
+	}
 
 	/**
 	 * Gets the job metadata through ajax plain text stream to reduce memory overhead.
diff --git a/src/web/js/azkaban.jobsummary.view.js b/src/web/js/azkaban.jobsummary.view.js
index eafd9c9..79caaad 100644
--- a/src/web/js/azkaban.jobsummary.view.js
+++ b/src/web/js/azkaban.jobsummary.view.js
@@ -16,13 +16,13 @@
 
 $.namespace('azkaban');
 
-var logModel;
-azkaban.LogModel = Backbone.Model.extend({});
+var summaryModel;
+azkaban.SummaryModel = Backbone.Model.extend({});
 
-var jobLogView;
-azkaban.JobLogView = Backbone.View.extend({
+var jobSummaryView;
+azkaban.JobSummaryView = Backbone.View.extend({
 	events: {
-		"click #updateLogBtn" : "handleUpdate"
+		"click #updateSummaryBtn" : "handleUpdate"
 	},
 	initialize: function(settings) {
 		this.model.set({"offset": 0});
@@ -43,13 +43,13 @@ azkaban.JobLogView = Backbone.View.extend({
 				type: "get",
 				async: false,
 				dataType: "json",
-				data: {"execid": execId, "jobId": jobId, "ajax":"fetchExecJobLogs", "offset": offset, "length": 50000, "attempt": attempt},
+				data: {"execid": execId, "jobId": jobId, "ajax":"fetchExecJobSummary", "offset": offset, "length": 50000, "attempt": attempt},
 				error: function(data) {
 					console.log(data);
 					finished = true;
 				},
 				success: function(data) {
-					console.log("fetchLogs");
+					console.log("fetchSummary");
 					if (data.error) {
 						console.log(data.error);
 						finished = true;
@@ -62,27 +62,27 @@ azkaban.JobLogView = Backbone.View.extend({
 						var endTime = date.getTime();
 						if ((endTime - startTime) > 10000) {
 							finished = true;
-							showDialog("Alert","The log is taking a long time to finish loading. Azkaban has stopped loading them. Please click Refresh to restart the load.");
+							showDialog("Alert","The summary is taking a long time to finish loading. Azkaban has stopped loading them. Please click Refresh to restart the load.");
 						} 
 	
 						var re = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g;
-						var log = $("#logSection").text();
-						if (!log) {
-							log = data.data;
+						var summary = $("#summarySection").text();
+						if (!summary) {
+							summary = data.data;
 						}
 						else {
-							log += data.data;
+							summary += data.data;
 						}
 	
 						var newOffset = data.offset + data.length;
 	
-						$("#logSection").text(log);
-						log = $("#logSection").html();
-						log = log.replace(re, "<a href=\"$1\" title=\"\">$1</a>");
-						$("#logSection").html(log);
+						$("#summarySection").text(summary);
+						summary = $("#summarySection").html();
+						summary = summary.replace(re, "<a href=\"$1\" title=\"\">$1</a>");
+						$("#summarySection").html(summary);
 	
-						model.set({"offset": newOffset, "log": log});
-						$(".logViewer").scrollTop(9999);
+						model.set({"offset": newOffset, "summary": summary});
+						$(".summaryViewer").scrollTop(9999);
 					}
 				}
 			});
@@ -111,6 +111,6 @@ var showDialog = function(title, message) {
 $(function() {
 	var selected;
 
-	logModel = new azkaban.LogModel();
-	jobLogView = new azkaban.JobLogView({el:$('#jobLogView'), model: logModel});
+	summaryModel = new azkaban.SummaryModel();
+	jobSummaryView = new azkaban.JobSummaryView({el:$('#jobSummaryView'), model: summaryModel});
 });