mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-25 06:03:36 +03:00
The driver engine now uses symbols to address actions. Method objects
are used when an action is registered git-svn-id: http://svn.opennebula.org/one/trunk@342 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
2182cfe6ca
commit
99d02a2689
@ -97,11 +97,10 @@ class ActionManager
|
||||
# +aargs+ arguments to call the action
|
||||
def trigger_action(aname,*aargs)
|
||||
|
||||
return if @finalize
|
||||
|
||||
@threads_mutex.synchronize {
|
||||
return if @finalize
|
||||
|
||||
if aname == "FINALIZE"
|
||||
if aname == :FINALIZE
|
||||
@finalize = true
|
||||
@threads_cond.signal if @running_actions == 0
|
||||
return
|
||||
@ -110,10 +109,8 @@ class ActionManager
|
||||
if !@actions.has_key?(aname)
|
||||
return
|
||||
end
|
||||
|
||||
method_obj = method(@actions[aname][:method])
|
||||
|
||||
if method_obj.arity != aargs.length
|
||||
if @actions[aname][:method].arity != aargs.length
|
||||
return
|
||||
end
|
||||
|
||||
@ -174,9 +171,9 @@ if __FILE__ == $0
|
||||
def initialize
|
||||
@am = ActionManager.new(15,true)
|
||||
|
||||
@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"))
|
||||
@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"))
|
||||
end
|
||||
|
||||
def sleep_action(secs, id)
|
||||
@ -195,14 +192,14 @@ if __FILE__ == $0
|
||||
Thread.new {
|
||||
sleep 1
|
||||
100.times {|n|
|
||||
s.am.trigger_action("SLEEP",rand(3)+1,n)
|
||||
s.am.trigger_action("NOP")
|
||||
s.am.trigger_action(:SLEEP,rand(3)+1,n)
|
||||
s.am.trigger_action(:NOP)
|
||||
}
|
||||
|
||||
s.am.trigger_action("FINALIZE")
|
||||
s.am.trigger_action(:FINALIZE)
|
||||
|
||||
s.am.trigger_action("SLEEP",rand(3)+1,999)
|
||||
s.am.trigger_action("SLEEP",rand(3)+1,333)
|
||||
s.am.trigger_action(:SLEEP,rand(3)+1,999)
|
||||
s.am.trigger_action(:SLEEP,rand(3)+1,333)
|
||||
}
|
||||
|
||||
s.am.start_listener
|
||||
|
@ -38,7 +38,7 @@ class OpenNebulaDriver < ActionManager
|
||||
def initialize(concurrency=10, threaded=true)
|
||||
super(concurrency,threaded)
|
||||
|
||||
register_action("INIT", method("init"))
|
||||
register_action(:INIT, method("init"))
|
||||
@send_mutex=Mutex.new
|
||||
end
|
||||
|
||||
@ -80,7 +80,7 @@ private
|
||||
args = str.split(/\s+/)
|
||||
next if args.length == 0
|
||||
|
||||
action = args.shift.upcase
|
||||
action = args.shift.upcase.to_sym
|
||||
|
||||
trigger_action(action,*args)
|
||||
end
|
||||
@ -93,7 +93,7 @@ if __FILE__ == $0
|
||||
def initialize
|
||||
super(15,true)
|
||||
|
||||
register_action("SLEEP",method("my_sleep"))
|
||||
register_action(:SLEEP,method("my_sleep"))
|
||||
end
|
||||
|
||||
def my_sleep(timeout, num)
|
||||
|
@ -30,6 +30,9 @@ require "OpenNebulaDriver"
|
||||
|
||||
class VirtualMachineDriver < OpenNebulaDriver
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Virtual Machine Driver Protocol constants
|
||||
# -------------------------------------------------------------------------
|
||||
ACTION = {
|
||||
:deploy => "DEPLOY",
|
||||
:shutdown => "SHUTDOWN",
|
||||
@ -55,18 +58,25 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
:deleted => 'd'
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Register default actions for the protocol
|
||||
# -------------------------------------------------------------------------
|
||||
def initialize(concurrency=10, threaded=true)
|
||||
super(concurrency,threaded)
|
||||
|
||||
register_action(ACTION[:deploy], method("deploy"))
|
||||
register_action(ACTION[:shutdown], method("shutdown"))
|
||||
register_action(ACTION[:cancel], method("cancel"))
|
||||
register_action(ACTION[:save], method("save"))
|
||||
register_action(ACTION[:restore], method("restore"))
|
||||
register_action(ACTION[:migrate], method("migrate"))
|
||||
register_action(ACTION[:poll], method("poll"))
|
||||
register_action(ACTION[:deploy].to_sym, method("deploy"))
|
||||
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
|
||||
register_action(ACTION[:cancel].to_sym, method("cancel"))
|
||||
register_action(ACTION[:save].to_sym, method("save"))
|
||||
register_action(ACTION[:restore].to_sym, method("restore"))
|
||||
register_action(ACTION[:migrate].to_sym, method("migrate"))
|
||||
register_action(ACTION[:poll].to_sym, method("poll"))
|
||||
end
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Converts a deployment file from its remote path to the local (front-end)
|
||||
# path
|
||||
# -------------------------------------------------------------------------
|
||||
def get_local_deployment_file(remote_deployment_file)
|
||||
|
||||
local_deployment_file = nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user