Class: Marathon::App

Inherits:
Base
  • Object
show all
Defined in:
lib/marathon/app.rb

Overview

This class represents a Marathon App. See https://mesosphere.github.io/marathon/docs/rest-api.html#apps for full list of API's methods.

Constant Summary collapse

ACCESSORS =
%w[ id args cmd cpus disk env executor fetch instances mem ports requirePorts
storeUris tasksHealthy tasksUnhealthy tasksRunning tasksStaged upgradeStrategy
deployments uris user version labels ]
DEFAULTS =
{
    :env => {},
    :labels => {}
}

Instance Attribute Summary collapse

Attributes inherited from Base

#info

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_json

Methods included from Error

error_class, error_message, from_response

Constructor Details

#initialize(hash, marathon_instance = Marathon.singleton, read_only = false) ⇒ App

Create a new application object. ++hash++: Hash including all attributes. See https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/apps for full details. ++read_only++: prevent actions on this application ++marathon_instance++: MarathonInstance holding a connection to marathon

Raises:



21
22
23
24
25
26
27
# File 'lib/marathon/app.rb', line 21

def initialize(hash, marathon_instance = Marathon.singleton, read_only = false)
  super(Marathon::Util.merge_keywordized_hash(DEFAULTS, hash), ACCESSORS)
  raise ArgumentError, 'App must have an id' unless id
  @read_only = read_only
  @marathon_instance = marathon_instance
  refresh_attributes
end

Instance Attribute Details

#constraints ⇒ Object (readonly)

Returns the value of attribute constraints.



14
15
16
# File 'lib/marathon/app.rb', line 14

def constraints
  @constraints
end

#container ⇒ Object (readonly)

Returns the value of attribute container.



14
15
16
# File 'lib/marathon/app.rb', line 14

def container
  @container
end

#healthChecks ⇒ Object (readonly)

Returns the value of attribute healthChecks.



14
15
16
# File 'lib/marathon/app.rb', line 14

def healthChecks
  @healthChecks
end

#read_only ⇒ Object (readonly)

Returns the value of attribute read_only.



14
15
16
# File 'lib/marathon/app.rb', line 14

def read_only
  @read_only
end

#tasks ⇒ Object (readonly)

Returns the value of attribute tasks.



14
15
16
# File 'lib/marathon/app.rb', line 14

def tasks
  @tasks
end

Class Method Details

.change(id, hash, force = false) ⇒ Object

Change parameters of a running application. The new application parameters apply only to subsequently created tasks. Currently running tasks are restarted, while maintaining the minimumHealthCapacity. ++id++: Application's id. ++hash++: A subset of app's attributes. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



220
221
222
# File 'lib/marathon/app.rb', line 220

def change(id, hash, force = false)
  Marathon.singleton.apps.change(id, hash, force)
end

.delete(id) ⇒ Object Also known as: remove

Delete the application with id. ++id++: Application's id.



191
192
193
# File 'lib/marathon/app.rb', line 191

def delete(id)
  Marathon.singleton.apps.delete(id)
end

.get(id) ⇒ Object

List the application with id. ++id++: Application's id.



175
176
177
# File 'lib/marathon/app.rb', line 175

def get(id)
  Marathon.singleton.apps.get(id)
end

.list(cmd = nil, embed = nil, id = nil, label = nil) ⇒ Object

List all applications. ++:cmd++: Filter apps to only those whose commands contain cmd. ++:embed++: Embeds nested resources that match the supplied path. Possible values: "apps.tasks". Apps' tasks are not embedded in the response by default. "apps.failures". Apps' last failures are not embedded in the response by default.



185
186
187
# File 'lib/marathon/app.rb', line 185

def list(cmd = nil, embed = nil, id=nil, label=nil)
  Marathon.singleton.apps.list(cmd, embed, id, label)
end

.restart(id, force = false) ⇒ Object

Restart the application with id. ++id++: Application's id. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



210
211
212
# File 'lib/marathon/app.rb', line 210

def restart(id, force = false)
  Marathon.singleton.apps.restart(id, force)
end

.start(hash) ⇒ Object Also known as: create

Create and start an application. ++hash++: Hash including all attributes see https://mesosphere.github.io/marathon/docs/rest-api.html#post-/v2/apps for full details



200
201
202
# File 'lib/marathon/app.rb', line 200

def start(hash)
  Marathon.singleton.apps.start(hash)
end

.version(id, version) ⇒ Object

List the configuration of the application with id at version. ++id++: Application id ++version++: Version name



233
234
235
# File 'lib/marathon/app.rb', line 233

def version(id, version)
  Marathon.singleton.apps.version(id, version)
end

.versions(id) ⇒ Object

List the versions of the application with id. ++id++: Application id



226
227
228
# File 'lib/marathon/app.rb', line 226

def versions(id)
  Marathon.singleton.apps.versions(id)
end

Instance Method Details

#change!(hash, force = false) ⇒ Object

Change parameters of a running application. The new application parameters apply only to subsequently created tasks. Currently running tasks are restarted, while maintaining the minimumHealthCapacity. ++hash++: Hash of attributes to change. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/marathon/app.rb', line 80

def change!(hash, force = false)
  check_read_only
  Marathon::Util.keywordize_hash!(hash)
  if hash[:version] and hash.size > 1
    # remove :version if it's not the only key
    new_hash = Marathon::Util.remove_keys(hash, [:version])
  else
    new_hash = hash
  end
  @marathon_instance.apps.change(id, new_hash, force)
end

#check_read_only ⇒ Object

Prevent actions on read only instances. Raises an ArgumentError when triying to change read_only instances.



31
32
33
34
35
# File 'lib/marathon/app.rb', line 31

def check_read_only
  if read_only
    raise Marathon::Error::ArgumentError, "This app is 'read only' and does not support any actions"
  end
end

#refresh ⇒ Object

Reload attributes from marathon API.



50
51
52
53
54
55
56
# File 'lib/marathon/app.rb', line 50

def refresh
  check_read_only
  new_app = @marathon_instance.apps.get(id)
  @info = new_app.info
  refresh_attributes
  self
end

#restart!(force = false) ⇒ Object

Initiates a rolling restart of all running tasks of the given app. This call respects the configured minimumHealthCapacity. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



69
70
71
72
# File 'lib/marathon/app.rb', line 69

def restart!(force = false)
  check_read_only
  @marathon_instance.apps.restart(id, force)
end

#roll_back!(version, force = false) ⇒ Object

Create a new version with parameters of an old version. Currently running tasks are restarted, while maintaining the minimumHealthCapacity. ++version++: Version name of the old version. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



97
98
99
# File 'lib/marathon/app.rb', line 97

def roll_back!(version, force = false)
  change!({:version => version}, force)
end

#scale!(instances, force = false) ⇒ Object

Change the number of desired instances. ++instances++: Number of running instances. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



105
106
107
# File 'lib/marathon/app.rb', line 105

def scale!(instances, force = false)
  change!({:instances => instances}, force)
end

#start!(force = false) ⇒ Object

Create and start the application. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



61
62
63
# File 'lib/marathon/app.rb', line 61

def start!(force = false)
  change!(info, force)
end

#suspend!(force = false) ⇒ Object

Change the number of desired instances to 0. ++force++: If the app is affected by a running deployment, then the update operation will fail. The current deployment can be overridden by setting the force query parameter.



112
113
114
# File 'lib/marathon/app.rb', line 112

def suspend!(force = false)
  scale!(0, force)
end

#to_pretty_s ⇒ Object

Returns a string for listing the application.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/marathon/app.rb', line 121

def to_pretty_s
  %Q[
  App ID:     #{id}
  Instances:  #{tasks.size}/#{instances}
  Command:    #{cmd}
  CPUs:       #{cpus}
  Memory:     #{mem} MB
  #{pretty_container}
  #{pretty_uris}
  #{pretty_env}
  #{pretty_constraints}
  Version:    #{version}
  ]
      .gsub(/\n\s+/, "\n")
      .gsub(/\n\n+/, "\n")
      .strip
end

#to_s ⇒ Object



116
117
118
# File 'lib/marathon/app.rb', line 116

def to_s
  "Marathon::App { :id => #{id} }"
end

#versions(version = nil) ⇒ Object

List the versions of the application. ++version++: Get a specific versions Returns Array of Strings if ++version = nil++, else returns Hash with version information.



41
42
43
44
45
46
47
# File 'lib/marathon/app.rb', line 41

def versions(version = nil)
  if version
    @marathon_instance.apps.version(id, version)
  else
    @marathon_instance.apps.versions(id)
  end
end