marathon-srv 0.2.0 → 1.0.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: f715198df145818dbb69e69744f6a1afdf4f56d4
4
- data.tar.gz: 33040bfa1df9d3590454b0d7c19debebca393959
3
+ metadata.gz: fa9a28d5862099feadc9a80ef60a903809befd1b
4
+ data.tar.gz: bbbe7c05380fb15a51ee1944fab7f1c6de10a4a6
5
5
  SHA512:
6
- metadata.gz: 459686d8421eef8b2fc03312d8008c3bfe7e52bcef720c622f028f3593f34507fb51b98ad455955f0e3db7ed90ca81634f85366e7406c4bd07d3bbe53d5bc131
7
- data.tar.gz: 52f66d636cdc2294e95ec5321207f2aa63a35fef81f1cc2ceea5597013ef685cbe6f692fe13c0541c7b6835596a0f026180678f2b07ea54262926ce0be2894d4
6
+ metadata.gz: 5d783c03cbfaa26adc93cad895769f9c9cdf10569a6d64ef6defb595b8da04adc5a231c09eaeb08980f0b2e7eee190580ff80a32ecc9a7a3eee7bd8ab57a9ef5
7
+ data.tar.gz: 2a8033b5cfd84d190d75d40c78f2b5d5a697ff583fb65dd7368ba4dd049d5e4ba5d2926963b1142aa4f0f179fb8b8e1fef32b6853bccaefc5e0a6d282b7b3c37
@@ -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, :required => true, :desc => "Docker container-side port to translate"
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
- hosts = client.get_bridged_port_array options[:app_id], (options[:healthy] ? true : falses)
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 hosts
32
+ puts JSON apps
33
33
  else
34
34
 
35
35
  lines=[]
36
- hosts.each do |host|
36
+ apps.each do |app, hosts|
37
37
 
38
- line=[]
39
- line.push host[:host]
40
- host[:services].each do |protocol, services|
41
- line.push protocol
42
- services.each do |port, host_port|
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
- lines.push line.join ","
51
+
48
52
 
49
53
  end
50
54
 
@@ -18,7 +18,7 @@ module Marathon
18
18
 
19
19
  API_VERSION = "v2"
20
20
 
21
- PATH_FIND_APP = "/#{API_VERSION}/apps/%s"
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
- app = (JSON response.body)["app"]
57
-
58
- @logger.debug "Retrieved app object #{app}"
59
-
60
- raise Marathon::Srv::NotDockerContainerizedApplicationError.new unless app["container"]["type"] == "DOCKER"
61
- raise Marathon::Srv::NoRunningTasksFoundError.new unless app["tasks"].size > 0
62
- raise Marathon::Srv::NoHealthChecksDefinedError.new unless app["healthChecks"] != nil && app["healthChecks"].size > 0
63
-
64
- # collect slave ports of (healthy) tasks
65
- ports=[]
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
- if(healthy_tasks_only)
69
- @logger.debug "Verifying health checks for task #{task}"
70
- # all health checks must be passing
71
- passing=true
72
- task["healthCheckResults"].each do |health_check_result|
73
- (passing=false; @logger.debug "%s has failing health check, not considering it" % task; break) unless health_check_result["alive"] == true
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
- ports.reject! do |host|
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.member? port_mapping["containerPort"]))
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
@@ -1,5 +1,5 @@
1
1
  module Marathon
2
2
  module Srv
3
- VERSION = "0.2.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
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.2.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-06 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor