1 class ContainerRequest < ArvadosModel
4 include CommonApiTemplate
6 serialize :properties, Hash
7 serialize :environment, Hash
8 serialize :mounts, Hash
9 serialize :runtime_constraints, Hash
10 serialize :command, Array
12 before_create :set_state_before_save
13 validate :validate_change_permitted
14 validate :validate_status
15 validate :validate_state_change
17 api_accessible :user, extend: :common do |t|
19 t.add :container_count_max
20 t.add :container_image
32 t.add :requesting_container_uuid
33 t.add :runtime_constraints
37 # Supported states for a container request
40 (Uncommitted = 'Uncommitted'),
41 (Committed = 'Committed'),
45 def set_state_before_save
46 self.state ||= Uncommitted
49 def validate_change_permitted
57 # only allow state and priority to change.
58 not (self.command_changed? or
59 self.container_count_max_changed? or
60 self.container_image_changed? or
61 self.container_uuid_changed? or
63 self.description_changed? or
64 self.environment_changed? or
65 self.expires_at_changed? or
66 self.filters_changed? or
67 self.mounts_changed? or
69 self.output_path_changed? or
70 self.properties_changed? or
71 self.requesting_container_uuid_changed? or
72 self.runtime_constraints_changed?)
79 errors.add :state, "Invalid update of container request in #{self.state} state"
85 if self.state.in?(States)
88 errors.add :state, "#{state.inspect} must be one of: #{States.inspect}"
93 def validate_state_change
95 if self.state_changed?
96 ok = case self.state_was
98 # Must go to Uncommitted
99 self.state == Uncommitted
101 # Must go to Committed
102 self.state == Committed
107 # Once in a final state, don't permit any more state changes
110 # Any other state transition is also invalid
114 errors.add :state, "invalid change from #{self.state_was} to #{self.state}"