mamiya 0.0.1.alpha24 → 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -18
  3. data/example/config.agent.rb +3 -0
  4. data/example/config.rb +27 -0
  5. data/example/deploy.rb +19 -11
  6. data/lib/mamiya/agent.rb +38 -2
  7. data/lib/mamiya/agent/actions.rb +4 -0
  8. data/lib/mamiya/agent/tasks/clean.rb +35 -0
  9. data/lib/mamiya/agent/tasks/notifyable.rb +4 -1
  10. data/lib/mamiya/agent/tasks/prepare.rb +2 -0
  11. data/lib/mamiya/agent/tasks/switch.rb +123 -0
  12. data/lib/mamiya/cli.rb +1 -20
  13. data/lib/mamiya/cli/client.rb +225 -3
  14. data/lib/mamiya/configuration.rb +18 -0
  15. data/lib/mamiya/master/agent_monitor.rb +19 -4
  16. data/lib/mamiya/master/agent_monitor_handlers.rb +10 -0
  17. data/lib/mamiya/master/application_status.rb +72 -0
  18. data/lib/mamiya/master/package_status.rb +178 -0
  19. data/lib/mamiya/master/web.rb +48 -44
  20. data/lib/mamiya/steps/build.rb +1 -1
  21. data/lib/mamiya/steps/prepare.rb +1 -1
  22. data/lib/mamiya/steps/switch.rb +2 -1
  23. data/lib/mamiya/storages/filesystem.rb +1 -1
  24. data/lib/mamiya/storages/mock.rb +1 -1
  25. data/lib/mamiya/storages/s3.rb +1 -1
  26. data/lib/mamiya/storages/s3_proxy.rb +1 -1
  27. data/lib/mamiya/version.rb +1 -1
  28. data/spec/agent/actions_spec.rb +26 -1
  29. data/spec/agent/tasks/clean_spec.rb +88 -2
  30. data/spec/agent/tasks/notifyable_spec.rb +3 -3
  31. data/spec/agent/tasks/switch_spec.rb +176 -0
  32. data/spec/agent_spec.rb +142 -1
  33. data/spec/configuration_spec.rb +23 -0
  34. data/spec/master/agent_monitor_spec.rb +128 -38
  35. data/spec/master/application_status_spec.rb +171 -0
  36. data/spec/master/package_status_spec.rb +560 -0
  37. data/spec/master/web_spec.rb +116 -1
  38. data/spec/steps/build_spec.rb +1 -1
  39. data/spec/steps/prepare_spec.rb +6 -1
  40. data/spec/steps/switch_spec.rb +6 -2
  41. data/spec/storages/filesystem_spec.rb +2 -21
  42. data/spec/storages/s3_proxy_spec.rb +2 -22
  43. data/spec/storages/s3_spec.rb +2 -20
  44. metadata +11 -2
@@ -4,6 +4,8 @@ require 'fileutils'
4
4
 
5
5
  require 'mamiya/storages/mock'
6
6
  require 'mamiya/package'
7
+ require 'mamiya/master/package_status'
8
+ require 'mamiya/master/application_status'
7
9
 
8
10
  require 'mamiya/master/web'
9
11
 
@@ -31,8 +33,25 @@ describe Mamiya::Master::Web do
31
33
  {}
32
34
  end
33
35
 
36
+ let(:package_status) do
37
+ Mamiya::Master::PackageStatus.new(agent_monitor, 'myapp', 'mypackage')
38
+ end
39
+
40
+ let(:application_status) do
41
+ Mamiya::Master::ApplicationStatus.new(agent_monitor, 'myapp')
42
+ end
43
+
44
+
34
45
  let(:agent_monitor) do
35
- double('agent_monitor', statuses: agent_statuses)
46
+ double('agent_monitor', statuses: agent_statuses).tap do |a|
47
+ allow(a).to receive(:package_status).with('myapp','mypackage',labels: nil) do
48
+ package_status
49
+ end
50
+
51
+ allow(a).to receive(:application_status).with('myapp', labels: nil) do
52
+ application_status
53
+ end
54
+ end
36
55
  end
37
56
 
38
57
  let(:master) do
@@ -67,6 +86,36 @@ describe Mamiya::Master::Web do
67
86
  end
68
87
  end
69
88
 
89
+ describe "GET /applications/:application/status" do
90
+ subject(:status) do
91
+ res = get('/applications/myapp/status')
92
+ expect(res.status).to eq 200
93
+ JSON.parse res.body
94
+ end
95
+
96
+ context "when application exists" do
97
+ before do
98
+ allow(application_status).to receive(:to_hash).and_return(foo: :bar)
99
+ allow(application_status).to receive(:participants).and_return('foo' => {'currents' => {'myapp' => nil}})
100
+ end
101
+
102
+ it "returns status.to_hash JSON" do
103
+ expect(status).to eq('foo' => 'bar')
104
+ end
105
+ end
106
+
107
+ context "when application has no participants" do
108
+ before do
109
+ allow(application_status).to receive(:participants).and_return({})
110
+ end
111
+
112
+ it "returns 404" do
113
+ res = get('/applications/myapp/status')
114
+ expect(res.status).to eq 404
115
+ end
116
+ end
117
+ end
118
+
70
119
  describe "GET /packages/:application" do
71
120
  it "returns package list" do
72
121
  get '/packages/myapp'
@@ -168,8 +217,74 @@ describe Mamiya::Master::Web do
168
217
  end
169
218
  end
170
219
 
220
+ describe "POST /packages/:application/:package/switch" do
221
+ it "dispatchs switch request" do
222
+ expect(master).to receive(:switch).with('myapp', 'mypackage', labels: nil, no_release: false)
223
+
224
+ post '/packages/myapp/mypackage/switch'
225
+
226
+ expect(last_response.status).to eq 204 # no content
227
+ end
228
+
229
+ context "with no_release" do
230
+ it "dispatchs switch request" do
231
+ expect(master).to receive(:switch).with('myapp', 'mypackage', labels: nil, no_release: true)
232
+
233
+ post '/packages/myapp/mypackage/switch',
234
+ {'no_release' => true}.to_json,
235
+ 'CONTENT_TYPE' => 'application/json'
236
+
237
+ expect(last_response.status).to eq 204 # no content
238
+ end
239
+ end
240
+
241
+ context "with labels" do
242
+ it "dispatchs prepare request with labels" do
243
+ expect(master).to receive(:switch).with('myapp', 'mypackage', labels: ['foo'], no_release: false)
244
+
245
+ post '/packages/myapp/mypackage/switch',
246
+ {'labels' => ["foo"]}.to_json,
247
+ 'CONTENT_TYPE' => 'application/json'
248
+
249
+ expect(last_response.status).to eq 204 # no content
250
+ end
251
+ end
252
+
253
+ context "when package not found" do
254
+ it "returns 404" do
255
+ post '/packages/myapp/noexist/prepare'
256
+ expect(last_response.status).to eq 404
257
+ end
258
+ end
259
+ end
260
+
261
+ describe "GET /package/:application/:package/status" do
262
+ subject(:status) do
263
+ res = get('/packages/myapp/mypackage/status')
264
+ expect(res.status).to eq 200
265
+ JSON.parse res.body
266
+ end
267
+
268
+ context "when package exists" do
269
+ before do
270
+ allow(package_status).to receive(:to_hash).and_return(foo: :bar)
271
+ end
272
+
273
+ it "returns package_status.to_hash JSON" do
274
+ expect(status).to eq('foo' => 'bar')
275
+ end
276
+ end
277
+
278
+ context "when package not found" do
279
+ it "returns 404" do
280
+ get '/packages/myapp/noexist/status'
281
+ expect(last_response.status).to eq 404
282
+ end
283
+ end
284
+ end
171
285
 
172
286
  describe "GET /package/:application/:package/distribution" do
287
+ # TODO: Deprecated. Remove this
173
288
  subject(:distribution) do
174
289
  res = get('/packages/myapp/mypackage/distribution')
175
290
  expect(res.status).to eq 200
@@ -235,7 +235,7 @@ describe Mamiya::Steps::Build do
235
235
 
236
236
  # Default candidates
237
237
  expect(received.size).to eq 2
238
- expect(received[0]).to match(/\A\d{4}-\d{2}-\d{2}_\d{2}\.\d{2}\.\d{2}\z/)
238
+ expect(received[0]).to match(/\A\d{14}\z/)
239
239
  expect(received[1]).to eq script.application
240
240
  end
241
241
 
@@ -23,6 +23,7 @@ describe Mamiya::Steps::Prepare do
23
23
 
24
24
  let(:script) do
25
25
  double('script',
26
+ application: 'myapp',
26
27
  before_prepare: proc {},
27
28
  prepare: proc {},
28
29
  after_prepare: proc {},
@@ -30,7 +31,10 @@ describe Mamiya::Steps::Prepare do
30
31
  end
31
32
 
32
33
  let(:config) do
33
- double('config')
34
+ double('config').tap do |config|
35
+ allow(config).to receive(:deploy_to_for).with('myapp') \
36
+ .and_return(Pathname.new('/dev/null'))
37
+ end
34
38
  end
35
39
 
36
40
  let(:options) do
@@ -109,6 +113,7 @@ describe Mamiya::Steps::Prepare do
109
113
  end
110
114
 
111
115
  it "sets release_path" do
116
+ expect(script).to receive(:set).with(:deploy_to, Pathname.new('/dev/null'))
112
117
  expect(script).to receive(:set).with(:release_path, target_dir.realpath)
113
118
  expect(script).to receive(:set).with(:logger, step.logger)
114
119
  step.run!
@@ -25,7 +25,7 @@ describe Mamiya::Steps::Switch do
25
25
 
26
26
  let(:script) do
27
27
  double('script',
28
- deploy_to: deploy_to,
28
+ application: 'myapp',
29
29
  before_switch: proc {},
30
30
  release: proc {},
31
31
  after_switch: proc {},
@@ -34,7 +34,10 @@ describe Mamiya::Steps::Switch do
34
34
  end
35
35
 
36
36
  let(:config) do
37
- double('config')
37
+ double('config').tap do |config|
38
+ allow(config).to receive(:deploy_to_for).with('myapp') \
39
+ .and_return(deploy_to)
40
+ end
38
41
  end
39
42
 
40
43
  let(:options) do
@@ -94,6 +97,7 @@ describe Mamiya::Steps::Switch do
94
97
  end
95
98
 
96
99
  it "sets release_path" do
100
+ expect(script).to receive(:set).with(:deploy_to, deploy_to)
97
101
  expect(script).to receive(:set).with(:release_path, release_path.realpath)
98
102
  expect(script).to receive(:set).with(:logger, step.logger)
99
103
  step.run!
@@ -111,28 +111,9 @@ describe Mamiya::Storages::Filesystem do
111
111
  end
112
112
  end
113
113
 
114
- context "when meta already exists" do
114
+ context "when meta and tarball already exists" do
115
115
  before do
116
116
  File.write metafile, "\n"
117
- end
118
-
119
- it "raises error" do
120
- expect {
121
- fetch
122
- }.to raise_error(Mamiya::Storages::Abstract::AlreadyFetched)
123
- end
124
-
125
- it "doesn't remove anything" do
126
- begin
127
- fetch
128
- rescue Mamiya::Storages::Abstract::AlreadyFetched; end
129
-
130
- expect(File.exist?(metafile)).to be_true
131
- end
132
- end
133
-
134
- context "when tarball already exists" do
135
- before do
136
117
  File.write tarball, "\n"
137
118
  end
138
119
 
@@ -147,7 +128,7 @@ describe Mamiya::Storages::Filesystem do
147
128
  fetch
148
129
  rescue Mamiya::Storages::Abstract::AlreadyFetched; end
149
130
 
150
- expect(File.exist?(tarball)).to be_true
131
+ expect(File.exist?(metafile)).to be_true
151
132
  end
152
133
  end
153
134
 
@@ -95,29 +95,9 @@ describe Mamiya::Storages::S3Proxy do
95
95
  end
96
96
  end
97
97
 
98
- context "when meta already exists" do
98
+ context "when meta and tarball already exists" do
99
99
  before do
100
100
  File.write metafile, "\n"
101
- end
102
-
103
- it "raises error" do
104
- expect {
105
- fetch
106
- }.to raise_error(Mamiya::Storages::Abstract::AlreadyFetched)
107
- end
108
-
109
- it "doesn't remove anything" do
110
- begin
111
- fetch
112
- rescue Mamiya::Storages::Abstract::AlreadyFetched; end
113
-
114
- expect(File.exist?(metafile)).to be_true
115
- end
116
-
117
- end
118
-
119
- context "when tarball already exists" do
120
- before do
121
101
  File.write tarball, "\n"
122
102
  end
123
103
 
@@ -132,7 +112,7 @@ describe Mamiya::Storages::S3Proxy do
132
112
  fetch
133
113
  rescue Mamiya::Storages::Abstract::AlreadyFetched; end
134
114
 
135
- expect(File.exist?(tarball)).to be_true
115
+ expect(File.exist?(metafile)).to be_true
136
116
  end
137
117
  end
138
118
  end
@@ -154,9 +154,10 @@ describe Mamiya::Storages::S3 do
154
154
  end
155
155
  end
156
156
 
157
- context "when meta already exists" do
157
+ context "when meta and tarball already exists" do
158
158
  before do
159
159
  File.write metafile, "\n"
160
+ File.write tarball, "\n"
160
161
  end
161
162
 
162
163
  it "raises error" do
@@ -174,25 +175,6 @@ describe Mamiya::Storages::S3 do
174
175
  end
175
176
  end
176
177
 
177
- context "when tarball already exists" do
178
- before do
179
- File.write tarball, "\n"
180
- end
181
-
182
- it "raises error" do
183
- expect {
184
- fetch
185
- }.to raise_error(Mamiya::Storages::Abstract::AlreadyFetched)
186
- end
187
-
188
- it "doesn't remove anything" do
189
- begin
190
- fetch
191
- rescue Mamiya::Storages::Abstract::AlreadyFetched; end
192
-
193
- expect(File.exist?(tarball)).to be_true
194
- end
195
- end
196
178
 
197
179
  context "when name has .json" do
198
180
  let(:package_name) { 'test.json' }
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.alpha24
4
+ version: 0.0.1.beta1
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-09-11 00:00:00.000000000 Z
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -201,6 +201,7 @@ files:
201
201
  - lib/mamiya/agent/tasks/fetch.rb
202
202
  - lib/mamiya/agent/tasks/notifyable.rb
203
203
  - lib/mamiya/agent/tasks/prepare.rb
204
+ - lib/mamiya/agent/tasks/switch.rb
204
205
  - lib/mamiya/cli.rb
205
206
  - lib/mamiya/cli/client.rb
206
207
  - lib/mamiya/configuration.rb
@@ -210,6 +211,8 @@ files:
210
211
  - lib/mamiya/master.rb
211
212
  - lib/mamiya/master/agent_monitor.rb
212
213
  - lib/mamiya/master/agent_monitor_handlers.rb
214
+ - lib/mamiya/master/application_status.rb
215
+ - lib/mamiya/master/package_status.rb
213
216
  - lib/mamiya/master/web.rb
214
217
  - lib/mamiya/package.rb
215
218
  - lib/mamiya/script.rb
@@ -238,6 +241,7 @@ files:
238
241
  - spec/agent/tasks/fetch_spec.rb
239
242
  - spec/agent/tasks/notifyable_spec.rb
240
243
  - spec/agent/tasks/prepare_spec.rb
244
+ - spec/agent/tasks/switch_spec.rb
241
245
  - spec/agent_spec.rb
242
246
  - spec/configuration_spec.rb
243
247
  - spec/dsl_spec.rb
@@ -250,6 +254,8 @@ files:
250
254
  - spec/fixtures/test.yml
251
255
  - spec/logger_spec.rb
252
256
  - spec/master/agent_monitor_spec.rb
257
+ - spec/master/application_status_spec.rb
258
+ - spec/master/package_status_spec.rb
253
259
  - spec/master/web_spec.rb
254
260
  - spec/master_spec.rb
255
261
  - spec/package_spec.rb
@@ -301,6 +307,7 @@ test_files:
301
307
  - spec/agent/tasks/fetch_spec.rb
302
308
  - spec/agent/tasks/notifyable_spec.rb
303
309
  - spec/agent/tasks/prepare_spec.rb
310
+ - spec/agent/tasks/switch_spec.rb
304
311
  - spec/agent_spec.rb
305
312
  - spec/configuration_spec.rb
306
313
  - spec/dsl_spec.rb
@@ -313,6 +320,8 @@ test_files:
313
320
  - spec/fixtures/test.yml
314
321
  - spec/logger_spec.rb
315
322
  - spec/master/agent_monitor_spec.rb
323
+ - spec/master/application_status_spec.rb
324
+ - spec/master/package_status_spec.rb
316
325
  - spec/master/web_spec.rb
317
326
  - spec/master_spec.rb
318
327
  - spec/package_spec.rb