marathon-api 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +11 -6
  4. data/bin/marathon +49 -41
  5. data/fixtures/vcr/Marathon/_info/returns_the_info_hash.yml +10 -2
  6. data/fixtures/vcr/Marathon/_ping/ping/.yml +7 -1
  7. data/fixtures/vcr/Marathon_App/_changes/changes_the_app.yml +21 -5
  8. data/fixtures/vcr/Marathon_App/_changes/fails_with_stange_attributes.yml +8 -2
  9. data/fixtures/vcr/Marathon_App/_delete/deletes_the_app.yml +11 -3
  10. data/fixtures/vcr/Marathon_App/_delete/fails_deleting_not_existing_app.yml +9 -1
  11. data/fixtures/vcr/Marathon_App/_get/fails_getting_not_existing_app.yml +9 -1
  12. data/fixtures/vcr/Marathon_App/_get/gets_the_app.yml +10 -2
  13. data/fixtures/vcr/Marathon_App/_list/lists_apps.yml +11 -4
  14. data/fixtures/vcr/Marathon_App/_restart/fails_restarting_not_existing_app.yml +9 -1
  15. data/fixtures/vcr/Marathon_App/_restart/restarts_an_app.yml +9 -3
  16. data/fixtures/vcr/Marathon_App/_start/fails_getting_not_existing_app.yml +9 -1
  17. data/fixtures/vcr/Marathon_App/_start/starts_the_app.yml +12 -4
  18. data/fixtures/vcr/Marathon_App/_version/gets_a_version.yml +19 -7
  19. data/fixtures/vcr/Marathon_App/_versions/gets_versions.yml +9 -3
  20. data/fixtures/vcr/Marathon_Deployment/_delete/cleans_app_from_marathon.yml +38 -0
  21. data/fixtures/vcr/Marathon_Deployment/_delete/deletes_deployments.yml +20 -8
  22. data/fixtures/vcr/Marathon_Deployment/_list/lists_deployments.yml +34 -14
  23. data/fixtures/vcr/Marathon_EventSubscriptions/_list/lists_callbacks.yml +10 -2
  24. data/fixtures/vcr/Marathon_EventSubscriptions/_register/registers_callback.yml +10 -2
  25. data/fixtures/vcr/Marathon_EventSubscriptions/_unregister/unregisters_callback.yml +10 -2
  26. data/fixtures/vcr/Marathon_Group/_changes/changes_the_group.yml +20 -8
  27. data/fixtures/vcr/Marathon_Group/_changes/previews_changes.yml +38 -0
  28. data/fixtures/vcr/Marathon_Group/_delete/deletes_the_group.yml +9 -3
  29. data/fixtures/vcr/Marathon_Group/_delete/fails_deleting_not_existing_app.yml +8 -2
  30. data/fixtures/vcr/Marathon_Group/_get/fails_getting_not_existing_app.yml +8 -2
  31. data/fixtures/vcr/Marathon_Group/_get/gets_the_group.yml +9 -3
  32. data/fixtures/vcr/Marathon_Group/_list/lists_apps.yml +12 -4
  33. data/fixtures/vcr/Marathon_Group/_start/fails_getting_not_existing_group.yml +8 -2
  34. data/fixtures/vcr/Marathon_Group/_start/starts_the_group.yml +9 -3
  35. data/fixtures/vcr/Marathon_Leader/_delete/delete/.yml +9 -1
  36. data/fixtures/vcr/Marathon_Leader/_get/get/.yml +10 -2
  37. data/fixtures/vcr/Marathon_Queue/_list/lists_queue.yml +9 -4
  38. data/fixtures/vcr/Marathon_Task/_delete/kills_a_tasks_of_an_app.yml +26 -10
  39. data/fixtures/vcr/Marathon_Task/_delete_all/kills_all_tasks_of_an_app.yml +10 -2
  40. data/fixtures/vcr/Marathon_Task/_get/gets_tasks_of_an_app.yml +10 -2
  41. data/fixtures/vcr/Marathon_Task/_list/lists_running_tasks.yml +10 -2
  42. data/fixtures/vcr/Marathon_Task/_list/lists_tasks.yml +10 -2
  43. data/lib/marathon/deployment.rb +5 -2
  44. data/lib/marathon/deployment_action.rb +23 -0
  45. data/lib/marathon/deployment_info.rb +17 -1
  46. data/lib/marathon/deployment_step.rb +21 -0
  47. data/lib/marathon/error.rb +1 -1
  48. data/lib/marathon/group.rb +13 -5
  49. data/lib/marathon/task.rb +7 -9
  50. data/lib/marathon/version.rb +1 -1
  51. data/lib/marathon.rb +2 -0
  52. data/spec/marathon/app_spec.rb +5 -7
  53. data/spec/marathon/deployment_action_spec.rb +25 -0
  54. data/spec/marathon/deployment_info_spec.rb +10 -1
  55. data/spec/marathon/deployment_spec.rb +7 -3
  56. data/spec/marathon/deployment_step_spec.rb +32 -0
  57. data/spec/marathon/event_subscriptions_spec.rb +2 -2
  58. data/spec/marathon/group_spec.rb +31 -19
  59. data/spec/marathon/leader_spec.rb +2 -4
  60. data/spec/marathon/queue_spec.rb +1 -2
  61. data/spec/marathon/task_spec.rb +4 -10
  62. metadata +10 -3
  63. data/fixtures/vcr/Marathon_App/_tasks/has_tasks.yml +0 -30
@@ -266,7 +266,6 @@ describe Marathon::App do
266
266
  apps = subject.list
267
267
  expect(apps.size).not_to eq(0)
268
268
  expect(apps.first).to be_instance_of(described_class)
269
- expect(apps.first.cpus).to eq(0.1)
270
269
  end
271
270
 
272
271
  end
@@ -276,15 +275,14 @@ describe Marathon::App do
276
275
 
277
276
  it 'starts the app', :vcr do
278
277
  app = subject.start({
279
- :id => '/test',
278
+ :id => '/test-app',
280
279
  :cmd => 'sleep 10',
281
280
  :instances => 1,
282
281
  :cpus => 0.1,
283
- :mem => 32,
284
- :version => 'foo-version'
282
+ :mem => 32
285
283
  })
286
284
  expect(app).to be_instance_of(described_class)
287
- expect(app.id).to eq('/test')
285
+ expect(app.id).to eq('/test-app')
288
286
  expect(app.instances).to eq(1)
289
287
  expect(app.cpus).to eq(0.1)
290
288
  expect(app.mem).to eq(32)
@@ -320,7 +318,7 @@ describe Marathon::App do
320
318
  subject { described_class }
321
319
 
322
320
  it 'deletes the app', :vcr do
323
- subject.delete('/ubuntu')
321
+ subject.delete('/test-app')
324
322
  end
325
323
 
326
324
  it 'fails deleting not existing app', :vcr do
@@ -348,7 +346,7 @@ describe Marathon::App do
348
346
  subject { described_class }
349
347
 
350
348
  it 'changes the app', :vcr do
351
- expect(subject.change('/ubuntu2', { 'instances' => 2 }))
349
+ expect(subject.change('/ubuntu2', { 'instances' => 2 }, true))
352
350
  .to be_instance_of(Marathon::DeploymentInfo)
353
351
  expect(subject.change('/ubuntu2', { 'instances' => 1 }, true))
354
352
  .to be_instance_of(Marathon::DeploymentInfo)
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ DEPLOYMENT_ACTION_EXAMPLE = { "app" => "app1", "type" => "StartApplication" }
4
+
5
+ describe Marathon::DeploymentAction do
6
+
7
+ describe '#attributes' do
8
+ subject { described_class.new(DEPLOYMENT_ACTION_EXAMPLE) }
9
+
10
+ its(:app) { should == 'app1' }
11
+ its(:type) { should == 'StartApplication' }
12
+ end
13
+
14
+ describe '#to_s' do
15
+ subject { described_class.new(DEPLOYMENT_ACTION_EXAMPLE) }
16
+
17
+ let(:expected_string) do
18
+ 'Marathon::DeploymentAction { :app => app1 :type => StartApplication }'
19
+ end
20
+
21
+ its(:to_s) { should == expected_string }
22
+ its(:to_pretty_s) { should == 'app1/StartApplication' }
23
+ end
24
+
25
+ end
@@ -14,6 +14,15 @@ describe Marathon::DeploymentInfo do
14
14
  its(:version) { should == 'version-456' }
15
15
  end
16
16
 
17
+ describe '#wait' do
18
+ subject { described_class.new(DEPLOYMENT_INFO_EXAMPLE) }
19
+
20
+ it 'waits for the deployment' do
21
+ expect(Marathon::Deployment).to receive(:list) { [] }
22
+ subject.wait
23
+ end
24
+ end
25
+
17
26
  describe '#to_s' do
18
27
  subject { described_class.new(DEPLOYMENT_INFO_EXAMPLE) }
19
28
 
@@ -40,4 +49,4 @@ describe Marathon::DeploymentInfo do
40
49
  its(:to_json) { should == DEPLOYMENT_INFO_EXAMPLE.to_json }
41
50
  end
42
51
 
43
- end
52
+ end
@@ -70,9 +70,9 @@ describe Marathon::Deployment do
70
70
 
71
71
  it 'lists deployments', :vcr do
72
72
  # start a deployment
73
- Marathon::App.change('/test', {:instances => 0})
73
+ Marathon::App.change('/test-app', {:instances => 0, :cmd => 'sleep 60'}, true)
74
74
  sleep 1
75
- Marathon::App.change('/test', {:instances => 2})
75
+ Marathon::App.change('/test-app', {:instances => 2}, true)
76
76
  sleep 1
77
77
 
78
78
  deployments = subject.list
@@ -86,9 +86,13 @@ describe Marathon::Deployment do
86
86
 
87
87
  it 'deletes deployments', :vcr do
88
88
  # start a deployment
89
- info = Marathon::App.change('/test', {:instances => 1})
89
+ info = Marathon::App.change('/test-app', {:instances => 1}, true)
90
90
  expect(subject.delete(info.deploymentId)).to be_instance_of(Marathon::DeploymentInfo)
91
91
  end
92
+
93
+ it 'cleans app from marathon', :vcr do
94
+ Marathon::App.delete('/test-app')
95
+ end
92
96
  end
93
97
 
94
98
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ DEPLOYMENT_STEP_EXAMPLE = {
4
+ "actions" => [
5
+ { "app" => "app1", "type" => "StartApplication" },
6
+ { "app" => "app2", "type" => "StartApplication" }
7
+ ]
8
+ }
9
+
10
+ describe Marathon::DeploymentStep do
11
+
12
+ describe '#attributes' do
13
+ subject { described_class.new(DEPLOYMENT_STEP_EXAMPLE) }
14
+
15
+ it 'has actions' do
16
+ expect(subject.actions).to be_instance_of(Array)
17
+ expect(subject.actions.size).to eq(2)
18
+ expect(subject.actions.first).to be_instance_of(Marathon::DeploymentAction)
19
+ end
20
+ end
21
+
22
+ describe '#to_s' do
23
+ subject { described_class.new(DEPLOYMENT_STEP_EXAMPLE) }
24
+
25
+ let(:expected_string) do
26
+ 'Marathon::DeploymentStep { :actions => app1/StartApplication,app2/StartApplication }'
27
+ end
28
+
29
+ its(:to_s) { should == expected_string }
30
+ end
31
+
32
+ end
@@ -19,7 +19,7 @@ describe Marathon::EventSubscriptions do
19
19
  it 'lists callbacks', :vcr do
20
20
  json = subject.list
21
21
  expect(json).to be_instance_of(Array)
22
- expect(json).to eq(['http://localhost/events/foo'])
22
+ expect(json).to include('http://localhost/events/foo')
23
23
  end
24
24
  end
25
25
 
@@ -34,4 +34,4 @@ describe Marathon::EventSubscriptions do
34
34
  end
35
35
  end
36
36
 
37
- end
37
+ end
@@ -23,17 +23,24 @@ EXAMPLE_GROUP = {
23
23
  "upgradeStrategy" => {
24
24
  "minimumHealthCapacity" => 1.0
25
25
  },
26
- "tasks" => [],
27
- "version" => 'foo-version'
26
+ "tasks" => []
28
27
  }
29
28
  ],
30
29
  "dependencies" => [],
31
- "groups" => [],
32
- "version" => 'foo-version'
30
+ "groups" => []
33
31
  }
34
32
 
35
33
  describe Marathon::Group do
36
34
 
35
+ describe '#init' do
36
+ subject { described_class }
37
+
38
+ it 'fails with group + apps' do
39
+ expect{subject.new(:apps => [{:id => 'app'}], :groups => [{:id => 'group'}], :id => '/foo')}
40
+ .to raise_error(Marathon::Error::ArgumentError, /Group can have either/)
41
+ end
42
+ end
43
+
37
44
  describe '#to_s' do
38
45
  subject { described_class.new(EXAMPLE_GROUP) }
39
46
 
@@ -48,8 +55,8 @@ describe Marathon::Group do
48
55
  " Command: sleep 30\n" + \
49
56
  " CPUs: 1.0\n" + \
50
57
  " Memory: 128.0 MB\n" + \
51
- " Version: foo-version\n" + \
52
- "Version: foo-version"
58
+ " Version:\n" + \
59
+ "Version:"
53
60
 
54
61
  end
55
62
 
@@ -85,12 +92,12 @@ describe Marathon::Group do
85
92
  subject { described_class.new({ 'id' => '/app/foo' }) }
86
93
 
87
94
  it 'changes the group' do
88
- expect(described_class).to receive(:change).with('/app/foo', {:instances => 9000 }, false)
95
+ expect(described_class).to receive(:change).with('/app/foo', {:instances => 9000 }, false, false)
89
96
  subject.change!('instances' => 9000)
90
97
  end
91
98
 
92
99
  it 'changes the group and strips :version' do
93
- expect(described_class).to receive(:change).with('/app/foo', {:instances => 9000 }, false)
100
+ expect(described_class).to receive(:change).with('/app/foo', {:instances => 9000 }, false, false)
94
101
  subject.change!('instances' => 9000, :version => 'old-version')
95
102
  end
96
103
  end
@@ -151,6 +158,22 @@ describe Marathon::Group do
151
158
  end
152
159
  end
153
160
 
161
+ describe '.changes' do
162
+ subject { described_class }
163
+
164
+ it 'previews changes', :vcr do
165
+ steps = subject.change('/test-group', { 'instances' => 20 }, false, true)
166
+ expect(steps).to be_instance_of(Array)
167
+ end
168
+
169
+ it 'changes the group', :vcr do
170
+ expect(subject.change('/test-group', { 'instances' => 2 }, true))
171
+ .to be_instance_of(Marathon::DeploymentInfo)
172
+ expect(subject.change('/test-group', { 'instances' => 1 }, true))
173
+ .to be_instance_of(Marathon::DeploymentInfo)
174
+ end
175
+ end
176
+
154
177
  describe '.delete' do
155
178
  subject { described_class }
156
179
 
@@ -165,15 +188,4 @@ describe Marathon::Group do
165
188
  end
166
189
  end
167
190
 
168
- describe '.changes' do
169
- subject { described_class }
170
-
171
- it 'changes the group', :vcr do
172
- expect(subject.change('/ubuntu2', { 'instances' => 2 }))
173
- .to be_instance_of(Marathon::DeploymentInfo)
174
- expect(subject.change('/ubuntu2', { 'instances' => 1 }, true))
175
- .to be_instance_of(Marathon::DeploymentInfo)
176
- end
177
- end
178
-
179
191
  end
@@ -5,9 +5,7 @@ describe Marathon::Leader do
5
5
  describe '.get', :vcr do
6
6
  subject { described_class }
7
7
 
8
- let(:expected_string) { 'mesos:8080' }
9
-
10
- its(:get) { should == expected_string }
8
+ its(:get) { is_expected.to be_instance_of(String) }
11
9
  end
12
10
 
13
11
  describe '.delete', :vcr do
@@ -18,4 +16,4 @@ describe Marathon::Leader do
18
16
  its(:delete) { should == expected_string }
19
17
  end
20
18
 
21
- end
19
+ end
@@ -55,8 +55,7 @@ describe Marathon::Queue do
55
55
  it 'lists queue', :vcr do
56
56
  queue = described_class.list
57
57
  expect(queue).to be_instance_of(Array)
58
- expect(queue.first).to be_instance_of(Marathon::Queue)
59
58
  end
60
59
  end
61
60
 
62
- end
61
+ end
@@ -49,13 +49,8 @@ describe Marathon::Task do
49
49
  }) }
50
50
 
51
51
  it 'deletes the task' do
52
- expect(described_class).to receive(:delete).with('/app/foo', 'task_123', false) do
53
- described_class.new({
54
- 'id' => 'task_123', 'appId' => '/app/foo', 'deleted' => true
55
- })
56
- end
52
+ expect(described_class).to receive(:delete).with('task_123', false)
57
53
  task.delete!
58
- expect(task.info[:deleted]).to be(true)
59
54
  end
60
55
  end
61
56
 
@@ -86,7 +81,7 @@ describe Marathon::Task do
86
81
 
87
82
  it 'gets tasks of an app', :vcr do
88
83
  tasks = subject.get('/ubuntu2')
89
- expect(tasks.size).to eq(1)
84
+ expect(tasks.size).not_to eq(0)
90
85
  expect(tasks.first).to be_instance_of(described_class)
91
86
  expect(tasks.first.appId).to eq('/ubuntu2')
92
87
  end
@@ -97,8 +92,7 @@ describe Marathon::Task do
97
92
 
98
93
  it 'kills a tasks of an app', :vcr do
99
94
  tasks = subject.get('/ubuntu2')
100
- task = subject.delete('/ubuntu2', tasks.first.id)
101
- task.id == tasks.first.id
95
+ subject.delete(tasks.first.id)
102
96
  end
103
97
  end
104
98
 
@@ -110,4 +104,4 @@ describe Marathon::Task do
110
104
  end
111
105
  end
112
106
 
113
- end
107
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marathon-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Bechstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -211,15 +211,16 @@ files:
211
211
  - fixtures/vcr/Marathon_App/_restart/restarts_an_app.yml
212
212
  - fixtures/vcr/Marathon_App/_start/fails_getting_not_existing_app.yml
213
213
  - fixtures/vcr/Marathon_App/_start/starts_the_app.yml
214
- - fixtures/vcr/Marathon_App/_tasks/has_tasks.yml
215
214
  - fixtures/vcr/Marathon_App/_version/gets_a_version.yml
216
215
  - fixtures/vcr/Marathon_App/_versions/gets_versions.yml
216
+ - fixtures/vcr/Marathon_Deployment/_delete/cleans_app_from_marathon.yml
217
217
  - fixtures/vcr/Marathon_Deployment/_delete/deletes_deployments.yml
218
218
  - fixtures/vcr/Marathon_Deployment/_list/lists_deployments.yml
219
219
  - fixtures/vcr/Marathon_EventSubscriptions/_list/lists_callbacks.yml
220
220
  - fixtures/vcr/Marathon_EventSubscriptions/_register/registers_callback.yml
221
221
  - fixtures/vcr/Marathon_EventSubscriptions/_unregister/unregisters_callback.yml
222
222
  - fixtures/vcr/Marathon_Group/_changes/changes_the_group.yml
223
+ - fixtures/vcr/Marathon_Group/_changes/previews_changes.yml
223
224
  - fixtures/vcr/Marathon_Group/_delete/deletes_the_group.yml
224
225
  - fixtures/vcr/Marathon_Group/_delete/fails_deleting_not_existing_app.yml
225
226
  - fixtures/vcr/Marathon_Group/_get/fails_getting_not_existing_app.yml
@@ -245,7 +246,9 @@ files:
245
246
  - lib/marathon/container_docker_port_mapping.rb
246
247
  - lib/marathon/container_volume.rb
247
248
  - lib/marathon/deployment.rb
249
+ - lib/marathon/deployment_action.rb
248
250
  - lib/marathon/deployment_info.rb
251
+ - lib/marathon/deployment_step.rb
249
252
  - lib/marathon/error.rb
250
253
  - lib/marathon/event_subscriptions.rb
251
254
  - lib/marathon/group.rb
@@ -264,8 +267,10 @@ files:
264
267
  - spec/marathon/container_docker_spec.rb
265
268
  - spec/marathon/container_spec.rb
266
269
  - spec/marathon/container_volume_spec.rb
270
+ - spec/marathon/deployment_action_spec.rb
267
271
  - spec/marathon/deployment_info_spec.rb
268
272
  - spec/marathon/deployment_spec.rb
273
+ - spec/marathon/deployment_step_spec.rb
269
274
  - spec/marathon/error_spec.rb
270
275
  - spec/marathon/event_subscriptions_spec.rb
271
276
  - spec/marathon/group_spec.rb
@@ -309,8 +314,10 @@ test_files:
309
314
  - spec/marathon/container_docker_spec.rb
310
315
  - spec/marathon/container_spec.rb
311
316
  - spec/marathon/container_volume_spec.rb
317
+ - spec/marathon/deployment_action_spec.rb
312
318
  - spec/marathon/deployment_info_spec.rb
313
319
  - spec/marathon/deployment_spec.rb
320
+ - spec/marathon/deployment_step_spec.rb
314
321
  - spec/marathon/error_spec.rb
315
322
  - spec/marathon/event_subscriptions_spec.rb
316
323
  - spec/marathon/group_spec.rb
@@ -1,30 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: http://localhost:8080/v2/apps//ubuntu2
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Content-Type:
11
- - application/json
12
- Accept:
13
- - application/json
14
- response:
15
- status:
16
- code: 200
17
- message: OK
18
- headers:
19
- Content-Type:
20
- - application/json
21
- Transfer-Encoding:
22
- - chunked
23
- Server:
24
- - Jetty(8.y.z-SNAPSHOT)
25
- body:
26
- encoding: UTF-8
27
- string: '{"app":{"id":"/ubuntu2","cmd":"while sleep 10; do date -u +%T; done","args":null,"user":null,"env":{},"instances":1,"cpus":0.1,"mem":64.0,"disk":0.0,"executor":"","constraints":[],"uris":[],"storeUrls":[],"ports":[10001],"requirePorts":false,"backoffSeconds":1,"backoffFactor":1.15,"maxLaunchDelaySeconds":3600,"container":{"type":"DOCKER","volumes":[],"docker":{"image":"libmesos/ubuntu","privileged":false,"parameters":[]}},"healthChecks":[],"dependencies":[],"upgradeStrategy":{"minimumHealthCapacity":1.0,"maximumOverCapacity":1.0},"labels":{},"version":"2015-03-03T18:08:28.455Z","tasksStaged":0,"tasksRunning":1,"deployments":[],"tasks":[{"id":"ubuntu2.37fbe1bc-c1d0-11e4-82d4-46b02d3b7f9e","host":"mesos","ports":[31290],"startedAt":"2015-03-03T18:07:57.097Z","stagedAt":"2015-03-03T18:07:56.457Z","version":"2015-03-03T18:07:47.581Z","appId":"/ubuntu2"}],"lastTaskFailure":null}}'
28
- http_version:
29
- recorded_at: Tue, 03 Mar 2015 18:08:29 GMT
30
- recorded_with: VCR 2.9.3