jflow 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jflow.rb +1 -0
- data/lib/jflow/cli.rb +20 -4
- data/lib/jflow/termination_protector.rb +49 -0
- data/lib/jflow/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00ce3f02a925a9d23d449d6e58d5ee6e234b5053
|
4
|
+
data.tar.gz: 64979f0b07f76690b8f7f6d0705936d3c4679a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15148f66af1e2011e5f1a3bf68df900548d399fba332001abff1b308c4da304820c6f3bd201fe086dd2963438c163bb9122f5516eb8617fdc3e371b69f3dbbfb
|
7
|
+
data.tar.gz: 4b254b3f1313f2e99230c265f6d184f428062111ca536b36b87beb393190fab7ec0b6da7ba21fe5d47dccc67eb0725c8608258bf848e1ac03fe96126164329c0
|
data/lib/jflow.rb
CHANGED
data/lib/jflow/cli.rb
CHANGED
@@ -25,7 +25,7 @@ module JFlow
|
|
25
25
|
number_of_workers.times do
|
26
26
|
worker_threads << worker_thread
|
27
27
|
end
|
28
|
-
worker_threads <<
|
28
|
+
worker_threads << maintenance_thread if enable_stats || is_ec2_instance?
|
29
29
|
worker_threads.each(&:join)
|
30
30
|
end
|
31
31
|
|
@@ -63,18 +63,34 @@ module JFlow
|
|
63
63
|
JFlow.load_activities
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def maintenance_thread
|
67
67
|
JFlow::WorkerThread.new do
|
68
68
|
Thread.current.set_state(:polling)
|
69
69
|
stats = JFlow::Stats.new(@domain, @tasklist)
|
70
|
+
protector = JFlow::TerminationProtector.new
|
70
71
|
loop do
|
71
72
|
break if Thread.current.marked_for_shutdown?
|
72
|
-
|
73
|
+
JFlow.configuration.logger.debug "Should protect?: #{should_protect?}"
|
74
|
+
protector.set_protection(should_protect?) if is_ec2_instance?
|
75
|
+
stats.tick if enable_stats
|
73
76
|
sleep 30
|
74
77
|
end
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
81
|
+
# returns true if any thread if working on someting
|
82
|
+
def should_protect?
|
83
|
+
worker_threads.each do |thread|
|
84
|
+
return true if thread.currently_working?
|
85
|
+
end
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
|
89
|
+
# This should exist on all EC2 instances
|
90
|
+
def is_ec2_instance?
|
91
|
+
@ec2_instance ||= File.exist?('/sys/hypervisor/uuid')
|
92
|
+
end
|
93
|
+
|
78
94
|
def log(str)
|
79
95
|
JFlow.configuration.logger.info str
|
80
96
|
end
|
@@ -95,4 +111,4 @@ module JFlow
|
|
95
111
|
end
|
96
112
|
|
97
113
|
end
|
98
|
-
end
|
114
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module JFlow
|
5
|
+
class TerminationProtector
|
6
|
+
|
7
|
+
def region
|
8
|
+
instance_data['region']
|
9
|
+
end
|
10
|
+
|
11
|
+
def instance_id
|
12
|
+
instance_data['instanceId']
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a hash of instance data, including region, instance id + more
|
16
|
+
def instance_data
|
17
|
+
@instance_data ||= JSON.parse(Net::HTTP.get(URI.parse('http://169.254.169.254/latest/dynamic/instance-identity/document')))
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_asg_name
|
21
|
+
ec2_client = Aws::EC2::Client.new(region: region)
|
22
|
+
instance_tags = ec2_client.describe_tags(filters: [
|
23
|
+
{
|
24
|
+
name: "resource-id",
|
25
|
+
values: [instance_id]
|
26
|
+
}
|
27
|
+
])[0]
|
28
|
+
asg_name = instance_tags.select{|tag| tag.key == "aws:autoscaling:groupName"}.first.value
|
29
|
+
JFlow.configuration.logger.debug "Discovered autoscaling group name #{asg_name}"
|
30
|
+
|
31
|
+
asg_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_protection(protect_status)
|
35
|
+
JFlow.configuration.logger.debug "Setting termination protection status to #{protect_status} for instance #{@instance_id} in region #{@region}"
|
36
|
+
begin
|
37
|
+
asg_client = Aws::AutoScaling::Client.new(region: region)
|
38
|
+
asg_client.set_instance_protection({
|
39
|
+
instance_ids: [instance_id],
|
40
|
+
auto_scaling_group_name: get_asg_name,
|
41
|
+
protected_from_scale_in: protect_status
|
42
|
+
})
|
43
|
+
rescue => e
|
44
|
+
JFlow.configuration.logger.debug "Something went wrong setting termination proection: #{e.inspect}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/jflow/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christophe Verbinnen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-05-
|
12
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/jflow/configuration.rb
|
141
141
|
- lib/jflow/domain.rb
|
142
142
|
- lib/jflow/stats.rb
|
143
|
+
- lib/jflow/termination_protector.rb
|
143
144
|
- lib/jflow/version.rb
|
144
145
|
- lib/jflow/worker_thread.rb
|
145
146
|
homepage: https://github.com/djpate/jflow
|