mamiya 0.0.1.alpha19 → 0.0.1.alpha20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/mamiya/agent.rb +25 -30
- data/lib/mamiya/agent/actions.rb +9 -6
- data/lib/mamiya/agent/handlers/task.rb +13 -0
- data/lib/mamiya/agent/task_queue.rb +151 -0
- data/lib/mamiya/agent/tasks/abstract.rb +61 -0
- data/lib/mamiya/agent/tasks/clean.rb +44 -0
- data/lib/mamiya/agent/tasks/fetch.rb +60 -0
- data/lib/mamiya/agent/tasks/notifyable.rb +30 -0
- data/lib/mamiya/cli/client.rb +1 -1
- data/lib/mamiya/master.rb +4 -9
- data/lib/mamiya/master/agent_monitor_handlers.rb +42 -25
- data/lib/mamiya/master/web.rb +22 -7
- data/lib/mamiya/version.rb +1 -1
- data/mamiya.gemspec +1 -1
- data/spec/agent/actions_spec.rb +2 -8
- data/spec/agent/handlers/task_spec.rb +39 -0
- data/spec/agent/task_queue_spec.rb +246 -0
- data/spec/agent/tasks/abstract_spec.rb +58 -0
- data/spec/agent/tasks/clean_spec.rb +72 -0
- data/spec/agent/tasks/fetch_spec.rb +56 -0
- data/spec/agent/tasks/notifyable_spec.rb +37 -0
- data/spec/agent_spec.rb +33 -54
- data/spec/master/agent_monitor_spec.rb +155 -69
- data/spec/master/web_spec.rb +340 -1
- data/spec/master_spec.rb +0 -21
- metadata +22 -10
- data/lib/mamiya/agent/fetcher.rb +0 -165
- data/lib/mamiya/agent/handlers/fetch.rb +0 -78
- data/spec/agent/fetcher_spec.rb +0 -237
- data/spec/agent/handlers/fetch_spec.rb +0 -127
data/spec/master/web_spec.rb
CHANGED
@@ -27,8 +27,16 @@ describe Mamiya::Master::Web do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
let(:agent_statuses) do
|
31
|
+
{}
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:agent_monitor) do
|
35
|
+
double('agent_monitor', statuses: agent_statuses)
|
36
|
+
end
|
37
|
+
|
30
38
|
let(:master) do
|
31
|
-
double('master', config: config).tap do |m|
|
39
|
+
double('master', config: config, agent_monitor: agent_monitor).tap do |m|
|
32
40
|
allow(m).to receive(:storage) do |app|
|
33
41
|
Mamiya::Storages::Mock.new(application: app)
|
34
42
|
end
|
@@ -118,4 +126,335 @@ describe Mamiya::Master::Web do
|
|
118
126
|
end
|
119
127
|
end
|
120
128
|
end
|
129
|
+
|
130
|
+
describe "GET /package/:application/:package/distribution" do
|
131
|
+
subject(:distribution) do
|
132
|
+
res = get('/packages/myapp/mypackage/distribution')
|
133
|
+
expect(res.status).to eq 200
|
134
|
+
JSON.parse res.body
|
135
|
+
end
|
136
|
+
|
137
|
+
context "when package exists" do
|
138
|
+
describe "about status" do
|
139
|
+
subject { distribution['status'] }
|
140
|
+
|
141
|
+
context "if there's fetching agents" do
|
142
|
+
let(:agent_statuses) do
|
143
|
+
{
|
144
|
+
'agent1' => {
|
145
|
+
'packages' => {'myapp' => [
|
146
|
+
]},
|
147
|
+
'queues' => {'fetch' => {
|
148
|
+
'working' => {
|
149
|
+
'task' => 'fetch',
|
150
|
+
'app' => 'myapp',
|
151
|
+
'pkg' => 'mypackage'
|
152
|
+
},
|
153
|
+
'queue' => [
|
154
|
+
]
|
155
|
+
}}
|
156
|
+
},
|
157
|
+
'agent2' => {
|
158
|
+
'packages' => {'myapp' => [
|
159
|
+
'mypackage',
|
160
|
+
]},
|
161
|
+
'queues' => {'fetch' => {
|
162
|
+
'working' => nil,
|
163
|
+
'queue' => [
|
164
|
+
]
|
165
|
+
}}
|
166
|
+
}
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
it { should eq 'distributing' }
|
171
|
+
end
|
172
|
+
|
173
|
+
context "if there's queued agents" do
|
174
|
+
let(:agent_statuses) do
|
175
|
+
{
|
176
|
+
'agent1' => {
|
177
|
+
'packages' => {'myapp' => [
|
178
|
+
]},
|
179
|
+
'queues' => {'fetch' => {
|
180
|
+
'working' => nil,
|
181
|
+
'queue' => [
|
182
|
+
{
|
183
|
+
'task' => 'fetch',
|
184
|
+
'app' => 'myapp',
|
185
|
+
'pkg' => 'mypackage'
|
186
|
+
}
|
187
|
+
]
|
188
|
+
}}
|
189
|
+
},
|
190
|
+
'agent2' => {
|
191
|
+
'packages' => {'myapp' => [
|
192
|
+
'mypackage',
|
193
|
+
]},
|
194
|
+
'queues' => {'fetch' => {
|
195
|
+
'working' => nil,
|
196
|
+
'queue' => [
|
197
|
+
]
|
198
|
+
}}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
end
|
202
|
+
|
203
|
+
it { should eq 'distributing' }
|
204
|
+
end
|
205
|
+
|
206
|
+
context "if any agents have the package" do
|
207
|
+
let(:agent_statuses) do
|
208
|
+
{
|
209
|
+
'agent1' => {
|
210
|
+
'packages' => {'myapp' => [
|
211
|
+
'mypackage',
|
212
|
+
]},
|
213
|
+
'queues' => {'fetch' => {
|
214
|
+
'working' => nil,
|
215
|
+
'queue' => [
|
216
|
+
]
|
217
|
+
}},
|
218
|
+
},
|
219
|
+
'agent2' => {
|
220
|
+
'packages' => {'myapp' => [
|
221
|
+
]},
|
222
|
+
'queues' => {'fetch' => {
|
223
|
+
'working' => nil,
|
224
|
+
'queue' => [
|
225
|
+
]
|
226
|
+
}}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
end
|
230
|
+
|
231
|
+
it { should eq 'partially_distributed' }
|
232
|
+
end
|
233
|
+
|
234
|
+
context "if all agents have the package" do
|
235
|
+
let(:agent_statuses) do
|
236
|
+
{
|
237
|
+
'agent1' => {
|
238
|
+
'packages' => {'myapp' => [
|
239
|
+
'mypackage',
|
240
|
+
]},
|
241
|
+
'queues' => {'fetch' => {
|
242
|
+
'working' => nil,
|
243
|
+
'queue' => [
|
244
|
+
]
|
245
|
+
}},
|
246
|
+
},
|
247
|
+
'agent2' => {
|
248
|
+
'packages' => {'myapp' => [
|
249
|
+
'mypackage',
|
250
|
+
]},
|
251
|
+
'queues' => {'fetch' => {
|
252
|
+
'working' => nil,
|
253
|
+
'queue' => [
|
254
|
+
]
|
255
|
+
}}
|
256
|
+
}
|
257
|
+
}
|
258
|
+
end
|
259
|
+
|
260
|
+
it { should eq 'distributed' }
|
261
|
+
end
|
262
|
+
|
263
|
+
context "if no agents relate to the package" do
|
264
|
+
let(:agent_statuses) do
|
265
|
+
{
|
266
|
+
'agent1' => {
|
267
|
+
'packages' => {'myapp' => [
|
268
|
+
]},
|
269
|
+
'queues' => {'fetch' => {
|
270
|
+
'working' => nil,
|
271
|
+
'queue' => [
|
272
|
+
]
|
273
|
+
}},
|
274
|
+
},
|
275
|
+
'agent2' => {
|
276
|
+
'packages' => {'myapp' => [
|
277
|
+
]},
|
278
|
+
'queues' => {'fetch' => {
|
279
|
+
'working' => nil,
|
280
|
+
'queue' => [
|
281
|
+
]
|
282
|
+
}}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
end
|
286
|
+
|
287
|
+
it { should eq 'unknown' }
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "about fetching agents" do
|
292
|
+
let(:agent_statuses) do
|
293
|
+
{
|
294
|
+
'agent1' => {
|
295
|
+
'packages' => {'myapp' => [
|
296
|
+
]},
|
297
|
+
'queues' => {'fetch' => {
|
298
|
+
'working' => {
|
299
|
+
'task' => 'fetch',
|
300
|
+
'app' => 'myapp',
|
301
|
+
'pkg' => 'mypackage',
|
302
|
+
},
|
303
|
+
'queue' => [
|
304
|
+
]
|
305
|
+
}},
|
306
|
+
},
|
307
|
+
'agent2' => {
|
308
|
+
'packages' => {'myapp' => [
|
309
|
+
'mypackage'
|
310
|
+
]},
|
311
|
+
'queues' => {'fetch' => {
|
312
|
+
'working' => nil,
|
313
|
+
'queue' => [
|
314
|
+
]
|
315
|
+
}}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
end
|
319
|
+
|
320
|
+
it "show in fetching" do
|
321
|
+
expect(distribution['fetching']).to eq %w(agent1)
|
322
|
+
expect(distribution['fetching_count']).to eq 1
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "about distribued agents" do
|
327
|
+
let(:agent_statuses) do
|
328
|
+
{
|
329
|
+
'agent1' => {
|
330
|
+
'packages' => {'myapp' => [
|
331
|
+
]},
|
332
|
+
'queues' => {'fetch' => {
|
333
|
+
'working' => {
|
334
|
+
'task' => 'fetch',
|
335
|
+
'app' => 'myapp',
|
336
|
+
'pkg' => 'mypackage',
|
337
|
+
},
|
338
|
+
'queue' => [
|
339
|
+
]
|
340
|
+
}},
|
341
|
+
},
|
342
|
+
'agent2' => {
|
343
|
+
'packages' => {'myapp' => [
|
344
|
+
'mypackage'
|
345
|
+
]},
|
346
|
+
'queues' => {'fetch' => {
|
347
|
+
'working' => nil,
|
348
|
+
'queue' => [
|
349
|
+
]
|
350
|
+
}}
|
351
|
+
}
|
352
|
+
}
|
353
|
+
end
|
354
|
+
|
355
|
+
it "show in distributed" do
|
356
|
+
expect(distribution['distributed']).to eq %w(agent2)
|
357
|
+
expect(distribution['distributed_count']).to eq 1
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe "about queued agents" do
|
362
|
+
let(:agent_statuses) do
|
363
|
+
{
|
364
|
+
'agent1' => {
|
365
|
+
'packages' => {'myapp' => [
|
366
|
+
]},
|
367
|
+
'queues' => {'fetch' => {
|
368
|
+
'working' => {
|
369
|
+
'task' => 'fetch',
|
370
|
+
'app' => 'myapp',
|
371
|
+
'pkg' => 'anotherpackage',
|
372
|
+
},
|
373
|
+
'queue' => [
|
374
|
+
{
|
375
|
+
'task' => 'fetch',
|
376
|
+
'app' => 'myapp',
|
377
|
+
'pkg' => 'mypackage',
|
378
|
+
}
|
379
|
+
]
|
380
|
+
}},
|
381
|
+
},
|
382
|
+
'agent2' => {
|
383
|
+
'packages' => {'myapp' => [
|
384
|
+
'mypackage'
|
385
|
+
]},
|
386
|
+
'queues' => {'fetch' => {
|
387
|
+
'working' => nil,
|
388
|
+
'queue' => [
|
389
|
+
]
|
390
|
+
}}
|
391
|
+
}
|
392
|
+
}
|
393
|
+
end
|
394
|
+
|
395
|
+
it "show in queued" do
|
396
|
+
expect(distribution['queued']).to eq %w(agent1)
|
397
|
+
expect(distribution['queued_count']).to eq 1
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
describe "about unknown agents" do
|
402
|
+
let(:agent_statuses) do
|
403
|
+
{
|
404
|
+
'agent1' => {
|
405
|
+
'packages' => {'myapp' => [
|
406
|
+
]},
|
407
|
+
'queues' => {'fetch' => {
|
408
|
+
'working' => nil,
|
409
|
+
'queue' => [
|
410
|
+
]
|
411
|
+
}},
|
412
|
+
},
|
413
|
+
'agent2' => {
|
414
|
+
'packages' => {'myapp' => [
|
415
|
+
'mypackage'
|
416
|
+
]},
|
417
|
+
'queues' => {'fetch' => {
|
418
|
+
'working' => nil,
|
419
|
+
'queue' => [
|
420
|
+
]
|
421
|
+
}}
|
422
|
+
}
|
423
|
+
}
|
424
|
+
end
|
425
|
+
|
426
|
+
it "show in not_distributed" do
|
427
|
+
expect(distribution['not_distributed']).to eq %w(agent1)
|
428
|
+
expect(distribution['not_distributed_count']).to eq 1
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
context "with count_only" do
|
433
|
+
subject(:distribution) do
|
434
|
+
res = get('/packages/myapp/mypackage/distribution?count_only=1')
|
435
|
+
expect(res.status).to eq 200
|
436
|
+
JSON.parse res.body
|
437
|
+
end
|
438
|
+
|
439
|
+
it "returns only count columns" do
|
440
|
+
expect(distribution.keys).not_to include('distributed')
|
441
|
+
expect(distribution.keys).not_to include('fetching')
|
442
|
+
expect(distribution.keys).not_to include('queued')
|
443
|
+
expect(distribution.keys).not_to include('not_distributed')
|
444
|
+
|
445
|
+
expect(distribution.keys).to include('distributed_count')
|
446
|
+
expect(distribution.keys).to include('fetching_count')
|
447
|
+
expect(distribution.keys).to include('queued_count')
|
448
|
+
expect(distribution.keys).to include('not_distributed_count')
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
context "when package not found" do
|
454
|
+
it "returns 404" do
|
455
|
+
get '/packages/myapp/noexist/distribution'
|
456
|
+
expect(last_response.status).to eq 404
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
121
460
|
end
|
data/spec/master_spec.rb
CHANGED
@@ -35,27 +35,6 @@ describe Mamiya::Master do
|
|
35
35
|
expect(described_class.superclass).to eq Mamiya::Agent
|
36
36
|
end
|
37
37
|
|
38
|
-
describe "#distribute" do
|
39
|
-
# let!(:tmpdir) { Dir.mktmpdir('maimya-master-spec') }
|
40
|
-
# after { FileUtils.remove_entry_secure(tmpdir) }
|
41
|
-
|
42
|
-
# let(:package) do
|
43
|
-
# File.write File.join(tmpdir, 'mypackage.tar.gz'), "\n"
|
44
|
-
# File.write File.join(tmpdir, 'mypackage.json'), "#{{meta: 'data'}.to_json}\n"
|
45
|
-
# Mamiya::Package.new(File.join(tmpdir, 'mypackage'))
|
46
|
-
# end
|
47
|
-
|
48
|
-
# before do
|
49
|
-
# Mamiya::Storages::Mock.new(application: 'myapp').push(package)
|
50
|
-
# end
|
51
|
-
|
52
|
-
it "triggers fetch event" do
|
53
|
-
expect(master).to receive(:trigger).with(:fetch, coalesce: false, application: 'myapp', package: 'mypackage')
|
54
|
-
|
55
|
-
master.distribute('myapp', 'mypackage')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
38
|
it "starts agent monitor"
|
60
39
|
|
61
40
|
describe "(member join event)" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mamiya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.alpha20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Fukumori (sora_h)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.0.0.
|
33
|
+
version: 2.0.0.rc15
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.0.0.
|
40
|
+
version: 2.0.0.rc15
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: term-ansicolor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,9 +174,13 @@ files:
|
|
174
174
|
- lib/mamiya.rb
|
175
175
|
- lib/mamiya/agent.rb
|
176
176
|
- lib/mamiya/agent/actions.rb
|
177
|
-
- lib/mamiya/agent/fetcher.rb
|
178
177
|
- lib/mamiya/agent/handlers/abstract.rb
|
179
|
-
- lib/mamiya/agent/handlers/
|
178
|
+
- lib/mamiya/agent/handlers/task.rb
|
179
|
+
- lib/mamiya/agent/task_queue.rb
|
180
|
+
- lib/mamiya/agent/tasks/abstract.rb
|
181
|
+
- lib/mamiya/agent/tasks/clean.rb
|
182
|
+
- lib/mamiya/agent/tasks/fetch.rb
|
183
|
+
- lib/mamiya/agent/tasks/notifyable.rb
|
180
184
|
- lib/mamiya/cli.rb
|
181
185
|
- lib/mamiya/cli/client.rb
|
182
186
|
- lib/mamiya/config.rb
|
@@ -204,8 +208,12 @@ files:
|
|
204
208
|
- mamiya.gemspec
|
205
209
|
- misc/logger_test.rb
|
206
210
|
- spec/agent/actions_spec.rb
|
207
|
-
- spec/agent/
|
208
|
-
- spec/agent/
|
211
|
+
- spec/agent/handlers/task_spec.rb
|
212
|
+
- spec/agent/task_queue_spec.rb
|
213
|
+
- spec/agent/tasks/abstract_spec.rb
|
214
|
+
- spec/agent/tasks/clean_spec.rb
|
215
|
+
- spec/agent/tasks/fetch_spec.rb
|
216
|
+
- spec/agent/tasks/notifyable_spec.rb
|
209
217
|
- spec/agent_spec.rb
|
210
218
|
- spec/config_spec.rb
|
211
219
|
- spec/dsl_spec.rb
|
@@ -259,8 +267,12 @@ specification_version: 4
|
|
259
267
|
summary: Fast deploy tool using tarballs and serf
|
260
268
|
test_files:
|
261
269
|
- spec/agent/actions_spec.rb
|
262
|
-
- spec/agent/
|
263
|
-
- spec/agent/
|
270
|
+
- spec/agent/handlers/task_spec.rb
|
271
|
+
- spec/agent/task_queue_spec.rb
|
272
|
+
- spec/agent/tasks/abstract_spec.rb
|
273
|
+
- spec/agent/tasks/clean_spec.rb
|
274
|
+
- spec/agent/tasks/fetch_spec.rb
|
275
|
+
- spec/agent/tasks/notifyable_spec.rb
|
264
276
|
- spec/agent_spec.rb
|
265
277
|
- spec/config_spec.rb
|
266
278
|
- spec/dsl_spec.rb
|