Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
authorFuad Muhic <fmuhic@capeannenterprises.com>
Mon, 4 Dec 2017 16:11:07 +0000 (17:11 +0100)
committerFuad Muhic <fmuhic@capeannenterprises.com>
Mon, 4 Dec 2017 16:11:07 +0000 (17:11 +0100)
Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic@capeannenterprises.com>

services/api/app/models/container.rb
services/api/test/unit/container_request_test.rb

index 83765fb1dc5571b4454ff8143a1545321f34c91c..466adc0eefb573a08b18dff2d5280102ef448210 100644 (file)
@@ -31,6 +31,7 @@ class Container < ArvadosModel
   after_validation :assign_auth
   before_save :sort_serialized_attrs
   after_save :handle_completed
+  after_save :propagate_priority
 
   has_many :container_requests, :foreign_key => :container_uuid, :class_name => 'ContainerRequest', :primary_key => :uuid
   belongs_to :auth, :class_name => 'ApiClientAuthorization', :foreign_key => :auth_uuid, :primary_key => :uuid
@@ -93,6 +94,20 @@ class Container < ArvadosModel
     end
   end
 
+  def propagate_priority
+    if self.priority_changed?
+      act_as_system_user do
+         # Update the priority of child container requests to match new priority
+         # of the parent container.
+         ContainerRequest.where(requesting_container_uuid: self.uuid,
+                                state: ContainerRequest::Committed).each do |cr|
+           cr.priority = self.priority
+           cr.save
+         end
+       end
+    end
+  end
+
   # Create a new container (or find an existing one) to satisfy the
   # given container request.
   def self.resolve(req)
index e751d6158cdc2eb1b26fd3d80fa277839d7ad590..cecf7b818e7004f74fb4544033d1a6e636e55069 100644 (file)
@@ -293,6 +293,35 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_equal 0, c2.priority
   end
 
+
+  test "Container makes container request, then changes priority" do
+    set_user_from_auth :active
+    cr = create_minimal_req!(priority: 5, state: "Committed", container_count_max: 1)
+
+    c = Container.find_by_uuid cr.container_uuid
+    assert_equal 5, c.priority
+
+    cr2 = create_minimal_req!
+    cr2.update_attributes!(priority: 5, state: "Committed", requesting_container_uuid: c.uuid, command: ["echo", "foo2"], container_count_max: 1)
+    cr2.reload
+
+    c2 = Container.find_by_uuid cr2.container_uuid
+    assert_equal 5, c2.priority
+
+    act_as_system_user do
+      c.priority = 10
+      c.save!
+    end
+
+    cr.reload
+
+    cr2.reload
+    assert_equal 10, cr2.priority
+
+    c2.reload
+    assert_equal 10, c2.priority
+  end
+
   [
     ['running_container_auth', 'zzzzz-dz642-runningcontainr'],
     ['active_no_prefs', nil],