marathon_client 0.0.11 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2826c962535b90d6ff63a6a6af09057c4dbe3ba0
4
- data.tar.gz: 283f90955e142fb3dfd0b5a45c5b8ae528a74b81
3
+ metadata.gz: 373a4dd26360c174192c911f7f5077ea9c1822a6
4
+ data.tar.gz: 73a66e779cb50071b726fa554e4fecf5708fe46d
5
5
  SHA512:
6
- metadata.gz: a0d6a767036a503a0a9c32661263f2f23830d15d630d44a32c84344de5eedd5dd0d94b89f9c6abe81df36c1c002f8fed7b5befd4e27a5eedfd293cf15f748507
7
- data.tar.gz: 2e4f10ea0ad84fcca7ab18892eb7e97f6cf896114b38eb1078ac1ef6640706be1d92a81555f0819bf9bebe486bdc6c2a916ac61f758dc38dba8cad8f42e75e67
6
+ metadata.gz: 4d07a14c8e6b562e84f4dfc83cf00b9eaa1c66b19d8fcdfc4dcd6398ae29cf131e9e577b95dfc46a09bbd14e95e07a7c75440dfd82a9b5e864d346237abf4efa
7
+ data.tar.gz: e6b8abd1120b3dd4e39be8b13dfc3cb1a77597eeba0fdcaa53febfc11b1ea0f1c64f25120d8fc1515c5b4a4562cb8075bc25d760a708981b583f3723f70919c4
data/bin/marathon CHANGED
@@ -3,7 +3,7 @@
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'marathon'))
4
4
  require 'trollop'
5
5
 
6
- SUB_COMMANDS = %w[start stop scale list]
6
+ SUB_COMMANDS = %w[start stop scale list search]
7
7
 
8
8
  global_opts = Trollop.options do
9
9
  version Marathon::VERSION
@@ -16,6 +16,7 @@ Available commands:
16
16
  scale Scale the number of app instances.
17
17
  stop Stop an app and remove it from Marathon.
18
18
  list Show a list of running apps and their options.
19
+ search Search the current list of apps.
19
20
 
20
21
  Global options:
21
22
  EOS
@@ -49,6 +50,11 @@ cmd_opts = case cmd
49
50
  Trollop.options do
50
51
  opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
51
52
  end
53
+ when 'search'
54
+ Trollop.options do
55
+ opt :id, 'A unique identifier for the app.', :short => '-i', :type => String, :default => nil
56
+ opt :command, 'The command for the app.', :short => '-C', :type => String, :default => nil
57
+ end
52
58
  else
53
59
  {}
54
60
  end
@@ -59,31 +65,7 @@ marathon = Marathon::Client.new(
59
65
  global_opts[:marathon_pass]
60
66
  )
61
67
 
62
- # Run
63
- case cmd
64
- when 'start'
65
- app_opts = {
66
- :instances => cmd_opts[:num_instances] || 1,
67
- :uris => cmd_opts[:uri] || [],
68
- :cmd => cmd_opts[:command],
69
- :env => cmd_opts[:env].nil? ? {} : Hash[cmd_opts[:env].map { |e| e.split('=', 2) }],
70
- :cpus => cmd_opts[:cpus] || 1.0,
71
- :mem => cmd_opts[:mem] || 10.0,
72
- :constraints => (cmd_opts[:constraint] || []).map { |c| c.split(':') }
73
- }
74
- puts "Starting app '#{cmd_opts[:id]}'"
75
- res = marathon.start(cmd_opts[:id], app_opts)
76
- puts res
77
- when 'scale'
78
- puts "Scaling app '#{cmd_opts[:id]}' to #{cmd_opts[:num_instances]} instances"
79
- res = marathon.scale(cmd_opts[:id], cmd_opts[:num_instances])
80
- puts res
81
- when 'stop'
82
- puts "Stopping app '#{cmd_opts[:id]}'"
83
- res = marathon.stop(cmd_opts[:id])
84
- puts res
85
- when 'list'
86
- res = marathon.list
68
+ def handle_listing(res)
87
69
  if res.success?
88
70
  res.parsed_response.each do |app|
89
71
  puts "App ID: #{app['id']}"
@@ -109,6 +91,35 @@ when 'list'
109
91
  else
110
92
  puts res
111
93
  end
94
+ end
95
+
96
+ # Run
97
+ case cmd
98
+ when 'start'
99
+ app_opts = {
100
+ :instances => cmd_opts[:num_instances] || 1,
101
+ :uris => cmd_opts[:uri] || [],
102
+ :cmd => cmd_opts[:command],
103
+ :env => cmd_opts[:env].nil? ? {} : Hash[cmd_opts[:env].map { |e| e.split('=', 2) }],
104
+ :cpus => cmd_opts[:cpus] || 1.0,
105
+ :mem => cmd_opts[:mem] || 10.0,
106
+ :constraints => (cmd_opts[:constraint] || []).map { |c| c.split(':') }
107
+ }
108
+ puts "Starting app '#{cmd_opts[:id]}'"
109
+ res = marathon.start(cmd_opts[:id], app_opts)
110
+ puts res
111
+ when 'scale'
112
+ puts "Scaling app '#{cmd_opts[:id]}' to #{cmd_opts[:num_instances]} instances"
113
+ res = marathon.scale(cmd_opts[:id], cmd_opts[:num_instances])
114
+ puts res
115
+ when 'stop'
116
+ puts "Stopping app '#{cmd_opts[:id]}'"
117
+ res = marathon.stop(cmd_opts[:id])
118
+ puts res
119
+ when 'list'
120
+ handle_listing(marathon.list)
121
+ when 'search'
122
+ handle_listing(marathon.search(cmd_opts[:id], cmd_opts[:command]))
112
123
  else
113
124
  Trollop.die "unknown subcommand #{cmd.inspect}"
114
125
  end
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  module Marathon
2
4
  class Client
3
5
  include HTTParty
@@ -24,6 +26,18 @@ module Marathon
24
26
  wrap_request(:get, '/v1/apps')
25
27
  end
26
28
 
29
+ def list_tasks(id)
30
+ wrap_request(:get, URI.escape("/v1/apps/#{id}/tasks"))
31
+ end
32
+
33
+ def search(id = nil, cmd = nil)
34
+ params = {}
35
+ params[:id] = id unless id.nil?
36
+ params[:cmd] = cmd unless cmd.nil?
37
+
38
+ wrap_request(:get, "/v1/apps/search?#{query_params(params)}")
39
+ end
40
+
27
41
  def endpoints(id = nil)
28
42
  if id.nil?
29
43
  wrap_request(:get, "/v1/endpoints")
@@ -48,6 +62,12 @@ module Marathon
48
62
  wrap_request(:post, '/v1/apps/stop', :body => body)
49
63
  end
50
64
 
65
+ def kill_tasks(appId, host = '*', scale = false)
66
+ body = {}
67
+ params = {:scale => scale, :host => host, :appId => appId}
68
+ wrap_request(:post, "/v1/tasks/kill?#{query_params(params)}", :body => body)
69
+ end
70
+
51
71
  private
52
72
 
53
73
  def wrap_request(method, url, options = {})
@@ -57,5 +77,9 @@ module Marathon
57
77
  rescue => e
58
78
  Marathon::Response.error(e.message)
59
79
  end
80
+
81
+ def query_params(hash)
82
+ URI.escape(hash.map { |k,v| "#{k}=#{v}" }.join('&'))
83
+ end
60
84
  end
61
85
  end
@@ -1,3 +1,3 @@
1
1
  module Marathon
2
- VERSION = "0.0.11"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marathon_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobi Knaup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop