Class: MesosCluster
Instance Attribute Summary collapse
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 = 5050) ⇒ MesosCluster
Returns a new instance of MesosCluster.
13
14
15
16
17
18
19
20
|
# File 'lib/panteras_api/mesos_cluster.rb', line 13
def initialize(host, port=5050)
@protocol = "http:"
@host = host
@port = port
@master_info = "/master/redirect"
@state_info = "/master/state"
@state = parse_state
end
|
Instance Attribute Details
#state ⇒ Object
Returns the value of attribute state.
11
12
13
|
# File 'lib/panteras_api/mesos_cluster.rb', line 11
def state
@state
end
|
Instance Method Details
#frameworks ⇒ Object
44
45
46
|
# File 'lib/panteras_api/mesos_cluster.rb', line 44
def frameworks
state[:frameworks]
end
|
#master_hostname ⇒ Object
36
37
38
|
# File 'lib/panteras_api/mesos_cluster.rb', line 36
def master_hostname
state[:hostname]
end
|
#master_id ⇒ Object
40
41
42
|
# File 'lib/panteras_api/mesos_cluster.rb', line 40
def master_id
state[:id]
end
|
#my_tasks_ids(hostname, framework) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/panteras_api/mesos_cluster.rb', line 65
def my_tasks_ids(hostname, framework)
raise ArgumentError, "missing hostname argument", caller if hostname.nil?
if tasks(framework).nil?
framework = framework.gsub(/-[^\s]+/,"")
end
new_tasks = tasks(framework)
if ! new_tasks.nil?
new_tasks.select { |t| t[:slave_hostname] =~ /^#{hostname}$/ }.collect { |t| t[:id] }
else
new_tasks = []
end
end
|
#parse_state ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/panteras_api/mesos_cluster.rb', line 22
def parse_state
response = get_response_with_redirect(@host, @master_info, @port).to_s
response = @protocol + response if !response.include?@protocol
redirect_response = response
if URI.parse(redirect_response).kind_of?(URI::HTTP)
if ! valid_url(redirect_response.to_s)
raise StandardError, "Response from #{@protocol}//#{@host}:#{@port}#{@master_info} is not a valid url: #{redirect_response.to_s}"
end
uri = construct_uri redirect_response.to_s
return to_j(get_response_with_redirect(uri.host, @state_info, uri.port))
end
end
|
#resources ⇒ Object
80
81
82
|
# File 'lib/panteras_api/mesos_cluster.rb', line 80
def resources
state[:frameworks].collect { |f| f[:used_resources] }
end
|
#slave_hostname_by_id(id) ⇒ Object
84
85
86
|
# File 'lib/panteras_api/mesos_cluster.rb', line 84
def slave_hostname_by_id(id)
slaves.select { |s| s[:id] == id }.first[:hostname]
end
|
#slaves ⇒ Object
88
89
90
91
92
|
# File 'lib/panteras_api/mesos_cluster.rb', line 88
def slaves
state[:slaves].collect do |s|
s.select { |k,v| [:hostname, :id].include?(k)}
end
end
|
#task_ids(framework) ⇒ Object
61
62
63
|
# File 'lib/panteras_api/mesos_cluster.rb', line 61
def task_ids(framework)
tasks(framework).collect { |t| t[:id] } if not tasks(framework).nil?
end
|
#tasks(framework = nil) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/panteras_api/mesos_cluster.rb', line 52
def tasks(framework = nil)
results = frameworks.collect do |a|
if a[:name].include? framework
a[:tasks].collect { |t| t[:slave_hostname] = slave_hostname_by_id(t[:slave_id]) ; t }
end
end
results.reject { |r| r.nil? or r.length == 0 }.first
end
|
#tasks_completed ⇒ Object
48
49
50
|
# File 'lib/panteras_api/mesos_cluster.rb', line 48
def tasks_completed
state[:frameworks].collect { |f| f[:completed_tasks].collect { |t| t } }
end
|
#to_s ⇒ Object
94
95
96
|
# File 'lib/panteras_api/mesos_cluster.rb', line 94
def to_s
JSON.pretty_generate @state
end
|