[ARVADOS] updated: 2.1.0-222-gf693516a9

Git user git at public.arvados.org
Wed Dec 30 14:56:07 UTC 2020


Summary of changes:
 services/api/app/models/arvados_model.rb           | 10 +++++++
 services/api/app/models/container_request.rb       | 31 ++++++++++++++++++++++
 .../v1/container_requests_controller_test.rb       | 22 +++++++++++++++
 3 files changed, 63 insertions(+)

       via  f693516a9f47903e791b3e1c918fcbb6ebf46110 (commit)
      from  d5daf2f717d4021aec77e6cd7d36bcd9b849958e (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 f693516a9f47903e791b3e1c918fcbb6ebf46110
Author: Nico Cesar <nico at nicocesar.com>
Date:   Wed Dec 30 09:55:11 2020 -0500

    Added set_defaults to arvados_model to handle zero value in attrs
    
    Arvados-DCO-1.1-Signed-off-by: Nico Cesar <nico at curii.com>

diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 6a0a58f08..e12ed4b89 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -31,6 +31,7 @@ class ArvadosModel < ApplicationRecord
   before_validation :normalize_collection_uuids
   before_validation :set_default_owner
   validate :ensure_valid_uuids
+  after_find :set_defaults
 
   # Note: This only returns permission links. It does not account for
   # permissions obtained via user.is_admin or
@@ -46,6 +47,15 @@ class ArvadosModel < ApplicationRecord
   # penalty.
   attr_accessor :async_permissions_update
 
+  # set_defaults will fill out default values that are not in the database
+  # this is meant to be implemented in the children as needed.
+  def set_defaults
+    ## to do this correctly this is an example:
+    ## attributes["runtime_constraints"]["keep_cache_ram"] = 0
+    ## self.clear_attribute_changes(["runtime_constraints"])
+    ## super  # <- we should call arvados_model's set_defaults() 
+  end
+
   # Ignore listed attributes on mass assignments
   def self.protected_attributes
     []
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 2ba175fd9..8c1210ab9 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -97,6 +97,19 @@ class ContainerRequest < ArvadosModel
   :runtime_constraints, :state, :container_uuid, :use_existing,
   :scheduling_parameters, :secret_mounts, :output_name, :output_ttl]
 
+  AttrsRuntimeConstraintsDefaults = {
+    "vcpus"=>0,
+    "ram"=>0,
+    "api"=>false,
+    "keep_cache_ram"=>0
+  }
+
+  AttrsSchedulingParametersDefaults = {
+    "max_run_time"=>0,
+    "partitions"=>nil,
+    "preemptible"=>false
+  }
+
   def self.limit_index_columns_read
     ["mounts"]
   end
@@ -443,6 +456,24 @@ class ContainerRequest < ArvadosModel
     super(permitted)
   end
 
+  def set_defaults
+    # this will fill out default values that are not in the database,
+    # see https://dev.arvados.org/issues/17014#note-28 for details
+
+    AttrsRuntimeConstraintsDefaults.each do |key, value|
+      if !self.runtime_constraints.key?(key)
+        attributes["runtime_constraints"][key] = value
+      end
+    end
+    AttrsSchedulingParametersDefaults.each do |key, value|
+      if !self.scheduling_parameters.key?(key)
+        attributes["scheduling_parameters"][key] = value
+      end
+    end
+    self.clear_attribute_changes(["runtime_constraints","scheduling_parameters"])
+    super
+  end
+
   def secret_mounts_key_conflict
     secret_mounts.each do |k, v|
       if mounts.has_key?(k)
diff --git a/services/api/test/functional/arvados/v1/container_requests_controller_test.rb b/services/api/test/functional/arvados/v1/container_requests_controller_test.rb
index 95c477f41..ceb94fe92 100644
--- a/services/api/test/functional/arvados/v1/container_requests_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/container_requests_controller_test.rb
@@ -62,6 +62,28 @@ class Arvados::V1::ContainerRequestsControllerTest < ActionController::TestCase
     assert_equal 'bar', req.secret_mounts['/foo']['content']
   end
 
+  test "runtime constraints with default values" do
+    authorize_with :active
+    req = container_requests(:queued)
+
+    patch :update, params: {
+      id: req.uuid,
+      container_request: {
+        state: 'Final',
+        priority: 0,
+        runtime_constraints: {
+          'vcpus' => 1,
+          'ram' => 123,
+          'keep_cache_ram' => 0,
+        },
+        scheduling_parameters: {
+          "preemptible"=>false
+        }
+      },
+    }
+    assert_response :success
+  end
+
   test "update without deleting secret_mounts" do
     authorize_with :active
     req = container_requests(:uncommitted)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list