Class: MarathonEndpoint

Inherits:
Object
  • Object
show all
Includes:
HTTPUtils, Utils
Defined in:
lib/panteras_api/marathon_endpoint.rb

Instance Method Summary collapse

Methods included from Utils

fully_qualified_hostname, hostname

Methods included from HTTPUtils

#construct_uri, #get_response_with_redirect, #to_j, #valid_url

Constructor Details

#initialize(host, port = 8080, user = '', passwd = '') ⇒ MarathonEndpoint



5
6
7
8
9
10
# File 'lib/panteras_api/marathon_endpoint.rb', line 5

def initialize(host, port=8080, user='', passwd='')
  @host = host
  @port = port
  @user = user
  @passwd = passwd
end

Instance Method Details

#all_appsObject



17
18
19
# File 'lib/panteras_api/marathon_endpoint.rb', line 17

def all_apps
  to_j(get_response_with_redirect(@host, '/v2/apps/', @port, @user, @passwd))[:apps]
end

#app(app_name) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
# File 'lib/panteras_api/marathon_endpoint.rb', line 12

def app(app_name)
  raise ArgumentError, "Argument be a String" unless (app_name.class == String )
  to_j(get_response_with_redirect(@host, '/v2/apps/' + app_name, @port, @user, @passwd))[:app]
end

#app_namesObject

Raises:

  • (StandardError)


29
30
31
32
33
# File 'lib/panteras_api/marathon_endpoint.rb', line 29

def app_names
  apps = all_apps
  raise StandardError, "Empty response from marathon", caller if apps.nil?
  apps.collect { |a| a[:id][1..-1] }
end

#deploymentsObject



25
26
27
# File 'lib/panteras_api/marathon_endpoint.rb', line 25

def deployments
  to_j(get_response_with_redirect(@host, '/v2/deployments', @port, @user, @passwd))
end

#leaderObject



21
22
23
# File 'lib/panteras_api/marathon_endpoint.rb', line 21

def leader
  to_j(get_response_with_redirect(@host, '/v2/leader', @port, @user, @passwd))[:leader].split(':').first
end

#my_task_ids(hostname, framework = 'marathon') ⇒ Object



44
45
46
# File 'lib/panteras_api/marathon_endpoint.rb', line 44

def my_task_ids(hostname, framework = 'marathon')
  my_tasks(hostname).collect { |t| t.collect { |a| a[:id] } }.flatten
end

#my_tasks(hostname) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/panteras_api/marathon_endpoint.rb', line 39

def my_tasks(hostname)
  raise ArgumentError, "missing hostname argument", caller if hostname.nil?
  app_names.collect { |n| app(n)[:tasks].select { |t| t[:host] =~ /^#{hostname}$/ }  }
end

#task_idsObject



48
49
50
# File 'lib/panteras_api/marathon_endpoint.rb', line 48

def task_ids
  app_names.collect { |a| tasks_ids(a) }
end

#tasks_ids(app_name) ⇒ Object



35
36
37
# File 'lib/panteras_api/marathon_endpoint.rb', line 35

def tasks_ids(app_name)
  app(app_name)[:tasks].collect { |t| t[:id] }
end