[ARVADOS] updated: d4939c581f629a19220bc5b469fed98462b2b7eb
git at public.curoverse.com
git at public.curoverse.com
Wed Dec 9 15:48:43 EST 2015
Summary of changes:
services/api/app/models/container.rb | 27 ++++++++++--------------
services/api/app/models/container_request.rb | 16 ++++++++------
services/api/test/unit/container_request_test.rb | 20 ++----------------
3 files changed, 23 insertions(+), 40 deletions(-)
via d4939c581f629a19220bc5b469fed98462b2b7eb (commit)
from ce6f582e7e1d5b927aeee0aab3def7ab8a5cae4f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit d4939c581f629a19220bc5b469fed98462b2b7eb
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Wed Dec 9 15:48:37 2015 -0500
6429: Complete/Cancelled containers finalize associated container requests;
container requests update priority for associated containers.
diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 15bbbe0..79c9868 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -17,7 +17,6 @@ class Container < ArvadosModel
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
@@ -151,22 +150,18 @@ class Container < ArvadosModel
# 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
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 1011f6f..4e76a0e 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -145,12 +145,16 @@ class ContainerRequest < ArvadosModel
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
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index 6d1a576..6470b78 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -199,7 +199,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
end
- test "Container cancel process tree" do
+ test "Container request finalize" do
set_user_from_auth :active_trustedclient
c = ContainerRequest.new
c.state = "Committed"
@@ -210,31 +210,15 @@ class ContainerRequestTest < ActiveSupport::TestCase
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
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list