Feature #1854 #1852: Scaling works in two steps, to allow manual intevention

This commit is contained in:
Carlos Martín committed 2013-05-31 16:40:49 +02:00
1 parent e7af944e8b
commit 18268036e9
3 files changed
+66 -55

No files matched your search

+9 -10
View File
@@ -75,20 +75,14 @@ class ServiceLCM
if !service.all_roles_running?
service.set_state(Service::STATE['UNKNOWN'])
else
rc = strategy.scale_step(service)
if strategy.apply_scaling_policies(service)
service.set_state(Service::STATE['SCALING'])
scale = rc[0]
succ = rc[1]
error_msg = rc[2]
if scale
if succ
service.set_state(Service::STATE['SCALING'])
else
rc = strategy.scale_step(service)
if !rc[0]
service.set_state(Service::STATE['FAILED_SCALING'])
end
end
end
when Service::STATE['SCALING']
strategy.monitor_step(service)
@@ -100,6 +94,11 @@ class ServiceLCM
service.set_state(Service::STATE['FAILED_SCALING'])
elsif !service.any_role_scaling?
service.set_state(Service::STATE['RUNNING'])
else
rc = strategy.scale_step(service)
if !rc[0]
service.set_state(Service::STATE['FAILED_SCALING'])
end
end
when Service::STATE['FAILED_SCALING']
strategy.monitor_step(service)
+33 -27
View File
@@ -74,45 +74,51 @@ class Strategy
return [true, nil]
end
#
# @return [Array<false, nil, nil>, Array<true, true, nil>, Array<true, false, String>]
# 1st elem: true if the service needed to scale
# 2nd elem: true if the operation succeeded
# 3rd elem: error reason, if any
def scale_step(service)
Log.debug LOG_COMP, "Scale step", service.id()
scale = false
# If a role needs to scale, its cardinality is updated, and its state is set
# to SCALING. Only one role is set to scale.
# @param [Service] service
# @return [true|false] true if any role needs to scale
def apply_scaling_policies(service)
Log.debug LOG_COMP, "Apply scaling policies", service.id()
service.get_roles.each do |name, role|
diff = role.scale?
if diff > 0
Log.debug LOG_COMP, "Scaling up role #{name}, #{diff} nodes", service.id()
rc = role.scale_up(role.cardinality() + diff)
elsif diff < 0
Log.debug LOG_COMP, "Scaling down role #{name}, #{diff} nodes", service.id()
rc = role.scale_down(role.cardinality() + diff)
end
if diff != 0
Log.debug LOG_COMP, "Role #{name} needs to scale #{diff} nodes", service.id()
role.set_cardinality(role.cardinality() + diff)
role.set_state(Role::STATE['SCALING'])
return true
end
end
return false
end
# If a role is scaling, the nodes are created/destroyed to match the current
# cardinality
# @return [Array<true, nil>, Array<false, String>] true if the action was
# performed, false and the error reason if there was a problem
def scale_step(service)
Log.debug LOG_COMP, "Scale step", service.id()
service.get_roles.each do |name, role|
if role.state == Role::STATE['SCALING']
rc = role.scale()
if !rc[0]
role.set_state(Role::STATE['FAILED_SCALING'])
return [true] + rc
return rc
end
role.set_state(Role::STATE['SCALING'])
scale = true
break
end
end
return [scale, true, nil]
return [true, nil]
end
# Performs a monitor step, check if the roles already deployed are running
@@ -146,7 +152,7 @@ class Strategy
when Role::STATE['SCALING']
if OpenNebula.is_error?(rc)
role.set_state(Role::STATE['FAILED_SCALING'])
elsif role_nodes_running?(role)
elsif role_finished_scaling?(role)
role.set_state(Role::STATE['RUNNING'])
elsif any_node_failed_scaling?(role)
role.set_state(Role::STATE['FAILED_SCALING'])
+24 -18
View File
@@ -84,8 +84,12 @@ module OpenNebula
# Sets a new cardinality for this role
# @param [Integer] the new cardinality
def set_cardinality(cardinality)
@body['cardinality'] = cardinality.to_i
def set_cardinality(target_cardinality)
msg = "Role #{name} scaling up from #{cardinality} to #{target_cardinality} nodes"
Log.info LOG_COMP, msg, @service.id()
@service.log_info(msg)
@body['cardinality'] = target_cardinality.to_i
end
# Returns the role max cardinality
@@ -512,24 +516,28 @@ module OpenNebula
return treetop.result(self)
end
def scale_up(target_cardinality)
msg = "Role #{name} scaling up from #{cardinality} to #{target_cardinality} nodes"
Log.info LOG_COMP, msg, @service.id()
@service.log_info(msg)
# Scales up or down the number of nodes needed to match the current
# cardinality
#
# @return [Array<true, nil>, Array<false, String>] true if all the VMs
# were created/shut down, false and the error reason if there
# was a problem
def scale()
n_nodes = 0
set_cardinality(target_cardinality)
get_nodes.each do |node|
n_nodes += 1 if node['disposed'] != "1"
end
return deploy()
end
diff = cardinality - n_nodes
def scale_down(target_cardinality)
msg = "Role #{name} scaling down from #{cardinality} to #{target_cardinality} nodes"
Log.info LOG_COMP, msg, @service.id()
@service.log_info(msg)
if diff > 0
return deploy()
elsif diff < 0
return shutdown(true)
end
set_cardinality(target_cardinality)
return shutdown(true)
return [true, nil]
end
# For a failed scale up, the cardinality is updated to the actual value
@@ -581,8 +589,6 @@ module OpenNebula
set_cardinality( get_nodes.size() - n_dispose )
end
def update(template)
set_cardinality(template["cardinality"])
end