Commit 522ac583 authored by Jérémie Gaidamour's avatar Jérémie Gaidamour

[dev] oar-properties: added the capability to create varchar properties

parent 8fa8368d
......@@ -235,14 +235,20 @@ def diff_node_properties(node_properties_oar, node_properties_ref)
end
# Return a list of properties
# Return a list of properties (as a hash: { property1 => String, property2 => Fixnum, ... })
# We try to detect the type of the property (Fixnum/String) by looking at the existing values. This is not possible if no value is set (NilClass).
def get_property_keys(nodelist_properties)
properties_keys = Set.new []
properties_keys = {}
nodelist_properties.each { |site_uid, site_properties|
# We do not use site/cluster/node filters here as we want the same list of properties across OAR servers
site_properties.each { |node_uid, node_properties|
next if node_uid == nil
properties_keys.merge(node_properties.keys)
node_properties.each { |k, v|
unless properties_keys.key?(k) && NilClass === v
properties_keys[k] = v.class
end
}
}
}
return properties_keys
......@@ -339,8 +345,14 @@ end
def oarcmd_create_properties(properties_keys)
command = ""
properties_keys.each { |key|
command += "oarproperty -a #{key} || true\n"
properties_keys.each { |key, type|
if type == Fixnum
command += "oarproperty -a #{key} || true\n"
elsif type == String
command += "oarproperty -a #{key} --varchar || true\n"
else
raise "Error: the type of the '#{key}' property is unknown (Integer/String). Cannot generate the corresponding 'oarproperty' command."
end
}
return command
end
......
......@@ -141,6 +141,8 @@ options[:diff] = false unless options[:diff]
puts "Options: #{options}" if options[:verbose]
puts "Hint: You might want to use either --verbose, --output or --exec." unless options[:verbose] || options[:output] || options[:exec]
nodelist_properties = {} # ["ref"] : properties from the reference-repo
# ["oar"] : properties from the OAR server
# ["diff"] : diff between "ref" and "oar"
......@@ -254,13 +256,21 @@ if options[:diff]
}
# Build the list of properties that must be created in the OAR server
# Get the list of property keys from the OAR scheduler (["oar"])
properties_keys["oar"] = get_property_keys(nodelist_properties["oar"])
properties_keys["diff"] = properties_keys["ref"] - properties_keys["oar"]
puts "Properties that need to be created on the server: #{properties_keys["diff"].to_a.join(', ')}" if options[:verbose] && properties_keys["diff"].size>0
# Build the list of properties that must be created in the OAR server
properties_keys["diff"] = {}
properties_keys["ref"].each { |k, v_ref|
v_oar = properties_keys["oar"][k]
properties_keys["diff"][k] = v_ref unless v_oar
if v_oar && v_oar != v_ref && v_ref != NilClass && v_oar != NilClass
# Detect inconsistency between the type (String/Fixnum) of properties generated by this script and the existing values on the server.
raise "Error: the OAR property '#{k}' is a '#{v_oar}' on the server and this script uses '#{v_ref}' for this property."
end
}
puts "Properties that need to be created on the server: #{properties_keys["diff"].keys.to_a.join(', ')}" if options[:verbose] && properties_keys["diff"].keys.size>0
end # if options[:diff]
#
......
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