validate :validate_state_change
validate :validate_change
after_save :request_finalize
- after_save :process_tree_priority
has_many :container_requests, :foreign_key => :container_uuid, :class_name => 'ContainerRequest', :primary_key => :uuid
# that are associated with this container.
if self.state_changed? and [Complete, Cancelled].include? self.state
act_as_system_user do
- # Note using update_all skips model validation and callbacks.
- ContainerRequest.update_all({:state => ContainerRequest::Final}, ['container_uuid=?', uuid])
- end
- end
- end
+ # Try to close container requests associated with this container
+ ContainerRequest.where(container_uuid: uuid,
+ :state => ContainerRequest::Committed).each do |cr|
+ cr.state = ContainerRequest::Final
+ cr.save
+ end
- def process_tree_priority
- # This container is cancelled so cancel any container requests made by this
- # container.
- if self.priority_changed? and self.priority == 0
- # This could propagate any parent priority to the children (not just
- # priority 0)
- act_as_system_user do
- ContainerRequest.where(requesting_container_uuid: uuid).each do |cr|
- cr.priority = self.priority
- cr.save!
+ # Try to close any outstanding container requests made by this container.
+ ContainerRequest.where(requesting_container_uuid: uuid,
+ :state => ContainerRequest::Committed).each do |cr|
+ cr.state = ContainerRequest::Final
+ cr.save
end
end
end
end
def update_priority
- if self.state == Committed and (self.state_changed? or
- self.priority_changed? or
- self.container_uuid_changed?)
- c = Container.find_by_uuid self.container_uuid
- act_as_system_user do
- c.update_priority!
+ if [Committed, Final].include? self.state and (self.state_changed? or
+ self.priority_changed? or
+ self.container_uuid_changed?)
+ [self.container_uuid_was, self.container_uuid].each do |cuuid|
+ unless cuuid.nil?
+ c = Container.find_by_uuid cuuid
+ act_as_system_user do
+ c.update_priority!
+ end
+ end
end
end
end
end
- test "Container cancel process tree" do
+ test "Container request finalize" do
set_user_from_auth :active_trustedclient
c = ContainerRequest.new
c.state = "Committed"
c.priority = 5
c.save!
- c2 = ContainerRequest.new
- c2.state = "Committed"
- c2.container_image = "img"
- c2.command = ["foo", "bar"]
- c2.output_path = "/tmp"
- c2.cwd = "/tmp"
- c2.priority = 10
- c2.requesting_container_uuid = c.container_uuid
- c2.save!
-
t = Container.find_by_uuid c.container_uuid
assert_equal 5, t.priority
- t2 = Container.find_by_uuid c2.container_uuid
- assert_equal 10, t2.priority
-
- c.priority = 0
+ c.state = "Final"
c.save!
t.reload
assert_equal 0, t.priority
- t2.reload
- assert_equal 0, t2.priority
-
end