1 require 'whitelist_update'
3 class ContainerRequest < ArvadosModel
6 include CommonApiTemplate
7 include WhitelistUpdate
9 serialize :properties, Hash
10 serialize :environment, Hash
11 serialize :mounts, Hash
12 serialize :runtime_constraints, Hash
13 serialize :command, Array
15 before_validation :fill_field_defaults, :if => :new_record?
16 validates :command, :container_image, :output_path, :cwd, :presence => true
17 validate :validate_change
19 api_accessible :user, extend: :common do |t|
21 t.add :container_count_max
22 t.add :container_image
34 t.add :requesting_container_uuid
35 t.add :runtime_constraints
39 # Supported states for a container request
42 (Uncommitted = 'Uncommitted'),
43 (Committed = 'Committed'),
49 def fill_field_defaults
50 self.state ||= Uncommitted
51 self.environment ||= {}
52 self.runtime_constraints ||= {}
59 permitted = [:owner_uuid]
63 # Permit updating most fields
64 permitted.push :command, :container_count_max,
65 :container_image, :cwd, :description, :environment,
66 :filters, :mounts, :name, :output_path, :priority,
67 :properties, :requesting_container_uuid, :runtime_constraints,
70 if self.container_uuid_changed? and (current_user.andand.is_admin or self.container_uuid.nil?)
71 permitted.push :container_uuid
75 # Can only update priority, container count.
76 permitted.push :priority, :container_count_max
78 if self.state_changed?
79 if self.state_was == Uncommitted
82 errors.add :state, "Can only go from Uncommitted to Committed"
86 if self.container_uuid_changed? and current_user.andand.is_admin
87 permitted.push :container_uuid
91 if self.state_changed?
92 if self.state_was == Committed
95 errors.add :state, "Can only go from Committed to Final"
98 errors.add "Cannot update record in Final state"
102 errors.add :state, "Invalid state #{self.state}"
105 check_update_whitelist permitted