Feature #1852: Improve grammar

* Now grammar will look for attributes inside /VM/USER_TEMPLATE,
/VM, and /VM/TEMPLATE, in that order
 * VMs without the attribute are not included in the average calc.
 * If the attribute is not found, the condition is false, instead
of assuming a value of 0
This commit is contained in:
Carlos Martín committed 2013-05-29 16:49:35 +02:00
1 parent c443bcf2f9
commit 2fd735934e
2 files changed
+62 -12

No files matched your search

+31 -6
View File
@@ -294,7 +294,17 @@ module ElasticityGrammar
module LogicCond1
def result(role)
comp_op.apply(left.result(role), right.result(role))
l_res = left.result(role)
r_res = right.result(role)
if l_res.nil? || r_res.nil?
# An attribute was not found, we return false instead
# of assuming a value of 0
return false
else
comp_op.apply(l_res, r_res)
end
end
end
@@ -849,20 +859,35 @@ module ElasticityGrammar
def result(role)
nodes = role.get_nodes
total = 0
n_nodes = 0
att = text_value.upcase
# TODO: search in 'TEMPLATE' also?
# TODO: what to do if value is not found
nodes.each { |node|
if node && node['vm_info'] && node['vm_info']['VM']['USER_TEMPLATE'][text_value.upcase]
# TODO: Check value is numeric
total += (node['vm_info']['VM']['USER_TEMPLATE'][text_value.upcase]).to_f
if node && node['vm_info']
if node['vm_info']['VM']['USER_TEMPLATE'][att]
total += (node['vm_info']['VM']['USER_TEMPLATE'][att]).to_f
n_nodes += 1
elsif node['vm_info']['VM'][att]
total += (node['vm_info']['VM'][att]).to_f
n_nodes += 1
elsif node['vm_info']['VM']['TEMPLATE'][att]
total += (node['vm_info']['VM']['TEMPLATE'][att]).to_f
n_nodes += 1
end
end
}
Log.debug "ELAS", "Role #{role.name} attribute #{text_value.upcase} avg value of #{total / nodes.size}"
# The attribute wasn't found for any of the nodes
if n_nodes == 0
return nil
end
return total / nodes.size
Log.debug "ELAS", "Role #{role.name} attribute #{att} avg value of #{total / n_nodes}"
return total / n_nodes
end
end
+31 -6
View File
@@ -53,7 +53,17 @@ grammar ElasticityGrammar
# /
left:operand space comp_op space right:operand {
def result(role)
comp_op.apply(left.result(role), right.result(role))
l_res = left.result(role)
r_res = right.result(role)
if l_res.nil? || r_res.nil?
# An attribute was not found, we return false instead
# of assuming a value of 0
return false
else
comp_op.apply(l_res, r_res)
end
end
}
/
@@ -145,20 +155,35 @@ grammar ElasticityGrammar
def result(role)
nodes = role.get_nodes
total = 0
n_nodes = 0
att = text_value.upcase
# TODO: search in 'TEMPLATE' also?
# TODO: what to do if value is not found
nodes.each { |node|
if node && node['vm_info'] && node['vm_info']['VM']['USER_TEMPLATE'][text_value.upcase]
# TODO: Check value is numeric
total += (node['vm_info']['VM']['USER_TEMPLATE'][text_value.upcase]).to_f
if node && node['vm_info']
if node['vm_info']['VM']['USER_TEMPLATE'][att]
total += (node['vm_info']['VM']['USER_TEMPLATE'][att]).to_f
n_nodes += 1
elsif node['vm_info']['VM'][att]
total += (node['vm_info']['VM'][att]).to_f
n_nodes += 1
elsif node['vm_info']['VM']['TEMPLATE'][att]
total += (node['vm_info']['VM']['TEMPLATE'][att]).to_f
n_nodes += 1
end
end
}
Log.debug "ELAS", "Role #{role.name} attribute #{text_value.upcase} avg value of #{total / nodes.size}"
# The attribute wasn't found for any of the nodes
if n_nodes == 0
return nil
end
return total / nodes.size
Log.debug "ELAS", "Role #{role.name} attribute #{att} avg value of #{total / n_nodes}"
return total / n_nodes
end
}
end