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

constraints[R]
container[R]
healthChecks[R]
read_only[R]
tasks[R]

Public Class Methods

new(hash, marathon_instance = Marathon.singleton, read_only = false) click to toggle source

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

Calls superclass method 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(id, hash, force = false) click to toggle source

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
create(hash)
Alias for: start
delete(id) click to toggle source

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
Also aliased as: remove
get(id) click to toggle source

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(cmd = nil, embed = nil, id=nil, label=nil) click to toggle source

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
remove(id)
Alias for: delete
restart(id, force = false) click to toggle source

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
start(hash) click to toggle source

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
Also aliased as: create
version(id, version) click to toggle source

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
versions(id) click to toggle source

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!(hash, force = false) click to toggle source

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
check_read_only() click to toggle source

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
refresh() click to toggle source

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
restart!(force = false) click to toggle source

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
roll_back!(version, force = false) click to toggle source

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
scale!(instances, force = false) click to toggle source

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
start!(force = false) click to toggle source

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
suspend!(force = false) click to toggle source

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
to_pretty_s() click to toggle source

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
to_s() click to toggle source
# File lib/marathon/app.rb, line 116
def to_s
  "Marathon::App { :id => #{id} }"
end
versions(version = nil) click to toggle source

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

pretty_constraints() click to toggle source
# File lib/marathon/app.rb, line 155
def pretty_constraints
  constraints.map { |e| "Constraint: #{e.to_pretty_s}" }.join("\n")
end
pretty_container() click to toggle source
# File lib/marathon/app.rb, line 141
def pretty_container
  if container and container.docker
    "Docker:     #{container.docker.to_pretty_s}"
  end
end
pretty_env() click to toggle source
# File lib/marathon/app.rb, line 147
def pretty_env
  env.map { |k, v| "ENV:        #{k}=#{v}" }.join("\n")
end
pretty_uris() click to toggle source
# 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
refresh_attributes() click to toggle source

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