nomade 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nomade/deployer.rb +30 -8
- data/lib/nomade/exceptions.rb +1 -0
- data/lib/nomade/http.rb +32 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85557a8305dae1d56eaf0f9d8497948f928f270b8f43d28860836a1ad1fb0b3e
|
4
|
+
data.tar.gz: 92e9afd8c92efb363edf7daf7c3f04f40dd71ca243c58dddfd9d4cd71925bd65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f33f910a59f67c4dcf63ba394a4d4a6d3e48ea555a562d73f5ee2d0dc59e98489270b9502a5e3dc8a2f56398a4d605e0ee11a135d26332a74a5186e3b162d44
|
7
|
+
data.tar.gz: 172af74987917d6a0b2cea45d2e461991a5bc7af46de64a738edd220ecd0e829a25293013fcc45e864c1e7e4eeb74cbcc4da813b86188403a57016bb3f813266
|
data/lib/nomade/deployer.rb
CHANGED
@@ -8,31 +8,53 @@ module Nomade
|
|
8
8
|
@nomad_endpoint = nomad_endpoint
|
9
9
|
@http = Nomade::Http.new(@nomad_endpoint)
|
10
10
|
@logger = opts.fetch(:logger, Nomade.logger)
|
11
|
+
|
12
|
+
@on_success = opts.fetch(:on_success, [])
|
13
|
+
@on_failure = opts.fetch(:on_failure, [])
|
14
|
+
@on_failure << method(:print_errors)
|
11
15
|
end
|
12
16
|
|
13
17
|
def deploy!
|
18
|
+
plan
|
14
19
|
deploy
|
15
20
|
rescue Nomade::NoModificationsError => e
|
16
|
-
|
21
|
+
call_failure_handlers ["No modifications to make, exiting!"]
|
17
22
|
exit(0)
|
18
23
|
rescue Nomade::GeneralError => e
|
19
|
-
|
20
|
-
@logger.warn "GeneralError hit, exiting!"
|
24
|
+
call_failure_handlers [e.message, "GeneralError hit, exiting!"]
|
21
25
|
exit(1)
|
22
26
|
rescue Nomade::PlanningError => e
|
23
|
-
|
27
|
+
call_failure_handlers ["Couldn't make a plan, maybe a bad connection to Nomad server, exiting!"]
|
24
28
|
exit(2)
|
25
29
|
rescue Nomade::AllocationFailedError => e
|
26
|
-
|
30
|
+
call_failure_handlers ["Allocation failed with errors, exiting!"]
|
27
31
|
exit(3)
|
28
32
|
rescue Nomade::UnsupportedDeploymentMode => e
|
29
|
-
|
30
|
-
@logger.warn "Deployment failed with errors, exiting!"
|
33
|
+
call_failure_handlers [e.message, "Deployment failed with errors, exiting!"]
|
31
34
|
exit(4)
|
35
|
+
rescue Nomade::FailedTaskGroupPlan => e
|
36
|
+
call_failure_handlers [e.message, "Couldn't plan correctly, exiting!"]
|
37
|
+
exit(5)
|
32
38
|
end
|
33
39
|
|
34
40
|
private
|
35
41
|
|
42
|
+
def call_failure_handlers(messages)
|
43
|
+
@on_failure.each do |failure_handler|
|
44
|
+
failure_handler.call(messages)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def print_errors(errors)
|
49
|
+
errors.each do |error|
|
50
|
+
@logger.warn(error)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def plan
|
55
|
+
@http.capacity_plan_job(@nomad_job)
|
56
|
+
end
|
57
|
+
|
36
58
|
def deploy
|
37
59
|
@logger.info "Deploying #{@nomad_job.job_name} (#{@nomad_job.job_type}) with #{@nomad_job.image_name_and_version}"
|
38
60
|
@logger.info "URL: #{@nomad_endpoint}/ui/jobs/#{@nomad_job.job_name}"
|
@@ -207,7 +229,7 @@ module Nomade
|
|
207
229
|
end
|
208
230
|
end
|
209
231
|
|
210
|
-
sleep
|
232
|
+
sleep 5 if succesful_deployment == nil
|
211
233
|
end
|
212
234
|
|
213
235
|
if succesful_deployment
|
data/lib/nomade/exceptions.rb
CHANGED
data/lib/nomade/http.rb
CHANGED
@@ -222,8 +222,40 @@ module Nomade
|
|
222
222
|
raise
|
223
223
|
end
|
224
224
|
|
225
|
+
def capacity_plan_job(nomad_job)
|
226
|
+
uri = URI("#{@nomad_endpoint}/v1/job/#{nomad_job.job_name}/plan")
|
227
|
+
|
228
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
229
|
+
if @nomad_endpoint.include?("https://")
|
230
|
+
http.use_ssl = true
|
231
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
232
|
+
end
|
233
|
+
|
234
|
+
req = Net::HTTP::Post.new(uri)
|
235
|
+
req.add_field "Content-Type", "application/json"
|
236
|
+
req.body = nomad_job.configuration(:json)
|
237
|
+
|
238
|
+
res = http.request(req)
|
239
|
+
raise if res.code != "200"
|
240
|
+
raise if res.content_type != "application/json"
|
241
|
+
|
242
|
+
plan_output = JSON.parse(res.body)
|
243
|
+
|
244
|
+
if plan_output["FailedTGAllocs"]
|
245
|
+
raise Nomade::FailedTaskGroupPlan.new("Failed to plan groups: #{plan_output["FailedTGAllocs"].keys.join(",")}")
|
246
|
+
end
|
247
|
+
|
248
|
+
true
|
249
|
+
rescue Nomade::FailedTaskGroupPlan => e
|
250
|
+
raise
|
251
|
+
rescue StandardError => e
|
252
|
+
Nomade.logger.fatal "HTTP Request failed (#{e.message})"
|
253
|
+
raise
|
254
|
+
end
|
255
|
+
|
225
256
|
def plan_job(nomad_job)
|
226
257
|
rendered_template = nomad_job.configuration(:hcl)
|
258
|
+
|
227
259
|
# 0: No allocations created or destroyed. Nothing to do.
|
228
260
|
# 1: Allocations created or destroyed.
|
229
261
|
# 255: Error determining plan results. Nothing to do.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nomade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Grubbe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yell
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.12.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email: nomade@kaspergrubbe.com
|
43
57
|
executables: []
|