murakumo 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,6 +79,12 @@ max-ip-num: 8
79
79
  # (another way)
80
80
  #init-script: /foo/bar/zoo/murakumo-init.rb
81
81
 
82
+ # verifies communication of initial nodes
83
+ #ping-init-nodes: true
84
+
85
+ # delay of a gossip start (cli arg: -D)
86
+ #gossip-start-delay: 60
87
+
82
88
  #name-includes: ^app-\d+$, ^db-\d+$
83
89
  #name-excludes:
84
90
  #addr-includes: ^10\..*
@@ -123,6 +129,7 @@ host: $ip_addr, $hostname, 60
123
129
  # timeout: 5
124
130
  # healthy: 2
125
131
  # unhealthy: 2
132
+ # #init-status: inactive # active/inactive (default: active)
126
133
  # #on-activate: /foo/bar/zoo.sh # args: address name status
127
134
  # #on-inactivate: /foo/bar/zoo.sh # args: address name status
128
135
  # script: |
@@ -19,6 +19,12 @@ max-ip-num: 8
19
19
  # (another way)
20
20
  #init-script: /foo/bar/zoo/murakumo-init.rb
21
21
 
22
+ # verifies communication of initial nodes
23
+ #ping-init-nodes: true
24
+
25
+ # delay of a gossip start (cli arg: -D)
26
+ #gossip-start-delay: 60
27
+
22
28
  #name-includes: ^app-\d+$, ^db-\d+$
23
29
  #name-excludes:
24
30
  #addr-includes: ^10\..*
@@ -63,6 +69,7 @@ alias:
63
69
  # timeout: 5
64
70
  # healthy: 2
65
71
  # unhealthy: 2
72
+ # #init-status: inactive # active/inactive (default: active)
66
73
  # #on-activate: /foo/bar/zoo.sh # args: address name status
67
74
  # #on-inactivate: /foo/bar/zoo.sh # args: address name status
68
75
  # script: |
@@ -18,6 +18,9 @@ begin
18
18
  case cmd
19
19
  # 一覧表示
20
20
  when :list
21
+ # アドレスの取得
22
+ address = there.address
23
+
21
24
  # レコードの取得
22
25
  records = there.list_records
23
26
 
@@ -48,11 +51,13 @@ begin
48
51
  puts 'No macth'
49
52
  else
50
53
  puts <<-EOF
51
- IP address TTL Priority Weight Activity Hostname
52
- --------------- ------ --------- ------ -------- ----------
54
+ IP address TTL Priority Weight Activity Hostname
55
+ --------------- ------ --------- ------ -------- ----------
53
56
  EOF
54
57
  records.each do |r|
55
- puts '%-15s %6d %-9s %6s %-8s %s' % r.values_at(0, 2, 3, 4, 5, 1)
58
+ values = r.values_at(0, 2, 3, 4, 5, 1)
59
+ values.unshift(address == values[0] ? '*' : ' ')
60
+ puts '%s %-15s %6d %-9s %6s %-8s %s' % values
56
61
  end
57
62
  end
58
63
 
@@ -131,6 +131,12 @@ def murakumo_parse_args
131
131
  desc 'reception timeout of a gossip protocol'
132
132
  option :gossip_receive_timeout, '-O', '--gossip-receive-timeout NUM', :type => Integer, :default => 3
133
133
 
134
+ desc 'verifies communication of initial nodes'
135
+ option :ping_init_nodes, '-V', '--ping-init-nodes', :default => false
136
+
137
+ desc 'delay of a gossip start'
138
+ option :gossip_start_delay, '-D', '--gossip-start-delay', :type => Integer, :default => 0
139
+
134
140
  after do |options|
135
141
  # auth_key
136
142
  if File.exist?(options[:auth_key])
@@ -203,6 +209,11 @@ def murakumo_parse_args
203
209
  parse_error('same hostname was found')
204
210
  end
205
211
 
212
+ # ping init nodes
213
+ if options[:ping_init_nodes]
214
+ options[:ping_init_nodes] = !!options[:ping_init_nodes]
215
+ end
216
+
206
217
  # health check
207
218
  if (health_check = options[:health_check])
208
219
  health_check.kind_of?(Hash) or parse_error('configuration of a health check is not right')
@@ -221,6 +232,18 @@ def murakumo_parse_args
221
232
  end
222
233
  end
223
234
 
235
+ conf['init-status'] ||= 'active'
236
+
237
+ unless /\A(active|inactive)\Z/i =~ conf['init-status']
238
+ parse_error('configuration of a health check is not right', "#{name}/init-status")
239
+ end
240
+
241
+ if conf['init-status'] =~ /\Aactive\Z/i
242
+ conf['init-status'] = Murakumo::ACTIVE
243
+ else
244
+ conf['init-status'] = Murakumo::INACTIVE
245
+ end
246
+
224
247
  # 各種変数の設定
225
248
  {
226
249
  'interval' => [ 5, 1, 300],
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.4.5'
2
+ VERSION = '0.4.6'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -44,7 +44,7 @@ Status: #{status}
44
44
  EOS
45
45
  end
46
46
 
47
- @logger.info("sent the notice: #{status}")
47
+ @logger.info("sent notice: #{status}")
48
48
  rescue Exception => e
49
49
  message = (["#{e.class}: #{e.message}"] + (e.backtrace || [])).join("\n\tfrom ")
50
50
  @logger.error("activity check failed: #{@name}: #{message}")
@@ -108,28 +108,65 @@ module Murakumo
108
108
  end
109
109
 
110
110
  # 宛先をソート
111
- dests = (0...records.length).map {|i| [records[i]['ip_address'], i] }.sort_by {|a, b| a }
111
+ dests = (0...records.length).map {
112
+ |i| [records[i].values_at('ip_address', 'weight'), i].flatten
113
+ }.sort_by {|addr, weight, i| addr }
112
114
  dests_orig = dests
113
115
  dests_orig_len = dests_orig.length
114
116
 
115
- # 数をそろえる
116
- if sources.length < dests.length
117
- dests = dests.slice(0, sources.length)
118
- elsif sources.length > dests.length
119
- dests = dests_orig = dests * (sources.length.to_f / dests.length).ceil
120
- dests = dests.slice(0, sources.length)
117
+ # 按分する
118
+ dests = arrange_length(sources, dests)
119
+
120
+ # 宛先がない場合はとりあえずランダムで
121
+ if dests.length.zero?
122
+ @logger.warn('destination is not found')
123
+ return random(records, max_ip_num)
121
124
  end
122
125
 
123
126
  # 先頭を決めてローテート
124
- first_index = sources.zip(dests).index {|s, d| s == @address }
127
+ first_record = sources.zip(dests).assoc(@address)[1]
128
+ first_index = dests_orig.index {|i| i[0] == first_record[0] }
125
129
 
126
130
  # 元の配列に戻す
127
131
  dests = (dests_orig + dests_orig).slice(first_index, dests_orig_len)
128
132
 
129
133
  # 先頭インデックスからレコードを並べ直す
130
- yield(records.values_at(*dests.map {|addr, i| i }))
134
+ yield(records.values_at(*dests.map {|addr, weight, i| i }))
131
135
  end # fix_by_src0
132
136
 
137
+ def arrange_length(sources, dests)
138
+ weights = {}
139
+ sum = dests.inject(0) {|r, i| r + i[1] }
140
+
141
+ # 重みでソースの長さを按分する
142
+ dests.each do |addr, weight, i|
143
+ weights[addr] = ((weight.to_f / sum) * sources.length).round
144
+ end
145
+
146
+ # 端数分をそろえる
147
+ delta = weights.inject(0) {|r, i| r + i[1] } - sources.length
148
+ key_list = weights.sort_by {|k, v| k }.map {|k, v| k } # 順序は一定に!
149
+ addval = (delta > 0) ? -1 : 1
150
+
151
+ # ローテートしながら端数分を埋める
152
+ until delta.zero?
153
+ key = key_list.shift
154
+ key_list.push(key)
155
+ weights[key] += addval
156
+ delta += addval
157
+ end
158
+
159
+ new_dests = []
160
+
161
+ dests.each do |addr, weight, i|
162
+ weights[addr].to_i.times do
163
+ new_dests << [addr, weight, i]
164
+ end
165
+ end
166
+
167
+ return new_dests
168
+ end # arrange_length
169
+
133
170
  end # Balancer
134
171
 
135
172
  end # Murakumo
@@ -26,7 +26,12 @@ module Murakumo
26
26
  host_data = options[:host]
27
27
  @address = host_data.shift
28
28
  host_data.concat [ORIGIN, 0, ACTIVE]
29
- alias_datas = options[:aliases].map {|r| r + [ACTIVE] }
29
+ alias_datas = options[:aliases].map {|r|
30
+ # ヘルスチェックの初期値に合わせて健康状態を設定
31
+ health_check_conf = (@options[:health_check] || {}).find {|k, v| k =~ /\A#{r[0]}\Z/i } || []
32
+ init_status = health_check_conf.fetch(1, {}).fetch('init-status', ACTIVE)
33
+ r + [init_status]
34
+ }
30
35
  @logger = options[:logger]
31
36
 
32
37
  # 名前は小文字に変換
@@ -54,6 +59,7 @@ module Murakumo
54
59
  :gossip_interval => options[:gossip_send_interval],
55
60
  :receive_timeout => options[:gossip_receive_timeout],
56
61
  :logger => @logger,
62
+ :ping_init_nodes => options[:ping_init_nodes],
57
63
  })
58
64
 
59
65
  # ノードの更新をフック
@@ -153,7 +159,15 @@ module Murakumo
153
159
  exec_start_script(@options[:on_start])
154
160
  end
155
161
 
156
- @gossip.start
162
+ @logger.info("Delay of a gossip start: #{@options[:gossip_start_delay]}")
163
+
164
+ Thread.start do
165
+ # ゴシッププロトコルの開始を遅延
166
+ sleep @options[:gossip_start_delay]
167
+
168
+ @logger.info('Gossip was started')
169
+ @gossip.start
170
+ end
157
171
  end
158
172
 
159
173
  def exec_start_script(script)
@@ -200,6 +214,8 @@ module Murakumo
200
214
  'gossip-receive-timeout',
201
215
  @gossip.context.receive_timeout
202
216
  ]},
217
+ :ping_init_nodes => 'ping-init-nodes',
218
+ :gossip_start_delay => 'gossip-start-delay',
203
219
  }
204
220
 
205
221
  hash = {}
@@ -230,6 +246,16 @@ module Murakumo
230
246
  if @options.config_file
231
247
  if @options.config_file['health-check']
232
248
  hash['health-check'] = @options.config_file['health-check']
249
+
250
+ # ちょっと直したい…
251
+ hash['health-check'].values.each do |h|
252
+ next unless h['init-status']
253
+
254
+ h['init-status'] = {
255
+ ACTIVE => 'active' ,
256
+ INACTIVE => 'inactive',
257
+ }.fetch(h['init-status'])
258
+ end
233
259
  end
234
260
 
235
261
  if @options.config_file['activity-check']
@@ -45,7 +45,7 @@ Status: #{status}
45
45
  EOS
46
46
  end
47
47
 
48
- @logger.info("sent the notice: #{status}")
48
+ @logger.info("sent notice: #{status}")
49
49
  rescue Exception => e
50
50
  message = (["#{e.class}: #{e.message}"] + (e.backtrace || [])).join("\n\tfrom ")
51
51
  @logger.error("health check failed: #{@name}: #{message}")
@@ -89,7 +89,7 @@ module Murakumo
89
89
  def start
90
90
  # 各種変数は初期状態にする
91
91
  @alive = true
92
- @normal_health = true
92
+ @normal_health = (@options['init-status'] == ACTIVE)
93
93
  @healthy_count = 0
94
94
  @unhealthy_count = 0
95
95
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murakumo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-22 00:00:00 Z
18
+ date: 2012-02-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubydns
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- hash: 17
44
+ hash: 31
45
45
  segments:
46
46
  - 0
47
47
  - 2
48
- - 3
49
- version: 0.2.3
48
+ - 4
49
+ version: 0.2.4
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
@@ -99,43 +99,43 @@ extra_rdoc_files: []
99
99
 
100
100
  files:
101
101
  - README
102
- - bin/murakumo-show-ec2-instances
103
102
  - bin/murakumo-show-ec2-private-ip-addresses
104
- - bin/murakumo-attach-ec2-attach-interface
105
- - bin/murakumo
103
+ - bin/murakumo-install-init-script
106
104
  - bin/murakumo-show-ec2-tags
107
- - bin/murakumo-show-ip-address
108
105
  - bin/murakumo-show-ec2-interfaces
109
- - bin/murakumo-install-init-script
106
+ - bin/murakumo-show-ip-address
107
+ - bin/murakumo-show-ec2-instances
108
+ - bin/murakumo-attach-ec2-attach-interface
110
109
  - bin/mrkmctl
110
+ - bin/murakumo
111
+ - lib/cli/murakumo_options.rb
111
112
  - lib/cli/mrkmctl.rb
113
+ - lib/cli/mrkmctl_options.rb
112
114
  - lib/cli/murakumo.rb
113
- - lib/cli/murakumo_options.rb
114
115
  - lib/cli/murakumo_initializer_context.rb
115
- - lib/cli/mrkmctl_options.rb
116
- - lib/misc/murakumo_const.rb
116
+ - lib/srv/murakumo_health_check_notifier.rb
117
+ - lib/srv/murakumo_balancer.rb
118
+ - lib/srv/murakumo_server.rb
119
+ - lib/srv/murakumo_health_checker.rb
120
+ - lib/srv/murakumo_cloud.rb
121
+ - lib/srv/murakumo_activity_check_notifier.rb
122
+ - lib/srv/murakumo_activity_checker.rb
123
+ - lib/srv/murakumo_health_check_context.rb
117
124
  - lib/util/murakumo_ec2_private_ip_addresses.rb
118
125
  - lib/util/murakumo_ec2_instances.rb
126
+ - lib/util/murakumo_ec2_client.rb
119
127
  - lib/util/murakumo_ec2_tags.rb
120
- - lib/util/murakumo_ec2_interfaces.rb
121
128
  - lib/util/murakumo_self_ip_address.rb
129
+ - lib/util/murakumo_ec2_interfaces.rb
122
130
  - lib/util/murakumo_ec2_attach_interface.rb
123
- - lib/util/murakumo_ec2_client.rb
124
- - lib/srv/murakumo_health_check_context.rb
125
- - lib/srv/murakumo_server.rb
126
- - lib/srv/murakumo_health_check_notifier.rb
127
- - lib/srv/murakumo_activity_check_notifier.rb
128
- - lib/srv/murakumo_activity_checker.rb
129
- - lib/srv/murakumo_health_checker.rb
130
- - lib/srv/murakumo_balancer.rb
131
- - lib/srv/murakumo_cloud.rb
132
- - etc/murakumo.server
133
- - etc/murakumo-init.rb.for-ec2
134
- - etc/murakumo.yml.example
135
- - etc/gai.conf.example
131
+ - lib/misc/murakumo_const.rb
136
132
  - etc/murakumo-update-config-for-ec2
133
+ - etc/gai.conf.example
137
134
  - etc/attach_if.sh.example
135
+ - etc/murakumo.yml.example
138
136
  - etc/dhclient-script.patch
137
+ - etc/murakumo-init.rb.for-ec2
138
+ - etc/murakumo.server
139
139
  homepage: https://github.com/cookpad/murakumo/wiki
140
140
  licenses: []
141
141
 
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  requirements: []
166
166
 
167
167
  rubyforge_project:
168
- rubygems_version: 1.8.15
168
+ rubygems_version: 1.8.1
169
169
  signing_key:
170
170
  specification_version: 3
171
171
  summary: Murakumo is the internal DNS server which manages name information using a gossip protocol.