1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #2911: Add support to optionally execute the same action more than once in a host

This commit is contained in:
Ruben S. Montero 2014-09-29 10:13:27 +02:00
parent d62b7335fa
commit 9765db73e0
3 changed files with 53 additions and 14 deletions

View File

@ -112,7 +112,7 @@ class ActionManager
end
arity=@actions[aname][:method].arity
if arity < 0
# Last parameter is an array
arity = -arity - 1
@ -145,7 +145,7 @@ class ActionManager
else
thread = nil
end
if thread
thread.kill
@ -173,17 +173,17 @@ class ActionManager
}
end
end
private
protected
def delete_running_action(action_id)
@action_running.delete(action_id)
end
def get_runable_action
@action_queue.shift
end
def empty_queue
@action_queue.size==0
end
@ -228,13 +228,13 @@ if __FILE__ == $0
@am.register_action(:SLEEP,method("sleep_action"))
# @am.register_action(:SLEEP,Proc.new{|s,i| p s ; sleep(s)})
@am.register_action(:NOP,method("nop_action"))
def @am.get_runable_action
action = super
puts "getting: #{action.inspect}"
action
end
def @am.delete_running_action(action_id)
puts "deleting: #{action_id}"
super(action_id)
@ -250,7 +250,7 @@ if __FILE__ == $0
def nop_action
p " - Just an action"
end
end
s = Sample.new
@ -264,7 +264,7 @@ if __FILE__ == $0
}
s.am.trigger_action(:SLEEP,301,5,301)
s.am.cancel_action(301)
s.am.trigger_action(:FINALIZE,0)

View File

@ -77,7 +77,8 @@ class VirtualMachineDriver < OpenNebulaDriver
# @option options [Boolean] :threaded (true) enables or disables threads
def initialize(directory, options={})
@options={
:threaded => true
:threaded => true,
:single_host => true
}.merge!(options)
super(directory, @options)
@ -214,8 +215,17 @@ class VirtualMachineDriver < OpenNebulaDriver
end
private
# Interface to handle the pending events from the ActionManager Interface
def delete_running_action(action_id)
if @options[:single_host]
delete_running_action_single_host(action_id)
else
super(action_id)
end
end
def delete_running_action_single_host(action_id)
action=@action_running[action_id]
if action
@hosts.delete(action[:host])
@ -224,6 +234,14 @@ private
end
def get_first_runable
if @options[:single_host]
get_first_runable_single_host
else
super
end
end
def get_first_runable_single_host
action_index=nil
@action_queue.each_with_index do |action, index|
if !action.keys.include?(:host)
@ -255,6 +273,14 @@ private
end
def get_runable_action
if @options[:single_host]
get_runable_action_single_host
else
super
end
end
def get_runable_action_single_host
action_index=get_first_runable
if action_index
@ -272,6 +298,14 @@ private
end
def empty_queue
if @options[:single_host]
empty_queue_single_host
else
super
end
end
def empty_queue_single_host
get_first_runable==nil
end
end

View File

@ -901,7 +901,8 @@ opts = GetoptLong.new(
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--local', '-l', GetoptLong::REQUIRED_ARGUMENT ],
[ '--shell', '-s', GetoptLong::REQUIRED_ARGUMENT ]
[ '--shell', '-s', GetoptLong::REQUIRED_ARGUMENT ],
[ '--parallel' '-p', GetoptLong::REQUIRED_ARGUMENT ]
)
hypervisor = ''
@ -909,6 +910,7 @@ retries = 0
threads = 15
shell = 'bash'
local_actions = {}
single_host = true
begin
opts.each do |opt, arg|
@ -921,6 +923,8 @@ begin
local_actions=OpenNebulaDriver.parse_actions_list(arg)
when '--shell'
shell = arg
when '--parallel'
single_host = false
end
end
rescue Exception => e
@ -937,6 +941,7 @@ exec_driver = ExecDriver.new(hypervisor,
:concurrency => threads,
:retries => retries,
:local_actions => local_actions,
:shell => shell)
:shell => shell,
:single_host => single_host)
exec_driver.start_driver