class Marathon::App
This class represents a Marathon
App
. See mesosphere.github.io/marathon/docs/rest-api.html#apps for full list of API's methods.
Constants
- ACCESSORS
- DEFAULTS
Attributes
Public Class Methods
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
Marathon::Base::new
# 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
Private Class Methods
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.
# File lib/marathon/app.rb, line 220 def change(id, hash, force = false) Marathon.singleton.apps.change(id, hash, force) end
Delete the application with id. id
: Application's id.
# File lib/marathon/app.rb, line 191 def delete(id) Marathon.singleton.apps.delete(id) end
List the application with id. id
: Application's id.
# File lib/marathon/app.rb, line 175 def get(id) Marathon.singleton.apps.get(id) end
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.
# 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 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.
# File lib/marathon/app.rb, line 210 def restart(id, force = false) Marathon.singleton.apps.restart(id, force) end
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
# File lib/marathon/app.rb, line 200 def start(hash) Marathon.singleton.apps.start(hash) end
List the configuration of the application with id at version. id
: Application id version
: Version name
# File lib/marathon/app.rb, line 233 def version(id, version) Marathon.singleton.apps.version(id, version) end
List the versions of the application with id. id
: Application id
# File lib/marathon/app.rb, line 226 def versions(id) Marathon.singleton.apps.versions(id) end
Public Instance Methods
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.
# 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
Prevent actions on read only instances. Raises an ArgumentError when triying to change read_only
instances.
# 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
Reload attributes from marathon API.
# 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
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.
# File lib/marathon/app.rb, line 69 def restart!(force = false) check_read_only @marathon_instance.apps.restart(id, force) end
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.
# File lib/marathon/app.rb, line 97 def roll_back!(version, force = false) change!({:version => version}, force) end
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.
# File lib/marathon/app.rb, line 105 def scale!(instances, force = false) change!({:instances => instances}, force) end
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.
# File lib/marathon/app.rb, line 61 def start!(force = false) change!(info, force) end
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.
# File lib/marathon/app.rb, line 112 def suspend!(force = false) scale!(0, force) end
Returns a string for listing the application.
# 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
# File lib/marathon/app.rb, line 116 def to_s "Marathon::App { :id => #{id} }" end
List the versions of the application. version
: Get a specific versions Returns Array of Strings if ++version = nil++, else returns Hash with version information.
# 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
Private Instance Methods
# File lib/marathon/app.rb, line 155 def pretty_constraints constraints.map { |e| "Constraint: #{e.to_pretty_s}" }.join("\n") end
# File lib/marathon/app.rb, line 141 def pretty_container if container and container.docker "Docker: #{container.docker.to_pretty_s}" end end
# File lib/marathon/app.rb, line 147 def pretty_env env.map { |k, v| "ENV: #{k}=#{v}" }.join("\n") end
# File lib/marathon/app.rb, line 151 def pretty_uris [ (fetch || []).map { |e| e[:uri] } , uris ].compact.reduce([], :|).map { |e| "URI: #{e}" }.join("\n") end
Rebuild attribute classes
# File lib/marathon/app.rb, line 160 def refresh_attributes @healthChecks = (info[:healthChecks] || []).map { |e| Marathon::HealthCheck.new(e) } @constraints = (info[:constraints] || []).map { |e| Marathon::Constraint.new(e) } if info[:container] @container = Marathon::Container.new(info[:container]) else @container = nil end @tasks = (@info[:tasks] || []).map { |e| Marathon::Task.new(e, @marathon_instance) } end