flapjack 0.6.43 → 0.6.44

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 (90) hide show
  1. data/bin/flapjack +4 -2
  2. data/bin/flapjack-nagios-receiver +4 -1
  3. data/bin/flapjack-populator +4 -1
  4. data/etc/flapjack_config.yaml.example +111 -106
  5. data/features/steps/notifications_steps.rb +6 -6
  6. data/lib/flapjack/configuration.rb +76 -24
  7. data/lib/flapjack/coordinator.rb +27 -44
  8. data/lib/flapjack/data/entity.rb +28 -7
  9. data/lib/flapjack/data/entity_check.rb +18 -20
  10. data/lib/flapjack/executive.rb +5 -4
  11. data/lib/flapjack/gateways/api.rb +391 -0
  12. data/lib/flapjack/gateways/api/entity_check_presenter.rb +185 -0
  13. data/lib/flapjack/gateways/api/entity_presenter.rb +70 -0
  14. data/lib/flapjack/gateways/base.rb +38 -0
  15. data/lib/flapjack/{notification → gateways}/email.rb +4 -5
  16. data/lib/flapjack/{notification → gateways}/email/alert.html.haml +0 -0
  17. data/lib/flapjack/{notification → gateways}/email/alert.text.erb +0 -0
  18. data/lib/flapjack/gateways/jabber.rb +387 -0
  19. data/lib/flapjack/gateways/oobetet.rb +241 -0
  20. data/lib/flapjack/gateways/pagerduty.rb +247 -0
  21. data/lib/flapjack/{notification → gateways}/sms.rb +5 -6
  22. data/lib/flapjack/{notification → gateways}/sms/messagenet.rb +1 -1
  23. data/lib/flapjack/gateways/web.rb +293 -0
  24. data/lib/flapjack/{web → gateways/web}/views/_css.haml +0 -0
  25. data/lib/flapjack/{web → gateways/web}/views/_nav.haml +0 -0
  26. data/lib/flapjack/{web → gateways/web}/views/check.haml +0 -0
  27. data/lib/flapjack/{web → gateways/web}/views/contact.haml +0 -0
  28. data/lib/flapjack/{web → gateways/web}/views/contacts.haml +0 -0
  29. data/lib/flapjack/{web → gateways/web}/views/index.haml +0 -0
  30. data/lib/flapjack/{web → gateways/web}/views/self_stats.haml +0 -0
  31. data/lib/flapjack/pikelet.rb +0 -23
  32. data/lib/flapjack/version.rb +1 -1
  33. data/spec/lib/flapjack/coordinator_spec.rb +56 -36
  34. data/spec/lib/flapjack/data/entity_spec.rb +53 -4
  35. data/spec/lib/flapjack/{api → gateways/api}/entity_check_presenter_spec.rb +10 -13
  36. data/spec/lib/flapjack/{api → gateways/api}/entity_presenter_spec.rb +10 -10
  37. data/spec/lib/flapjack/{api_spec.rb → gateways/api_spec.rb} +14 -14
  38. data/spec/lib/flapjack/gateways/email_spec.rb +6 -0
  39. data/spec/lib/flapjack/{jabber_spec.rb → gateways/jabber_spec.rb} +9 -9
  40. data/spec/lib/flapjack/{oobetet_spec.rb → gateways/oobetet_spec.rb} +10 -10
  41. data/spec/lib/flapjack/{pagerduty_spec.rb → gateways/pagerduty_spec.rb} +11 -11
  42. data/spec/lib/flapjack/gateways/sms_spec.rb +6 -0
  43. data/spec/lib/flapjack/{web_spec.rb → gateways/web_spec.rb} +4 -4
  44. metadata +46 -79
  45. data/bin/install-flapjack-systemwide +0 -58
  46. data/features/steps/flapjack-importer_steps.rb +0 -109
  47. data/features/steps/flapjack-worker_steps.rb +0 -68
  48. data/lib/flapjack/api.rb +0 -388
  49. data/lib/flapjack/api/entity_check_presenter.rb +0 -181
  50. data/lib/flapjack/api/entity_presenter.rb +0 -66
  51. data/lib/flapjack/cli/worker_manager.rb +0 -46
  52. data/lib/flapjack/inifile.rb +0 -44
  53. data/lib/flapjack/jabber.rb +0 -383
  54. data/lib/flapjack/notifier_engine.rb +0 -40
  55. data/lib/flapjack/notifiers/mailer/init.rb +0 -3
  56. data/lib/flapjack/notifiers/mailer/mailer.rb +0 -51
  57. data/lib/flapjack/notifiers/xmpp/init.rb +0 -3
  58. data/lib/flapjack/notifiers/xmpp/xmpp.rb +0 -46
  59. data/lib/flapjack/oobetet.rb +0 -240
  60. data/lib/flapjack/pagerduty.rb +0 -242
  61. data/lib/flapjack/web.rb +0 -286
  62. data/spec.old/check_sandbox/echo +0 -3
  63. data/spec.old/check_sandbox/sandboxed_check +0 -5
  64. data/spec.old/configs/flapjack-notifier-couchdb.ini +0 -25
  65. data/spec.old/configs/flapjack-notifier.ini +0 -39
  66. data/spec.old/configs/recipients.ini +0 -14
  67. data/spec.old/helpers.rb +0 -15
  68. data/spec.old/inifile_spec.rb +0 -66
  69. data/spec.old/mock-notifiers/mock/init.rb +0 -3
  70. data/spec.old/mock-notifiers/mock/mock.rb +0 -19
  71. data/spec.old/notifier-directories/spoons/testmailer/init.rb +0 -20
  72. data/spec.old/notifier_application_spec.rb +0 -222
  73. data/spec.old/notifier_filters_spec.rb +0 -52
  74. data/spec.old/notifier_options_multiplexer_spec.rb +0 -71
  75. data/spec.old/notifier_options_spec.rb +0 -115
  76. data/spec.old/notifier_spec.rb +0 -57
  77. data/spec.old/notifiers/mailer_spec.rb +0 -36
  78. data/spec.old/notifiers/xmpp_spec.rb +0 -36
  79. data/spec.old/persistence/datamapper_spec.rb +0 -74
  80. data/spec.old/persistence/mock_persistence_backend.rb +0 -26
  81. data/spec.old/simple.ini +0 -6
  82. data/spec.old/spec.opts +0 -4
  83. data/spec.old/test-filters/blocker.rb +0 -13
  84. data/spec.old/test-filters/mock.rb +0 -13
  85. data/spec.old/transports/beanstalkd_spec.rb +0 -44
  86. data/spec.old/transports/mock_transport.rb +0 -58
  87. data/spec.old/worker_application_spec.rb +0 -62
  88. data/spec.old/worker_options_spec.rb +0 -83
  89. data/spec/lib/flapjack/notification/email_spec.rb +0 -6
  90. data/spec/lib/flapjack/notification/sms_spec.rb +0 -6
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'flapjack/pikelet'
4
- require 'flapjack/notification/sms/messagenet'
4
+ require 'flapjack/gateways/sms/messagenet'
5
5
 
6
6
  module Flapjack
7
- module Notification
7
+ module Gateways
8
8
 
9
9
  class Sms
10
-
11
- extend Flapjack::ResquePikelet
10
+ extend Flapjack::Gateways::Resque
12
11
 
13
12
  class << self
14
13
 
@@ -41,9 +40,9 @@ module Flapjack
41
40
  message += " at #{Time.at(time).strftime('%-d %b %H:%M')}, #{summary}"
42
41
 
43
42
  notification['message'] = message
44
- Flapjack::Notification::Sms::Messagenet.sender(notification,
43
+ Flapjack::Gateways::Sms::Messagenet.sender(notification,
45
44
  :logger => opts[:logger],
46
- :config => Flapjack::Notification::Sms.instance_variable_get('@config'))
45
+ :config => Flapjack::Gateways::Sms.instance_variable_get('@config'))
47
46
  end
48
47
 
49
48
  end
@@ -4,7 +4,7 @@ require 'net/http'
4
4
  require 'uri'
5
5
 
6
6
  module Flapjack
7
- module Notification
7
+ module Gateways
8
8
  class Sms
9
9
  class Messagenet
10
10
 
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'chronic'
4
+ require 'chronic_duration'
5
+ require 'sinatra/base'
6
+ require 'haml'
7
+ require 'rack/fiber_pool'
8
+
9
+ require 'async-rack'
10
+ require 'flapjack/rack_logger'
11
+
12
+ require 'flapjack/data/contact'
13
+ require 'flapjack/data/entity_check'
14
+ require 'flapjack/redis_pool'
15
+ require 'flapjack/utility'
16
+
17
+ require 'flapjack/gateways/base'
18
+
19
+ module Flapjack
20
+
21
+ module Gateways
22
+
23
+ class Web < Sinatra::Base
24
+
25
+ if defined?(FLAPJACK_ENV) && 'test'.eql?(FLAPJACK_ENV)
26
+ # expose test errors properly
27
+ set :raise_errors, true
28
+ set :show_exceptions, false
29
+ else
30
+ rescue_exception = Proc.new do |env, e|
31
+ if settings.show_exceptions?
32
+ # ensure the sinatra error page shows properly
33
+ request = Sinatra::Request.new(env)
34
+ printer = Sinatra::ShowExceptions.new(proc{ raise e })
35
+ s, h, b = printer.call(env)
36
+ [s, h, b]
37
+ else
38
+ logger.error e.message
39
+ logger.error e.backtrace.join("\n")
40
+ [503, {}, ""]
41
+ end
42
+ end
43
+
44
+ # doesn't work with Rack::Test unless we wrap tests in EM.synchrony blocks
45
+ use Rack::FiberPool, :size => 25, :rescue_exception => rescue_exception
46
+ end
47
+ use Rack::MethodOverride
48
+
49
+ class << self
50
+ include Flapjack::Gateways::Thin
51
+
52
+ attr_accessor :redis
53
+
54
+ alias_method :thin_bootstrap, :bootstrap
55
+ alias_method :thin_cleanup, :cleanup
56
+
57
+ def bootstrap(opts = {})
58
+ thin_bootstrap(opts)
59
+ @redis = Flapjack::RedisPool.new(:config => opts[:redis_config], :size => 1)
60
+
61
+ if config && config['access_log']
62
+ access_logger = Flapjack::RackLogger.new(config['access_log'])
63
+ use Rack::CommonLogger, access_logger
64
+ end
65
+ end
66
+
67
+ def cleanup
68
+ @redis.empty! if @redis
69
+ thin_cleanup
70
+ end
71
+
72
+ end
73
+
74
+ include Flapjack::Utility
75
+
76
+ set :views, settings.root + '/web/views'
77
+
78
+ def redis
79
+ self.class.instance_variable_get('@redis')
80
+ end
81
+
82
+ def logger
83
+ self.class.instance_variable_get('@logger')
84
+ end
85
+
86
+ get '/' do
87
+ self_stats
88
+
89
+ # TODO (?) recast as Entity.all do |e|; e.checks.do |ec|; ...
90
+ @states = redis.keys('*:*:states').map { |r|
91
+ parts = r.split(':')[0..1]
92
+ [parts[0], parts[1]] + entity_check_state(parts[0], parts[1])
93
+ }.compact.sort_by {|parts| parts }
94
+ haml :index
95
+ end
96
+
97
+ get '/failing' do
98
+ self_stats
99
+ @states = redis.zrange('failed_checks', 0, -1).map {|key|
100
+ parts = key.split(':')
101
+ [parts[0], parts[1]] + entity_check_state(parts[0], parts[1])
102
+ }.compact.sort_by {|parts| parts}
103
+ haml :index
104
+ end
105
+
106
+ get '/self_stats' do
107
+ self_stats
108
+ haml :self_stats
109
+ end
110
+
111
+ get '/check' do
112
+ @entity = params[:entity]
113
+ @check = params[:check]
114
+
115
+ entity_check = get_entity_check(@entity, @check)
116
+ return 404 if entity_check.nil?
117
+
118
+ last_change = entity_check.last_change
119
+
120
+ @check_state = entity_check.state
121
+ @check_last_update = entity_check.last_update
122
+ @check_last_change = last_change
123
+ @check_summary = entity_check.summary
124
+ @last_notifications = entity_check.last_notifications_of_each_type
125
+ @scheduled_maintenances = entity_check.maintenances(nil, nil, :scheduled => true)
126
+ @acknowledgement_id = entity_check.failed? ?
127
+ entity_check.event_count_at(entity_check.last_change) : nil
128
+
129
+ @current_scheduled_maintenance = entity_check.current_maintenance(:scheduled => true)
130
+ @current_unscheduled_maintenance = entity_check.current_maintenance(:scheduled => false)
131
+
132
+ @contacts = entity_check.contacts
133
+
134
+ haml :check
135
+ end
136
+
137
+ post '/acknowledgements/:entity/:check' do
138
+ @entity = params[:entity]
139
+ @check = params[:check]
140
+ @summary = params[:summary]
141
+ @acknowledgement_id = params[:acknowledgement_id]
142
+
143
+ dur = ChronicDuration.parse(params[:duration] || '')
144
+ @duration = (dur.nil? || (dur <= 0)) ? (4 * 60 * 60) : dur
145
+
146
+ entity_check = get_entity_check(@entity, @check)
147
+ return 404 if entity_check.nil?
148
+
149
+ ack = entity_check.create_acknowledgement('summary' => (@summary || ''),
150
+ 'acknowledgement_id' => @acknowledgement_id, 'duration' => @duration)
151
+
152
+ redirect back
153
+ end
154
+
155
+ # FIXME: there is bound to be a more idiomatic / restful way of doing this
156
+ # (probably using 'delete' or 'patch')
157
+ post '/end_unscheduled_maintenance/:entity/:check' do
158
+ @entity = params[:entity]
159
+ @check = params[:check]
160
+
161
+ entity_check = get_entity_check(@entity, @check)
162
+ return 404 if entity_check.nil?
163
+
164
+ entity_check.end_unscheduled_maintenance
165
+
166
+ redirect back
167
+ end
168
+
169
+ # create scheduled maintenance
170
+ post '/scheduled_maintenances/:entity/:check' do
171
+ start_time = Chronic.parse(params[:start_time]).to_i
172
+ raise ArgumentError, "start time parsed to zero" unless start_time > 0
173
+ duration = ChronicDuration.parse(params[:duration])
174
+ summary = params[:summary]
175
+
176
+ entity_check = get_entity_check(params[:entity], params[:check])
177
+ return 404 if entity_check.nil?
178
+
179
+ entity_check.create_scheduled_maintenance(:start_time => start_time,
180
+ :duration => duration,
181
+ :summary => summary)
182
+ redirect back
183
+ end
184
+
185
+ # modify scheduled maintenance
186
+ patch '/scheduled_maintenances/:entity/:check' do
187
+ entity_check = get_entity_check(params[:entity], params[:check])
188
+ return 404 if entity_check.nil?
189
+
190
+ end_time = Chronic.parse(params[:end_time]).to_i
191
+ start_time = params[:start_time].to_i
192
+ raise ArgumentError, "start time parsed to zero" unless start_time > 0
193
+
194
+ patches = {}
195
+ patches[:end_time] = end_time if end_time && (end_time > start_time)
196
+
197
+ raise ArgumentError.new("no valid data received to patch with") if patches.empty?
198
+
199
+ entity_check.update_scheduled_maintenance(start_time, patches)
200
+ redirect back
201
+ end
202
+
203
+ # delete a scheduled maintenance
204
+ delete '/scheduled_maintenances/:entity/:check' do
205
+ entity_check = get_entity_check(params[:entity], params[:check])
206
+ return 404 if entity_check.nil?
207
+
208
+ entity_check.delete_scheduled_maintenance(:start_time => params[:start_time].to_i)
209
+ redirect back
210
+ end
211
+
212
+ get '/contacts' do
213
+ @contacts = Flapjack::Data::Contact.all(:redis => redis)
214
+ haml :contacts
215
+ end
216
+
217
+ get "/contacts/:contact" do
218
+ contact_id = params[:contact]
219
+
220
+ if contact_id
221
+ @contact = Flapjack::Data::Contact.find_by_id(contact_id, :redis => redis)
222
+ end
223
+
224
+ unless @contact
225
+ status 404
226
+ return
227
+ end
228
+
229
+ if @contact.media.has_key?('pagerduty')
230
+ @pagerduty_credentials = @contact.pagerduty_credentials
231
+ end
232
+
233
+ @entities_and_checks = @contact.entities_and_checks.sort_by {|ec|
234
+ ec[:entity].name
235
+ }
236
+
237
+ haml :contact
238
+ end
239
+
240
+ private
241
+
242
+ def get_entity_check(entity, check)
243
+ entity_obj = (entity && entity.length > 0) ?
244
+ Flapjack::Data::Entity.find_by_name(entity, :redis => redis) : nil
245
+ return if entity_obj.nil? || (check.nil? || check.length == 0)
246
+ Flapjack::Data::EntityCheck.for_entity(entity_obj, check, :redis => redis)
247
+ end
248
+
249
+ def entity_check_state(entity_name, check)
250
+ entity = Flapjack::Data::Entity.find_by_name(entity_name,
251
+ :redis => redis)
252
+ return if entity.nil?
253
+ entity_check = Flapjack::Data::EntityCheck.for_entity(entity,
254
+ check, :redis => redis)
255
+ latest_notif =
256
+ {:problem => entity_check.last_problem_notification,
257
+ :recovery => entity_check.last_recovery_notification,
258
+ :acknowledgement => entity_check.last_acknowledgement_notification
259
+ }.max_by {|n| n[1] || 0}
260
+ [(entity_check.state || '-'),
261
+ (entity_check.last_change || '-'),
262
+ (entity_check.last_update || '-'),
263
+ entity_check.in_unscheduled_maintenance?,
264
+ entity_check.in_scheduled_maintenance?,
265
+ latest_notif[0],
266
+ latest_notif[1]
267
+ ]
268
+ end
269
+
270
+ def self_stats
271
+ @fqdn = `/bin/hostname -f`.chomp
272
+ @pid = Process.pid
273
+ @instance_id = "#{@fqdn}:#{@pid}"
274
+
275
+ @keys = redis.keys '*'
276
+ @count_failing_checks = redis.zcard 'failed_checks'
277
+ @count_all_checks = redis.keys('check:*:*').length
278
+ @executive_instances = redis.zrange('executive_instances', '0', '-1', :withscores => true)
279
+ @event_counters = redis.hgetall('event_counters')
280
+ @event_counters_instance = redis.hgetall("event_counters:#{@instance_id}")
281
+ @boot_time = Time.at(redis.zscore('executive_instances', @instance_id).to_i)
282
+ @uptime = Time.now.to_i - @boot_time.to_i
283
+ @uptime_string = time_period_in_words(@uptime)
284
+ @event_rate_all = (@uptime > 0) ?
285
+ (@event_counters_instance['all'].to_f / @uptime) : 0
286
+ @events_queued = redis.llen('events')
287
+ end
288
+
289
+ end
290
+
291
+ end
292
+
293
+ end
File without changes
File without changes
File without changes
File without changes
@@ -61,27 +61,4 @@ module Flapjack
61
61
 
62
62
  end
63
63
 
64
- module ResquePikelet
65
- include Flapjack::Pikelet
66
- end
67
-
68
- module ThinPikelet
69
- include Flapjack::Pikelet
70
-
71
- attr_accessor :port
72
-
73
- alias_method :orig_bootstrap, :bootstrap
74
-
75
- def bootstrap(opts = {})
76
- return if @bootstrapped
77
-
78
- if config = opts[:config]
79
- @port = config['port'] ? config['port'].to_i : nil
80
- @port = 3001 if (@port.nil? || @port <= 0 || @port > 65535)
81
- end
82
-
83
- orig_bootstrap(opts)
84
- end
85
-
86
- end
87
64
  end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.6.43"
4
+ VERSION = "0.6.44"
5
5
  end
@@ -1,23 +1,24 @@
1
1
  require 'spec_helper'
2
- require 'flapjack/coordinator'
3
2
 
4
- describe Flapjack::Coordinator do
3
+ require 'flapjack/configuration'
4
+ require 'flapjack/executive'
5
+
6
+ require 'flapjack/gateways/web'
7
+ require 'flapjack/gateways/jabber'
8
+ require 'flapjack/gateways/email'
5
9
 
6
- let(:fiber) { mock('Fiber') }
10
+ require 'flapjack/coordinator'
7
11
 
8
- let(:config) {
9
- {'redis' => {},
10
- 'executive' => {'enabled' => 'yes'},
11
- 'email_notifier' => {'enabled' => 'yes'},
12
- 'web' => {'enabled' => 'yes'}
13
- }
14
- }
12
+ describe Flapjack::Coordinator do
15
13
 
16
- let(:redis_config) { {} }
14
+ let(:fiber) { mock(Fiber) }
15
+ let(:config) { mock(Flapjack::Configuration) }
17
16
 
18
17
  # leaving actual testing of daemonisation to that class's tests
19
18
  it "daemonizes properly" do
20
- fc = Flapjack::Coordinator.new(config, redis_config)
19
+ config.should_receive(:for_redis).and_return({})
20
+ fc = Flapjack::Coordinator.new(config)
21
+
21
22
  fc.should_receive(:daemonize)
22
23
  fc.should_not_receive(:build_pikelet)
23
24
  fc.start(:daemonize => true, :signals => false)
@@ -25,17 +26,24 @@ describe Flapjack::Coordinator do
25
26
 
26
27
  it "runs undaemonized" do
27
28
  EM.should_receive(:synchrony).and_yield
29
+ config.should_receive(:for_redis).and_return({})
30
+ config.should_receive(:pikelets).and_return(Flapjack::Executive => {'enabled' => 'yes'})
31
+ config.should_receive(:gateways).and_return({})
28
32
 
29
- fc = Flapjack::Coordinator.new(config, redis_config)
30
- fc.should_receive(:build_pikelet).exactly(3).times
33
+ fc = Flapjack::Coordinator.new(config)
34
+ fc.should_receive(:build_pikelet)
31
35
  fc.start(:daemonize => false, :signals => false)
32
36
  end
33
37
 
34
38
  it "starts after daemonizing" do
35
39
  EM.should_receive(:synchrony).and_yield
36
40
 
37
- fc = Flapjack::Coordinator.new(config, redis_config)
38
- fc.should_receive(:build_pikelet).exactly(3).times
41
+ config.should_receive(:for_redis).and_return({})
42
+ config.should_receive(:pikelets).and_return(Flapjack::Executive => {'enabled' => 'yes'})
43
+ config.should_receive(:gateways).and_return({})
44
+
45
+ fc = Flapjack::Coordinator.new(config)
46
+ fc.should_receive(:build_pikelet)
39
47
  fc.after_daemonize
40
48
  end
41
49
 
@@ -46,7 +54,8 @@ describe Flapjack::Coordinator do
46
54
  Kernel.should_receive(:trap).with('TERM').and_yield
47
55
  Kernel.should_receive(:trap).with('QUIT').and_yield
48
56
 
49
- fc = Flapjack::Coordinator.new(config, redis_config)
57
+ config.should_receive(:for_redis).and_return({})
58
+ fc = Flapjack::Coordinator.new(config)
50
59
  fc.should_receive(:stop).exactly(3).times
51
60
 
52
61
  fc.send(:setup_signals)
@@ -59,7 +68,8 @@ describe Flapjack::Coordinator do
59
68
  Kernel.should_receive(:trap).with('TERM').and_yield
60
69
  Kernel.should_not_receive(:trap).with('QUIT')
61
70
 
62
- fc = Flapjack::Coordinator.new(config, redis_config)
71
+ config.should_receive(:for_redis).and_return({})
72
+ fc = Flapjack::Coordinator.new(config)
63
73
  fc.should_receive(:stop).twice
64
74
 
65
75
  fc.send(:setup_signals)
@@ -78,7 +88,7 @@ describe Flapjack::Coordinator do
78
88
  email = mock('worker')
79
89
  email.should_receive(:is_a?).with(Flapjack::GenericPikelet).twice.and_return(false)
80
90
  email.should_receive(:shutdown)
81
- Flapjack::Notification::Email.should_receive(:cleanup)
91
+ Flapjack::Gateways::Email.should_receive(:cleanup)
82
92
 
83
93
  backend = mock('backend')
84
94
  backend.should_receive(:size).twice.and_return(1, 0)
@@ -86,7 +96,7 @@ describe Flapjack::Coordinator do
86
96
  web.should_receive(:is_a?).with(Flapjack::GenericPikelet).twice.and_return(false)
87
97
  web.should_receive(:backend).twice.and_return(backend)
88
98
  web.should_receive(:stop!)
89
- Flapjack::Web.should_receive(:cleanup)
99
+ Flapjack::Gateways::Web.should_receive(:cleanup)
90
100
 
91
101
  redis = mock('redis')
92
102
  redis.should_receive(:quit)
@@ -104,10 +114,12 @@ describe Flapjack::Coordinator do
104
114
  EM.should_receive(:stop)
105
115
 
106
116
  pikelets = [{:fiber => fiber_exec, :instance => exec, :class => Flapjack::Executive},
107
- {:fiber => fiber_rsq, :instance => email, :class => Flapjack::Notification::Email},
108
- {:instance => web, :class => Flapjack::Web}]
117
+ {:fiber => fiber_rsq, :instance => email, :class => Flapjack::Gateways::Email},
118
+ {:instance => web, :class => Flapjack::Gateways::Web}]
119
+
120
+ config.should_receive(:for_redis).and_return({})
109
121
 
110
- fc = Flapjack::Coordinator.new(config, redis_config)
122
+ fc = Flapjack::Coordinator.new(config)
111
123
  fc.instance_variable_set('@redis_options', {})
112
124
  fc.instance_variable_set('@pikelets', pikelets)
113
125
  fc.stop
@@ -123,8 +135,10 @@ describe Flapjack::Coordinator do
123
135
  fiber.should_receive(:resume)
124
136
  Fiber.should_receive(:new).and_yield.and_return(fiber)
125
137
 
126
- fc = Flapjack::Coordinator.new(config, redis_config)
127
- fc.send(:build_pikelet, 'executive', {})
138
+ config.should_receive(:for_redis).and_return({})
139
+
140
+ fc = Flapjack::Coordinator.new(config)
141
+ fc.send(:build_pikelet, Flapjack::Executive, {'enabled' => 'yes'})
128
142
  pikelets = fc.instance_variable_get('@pikelets')
129
143
  pikelets.should_not be_nil
130
144
  pikelets.should be_an(Array)
@@ -135,21 +149,23 @@ describe Flapjack::Coordinator do
135
149
  it "handles an exception raised by a fiber pikelet" do
136
150
  jabber = mock('jabber')
137
151
  jabber.should_receive(:bootstrap)
138
- Flapjack::Jabber.should_receive(:new).and_return(jabber)
152
+ Flapjack::Gateways::Jabber.should_receive(:new).and_return(jabber)
139
153
  jabber.should_receive(:is_a?).with(Flapjack::GenericPikelet).and_return(true)
140
154
  jabber.should_receive(:main).and_raise(RuntimeError)
141
155
 
142
156
  fiber.should_receive(:resume)
143
157
  Fiber.should_receive(:new).and_yield.and_return(fiber)
144
158
 
145
- fc = Flapjack::Coordinator.new(config, redis_config)
159
+ config.should_receive(:for_redis).and_return({})
160
+
161
+ fc = Flapjack::Coordinator.new(config)
146
162
  fc.should_receive(:stop)
147
- fc.send(:build_pikelet, 'jabber_gateway', {})
163
+ fc.send(:build_pikelet, Flapjack::Gateways::Jabber, {'enabled' => 'yes'})
148
164
  pikelets = fc.instance_variable_get('@pikelets')
149
165
  pikelets.should_not be_nil
150
166
  pikelets.should be_an(Array)
151
167
  pikelets.should have(1).pikelet
152
- pikelets.first.should == {:fiber => fiber, :class => Flapjack::Jabber, :instance => jabber}
168
+ pikelets.first.should == {:fiber => fiber, :class => Flapjack::Gateways::Jabber, :instance => jabber}
153
169
  end
154
170
 
155
171
  it "creates a resque worker pikelet" do
@@ -164,13 +180,15 @@ describe Flapjack::Coordinator do
164
180
  fiber.should_receive(:resume)
165
181
  Fiber.should_receive(:new).and_yield.and_return(fiber)
166
182
 
167
- fc = Flapjack::Coordinator.new(config, redis_config)
168
- fc.send(:build_pikelet, 'email_notifier', {})
183
+ config.should_receive(:for_redis).and_return({})
184
+
185
+ fc = Flapjack::Coordinator.new(config)
186
+ fc.send(:build_pikelet, Flapjack::Gateways::Email, {'enabled' => 'yes'})
169
187
  pikelets = fc.instance_variable_get('@pikelets')
170
188
  pikelets.should_not be_nil
171
189
  pikelets.should be_an(Array)
172
190
  pikelets.should have(1).pikelet
173
- pikelets.first.should == {:fiber => fiber, :class => Flapjack::Notification::Email,
191
+ pikelets.first.should == {:fiber => fiber, :class => Flapjack::Gateways::Email,
174
192
  :instance => worker}
175
193
  end
176
194
 
@@ -180,18 +198,20 @@ describe Flapjack::Coordinator do
180
198
  server = mock('server')
181
199
  server.should_receive(:start)
182
200
  Thin::Server.should_receive(:new).
183
- with(/^(?:\d{1,3}\.){3}\d{1,3}$/, an_instance_of(Fixnum), Flapjack::Web, :signals => false).
201
+ with(/^(?:\d{1,3}\.){3}\d{1,3}$/, an_instance_of(Fixnum), Flapjack::Gateways::Web, :signals => false).
184
202
  and_return(server)
185
203
 
186
204
  Flapjack::RedisPool.should_receive(:new)
187
205
 
188
- fc = Flapjack::Coordinator.new(config, redis_config)
189
- fc.send(:build_pikelet, 'web', {})
206
+ config.should_receive(:for_redis).and_return({})
207
+
208
+ fc = Flapjack::Coordinator.new(config)
209
+ fc.send(:build_pikelet, Flapjack::Gateways::Web, {'enabled' => 'yes'})
190
210
  pikelets = fc.instance_variable_get('@pikelets')
191
211
  pikelets.should_not be_nil
192
212
  pikelets.should be_an(Array)
193
213
  pikelets.should have(1).pikelet
194
- pikelets.first.should == {:class => Flapjack::Web, :instance => server}
214
+ pikelets.first.should == {:class => Flapjack::Gateways::Web, :instance => server}
195
215
  end
196
216
 
197
217
  # NB: exceptions are handled directly by the Thin pikelets