jackal-cfn 0.2.26 → 0.2.28

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: 4e0eb97177871e4d5e59799e6dcd6348e3f37f82
4
- data.tar.gz: b965abfa8ca1b3a6bfda081d8db644d8591699d4
3
+ metadata.gz: 088e25e5d30d7eb4a390ca828fab69c6975d064f
4
+ data.tar.gz: 16fddf96b436841f9a527fa7391633feb6562b37
5
5
  SHA512:
6
- metadata.gz: 1dddef4c1cca5592238e40fcc0a31bbcf95d1ff6a43ad1da9542306017c91983bc6f21d82666f83bc421bdf64bcf5f0f790cda7d09446501575f42e03ec6cede
7
- data.tar.gz: 02f44b55eb33008fc49d28166ccc083db25b94858dc9981c3ebaba96c12205095d6d3eb0880aefb658e3377ef507e0700f18f381b1552644e03a6e9aeee7b6e5
6
+ metadata.gz: 8e8ec86af5481f38ba6325abcd606de0d6222d39068df53e71da0ca1bc9e398ed51b3d0933de286dd7a2ab4ae10513848b0b3521cc52e83537a557d5820c2815
7
+ data.tar.gz: b819b5eb2f5af7b4c48db3362a706e5b31866a3edc81de7d422eb3a916f73362452331718d9ff78eda94c89ee21db0bac981f8492398b71997e9bfcc1a1a4b6d
@@ -1,3 +1,9 @@
1
+ # v0.2.28
2
+ * [fix] Break out of command loop at correct context in OrchestrationUnit
3
+ * [enhancement] Reduce maximum allowed size of result included within response in OrchestrationUnit
4
+ * [enhancement] Add keepalive while OrchestrationUnit is processed
5
+ * [enhancement] Add conditional support to unit execution in OrchestrationUnit
6
+
1
7
  # v0.2.26
2
8
  * [fix] Update readpartial usage in OrchestrationUnit
3
9
  * [enhancement] Add debug output to OrchestrationUnit execution
data/README.md CHANGED
@@ -337,13 +337,17 @@ Resource Usage:
337
337
  "CUSTOM_ENV_VARS": "FOR_COMMAND"
338
338
  },
339
339
  "RawResult": true,
340
+ "OnlyIf": "STRING_COMMAND",
341
+ "NotIf": "STRING_COMMAND",
340
342
  "OnCreate": {
341
343
  "Exec": "STRING_COMMAND",
342
344
  "ExecZip": "REMOTE_URL_TO_ZIP",
343
345
  "Env": {
344
346
  "CUSTOM_ENV_VARS": "FOR_COMMAND"
345
347
  },
346
- "RawResult": true
348
+ "RawResult": true,
349
+ "OnlyIf": "STRING_COMMAND",
350
+ "NotIf": "STRING_COMMAND"
347
351
  },
348
352
  "OnUpdate": {
349
353
  "Exec": "STRING_COMMAND",
@@ -351,7 +355,9 @@ Resource Usage:
351
355
  "Env": {
352
356
  "CUSTOM_ENV_VARS": "FOR_COMMAND"
353
357
  },
354
- "RawResult": true
358
+ "RawResult": true,
359
+ "OnlyIf": "STRING_COMMAND",
360
+ "NotIf": "STRING_COMMAND"
355
361
  },
356
362
  "OnDelete": {
357
363
  "Exec": "STRING_COMMAND",
@@ -359,7 +365,9 @@ Resource Usage:
359
365
  "Env": {
360
366
  "CUSTOM_ENV_VARS": "FOR_COMMAND"
361
367
  },
362
- "RawResult": true
368
+ "RawResult": true,
369
+ "OnlyIf": "STRING_COMMAND",
370
+ "NotIf": "STRING_COMMAND"
363
371
  }
364
372
  }
365
373
  }
@@ -14,27 +14,36 @@ module Jackal
14
14
  # "ExecZip": "DOWNLOAD_URI",
15
15
  # "RawResult": true,
16
16
  # "Env": {
17
- # }
17
+ # },
18
+ # OnlyIf": "SHELL_COMMAND",
19
+ # NotIf": "SHELL_COMMAND"
18
20
  # },
19
21
  # "OnUpdate": {
20
22
  # "Exec": "SHELL_COMMAND",
21
23
  # "ExecZip": "DOWNLOAD_URI",
22
24
  # "RawResult": true,
23
25
  # "Env": {
24
- # }
26
+ # },
27
+ # },
28
+ # OnlyIf": "SHELL_COMMAND",
29
+ # NotIf": "SHELL_COMMAND"
25
30
  # },
26
31
  # "OnDelete": {
27
32
  # "Exec": "SHELL_COMMAND",
28
33
  # "ExecZip": "DOWNLOAD_URI",
29
34
  # "RawResult": true,
30
35
  # "Env": {
31
- # }
36
+ # },
37
+ # OnlyIf": "SHELL_COMMAND",
38
+ # NotIf": "SHELL_COMMAND"
32
39
  # },
33
40
  # "Exec": "SHELL_COMMAND",
34
41
  # "ExecZip": "DOWNLOAD_URI",
35
42
  # "Env": {
36
43
  # },
37
- # "RawResult": true
44
+ # "RawResult": true,
45
+ # "OnlyIf": "SHELL_COMMAND",
46
+ # "NotIf": "SHELL_COMMAND"
38
47
  # }
39
48
  # }
40
49
  # }
@@ -42,7 +51,7 @@ module Jackal
42
51
  class OrchestrationUnit < Jackal::Cfn::Resource
43
52
 
44
53
  # Max result size
45
- MAX_RESULT_SIZE = 4096
54
+ MAX_RESULT_SIZE = 2048
46
55
 
47
56
  # Execute orchestration unit
48
57
  #
@@ -54,9 +63,18 @@ module Jackal
54
63
  parameters = rekey_hash(properties[:parameters])
55
64
  cfn_response = build_response(cfn_resource)
56
65
  unit = unit_for(cfn_resource[:request_type], parameters)
57
- working_dir = create_working_directory(payload[:id])
58
- run_unit(unit, working_dir, cfn_response)
59
- FileUtils.rm_rf(working_dir)
66
+ if(unit_runnable?(unit))
67
+ working_dir = create_working_directory(payload[:id])
68
+ keepalive = every(10){ message.touch! }
69
+ begin
70
+ run_unit(unit, working_dir, cfn_response)
71
+ ensure
72
+ keepalive.cancel
73
+ end
74
+ FileUtils.rm_rf(working_dir)
75
+ else
76
+ debug "Received unit for #{message} is not runnable due to conditions! #{unit}"
77
+ end
60
78
  respond_to_stack(cfn_response, cfn_resource[:response_url])
61
79
  job_completed(:jackal_cfn, payload, message)
62
80
  end
@@ -78,6 +96,57 @@ module Jackal
78
96
  dir_path
79
97
  end
80
98
 
99
+ # Determine if unit should be run based on conditional
100
+ # fields
101
+ #
102
+ # @param unit [Hash]
103
+ # @return [TrueClass, FalseClass]
104
+ def unit_runnable?(unit)
105
+ result = true
106
+ conditionals = Smash[
107
+ [:only_if, :not_if].map do |conditional_key|
108
+ stdout = process_manager.create_io_tmp(Carnivore.uuid, 'stdout')
109
+ stderr = process_manager.create_io_tmp(Carnivore.uuid, 'stderr')
110
+ if(unit[conditional_key])
111
+ debug "Executing conditional `#{conditional_key}`: #{unit[conditional_key]}"
112
+ conditional_result = false
113
+ process_manager.process(unit.hash, unit[conditional_key]) do |process|
114
+ process.io.stdout = stdout
115
+ process.io.stderr = stderr
116
+ process.cwd = '/tmp'
117
+ if(unit[:env])
118
+ debug "Custom environment defined: #{unit[:env]}"
119
+ process.environment.replace(unit[:env])
120
+ end
121
+ process.leader = true
122
+ process.start
123
+ begin
124
+ process.poll_for_exit(config.fetch(:max_execution_time, 60))
125
+ debug "Result of conditional `#{conditional_key}`: #{process.exit_code}"
126
+ stdout.rewind
127
+ stderr.rewind
128
+ debug "Result of conditional `#{conditional_key}` output STDOUT: #{stdout.read}"
129
+ debug "Result of conditional `#{conditional_key}` output STDERR: #{stderr.read}"
130
+ conditional_result = process.exit_code == 0
131
+ rescue ChildProcess::TimeoutError
132
+ process.stop
133
+ conditional_result = false
134
+ end
135
+ end
136
+ [conditional_key, conditional_result]
137
+ end
138
+ end.compact
139
+ ]
140
+ if(conditionals.key?(:not_if) && conditionals.key?(:only_if))
141
+ result = !conditionals[:not_if] && conditionals[:only_if]
142
+ elsif(conditionals.key?(:not_if))
143
+ result = !conditionals.key?(:not_if)
144
+ elsif(conditionals.key?(:only_if))
145
+ result = conditionals[:only_if]
146
+ end
147
+ result
148
+ end
149
+
81
150
  # Fetch compressed zip file from remote location and unpack into
82
151
  # provided working directory
83
152
  #
@@ -128,9 +197,8 @@ module Jackal
128
197
  process.leader = true
129
198
  process.start
130
199
  begin
131
- process.poll_for_exit(config.fetch(:max_execution_time, 60))
200
+ process.poll_for_exit(config.fetch(:max_execution_time, 500))
132
201
  result[:exit_code] = process.exit_code
133
- break if result[:exit_code] != 0
134
202
  debug "Execution of command successful - #{exec_command}"
135
203
  rescue ChildProcess::TimeoutError
136
204
  process.stop
@@ -138,17 +206,18 @@ module Jackal
138
206
  result[:exit_code] = process.exit_code
139
207
  end
140
208
  end
209
+ break if result[:exit_code] != 0
141
210
  end
142
211
  result[:stop_time] = Time.now.to_i
143
212
  stdout.rewind
144
213
  if(stdout.size > MAX_RESULT_SIZE)
145
214
  warn "Command result greater than allowed size: #{stdout.size} > #{MAX_RESULT_SIZE}"
146
215
  end
147
- result[:content] = stdout.readpartial(MAX_RESULT_SIZE)
216
+ result[:content] = stdout.size > 0 ? stdout.readpartial(MAX_RESULT_SIZE) : ''
148
217
  if(result[:exit_code] != 0)
149
218
  debug "Execution of unit failed - #{unit}"
150
219
  stderr.rewind
151
- result[:error_message] = stderr.readpartial(MAX_RESULT_SIZE)
220
+ result[:error_message] = stderr.size > 0 ? stderr.readpartial(MAX_RESULT_SIZE) : ''
152
221
  stderr.rewind
153
222
  stdout.rewind
154
223
  debug "Failed unit STDOUT: #{stdout.read}"
@@ -184,9 +253,10 @@ module Jackal
184
253
  base_key = "on_#{request_type.to_s.downcase}"
185
254
  result = Smash.new
186
255
  if(direct_unit = parameters[base_key])
187
- [:exec, :exec_zip, :env, :raw_result].each do |p_key|
256
+ direct_unit = rekey_hash(direct_unit)
257
+ [:exec, :exec_zip, :env, :raw_result, :only_if, :not_if].each do |p_key|
188
258
  if(direct_unit[p_key])
189
- result[p_key] = direct[p_key]
259
+ result[p_key] = direct_unit[p_key]
190
260
  end
191
261
  end
192
262
  end
@@ -207,6 +277,11 @@ module Jackal
207
277
  unless(result.key?('raw_result'))
208
278
  result[:raw_result] = parameters.fetch('raw_result', true)
209
279
  end
280
+ [:only_if, :not_if].each do |conditional_key|
281
+ if(!result.key?(conditional_key) && parameters.key?(conditional_key))
282
+ result[conditional_key] = parameters[conditional_key]
283
+ end
284
+ end
210
285
  result[:env] ||= Smash.new
211
286
  result[:env]['CFN_REQUEST_TYPE'] = request_type.to_s.upcase
212
287
  result
@@ -1,6 +1,6 @@
1
1
  module Jackal
2
2
  module Cfn
3
3
  # Current version
4
- VERSION = Gem::Version.new('0.2.26')
4
+ VERSION = Gem::Version.new('0.2.28')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackal-cfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.26
4
+ version: 0.2.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jackal