baton 0.4.5 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,4 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  log/*
19
- .DS_Store
19
+ .DS_Store
20
+ coverage
21
+ *.swp
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ gemspec
5
5
 
6
6
  group :darwin do
7
7
  gem "guard-rspec", "~> 0.5.8"
8
- gem 'rb-fsevent', "~> 0.4.3.1"
8
+ gem 'rb-fsevent', "~> 0.9.1"
9
9
  gem 'growl_notify', "~> 0.0.3"
10
10
  end
data/README.md CHANGED
@@ -28,12 +28,26 @@ Or, in your Gemfile:
28
28
 
29
29
  ## How to use
30
30
 
31
- Please check an existing extension, e.g. [baton-ping](https://github.com/digital-science/baton-ping), for more information about how to use and extend baton.
31
+ Please check an existing extension, e.g. [baton-ping](https://github.com/digital-science/baton-ping), for more information about how to use and extend baton.
32
32
  Since baton was created as a base for other extensions, it doesn't do anything in particular by itself but provide the structure and a basic setup on top of RabbitMQ and EventMachine.
33
33
 
34
+ ## Submitting a Pull Request
35
+
36
+ 1. [Fork the repository.](https://help.github.com/articles/fork-a-repo)
37
+ 2. [Create a topic branch.](http://learn.github.com/p/branching.html)
38
+ 3. Add specs for your unimplemented feature or bug fix.
39
+ 4. Run `bundle exec rake test`. If your specs pass, return to step 3.
40
+ 5. Implement your feature or bug fix.
41
+ 6. Run `bundle exec rake test`. If your specs fail, return to step 5.
42
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
43
+ by your tests, return to step 3.
44
+ 8. Add documentation for your feature or bug fix.
45
+ 9. Add, commit, and push your changes.
46
+ 10. [Submit a pull request.](https://help.github.com/articles/using-pull-requests)
47
+
34
48
  ## Details and Building Extensions
35
49
 
36
- Baton relies on [EventMachine](http://rubyeventmachine.com/) and [AMQP](http://rubyamqp.info/) for message passing. The gem defines a basic set of classes operating on top of RabbitMQ. The initial configuration will setup an input exchange and an output exchange.
50
+ Baton relies on [EventMachine](http://rubyeventmachine.com/) and [AMQP](http://rubyamqp.info/) for message passing. The gem defines a basic set of classes operating on top of RabbitMQ. The initial configuration will setup an input exchange and an output exchange.
37
51
 
38
52
  On the input exchange, baton will wait for meaningful messages to perform actions (described by each service) and it will output messages to the output exchange.
39
53
 
@@ -59,7 +73,7 @@ This class must be extended in order to process each received message. One shoul
59
73
 
60
74
  ### Channel
61
75
 
62
- Like the consumer manager, this class doesn't need to be extended. It provides functionality to setup the exchanges and add consumers.
76
+ Like the consumer manager, this class doesn't need to be extended. It provides functionality to setup the exchanges and add consumers.
63
77
 
64
78
  ### Observer
65
79
 
data/baton.gemspec CHANGED
@@ -15,10 +15,10 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Baton::VERSION
17
17
 
18
- gem.add_runtime_dependency "amqp", "~> 0.8.4"
19
- gem.add_runtime_dependency "eventmachine", "~> 1.0.0.beta.4"
20
- gem.add_runtime_dependency "em-http-request", "1.0.0"
21
- gem.add_runtime_dependency "bunny", "~> 0.7.8"
18
+ gem.add_runtime_dependency "amqp", "~> 0.9.7"
19
+ gem.add_runtime_dependency "eventmachine", "~> 1.0.0"
20
+ gem.add_runtime_dependency "em-http-request", "1.0.3"
21
+ gem.add_runtime_dependency "bunny", "~> 0.8.0"
22
22
  gem.add_runtime_dependency "ohai", "~> 0.6.12"
23
23
  gem.add_runtime_dependency "thor"
24
24
 
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency "moqueue", "~> 0.1.4"
27
27
  gem.add_development_dependency "fakefs", "~> 0.4.0"
28
28
  gem.add_development_dependency "rake", "~> 0.9.2"
29
- gem.add_development_dependency "webmock", "~> 1.7.7"
29
+ gem.add_development_dependency "webmock", "~> 1.8.7"
30
30
  gem.add_development_dependency "minitar", "0.5.3"
31
+ gem.add_development_dependency "simplecov", "0.6.4"
31
32
  end
data/lib/baton/channel.rb CHANGED
@@ -7,7 +7,7 @@ module Baton
7
7
 
8
8
  attr_accessor :channel, :exchange_in, :exchange_out, :connection, :connection_options, :amqp_hosts
9
9
 
10
- # Public: Initialize a Channel. It creates an AMQP connection, a channel,
10
+ # Public: Initialize a Channel. It creates an AMQP connection, a channel,
11
11
  # an input and an output exchange and finally attaches the handle_channel_exception
12
12
  # callback to the on_error event on the channel.
13
13
  def initialize
@@ -20,9 +20,19 @@ module Baton
20
20
  @connection = AMQP.connect(@connection_options)
21
21
  @channel = AMQP::Channel.new(@connection)
22
22
  @channel.auto_recovery = true
23
+
24
+ # Not everything needs an input exchange, default to the "" exchange if there isn't
25
+ # one defined in the config (monitors for example)
26
+ Baton.configuration.exchange = '' if Baton.configuration.exchange.nil?
27
+
28
+ # Create the exchanges
23
29
  @exchange_in = channel.direct(Baton.configuration.exchange)
24
30
  @exchange_out = channel.direct(Baton.configuration.exchange_out)
31
+
32
+ # Attach callbacks for error handling
25
33
  @connection.on_tcp_connection_loss(&method(:handle_tcp_failure))
34
+ @connection.on_tcp_connection_failure(&method(:handle_tcp_failure))
35
+ @connection.on_connection_interruption(&method(:handle_tcp_failure))
26
36
  @channel.on_error(&method(:handle_channel_exception))
27
37
  end
28
38
 
@@ -45,7 +55,7 @@ module Baton
45
55
  # Public: Callback to handle errors on an AMQP channel.
46
56
  #
47
57
  # channel - An AMQP channel
48
- # channel_close -
58
+ # channel_close -
49
59
  #
50
60
  # Returns nothing.
51
61
  #
@@ -58,7 +68,7 @@ module Baton
58
68
  # amqp_hosts - An array of hostnames for your AMQP servers
59
69
  #
60
70
  # Returns a string of an AMQP hostname.
61
- #
71
+ #
62
72
  def get_new_amqp_host(amqp_hosts)
63
73
  amqp_hosts[Kernel.rand(amqp_hosts.size)]
64
74
  end
@@ -4,7 +4,6 @@ require "baton/<%= config[:name] %>/<%= config[:name] %>-monitor"
4
4
 
5
5
  Baton.configure do |c|
6
6
  c.config_path = "<%= File.join(Dir.pwd, config[:name], 'config', config[:name]) %>.cfg"
7
- c.exchange = "<%= config[:name] %>_monitor_in"
8
7
  c.exchange_out = "<%= config[:name] %>_out"
9
8
  end
10
9
 
data/lib/baton/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Baton
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.8"
3
3
  end
@@ -7,24 +7,24 @@ describe Baton::Configuration do
7
7
  before(:each) do
8
8
  subject.config_path = "#{File.dirname(__FILE__)}/../fixtures/config.cfg"
9
9
  end
10
-
10
+
11
11
  it "will set the host" do
12
12
  subject.host.should eq("fromconfig.com")
13
13
  end
14
-
14
+
15
15
  it "will set the vhost" do
16
16
  subject.vhost.should eq("fromconfig")
17
17
  end
18
-
18
+
19
19
  it "will set the user" do
20
20
  subject.user.should eq("fromconfiguser")
21
21
  end
22
-
22
+
23
23
  it "will set the password" do
24
24
  subject.password.should eq("fromconfigpass")
25
25
  end
26
26
  end
27
-
27
+
28
28
  context "given a non existing file" do
29
29
  it "will log an erorr" do
30
30
  subject.logger.should_receive(:error).with("Could not find a baton configuration file at bad_path")
@@ -32,22 +32,22 @@ describe Baton::Configuration do
32
32
  end
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe "#connection_opts" do
37
37
  before(:each) do
38
38
  subject.config_path = "#{File.dirname(__FILE__)}/../fixtures/config.cfg"
39
39
  end
40
-
40
+
41
41
  context "give a config file" do
42
42
  it "will return a config hash" do
43
43
  subject.connection_opts.should eq({:host=>"fromconfig.com", :vhost=>"fromconfig", :user=>"fromconfiguser", :password=>"fromconfigpass", :pass=>"fromconfigpass"})
44
44
  end
45
45
  end
46
-
46
+
47
47
  context "given one of the configuration options is nil" do
48
48
  it "will not be returned in the config hash" do
49
49
  subject.vhost = nil
50
- subject.connection_opts.should eq({:host=>"fromconfig.com", :user=>"fromconfiguser", :password=>"fromconfigpass", :pass=>"fromconfigpass"})
50
+ subject.connection_opts.should eq({:host=>"fromconfig.com", :user=>"fromconfiguser", :password=>"fromconfigpass", :pass=>"fromconfigpass"})
51
51
  end
52
52
  end
53
53
  end
@@ -68,5 +68,23 @@ describe Baton::ConsumerManager do
68
68
  subject.handle_message(metadata, payload)
69
69
  end
70
70
  end
71
+
72
+ context "given an error message" do
73
+ it "should log the error and publish it to the exchange" do
74
+ message = {:type => "error", :message => "an error message"}
75
+ subject.logger.should_receive(:error).with(message)
76
+ subject.exchange_out.should_receive(:publish)
77
+ subject.update(message)
78
+ end
79
+ end
80
+
81
+ context "given an info message" do
82
+ it "should log the info and publish it to the exchange" do
83
+ message = {:type => "info", :message => "an info message"}
84
+ subject.logger.should_receive(:info).with(message)
85
+ subject.exchange_out.should_receive(:publish)
86
+ subject.update(message)
87
+ end
88
+ end
71
89
  end
72
90
  end
@@ -60,4 +60,12 @@ describe Baton::Consumer do
60
60
  end
61
61
  end
62
62
 
63
+ describe "#attributes" do
64
+ context "given an instance of a consumer" do
65
+ it "should have empty attributes" do
66
+ subject.attributes.should eq({})
67
+ end
68
+ end
69
+ end
70
+
63
71
  end
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+ require "baton/observer"
3
+
4
+ describe "Baton::Observer module" do
5
+
6
+ let(:my_observer) {
7
+ class MyObserver
8
+ include Baton::Observer
9
+
10
+ def attributes
11
+ {name: "my_observer_name"}
12
+ end
13
+ end
14
+ MyObserver.new
15
+ }
16
+
17
+ describe "#notify_error" do
18
+ context "given an error message" do
19
+ it "should notify the observers about it" do
20
+ my_observer.should_receive(:notify_observers).with(
21
+ {:name=>"my_observer_name", :type=>"error", :error_class=>Exception, :error_message=>"an error"})
22
+ my_observer.notify_error(Exception, "an error")
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "#notify_info" do
28
+ context "given an info message" do
29
+ it "should notify the observers about it" do
30
+ my_observer.should_receive(:notify_observers).with(
31
+ {:name=>"my_observer_name", :type=>"info", :message=>"a message"})
32
+ my_observer.notify_info("a message")
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#notify_success" do
38
+ context "given a success message" do
39
+ it "should notify the observers about it" do
40
+ my_observer.should_receive(:notify_observers).with(
41
+ {:name=>"my_observer_name", :type=>"success", :message=>"a success message"})
42
+ my_observer.notify_success("a success message")
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#notify_log" do
48
+ context "given a set or attributes" do
49
+ it "should notify the observers with those attributes" do
50
+ my_observer.should_receive(:notify_observers).with(
51
+ {:name=>"my_observer_name", :attr_1=>1, :attr_2=>2})
52
+ my_observer.notify_log({attr_1: 1, attr_2: 2})
53
+ end
54
+ end
55
+ end
56
+
57
+ end
@@ -46,4 +46,14 @@ describe Baton::Server do
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe "#attributes" do
51
+ context "given an instance of a server" do
52
+ it "should have the attributes set" do
53
+ subject.attributes.should eq({:environment=>"production",
54
+ :fqdn=>"build-prod-i-722b0004.dsci.it",
55
+ :app_names=>["octobutler"]})
56
+ end
57
+ end
58
+ end
49
59
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/spec"
4
+ end
1
5
  require 'rubygems'
2
6
  require 'bundler'
3
7
  Bundler.setup
4
8
  require 'fakefs/spec_helpers'
5
9
  require "moqueue"
10
+ require "rspec/expectations"
6
11
  require 'webmock/rspec'
7
12
  require "baton/logging"
8
13
  require 'json'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,55 +10,55 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-20 00:00:00.000000000 Z
13
+ date: 2012-09-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: amqp
17
- requirement: &70266370641740 !ruby/object:Gem::Requirement
17
+ requirement: &70113747826820 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 0.8.4
22
+ version: 0.9.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70266370641740
25
+ version_requirements: *70113747826820
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: eventmachine
28
- requirement: &70266370640380 !ruby/object:Gem::Requirement
28
+ requirement: &70113747826260 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0.beta.4
33
+ version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70266370640380
36
+ version_requirements: *70113747826260
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: em-http-request
39
- requirement: &70266370639480 !ruby/object:Gem::Requirement
39
+ requirement: &70113747825660 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - =
43
43
  - !ruby/object:Gem::Version
44
- version: 1.0.0
44
+ version: 1.0.3
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70266370639480
47
+ version_requirements: *70113747825660
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bunny
50
- requirement: &70266370638360 !ruby/object:Gem::Requirement
50
+ requirement: &70113747841380 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: 0.7.8
55
+ version: 0.8.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70266370638360
58
+ version_requirements: *70113747841380
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ohai
61
- requirement: &70266370637580 !ruby/object:Gem::Requirement
61
+ requirement: &70113747840660 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.6.12
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70266370637580
69
+ version_requirements: *70113747840660
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: thor
72
- requirement: &70266370635720 !ruby/object:Gem::Requirement
72
+ requirement: &70113747840100 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *70266370635720
80
+ version_requirements: *70113747840100
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rspec
83
- requirement: &70266370650760 !ruby/object:Gem::Requirement
83
+ requirement: &70113747839200 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '2.7'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70266370650760
91
+ version_requirements: *70113747839200
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: moqueue
94
- requirement: &70266370648860 !ruby/object:Gem::Requirement
94
+ requirement: &70113747838660 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 0.1.4
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70266370648860
102
+ version_requirements: *70113747838660
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: fakefs
105
- requirement: &70266370647660 !ruby/object:Gem::Requirement
105
+ requirement: &70113747838200 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 0.4.0
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70266370647660
113
+ version_requirements: *70113747838200
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rake
116
- requirement: &70266370645600 !ruby/object:Gem::Requirement
116
+ requirement: &70113747837720 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,21 +121,21 @@ dependencies:
121
121
  version: 0.9.2
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70266370645600
124
+ version_requirements: *70113747837720
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: webmock
127
- requirement: &70266370644560 !ruby/object:Gem::Requirement
127
+ requirement: &70113747837260 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
131
131
  - !ruby/object:Gem::Version
132
- version: 1.7.7
132
+ version: 1.8.7
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70266370644560
135
+ version_requirements: *70113747837260
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: minitar
138
- requirement: &70266370683360 !ruby/object:Gem::Requirement
138
+ requirement: &70113747836740 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - =
@@ -143,7 +143,18 @@ dependencies:
143
143
  version: 0.5.3
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70266370683360
146
+ version_requirements: *70113747836740
147
+ - !ruby/object:Gem::Dependency
148
+ name: simplecov
149
+ requirement: &70113747836280 !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - =
153
+ - !ruby/object:Gem::Version
154
+ version: 0.6.4
155
+ type: :development
156
+ prerelease: false
157
+ version_requirements: *70113747836280
147
158
  description: Baton
148
159
  email:
149
160
  - johnog@gmail.com
@@ -193,6 +204,7 @@ files:
193
204
  - spec/baton/configuration_spec.rb
194
205
  - spec/baton/consumer_manager_spec.rb
195
206
  - spec/baton/consumer_spec.rb
207
+ - spec/baton/observer_spec.rb
196
208
  - spec/baton/server_spec.rb
197
209
  - spec/fixtures/config-multi.cfg
198
210
  - spec/fixtures/config.cfg
@@ -215,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
227
  version: '0'
216
228
  segments:
217
229
  - 0
218
- hash: 2228522700796728917
230
+ hash: -4118038194259217623
219
231
  required_rubygems_version: !ruby/object:Gem::Requirement
220
232
  none: false
221
233
  requirements:
@@ -224,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
236
  version: '0'
225
237
  segments:
226
238
  - 0
227
- hash: 2228522700796728917
239
+ hash: -4118038194259217623
228
240
  requirements: []
229
241
  rubyforge_project:
230
242
  rubygems_version: 1.8.11
@@ -236,6 +248,7 @@ test_files:
236
248
  - spec/baton/configuration_spec.rb
237
249
  - spec/baton/consumer_manager_spec.rb
238
250
  - spec/baton/consumer_spec.rb
251
+ - spec/baton/observer_spec.rb
239
252
  - spec/baton/server_spec.rb
240
253
  - spec/fixtures/config-multi.cfg
241
254
  - spec/fixtures/config.cfg