rabbitmq-cluster 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rabbitmq-cluster +0 -1
- data/bin/{rabbitmq-cluster-sidekick → rabbitmq-cluster-discovery} +0 -0
- data/bin/rabbitmq-cluster-prestart +4 -0
- data/lib/rabbitmq/cluster.rb +1 -2
- data/lib/rabbitmq/cluster/etcd.rb +1 -1
- data/lib/rabbitmq/cluster/server.rb +8 -34
- data/lib/rabbitmq/cluster/version.rb +2 -2
- data/spec/unit/server_spec.rb +75 -107
- metadata +7 -5
data/bin/rabbitmq-cluster
CHANGED
File without changes
|
data/lib/rabbitmq/cluster.rb
CHANGED
@@ -7,7 +7,7 @@ class RabbitMQManager
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
class RabbitMQ::Cluster
|
11
11
|
class Server
|
12
12
|
attr_accessor :client, :etcd
|
13
13
|
private :client, :etcd
|
@@ -24,18 +24,13 @@ module RabbitMQ::Cluster
|
|
24
24
|
self.etcd = etcd
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
|
29
|
-
setup_erlang_cookie
|
30
|
-
start_rabbitmq_server
|
31
|
-
save_erlang_cookie
|
32
|
-
join_cluster
|
33
|
-
end
|
27
|
+
def prestart
|
28
|
+
setup_erlang_cookie
|
34
29
|
end
|
35
30
|
|
36
31
|
def synchronize
|
37
|
-
remove_stopped_nodes if stopped_nodes.any?
|
38
32
|
join_cluster
|
33
|
+
remove_stopped_nodes if stopped_nodes.any?
|
39
34
|
end
|
40
35
|
|
41
36
|
def healthcheck
|
@@ -95,32 +90,11 @@ module RabbitMQ::Cluster
|
|
95
90
|
etcd.nodes - [name]
|
96
91
|
end
|
97
92
|
|
98
|
-
def start_rabbitmq_server
|
99
|
-
system("/usr/sbin/rabbitmq-server &")
|
100
|
-
waits = 1
|
101
|
-
until up?
|
102
|
-
sleep waits
|
103
|
-
waits *= 2
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def erlang_cookie
|
108
|
-
IO.read('/var/lib/rabbitmq/.erlang.cookie')
|
109
|
-
end
|
110
|
-
|
111
93
|
def setup_erlang_cookie
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
94
|
+
fail "erlang cookie must be preset in etcd" unless etcd.erlang_cookie
|
95
|
+
File.open('/var/lib/rabbitmq/.erlang.cookie', 'w') { |file| file.write etcd.erlang_cookie }
|
96
|
+
`chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie`
|
97
|
+
`chmod 400 /var/lib/rabbitmq/.erlang.cookie`
|
117
98
|
end
|
118
|
-
|
119
|
-
def save_erlang_cookie
|
120
|
-
unless etcd.erlang_cookie
|
121
|
-
etcd.erlang_cookie = erlang_cookie
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
99
|
end
|
126
100
|
end
|
data/spec/unit/server_spec.rb
CHANGED
@@ -64,41 +64,92 @@ describe RabbitMQ::Cluster::Server do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe 'starting the server' do
|
68
|
-
let(:client) { double(:client).as_null_object }
|
69
67
|
|
68
|
+
describe '#prestart' do
|
69
|
+
context 'with an erlang cookie in etcd' do
|
70
|
+
before do
|
71
|
+
allow(File).to receive(:open)
|
72
|
+
allow(subject).to receive(:"`")
|
73
|
+
allow(etcd).to receive(:erlang_cookie).and_return('NummmNugnnmNuyum')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets up the erlang cookie' do
|
77
|
+
expect(File).to receive(:open).with('/var/lib/rabbitmq/.erlang.cookie', 'w')
|
78
|
+
subject.prestart
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets up the ownership and permissions of the erlang cooke' do
|
82
|
+
expect(subject).to receive(:"`")
|
83
|
+
.with("chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie")
|
84
|
+
expect(subject).to receive(:"`")
|
85
|
+
.with("chmod 400 /var/lib/rabbitmq/.erlang.cookie")
|
86
|
+
subject.prestart
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when there was no erlang cookie in etcd' do
|
91
|
+
before do
|
92
|
+
allow(etcd).to receive(:erlang_cookie).and_return(false)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'fails hard and fast' do
|
96
|
+
expect { subject.prestart }.to raise_error('erlang cookie must be preset in etcd')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#synchronize' do
|
70
102
|
before do
|
103
|
+
allow(client).to receive(:nodes)
|
104
|
+
.and_return([
|
105
|
+
{"name" => "rabbit@node1", "running" => true},
|
106
|
+
{"name" => "rabbit@node2", "running" => false}
|
107
|
+
])
|
71
108
|
allow(subject).to receive(:system)
|
72
|
-
allow(client).to receive(:aliveness_test).and_return(
|
73
|
-
allow(
|
74
|
-
allow(IO).to receive(:read)
|
75
|
-
allow(subject).to receive(:"`")
|
109
|
+
allow(client).to receive(:aliveness_test).and_return("status" => "ok")
|
110
|
+
allow(client).to receive(:overview).and_return("node" => "rabbit@this_node")
|
76
111
|
end
|
77
112
|
|
78
|
-
|
79
|
-
|
80
|
-
|
113
|
+
context 'the node is not up' do
|
114
|
+
before do
|
115
|
+
allow(client).to receive(:aliveness_test).and_return("status" => "agghghghgh")
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'does not register the node' do
|
119
|
+
expect(etcd).to_not receive(:register).with('rabbit@this_node')
|
120
|
+
subject.synchronize
|
121
|
+
end
|
81
122
|
end
|
82
123
|
|
83
|
-
context '
|
84
|
-
it '
|
85
|
-
expect(subject).to receive(:
|
86
|
-
|
124
|
+
context 'the node is up' do
|
125
|
+
it 'removes the stopped node from the cluster' do
|
126
|
+
expect(subject).to receive(:system)
|
127
|
+
.with('rabbitmqctl forget_cluster_node rabbit@node2')
|
128
|
+
subject.synchronize
|
87
129
|
end
|
88
130
|
end
|
89
131
|
|
90
132
|
describe 'joining the cluster' do
|
133
|
+
let(:client) { double(:client).as_null_object }
|
134
|
+
|
135
|
+
before do
|
136
|
+
allow(subject).to receive(:system)
|
137
|
+
allow(subject).to receive(:"`")
|
138
|
+
allow(client).to receive(:aliveness_test).and_return({ "status" => "ok" })
|
139
|
+
end
|
140
|
+
|
141
|
+
|
91
142
|
context 'with no nodes in etcd' do
|
92
143
|
it 'does nothing' do
|
93
144
|
expect(subject).to_not receive(:"`")
|
94
|
-
subject.
|
145
|
+
subject.synchronize
|
95
146
|
end
|
96
147
|
end
|
97
148
|
|
98
149
|
context 'with some nodes allready in etcd' do
|
99
150
|
before do
|
100
151
|
allow(client).to receive(:nodes)
|
101
|
-
|
152
|
+
.and_return([{}])
|
102
153
|
etcd.register('rabbit@node1')
|
103
154
|
etcd.register('rabbit@node2')
|
104
155
|
end
|
@@ -106,122 +157,39 @@ describe RabbitMQ::Cluster::Server do
|
|
106
157
|
context 'allready in a cluster' do
|
107
158
|
before do
|
108
159
|
allow(client).to receive(:nodes)
|
109
|
-
|
160
|
+
.and_return([{},{}])
|
110
161
|
end
|
111
162
|
|
112
163
|
it 'does nothing' do
|
113
164
|
expect(subject).to_not receive(:"`")
|
114
|
-
subject.
|
165
|
+
expect(subject).to_not receive(:system)
|
166
|
+
subject.synchronize
|
115
167
|
end
|
116
168
|
end
|
117
169
|
|
118
170
|
it 'tries to join the cluster' do
|
119
171
|
expect(subject).to receive(:system).with("rabbitmqctl join_cluster rabbit@node1")
|
120
|
-
subject.
|
172
|
+
subject.synchronize
|
121
173
|
end
|
122
174
|
|
123
175
|
it 'stops the management app before clustering' do
|
124
176
|
expect(subject).to receive(:"`")
|
125
|
-
|
177
|
+
.with('rabbitmqctl stop_app')
|
126
178
|
expect(subject).to receive(:"`")
|
127
|
-
|
128
|
-
subject.
|
179
|
+
.with('rabbitmqctl start_app')
|
180
|
+
subject.synchronize
|
129
181
|
end
|
130
182
|
|
131
183
|
it 'does not try to cluster with itself' do
|
132
184
|
allow(client).to receive(:overview).and_return('node' => 'rabbit@node1')
|
133
185
|
expect(subject).to receive(:system).with("rabbitmqctl join_cluster rabbit@node2")
|
134
|
-
subject.
|
186
|
+
subject.synchronize
|
135
187
|
end
|
136
188
|
|
137
189
|
it 'registers itself' do
|
138
190
|
allow(client).to receive(:overview).and_return('node' => 'rabbit@this_node')
|
139
|
-
subject.start
|
140
|
-
expect(etcd.nodes).to include('rabbit@this_node')
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'with an erlang cookie in etcd' do
|
146
|
-
|
147
|
-
before do
|
148
|
-
allow(etcd).to receive(:erlang_cookie).and_return('NummmNugnnmNuyum')
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'sets up the erlang cookie' do
|
152
|
-
expect(File).to receive(:open).with('/var/lib/rabbitmq/.erlang.cookie', 'w')
|
153
|
-
subject.start
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'sets up the ownership and permissions of the erlang cooke' do
|
157
|
-
expect(subject).to receive(:"`")
|
158
|
-
.with("chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie")
|
159
|
-
expect(subject).to receive(:"`")
|
160
|
-
.with("chmod 400 /var/lib/rabbitmq/.erlang.cookie")
|
161
|
-
subject.start
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'when there was no erlang cookie in etcd' do
|
166
|
-
before do
|
167
|
-
allow(IO).to receive(:read)
|
168
|
-
.with('/var/lib/rabbitmq/.erlang.cookie')
|
169
|
-
.and_return('ErLAnGCOookie')
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'saves the on disk cookie to etcd' do
|
173
|
-
subject.start
|
174
|
-
expect(etcd.erlang_cookie).to eq 'ErLAnGCOookie'
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe '#synchronize' do
|
180
|
-
context 'etcd has more nodes than are running' do
|
181
|
-
before do
|
182
|
-
allow(client).to receive(:nodes)
|
183
|
-
.and_return([
|
184
|
-
{"name" => "rabbit@node1", "running" => true},
|
185
|
-
{"name" => "rabbit@node2", "running" => false}
|
186
|
-
])
|
187
|
-
allow(subject).to receive(:system)
|
188
|
-
allow(client).to receive(:aliveness_test).and_return("status" => "ok")
|
189
|
-
allow(client).to receive(:overview).and_return("node" => "rabbit@this_node")
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'the node is not up' do
|
193
|
-
before do
|
194
|
-
allow(client).to receive(:aliveness_test).and_return("status" => "agghghghgh")
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'does not register the node' do
|
198
|
-
expect(etcd).to_not receive(:register).with('rabbit@this_node')
|
199
|
-
subject.synchronize
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'removes the stopped node from the cluster' do
|
204
|
-
expect(subject).to receive(:system)
|
205
|
-
.with('rabbitmqctl forget_cluster_node rabbit@node2')
|
206
|
-
subject.synchronize
|
207
|
-
end
|
208
|
-
|
209
|
-
|
210
|
-
context 'etcd nodes matches running nodes in the cluster' do
|
211
|
-
before do
|
212
|
-
etcd.register('rabbit@node1')
|
213
|
-
etcd.register('rabbit@node2')
|
214
|
-
allow(client).to receive(:nodes)
|
215
|
-
.and_return([
|
216
|
-
{"name" => "rabbit@node1", "running" => true},
|
217
|
-
{"name" => "rabbit@node2", "running" => true},
|
218
|
-
{"name" => "rabbit@this_node", "running" => true}
|
219
|
-
])
|
220
|
-
end
|
221
|
-
|
222
|
-
it 'will not remove any nodes' do
|
223
|
-
expect(subject).to_not receive(:system)
|
224
191
|
subject.synchronize
|
192
|
+
expect(etcd.nodes).to include('rabbit@this_node')
|
225
193
|
end
|
226
194
|
end
|
227
195
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitmq-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -112,7 +112,8 @@ email:
|
|
112
112
|
- ed.robinson@reevoo.com
|
113
113
|
executables:
|
114
114
|
- rabbitmq-cluster
|
115
|
-
- rabbitmq-cluster-
|
115
|
+
- rabbitmq-cluster-discovery
|
116
|
+
- rabbitmq-cluster-prestart
|
116
117
|
extensions: []
|
117
118
|
extra_rdoc_files: []
|
118
119
|
files:
|
@@ -122,7 +123,8 @@ files:
|
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|
124
125
|
- bin/rabbitmq-cluster
|
125
|
-
- bin/rabbitmq-cluster-
|
126
|
+
- bin/rabbitmq-cluster-discovery
|
127
|
+
- bin/rabbitmq-cluster-prestart
|
126
128
|
- lib/rabbitmq/cluster.rb
|
127
129
|
- lib/rabbitmq/cluster/etcd.rb
|
128
130
|
- lib/rabbitmq/cluster/server.rb
|
@@ -146,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
148
|
version: '0'
|
147
149
|
segments:
|
148
150
|
- 0
|
149
|
-
hash: -
|
151
|
+
hash: -99154985774826741
|
150
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
153
|
none: false
|
152
154
|
requirements:
|
@@ -155,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
157
|
version: '0'
|
156
158
|
segments:
|
157
159
|
- 0
|
158
|
-
hash: -
|
160
|
+
hash: -99154985774826741
|
159
161
|
requirements: []
|
160
162
|
rubyforge_project:
|
161
163
|
rubygems_version: 1.8.25
|