Merge remote-tracking branch 'origin/master' into origin-2228-check-filter-uuid-columns
[arvados.git] / services / api / app / controllers / arvados / v1 / jobs_controller.rb
index a403356d8ea638f100e5e50b1d442174e215d2b9..40f2def5dcbfd3a7546e55e68ebfcdc3547f4961 100644 (file)
@@ -6,6 +6,14 @@ class Arvados::V1::JobsController < ApplicationController
   skip_before_filter :render_404_if_no_object, :only => :queue
 
   def create
+    [:repository, :script, :script_version, :script_parameters].each do |r|
+      if !resource_attrs[r]
+        return render json: {
+          :error => "#{r} attribute must be specified"
+        }, status: :unprocessable_entity
+      end
+    end
+
     r = Commit.find_commit_range(current_user,
                                  resource_attrs[:repository],
                                  resource_attrs[:minimum_script_version],
@@ -14,14 +22,24 @@ class Arvados::V1::JobsController < ApplicationController
     if !resource_attrs[:nondeterministic] and !resource_attrs[:no_reuse]
       # Search for jobs where the script_version is in the list of commits
       # returned by find_commit_range
+      @object = nil
       Job.readable_by(current_user).where(script: resource_attrs[:script],
                                           script_version: r).
         each do |j|
-        if j.nondeterministic != true and 
-            j.success != false and 
+        if j.nondeterministic != true and
+            j.success != false and
             j.script_parameters == resource_attrs[:script_parameters]
-          # We can re-use this job
-          @object = j
+          # Record the first job in the list
+          if !@object
+            @object = j
+          end
+          # Ensure that all candidate jobs actually did produce the same output
+          if @object.output != j.output
+            @object = nil
+            break
+          end
+        end
+        if @object
           return show
         end
       end
@@ -31,7 +49,6 @@ class Arvados::V1::JobsController < ApplicationController
     end
 
     # Don't pass these on to activerecord
-    resource_attrs.delete(:repository)
     resource_attrs.delete(:minimum_script_version)
     resource_attrs.delete(:exclude_script_versions)
     resource_attrs.delete(:no_reuse)
@@ -40,7 +57,7 @@ class Arvados::V1::JobsController < ApplicationController
 
   def cancel
     reload_object_before_update
-    @object.update_attributes cancelled_at: Time.now
+    @object.update_attributes! cancelled_at: Time.now
     show
   end