[ARVADOS] updated: 06f40b3d477f3ab1c834d9671808c3da02ca7dfd
Git user
git at public.curoverse.com
Thu Oct 13 11:49:57 EDT 2016
Summary of changes:
services/api/app/models/container.rb | 8 +++++--
services/api/app/models/container_request.rb | 14 ++++++++++--
services/api/test/unit/container_request_test.rb | 27 ++++++++++++++++++++++++
3 files changed, 45 insertions(+), 4 deletions(-)
via 06f40b3d477f3ab1c834d9671808c3da02ca7dfd (commit)
via 8f794ab549d05adba6774ab91066b55f719c181a (commit)
from 29389eac8cf5f7c9f210579b6d74ca9c84f39ad4 (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 06f40b3d477f3ab1c834d9671808c3da02ca7dfd
Merge: 29389ea 8f794ab
Author: Tom Clegg <tom at curoverse.com>
Date: Thu Oct 13 11:14:40 2016 -0400
Merge branch '9848-finalize-on-reuse' closes #9848
commit 8f794ab549d05adba6774ab91066b55f719c181a
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Oct 11 17:21:06 2016 -0400
9848: Finalize container request immediately if resolving to an already-finished container.
diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 43c5b30..3a16e30 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -166,6 +166,10 @@ class Container < ArvadosModel
uuids: uuid_list)
end
+ def final?
+ [Complete, Cancelled].include?(self.state)
+ end
+
protected
def fill_field_defaults
@@ -305,7 +309,7 @@ class Container < ArvadosModel
def handle_completed
# This container is finished so finalize any associated container requests
# that are associated with this container.
- if self.state_changed? and [Complete, Cancelled].include? self.state
+ if self.state_changed? and self.final?
act_as_system_user do
if self.state == Cancelled
@@ -337,7 +341,7 @@ class Container < ArvadosModel
# Notify container requests associated with this container
ContainerRequest.where(container_uuid: uuid,
state: ContainerRequest::Committed).each do |cr|
- cr.container_completed!
+ cr.finalize!
end
# Try to cancel any outstanding container requests made by this container.
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index a588c86..696b873 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -19,6 +19,7 @@ class ContainerRequest < ArvadosModel
validate :validate_change
validate :validate_runtime_constraints
after_save :update_priority
+ after_save :finalize_if_needed
before_create :set_requesting_container_uuid
api_accessible :user, extend: :common do |t|
@@ -65,10 +66,19 @@ class ContainerRequest < ArvadosModel
%w(modified_by_client_uuid container_uuid requesting_container_uuid)
end
+ def finalize_if_needed
+ if state == Committed && Container.find_by_uuid(container_uuid).final?
+ reload
+ act_as_system_user do
+ finalize!
+ end
+ end
+ end
+
# Finalize the container request after the container has
# finished/cancelled.
- def container_completed!
- update_attributes!(state: ContainerRequest::Final)
+ def finalize!
+ update_attributes!(state: Final)
c = Container.find_by_uuid(container_uuid)
['output', 'log'].each do |out_type|
pdh = c.send(out_type)
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index 3b17574..1c5c7ae 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -481,4 +481,31 @@ class ContainerRequestTest < ActiveSupport::TestCase
assert_equal prev_container_uuid, cr.container_uuid
end
+ test "Finalize committed request when reusing a finished container" do
+ set_user_from_auth :active
+ cr = create_minimal_req!(priority: 1, state: ContainerRequest::Committed)
+ cr.reload
+ assert_equal ContainerRequest::Committed, cr.state
+ act_as_system_user do
+ c = Container.find_by_uuid(cr.container_uuid)
+ c.update_attributes!(state: Container::Locked)
+ c.update_attributes!(state: Container::Running)
+ c.update_attributes!(state: Container::Complete,
+ exit_code: 0,
+ output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
+ log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
+ end
+ cr.reload
+ assert_equal ContainerRequest::Final, cr.state
+
+ cr2 = create_minimal_req!(priority: 1, state: ContainerRequest::Committed)
+ assert_equal cr.container_uuid, cr2.container_uuid
+ assert_equal ContainerRequest::Final, cr2.state
+
+ cr3 = create_minimal_req!(priority: 1, state: ContainerRequest::Uncommitted)
+ assert_equal ContainerRequest::Uncommitted, cr3.state
+ cr3.update_attributes!(state: ContainerRequest::Committed)
+ assert_equal cr.container_uuid, cr3.container_uuid
+ assert_equal ContainerRequest::Final, cr3.state
+ end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list