marathon-api 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.cane +3 -0
  3. data/.gitignore +7 -0
  4. data/.simplecov +5 -0
  5. data/.travis.yml +10 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +22 -0
  8. data/README.md +91 -0
  9. data/Rakefile +34 -0
  10. data/TESTING.md +49 -0
  11. data/fixtures/marathon_docker_sample.json +14 -0
  12. data/fixtures/marathon_docker_sample_2.json +14 -0
  13. data/fixtures/vcr/Marathon/_info/returns_the_info_hash.yml +30 -0
  14. data/fixtures/vcr/Marathon/_ping/ping/.yml +35 -0
  15. data/fixtures/vcr/Marathon_App/_changes/changes_the_app.yml +57 -0
  16. data/fixtures/vcr/Marathon_App/_changes/fails_with_stange_attributes.yml +32 -0
  17. data/fixtures/vcr/Marathon_App/_delete/deletes_the_app.yml +30 -0
  18. data/fixtures/vcr/Marathon_App/_delete/fails_deleting_not_existing_app.yml +30 -0
  19. data/fixtures/vcr/Marathon_App/_get/fails_getting_not_existing_app.yml +30 -0
  20. data/fixtures/vcr/Marathon_App/_get/gets_the_app.yml +30 -0
  21. data/fixtures/vcr/Marathon_App/_list/lists_apps.yml +32 -0
  22. data/fixtures/vcr/Marathon_App/_restart/fails_restarting_not_existing_app.yml +30 -0
  23. data/fixtures/vcr/Marathon_App/_start/fails_getting_not_existing_app.yml +30 -0
  24. data/fixtures/vcr/Marathon_App/_start/starts_the_app.yml +32 -0
  25. data/fixtures/vcr/Marathon_App/_tasks/has_tasks.yml +30 -0
  26. data/fixtures/vcr/Marathon_App/_version/gets_a_version.yml +61 -0
  27. data/fixtures/vcr/Marathon_App/_versions/gets_versions.yml +32 -0
  28. data/fixtures/vcr/Marathon_Deployment/_delete/deletes_deployments.yml +61 -0
  29. data/fixtures/vcr/Marathon_Deployment/_list/lists_deployments.yml +90 -0
  30. data/fixtures/vcr/Marathon_EventSubscriptions/_list/lists_callbacks.yml +30 -0
  31. data/fixtures/vcr/Marathon_EventSubscriptions/_register/registers_callback.yml +30 -0
  32. data/fixtures/vcr/Marathon_EventSubscriptions/_unregister/unregisters_callback.yml +30 -0
  33. data/fixtures/vcr/Marathon_Leader/_delete/delete/.yml +30 -0
  34. data/fixtures/vcr/Marathon_Leader/_get/get/.yml +30 -0
  35. data/fixtures/vcr/Marathon_Queue/_list/lists_queue.yml +33 -0
  36. data/fixtures/vcr/Marathon_Task/_delete/kills_a_tasks_of_an_app.yml +57 -0
  37. data/fixtures/vcr/Marathon_Task/_delete_all/kills_all_tasks_of_an_app.yml +30 -0
  38. data/fixtures/vcr/Marathon_Task/_get/gets_tasks_of_an_app.yml +30 -0
  39. data/fixtures/vcr/Marathon_Task/_list/lists_running_tasks.yml +30 -0
  40. data/fixtures/vcr/Marathon_Task/_list/lists_tasks.yml +30 -0
  41. data/lib/marathon.rb +65 -0
  42. data/lib/marathon/app.rb +200 -0
  43. data/lib/marathon/connection.rb +97 -0
  44. data/lib/marathon/deployment.rb +60 -0
  45. data/lib/marathon/error.rb +62 -0
  46. data/lib/marathon/event_subscriptions.rb +33 -0
  47. data/lib/marathon/leader.rb +19 -0
  48. data/lib/marathon/queue.rb +36 -0
  49. data/lib/marathon/task.rb +85 -0
  50. data/lib/marathon/util.rb +35 -0
  51. data/lib/marathon/version.rb +3 -0
  52. data/marathon-api.gemspec +31 -0
  53. data/spec/marathon/app_spec.rb +334 -0
  54. data/spec/marathon/connection_spec.rb +40 -0
  55. data/spec/marathon/deployment_spec.rb +95 -0
  56. data/spec/marathon/error_spec.rb +40 -0
  57. data/spec/marathon/event_subscriptions_spec.rb +37 -0
  58. data/spec/marathon/leader_spec.rb +21 -0
  59. data/spec/marathon/marathon_spec.rb +47 -0
  60. data/spec/marathon/queue_spec.rb +62 -0
  61. data/spec/marathon/task_spec.rb +100 -0
  62. data/spec/marathon/util_spec.rb +44 -0
  63. data/spec/spec_helper.rb +34 -0
  64. metadata +271 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43d4d0f2016049fc44bde4ee4ffe6789de4631c0
4
+ data.tar.gz: 03579636a8d4577d7e8dc2ba1098eeb67b099ad2
5
+ SHA512:
6
+ metadata.gz: fe8feb603efd0ebe26e33ccd4cc3a406906a3dcef67e15e8f4b14393a239a8a01995de5e2d77fc89cc980d900319e1ee011b77caca1c7894bd03850be697a484
7
+ data.tar.gz: c0f7768067d89be77eb44e179636e40e9533722697555bc65fbe84c090d7307e0980016f0dcd52533bc965e4599af4cbcd9ade1b7ebb389933dc8358ddabe08b
data/.cane ADDED
@@ -0,0 +1,3 @@
1
+ --style-measure 120
2
+ --color
3
+ --parallel
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle
2
+ .DS_Store
3
+ *.swp
4
+ *.gem
5
+ Gemfile.lock
6
+ vendor
7
+ coverage/
data/.simplecov ADDED
@@ -0,0 +1,5 @@
1
+ SimpleCov.start do
2
+ add_group 'Library', 'lib'
3
+ add_group 'Specs', 'spec'
4
+ add_filter '/vendor/'
5
+ end
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - 2.2.0
7
+ env:
8
+ global:
9
+ - CODECLIMATE_REPO_TOKEN=8e7c316d892f832fa3de24bc2e88bf0d243e09947ea95319afcafcdb10f5eb3c
10
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Swipely, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ marathon-api
2
+ ============
3
+
4
+ [![travis-ci](https://travis-ci.org/felixb/marathon-api.png?branch=master)](https://travis-ci.org/felixb/marathon-api) [![Code Climate](https://codeclimate.com/github/felixb/marathon-api/badges/gpa.svg)](https://codeclimate.com/github/felixb/marathon-api) [![Test Coverage](https://codeclimate.com/github/felixb/marathon-api/badges/coverage.svg)](https://codeclimate.com/github/felixb/marathon-api)
5
+
6
+ This gem provides an object oriented interface to the [Marathon Remote API][1]. At the time if this writing, marathon-api is meant to interface with Marathon version 0.8.0.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Add this line to your application's Gemfile=>
12
+
13
+ ```ruby
14
+ gem 'docker-api', =>require => 'docker', =>git => 'https=>//github.com/felixb/marathon-api.git'
15
+ ```
16
+
17
+ And then run=>
18
+
19
+ ```shell
20
+ $ bundle install
21
+ ```
22
+
23
+ Finally, just add `require 'marathon'` to the top of the file using this gem.
24
+
25
+ Usage
26
+ -----
27
+
28
+ marathon-api is designed to be very lightweight. Only little state is cached to ensure that each method call's information is up to date. As such, just about every external method represents an API call.
29
+
30
+ If you're running Marathon locally on port 8080, there is no setup to do in Ruby. If you're not or change the path or port, you'll have to point the gem to your socket or local/remote port. For example=>
31
+
32
+ ```ruby
33
+ Marathon.url = 'http=>//example.com=>8080'
34
+ ```
35
+
36
+ It's possible to use `ENV` variables to configure the endpoint as well=>
37
+
38
+ ```shell
39
+ $ MARATHON_URL=http=>//remote.marathon.example.com=>8080 irb
40
+ irb(main)=>001=>0> require 'marathon'
41
+ => true
42
+ irb(main)=>002=>0> Marathon.url
43
+ => "http=>//remote.marathon.example.com=>8080"
44
+ ```
45
+
46
+ ## Global calls
47
+
48
+ ```ruby
49
+ require 'marathon'
50
+ # => true
51
+
52
+ Marathon.info
53
+ # => {"name"=>"marathon", "http_config"=>{"assets_path"=>null, "http_port"=>8080, "https_port"=>8443}, "frameworkId"=>"20150228-110436-16842879-5050-2169-0001", "leader"=>null, "event_subscriber"=>null, "marathon_config"=>{"local_port_max"=>20000, "local_port_min"=>10000, "hostname"=>"mesos", "master"=>"zk=>//localhost=>2181/mesos", "reconciliation_interval"=>300000, "mesos_role"=>null, "task_launch_timeout"=>300000, "reconciliation_initial_delay"=>15000, "ha"=>true, "failover_timeout"=>604800, "checkpoint"=>true, "executor"=>"//cmd", "marathon_store_timeout"=>2000, "mesos_user"=>"root"}, "version"=>"0.8.0", "zookeeper_config"=>{"zk_path"=>"/marathon", "zk"=>null, "zk_timeout"=>10, "zk_hosts"=>"localhost=>2181", "zk_future_timeout"=>{"duration"=>10}}, "elected"=>false}
54
+
55
+ Docker.ping
56
+ # => 'pong'
57
+
58
+ ```
59
+
60
+ ## Applications
61
+
62
+ You can list, change, delete apps like this:
63
+
64
+ ```ruby
65
+ require 'marathon'
66
+
67
+ # fetch a list of applications
68
+ apps = Marathon::App.list
69
+
70
+ # scale the first app to 2 instances
71
+ apps.first.scale!(2)
72
+
73
+ # delete the last app
74
+ apps.last.delete!
75
+ ```
76
+
77
+ The other Marathon endpoints are available in the same way.
78
+
79
+ Credits
80
+ -------
81
+
82
+ This gem is inspired by mesosphere's abondend [marathon_client][2] and swipelies [docker-api][3].
83
+
84
+ License
85
+ -------
86
+
87
+ This program is licensed under the MIT license. See LICENSE for details.
88
+
89
+ [1]: https://mesosphere.github.io/marathon/docs/rest-api.html
90
+ [2]: https://github.com/mesosphere/marathon_client
91
+ [3]: https://github.com/swipely/docker-api
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'rake'
4
+ require 'json'
5
+ require 'marathon'
6
+ require 'rspec/core/rake_task'
7
+ require 'vcr'
8
+ require 'cane/rake_task'
9
+
10
+ task :default => [:spec, :quality]
11
+
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = 'spec/**/*_spec.rb'
14
+ end
15
+
16
+ Cane::RakeTask.new(:quality) do |cane|
17
+ cane.canefile = '.cane'
18
+ end
19
+
20
+ dir = File.expand_path(File.dirname(__FILE__))
21
+ namespace :vcr do
22
+ desc 'Run spec tests and record VCR cassettes'
23
+ task :record do
24
+ FileUtils.remove_dir("#{dir}/fixtures/vcr", true)
25
+ json = JSON.parse(File.read("#{dir}/fixtures/marathon_docker_sample.json"))
26
+ Marathon::App.new(json).start!
27
+ json = JSON.parse(File.read("#{dir}/fixtures/marathon_docker_sample_2.json"))
28
+ Marathon::App.new(json).start!
29
+
30
+ # finally run spec tests
31
+ Rake::Task["spec"].invoke
32
+ end
33
+
34
+ end
data/TESTING.md ADDED
@@ -0,0 +1,49 @@
1
+ # Prerequisites
2
+ To develop on this gem, you must the following installed:
3
+ * a sane Ruby 1.9+ environment with `bundler`
4
+ ```shell
5
+ $ gem install bundler
6
+ ```
7
+ * Local Marathon v0.8.0 or greater running on Port 8080. Use [Vagrant][1] or [docker][2] to prevent local installation.
8
+
9
+
10
+
11
+ # Getting Started
12
+ 1. Clone the git repository from Github:
13
+ ```shell
14
+ $ git clone git@github.com:felixb/marathon-api.git
15
+ ```
16
+ 2. Install the dependencies using Bundler
17
+ ```shell
18
+ $ bundle install
19
+ ```
20
+ 3. Create a branch for your changes
21
+ ```shell
22
+ $ git checkout -b my_bug_fix
23
+ ```
24
+ 4. Make any changes
25
+ 5. Write tests to support those changes.
26
+ 6. Run the tests:
27
+ * `bundle exec rake vcr:test`
28
+ 7. Assuming the tests pass, open a Pull Request on Github.
29
+
30
+ # Using Rakefile Commands
31
+ This repository comes with five Rake commands to assist in your testing of the code.
32
+
33
+ ## `rake spec`
34
+ This command will run Rspec tests normally on your local system. Be careful that VCR will behave "weirdly" if you currently have the Docker daemon running.
35
+
36
+ ## `rake quality`
37
+ This command runs a code quality threshold checker to hinder bad code.
38
+
39
+ ## `rake vcr`
40
+ This gem uses [VCR](https://relishapp.com/vcr/vcr) to record and replay HTTP requests made to the Docker API. The `vcr` namespace is used to record and replay spec tests inside of a Docker container. This will allow each developer to run and rerecord VCR cassettes in a consistent environment.
41
+
42
+ ### `rake vcr:record`
43
+ This is the command you will use to record a new set of VCR cassettes. This command runs the following procedures:
44
+ 1. Delete the existing `fixtures/vcr` directory.
45
+ 2. Launch some tasks on local Marathon instance
46
+ 3. Record new VCR cassettes by running the Rspec test suite against the local Marathon instance.
47
+
48
+ [1]: https://github.com/everpeace/vagrant-mesos
49
+ [2]: https://registry.hub.docker.com/u/mesosphere/marathon/
@@ -0,0 +1,14 @@
1
+ {
2
+ "container": {
3
+ "type": "DOCKER",
4
+ "docker": {
5
+ "image": "libmesos/ubuntu"
6
+ }
7
+ },
8
+ "id": "/ubuntu",
9
+ "instances": 1,
10
+ "cpus": 0.1,
11
+ "mem": 64,
12
+ "uris": [],
13
+ "cmd": "while sleep 10; do date -u +%T; done"
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "container": {
3
+ "type": "DOCKER",
4
+ "docker": {
5
+ "image": "libmesos/ubuntu"
6
+ }
7
+ },
8
+ "id": "/ubuntu2",
9
+ "instances": 1,
10
+ "cpus": 0.1,
11
+ "mem": 64,
12
+ "uris": [],
13
+ "cmd": "while sleep 10; do date -u +%T; done"
14
+ }
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:8080/v2/info
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: '{"name":"marathon","http_config":{"assets_path":null,"http_port":8080,"https_port":8443},"frameworkId":"20150228-110436-16842879-5050-2169-0001","leader":null,"event_subscriber":null,"marathon_config":{"local_port_max":20000,"local_port_min":10000,"hostname":"mesos","master":"zk://localhost:2181/mesos","reconciliation_interval":300000,"mesos_role":null,"task_launch_timeout":300000,"reconciliation_initial_delay":15000,"ha":true,"failover_timeout":604800,"checkpoint":true,"executor":"//cmd","marathon_store_timeout":2000,"mesos_user":"root"},"version":"0.8.0","zookeeper_config":{"zk_path":"/marathon","zk":null,"zk_timeout":10,"zk_hosts":"localhost:2181","zk_future_timeout":{"duration":10}},"elected":false}'
28
+ http_version:
29
+ recorded_at: Mon, 02 Mar 2015 10:49:28 GMT
30
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,35 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:8080/ping
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
+ Cache-Control:
20
+ - must-revalidate,no-cache,no-store
21
+ Access-Control-Allow-Credentials:
22
+ - 'true'
23
+ Content-Type:
24
+ - text/plain;charset=ISO-8859-1
25
+ Content-Length:
26
+ - '5'
27
+ Server:
28
+ - Jetty(8.y.z-SNAPSHOT)
29
+ body:
30
+ encoding: UTF-8
31
+ string: |
32
+ pong
33
+ http_version:
34
+ recorded_at: Mon, 02 Mar 2015 10:49:28 GMT
35
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://localhost:8080/v2/apps//ubuntu2
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"instances":2}'
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: '{"version":"2015-03-03T18:08:29.872Z","deploymentId":"577a4136-d861-4f41-b400-1f73314c9ffd"}'
28
+ http_version:
29
+ recorded_at: Tue, 03 Mar 2015 18:08:29 GMT
30
+ - request:
31
+ method: put
32
+ uri: http://localhost:8080/v2/apps//ubuntu2?force=true
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"instances":1}'
36
+ headers:
37
+ Content-Type:
38
+ - application/json
39
+ Accept:
40
+ - application/json
41
+ response:
42
+ status:
43
+ code: 200
44
+ message: OK
45
+ headers:
46
+ Content-Type:
47
+ - application/json
48
+ Transfer-Encoding:
49
+ - chunked
50
+ Server:
51
+ - Jetty(8.y.z-SNAPSHOT)
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"version":"2015-03-03T18:08:30.012Z","deploymentId":"b1457aac-c4af-426f-bc2b-c2d67afed429"}'
55
+ http_version:
56
+ recorded_at: Tue, 03 Mar 2015 18:08:30 GMT
57
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://localhost:8080/v2/apps//ubuntu2
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"instances":"foo"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - ub0r/Marathon-API 0.8.0
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ Transfer-Encoding:
24
+ - chunked
25
+ Server:
26
+ - Jetty(8.y.z-SNAPSHOT)
27
+ body:
28
+ encoding: UTF-8
29
+ string: '{"message":"Invalid JSON: JsResultException(errors:List((/instances,List(ValidationError(error.expected.jsnumber,WrappedArray())))))"}'
30
+ http_version:
31
+ recorded_at: Wed, 04 Mar 2015 16:38:10 GMT
32
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: http://localhost:8080/v2/apps//ubuntu
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: '{"version":"2015-03-03T18:08:29.568Z","deploymentId":"475735d1-4c08-439d-8687-d13626e512a1"}'
28
+ http_version:
29
+ recorded_at: Tue, 03 Mar 2015 18:08:29 GMT
30
+ recorded_with: VCR 2.9.3