浏览代码

HUE-69: JobBrowser: Kill Job not displaying an OK on a succesful kill and double-click behavior not enabled.

Philip Zeyliger 15 年之前
父节点
当前提交
b5356d1e60

+ 3 - 3
apps/jobbrowser/src/jobbrowser/templates/job.mako

@@ -31,11 +31,11 @@
     </thead>
     <tbody>
       % for task in tasks:
-        <tr>
+        <tr data-dblclick-delegate="{'dblclick_loads':'.view_task'}">
           <td class="task_table_id">${task.taskId_short}</td>
           <td class="task_table_type">${task.taskType}</td>
-          <td class="jtask_view_col"><a class="frame_tip jtask_view jt_slide_right" title="View this task"
-                 href="${ url('jobbrowser.views.single_task', jobid=job.jobId, taskid=task.taskId) }"></a></td>
+          <td class="jtask_view_col"><a class="frame_tip jtask_view jt_slide_right view_task" title="View this task"
+                 href="${ url('jobbrowser.views.single_task', jobid=job.jobId, taskid=task.taskId) }">View</a></td>
         </tr>
       % endfor
     </tbody>

+ 6 - 3
apps/jobbrowser/src/jobbrowser/templates/jobs.mako

@@ -16,6 +16,7 @@
 <%
   from jobbrowser.views import get_state_link
   from desktop import appmanager
+  from django.template.defaultfilters import urlencode
 %>
 <%namespace name="comps" file="jobbrowser_components.mako" />
 <%def name="get_state(option, state)">
@@ -74,7 +75,7 @@
               </tr>
             % endif
             % for job in jobs:
-            <tr>
+            <tr data-dblclick-delegate="{'dblclick_loads':'.view_this_job'}">
               <td>${job.jobName}
                   <div class="jt_jobid">${job.jobId_short}</div>
               </td>
@@ -95,10 +96,12 @@
               <td>${job.startTimeFormatted}</td>
               <td>
                 % if job.status.lower() == 'running' or job.status.lower() == 'pending':
-                  <a href="${url('jobbrowser.views.kill_job', jobid=job.jobId)}" class="frame_tip jt_kill confirm_and_post" title="Kill this job">kill</a>
+                  % if request.user.is_superuser or request.user.username == job.user:
+                    <a href="${url('jobbrowser.views.kill_job', jobid=job.jobId)}?next=${request.get_full_path()|urlencode}" class="frame_tip jt_kill confirm_and_post" title="Kill this job">kill</a>
+                  % endif
                 % endif
               </td>
-              <td><a href="${url('jobbrowser.views.single_job', jobid=job.jobId)}" class="frame_tip jt_view jt_slide_right" title="View this job">view</a></td>
+              <td><a href="${url('jobbrowser.views.single_job', jobid=job.jobId)}" class="frame_tip jt_view jt_slide_right view_this_job" title="View this job">view</a></td>
             </tr>
             % endfor
           </tbody>

+ 2 - 2
apps/jobbrowser/src/jobbrowser/templates/task.mako

@@ -59,7 +59,7 @@
               </thead>
               <tbody>
                 % for attempt in task.attempts:
-                 <tr>
+                 <tr data-dblclick-delegate="{'dblclick_loads':'.view_attempt'}">
                    <td>${attempt.attemptId_short}</td>
                    <td>${"%d" % (attempt.progress * 100)}%</td>
                    <td><span class="status_link ${attempt.state}">${attempt.state}</span></td>
@@ -71,7 +71,7 @@
                    <td>${attempt.shuffleFinishTimeFormatted}</td>
                    <td>${attempt.sortFinishTimeFormatted}</td>
                    <td>${attempt.mapFinishTimeFormatted}</td>
-                   <td><a class="frame_tip jtask_view jt_slide_right" title="View this attempt"
+                   <td><a class="frame_tip jtask_view jt_slide_right view_attempt" title="View this attempt"
                           href="${ url('jobbrowser.views.single_task_attempt', jobid=joblnk.jobId, taskid=task.taskId, attemptid=attempt.attemptId) }"></a></td>
                  </tr>
                 % endfor

+ 2 - 2
apps/jobbrowser/src/jobbrowser/templates/tasks.mako

@@ -105,7 +105,7 @@
       </thead>
       <tbody>
         %for t in page.object_list:
-         <tr>
+         <tr data-dblclick-delegate="{'dblclick_loads':'.view_task'}">
             <td>${t.taskId_short}</td>
             <td>${t.taskType}</td>
             <td>${"%d" % (t.progress * 100)}%</td>
@@ -115,7 +115,7 @@
             <td>${t.mostRecentState}</td>
             <td>${t.execStartTimeFormatted}</td>
             <td>${t.execFinishTimeFormatted}</td>
-            <td><a href="/jobbrowser/jobs/${jobid}/tasks/${t.taskId}" class="jt_slide_right">Attempts</a></td>
+            <td><a href="/jobbrowser/jobs/${jobid}/tasks/${t.taskId}" class="view_task jt_slide_right">Attempts</a></td>
          </tr>
         %endfor
       </tbody>

+ 7 - 0
apps/jobbrowser/src/jobbrowser/tests.py

@@ -230,8 +230,15 @@ class TestJobBrowserWithHadoop(object):
     time.sleep(15)                      # 15 seconds should be enough to start the job
     hadoop_job_id = get_hadoop_job_id(self.jobsubd, job_id)
 
+    client2 = make_logged_in_client('test_non_superuser', is_superuser=False)
+    response = client2.post('/jobbrowser/jobs/%s/kill' % (hadoop_job_id,))
+    assert_equal("Permission denied.  User test_non_superuser cannot delete user test's job.",
+      response.context["error"])
+
     self.client.post('/jobbrowser/jobs/%s/kill' % (hadoop_job_id,))
 
+  
+
     # It should say killed
     response = self.client.get('/jobbrowser/jobs/%s' % (hadoop_job_id,))
     html = response.content.lower()

+ 7 - 2
apps/jobbrowser/src/jobbrowser/views.py

@@ -26,6 +26,8 @@ from urllib import quote_plus
 from desktop.lib.paginator import Paginator
 from desktop.lib.django_util import render_json, MessageException, render
 from desktop.lib.django_util import copy_query_dict
+from django.http import HttpResponseRedirect
+
 from desktop.log.access import access_warn, access_log_level
 from desktop.views import register_status_bar_view
 from hadoop.api.jobtracker.ttypes import ThriftJobPriority
@@ -102,7 +104,7 @@ def kill_job(request, jobid):
   if job.user != request.user.username and not request.user.is_superuser:
     access_warn(request, 'Insufficient permission')
     raise MessageException("Permission denied.  User %s cannot delete user %s's job." %
-                           (request.user.username, job.profile.user))
+                           (request.user.username, job.user))
 
   job.kill()
   cur_time = time.time()
@@ -110,7 +112,10 @@ def kill_job(request, jobid):
     job = Job.from_id(jt=request.jt, jobid=jobid)
 
     if job.status not in ["RUNNING", "QUEUED"]:
-      return render_json({})
+      if request.REQUEST.get("next"):
+        return HttpResponseRedirect(request.REQUEST.get("next"))
+      else:
+        raise MessageException("Job Killed")
     time.sleep(1)
     job = Job.from_id(jt=request.jt, jobid=jobid)