Skip to content

otto-de-legacy/marathon-api

Repository files navigation

marathon-api

Gem Version travis-ci Code Climate

This gem provides an object oriented interface to the Marathon Remote API. At the time if this writing, marathon-api is meant to interface with Marathon version 0.10.1.

Installation

Add this line to your application's Gemfile:

gem 'marathon-api', :require => 'marathon'

And then run:

$ bundle install

Alternatively, if you wish to just use the gem in a script, you can run:

$ gem install marathon-api

Finally, just add require 'marathon' to the top of the file using this gem.

Usage

marathon-api is designed to be very lightweight. Only little state is cached to ensure that each method call's information is up to date. As such, just about every external method represents an API call.

If you're running Marathon locally on port 8080, there is no setup to do in Ruby. If you're not or change the path or port, you'll have to point the gem to your socket or local/remote port. For example:

Marathon.url = 'https://example.com:8080'

It's possible to use ENV variables to configure the endpoint as well:

$ MARATHON_URL=https://remote.marathon.example.com:8080 irb
irb(main):001:0> require 'marathon'
=> true
irb(main):002:0> Marathon.url
=> "https://remote.marathon.example.com:8080"

Authentification

You have two options to set authentification if your Marathon API requires it:

Marathon.options = {:username => 'your-user-name', :password => 'your-secret-password'}

or

$ export MARATHON_USER=your-user-name
$ export MARATHON_PASSWORD=your-secret-password
$ irb
irb(main):001:0> require 'marathon'
=> true
irb(main):002:0> Marathon.options
=> {:username => "your-user-name", :password => "your-secret-password"}

Global calls

require 'marathon'
# => true

Marathon.info
# => {"name"=>"marathon", "http_config"=>{"assets_path"=>null, "http_port"=>8080, "https_port"=>8443}, "frameworkId"=>"20150228-110436-16842879-5050-2169-0001", "leader"=>null, "event_subscriber"=>null, "marathon_config"=>{"local_port_max"=>20000, "local_port_min"=>10000, "hostname"=>"mesos", "master"=>"zk:https://localhost:2181/mesos", "reconciliation_interval"=>300000, "mesos_role"=>null, "task_launch_timeout"=>300000, "reconciliation_initial_delay"=>15000, "ha"=>true, "failover_timeout"=>604800, "checkpoint"=>true, "executor"=>"//cmd", "marathon_store_timeout"=>2000, "mesos_user"=>"root"}, "version"=>"0.8.0", "zookeeper_config"=>{"zk_path"=>"/marathon", "zk"=>null, "zk_timeout"=>10, "zk_hosts"=>"localhost:2181", "zk_future_timeout"=>{"duration"=>10}}, "elected"=>false}

Marathon.ping
# => 'pong'

Applications

You can list, change, delete apps like this:

require 'marathon'

# fetch a list of applications
apps = Marathon::App.list

# scale the first app to 2 instances
apps.first.scale!(2)

# delete the last app
apps.last.delete!

The other Marathon endpoints are available in the same way.

Contributing

Please fork and send pull request. Make sure to have test cases for your changes.

Credits

This gem is inspired by mesosphere's abondend marathon_client and swipelies docker-api.

License

This program is licensed under the MIT license. See LICENSE for details.