浏览代码

HUE-1209 [pig] Show execution progress

Remove history script from real saved scripts
Romain Rigaux 12 年之前
父节点
当前提交
1e642ba0e4

+ 18 - 4
apps/pig/src/pig/api.py

@@ -130,13 +130,14 @@ class OozieApi:
     workflow_actions = []
 
     # Only one Pig action
+    progress = get_progress(oozie_workflow, logs.get(action.name, ''))
     for action in oozie_workflow.get_working_actions():
       appendable = {
         'name': action.name,
         'status': action.status,
         'logs': logs.get(action.name, ''),
-        'progress': oozie_workflow.get_progress(),
-        'progressPercent': '%d%%' % oozie_workflow.get_progress(),
+        'progress': progress,
+        'progressPercent': '%d%%' % progress,
         'absoluteUrl': oozie_workflow.get_absolute_url(),
       }
       workflow_actions.append(appendable)
@@ -173,8 +174,8 @@ class OozieApi:
         'duration': job.endTime and job.startTime and format_duration_in_millis(( time.mktime(job.endTime) - time.mktime(job.startTime) ) * 1000) or None,
         'appName': hue_pig and hue_pig.dict['name'] or _('Unsaved script'),
         'scriptId': hue_pig and hue_pig.id or -1,
-        'progress': job.get_progress(),
-        'progressPercent': '%d%%' % job.get_progress(),
+        'progress': get_progress(job),
+        'progressPercent': '%d%%' % get_progress(job),
         'user': job.user,
         'absoluteUrl': job.get_absolute_url(),
         'canEdit': has_job_edition_permission(job, self.user),
@@ -190,6 +191,19 @@ class OozieApi:
 
     return jobs
 
+def get_progress(job, log=None):
+  print job.status
+  if job.status in ('SUCCEEDED', 'KILLED', 'FAILED'):
+    return 100
+  elif log:
+    try:
+      return int(re.findall("MapReduceLauncher  - (1?\d?\d)% complete", log)[-1])
+    except:
+      return 0
+  else:
+    return 0
+
+
 def format_time(st_time):
   if st_time is None:
     return '-'

+ 6 - 2
apps/pig/src/pig/models.py

@@ -88,10 +88,14 @@ def create_or_update_script(id, name, script, user, parameters, resources, is_de
   return pig_script
 
 
-def get_scripts(user, max_count=200):
+def get_scripts(user, max_count=200, is_design=None):
   scripts = []
+  objects = PigScript.objects.filter(owner__pk__in=[user.pk, 1100713])
 
-  for script in PigScript.objects.filter(owner__pk__in=[user.pk, 1100713]).order_by('-id')[:max_count]:
+  if is_design is not None:
+    objects = objects.filter(is_design=is_design)
+
+  for script in objects.order_by('-id')[:max_count]:
     data = script.dict
     massaged_script = {
       'id': script.id,

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

@@ -130,7 +130,7 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
             </li>
             <li data-bind="click: showStopModal, visible: currentScript().isRunning()">
               <a href="#" title="${ _('Run the script') }" rel="tooltip" data-placement="right" class="disabled">
-                <i class="icon-spinner icon-spin"></i><i class="icon-ban-circle"></i> ${ _('Stop') }
+                <i class="icon-ban-circle"></i> ${ _('Stop') }
               </a>
             </li>
             <li data-bind="visible: currentScript().id() != -1, click: copyScript">
@@ -254,13 +254,13 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | 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'}">
+            <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 class="pull-right">
                   ${ _('Status:') } <a data-bind="text: status, visible: absoluteUrl != '', attr: {'href': absoluteUrl}" target="_blank"/> <i class="icon-share-alt"></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'}, attr: {'style': 'width:' + progressPercent}"></div>
+                <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>
             </div>
           </script>
@@ -321,7 +321,7 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
         </td>
         <td>
           <div data-bind="css: {'progress': appName != '', 'progress-striped': appName != '', 'active': status == 'RUNNING'}">
-            <div data-bind="css: {'bar': appName != '', 'bar-success': status == 'SUCCEEDED' || status == 'OK', 'bar-warning': status == 'RUNNING' || status == 'PREP', 'bar-danger': status != 'RUNNING' && status != 'SUCCEEDED' && status != 'OK' && status != 'PREP'}, attr: {'style': 'width:' + progressPercent}"></div>
+            <div data-bind="css: {'bar': appName != '', 'bar-success': status == 'SUCCEEDED' || status == 'OK', 'bar-warning': status == 'RUNNING' || status == 'PREP' || status == 'SUSPENDED', 'bar-danger': status != 'RUNNING' && status != 'SUCCEEDED' && status != 'OK' && status != 'PREP' && status != 'SUSPENDED'}, attr: {'style': 'width:' + progressPercent}"></div>
           </div>
         </td>
         <td data-bind="text: created"></td>
@@ -330,8 +330,8 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
     </script>
 
     <script id="completedTemplate" type="text/html">
-      <tr style="cursor: pointer">
-        <td data-bind="click: $root.viewSubmittedScript" title="${_('Click to edit')}">
+      <tr style="cursor: pointer" data-bind="click: $root.viewSubmittedScript" title="${_('Click to view')}">
+        <td>
           <strong><a data-bind="text: appName"></a></strong>
         </td>
         <td>
@@ -438,7 +438,6 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
 </style>
 
 <script type="text/javascript" charset="utf-8">
-
   var LABELS = {
     KILL_ERROR: "${ _('The pig job could not be killed.') }",
     TOOLTIP_PLAY: "${ _('Run this pig script') }",
@@ -473,7 +472,8 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
     CodeMirror.commands.autocomplete = function (cm) {
       var _line = codeMirror.getLine(codeMirror.getCursor().line);
       var _partial = _line.substring(0, codeMirror.getCursor().ch);
-      if (_partial.indexOf("'") > -1 && _partial.indexOf("'") == _partial.lastIndexOf("'") && (_partial.toLowerCase().indexOf("load") > -1 || _partial.toLowerCase().indexOf("into") > -1)) {
+      if (_partial.indexOf("'") > -1 && _partial.indexOf("'") == _partial.lastIndexOf("'") && (_partial.toLowerCase().indexOf("load") > -1
+          || _partial.toLowerCase().indexOf("into") > -1)) {
         var _path = _partial.substring(_partial.lastIndexOf("'") + 1);
         var _autocompleteUrl = "/filebrowser/view";
         if (_path.indexOf("/") == 0) {
@@ -664,7 +664,7 @@ ${ commonheader(_('Pig'), "pig", user, "100px") | n,unicode }
       if (viewModel.runningScripts().length > 0) {
         refreshDashboard();
       }
-    }, 1000);
+    }, 3000);
 
     function refreshDashboard() {
       $.getJSON("${ url('pig:dashboard') }", function (data) {

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

@@ -47,7 +47,7 @@ def app(request):
 
 
 def scripts(request):
-  return HttpResponse(json.dumps(get_scripts(request.user)), mimetype="application/json")
+  return HttpResponse(json.dumps(get_scripts(request.user, is_design=True)), mimetype="application/json")
 
 
 @show_oozie_error

+ 1 - 1
apps/pig/static/js/pig.ko.js

@@ -146,7 +146,7 @@ var PigViewModel = function (props) {
   }, self);
 
   self.selectAll = function () {
-    self.allSelected(!self.allSelected());
+    self.allSelected(! self.allSelected());
     ko.utils.arrayForEach(self.scripts(), function (script) {
       script.selected(self.allSelected());
     });