big_brother 0.1.0

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.
Files changed (48) hide show
  1. data/.gitignore +21 -0
  2. data/.rake_commit +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +6 -0
  8. data/big_brother.gemspec +33 -0
  9. data/bin/bigbro +6 -0
  10. data/bin/ocf_big_brother +174 -0
  11. data/config.ru +5 -0
  12. data/lib/big_brother.rb +49 -0
  13. data/lib/big_brother/app.rb +30 -0
  14. data/lib/big_brother/cli.rb +82 -0
  15. data/lib/big_brother/cluster.rb +70 -0
  16. data/lib/big_brother/configuration.rb +48 -0
  17. data/lib/big_brother/ipvs.rb +51 -0
  18. data/lib/big_brother/logger.rb +11 -0
  19. data/lib/big_brother/node.rb +30 -0
  20. data/lib/big_brother/shell_executor.rb +18 -0
  21. data/lib/big_brother/status_file.rb +26 -0
  22. data/lib/big_brother/ticker.rb +28 -0
  23. data/lib/big_brother/version.rb +3 -0
  24. data/lib/sinatra/synchrony.rb +40 -0
  25. data/lib/thin/backends/tcp_server_with_callbacks.rb +20 -0
  26. data/lib/thin/callback_rack_handler.rb +14 -0
  27. data/lib/thin/callbacks.rb +19 -0
  28. data/spec/big_brother/app_spec.rb +127 -0
  29. data/spec/big_brother/cluster_spec.rb +102 -0
  30. data/spec/big_brother/configuration_spec.rb +81 -0
  31. data/spec/big_brother/ipvs_spec.rb +26 -0
  32. data/spec/big_brother/node_spec.rb +44 -0
  33. data/spec/big_brother/shell_executor_spec.rb +21 -0
  34. data/spec/big_brother/status_file_spec.rb +39 -0
  35. data/spec/big_brother/ticker_spec.rb +60 -0
  36. data/spec/big_brother/version_spec.rb +7 -0
  37. data/spec/big_brother_spec.rb +119 -0
  38. data/spec/spec_helper.rb +57 -0
  39. data/spec/support/example_config.yml +34 -0
  40. data/spec/support/factories/cluster_factory.rb +13 -0
  41. data/spec/support/factories/node_factory.rb +9 -0
  42. data/spec/support/ipvsadm +3 -0
  43. data/spec/support/mock_session.rb +14 -0
  44. data/spec/support/null_logger.rb +7 -0
  45. data/spec/support/playback_executor.rb +13 -0
  46. data/spec/support/recording_executor.rb +11 -0
  47. data/spec/support/stub_server.rb +22 -0
  48. metadata +271 -0
@@ -0,0 +1,57 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rspec'
4
+ require 'rack/test'
5
+ require 'big_brother'
6
+ require "socket"
7
+
8
+ Dir.glob("#{File.expand_path('support', File.dirname(__FILE__))}/**/*.rb").each { |f| require f }
9
+
10
+ RSpec.configure do |config|
11
+ config.expect_with :rspec
12
+ config.include Rack::Test::Methods
13
+
14
+ config.around(:each) do |spec|
15
+ ipvs = BigBrother.ipvs
16
+ @recording_executor = RecordingExecutor.new
17
+ BigBrother.ipvs = BigBrother::IPVS.new(@recording_executor)
18
+ spec.run
19
+ BigBrother.ipvs = ipvs
20
+ end
21
+
22
+ config.before(:each) do
23
+ BigBrother.clusters.replace({})
24
+ FileUtils.rm_rf(BigBrother.config_dir)
25
+ BigBrother.logger = NullLogger.new
26
+ end
27
+ end
28
+
29
+ def run_in_reactor
30
+ around(:each) do |spec|
31
+ EM.synchrony do
32
+ spec.run
33
+ EM.stop
34
+ end
35
+ end
36
+ end
37
+
38
+ def with_litmus_server(ip, port, health)
39
+ around(:each) do |spec|
40
+ server = StubServer.new(<<-HTTP, 0.25, port, ip)
41
+ HTTP/1.0 200 OK
42
+ Connection: close
43
+
44
+ Health: #{health}
45
+ HTTP
46
+ spec.run
47
+ server.stop
48
+ end
49
+ end
50
+
51
+ def public_ip_address
52
+ local_ip = UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
53
+ end
54
+
55
+ BigBrother.config_dir = "/tmp/big_brother"
56
+
57
+ TEST_CONFIG = File.expand_path('support/example_config.yml', File.dirname(__FILE__))
@@ -0,0 +1,34 @@
1
+ ---
2
+ test1:
3
+ checkInterval: 1
4
+ scheduler: wrr
5
+ fwmark: 1
6
+ nodes:
7
+ - address: 127.0.0.1
8
+ port: 9001
9
+ path: /test/valid
10
+ - address: 127.0.0.1
11
+ port: 9002
12
+ path: /test/valid
13
+ test2:
14
+ checkInterval: 1
15
+ scheduler: wrr
16
+ fwmark: 2
17
+ nodes:
18
+ - address: 127.0.0.1
19
+ port: 9001
20
+ path: /test/invalid
21
+ - address: 127.0.0.1
22
+ port: 9002
23
+ path: /test/invalid
24
+ test3:
25
+ checkInterval: 1
26
+ scheduler: wrr
27
+ fwmark: 3
28
+ nodes:
29
+ - address: 127.0.0.1
30
+ port: 9001
31
+ path: /test/valid
32
+ - address: 127.0.0.1
33
+ port: 9002
34
+ path: /test/invalid
@@ -0,0 +1,13 @@
1
+ class Factory
2
+ def self.cluster(overrides = {})
3
+ BigBrother::Cluster.new(
4
+ overrides.fetch(:name, 'test'),
5
+ {
6
+ 'fwmark' => overrides.fetch(:fwmark, 100),
7
+ 'scheduler' => overrides.fetch(:scheduler, 'wrr'),
8
+ 'check_interval' => overrides.fetch(:check_interval, 1),
9
+ 'nodes' => overrides.fetch(:nodes, [])
10
+ }
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class Factory
2
+ def self.node(overrides = {})
3
+ BigBrother::Node.new(
4
+ overrides.fetch(:address, 'localhost'),
5
+ overrides.fetch(:port, 8081),
6
+ overrides.fetch(:path, '/test/status')
7
+ )
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ echo $@ >> /tmp/ipvsadm.log
@@ -0,0 +1,14 @@
1
+ # inlined from sinatra-synchrony
2
+ require 'rack/test'
3
+
4
+ module Rack
5
+ class MockSession
6
+ alias_method :request_original, :request
7
+ def request(uri, env)
8
+ EM.synchrony do
9
+ request_original uri, env
10
+ EM.stop
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ class NullLogger
2
+ def write(msg)
3
+ end
4
+
5
+ def info(msg)
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class PlaybackExecutor
2
+ def initialize
3
+ @responses = []
4
+ end
5
+
6
+ def invoke(command)
7
+ @responses.pop
8
+ end
9
+
10
+ def add_response(output, status)
11
+ @responses.push [output, status]
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class RecordingExecutor
2
+ attr_reader :commands
3
+
4
+ def initialize
5
+ @commands = []
6
+ end
7
+
8
+ def invoke(command)
9
+ @commands << command
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ class StubServer
2
+ module Server
3
+ attr_accessor :response, :delay
4
+ def receive_data(data)
5
+ EM.add_timer(@delay) {
6
+ send_data @response
7
+ close_connection_after_writing
8
+ }
9
+ end
10
+ end
11
+
12
+ def initialize(response, delay = 0, port = 8081, host = "127.0.0.1")
13
+ @sig = EventMachine::start_server(host, port, Server) { |s|
14
+ s.response = response
15
+ s.delay = delay
16
+ }
17
+ end
18
+
19
+ def stop
20
+ EventMachine.stop_server @sig
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,271 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: big_brother
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Braintree
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thin
16
+ requirement: &70321466649500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70321466649500
25
+ - !ruby/object:Gem::Dependency
26
+ name: async-rack
27
+ requirement: &70321466648640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.5.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70321466648640
36
+ - !ruby/object:Gem::Dependency
37
+ name: sinatra
38
+ requirement: &70321466648140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70321466648140
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-fiber_pool
49
+ requirement: &70321466647520 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70321466647520
58
+ - !ruby/object:Gem::Dependency
59
+ name: eventmachine
60
+ requirement: &70321466646780 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>'
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0.beta.1
66
+ - - <
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0.beta.100
69
+ type: :runtime
70
+ prerelease: false
71
+ version_requirements: *70321466646780
72
+ - !ruby/object:Gem::Dependency
73
+ name: em-http-request
74
+ requirement: &70321466645620 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: '1.0'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: *70321466645620
83
+ - !ruby/object:Gem::Dependency
84
+ name: em-synchrony
85
+ requirement: &70321466644700 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: *70321466644700
94
+ - !ruby/object:Gem::Dependency
95
+ name: em-resolv-replace
96
+ requirement: &70321466643840 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.1'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: *70321466643840
105
+ - !ruby/object:Gem::Dependency
106
+ name: em-syslog
107
+ requirement: &70321466642720 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: 0.0.2
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: *70321466642720
116
+ - !ruby/object:Gem::Dependency
117
+ name: rspec
118
+ requirement: &70321466641880 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ~>
122
+ - !ruby/object:Gem::Version
123
+ version: 2.9.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: *70321466641880
127
+ - !ruby/object:Gem::Dependency
128
+ name: rack-test
129
+ requirement: &70321466641380 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ version: 0.6.1
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: *70321466641380
138
+ - !ruby/object:Gem::Dependency
139
+ name: rake
140
+ requirement: &70321466640920 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: *70321466640920
149
+ - !ruby/object:Gem::Dependency
150
+ name: rake_commit
151
+ requirement: &70321466640060 !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ~>
155
+ - !ruby/object:Gem::Version
156
+ version: '0.13'
157
+ type: :development
158
+ prerelease: false
159
+ version_requirements: *70321466640060
160
+ - !ruby/object:Gem::Dependency
161
+ name: vagrant
162
+ requirement: &70321466639400 !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: *70321466639400
171
+ description: IPVS backend supervisor
172
+ email:
173
+ - code@getbraintree.com
174
+ executables:
175
+ - bigbro
176
+ - ocf_big_brother
177
+ extensions: []
178
+ extra_rdoc_files: []
179
+ files:
180
+ - .gitignore
181
+ - .rake_commit
182
+ - .rvmrc
183
+ - Gemfile
184
+ - LICENSE
185
+ - README.md
186
+ - Rakefile
187
+ - big_brother.gemspec
188
+ - bin/bigbro
189
+ - bin/ocf_big_brother
190
+ - config.ru
191
+ - lib/big_brother.rb
192
+ - lib/big_brother/app.rb
193
+ - lib/big_brother/cli.rb
194
+ - lib/big_brother/cluster.rb
195
+ - lib/big_brother/configuration.rb
196
+ - lib/big_brother/ipvs.rb
197
+ - lib/big_brother/logger.rb
198
+ - lib/big_brother/node.rb
199
+ - lib/big_brother/shell_executor.rb
200
+ - lib/big_brother/status_file.rb
201
+ - lib/big_brother/ticker.rb
202
+ - lib/big_brother/version.rb
203
+ - lib/sinatra/synchrony.rb
204
+ - lib/thin/backends/tcp_server_with_callbacks.rb
205
+ - lib/thin/callback_rack_handler.rb
206
+ - lib/thin/callbacks.rb
207
+ - spec/big_brother/app_spec.rb
208
+ - spec/big_brother/cluster_spec.rb
209
+ - spec/big_brother/configuration_spec.rb
210
+ - spec/big_brother/ipvs_spec.rb
211
+ - spec/big_brother/node_spec.rb
212
+ - spec/big_brother/shell_executor_spec.rb
213
+ - spec/big_brother/status_file_spec.rb
214
+ - spec/big_brother/ticker_spec.rb
215
+ - spec/big_brother/version_spec.rb
216
+ - spec/big_brother_spec.rb
217
+ - spec/spec_helper.rb
218
+ - spec/support/example_config.yml
219
+ - spec/support/factories/cluster_factory.rb
220
+ - spec/support/factories/node_factory.rb
221
+ - spec/support/ipvsadm
222
+ - spec/support/mock_session.rb
223
+ - spec/support/null_logger.rb
224
+ - spec/support/playback_executor.rb
225
+ - spec/support/recording_executor.rb
226
+ - spec/support/stub_server.rb
227
+ homepage: https://github.com/braintree/big_brother
228
+ licenses: []
229
+ post_install_message:
230
+ rdoc_options: []
231
+ require_paths:
232
+ - lib
233
+ required_ruby_version: !ruby/object:Gem::Requirement
234
+ none: false
235
+ requirements:
236
+ - - ! '>='
237
+ - !ruby/object:Gem::Version
238
+ version: '0'
239
+ required_rubygems_version: !ruby/object:Gem::Requirement
240
+ none: false
241
+ requirements:
242
+ - - ! '>='
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ requirements: []
246
+ rubyforge_project:
247
+ rubygems_version: 1.8.15
248
+ signing_key:
249
+ specification_version: 3
250
+ summary: Process to monitor and update weights for servers in an IPVS pool
251
+ test_files:
252
+ - spec/big_brother/app_spec.rb
253
+ - spec/big_brother/cluster_spec.rb
254
+ - spec/big_brother/configuration_spec.rb
255
+ - spec/big_brother/ipvs_spec.rb
256
+ - spec/big_brother/node_spec.rb
257
+ - spec/big_brother/shell_executor_spec.rb
258
+ - spec/big_brother/status_file_spec.rb
259
+ - spec/big_brother/ticker_spec.rb
260
+ - spec/big_brother/version_spec.rb
261
+ - spec/big_brother_spec.rb
262
+ - spec/spec_helper.rb
263
+ - spec/support/example_config.yml
264
+ - spec/support/factories/cluster_factory.rb
265
+ - spec/support/factories/node_factory.rb
266
+ - spec/support/ipvsadm
267
+ - spec/support/mock_session.rb
268
+ - spec/support/null_logger.rb
269
+ - spec/support/playback_executor.rb
270
+ - spec/support/recording_executor.rb
271
+ - spec/support/stub_server.rb