marathon-api 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bcd9ae14a3459ba8f19f3be38d2f1aa5bdb5746
4
- data.tar.gz: d3c3091fcdc97ecab48f942588bcba2b8cdeed43
3
+ metadata.gz: d3921a3fe5bd4c9ad4c204cdc19817507e74bfd4
4
+ data.tar.gz: fa9a7edb2421055296268c1675a6a1af4a164e2d
5
5
  SHA512:
6
- metadata.gz: c16b9ee84d8b507a4c62c8a29b63e2922be7b519986a513b63331241b3f77a27d7d200e2c29d557a4123bb9ad44f1e9c25e64fd2fb4acc16c1610fbcd6ea8a37
7
- data.tar.gz: 487c87de5f3a68325c8f421e4006f86f892166ce694d0c4d603cc024390e252ff2339eea2ceda78bed5893f0cb85fbbaa27c4f216c6cc8b48846abd0a331fefc
6
+ metadata.gz: 64b24ff2efea7b645643255e82da98d8fb28d73a69ac1f3a7034de3fcaca1960c9c354ee9faf877b145758637caaea975c5b7e3715cd06d67fbf0b4107fad8e0
7
+ data.tar.gz: b8f95656fe4c1dda9eddb51adea9ec0d7137dc437d9cc17aee50406a87c21e0bee0bd2e913c938080e0eb830a16917da3442288253154266b1c6d81503012258
data/.gitignore CHANGED
@@ -5,3 +5,4 @@
5
5
  Gemfile.lock
6
6
  vendor
7
7
  coverage/
8
+ .idea
data/lib/marathon.rb CHANGED
@@ -31,8 +31,56 @@ module Marathon
31
31
  require 'marathon/queue'
32
32
  require 'marathon/task'
33
33
 
34
+ # Represents an instance of Marathon
35
+ class MarathonInstance
36
+ attr_reader :connection
37
+
38
+ def initialize(url, options)
39
+ @connection = Connection.new(url,options)
40
+ end
41
+
42
+ def ping
43
+ connection.get('/ping')
44
+ end
45
+
46
+ # Get information about the marathon server
47
+ def info
48
+ connection.get('/v2/info')
49
+ end
50
+
51
+ def apps
52
+ Marathon::Apps.new(connection)
53
+ end
54
+
55
+ def deployments
56
+ Marathon::Deployments.new(connection)
57
+ end
58
+
59
+ def tasks
60
+ Marathon::Tasks.new(connection)
61
+ end
62
+
63
+ def queues
64
+ Marathon::Queues.new(connection)
65
+ end
66
+
67
+ def leaders
68
+ Marathon::Leader.new(connection)
69
+ end
70
+
71
+ def event_subscriptions
72
+ Marathon::EventSubscriptions.new(connection)
73
+ end
74
+
75
+ end
76
+
77
+
34
78
  DEFAULT_URL = 'http://localhost:8080'
35
79
 
80
+ attr_reader :singleton
81
+
82
+ @singleton = MarathonInstance::new(DEFAULT_URL,{})
83
+
36
84
  # Get the marathon url from environment
37
85
  def env_url
38
86
  ENV['MARATHON_URL']
@@ -60,36 +108,41 @@ module Marathon
60
108
  # Set a new url
61
109
  def url=(new_url)
62
110
  @url = new_url
63
- reset_connection!
111
+ reset_singleton!
64
112
  end
65
113
 
66
114
  # Set new options
67
115
  def options=(new_options)
68
116
  @options = env_options.merge(new_options || {})
69
- reset_connection!
117
+ reset_singleton!
70
118
  end
71
119
 
72
120
  # Set a new connection
73
121
  def connection
74
- @connection ||= Connection.new(url, options)
122
+ singleton.connection
123
+ end
124
+
125
+
126
+ def reset_singleton!
127
+ @singleton = MarathonInstance.new(url,options)
75
128
  end
76
129
 
77
- # Reset the connection
78
130
  def reset_connection!
79
- @connection = nil
131
+ reset_singleton!
80
132
  end
81
133
 
82
134
  # Get information about the marathon server
83
135
  def info
84
- connection.get('/v2/info')
136
+ singleton.info
85
137
  end
86
138
 
87
139
  # Ping marathon
88
140
  def ping
89
- connection.get('/ping')
141
+ singleton.ping
90
142
  end
91
143
 
92
144
  module_function :connection, :env_options, :env_url, :info, :logger, :logger=, :ping,
93
- :options, :options=, :url, :url= ,:reset_connection!
145
+ :options, :options=, :url, :url= ,:reset_connection!,:reset_singleton!,:singleton
146
+
94
147
 
95
148
  end
data/lib/marathon/app.rb CHANGED
@@ -168,8 +168,7 @@ Version: #{version}
168
168
  # List the application with id.
169
169
  # ++id++: Application's id.
170
170
  def get(id)
171
- json = Marathon.connection.get("/v2/apps/#{id}")['app']
172
- new(json)
171
+ Marathon.singleton.apps.get(id)
173
172
  end
174
173
 
175
174
  # List all applications.
@@ -179,17 +178,13 @@ Version: #{version}
179
178
  # "apps.tasks". Apps' tasks are not embedded in the response by default.
180
179
  # "apps.failures". Apps' last failures are not embedded in the response by default.
181
180
  def list(cmd = nil, embed = nil)
182
- query = {}
183
- query[:cmd] = cmd if cmd
184
- Marathon::Util.add_choice(query, :embed, embed, %w[apps.tasks apps.failures])
185
- json = Marathon.connection.get('/v2/apps', query)['apps']
186
- json.map { |j| new(j) }
181
+ Marathon.singleton.apps.list(cmd,embed)
187
182
  end
188
183
 
189
184
  # Delete the application with id.
190
185
  # ++id++: Application's id.
191
186
  def delete(id)
192
- Marathon.connection.delete("/v2/apps/#{id}")
187
+ Marathon.singleton.apps.delete(id)
193
188
  end
194
189
  alias :remove :delete
195
190
 
@@ -197,8 +192,7 @@ Version: #{version}
197
192
  # ++hash++: Hash including all attributes
198
193
  # see https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/apps for full details
199
194
  def start(hash)
200
- json = Marathon.connection.post('/v2/apps', nil, :body => hash)
201
- new(json)
195
+ Marathon.singleton.apps.start(hash)
202
196
  end
203
197
  alias :create :start
204
198
 
@@ -207,10 +201,7 @@ Version: #{version}
207
201
  # ++force++: If the app is affected by a running deployment, then the update operation will fail.
208
202
  # The current deployment can be overridden by setting the `force` query parameter.
209
203
  def restart(id, force = false)
210
- query = {}
211
- query[:force] = true if force
212
- json = Marathon.connection.post("/v2/apps/#{id}/restart", query)
213
- Marathon::DeploymentInfo.new(json)
204
+ Marathon.singleton.apps.restart(id,force)
214
205
  end
215
206
 
216
207
  # Change parameters of a running application. The new application parameters apply only to subsequently
@@ -220,25 +211,102 @@ Version: #{version}
220
211
  # ++force++: If the app is affected by a running deployment, then the update operation will fail.
221
212
  # The current deployment can be overridden by setting the `force` query parameter.
222
213
  def change(id, hash, force = false)
223
- query = {}
224
- query[:force] = true if force
225
- json = Marathon.connection.put("/v2/apps/#{id}", query, :body => hash.merge(:id => id))
226
- Marathon::DeploymentInfo.new(json)
214
+ Marathon.singleton.apps.change(id,hash,force)
227
215
  end
228
216
 
229
217
  # List the versions of the application with id.
230
218
  # ++id++: Application id
231
219
  def versions(id)
232
- json = Marathon.connection.get("/v2/apps/#{id}/versions")
233
- json['versions']
220
+ Marathon.singleton.apps.versions(id)
234
221
  end
235
222
 
236
223
  # List the configuration of the application with id at version.
237
224
  # ++id++: Application id
238
225
  # ++version++: Version name
239
226
  def version(id, version)
240
- json = Marathon.connection.get("/v2/apps/#{id}/versions/#{version}")
241
- new(json, true)
227
+ Marathon.singleton.apps.version(id,version)
242
228
  end
243
229
  end
244
230
  end
231
+
232
+ # This class represents a set of Apps
233
+ class Marathon::Apps
234
+ def initialize(connection)
235
+ @connection = connection
236
+ end
237
+
238
+ # List the application with id.
239
+ # ++id++: Application's id.
240
+ def get(id)
241
+ json = @connection.get("/v2/apps/#{id}")['app']
242
+ Marathon::App.new(json)
243
+ end
244
+
245
+ # Delete the application with id.
246
+ # ++id++: Application's id.
247
+ def delete(id)
248
+ @connection.delete("/v2/apps/#{id}")
249
+ end
250
+
251
+ # Create and start an application.
252
+ # ++hash++: Hash including all attributes
253
+ # see https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/apps for full details
254
+ def start(hash)
255
+ json = @connection.post('/v2/apps', nil, :body => hash)
256
+ Marathon::App.new(json)
257
+ end
258
+
259
+ # Restart the application with id.
260
+ # ++id++: Application's id.
261
+ # ++force++: If the app is affected by a running deployment, then the update operation will fail.
262
+ # The current deployment can be overridden by setting the `force` query parameter.
263
+ def restart(id, force = false)
264
+ query = {}
265
+ query[:force] = true if force
266
+ json = @connection.post("/v2/apps/#{id}/restart", query)
267
+ Marathon::DeploymentInfo.new(json)
268
+ end
269
+
270
+ # Change parameters of a running application. The new application parameters apply only to subsequently
271
+ # created tasks. Currently running tasks are restarted, while maintaining the minimumHealthCapacity.
272
+ # ++id++: Application's id.
273
+ # ++hash++: A subset of app's attributes.
274
+ # ++force++: If the app is affected by a running deployment, then the update operation will fail.
275
+ # The current deployment can be overridden by setting the `force` query parameter.
276
+ def change(id, hash, force = false)
277
+ query = {}
278
+ query[:force] = true if force
279
+ json = @connection.put("/v2/apps/#{id}", query, :body => hash.merge(:id => id))
280
+ Marathon::DeploymentInfo.new(json)
281
+ end
282
+
283
+ # List the versions of the application with id.
284
+ # ++id++: Application id
285
+ def versions(id)
286
+ json = @connection.get("/v2/apps/#{id}/versions")
287
+ json['versions']
288
+ end
289
+
290
+ # List the configuration of the application with id at version.
291
+ # ++id++: Application id
292
+ # ++version++: Version name
293
+ def version(id, version)
294
+ json = @connection.get("/v2/apps/#{id}/versions/#{version}")
295
+ Marathon::App.new(json, true)
296
+ end
297
+
298
+ # List all applications.
299
+ # ++:cmd++: Filter apps to only those whose commands contain cmd.
300
+ # ++:embed++: Embeds nested resources that match the supplied path.
301
+ # Possible values:
302
+ # "apps.tasks". Apps' tasks are not embedded in the response by default.
303
+ # "apps.failures". Apps' last failures are not embedded in the response by default.
304
+ def list(cmd = nil, embed = nil)
305
+ query = {}
306
+ query[:cmd] = cmd if cmd
307
+ Marathon::Util.add_choice(query, :embed, embed, %w[apps.tasks apps.failures])
308
+ json = @connection.get('/v2/apps', query)['apps']
309
+ json.map { |j| Marathon::App.new(j) }
310
+ end
311
+
312
+ end
@@ -32,8 +32,7 @@ class Marathon::Deployment < Marathon::Base
32
32
 
33
33
  # List running deployments.
34
34
  def list
35
- json = Marathon.connection.get('/v2/deployments')
36
- json.map { |j| new(j) }
35
+ Marathon.singleton.deployments.list
37
36
  end
38
37
 
39
38
  # Cancel the deployment with id.
@@ -42,12 +41,34 @@ class Marathon::Deployment < Marathon::Base
42
41
  # is created to restore the previous configuration. If set to true, then the deployment
43
42
  # is still canceled but no rollback deployment is created.
44
43
  def delete(id, force = false)
45
- query = {}
46
- query[:force] = true if force
47
- json = Marathon.connection.delete("/v2/deployments/#{id}")
48
- Marathon::DeploymentInfo.new(json)
44
+ Marathon.singleton.deployments.delete(id,force)
49
45
  end
50
46
  alias :cancel :delete
51
47
  alias :remove :delete
52
48
  end
53
49
  end
50
+
51
+ # This class represents a set of Deployments
52
+ class Marathon::Deployments
53
+ def initialize(connection)
54
+ @connection = connection
55
+ end
56
+ # List running deployments.
57
+ def list
58
+ json = @connection.get('/v2/deployments')
59
+ json.map { |j| Marathon::Deployment.new(j) }
60
+ end
61
+
62
+ # Cancel the deployment with id.
63
+ # ++id++: Deployment's id
64
+ # ++force++: If set to false (the default) then the deployment is canceled and a new deployment
65
+ # is created to restore the previous configuration. If set to true, then the deployment
66
+ # is still canceled but no rollback deployment is created.
67
+ def delete(id, force = false)
68
+ query = {}
69
+ query[:force] = true if force
70
+ json = @connection.delete("/v2/deployments/#{id}")
71
+ Marathon::DeploymentInfo.new(json)
72
+ end
73
+
74
+ end
@@ -2,32 +2,57 @@
2
2
  # See https://mesosphere.github.io/marathon/docs/rest-api.html#event-subscriptions for full list of API's methods.
3
3
  class Marathon::EventSubscriptions
4
4
 
5
+ def initialize(connection)
6
+ @connection = connection
7
+ end
8
+
9
+ # List all event subscriber callback URLs.
10
+ # Returns a list of strings/URLs.
11
+ def list
12
+ json = @connection.get('/v2/eventSubscriptions')
13
+ json['callbackUrls']
14
+ end
15
+
16
+ # Register a callback URL as an event subscriber.
17
+ # ++callbackUrl++: URL to which events should be posted.
18
+ # Returns an event as hash.
19
+ def register(callbackUrl)
20
+ query = {}
21
+ query[:callbackUrl] = callbackUrl
22
+ json = @connection.post('/v2/eventSubscriptions', query)
23
+ json
24
+ end
25
+
26
+ # Unregister a callback URL from the event subscribers list.
27
+ # ++callbackUrl++: URL passed when the event subscription was created.
28
+ # Returns an event as hash.
29
+ def unregister(callbackUrl)
30
+ query = {}
31
+ query[:callbackUrl] = callbackUrl
32
+ json = @connection.delete('/v2/eventSubscriptions', query)
33
+ json
34
+ end
35
+
36
+
5
37
  class << self
6
38
  # List all event subscriber callback URLs.
7
39
  # Returns a list of strings/URLs.
8
40
  def list
9
- json = Marathon.connection.get('/v2/eventSubscriptions')
10
- json['callbackUrls']
41
+ Marathon.singleton.event_subscriptions.list
11
42
  end
12
43
 
13
44
  # Register a callback URL as an event subscriber.
14
45
  # ++callbackUrl++: URL to which events should be posted.
15
46
  # Returns an event as hash.
16
47
  def register(callbackUrl)
17
- query = {}
18
- query[:callbackUrl] = callbackUrl
19
- json = Marathon.connection.post('/v2/eventSubscriptions', query)
20
- json
48
+ Marathon.singleton.event_subscriptions.register(callbackUrl)
21
49
  end
22
50
 
23
51
  # Unregister a callback URL from the event subscribers list.
24
52
  # ++callbackUrl++: URL passed when the event subscription was created.
25
53
  # Returns an event as hash.
26
54
  def unregister(callbackUrl)
27
- query = {}
28
- query[:callbackUrl] = callbackUrl
29
- json = Marathon.connection.delete('/v2/eventSubscriptions', query)
30
- json
55
+ Marathon.singleton.event_subscriptions.unregister(callbackUrl)
31
56
  end
32
57
  end
33
58
  end
@@ -2,18 +2,33 @@
2
2
  # See https://mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/leader for full list of API's methods.
3
3
  class Marathon::Leader
4
4
 
5
+ def initialize(connection)
6
+ @connection = connection
7
+ end
8
+
9
+ # Returns the current leader. If no leader exists, raises NotFoundError.
10
+ def get
11
+ json = @connection.get('/v2/leader')
12
+ json['leader']
13
+ end
14
+
15
+ # Causes the current leader to abdicate, triggering a new election.
16
+ # If no leader exists, raises NotFoundError.
17
+ def delete
18
+ json = @connection.delete('/v2/leader')
19
+ json['message']
20
+ end
21
+
5
22
  class << self
6
23
  # Returns the current leader. If no leader exists, raises NotFoundError.
7
24
  def get
8
- json = Marathon.connection.get('/v2/leader')
9
- json['leader']
25
+ Marathon.singleton.leaders.get
10
26
  end
11
27
 
12
28
  # Causes the current leader to abdicate, triggering a new election.
13
29
  # If no leader exists, raises NotFoundError.
14
30
  def delete
15
- json = Marathon.connection.delete('/v2/leader')
16
- json['message']
31
+ Marathon.singleton.leaders.delete
17
32
  end
18
33
  end
19
- end
34
+ end
@@ -20,8 +20,22 @@ class Marathon::Queue < Marathon::Base
20
20
  # Show content of the task queue.
21
21
  # Returns Array of Queue objects.
22
22
  def list
23
- json = Marathon.connection.get('/v2/queue')['queue']
24
- json.map { |j| new(j) }
23
+ Marathon.singleton.queues.list
25
24
  end
26
25
  end
26
+ end
27
+
28
+ # This class represents the Queue with all its elements
29
+ class Marathon::Queues
30
+ def initialize(connection)
31
+ @connection = connection
32
+ end
33
+
34
+ # Show content of the task queue.
35
+ # Returns Array of Queue objects.
36
+ def list
37
+ json = @connection.get('/v2/queue')['queue']
38
+ json.map { |j| Marathon::Queue.new(j) }
39
+ end
40
+
27
41
  end
data/lib/marathon/task.rb CHANGED
@@ -41,17 +41,13 @@ Version: #{version}
41
41
  # ++status++: Return only those tasks whose status matches this parameter.
42
42
  # If not specified, all tasks are returned. Possible values: running, staging.
43
43
  def list(status = nil)
44
- query = {}
45
- Marathon::Util.add_choice(query, :status, status, %w[running staging])
46
- json = Marathon.connection.get('/v2/tasks', query)['tasks']
47
- json.map { |j| new(j) }
44
+ Marathon.singleton.tasks.list(status)
48
45
  end
49
46
 
50
47
  # List all running tasks for application appId.
51
48
  # ++appId++: Application's id
52
49
  def get(appId)
53
- json = Marathon.connection.get("/v2/apps/#{appId}/tasks")['tasks']
54
- json.map { |j| new(j) }
50
+ Marathon.singleton.tasks.get(appId)
55
51
  end
56
52
 
57
53
  # Kill the given list of tasks and scale apps if requested.
@@ -59,10 +55,7 @@ Version: #{version}
59
55
  # ++scale++: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
60
56
  # after killing the specified tasks.
61
57
  def delete(ids, scale = false)
62
- query = {}
63
- query[:scale] = true if scale
64
- ids = [ids] if ids.is_a?(String)
65
- Marathon.connection.post("/v2/tasks/delete", query, :body => {:ids => ids})
58
+ Marathon.singleton.tasks.delete(ids,scale)
66
59
  end
67
60
  alias :remove :delete
68
61
  alias :kill :delete
@@ -73,14 +66,58 @@ Version: #{version}
73
66
  # ++scale++: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
74
67
  # after killing the specified tasks.
75
68
  def delete_all(appId, host = nil, scale = false)
76
- query = {}
77
- query[:host] = host if host
78
- query[:scale] = true if scale
79
- json = Marathon.connection.delete("/v2/apps/#{appId}/tasks", query)['tasks']
80
- json.map { |j| new(j) }
69
+ Marathon.singleton.tasks.delete_all(appId,host,scale)
81
70
  end
82
71
  alias :remove_all :delete_all
83
72
  alias :kill_all :delete_all
84
73
  end
74
+ end
75
+
76
+ # This class represents a set of Tasks
77
+ class Marathon::Tasks
78
+ def initialize(connection)
79
+ @connection = connection
80
+ end
81
+
82
+ # List tasks of all applications.
83
+ # ++status++: Return only those tasks whose status matches this parameter.
84
+ # If not specified, all tasks are returned. Possible values: running, staging.
85
+ def list(status = nil)
86
+ query = {}
87
+ Marathon::Util.add_choice(query, :status, status, %w[running staging])
88
+ json = @connection.get('/v2/tasks', query)['tasks']
89
+ json.map { |j| Marathon::Task.new(j) }
90
+ end
91
+
92
+ # List all running tasks for application appId.
93
+ # ++appId++: Application's id
94
+ def get(appId)
95
+ json = @connection.get("/v2/apps/#{appId}/tasks")['tasks']
96
+ json.map { |j| Marathon::Task.new(j) }
97
+ end
98
+
99
+ # Kill the given list of tasks and scale apps if requested.
100
+ # ++ids++: Id or list of ids with target tasks.
101
+ # ++scale++: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
102
+ # after killing the specified tasks.
103
+ def delete(ids, scale = false)
104
+ query = {}
105
+ query[:scale] = true if scale
106
+ ids = [ids] if ids.is_a?(String)
107
+ @connection.post("/v2/tasks/delete", query, :body => {:ids => ids})
108
+ end
109
+
110
+ # Kill tasks that belong to the application appId.
111
+ # ++appId++: Application's id
112
+ # ++host++: Kill only those tasks running on host host.
113
+ # ++scale++: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
114
+ # after killing the specified tasks.
115
+ def delete_all(appId, host = nil, scale = false)
116
+ query = {}
117
+ query[:host] = host if host
118
+ query[:scale] = true if scale
119
+ json = @connection.delete("/v2/apps/#{appId}/tasks", query)['tasks']
120
+ json.map { |j| Marathon::Task.new(j) }
121
+ end
85
122
 
86
123
  end
@@ -1,3 +1,3 @@
1
1
  module Marathon
2
- VERSION = '1.2.5'
2
+ VERSION = '1.3.0'
3
3
  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.2.5
4
+ version: 1.3.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-06-15 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json