marathon-template 0.0.11 → 0.0.12

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: 803d797b06375a5a01e76ceb30ceec4bba578e20
4
- data.tar.gz: 9fa87c89079f629e9683d4d117e7d8541cd46b29
3
+ metadata.gz: 68b6f9cdb9860cd1b0311093eab0718f3e64546d
4
+ data.tar.gz: 36b0e90716e2fb365618f47aba97a21abe944609
5
5
  SHA512:
6
- metadata.gz: 2715b6a51e65767779b181e89aa3ddd5a5d03530e061747ee37f28284aff34b8600d8f73f6e17416a0ebab1a967180addd2c46159f4237a912226e5d5ddea376
7
- data.tar.gz: b19ac5c0995384ee8f59568a60962350ef663d4b017d574f32b1e7f16304e8e8e6c96f4502af1db88e31efcee52cb83bd050fc177921213c00c85631d953314e
6
+ metadata.gz: 04afaedf48626b35ecce06a296e5c8a7473d84768be74f664cd30a21976b3ac1a126f84596ac1627d9480d5d0677b63d5956d47e6fbad0ffa1c6259f9fa3eb8a
7
+ data.tar.gz: e82b4dfd4e6f96ff9172c0790eba89ce53a4267ed36c090d774220a707be5c658a8ef5b141c6f058ad46fd50ee75061cdffdc441a2518132a84dddbccc1b575c
@@ -106,7 +106,10 @@ module Marathon_template
106
106
  app_name = values['app_name']
107
107
  options = values['options']
108
108
  servers = get_servers(app_name)
109
- if values['management_port']
109
+ if servers['404'] #== '404'
110
+ LOG.info servers
111
+ LOG.info "#{app_name} was not found in Marathon, skipping but continuing to manage the haproxy.cfg"
112
+ elsif values['management_port']
110
113
  LOG.info "#{app_name}: #{servers}"
111
114
  servers.each do |host, port|
112
115
  f.write "\tserver #{app_name}-#{host.split('_').last} #{host.split('_').first}:#{port[0]} #{options} port #{port[1]}\n"
@@ -134,39 +137,38 @@ module Marathon_template
134
137
  end
135
138
 
136
139
  def self.get_servers(app_name)
137
- begin
138
- LOG.info "Getting host and port assignments for #{app_name}..."
139
- marathon_app = "#{CONFIG[:marathon]}/v2/apps/#{app_name}"
140
- encoded_uri = URI.encode(marathon_app.to_s)
141
- uri = URI.parse(encoded_uri)
142
- http = Net::HTTP.new(uri.host, uri.port)
143
- request = Net::HTTP::Get.new(uri.request_uri)
144
- response = http.request(request)
145
-
146
- if response.code == '200'
147
- return_hash = Hash.new
148
- json = JSON.parse(response.body)
149
- tasks = json['app']['tasks']
150
- tasks.each_with_index do |task, i|
151
- LOG.info "Found host #{task['host']} and port #{task['ports']}"
152
- return_hash["#{task['host']}_#{i}"] = task['ports']
153
- # if task['ports'].length == 1
154
- #+ LOG.info "Found host #{task['host']} and port #{task['ports']}"
155
- # return_hash[i] = { task['host'] => task['port'] }
156
- # return_array << "#{task['host']}:#{task['ports'][1]}"
157
- end
158
- else
159
- if response.code == '404'
160
- abort LOG.error "Failed connecting to #{marathon_app}, response code: #{response.code}\n Are you sure the app #{app_name} exists?"
161
- else
162
- abort LOG.error "Failed connecting to #{marathon_app}, response code: #{response.code}"
163
- end
140
+ LOG.info "Getting host and port assignments for #{app_name}..."
141
+ # Setup the URI for marathon and check it before moving on
142
+ marathon_app = "#{CONFIG[:marathon]}/v2/apps/#{app_name}"
143
+ unless URI.parse(URI.encode(marathon_app))
144
+ abort LOG.info "The URI for #{marathon_app} doesn't look right."
145
+ end
146
+ LOG.info "Querying #{marathon_app}"
147
+ # Parse the URI for reals and make a request
148
+ encoded_uri = URI.encode(marathon_app.to_s)
149
+ uri = URI.parse(encoded_uri)
150
+ http = Net::HTTP.new(uri.host, uri.port)
151
+ request = Net::HTTP::Get.new(uri.request_uri)
152
+ response = http.request(request)
153
+ return_hash = Hash.new
154
+ # If we get a 200, lets return the servier hosts and ports assignments
155
+ if response.code == '200'
156
+ json = JSON.parse(response.body)
157
+ tasks = json['app']['tasks']
158
+ tasks.each_with_index do |task, i|
159
+ LOG.info "Found host #{task['host']} and port #{task['ports']}"
160
+ return_hash["#{task['host']}_#{i}"] = task['ports']
164
161
  end
165
- return_hash
166
- rescue Exception => e
167
- e.message
168
- e.backtrace
162
+ # If we don't then do not blow up, simply return not found and move on. This way usable servers still get proxied.
163
+ elsif response.code == '404'
164
+ LOG.warn "Response code: #{response.code}"
165
+ LOG.warn "Are you sure the app #{app_name} exsts?"
166
+ return_hash[response.code] = 'not_found'
167
+ LOG.info return_hash
168
+ else
169
+ abort LOG.error "Got #{response.code} which is neither 404 or 200"
169
170
  end
171
+ return_hash
170
172
  end
171
173
 
172
174
  def self.test_haproxy_dir
@@ -42,5 +42,7 @@ module Marathon_template
42
42
 
43
43
  rescue Exception => e
44
44
  puts "marathon-template failed to execute."
45
+ puts e.message
46
+ puts e.backtrace
45
47
  end
46
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marathon-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Malnick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: