consul-template-generator 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/consul/template/generator.rb +2 -2
- data/lib/consul/template/generator/cmd.rb +67 -60
- data/lib/consul/template/generator/init.rb +3 -3
- data/lib/consul/template/generator/version.rb +1 -1
- data/spec/init_spec.rb +3 -3
- 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: c81f7c798493e55d5de09e72f18774969babccb2
|
4
|
+
data.tar.gz: c8b6ed3a09773848a3c02cd4d97edc1d65c8dfbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c687b4a6fcc7414422484a01083ef65e9f592a0ba55950df4332d56bd9accdd689b62d23f6fbc2069f908a49580925b2440027bd9262ac7f521dbf3dfac5da3
|
7
|
+
data.tar.gz: a30164de62fbaac82dfd7715003fc2db6a5ed1bd8b351e7b31a9aee6ab2569477c05065eede82609914a48cc1e4bdab4523bc2d2f5775abce22b19434aebc352
|
data/Gemfile.lock
CHANGED
@@ -42,7 +42,7 @@ module Consul
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def create_session(name)
|
45
|
-
Diplomat::Session.create({:Node => self.config.node, :Name => name})
|
45
|
+
Diplomat::Session.create({:Node => self.config.node, :Name => name, :Behavior => 'release'})
|
46
46
|
end
|
47
47
|
|
48
48
|
def renew_session(sess_id)
|
@@ -54,7 +54,7 @@ module Consul
|
|
54
54
|
raise ConsulSessionExpired
|
55
55
|
rescue Exception => e
|
56
56
|
# Letting this go for the time being, until the above issue is fixed
|
57
|
-
self.config.logger.error "Unknown error
|
57
|
+
self.config.logger.error "Unknown error occurred: #{e.message}"
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -5,74 +5,81 @@ module Consul
|
|
5
5
|
module Generator
|
6
6
|
module CMD
|
7
7
|
include Consul::Template::Generator
|
8
|
+
class << self
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def configure(consul_host, templates, session_key, log_level, proxy = nil)
|
11
|
+
Consul::Template::Generator.configure do |config|
|
12
|
+
config.log_level = log_level
|
13
|
+
config.templates = templates
|
14
|
+
config.session_key = session_key
|
15
|
+
config.consul_host = consul_host
|
16
|
+
end
|
17
|
+
@config = Consul::Template::Generator.config
|
15
18
|
end
|
16
|
-
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
uploaded_hashes = {}
|
23
|
-
begin
|
24
|
-
runner = CTRunner.new
|
25
|
-
runner.acquire_session_lock do
|
26
|
-
config.logger.info "Session lock acquired..."
|
27
|
-
begin
|
28
|
-
config.templates.each do |template,template_key|
|
29
|
-
uploaded_hashes[template] = runner.run(template, template_key, uploaded_hashes[template]) || uploaded_hashes[template]
|
30
|
-
sleep cycle_sleep
|
31
|
-
end
|
32
|
-
rescue Interrupt
|
33
|
-
raise # Re-raise to break this rescue block
|
34
|
-
rescue ConsulSessionExpired
|
35
|
-
config.logger.error "The current consul session has expired."
|
36
|
-
break
|
37
|
-
rescue Exception => e
|
38
|
-
config.logger.error "An error occurred while updating template: #{e.message}"
|
39
|
-
config.logger.debug "Sleeping before attempting to update again..."
|
40
|
-
sleep lock_sleep
|
41
|
-
break
|
42
|
-
end until false
|
20
|
+
def signals
|
21
|
+
Signal.trap("INT") do
|
22
|
+
@config.logger.error "Received INT signal..."
|
23
|
+
@interrupted = true
|
43
24
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
25
|
+
Signal.trap("TERM") do
|
26
|
+
@config.logger.error "Received TERM signal..."
|
27
|
+
@terminated = true
|
28
|
+
@interrupted = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def run(cycle_sleep = nil, lock_sleep = nil)
|
33
|
+
signals
|
34
|
+
@terminated = false
|
35
|
+
cycle_sleep ||= 0.5
|
36
|
+
lock_sleep ||= 1.0
|
37
|
+
uploaded_hashes = {}
|
38
|
+
runner = CTRunner.new nil, false
|
50
39
|
begin
|
40
|
+
runner.create_session
|
41
|
+
@interrupted = false
|
42
|
+
runner.acquire_session_lock do
|
43
|
+
@config.logger.info "Session lock acquired..."
|
44
|
+
begin
|
45
|
+
@config.templates.each do |template,template_key|
|
46
|
+
uploaded_hashes[template] = runner.run(template, template_key, uploaded_hashes[template]) || uploaded_hashes[template]
|
47
|
+
sleep cycle_sleep
|
48
|
+
end
|
49
|
+
rescue ConsulSessionExpired
|
50
|
+
@config.logger.error "The current consul session has expired."
|
51
|
+
break
|
52
|
+
rescue Exception => e
|
53
|
+
@config.logger.error "An error occurred while updating template: #{e.message}"
|
54
|
+
@config.logger.debug "Sleeping before attempting to update again..."
|
55
|
+
sleep lock_sleep
|
56
|
+
break
|
57
|
+
end until @interrupted
|
58
|
+
end
|
59
|
+
rescue Exception => e
|
60
|
+
@config.logger.info "Unable to obtain session lock: #{e.message}"
|
61
|
+
@config.logger.debug "Sleeping before attempting lock session again..."
|
51
62
|
sleep lock_sleep
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
runner.destroy_session
|
58
|
-
end until false
|
59
|
-
0
|
60
|
-
end
|
63
|
+
ensure
|
64
|
+
runner.destroy_session
|
65
|
+
end until @terminated
|
66
|
+
0
|
67
|
+
end
|
61
68
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
69
|
+
def run_once
|
70
|
+
begin
|
71
|
+
@config.templates.each do |template,template_key|
|
72
|
+
runner = CTRunner.new
|
73
|
+
result = runner.run template, template_key
|
74
|
+
end
|
75
|
+
rescue Exception => e
|
76
|
+
@config.logger.error "An unexpected error occurred, unable to process template: #{e.message}"
|
77
|
+
1
|
78
|
+
else
|
79
|
+
0
|
68
80
|
end
|
69
|
-
|
70
|
-
|
71
|
-
1
|
72
|
-
else
|
73
|
-
0
|
74
|
-
end
|
75
|
-
end
|
81
|
+
end
|
82
|
+
end
|
76
83
|
end
|
77
84
|
end
|
78
85
|
end
|
@@ -4,8 +4,8 @@ module Consul
|
|
4
4
|
class CTRunner
|
5
5
|
attr_accessor :session
|
6
6
|
|
7
|
-
def initialize(consul_session_id = nil)
|
8
|
-
if consul_session_id.nil?
|
7
|
+
def initialize(consul_session_id = nil, do_create_session = true)
|
8
|
+
if (consul_session_id.nil? && do_create_session)
|
9
9
|
create_session
|
10
10
|
else
|
11
11
|
@session = consul_session_id
|
@@ -17,7 +17,7 @@ module Consul
|
|
17
17
|
unless @session.nil?
|
18
18
|
destroy_session
|
19
19
|
end
|
20
|
-
|
20
|
+
@session = Consul::Template::Generator.create_session 'consul-template-generator'
|
21
21
|
end
|
22
22
|
|
23
23
|
def destroy_session
|
data/spec/init_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
|
|
20
20
|
runner = Consul::Template::Generator::CTRunner.new
|
21
21
|
expect(runner.session).to eql('test-session-id')
|
22
22
|
runner.destroy_session
|
23
|
-
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator"}')
|
23
|
+
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
|
24
24
|
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/test-session-id')
|
25
25
|
expect(runner.session).to be_nil
|
26
26
|
end
|
@@ -30,7 +30,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
|
|
30
30
|
expect(runner.session).to eql('destroyed-session')
|
31
31
|
runner.create_session
|
32
32
|
runner.destroy_session
|
33
|
-
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator"}')
|
33
|
+
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
|
34
34
|
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/destroyed-session')
|
35
35
|
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/test-session-id')
|
36
36
|
expect(runner.session).to be_nil
|
@@ -40,7 +40,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
|
|
40
40
|
runner = Consul::Template::Generator::CTRunner.new 'failed-destroyed-session'
|
41
41
|
expect(runner.session).to eql('failed-destroyed-session')
|
42
42
|
runner.create_session
|
43
|
-
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator"}')
|
43
|
+
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
|
44
44
|
expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/failed-destroyed-session')
|
45
45
|
expect(runner.session).to eql('test-session-id')
|
46
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-template-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Oldfield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|