From 9765db73e0fcd21adca980857c61d0c28948adbd Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 29 Sep 2014 10:13:27 +0200 Subject: [PATCH] feature #2911: Add support to optionally execute the same action more than once in a host --- src/mad/ruby/ActionManager.rb | 22 ++++++++--------- src/mad/ruby/VirtualMachineDriver.rb | 36 +++++++++++++++++++++++++++- src/vmm_mad/exec/one_vmm_exec.rb | 9 +++++-- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/mad/ruby/ActionManager.rb b/src/mad/ruby/ActionManager.rb index 2116a3ff65..7a6f6342e9 100644 --- a/src/mad/ruby/ActionManager.rb +++ b/src/mad/ruby/ActionManager.rb @@ -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) diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index ca12065426..21f00cfc2d 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -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 diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index f2e4e6c5cb..500fa14f16 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -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