Merge branch '9617-reject-container-reqs-without-vcpus'
[arvados.git] / services / api / app / models / container_request.rb
index e84026a369120d8f9001cc60ec45865716ec4083..bf244bd907b4cf2a024ff1ff13e8032ab060bd56 100644 (file)
@@ -17,6 +17,7 @@ class ContainerRequest < ArvadosModel
   validates :command, :container_image, :output_path, :cwd, :presence => true
   validate :validate_state_change
   validate :validate_change
+  validate :validate_runtime_constraints
   after_save :update_priority
   before_create :set_requesting_container_uuid
 
@@ -170,6 +171,19 @@ class ContainerRequest < ArvadosModel
     end
   end
 
+  def validate_runtime_constraints
+    case self.state
+    when Committed
+      ['vcpus', 'ram'].each do |k|
+        if not (runtime_constraints.include? k and
+                runtime_constraints[k].is_a? Integer and
+                runtime_constraints[k] > 0)
+          errors.add :runtime_constraints, "#{k} must be a positive integer"
+        end
+      end
+    end
+  end
+
   def validate_change
     permitted = [:owner_uuid]