marathon-srv 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/marathon/srv/cli.rb +15 -11
- data/lib/marathon/srv/client.rb +43 -36
- data/lib/marathon/srv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa9a28d5862099feadc9a80ef60a903809befd1b
|
4
|
+
data.tar.gz: bbbe7c05380fb15a51ee1944fab7f1c6de10a4a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d783c03cbfaa26adc93cad895769f9c9cdf10569a6d64ef6defb595b8da04adc5a231c09eaeb08980f0b2e7eee190580ff80a32ecc9a7a3eee7bd8ab57a9ef5
|
7
|
+
data.tar.gz: 2a8033b5cfd84d190d75d40c78f2b5d5a697ff583fb65dd7368ba4dd049d5e4ba5d2926963b1142aa4f0f179fb8b8e1fef32b6853bccaefc5e0a6d282b7b3c37
|
data/lib/marathon/srv/cli.rb
CHANGED
@@ -17,7 +17,7 @@ module Marathon
|
|
17
17
|
option :marathon, :required => true, :desc => "Marathon API URL"
|
18
18
|
option :app_id, :reqired => true, :desc => "Marathon application id"
|
19
19
|
option :protocol, :default => "tcp"
|
20
|
-
option :container_port, :
|
20
|
+
option :container_port, :type => :numeric, :desc => "Docker container-side port to translate"
|
21
21
|
option :username, :required => false
|
22
22
|
option :password, :required => false
|
23
23
|
option :healthy, :default => true, :desc => "Consider healthy application instances/tasks only"
|
@@ -26,25 +26,29 @@ module Marathon
|
|
26
26
|
client = Marathon::Srv::Client.new options[:marathon], options[:username], options[:password], {:log_level => (options[:verbose] ? Logger::DEBUG : Logger::ERROR)}
|
27
27
|
|
28
28
|
begin
|
29
|
-
|
29
|
+
apps = client.get_bridged_port_array options[:app_id], (options[:healthy] ? true : false), (options[:container_port] != nil ? [options[:container_port]] : [])
|
30
30
|
|
31
31
|
if options[:json]
|
32
|
-
puts JSON
|
32
|
+
puts JSON apps
|
33
33
|
else
|
34
34
|
|
35
35
|
lines=[]
|
36
|
-
|
36
|
+
apps.each do |app, hosts|
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
line.push host_port
|
38
|
+
hosts.each do |host|
|
39
|
+
|
40
|
+
host[:services].each do |protocol, services|
|
41
|
+
services.each do |port, host_port|
|
42
|
+
line=[]
|
43
|
+
line.push app, host[:host], protocol, port, host_port
|
44
|
+
lines.push line.join ","
|
45
|
+
end
|
46
|
+
|
44
47
|
end
|
45
48
|
|
49
|
+
|
46
50
|
end
|
47
|
-
|
51
|
+
|
48
52
|
|
49
53
|
end
|
50
54
|
|
data/lib/marathon/srv/client.rb
CHANGED
@@ -18,7 +18,7 @@ module Marathon
|
|
18
18
|
|
19
19
|
API_VERSION = "v2"
|
20
20
|
|
21
|
-
PATH_FIND_APP = "/#{API_VERSION}/apps
|
21
|
+
PATH_FIND_APP = "/#{API_VERSION}/apps?id=%s&embed=tasks"
|
22
22
|
|
23
23
|
attr_reader :marathon_api
|
24
24
|
|
@@ -53,48 +53,55 @@ module Marathon
|
|
53
53
|
# parse JSON
|
54
54
|
begin
|
55
55
|
@logger.debug "Parsing body #{response.body}"
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
app["tasks"].each do |task|
|
56
|
+
apps = (JSON response.body)["apps"]
|
57
|
+
@logger.debug "Retrieved a total #{apps.size} app objects"
|
58
|
+
app_ports = {}
|
59
|
+
apps.each do |app|
|
60
|
+
|
61
|
+
@logger.debug "Retrieved app object #{app}"
|
62
|
+
|
63
|
+
raise Marathon::Srv::NotDockerContainerizedApplicationError.new unless app["container"]["type"] == "DOCKER"
|
64
|
+
raise Marathon::Srv::NoRunningTasksFoundError.new unless app["tasks"].size > 0
|
65
|
+
raise Marathon::Srv::NoHealthChecksDefinedError.new unless app["healthChecks"] != nil && app["healthChecks"].size > 0
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
# collect slave ports of (healthy) tasks
|
68
|
+
ports=[]
|
69
|
+
app["tasks"].each do |task|
|
70
|
+
|
71
|
+
if(healthy_tasks_only)
|
72
|
+
@logger.debug "Verifying health checks for task #{task}"
|
73
|
+
# all health checks must be passing
|
74
|
+
passing=true
|
75
|
+
task["healthCheckResults"].each do |health_check_result|
|
76
|
+
(passing=false; @logger.debug "%s has failing health check, not considering it" % task; break) unless health_check_result["alive"] == true
|
77
|
+
|
78
|
+
end
|
79
|
+
(@logger.debug "All health checks passing - filtering ports for task #{task}"; ports.push filter_ports(app, task, filter_ports)) if passing
|
80
|
+
|
81
|
+
else
|
82
|
+
# just add task
|
83
|
+
@logger.debug "Ignoring health checks - filtering ports for task #{task}"
|
84
|
+
ports.push filter_ports(app, task, filter_ports)
|
74
85
|
|
75
86
|
end
|
76
|
-
@logger.debug "All health checks passing - filtering ports for task #{task}"
|
77
|
-
ports.push filter_ports(app, task, filter_ports) if passing
|
78
|
-
|
79
|
-
else
|
80
|
-
# just add task
|
81
|
-
@logger.debug "Ignoring health checks - filtering ports for task #{task}"
|
82
|
-
ports.push filter_ports(app, task, filter_ports)
|
83
87
|
|
84
88
|
end
|
85
89
|
|
90
|
+
# cleanup
|
91
|
+
ports.reject! do |host|
|
92
|
+
|
93
|
+
host[:services].reject! {|protocol, services| services.size == 0 }
|
94
|
+
host[:services].size == 0
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
@logger.debug "Collected ports #{ports} for #{app["id"]}"
|
99
|
+
app_ports[app["id"]] = ports
|
100
|
+
|
86
101
|
end
|
87
102
|
|
88
|
-
|
89
|
-
|
90
|
-
host[:services].reject! {|protocol, services| services.size == 0 }
|
91
|
-
host[:services].size == 0
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
@logger.debug "Collected ports #{ports}"
|
96
|
-
ports
|
97
|
-
|
103
|
+
|
104
|
+
app_ports
|
98
105
|
rescue JSON::ParserError => e
|
99
106
|
raise Marathon::Srv::InvalidJSONResponseError.new e
|
100
107
|
|
@@ -109,7 +116,7 @@ module Marathon
|
|
109
116
|
def filter_ports(app, task, filter_ports=[])
|
110
117
|
port = {:host => task["host"], :services => {}}
|
111
118
|
app["container"]["docker"]["portMappings"].each_with_index do |port_mapping, port_i|
|
112
|
-
if (filter_ports.size == 0 || (filter_ports.
|
119
|
+
if (filter_ports.size == 0 || (filter_ports.include? port_mapping["containerPort"]))
|
113
120
|
port[:services][port_mapping["protocol"]] = {} unless port[:services].has_key? port_mapping["protocol"]
|
114
121
|
port[:services][port_mapping["protocol"]][port_mapping["containerPort"]] = task["ports"][port_i]
|
115
122
|
end
|
data/lib/marathon/srv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marathon-srv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andras Szerdahelyi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|