GithubHelp home page GithubHelp logo

marathon-api's Introduction

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 = 'http://example.com:8080'

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

$ MARATHON_URL=http://remote.marathon.example.com:8080 irb
irb(main):001:0> require 'marathon'
=> true
irb(main):002:0> Marathon.url
=> "http://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://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.

marathon-api's People

Contributors

actaeon avatar carlduevel avatar debanne avatar felixb avatar felixbechstein0000 avatar flosell avatar imriz avatar joergfreimuth3778 avatar mcclurmc avatar mikeantonelli avatar pierrecdn avatar splieth avatar yusufali2205 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

marathon-api's Issues

Group cannot have app and group inside it

Marathon::Group.list throws an error if a Group has an App and a sub-group inside it.
I think its a valid use case to have both an App and a Group inside a Group and should be handled by the API.

Implement Endpoint: /groups

  • GET /v2/groups: List all groups
  • GET /v2/groups/{groupId}: List the group with the specified ID
  • POST /v2/groups: Create and start a new groups
  • PUT /v2/groups/{groupId}: Change parameters of a deployed application group
  • DELETE /v2/groups/{groupId}: Destroy a group

better sync deployments

we should wait for all tasks have the same version like the app when waiting for deployments.

curl "http://marathon.example.com/v2/apps/{appid}" | jq '[(.app.tasks[] | .version) == .app.version] | all'

Implement Endpoint: /eventSubscriptions

  • POST /v2/eventSubscriptions: Register a callback URL as an event subscriber
  • GET /v2/eventSubscriptions: List all event subscriber callback URLs
  • DELETE /v2/eventSubscriptions Unregister a callback URL from the event subscribers list

Implement missing methods for /apps endpoint

  • GET /v2/apps/{appId}/versions: List the versions of the application with id appId.
  • GET /v2/apps/{appId}/versions/{version}: List the configuration of the application with id appId at
  • PUT /v2/apps/{appId}: Change config of the app appId

Get the number of nodes registered with the DC/OS cluster

I am using this Marathon Ruby SDK to get the number of nodes registered with the DC/OS cluster. But I am not getting any method which can return me the number of nodes registered with the cluster.
Any idea how can I get the registered nodes? Thanks in advance

Disable cert verification

I went digging and did not see any option so I thought I would ask..is there anyway to pass down an option to HTTParty to not verify SSL certificates?

dynamically defined accessors don't mix well with rspec

Most/all of the models dynamically define accessors through Marathon::Base and the ACCESSORS constant. I think this is a bit of an anti-pattern; it doesn't save a lot of lines of code (in fact I think it adds some) I see now it's because the accessor is overloaded to reach into the info hash, didn't notice that before.

Dynamic definitions don't play nicely with rspec, though. Say I have the following in a spec:

instance_double(Marathon::DeploymentInfo, deploymentId: 'deployment-id')

Running that test yields:

Marathon::DeploymentInfo class does not implement the instance method: deploymentId

Would you be open to a PR that replaces dynamic definitions of attr_accessors with static ones, assuming there's a way to still have those attributes use the info hash?

Version 2.0.0 cannot start an app in marathon

Since upgrade to 2.0.0, it is impossible to start an application using:

marathon start -j app.json

The command fails with the following trace:

/home/g_seux/.gem/ruby/2.3.0/gems/marathon-api-2.0.0/lib/marathon/app.rb:22:in `initialize': wrong number of arguments (given 1, expected 2..3) (ArgumentError)
    from /home/g_seux/.gem/ruby/2.3.0/gems/marathon-api-2.0.0/bin/marathon:65:in `new'
    from /home/g_seux/.gem/ruby/2.3.0/gems/marathon-api-2.0.0/bin/marathon:65:in `subcmd_start'
    from /home/g_seux/.gem/ruby/2.3.0/gems/marathon-api-2.0.0/bin/marathon:256:in `run_subcmd'
    from /home/g_seux/.gem/ruby/2.3.0/gems/marathon-api-2.0.0/bin/marathon:278:in `<top (required)>'
    from /home/g_seux/.gem/ruby/2.3.0/bin/marathon:23:in `load'
    from /home/g_seux/.gem/ruby/2.3.0/bin/marathon:23:in `<main>'

The reason seems to be that the constructor of Marathon::App has switched to 2 mandatory arguments+1 optional whereas many usages of this class still use the 1 mandator + 1 optional params.

MESOS_* health checks are valid

Currently marathon-api throws the following error:
protocol must be one of HTTP, TCP, COMMAND, HTTPS or nil, but is 'MESOS_HTTP'

Create subclasses on #init

Instead of creating objects when accessing a parameter like App.container, create the objects in App.new.
This triggers all validation of fields in App.new instead in App.container.

refs #14

Marathon tasks is always empty if getting it from the Marathon Group

If you retrieve the Marathon group by the id and then go through it's apps and print out all the tasks for each app, it will be an empty array.

Example:

Marathon::Group.get('group-id').apps.first.tasks # will return []

But this:

Marathon::App.get('app-id-in-group').tasks # will return array of tasks

So I've been getting around this by calling refresh on the Marathon::App to populate the tasks. But when I call refresh, it is returning an array of Marathon::Task since that is the last thing it did in the refresh method. It can be found here: https://github.com/otto-de/marathon-api/blob/master/lib/marathon/app.rb#L163

It should probably end with self so it would return a Marathon::App since that's the expected behavior.

Make accessors writable

At least in most cases it makes sense to let users change attributes of objects.
These changes should be stored to underlying @info.

Please release

Hi,
It's been a while since the last commits has been merged and they cover important feature since ports is now deprecated and portDefinitions should be used instead.
The only missing piece is to issue a new release. Could you do it please ?
Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.