Feature #1852: Method stubs to scale up

This commit is contained in:
Carlos Martín committed 2013-05-16 16:32:11 +02:00
1 parent dbdaafc61e
commit 24a047be88
4 files changed
+114

No files matched your search

+15
View File
@@ -74,6 +74,21 @@ class ServiceLCM
if !service.all_roles_running?
service.set_state(Service::STATE['UNKNOWN'])
elsif service.scale_up?
Log.debug "ELAS", "Service #{service.name} to scale up"
Log.debug "ELAS", "Scale up", service.id()
# TODO: create a new state SCALING, SCALING_UP?
# TODO: changing state stops the elasticity rules
# check until current deployments end.
service.set_state(Service::STATE['DEPLOYING'])
rc = strategy.boot_step(service)
if !rc[0]
service.set_state(Service::STATE['FAILED_DEPLOYING'])
end
end
when Service::STATE['UNKNOWN']
strategy.monitor_step(service)
+22
View File
@@ -74,6 +74,28 @@ module OpenNebula
return card
end
# Sets a new cardinality for this role
# @param [Integer] the new cardinality
def set_cardinality(cardinality)
@body['cardinality'] = cardinality.to_i
end
# Returns the role max cardinality
# @return [Integer] the role cardinality
def max_cardinality
max = nil
if !@body['elasticity_policy'].nil?
max = @body['elasticity_policy']['max_vms']
end
if max.nil?
max = cardinality()
end
return max.to_i
end
# Returns the string representation of the service state
# @return [String] the state string
def state_str
+44
View File
@@ -139,6 +139,50 @@ module OpenNebula
return false
end
# If any role scalability rule is triggered, the role is set to DEPLOYING
# and the cardinality is updated
#
# @return true if any role is going to scale up
def scale_up?()
scale = false
@roles.each { |name, role|
if role_scale_up?(role)
role.set_cardinality( role.cardinality + 1 )
role.set_state(Role::STATE['PENDING'])
scale = true
end
}
return scale
end
# Method stub, returns true if any VM has an attribute SCALE_UP=YES
def role_scale_up?(role)
role.get_nodes.each { |node|
if node && node['vm_info']
scale_up = node['vm_info']['VM']['USER_TEMPLATE']['SCALE_UP']
if scale_up == "YES"
Log.debug "ELAS", "Role #{role.name} to scale up"
if role.cardinality() < role.max_cardinality()
# Clean vm template
`echo "" > /tmp/empty.txt`
`onevm update #{node['deploy_id']} /tmp/empty.txt`
return true
else
Log.debug "ELAS", "Role #{role.name} has reached its VM limit"
end
end
end
}
return false
end
# Create a new service based on the template provided
# @param [String] template_json
# @return [nil, OpenNebula::Error] nil in case of success, Error
+33
View File
@@ -37,6 +37,39 @@ module OpenNebula
:items => {
:type => :string
}
},
'elasticity_policy' => {
:type => :object,
:properties => {
'type' => {
:type => :string,
:required => true
},
'min_vms' => {
:type => :integer,
:default => 1
},
'max_vms' => {
:type => :integer,
:required => true
},
'up_expr' => {
:type => :string,
:required => true
},
'down_expr' => {
:type => :string,
:required => true
},
'period_number' => {
:type => :integer,
:default => 1
},
'period_duration' => {
:type => :integer,
:required => true
}
}
}
}
}