projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
14873: Custom JSON attributes that default to [] or {} when nil.
[arvados.git]
/
services
/
api
/
app
/
models
/
node.rb
diff --git
a/services/api/app/models/node.rb
b/services/api/app/models/node.rb
index bf1b636c52836bd54c75373c29fde51897e4b766..148dffc23074138af0d70008e2cc49dd8b344ca1 100644
(file)
--- a/
services/api/app/models/node.rb
+++ b/
services/api/app/models/node.rb
@@
-8,8
+8,12
@@
class Node < ArvadosModel
include HasUuid
include KindAndEtag
include CommonApiTemplate
include HasUuid
include KindAndEtag
include CommonApiTemplate
- serialize :info, Hash
- serialize :properties, Hash
+
+ # Posgresql JSONB columns should NOT be declared as serialized, Rails 5
+ # already know how to properly treat them.
+ attribute :properties, :jsonbHash, default: {}
+ attribute :info, :jsonbHash, default: {}
+
before_validation :ensure_ping_secret
after_update :dns_server_update
before_validation :ensure_ping_secret
after_update :dns_server_update
@@
-106,27
+110,7
@@
class Node < ArvadosModel
end
end
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|
# Record other basic stats
['total_cpu_cores', 'total_ram_mb', 'total_scratch_mb'].each do |key|
@@
-140,8
+124,30
@@
class Node < ArvadosModel
save!
end
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
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
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