projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
16007: Add TrashedGroup model
[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..d200bb80110869ade17386d3ebbac9cf9b8de979 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
@@
-35,7
+39,7
@@
class Node < ArvadosModel
api_accessible :superuser, :extend => :user do |t|
t.add :first_ping_at
t.add :info
api_accessible :superuser, :extend => :user do |t|
t.add :first_ping_at
t.add :info
- t.add lambda { |x| Rails.configuration.
compute_node_nameserver
s }, :as => :nameservers
+ t.add lambda { |x| Rails.configuration.
Containers.SLURM.Managed.ComputeNodeNameservers.key
s }, :as => :nameservers
end
after_initialize do
end
after_initialize do
@@
-43,7
+47,7
@@
class Node < ArvadosModel
end
def domain
end
def domain
- super || Rails.configuration.
compute_node_d
omain
+ super || Rails.configuration.
Containers.SLURM.Managed.ComputeNodeD
omain
end
def api_job_uuid
end
def api_job_uuid
@@
-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.Containers.SLURM.Managed.AssignNodeHostname
+ 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
@@
-153,7
+159,7
@@
class Node < ArvadosModel
# query label:
'Node.available_slot_number',
# [col_id, val] for $1 vars:
# query label:
'Node.available_slot_number',
# [col_id, val] for $1 vars:
- [[nil, Rails.configuration.
max_compute_node
s]],
+ [[nil, Rails.configuration.
Containers.MaxComputeVM
s]],
).rows.first.andand.first
end
).rows.first.andand.first
end
@@
-188,24
+194,25
@@
class Node < ArvadosModel
template_vars = {
hostname: hostname,
template_vars = {
hostname: hostname,
- uuid_prefix: Rails.configuration.
uuid_prefix
,
+ uuid_prefix: Rails.configuration.
ClusterID
,
ip_address: ip_address,
ptr_domain: ptr_domain,
}
ip_address: ip_address,
ptr_domain: ptr_domain,
}
- if Rails.configuration.dns_server_conf_dir and Rails.configuration.dns_server_conf_template
+ if (!Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir.to_s.empty? and
+ !Rails.configuration.Containers.SLURM.Managed.DNSServerConfTemplate.to_s.empty?)
tmpfile = nil
begin
begin
tmpfile = nil
begin
begin
- template = IO.read(Rails.configuration.
dns_server_conf_t
emplate)
+ template = IO.read(Rails.configuration.
Containers.SLURM.Managed.DNSServerConfT
emplate)
rescue IOError, SystemCallError => e
rescue IOError, SystemCallError => e
- logger.error "Reading #{Rails.configuration.
dns_server_conf_t
emplate}: #{e.message}"
+ logger.error "Reading #{Rails.configuration.
Containers.SLURM.Managed.DNSServerConfT
emplate}: #{e.message}"
raise
end
raise
end
- hostfile = File.join Rails.configuration.
dns_server_conf_d
ir, "#{hostname}.conf"
+ hostfile = File.join Rails.configuration.
Containers.SLURM.Managed.DNSServerConfD
ir, "#{hostname}.conf"
Tempfile.open(["#{hostname}-", ".conf.tmp"],
Tempfile.open(["#{hostname}-", ".conf.tmp"],
- Rails.configuration.
dns_server_conf_d
ir) do |f|
+ Rails.configuration.
Containers.SLURM.Managed.DNSServerConfD
ir) do |f|
tmpfile = f.path
f.puts template % template_vars
end
tmpfile = f.path
f.puts template % template_vars
end
@@
-221,20
+228,21
@@
class Node < ArvadosModel
end
end
end
end
- if
Rails.configuration.dns_server_update_command
- cmd = Rails.configuration.
dns_server_update_c
ommand % template_vars
+ if
!Rails.configuration.Containers.SLURM.Managed.DNSServerUpdateCommand.empty?
+ cmd = Rails.configuration.
Containers.SLURM.Managed.DNSServerUpdateC
ommand % template_vars
if not system cmd
logger.error "dns_server_update_command #{cmd.inspect} failed: #{$?}"
ok = false
end
end
if not system cmd
logger.error "dns_server_update_command #{cmd.inspect} failed: #{$?}"
ok = false
end
end
- if Rails.configuration.dns_server_conf_dir and Rails.configuration.dns_server_reload_command
- restartfile = File.join(Rails.configuration.dns_server_conf_dir, 'restart.txt')
+ if (!Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir.to_s.empty? and
+ !Rails.configuration.Containers.SLURM.Managed.DNSServerReloadCommand.to_s.empty?)
+ restartfile = File.join(Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir, 'restart.txt')
begin
File.open(restartfile, 'w') do |f|
# Typically, this is used to trigger a dns server restart
begin
File.open(restartfile, 'w') do |f|
# Typically, this is used to trigger a dns server restart
- f.puts Rails.configuration.
dns_server_reload_c
ommand
+ f.puts Rails.configuration.
Containers.SLURM.Managed.DNSServerReloadC
ommand
end
rescue IOError, SystemCallError => e
logger.error "Unable to write #{restartfile}: #{e.message}"
end
rescue IOError, SystemCallError => e
logger.error "Unable to write #{restartfile}: #{e.message}"
@@
-246,7
+254,7
@@
class Node < ArvadosModel
end
def self.hostname_for_slot(slot_number)
end
def self.hostname_for_slot(slot_number)
- config = Rails.configuration.
assign_node_h
ostname
+ config = Rails.configuration.
Containers.SLURM.Managed.AssignNodeH
ostname
return nil if !config
return nil if !config
@@
-255,10
+263,13
@@
class Node < ArvadosModel
# At startup, make sure all DNS entries exist. Otherwise, slurmctld
# will refuse to start.
# At startup, make sure all DNS entries exist. Otherwise, slurmctld
# will refuse to start.
- if Rails.configuration.dns_server_conf_dir and Rails.configuration.dns_server_conf_template and Rails.configuration.assign_node_hostname
- (0..Rails.configuration.max_compute_nodes-1).each do |slot_number|
+ if (!Rails.configuration.Containers.SLURM.Managed.DNSServerConfDir.to_s.empty? and
+ !Rails.configuration.Containers.SLURM.Managed.DNSServerConfTemplate.to_s.empty? and
+ !Rails.configuration.Containers.SLURM.Managed.AssignNodeHostname.empty?)
+
+ (0..Rails.configuration.Containers.MaxComputeVMs-1).each do |slot_number|
hostname = hostname_for_slot(slot_number)
hostname = hostname_for_slot(slot_number)
- hostfile = File.join Rails.configuration.
dns_server_conf_d
ir, "#{hostname}.conf"
+ hostfile = File.join Rails.configuration.
Containers.SLURM.Managed.DNSServerConfD
ir, "#{hostname}.conf"
if !File.exist? hostfile
n = Node.where(:slot_number => slot_number).first
if n.nil? or n.ip_address.nil?
if !File.exist? hostfile
n = Node.where(:slot_number => slot_number).first
if n.nil? or n.ip_address.nil?