marathon_client 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +1 -0
- data/bin/marathon +99 -0
- data/lib/marathon/client.rb +44 -0
- data/lib/marathon/response.rb +46 -0
- data/lib/marathon/version.rb +3 -0
- data/lib/marathon.rb +12 -0
- data/marathon_client.gemspec +26 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2QxNmY3ZGJlNWFmNjIzOWYzZGExMWY5OTUxNzljMTEyOWZiOWZjYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmEyNzE1MzE0ZDU2NWIyZjY2ZGM5YjcyMDI2YTQ4Y2YzZDhmMzVkMg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGMwNWM4ZmFlNTYzMDk4YTJmZmQ4MjM3NWI2Y2UxYTI0MTlmZjI2MzZlOWIz
|
10
|
+
MmJmYTVhN2I3ZjgyOGZjMTRkMjdkMTk2M2RjNTM2N2JiODM4OGE5YjU2NDc2
|
11
|
+
ZGExZTQ5ZmY0NDJhZDQ3YTcyODg5ZGEzYzkwMmM1N2NiNDFhMTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2ViYWE1ZjgyOTE0YmYzNWU4ZGQ5NDc3YTkxNTE5MjZkNzhjYWRjNmE2YmRl
|
14
|
+
NjAxNmU4OTMzNzQzYjQ2ZGViYWE4ZjY4YjcwYTFlZDY1MGQwMjBhNzIyOWFi
|
15
|
+
NTVkOWE2NWQ5NmE4Yzg0YzFhYmY4YTQwMDI0MzQ4ZWEyOGU2M2Q=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tobi Knaup
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Marathon
|
2
|
+
|
3
|
+
Client gem for the Marathon scheduler
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'marathon_client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install marathon_client
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ marathon --help
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
Build the gem from the repo:
|
26
|
+
|
27
|
+
$ gem build marathon_client.gemspec
|
28
|
+
$ gem install marathon_client-*.gem
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/marathon
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'marathon'))
|
4
|
+
require 'slop'
|
5
|
+
|
6
|
+
|
7
|
+
opts = Slop.parse(:help => true) do
|
8
|
+
on :v, 'Print the version' do
|
9
|
+
puts "Version #{Marathon::VERSION}"
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
command 'start' do
|
14
|
+
description 'Start a new app.'
|
15
|
+
|
16
|
+
on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
|
17
|
+
on :i=, :id=, 'A unique identifier for the app.'
|
18
|
+
on :C=, :command=, 'The command to start the app.'
|
19
|
+
on :n=, :num_instances=, 'The number of instances to run (default 1).', :as => Integer
|
20
|
+
on :c=, :cpus=, 'The number of CPUs to give to this app, can be a fraction (default 1.0).', :as => Float
|
21
|
+
on :m=, :mem=, 'The memory limit for this app, in MB, can be a fraction (default 10.0).', :as => Float
|
22
|
+
on :u=, :uri=, 'URIs to download and unpack into the working directory.', :as => Array
|
23
|
+
on :e=, :env=, 'Environment variables to add to the process, as NAME=VALUE.', :as => Array
|
24
|
+
|
25
|
+
run do |opts, args|
|
26
|
+
app_opts = {
|
27
|
+
:instances => opts[:num_instances] || 1,
|
28
|
+
:uris => opts[:uri] || [],
|
29
|
+
:cmd => opts[:command],
|
30
|
+
:env => opts[:env].nil? ? {} : Hash[opts[:env].map { |e| e.split('=', 2) }],
|
31
|
+
:cpus => opts[:cpus] || 1.0,
|
32
|
+
:mem => opts[:mem] || 10.0
|
33
|
+
}
|
34
|
+
|
35
|
+
puts "Starting app '#{opts[:id]}'"
|
36
|
+
res = Marathon::Client.new(opts[:marathon_host]).start(opts[:id], app_opts)
|
37
|
+
puts res
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
command 'scale' do
|
42
|
+
description 'Scale the number of app instances.'
|
43
|
+
|
44
|
+
on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
|
45
|
+
on :i=, :id=, 'A unique identifier for the app.'
|
46
|
+
on :n=, :num_instances=, 'The number of instances to run.', :as => Integer
|
47
|
+
|
48
|
+
run do |opts, args|
|
49
|
+
puts "Scaling app '#{opts[:id]}' to #{opts[:num_instances]} instances"
|
50
|
+
res = Marathon::Client.new(opts[:marathon_host]).scale(opts[:id], opts[:num_instances])
|
51
|
+
puts res
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
command 'stop' do
|
56
|
+
description 'Stop an app and remove it from Marathon.'
|
57
|
+
|
58
|
+
on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
|
59
|
+
on :i=, :id=, 'A unique identifier for the app.'
|
60
|
+
|
61
|
+
run do |opts, args|
|
62
|
+
puts "Stopping app '#{opts[:id]}'"
|
63
|
+
res = Marathon::Client.new(opts[:marathon_host]).stop(opts[:id])
|
64
|
+
puts res
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
command 'list' do
|
69
|
+
description 'Show a list of running apps and their options.'
|
70
|
+
|
71
|
+
on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
|
72
|
+
|
73
|
+
run do |opts, args|
|
74
|
+
res = Marathon::Client.new(opts[:marathon_host]).list
|
75
|
+
if res.ok?
|
76
|
+
res.parsed_response.each do |app|
|
77
|
+
puts "App ID: #{app['id']}"
|
78
|
+
puts "Command: #{app['cmd']}"
|
79
|
+
puts "Instances: #{app['instances']}"
|
80
|
+
puts "CPUs: #{app['cpus']}"
|
81
|
+
puts "Memory: #{app['mem']} MB"
|
82
|
+
app['uris'].each do |uri|
|
83
|
+
puts "URI: #{uri}"
|
84
|
+
end
|
85
|
+
app['env'].each do |k, v|
|
86
|
+
puts "ENV: #{k}=#{v}"
|
87
|
+
end
|
88
|
+
puts
|
89
|
+
end
|
90
|
+
|
91
|
+
if res.parsed_response.empty?
|
92
|
+
puts "No apps are currently running"
|
93
|
+
end
|
94
|
+
else
|
95
|
+
puts res
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Marathon
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
headers 'Content-Type' => 'application/json'
|
6
|
+
query_string_normalizer ->(query) { MultiJson.dump(query) }
|
7
|
+
maintain_method_across_redirects
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(host = nil)
|
11
|
+
@host = host || ENV['MARATHON_HOST'] || 'http://localhost:8080'
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
wrap_request(:get, '/v1/apps')
|
16
|
+
end
|
17
|
+
|
18
|
+
def start(id, opts)
|
19
|
+
body = opts.dup
|
20
|
+
body[:id] = id
|
21
|
+
wrap_request(:post, '/v1/apps/start', :body => body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def scale(id, num_instances)
|
25
|
+
body = {:id => id, :instances => num_instances}
|
26
|
+
wrap_request(:post, '/v1/apps/scale', :body => body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stop(id)
|
30
|
+
body = {:id => id}
|
31
|
+
wrap_request(:post, '/v1/apps/stop', :body => body)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def wrap_request(method, url, options = {})
|
37
|
+
http = self.class.send(method, @host + url, options)
|
38
|
+
Marathon::Response.new(http)
|
39
|
+
rescue => e
|
40
|
+
Marathon::Response.error(e.message)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Marathon
|
2
|
+
class Response
|
3
|
+
|
4
|
+
# TODO make this attr_reader and set the error some other way
|
5
|
+
attr_accessor :error
|
6
|
+
|
7
|
+
def initialize(http)
|
8
|
+
@http = http
|
9
|
+
@error = error_message_from_response
|
10
|
+
end
|
11
|
+
|
12
|
+
def ok?
|
13
|
+
@ok ||= !!@http && @http.success?
|
14
|
+
end
|
15
|
+
|
16
|
+
def error?
|
17
|
+
!ok?
|
18
|
+
end
|
19
|
+
|
20
|
+
def parsed_response
|
21
|
+
@http && @http.parsed_response
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.error(message)
|
25
|
+
error = new(nil)
|
26
|
+
error.error = message
|
27
|
+
error
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
if ok?
|
32
|
+
"OK"
|
33
|
+
else
|
34
|
+
"ERROR: #{error}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def error_message_from_response
|
41
|
+
return if ok?
|
42
|
+
return if @http.nil?
|
43
|
+
@http.body
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/marathon.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
__LIB_DIR__ = File.expand_path(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift __LIB_DIR__ unless $LOAD_PATH.include?(__LIB_DIR__)
|
4
|
+
|
5
|
+
require "httparty"
|
6
|
+
|
7
|
+
require "marathon/version"
|
8
|
+
require "marathon/client"
|
9
|
+
require "marathon/response"
|
10
|
+
|
11
|
+
module Marathon
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'marathon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "marathon_client"
|
8
|
+
spec.version = Marathon::VERSION
|
9
|
+
spec.authors = ["Tobi Knaup"]
|
10
|
+
spec.email = ["tobi@knaup.me"]
|
11
|
+
spec.description = %q{Command line client for the Marathon scheduler. Marathon is a Mesos scheduler for long running services.}
|
12
|
+
spec.summary = %q{Command line client for the Marathon scheduler.}
|
13
|
+
spec.homepage = "http://www.mesosphe.re"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "slop", "~> 3.4.5"
|
22
|
+
spec.add_dependency "httparty", "~> 0.11.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marathon_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobi Knaup
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.4.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.11.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.11.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Command line client for the Marathon scheduler. Marathon is a Mesos scheduler
|
70
|
+
for long running services.
|
71
|
+
email:
|
72
|
+
- tobi@knaup.me
|
73
|
+
executables:
|
74
|
+
- marathon
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/marathon
|
84
|
+
- lib/marathon.rb
|
85
|
+
- lib/marathon/client.rb
|
86
|
+
- lib/marathon/response.rb
|
87
|
+
- lib/marathon/version.rb
|
88
|
+
- marathon_client.gemspec
|
89
|
+
homepage: http://www.mesosphe.re
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Command line client for the Marathon scheduler.
|
113
|
+
test_files: []
|