Class: HawatelTlb::Client
- Inherits:
-
Object
- Object
- HawatelTlb::Client
- Includes:
- WatchDog
- Defined in:
- lib/hawatel_tlb/client.rb
Constant Summary collapse
- WORKING_MODE =
{ 'dynamicratio' => Mode::DynamicRatio, 'roundrobin' => Mode::RoundRobin, 'fastest' => Mode::Fastest, 'ratio' => Mode::Ratio, 'weighted' => Mode::Weighted }
- DEFAULT_STATE =
'enable'- DEFAULT_PORT =
80- DEFAULT_WEIGHT =
1- DEFAULT_TIMEOUT =
5- DEFAULT_INTERVAL =
5
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
-
#add(args) ⇒ Integer
Add host to TLB group.
-
#configure(args) ⇒ Integer
Set settings for group.
-
#del(id) ⇒ String
Delete host from TLB group.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#list ⇒ Array<String>
Return hosts list.
-
#node ⇒ Integer
Description.
-
#status ⇒ Integer
Description.
Methods included from WatchDog
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 |
# File 'lib/hawatel_tlb/client.rb', line 24 def initialize @group = Array.new @interval = DEFAULT_INTERVAL watchdog_thread() end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
9 10 11 |
# File 'lib/hawatel_tlb/client.rb', line 9 def group @group end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
9 10 11 |
# File 'lib/hawatel_tlb/client.rb', line 9 def interval @interval end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
9 10 11 |
# File 'lib/hawatel_tlb/client.rb', line 9 def mode @mode end |
Instance Method Details
#add(args) ⇒ Integer
Add host to TLB group
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hawatel_tlb/client.rb', line 43 def add(args) host = args[:host] port = args[:port] || DEFAULT_PORT weight = args[:weight] || DEFAULT_WEIGHT timeout = args[:timeout] || DEFAULT_TIMEOUT state = args[:state] || DEFAULT_STATE status = validate_host_settings({:host => host, :port => port, :weight => weight, :timeout => timeout, :state => state}) if status == 'success' host_cfg = OpenStruct.new(:id => host_id.to_i, :host => host, :port => port, :weight => weight, :timeout => timeout, :state => state, :status => {:time => 0, :state => 'offline', :respond_time => 0}) @group.push(host_cfg) end @mode.refresh(@group) if @mode return status end |
#configure(args) ⇒ Integer
Set settings for group
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hawatel_tlb/client.rb', line 103 def configure(args) if @group[0] watcher if @group[0].status[:time] == 0 end mode = args[:mode] || 'roundrobin' @interval if args[:interval] return 'invalid mode' if !WORKING_MODE.key?(mode) if @mode @mode.destroy if @mode.respond_to?(:destroy) @mode = nil else @mode = nil end @mode = WORKING_MODE[mode].new(@group) end |
#del(id) ⇒ String
Delete host from TLB group
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hawatel_tlb/client.rb', line 69 def del(id) if id.is_a?(Fixnum) if @group[id-1] @group.delete(id-1) @mode.refresh(@group) if @mode return 'host successful deleted' else return 'invalid host id' end else 'invalid value' end end |
#list ⇒ Array<String>
Return hosts list
91 92 93 |
# File 'lib/hawatel_tlb/client.rb', line 91 def list return @group end |
#node ⇒ Integer
Description
130 131 132 133 |
# File 'lib/hawatel_tlb/client.rb', line 130 def node return @mode.node if @mode false end |
#status ⇒ Integer
Description
144 145 146 147 |
# File 'lib/hawatel_tlb/client.rb', line 144 def status @group.each do |node| end end |