Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 91ff9268 authored by Florent Didier's avatar Florent Didier
Browse files

[dev] Fix disk reservation

parent c36a98d1
# coding: utf-8
# Monkey patching Ruby's Hash class
# Merge a and b. If a and b are hashes, they are recursively merged.
......@@ -144,12 +145,14 @@ class ::Hash
# Custom iterator. Only consider entries corresponding to cluster_list and node_list. Sorted by node_uid.
def each_filtered_node_uid(cluster_list, node_list)
self.each_sort_by_node_uid { |key, properties|
# As an example, key can be equal to 'grimoire-1' for default resources or
# ['grimoire-1', 1] for disk resources (disk n°1 of grimoire-1)
node_uid, = key
cluster_uid = node_uid.split(/-/).first
if (! cluster_list || cluster_list.include?(cluster_uid)) &&
(! node_list || node_list.include?(node_uid))
yield node_uid, properties
yield key, properties
end
}
end
......
......@@ -177,10 +177,10 @@ def get_ref_disk_properties_internal(site_uid, cluster_uid, node_uid, node)
node_address = [node_uid, site_uid, 'grid5000.fr'].join('.')
h['cluster'] = cluster_uid
h['host'] = node_address
h['network_address'] = node_address
h['network_address'] = ''
h['disk'] = index
h['diskpath'] = device['by_path']
h['cpuset'] = "disk-#{index}"
h['cpuset'] = 0
properties[key] = h
end
end
......@@ -290,9 +290,14 @@ def diff_properties(type, properties_oar, properties_ref)
properties_oar ||= {}
properties_ref ||= {}
ignore_keys = ignore_keys()
ignore_keys.each { |key| properties_oar.delete(key) }
ignore_keys.each { |key| properties_ref.delete(key) }
if type == 'default'
ignore_keys = ignore_keys()
ignore_keys.each { |key| properties_oar.delete(key) }
ignore_keys.each { |key| properties_ref.delete(key) }
elsif type == 'disk'
properties_oar.select! { |k, _v| %w(cluster host network_address disk diskpath cpuset).include?(k) }
properties_ref.select! { |k, _v| %w(cluster host network_address disk diskpath cpuset).include?(k) }
end
# Ignore the 'state' property only if the node is not 'Dead' according to
# the reference-repo.
......@@ -310,6 +315,7 @@ def diff_properties(type, properties_oar, properties_ref)
end
# These keys will not be created neither compared with the -d option
# ignore_keys is only applied to resources of type 'default'
def ignore_keys()
# default OAR at resource creation:
# available_upto: '2147483647'
......@@ -366,6 +372,7 @@ def ignore_keys()
"scheduler_priority",
"state",
"state_num",
"switch",
"subnet_address",
"subnet_prefix",
"suspended_jobs",
......@@ -376,6 +383,8 @@ def ignore_keys()
"id", # id from API (= resource_id from oarnodes)
"api_timestamp", # from API
"links", # from API
"disk",
"diskpath"
]
return ignore_keys
end
......@@ -434,7 +443,7 @@ end
def oarcmd_set_node_properties(host, default_properties)
return '' if default_properties.size == 0
command = "echo; echo 'Setting properties for #{host}:'; echo\n"
command += "oarnodesetting --sql \"network_address='#{host}' and type='default'\" -p "
command += "oarnodesetting --sql \"host='#{host}' and type='default'\" -p "
command +=
default_properties.to_a.map{ |(k,v)|
v = "YES" if v == true
......@@ -450,7 +459,7 @@ def oarcmd_create_disk(host, disk_properties)
disk_exist = "disk_exist '#{host}' '#{disk}'"
command = "echo; echo 'Adding disk #{disk} on host #{host}:'\n"
command += "#{disk_exist} && echo '=> disk already exists'\n"
command += "#{disk_exist} || oarnodesetting -a -h '' -p network_address='#{host}' -p host='#{host}' -p type='disk' -p disk=#{disk}"
command += "#{disk_exist} || oarnodesetting -a -h '' -p host='#{host}' -p network_address='' -p type='disk' -p disk=#{disk}"
return command + "\n\n"
end
......@@ -460,7 +469,7 @@ def oarcmd_set_disk_properties(host, disk_properties)
disk = disk_properties['disk']
diskpath = disk_properties['diskpath']
command = "echo; echo 'Setting properties for disk #{disk} on host #{host}:'; echo\n"
command += "oarnodesetting --sql \"network_address='#{host}' and type='disk' and disk=#{disk}\" -p cpu=0 -p core=0 -p host='#{host}' -p cluster='#{cluster_uid}' -p cpuset='disk-#{disk}' -p diskpath='#{diskpath}'"
command += "oarnodesetting --sql \"host='#{host}' and type='disk' and disk=#{disk}\" -p cpu=0 -p core=0 -p network_address='' -p cluster='#{cluster_uid}' -p cpuset=0 -p diskpath='#{diskpath}'"
command += "\n\n"
return command
end
......
......@@ -257,13 +257,16 @@ Those nodes should be marked as 'retired' in the reference-repo.\n"
properties['diff'][site_uid] = {}
site_properties.each do |type, type_properties|
properties['diff'][site_uid][type] = {}
type_properties.each_filtered_node_uid(options[:clusters], options[:nodes]) do |node_uid, properties_ref|
type_properties.each_filtered_node_uid(options[:clusters], options[:nodes]) do |key, properties_ref|
# As an example, key can be equal to 'grimoire-1' for default resources or
# ['grimoire-1', 1] for disk resources (disk n°1 of grimoire-1)
node_uid, = key
if properties_ref['state'] == 'Dead'
skipped_nodes << node_uid
next
end
key = (type == 'default') ? node_uid : [node_uid, properties_ref['disk']]
properties_oar = properties['oar'][site_uid][type][key]
diff = diff_properties(type, properties_oar, properties_ref) # Note: this deletes some properties from the input parameters
......@@ -384,13 +387,16 @@ if options[:output] || options[:exec]
end
# Build and output disk commands
site_properties['disk'].each_filtered_node_uid(options[:clusters], options[:nodes]) do |node_uid, disk_properties|
site_properties['disk'].each_filtered_node_uid(options[:clusters], options[:nodes]) do |key, disk_properties|
# As an example, key can be equal to 'grimoire-1' for default resources or
# ['grimoire-1', 1] for disk resources (disk n°1 of grimoire-1)
node_uid, = key
host = [node_uid, site_uid, 'grid5000.fr'].join('.')
next if skipped_nodes.include?(node_uid)
# Create a new disk
if opt == 'ref' || properties['oar'][site_uid]['disk'][node_uid].nil?
if opt == 'ref' || properties['oar'][site_uid]['disk'][key].nil?
cmd << oarcmd_create_disk(host, disk_properties)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment