| Class | Uttk::Strategies::HostSelector |
| In: |
lib/uttk/strategies/HostSelector.rb
|
| Parent: | Strategy |
Example:
root: !S::Suite
contents:
- selector: !S::HostSelector
hosts: # The list of hosts.
- ssh://joe:tux@foo.com # Via ssh on foo.com.
- druby://bar.fr:4242/ttk # Another custom protocol.
- ... # Hosts can also be specified
# with a file containing hosts
# or an url.
static_select: | # Performed just one time.
reject! { |x| not x.alive? } # Example of static cleaning.
shuffle! # Shuffle the hosts.
dynamic_select: | # Called to elect an host.
roll # Move the first host to the
# end of the list and return it
# Other examples:
# - first (take the first)
# - choose (randomly)
- big suite: !S::Pool
attribute: !S::Jump
to: !url <<host_selector.elect>>
test: !S::Suite
... something long ...
contents:
- ...
- ...
# File lib/uttk/strategies/HostSelector.rb, line 49 def call ( selector, argument ) if selector.arity == 1 selector[argument] else argument.instance_eval(&selector) end end
Suppose that we have URI::Generic#load_average which returns the current load average of the targeted host.
With dynamic select you can simply do that
dynamic_select:
min { |x, y| x.load_average <=> y.load_average }
dynamic_min:
load_average
dynamic_min:
((alive?)? 0 : Float::MAX) + 3 * load_average.first + 5 * current_jobs_count
# File lib/uttk/strategies/HostSelector.rb, line 84 def do_dynamic_min @hosts_pool.min { |x, y| call(dynamic_min, x) <=> call(dynamic_min, y) } end
# File lib/uttk/strategies/HostSelector.rb, line 65 def do_dynamic_select call(@dynamic_select, @hosts_pool) end
# File lib/uttk/strategies/HostSelector.rb, line 58 def do_static_select @hosts_pool = @hosts.dup result = call(@static_select, @hosts_pool) @hosts_pool = result unless result.nil? end
# File lib/uttk/strategies/HostSelector.rb, line 89 def prologue super @static_select = @static_select.to_proc @dynamic_select = @dynamic_select.to_proc if @dynamic_select @dynamic_min = @dynamic_min.to_proc if @dynamic_min unless @dynamic_select or @dynamic_min raise ArgumentError, "Need at least dynamic_select or dynamic_min" end @symtbl[:host_selector] = self @symtbl['host_selector.elect''host_selector.elect'] = SymTbl::Trigger.new { elect } # ... end