[ARVADOS] created: 716fc68b444bb4d43ecad56bcb90e9ebf4bda854
Git user
git at public.curoverse.com
Thu Sep 1 20:53:37 EDT 2016
at 716fc68b444bb4d43ecad56bcb90e9ebf4bda854 (commit)
commit 716fc68b444bb4d43ecad56bcb90e9ebf4bda854
Author: radhika <radhika at curoverse.com>
Date: Thu Sep 1 20:42:16 2016 -0400
9898: add lock and unlock endpoints to containers_controller.
diff --git a/services/api/app/controllers/arvados/v1/containers_controller.rb b/services/api/app/controllers/arvados/v1/containers_controller.rb
index 21ee7ef..0da228f 100644
--- a/services/api/app/controllers/arvados/v1/containers_controller.rb
+++ b/services/api/app/controllers/arvados/v1/containers_controller.rb
@@ -19,4 +19,15 @@ class Arvados::V1::ContainersController < ApplicationController
super
end
end
+
+ def lock
+ @object.lock
+ show
+ end
+
+ def unlock
+ reload_object_before_update
+ @object.update_attributes! state: Container::Queued
+ show
+ end
end
diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 4c77008..a57fbf0 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -76,6 +76,15 @@ class Container < ArvadosModel
end
end
+ def lock
+ with_lock do
+ if self.state == Queued
+ self.state = Locked
+ self.save!
+ end
+ end
+ end
+
protected
def fill_field_defaults
diff --git a/services/api/config/routes.rb b/services/api/config/routes.rb
index 7bf7580..3638c72 100644
--- a/services/api/config/routes.rb
+++ b/services/api/config/routes.rb
@@ -31,6 +31,8 @@ Server::Application.routes.draw do
resources :job_tasks
resources :containers do
get 'auth', on: :member
+ post 'lock', on: :member
+ post 'unlock', on: :member
end
resources :container_requests
resources :jobs do
diff --git a/services/api/test/functional/arvados/v1/containers_controller_test.rb b/services/api/test/functional/arvados/v1/containers_controller_test.rb
index d9f7d96..28ffbbc 100644
--- a/services/api/test/functional/arvados/v1/containers_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/containers_controller_test.rb
@@ -49,4 +49,26 @@ class Arvados::V1::ContainersControllerTest < ActionController::TestCase
assert_response :success
assert_nil json_response['auth']
end
+
+ test "lock and unlock container" do
+ # lock container
+ authorize_with :dispatch1
+ post :lock, {id: containers(:queued).uuid}
+ assert_response :success
+ container = Container.where(uuid: containers(:queued).uuid).first
+ assert_equal 'Locked', container.state
+ assert_not_nil container.locked_by_uuid
+ assert_not_nil container.auth_uuid
+
+ # unlock container
+ @test_counter = 0 # Reset executed action counter
+ @controller = Arvados::V1::ContainersController.new
+ authorize_with :dispatch1
+ post :unlock, {id: container.uuid}
+ assert_response :success
+ container = Container.where(uuid: container.uuid).first
+ assert_equal 'Queued', container.state
+ assert_nil container.locked_by_uuid
+ assert_nil container.auth_uuid
+ end
end
diff --git a/services/api/test/unit/container_test.rb b/services/api/test/unit/container_test.rb
index 24186e8..c0b95f3 100644
--- a/services/api/test/unit/container_test.rb
+++ b/services/api/test/unit/container_test.rb
@@ -112,10 +112,13 @@ class ContainerTest < ActiveSupport::TestCase
refute c.update_attributes(state: Container::Complete), "not locked"
c.reload
- assert c.update_attributes(state: Container::Locked), show_errors(c)
+ assert c.lock, show_errors(c)
assert c.locked_by_uuid
assert c.auth_uuid
+ refute c.lock, "already locked"
+ c.reload
+
assert c.update_attributes(state: Container::Queued), show_errors(c)
refute c.locked_by_uuid
refute c.auth_uuid
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list