Merge branch 'master' into 4878-rerun-job
authorRadhika Chippada <radhika@curoverse.com>
Mon, 26 Jan 2015 21:17:28 +0000 (16:17 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Mon, 26 Jan 2015 21:17:28 +0000 (16:17 -0500)
apps/workbench/app/controllers/jobs_controller.rb
apps/workbench/app/views/jobs/_rerun_job_with_options_popup.html.erb [new file with mode: 0644]
apps/workbench/app/views/jobs/_show_job_buttons.html.erb
apps/workbench/app/views/jobs/rerun_job_with_options_popup.js.erb [new file with mode: 0644]
apps/workbench/app/views/jobs/show.html.erb
apps/workbench/config/routes.rb
apps/workbench/test/integration/jobs_test.rb
services/api/test/fixtures/jobs.yml

index 08fb94d2f085d4d7eb777f81cea43d84f9f2dbcf..2f618ee93bb5f07403062e79785018e2f55d428d 100644 (file)
@@ -82,4 +82,31 @@ class JobsController < ApplicationController
   def show_pane_list
     %w(Status Log Details Provenance Advanced)
   end
+
+  def rerun_job_with_options_popup
+    respond_to do |format|
+      format.js
+      format.html
+    end
+  end
+
+  def rerun_job_with_options
+    job_info = JSON.parse params['job_info']
+
+    @object = Job.new
+    @object.script = job_info['script']
+    @object.repository = job_info['repository']
+    @object.nondeterministic = job_info['nondeterministic']
+    @object.script_parameters = job_info['script_parameters']
+    @object.runtime_constraints = job_info['runtime_constraints']
+
+    if params['use_script'] == 'latest'
+      @object.script_version = job_info['supplied_script_version']
+    else
+      @object.script_version = job_info['script_version']
+    end
+
+    @object.save!
+    show
+  end
 end
diff --git a/apps/workbench/app/views/jobs/_rerun_job_with_options_popup.html.erb b/apps/workbench/app/views/jobs/_rerun_job_with_options_popup.html.erb
new file mode 100644 (file)
index 0000000..6d92edd
--- /dev/null
@@ -0,0 +1,47 @@
+<%
+  job_info = {}
+  job_info['script'] = params[:script]
+  job_info['script_version'] = params[:script_version]
+  job_info['repository'] = params[:repository]
+  job_info['supplied_script_version'] = params[:supplied_script_version]
+  job_info['nondeterministic'] = params[:nondeterministic]
+  job_info['script_parameters'] = params[:script_parameters]
+  job_info['runtime_constraints'] = params[:runtime_constraints]
+%>
+
+<div class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+  <div class="modal-dialog">
+    <div class="modal-content">
+      <%= form_tag rerun_job_with_options_path do |f| %>
+        <div class="modal-header">
+          <button type="button" class="close" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">&times;</button>
+          <div>
+            <div class="col-sm-6"> <h4 class="modal-title">Re-run job</h4> </div>
+          </div>
+          <br/>
+        </div>
+
+        <div class="modal-body">
+          <p> If this job is part of a pipeline, that pipeline would not know about the new job you are running.
+              If you want to update your pipeline results, please re-run the pipeline instead.
+          <p> The inputs and parameters will be the same as the current job.
+              Thus, the new job will not reflect any changes made to the pipeline that initiated this job. </p>
+          <div style="padding-left: 1em">
+            <%= radio_button_tag(:use_script, "latest", true) %>
+            <%= label_tag(:script_use_latest, "Use latest script version") %>
+            <p style="padding-left: 1em"> Use the current commit indicated by '<%=job_info['supplied_script_version']%>' in the '<%=job_info['repository']%>' repository.</p>
+            <%= radio_button_tag(:use_script, "same") %>
+            <%= label_tag(:script_use_same, "Use same script version as this run") %>
+            <p style="padding-left: 1em"> Use the same script version as the current job.</p>
+            <input type="hidden" name="job_info" value="<%=job_info.to_json%>">
+          </div>
+        </div>
+
+        <div class="modal-footer">
+          <button type="submit" class="btn btn-primary" name="rerun-with-options" value="RunningOnServer">Run now</button>
+          <button class="btn btn-default" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">Cancel</button>
+        </div>
+      <% end %>
+    </div>
+  </div>
+</div>
index 644da77425fe90bdc3c634c78d97e51099857cf1..aa5df3516f775673fe9360654fa300d525a7b153 100644 (file)
         <i class="fa fa-fw fa-gear"></i> Re-run same version
       <% end %>
     <% end %>
-  <% if @object.respond_to? :supplied_script_version and !@object.supplied_script_version.nil? and !@object.supplied_script_version.empty? and @object.script_version != @object.supplied_script_version%>
-      <%= form_tag '/jobs', style: "display:inline" do |f| %>
-      <% [:script, :repository, :supplied_script_version, :nondeterministic].each do |d| %>
-        <%= hidden_field :job, d, :value => @object[d] %>
-      <% end %>
-      <%= hidden_field :job, :script_version, :value => @object[:supplied_script_version] %>
-      <% [:script_parameters, :runtime_constraints].each do |d| %>
-        <%= hidden_field :job, d, :value => JSON.dump(@object[d]) %>
-      <% end %>
-      <%= button_tag ({class: 'btn btn-sm btn-primary', id: "re-run-latest-job-button",
-                       title: 'Re-run job using the latest script version'}) do%>
-        <i class="fa fa-fw fa-gear"></i> Re-run latest version
+    <% if @object.respond_to? :supplied_script_version and !@object.supplied_script_version.nil? and !@object.supplied_script_version.empty? and @object.script_version != @object.supplied_script_version%>
+      <%= link_to rerun_job_with_options_popup_path(script: @object[:script],
+                                                    script_version: @object[:script_version],
+                                                    repository: @object[:repository],
+                                                    supplied_script_version: @object[:supplied_script_version],
+                                                    nondeterministic: @object[:nondeterministic],
+                                                    script_parameters: @object[:script_parameters],
+                                                    runtime_constraints: @object[:runtime_constraints]),
+          {class: 'btn btn-sm btn-primary', :remote => true, 'data-toggle' =>  "modal",
+            'data-target' => '#rerun-job-with-options', return_to: request.url} do %>
+          <i class="fa fa-fw fa-gear"></i> Re-run with options...
       <% end %>
     <% end %>
-  <% end %>
 <% end %>
diff --git a/apps/workbench/app/views/jobs/rerun_job_with_options_popup.js.erb b/apps/workbench/app/views/jobs/rerun_job_with_options_popup.js.erb
new file mode 100644 (file)
index 0000000..ff2b64d
--- /dev/null
@@ -0,0 +1,2 @@
+$("#rerun-job-with-options-popup").html("<%= escape_javascript(render partial: 'rerun_job_with_options_popup') %>");
+$("#rerun-job-with-options-popup .modal").modal('show');
index 566014e4f328e256e81a8ba33d31794b41a6a29f..d6e2051500313566178b714179a11e1036ef7f36 100644 (file)
@@ -9,3 +9,4 @@
 
 <%= render partial: 'title_and_buttons' %>
 <%= render partial: 'content', layout: 'content_layout', locals: {pane_list: controller.show_pane_list }%>
+<div id="rerun-job-with-options-popup"></div>
index 6b29d0553d4f0903973f40f951fde82d99ab3144..964863aece622712ef9fd37ea37e773b5942cd8a 100644 (file)
@@ -12,6 +12,8 @@ ArvadosWorkbench::Application.routes.draw do
   get "users/setup" => 'users#setup', :as => :setup_user
   get "report_issue_popup" => 'actions#report_issue_popup', :as => :report_issue_popup
   post "report_issue" => 'actions#report_issue', :as => :report_issue
+  get "rerun-job-with-options-popup" => 'jobs#rerun_job_with_options_popup', :as => :rerun_job_with_options_popup
+  post "rerun-job-with-options" => 'jobs#rerun_job_with_options', :as => :rerun_job_with_options
   resources :nodes
   resources :humans
   resources :traits
index 716e7319874d56189b145acae6fd4c137a590f23..0de9149d1744d2268035b75f22887a2957b06845 100644 (file)
@@ -72,4 +72,50 @@ class JobsTest < ActionDispatch::IntegrationTest
     wait_for_ajax
     assert page.has_text? 'Showing only 100 bytes of this log'
   end
+
+  [
+    ['foobar', false, false, false],
+    ['job_with_latest_version', true, false, false],
+    ['job_with_latest_version', true, true, false],
+    ['job_with_latest_version', true, true, true],
+  ].each do |job_name, expect_options, use_options, click_option|
+    test "Rerun #{job_name} job, expect options #{expect_options},
+          use options #{use_options} and click option #{click_option}" do
+      need_javascript
+
+      job = api_fixture('jobs')[job_name]
+      visit page_with_token 'active', '/jobs/'+job['uuid']
+
+      assert_selector 'a,button', text: 'Re-run same version'
+      if expect_options
+        assert_text 'supplied_script_version: master'
+        assert_selector 'a,button', text: 'Re-run with options'
+      else
+        assert_text 'supplied_script_version: (none)'
+        assert_no_selector 'a,button', text: 'Re-run with options'
+      end
+
+      # Now re-run the job
+      if use_options
+        assert_triggers_dom_event 'shown.bs.modal' do
+          find('a,button', text: 'Re-run with options...').click
+        end
+        within('.modal-dialog') do
+          assert_selector 'a,button', text: 'Run now'
+          assert_selector 'a,button', text: 'Cancel'
+          page.choose('use_script_same') if click_option
+          find('button', text: 'Run now').click
+        end
+      else
+        find('a,button', text: 'Re-run same version').click
+      end
+
+      # We see Fiddlesticks, but let's make sure the correct script version is sought.
+      if use_options && !click_option
+        assert_text "Script version #{job['supplied_script_version']} does not resolve to a commit"
+      else
+        assert_text "Script version #{job['script_version']} does not resolve to a commit"
+      end
+    end
+  end
 end
index 888cb2af7f578e1dccd59251f8f8864b29995d24..2243339b75eb92e9649eff0b48d7c10439de1a40 100644 (file)
@@ -371,6 +371,34 @@ graph_stage3:
     input2: "stuff2"
   output: ea10d51bcf88862dbcc36eb292017dfd+45
 
+job_with_latest_version:
+  uuid: zzzzz-8i9sb-nj8ioxnrvjtyk2b
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  cancelled_at: ~
+  cancelled_by_user_uuid: ~
+  cancelled_by_client_uuid: ~
+  script: hash
+  repository: foo
+  script_version: 7def43a4d3f20789dda4700f703b5514cc3ed250
+  supplied_script_version: master
+  script_parameters:
+    input: 1f4b0bc7583c2a7f9102c395f4ffc5e3+45
+  created_at: <%= 4.minute.ago.to_s(:db) %>
+  started_at: <%= 3.minute.ago.to_s(:db) %>
+  finished_at: <%= 2.minute.ago.to_s(:db) %>
+  running: false
+  success: true
+  output: fa7aeb5140e2848d39b416daeef4ffc5+45
+  priority: 0
+  log: ea10d51bcf88862dbcc36eb292017dfd+45
+  is_locked_by_uuid: ~
+  tasks_summary:
+    failed: 0
+    todo: 0
+    running: 0
+    done: 1
+  runtime_constraints: {}
+  state: Complete
 
 # Test Helper trims the rest of the file