marathon-api 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/bin/marathon +1 -1
  4. data/lib/marathon.rb +4 -6
  5. data/lib/marathon/app.rb +27 -21
  6. data/lib/marathon/connection.rb +11 -11
  7. data/lib/marathon/constraint.rb +1 -1
  8. data/lib/marathon/container.rb +2 -2
  9. data/lib/marathon/container_docker.rb +2 -2
  10. data/lib/marathon/container_docker_port_mapping.rb +2 -2
  11. data/lib/marathon/container_volume.rb +1 -1
  12. data/lib/marathon/deployment.rb +4 -1
  13. data/lib/marathon/deployment_action.rb +1 -0
  14. data/lib/marathon/deployment_info.rb +3 -2
  15. data/lib/marathon/deployment_step.rb +1 -1
  16. data/lib/marathon/error.rb +24 -16
  17. data/lib/marathon/event_subscriptions.rb +1 -1
  18. data/lib/marathon/group.rb +2 -1
  19. data/lib/marathon/health_check.rb +7 -7
  20. data/lib/marathon/leader.rb +1 -1
  21. data/lib/marathon/queue.rb +2 -1
  22. data/lib/marathon/task.rb +7 -3
  23. data/lib/marathon/util.rb +7 -7
  24. data/lib/marathon/version.rb +1 -1
  25. data/spec/marathon/app_spec.rb +58 -54
  26. data/spec/marathon/base_spec.rb +10 -10
  27. data/spec/marathon/container_docker_port_mapping_spec.rb +7 -7
  28. data/spec/marathon/container_docker_spec.rb +13 -13
  29. data/spec/marathon/container_spec.rb +9 -9
  30. data/spec/marathon/container_volume_spec.rb +4 -4
  31. data/spec/marathon/deployment_action_spec.rb +1 -1
  32. data/spec/marathon/deployment_info_spec.rb +2 -2
  33. data/spec/marathon/deployment_spec.rb +19 -19
  34. data/spec/marathon/deployment_step_spec.rb +4 -4
  35. data/spec/marathon/error_spec.rb +7 -7
  36. data/spec/marathon/group_spec.rb +47 -47
  37. data/spec/marathon/marathon_spec.rb +1 -1
  38. data/spec/marathon/queue_spec.rb +9 -9
  39. data/spec/marathon/task_spec.rb +12 -12
  40. data/spec/marathon/util_spec.rb +17 -17
  41. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2655f3b4c932dcf453acb970aa41f6ae9ff774d
4
- data.tar.gz: 6689f06c21c986ba2bcb23aae214bf98a4cc582e
3
+ metadata.gz: 8b60887f834b4861afd26cac261c219767fbd208
4
+ data.tar.gz: b25e03b3dc591c0f3503cb60a3c8c4b528fe032e
5
5
  SHA512:
6
- metadata.gz: 7019da94e90e103908c78534428ca6dd93ad8319dacd04d49e332924dc1aa7fc146a93ab95d83f545e4e2a3392573ce1e3c082fae63feeeec427402a32175937
7
- data.tar.gz: 29f7d9d5f14c50853c4234fdfaa840e20809ed5efb912b1f6a1374acb1c03edbaa93ed17ab2f487b1a806917e53d64b28dc0e76273b66214b0d7ebe542fd78ce
6
+ metadata.gz: 66917b9f6d31568d01dcab7c31c083ef4a1d53d4423ddb1435c78cb86b76e2b5e069f630c2a9aa920c1ac1bc9e24746baa5894962e9fded20fd698dafae8ba72
7
+ data.tar.gz: 2d20bb4db6d22dd4c1ebf3cfee576b34616fd10547fa48bb69b43ed70b4965a9d6ed2a9b0e83890058752141051bd1af33028a29ccb5274d63c3944177084bfc
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.5
6
6
  - 2.2.0
7
+ - 2.3.0
7
8
  env:
8
9
  global:
9
10
  - CODECLIMATE_REPO_TOKEN=a0f25c19629dd353c43aef0cbbd886a7a4079c2238711fa4f932e1477b818195
@@ -110,7 +110,7 @@ end
110
110
  def subcmd_kill_tasks(cmd_opts)
111
111
  if cmd_opts[:task_id]
112
112
  puts "Killing task of '#{cmd_opts[:id]}' with id '#{cmd_opts[:task_id]}'"
113
- tasks = [Marathon::Task.delete(cmd_opts[:id], cmd_opts[:task_id], cmd_opts[:scale])]
113
+ tasks = [Marathon::Task.delete(cmd_opts[:task_id], cmd_opts[:scale])]
114
114
  elsif cmd_opts[:host]
115
115
  puts "Killing tasks of '#{cmd_opts[:id]}' on host '#{cmd_opts[:host]}'"
116
116
  tasks = Marathon::Task.delete_all(cmd_opts[:id], cmd_opts[:host], cmd_opts[:scale])
@@ -37,7 +37,7 @@ module Marathon
37
37
  attr_reader :connection
38
38
 
39
39
  def initialize(url, options)
40
- @connection = Connection.new(url,options)
40
+ @connection = Connection.new(url, options)
41
41
  end
42
42
 
43
43
  def ping
@@ -88,7 +88,7 @@ module Marathon
88
88
 
89
89
  attr_reader :singleton
90
90
 
91
- @singleton = MarathonInstance::new(DEFAULT_URL,{})
91
+ @singleton = MarathonInstance::new(DEFAULT_URL, {})
92
92
 
93
93
  # Get the marathon url from environment
94
94
  def env_url
@@ -134,7 +134,7 @@ module Marathon
134
134
 
135
135
 
136
136
  def reset_singleton!
137
- @singleton = MarathonInstance.new(url,options)
137
+ @singleton = MarathonInstance.new(url, options)
138
138
  end
139
139
 
140
140
  def reset_connection!
@@ -156,7 +156,5 @@ module Marathon
156
156
  end
157
157
 
158
158
  module_function :connection, :env_options, :env_url, :info, :logger, :logger=, :ping, :metrics,
159
- :options, :options=, :url, :url= ,:reset_connection!,:reset_singleton!,:singleton
160
-
161
-
159
+ :options, :options=, :url, :url=, :reset_connection!, :reset_singleton!, :singleton
162
160
  end
@@ -7,10 +7,10 @@ class Marathon::App < Marathon::Base
7
7
  deployments uris user version labels ]
8
8
 
9
9
  DEFAULTS = {
10
- :env => {},
11
- :labels => {},
12
- :ports => [],
13
- :uris => [],
10
+ :env => {},
11
+ :labels => {},
12
+ :ports => [],
13
+ :uris => [],
14
14
  }
15
15
 
16
16
  attr_reader :healthChecks, :constraints, :container, :read_only, :tasks
@@ -19,7 +19,8 @@ class Marathon::App < Marathon::Base
19
19
  # ++hash++: Hash including all attributes.
20
20
  # See https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/apps for full details.
21
21
  # ++read_only++: prevent actions on this application
22
- def initialize(hash, marathon_instance, read_only = false)
22
+ # ++marathon_instance++: MarathonInstance holding a connection to marathon
23
+ def initialize(hash, marathon_instance = Marathon.singleton, read_only = false)
23
24
  super(Marathon::Util.merge_keywordized_hash(DEFAULTS, hash), ACCESSORS)
24
25
  raise ArgumentError, 'App must have an id' unless id
25
26
  @read_only = read_only
@@ -121,17 +122,20 @@ class Marathon::App < Marathon::Base
121
122
  # Returns a string for listing the application.
122
123
  def to_pretty_s
123
124
  %Q[
124
- App ID: #{id}
125
- Instances: #{tasks.size}/#{instances}
126
- Command: #{cmd}
127
- CPUs: #{cpus}
128
- Memory: #{mem} MB
129
- #{pretty_container}
130
- #{pretty_uris}
131
- #{pretty_env}
132
- #{pretty_constraints}
133
- Version: #{version}
134
- ].gsub(/\n\n+/, "\n").strip
125
+ App ID: #{id}
126
+ Instances: #{tasks.size}/#{instances}
127
+ Command: #{cmd}
128
+ CPUs: #{cpus}
129
+ Memory: #{mem} MB
130
+ #{pretty_container}
131
+ #{pretty_uris}
132
+ #{pretty_env}
133
+ #{pretty_constraints}
134
+ Version: #{version}
135
+ ]
136
+ .gsub(/\n\s+/, "\n")
137
+ .gsub(/\n\n+/, "\n")
138
+ .strip
135
139
  end
136
140
 
137
141
  private
@@ -143,7 +147,7 @@ Version: #{version}
143
147
  end
144
148
 
145
149
  def pretty_env
146
- env.map { |k,v| "ENV: #{k}=#{v}" }.join("\n")
150
+ env.map { |k, v| "ENV: #{k}=#{v}" }.join("\n")
147
151
  end
148
152
 
149
153
  def pretty_uris
@@ -181,7 +185,7 @@ Version: #{version}
181
185
  # "apps.tasks". Apps' tasks are not embedded in the response by default.
182
186
  # "apps.failures". Apps' last failures are not embedded in the response by default.
183
187
  def list(cmd = nil, embed = nil, id=nil, label=nil)
184
- Marathon.singleton.apps.list(cmd,embed, id, label)
188
+ Marathon.singleton.apps.list(cmd, embed, id, label)
185
189
  end
186
190
 
187
191
  # Delete the application with id.
@@ -189,6 +193,7 @@ Version: #{version}
189
193
  def delete(id)
190
194
  Marathon.singleton.apps.delete(id)
191
195
  end
196
+
192
197
  alias :remove :delete
193
198
 
194
199
  # Create and start an application.
@@ -197,6 +202,7 @@ Version: #{version}
197
202
  def start(hash)
198
203
  Marathon.singleton.apps.start(hash)
199
204
  end
205
+
200
206
  alias :create :start
201
207
 
202
208
  # Restart the application with id.
@@ -204,7 +210,7 @@ Version: #{version}
204
210
  # ++force++: If the app is affected by a running deployment, then the update operation will fail.
205
211
  # The current deployment can be overridden by setting the `force` query parameter.
206
212
  def restart(id, force = false)
207
- Marathon.singleton.apps.restart(id,force)
213
+ Marathon.singleton.apps.restart(id, force)
208
214
  end
209
215
 
210
216
  # Change parameters of a running application. The new application parameters apply only to subsequently
@@ -214,7 +220,7 @@ Version: #{version}
214
220
  # ++force++: If the app is affected by a running deployment, then the update operation will fail.
215
221
  # The current deployment can be overridden by setting the `force` query parameter.
216
222
  def change(id, hash, force = false)
217
- Marathon.singleton.apps.change(id,hash,force)
223
+ Marathon.singleton.apps.change(id, hash, force)
218
224
  end
219
225
 
220
226
  # List the versions of the application with id.
@@ -227,7 +233,7 @@ Version: #{version}
227
233
  # ++id++: Application id
228
234
  # ++version++: Version name
229
235
  def version(id, version)
230
- Marathon.singleton.apps.version(id,version)
236
+ Marathon.singleton.apps.version(id, version)
231
237
  end
232
238
  end
233
239
  end
@@ -5,9 +5,9 @@ class Marathon::Connection
5
5
  include HTTParty
6
6
 
7
7
  headers(
8
- 'Content-Type' => 'application/json',
9
- 'Accept' => 'application/json',
10
- 'User-Agent' => "ub0r/Marathon-API #{Marathon::VERSION}"
8
+ 'Content-Type' => 'application/json',
9
+ 'Accept' => 'application/json',
10
+ 'User-Agent' => "ub0r/Marathon-API #{Marathon::VERSION}"
11
11
  )
12
12
 
13
13
  default_timeout 5
@@ -23,8 +23,8 @@ class Marathon::Connection
23
23
  @options = options
24
24
  if @options[:username] and @options[:password]
25
25
  @options[:basic_auth] = {
26
- :username => @options[:username],
27
- :password => @options[:password]
26
+ :username => @options[:username],
27
+ :password => @options[:password]
28
28
  }
29
29
  @options.delete(:username)
30
30
  @options.delete(:password)
@@ -47,14 +47,14 @@ class Marathon::Connection
47
47
  "Marathon::Connection { :url => #{url} :options => #{options} }"
48
48
  end
49
49
 
50
- private
50
+ private
51
51
 
52
52
  # Create URL suffix for a hash of query parameters.
53
53
  # URL escaping is done internally.
54
54
  # ++query++: Hash of query parameters.
55
55
  def query_params(query)
56
- query = query.select { |k,v| !v.nil? }
57
- URI.escape(query.map { |k,v| "#{k}=#{v}" }.join('&'))
56
+ query = query.select { |k, v| !v.nil? }
57
+ URI.escape(query.map { |k, v| "#{k}=#{v}" }.join('&'))
58
58
  end
59
59
 
60
60
  # Create request object.
@@ -68,9 +68,9 @@ private
68
68
  headers = opts.delete(:headers) || {}
69
69
  opts[:body] = opts[:body].to_json unless opts[:body].nil?
70
70
  {
71
- :method => http_method,
72
- :url => "#{@url}#{path}",
73
- :query => query
71
+ :method => http_method,
72
+ :url => "#{@url}#{path}",
73
+ :query => query
74
74
  }.merge(@options).merge(opts).reject { |_, v| v.nil? }
75
75
  end
76
76
 
@@ -7,7 +7,7 @@ class Marathon::Constraint < Marathon::Base
7
7
  def initialize(array)
8
8
  raise Marathon::Error::ArgumentError, 'array must be an Array' unless array.is_a?(Array)
9
9
  raise Marathon::Error::ArgumentError,
10
- 'array must be [attribute, operator, parameter] where only parameter is optional' \
10
+ 'array must be [attribute, operator, parameter] where only parameter is optional' \
11
11
  unless array.size != 2 or array.size != 3
12
12
  super
13
13
  end
@@ -6,8 +6,8 @@ class Marathon::Container < Marathon::Base
6
6
  SUPPERTED_TYPES = %w[ DOCKER MESOS]
7
7
  ACCESSORS = %w[ type ]
8
8
  DEFAULTS = {
9
- :type => 'DOCKER',
10
- :volumes => []
9
+ :type => 'DOCKER',
10
+ :volumes => []
11
11
  }
12
12
 
13
13
  attr_reader :docker, :volumes
@@ -4,8 +4,8 @@ class Marathon::ContainerDocker < Marathon::Base
4
4
 
5
5
  ACCESSORS = %w[ image network privileged parameters ]
6
6
  DEFAULTS = {
7
- :network => 'BRIDGE',
8
- :portMappings => []
7
+ :network => 'BRIDGE',
8
+ :portMappings => []
9
9
  }
10
10
 
11
11
  attr_reader :portMappings
@@ -4,8 +4,8 @@ class Marathon::ContainerDockerPortMapping < Marathon::Base
4
4
 
5
5
  ACCESSORS = %w[ containerPort hostPort servicePort protocol ]
6
6
  DEFAULTS = {
7
- :protocol => 'tcp',
8
- :hostPort => 0
7
+ :protocol => 'tcp',
8
+ :hostPort => 0
9
9
  }
10
10
 
11
11
  # Create a new container docker port mappint object.
@@ -4,7 +4,7 @@ class Marathon::ContainerVolume < Marathon::Base
4
4
 
5
5
  ACCESSORS = %w[ containerPath hostPath mode ]
6
6
  DEFAULTS = {
7
- :mode => 'RW'
7
+ :mode => 'RW'
8
8
  }
9
9
 
10
10
  # Create a new container volume object.
@@ -22,6 +22,7 @@ class Marathon::Deployment < Marathon::Base
22
22
  def delete(force = false)
23
23
  @marathon_instance.deployments.delete(id, force)
24
24
  end
25
+
25
26
  alias :cancel :delete
26
27
 
27
28
  def to_s
@@ -42,8 +43,9 @@ class Marathon::Deployment < Marathon::Base
42
43
  # is created to restore the previous configuration. If set to true, then the deployment
43
44
  # is still canceled but no rollback deployment is created.
44
45
  def delete(id, force = false)
45
- Marathon.singleton.deployments.delete(id,force)
46
+ Marathon.singleton.deployments.delete(id, force)
46
47
  end
48
+
47
49
  alias :cancel :delete
48
50
  alias :remove :delete
49
51
  end
@@ -55,6 +57,7 @@ class Marathon::Deployments
55
57
  @marathon_instance = marathon_instance
56
58
  @connection = @marathon_instance.connection
57
59
  end
60
+
58
61
  # List running deployments.
59
62
  def list
60
63
  json = @connection.get('/v2/deployments')
@@ -10,6 +10,7 @@ class Marathon::DeploymentAction < Marathon::Base
10
10
  def type
11
11
  info[:type] || info[:action]
12
12
  end
13
+
13
14
  alias :action :type
14
15
 
15
16
  def to_pretty_s
@@ -6,7 +6,8 @@ class Marathon::DeploymentInfo < Marathon::Base
6
6
 
7
7
  # Create a new deployment info object.
8
8
  # ++hash++: Hash returned by API, including 'deploymentId' and 'version'
9
- def initialize(hash, marathon_instance)
9
+ # ++marathon_instance++: MarathonInstance holding a connection to marathon
10
+ def initialize(hash, marathon_instance = Marathon.singleton)
10
11
  super(hash, %w[deploymentId version])
11
12
  raise Marathon::Error::ArgumentError, 'version must not be nil' unless version
12
13
  @marathon_instance = marathon_instance
@@ -17,7 +18,7 @@ class Marathon::DeploymentInfo < Marathon::Base
17
18
  def wait(timeout = 60)
18
19
  Timeout::timeout(timeout) do
19
20
  deployments = nil
20
- while deployments.nil? or deployments.select{|e| e.id == deploymentId}.size > 0 do
21
+ while deployments.nil? or deployments.any? { |e| e.id == deploymentId } do
21
22
  sleep(RECHECK_INTERVAL)
22
23
  deployments = @marathon_instance.deployments.list
23
24
  end
@@ -15,7 +15,7 @@ class Marathon::DeploymentStep < Marathon::Base
15
15
  end
16
16
 
17
17
  def to_s
18
- "Marathon::DeploymentStep { :actions => #{actions.map{|e| e.to_pretty_s}.join(',')} }"
18
+ "Marathon::DeploymentStep { :actions => #{actions.map { |e| e.to_pretty_s }.join(',')} }"
19
19
  end
20
20
 
21
21
  end
@@ -2,28 +2,36 @@
2
2
  module Marathon::Error
3
3
  # The default error. It's never actually raised, but can be used to catch all
4
4
  # gem-specific errors that are thrown as they all subclass from this.
5
- class MarathonError < StandardError; end
5
+ class MarathonError < StandardError;
6
+ end
6
7
 
7
8
  # Raised when invalid arguments are passed to a method.
8
- class ArgumentError < MarathonError; end
9
+ class ArgumentError < MarathonError;
10
+ end
9
11
 
10
12
  # Raised when a request returns a 400 or 422.
11
- class ClientError < MarathonError; end
13
+ class ClientError < MarathonError;
14
+ end
12
15
 
13
16
  # Raised when a request returns a 404.
14
- class NotFoundError < MarathonError; end
17
+ class NotFoundError < MarathonError;
18
+ end
15
19
 
16
20
  # Raised when there is an unexpected response code / body.
17
- class UnexpectedResponseError < MarathonError; end
21
+ class UnexpectedResponseError < MarathonError;
22
+ end
18
23
 
19
24
  # Raised when a request times out.
20
- class TimeoutError < MarathonError; end
25
+ class TimeoutError < MarathonError;
26
+ end
21
27
 
22
28
  # Raised when login fails.
23
- class AuthenticationError < MarathonError; end
29
+ class AuthenticationError < MarathonError;
30
+ end
24
31
 
25
32
  # Raised when an IO action fails.
26
- class IOError < MarathonError; end
33
+ class IOError < MarathonError;
34
+ end
27
35
 
28
36
  # Raise error specific to http response.
29
37
  # ++response++: HTTParty response object.
@@ -37,14 +45,14 @@ module Marathon::Error
37
45
  # ++response++: HTTParty response object.
38
46
  def error_class(response)
39
47
  case response.code
40
- when 400
41
- ClientError
42
- when 422
43
- ClientError
44
- when 404
45
- NotFoundError
46
- else
47
- UnexpectedResponseError
48
+ when 400
49
+ ClientError
50
+ when 422
51
+ ClientError
52
+ when 404
53
+ NotFoundError
54
+ else
55
+ UnexpectedResponseError
48
56
  end
49
57
  end
50
58
 
@@ -2,7 +2,7 @@
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(marathon_instance)
5
+ def initialize(marathon_instance = Marathon.singleton)
6
6
  @connection = marathon_instance.connection
7
7
  end
8
8
 
@@ -13,7 +13,8 @@ class Marathon::Group < Marathon::Base
13
13
  # Create a new group object.
14
14
  # ++hash++: Hash including all attributes.
15
15
  # See https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/groups for full details.
16
- def initialize(hash, marathon_instance)
16
+ # ++marathon_instance++: MarathonInstance holding a connection to marathon
17
+ def initialize(hash, marathon_instance = Marathon.singleton)
17
18
  super(Marathon::Util.merge_keywordized_hash(DEFAULTS, hash), ACCESSORS)
18
19
  @marathon_instance = marathon_instance
19
20
  raise ArgumentError, 'Group must have an id' unless id
@@ -3,13 +3,13 @@
3
3
  class Marathon::HealthCheck < Marathon::Base
4
4
 
5
5
  DEFAULTS = {
6
- :gracePeriodSeconds => 300,
7
- :intervalSeconds => 60,
8
- :maxConsecutiveFailures => 3,
9
- :path => '/',
10
- :portIndex => 0,
11
- :protocol => 'HTTP',
12
- :timeoutSeconds => 20
6
+ :gracePeriodSeconds => 300,
7
+ :intervalSeconds => 60,
8
+ :maxConsecutiveFailures => 3,
9
+ :path => '/',
10
+ :portIndex => 0,
11
+ :protocol => 'HTTP',
12
+ :timeoutSeconds => 20
13
13
  }
14
14
 
15
15
  ACCESSORS = %w[ command gracePeriodSeconds intervalSeconds maxConsecutiveFailures