X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e7672a0b679659d6ba90d23b4e102fba747fa9ef..080c940d7a8134a6e277a53b7e45eb27e2b2c87f:/services/api/app/models/node.rb diff --git a/services/api/app/models/node.rb b/services/api/app/models/node.rb index 8eb40f9fbb..3d8b91b4b6 100644 --- a/services/api/app/models/node.rb +++ b/services/api/app/models/node.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'tempfile' class Node < ArvadosModel @@ -102,27 +106,7 @@ class Node < ArvadosModel end end - # Assign slot_number - if self.slot_number.nil? - while true - n = self.class.available_slot_number - if n.nil? - raise "No available node slots" - end - self.slot_number = n - begin - self.save! - break - rescue ActiveRecord::RecordNotUnique - # try again - end - end - end - - # Assign hostname - if self.hostname.nil? and Rails.configuration.assign_node_hostname - self.hostname = self.class.hostname_for_slot(self.slot_number) - end + assign_slot # Record other basic stats ['total_cpu_cores', 'total_ram_mb', 'total_scratch_mb'].each do |key| @@ -136,8 +120,30 @@ class Node < ArvadosModel save! end + def assign_slot + return if self.slot_number.andand > 0 + while true + self.slot_number = self.class.available_slot_number + if self.slot_number.nil? + raise "No available node slots" + end + begin + save! + return assign_hostname + rescue ActiveRecord::RecordNotUnique + # try again + end + end + end + protected + def assign_hostname + if self.hostname.nil? and Rails.configuration.assign_node_hostname + self.hostname = self.class.hostname_for_slot(self.slot_number) + end + end + def self.available_slot_number # Join the sequence 1..max with the nodes table. Return the first # (i.e., smallest) value that doesn't match the slot_number of any