Browse Source

HUE-2028 [pig] The end of logs can be missing

Converted interval to recursive timeout
Forced refresh in case the workflow is marked as completed but the logs say otherwise
Enrico Berti 11 years ago
parent
commit
4648477b81
3 changed files with 16 additions and 17 deletions
  1. 5 1
      apps/pig/src/pig/api.py
  2. 9 15
      apps/pig/src/pig/templates/app.mako
  3. 2 1
      apps/pig/src/pig/views.py

+ 5 - 1
apps/pig/src/pig/api.py

@@ -144,6 +144,7 @@ class OozieApi:
 
   def get_log(self, request, oozie_workflow):
     logs = {}
+    is_really_done = False
 
     for action in oozie_workflow.get_working_actions():
       try:
@@ -152,6 +153,8 @@ class OozieApi:
           if data:
             matched_logs = self._match_logs(data)
             logs[action.name] = self._make_links(matched_logs)
+            is_really_done = OozieApi.RE_LOG_END.search(data['logs'][1]) is not None
+
       except Exception, e:
         LOG.error('An error happen while watching the demo running: %(error)s' % {'error': e})
 
@@ -164,13 +167,14 @@ class OozieApi:
         'name': action.name,
         'status': action.status,
         'logs': logs.get(action.name, ''),
+        'isReallyDone': is_really_done,
         'progress': progress,
         'progressPercent': '%d%%' % progress,
         'absoluteUrl': oozie_workflow.get_absolute_url(),
       }
       workflow_actions.append(appendable)
 
-    return logs, workflow_actions
+    return logs, workflow_actions, is_really_done
 
   def _match_logs(self, data):
     """Difficult to match multi lines of text"""

+ 9 - 15
apps/pig/src/pig/templates/app.mako

@@ -514,13 +514,13 @@ ${ commonheader(None, "pig", user) | n,unicode }
           </div>
           <div data-bind="template: {name: 'logTemplate', foreach: currentScript().actions}"></div>
           <script id="logTemplate" type="text/html">
-            <div data-bind="css:{'alert-modified': name != '', 'alert': name != '', 'alert-success': status == 'SUCCEEDED' || status == 'OK', 'alert-error': status != 'RUNNING' && status != 'SUCCEEDED' && status != 'OK' && status != 'PREP' && status != 'SUSPENDED'}">
+            <div data-bind="css:{'alert-modified': name != '', 'alert': name != '', 'alert-success': (status == 'SUCCEEDED' || status == 'OK') && isReallyDone, 'alert-error': status != 'RUNNING' && status != 'SUCCEEDED' && status != 'OK' && status != 'PREP' && status != 'SUSPENDED'}">
               <div class="pull-right">
                   ${ _('Status:') } <a data-bind="text: status, visible: absoluteUrl != '', attr: {'href': absoluteUrl}" target="_blank"/> <i class="fa fa-share"></i>
               </div>
               <h4>${ _('Progress:') } <span data-bind="text: progress"></span>${ _('%') }</h4>
               <div data-bind="css: {'progress': name != '', 'progress-striped': name != '', 'active': status == 'RUNNING'}" style="margin-top:10px">
-                <div data-bind="css: {'bar': name != '', 'bar-success': status == 'SUCCEEDED' || status == 'OK', 'bar-warning': status == 'RUNNING' || status == 'PREP', 'bar-danger': status != 'RUNNING' && status != 'SUCCEEDED' && status != 'OK' && status != 'PREP' && status != 'SUSPENDED'}, attr: {'style': 'width:' + progressPercent}"></div>
+                <div data-bind="css: {'bar': name != '', 'bar-success': (status == 'SUCCEEDED' || status == 'OK') && isReallyDone, 'bar-warning': status == 'RUNNING' || status == 'PREP' || !isReallyDone, 'bar-danger': status != 'RUNNING' && status != 'SUCCEEDED' && status != 'OK' && status != 'PREP' && status != 'SUSPENDED'}, attr: {'style': 'width:' + progressPercent}"></div>
               </div>
             </div>
           </script>
@@ -1114,20 +1114,10 @@ ${ commonheader(None, "pig", user) | n,unicode }
       $("#filter").val("");
     });
 
-    var logsRefreshInterval;
     $(document).on("startLogsRefresh", function () {
       logsAtEnd = true;
-      window.clearInterval(logsRefreshInterval);
       $("#withLogs").text("");
       refreshLogs();
-      logsRefreshInterval = window.setInterval(function () {
-        refreshLogs();
-      }, 500);
-    });
-
-    $(document).on("stopLogsRefresh", function () {
-      window.clearInterval(logsRefreshInterval);
-      $.jHueTitleUpdater.reset();
     });
 
     $(document).on("clearLogs", function () {
@@ -1210,22 +1200,26 @@ ${ commonheader(None, "pig", user) | n,unicode }
               }
             }, 100);
           }
-          if (data.workflow && data.workflow.isRunning) {
+          if ((data.workflow && data.workflow.isRunning) || !data.isReallyDone) {
             viewModel.currentScript().actions(data.workflow.actions);
             if (data.workflow.actions != null && data.workflow.actions.length > 0) {
               $.jHueTitleUpdater.set(data.workflow.actions[data.workflow.actions.length-1].progress + "%");
             }
+            else {
+              $.jHueTitleUpdater.reset();
+            }
+            window.setTimeout(function () {
+              refreshLogs();
+            }, 1000);
           }
           else {
             viewModel.currentScript().actions(data.workflow.actions);
             viewModel.currentScript().isRunning(false);
-            $(document).trigger("stopLogsRefresh");
             $.jHueTitleUpdater.reset();
           }
         });
       }
       else {
-        $(document).trigger("stopLogsRefresh");
         $.jHueTitleUpdater.reset();
       }
     }

+ 2 - 1
apps/pig/src/pig/views.py

@@ -202,7 +202,7 @@ def delete(request):
 @show_oozie_error
 def watch(request, job_id):
   oozie_workflow = check_job_access_permission(request, job_id)
-  logs, workflow_actions = api.get(request.jt, request.jt, request.user).get_log(request, oozie_workflow)
+  logs, workflow_actions, is_really_done = api.get(request.jt, request.jt, request.user).get_log(request, oozie_workflow)
   output = get_workflow_output(oozie_workflow, request.fs)
 
   workflow = {
@@ -218,6 +218,7 @@ def watch(request, job_id):
   response = {
     'workflow': workflow,
     'logs': logs,
+    'isReallyDone': is_really_done,
     'output': hdfs_link(output)
   }