hotdog 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d906ae40a16258f5ad595603dd51cf64b503e46
4
- data.tar.gz: 50186c1878f0de3534a4e7b8a502ce4380bbe2df
3
+ metadata.gz: 6a33c6f318f239ae040083b0b5fa2c2650dba0ea
4
+ data.tar.gz: a8812e2ddd826bbb5e40b980e5c3a38620b95402
5
5
  SHA512:
6
- metadata.gz: 84a3883786cf631e1874fb39ed08c6475ee4ca293c8bca4d80ca6852191b8e59facfdbb7bcd3ca5ff3ed41632dae89620776986e6e03e9868e029ac796ec003c
7
- data.tar.gz: ee613ad02480b125061011cbd80e05e60ca1716abd48242659552b8b3865ee083fcafca7733bf75eceaf2d2281f2b96403fa6d9e3c63f4a8c24c18b7407365f3
6
+ metadata.gz: bd017bf022fe2b3f8e6d6a129e361f02aa33c1cfaf3ff20a9fb2c0b322ccd3230f5834142b530eff6f6b7c9637e63165e13959a1e7c5365eb26152ace6e7944d
7
+ data.tar.gz: af6f72f01971977d1c727e741ce5bb67926e1732029bea3193976831014e8cddbce4db829568a44d419dc63a58221e9a2e7e4e6e609453a1df515e932ea96fe6
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,400 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-01-07 02:10:16 +0000 using RuboCop version 0.35.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 17
10
+ Lint/ShadowingOuterLocalVariable:
11
+ Exclude:
12
+ - 'lib/hotdog/commands.rb'
13
+ - 'lib/hotdog/commands/hosts.rb'
14
+ - 'lib/hotdog/commands/search.rb'
15
+ - 'lib/hotdog/commands/tags.rb'
16
+
17
+ # Offense count: 70
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
20
+ Lint/UnusedMethodArgument:
21
+ Exclude:
22
+ - 'lib/hotdog/commands.rb'
23
+ - 'lib/hotdog/commands/help.rb'
24
+ - 'lib/hotdog/commands/hosts.rb'
25
+ - 'lib/hotdog/commands/search.rb'
26
+ - 'lib/hotdog/commands/ssh.rb'
27
+ - 'lib/hotdog/commands/tags.rb'
28
+ - 'lib/hotdog/commands/version.rb'
29
+ - 'lib/hotdog/formatters.rb'
30
+ - 'lib/hotdog/formatters/plain.rb'
31
+
32
+ # Offense count: 28
33
+ Metrics/AbcSize:
34
+ Max: 151
35
+
36
+ # Offense count: 8
37
+ Metrics/BlockNesting:
38
+ Max: 7
39
+
40
+ # Offense count: 8
41
+ # Configuration parameters: CountComments.
42
+ Metrics/ClassLength:
43
+ Max: 291
44
+
45
+ # Offense count: 15
46
+ Metrics/CyclomaticComplexity:
47
+ Max: 15
48
+
49
+ # Offense count: 276
50
+ # Configuration parameters: AllowURI, URISchemes.
51
+ Metrics/LineLength:
52
+ Max: 215
53
+
54
+ # Offense count: 38
55
+ # Configuration parameters: CountComments.
56
+ Metrics/MethodLength:
57
+ Max: 87
58
+
59
+ # Offense count: 18
60
+ Metrics/PerceivedComplexity:
61
+ Max: 18
62
+
63
+ # Offense count: 1
64
+ Style/AccessorMethodName:
65
+ Exclude:
66
+ - 'lib/hotdog/commands.rb'
67
+
68
+ # Offense count: 52
69
+ # Cop supports --auto-correct.
70
+ Style/AlignArray:
71
+ Exclude:
72
+ - 'spec/core/commands_spec.rb'
73
+ - 'spec/parser/glob_expression_spec.rb'
74
+ - 'spec/parser/regexp_expression_spec.rb'
75
+ - 'spec/parser/string_expression_spec.rb'
76
+
77
+ # Offense count: 43
78
+ # Cop supports --auto-correct.
79
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
80
+ Style/AndOr:
81
+ Exclude:
82
+ - 'lib/hotdog/application.rb'
83
+ - 'lib/hotdog/commands.rb'
84
+ - 'lib/hotdog/commands/search.rb'
85
+ - 'lib/hotdog/commands/ssh.rb'
86
+ - 'lib/hotdog/commands/tags.rb'
87
+ - 'lib/hotdog/commands/up.rb'
88
+ - 'lib/hotdog/formatters.rb'
89
+ - 'lib/hotdog/formatters/csv.rb'
90
+ - 'lib/hotdog/formatters/json.rb'
91
+ - 'lib/hotdog/formatters/plain.rb'
92
+ - 'lib/hotdog/formatters/tsv.rb'
93
+ - 'lib/hotdog/formatters/yaml.rb'
94
+
95
+ # Offense count: 123
96
+ # Cop supports --auto-correct.
97
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
98
+ Style/BlockDelimiters:
99
+ Enabled: false
100
+
101
+ # Offense count: 77
102
+ # Cop supports --auto-correct.
103
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
104
+ Style/BracesAroundHashParameters:
105
+ Exclude:
106
+ - 'spec/parser/glob_expression_spec.rb'
107
+ - 'spec/parser/parser_spec.rb'
108
+ - 'spec/parser/regexp_expression_spec.rb'
109
+ - 'spec/parser/string_expression_spec.rb'
110
+
111
+ # Offense count: 18
112
+ Style/CaseEquality:
113
+ Exclude:
114
+ - 'lib/hotdog/application.rb'
115
+ - 'lib/hotdog/commands/search.rb'
116
+
117
+ # Offense count: 15
118
+ # Cop supports --auto-correct.
119
+ Style/DefWithParentheses:
120
+ Exclude:
121
+ - 'lib/hotdog/application.rb'
122
+ - 'lib/hotdog/commands.rb'
123
+ - 'lib/hotdog/commands/help.rb'
124
+ - 'lib/hotdog/commands/search.rb'
125
+ - 'lib/hotdog/formatters.rb'
126
+
127
+ # Offense count: 1
128
+ # Cop supports --auto-correct.
129
+ Style/DeprecatedHashMethods:
130
+ Exclude:
131
+ - 'lib/hotdog/application.rb'
132
+
133
+ # Offense count: 49
134
+ # Configuration parameters: Exclude.
135
+ Style/Documentation:
136
+ Enabled: false
137
+
138
+ # Offense count: 13
139
+ # Cop supports --auto-correct.
140
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
141
+ Style/EmptyElse:
142
+ Exclude:
143
+ - 'lib/hotdog/application.rb'
144
+ - 'lib/hotdog/commands.rb'
145
+ - 'lib/hotdog/commands/search.rb'
146
+
147
+ # Offense count: 9
148
+ # Cop supports --auto-correct.
149
+ Style/EmptyLinesAroundAccessModifier:
150
+ Exclude:
151
+ - 'lib/hotdog/application.rb'
152
+ - 'lib/hotdog/commands.rb'
153
+ - 'lib/hotdog/commands/help.rb'
154
+ - 'lib/hotdog/commands/pssh.rb'
155
+ - 'lib/hotdog/commands/search.rb'
156
+ - 'lib/hotdog/commands/ssh.rb'
157
+ - 'lib/hotdog/formatters.rb'
158
+
159
+ # Offense count: 23
160
+ # Cop supports --auto-correct.
161
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
162
+ Style/FirstParameterIndentation:
163
+ Exclude:
164
+ - 'spec/optparse/down_spec.rb'
165
+ - 'spec/optparse/hosts_spec.rb'
166
+ - 'spec/optparse/pssh_spec.rb'
167
+ - 'spec/optparse/search_spec.rb'
168
+ - 'spec/optparse/ssh_spec.rb'
169
+ - 'spec/optparse/tags_spec.rb'
170
+ - 'spec/optparse/up_spec.rb'
171
+
172
+ # Offense count: 20
173
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
174
+ Style/FormatString:
175
+ Exclude:
176
+ - 'lib/hotdog/commands.rb'
177
+ - 'lib/hotdog/commands/down.rb'
178
+ - 'lib/hotdog/commands/hosts.rb'
179
+ - 'lib/hotdog/commands/search.rb'
180
+ - 'lib/hotdog/commands/ssh.rb'
181
+ - 'lib/hotdog/commands/tags.rb'
182
+ - 'lib/hotdog/commands/up.rb'
183
+
184
+ # Offense count: 3
185
+ # Configuration parameters: AllowedVariables.
186
+ Style/GlobalVars:
187
+ Exclude:
188
+ - 'lib/hotdog/commands/search.rb'
189
+
190
+ # Offense count: 2
191
+ # Configuration parameters: MinBodyLength.
192
+ Style/GuardClause:
193
+ Exclude:
194
+ - 'lib/hotdog/commands/ssh.rb'
195
+
196
+ # Offense count: 3
197
+ # Cop supports --auto-correct.
198
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
199
+ Style/HashSyntax:
200
+ Enabled: false
201
+
202
+ # Offense count: 13
203
+ # Cop supports --auto-correct.
204
+ # Configuration parameters: MaxLineLength.
205
+ Style/IfUnlessModifier:
206
+ Exclude:
207
+ - 'lib/hotdog/application.rb'
208
+ - 'lib/hotdog/commands/down.rb'
209
+ - 'lib/hotdog/commands/ssh.rb'
210
+ - 'lib/hotdog/commands/up.rb'
211
+
212
+ # Offense count: 1
213
+ # Cop supports --auto-correct.
214
+ Style/Lambda:
215
+ Exclude:
216
+ - 'lib/hotdog/commands/search.rb'
217
+
218
+ # Offense count: 3
219
+ # Cop supports --auto-correct.
220
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
221
+ Style/LambdaCall:
222
+ Enabled: false
223
+
224
+ # Offense count: 2
225
+ # Cop supports --auto-correct.
226
+ Style/LeadingCommentSpace:
227
+ Exclude:
228
+ - 'bin/hotdog'
229
+
230
+ # Offense count: 12
231
+ # Cop supports --auto-correct.
232
+ Style/MethodCallParentheses:
233
+ Exclude:
234
+ - 'lib/hotdog/commands.rb'
235
+ - 'lib/hotdog/commands/search.rb'
236
+ - 'lib/hotdog/commands/up.rb'
237
+
238
+ # Offense count: 7
239
+ Style/MultilineBlockChain:
240
+ Exclude:
241
+ - 'lib/hotdog/commands.rb'
242
+ - 'lib/hotdog/commands/search.rb'
243
+ - 'lib/hotdog/commands/ssh.rb'
244
+
245
+ # Offense count: 1
246
+ # Cop supports --auto-correct.
247
+ Style/NegatedIf:
248
+ Exclude:
249
+ - 'lib/hotdog/commands.rb'
250
+
251
+ # Offense count: 1
252
+ # Cop supports --auto-correct.
253
+ # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
254
+ Style/Next:
255
+ Exclude:
256
+ - 'lib/hotdog/commands/ssh.rb'
257
+
258
+ # Offense count: 3
259
+ # Cop supports --auto-correct.
260
+ Style/Not:
261
+ Exclude:
262
+ - 'lib/hotdog/commands.rb'
263
+ - 'lib/hotdog/commands/search.rb'
264
+
265
+ # Offense count: 4
266
+ # Cop supports --auto-correct.
267
+ Style/NumericLiterals:
268
+ MinDigits: 6
269
+
270
+ # Offense count: 2
271
+ # Cop supports --auto-correct.
272
+ # Configuration parameters: PreferredDelimiters.
273
+ Style/PercentLiteralDelimiters:
274
+ Exclude:
275
+ - 'hotdog.gemspec'
276
+
277
+ # Offense count: 13
278
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
279
+ Style/RaiseArgs:
280
+ Enabled: false
281
+
282
+ # Offense count: 1
283
+ # Cop supports --auto-correct.
284
+ Style/RedundantBegin:
285
+ Exclude:
286
+ - 'lib/hotdog/commands.rb'
287
+
288
+ # Offense count: 2
289
+ # Cop supports --auto-correct.
290
+ Style/RedundantSelf:
291
+ Exclude:
292
+ - 'lib/hotdog/commands/search.rb'
293
+
294
+ # Offense count: 1
295
+ # Cop supports --auto-correct.
296
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
297
+ Style/RegexpLiteral:
298
+ Exclude:
299
+ - 'lib/hotdog/commands/search.rb'
300
+
301
+ # Offense count: 17
302
+ # Cop supports --auto-correct.
303
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
304
+ Style/SignalException:
305
+ Exclude:
306
+ - 'lib/hotdog/application.rb'
307
+ - 'lib/hotdog/commands.rb'
308
+ - 'lib/hotdog/commands/down.rb'
309
+ - 'lib/hotdog/commands/search.rb'
310
+ - 'lib/hotdog/commands/ssh.rb'
311
+ - 'lib/hotdog/commands/up.rb'
312
+ - 'lib/hotdog/formatters.rb'
313
+
314
+ # Offense count: 158
315
+ # Cop supports --auto-correct.
316
+ # Configuration parameters: SupportedStyles.
317
+ Style/SpaceAroundEqualsInParameterDefault:
318
+ EnforcedStyle: no_space
319
+
320
+ # Offense count: 3
321
+ # Cop supports --auto-correct.
322
+ # Configuration parameters: MultiSpaceAllowedForOperators.
323
+ Style/SpaceAroundOperators:
324
+ Exclude:
325
+ - 'lib/hotdog/commands/down.rb'
326
+ - 'lib/hotdog/commands/search.rb'
327
+
328
+ # Offense count: 1
329
+ # Cop supports --auto-correct.
330
+ Style/SpaceInsideBrackets:
331
+ Exclude:
332
+ - 'lib/hotdog/commands/search.rb'
333
+
334
+ # Offense count: 374
335
+ # Cop supports --auto-correct.
336
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
337
+ Style/SpaceInsideHashLiteralBraces:
338
+ Enabled: false
339
+
340
+ # Offense count: 25
341
+ # Cop supports --auto-correct.
342
+ Style/SpaceInsideParens:
343
+ Exclude:
344
+ - 'lib/hotdog/application.rb'
345
+ - 'lib/hotdog/commands.rb'
346
+ - 'lib/hotdog/commands/search.rb'
347
+
348
+ # Offense count: 4
349
+ # Cop supports --auto-correct.
350
+ Style/SpecialGlobalVars:
351
+ Exclude:
352
+ - 'lib/hotdog/commands/help.rb'
353
+ - 'lib/hotdog/commands/ssh.rb'
354
+ - 'lib/hotdog/commands/version.rb'
355
+
356
+ # Offense count: 1554
357
+ # Cop supports --auto-correct.
358
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
359
+ Style/StringLiterals:
360
+ Enabled: false
361
+
362
+ # Offense count: 15
363
+ # Cop supports --auto-correct.
364
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
365
+ Style/StringLiteralsInInterpolation:
366
+ Enabled: false
367
+
368
+ # Offense count: 16
369
+ # Cop supports --auto-correct.
370
+ # Configuration parameters: IgnoredMethods.
371
+ Style/SymbolProc:
372
+ Exclude:
373
+ - 'lib/hotdog/application.rb'
374
+ - 'lib/hotdog/commands.rb'
375
+ - 'lib/hotdog/commands/search.rb'
376
+
377
+ # Offense count: 71
378
+ # Cop supports --auto-correct.
379
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
380
+ Style/TrailingComma:
381
+ Enabled: false
382
+
383
+ # Offense count: 6
384
+ # Cop supports --auto-correct.
385
+ Style/TrailingWhitespace:
386
+ Exclude:
387
+ - 'spec/formatter/plain_spec.rb'
388
+ - 'spec/formatter/text_spec.rb'
389
+
390
+ # Offense count: 2
391
+ # Cop supports --auto-correct.
392
+ Style/UnneededPercentQ:
393
+ Exclude:
394
+ - 'hotdog.gemspec'
395
+
396
+ # Offense count: 66
397
+ # Cop supports --auto-correct.
398
+ # Configuration parameters: WordRegex.
399
+ Style/WordArray:
400
+ MinSize: 4
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.6
4
- - 2.2.3
5
- script: rspec spec
3
+ - 2.1.6
4
+ - 2.2.3
5
+ - 2.3.0
6
+ script:
7
+ - rspec spec
6
8
  sudo: false
data/hotdog.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.3.0"
24
+ spec.add_development_dependency "rubocop", "~> 0.35.1"
24
25
 
25
26
  spec.add_dependency "dogapi", ">= 1.13.0"
26
27
  spec.add_dependency "multi_json", "~> 1.11.2"
@@ -58,7 +58,7 @@ module Hotdog
58
58
  command = get_command(command_name)
59
59
  rescue NameError
60
60
  STDERR.puts("hotdog: '#{command_name}' is not a hotdog command.")
61
- get_command("help").parse_options(@optparse, ["commands"])
61
+ get_command("help").run(["commands"], options)
62
62
  exit(1)
63
63
  end
64
64
 
@@ -94,8 +94,8 @@ module Hotdog
94
94
  end
95
95
 
96
96
  command.run(args, @options)
97
- rescue Errno::EPIPE
98
- # nop
97
+ rescue Errno::EPIPE => error
98
+ STDERR.puts(error)
99
99
  end
100
100
  end
101
101
 
@@ -159,7 +159,8 @@ module Hotdog
159
159
  begin
160
160
  klass = Hotdog::Formatters.const_get(const_name(name))
161
161
  rescue NameError
162
- if library = find_library("hotdog/formatters", name)
162
+ library = find_library("hotdog/formatters", name)
163
+ if library
163
164
  load library
164
165
  klass = Hotdog::Formatters.const_get(const_name(File.basename(library, ".rb")))
165
166
  else
@@ -173,7 +174,8 @@ module Hotdog
173
174
  begin
174
175
  klass = Hotdog::Commands.const_get(const_name(name))
175
176
  rescue NameError
176
- if library = find_library("hotdog/commands", name)
177
+ library = find_library("hotdog/commands", name)
178
+ if library
177
179
  load library
178
180
  klass = Hotdog::Commands.const_get(const_name(File.basename(library, ".rb")))
179
181
  else
@@ -187,10 +189,11 @@ module Hotdog
187
189
  load_path = $LOAD_PATH.map { |path| File.join(path, dirname) }.select { |path| File.directory?(path) }
188
190
  libraries = load_path.flat_map { |path| Dir.glob(File.join(path, "*.rb")) }.select { |file| File.file?(file) }
189
191
  rbname = "#{name}.rb"
190
- if library = libraries.find { |file| File.basename(file) == rbname }
192
+ library = libraries.find { |file| File.basename(file) == rbname }
193
+ if library
191
194
  library
192
195
  else
193
- candidates = libraries.map { |file| [file, File.basename(file).slice(0, name.length)] }.select { |file, s| s == name }
196
+ candidates = libraries.map { |file| [file, File.basename(file).slice(0, name.length)] }.select { |_file, s| s == name }
194
197
  if candidates.length == 1
195
198
  candidates.first.first
196
199
  else
@@ -8,9 +8,16 @@ module Hotdog
8
8
  def define_options(optparse, options={})
9
9
  options[:downtime] = 86400
10
10
  options[:start] = Time.new
11
+ options[:retry] = 5
11
12
  optparse.on("--downtime DURATION") do |v|
12
13
  options[:downtime] = v.to_i
13
14
  end
15
+ optparse.on("--retry NUM") do |v|
16
+ options[:retry] = v.to_i
17
+ end
18
+ optparse.on("--retry-delay SECONDS") do |v|
19
+ options[:retry_delay] = v.to_i
20
+ end
14
21
  optparse.on("--start TIME") do |v|
15
22
  options[:start] = Time.parse(v)
16
23
  end
@@ -23,10 +30,18 @@ module Hotdog
23
30
  else
24
31
  scope = arg
25
32
  end
26
- code, schedule = dog.schedule_downtime(scope, :start => options[:start].to_i, :end => (options[:start]+options[:downtime]).to_i)
27
- logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, options[:start].to_i, (options[:start]+options[:downtime]).to_i, code.inspect, schedule.inspect])
28
- if code.to_i / 100 != 2
29
- raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect])
33
+ if 0 < options[:retry]
34
+ options[:retry].times do |i|
35
+ begin
36
+ schedule_downtime(scope, options)
37
+ break
38
+ rescue => error
39
+ logger.warn(error.to_s)
40
+ sleep(options[:retry_delay] || (1<<i))
41
+ end
42
+ end
43
+ else
44
+ schedule_downtime(scope, options)
30
45
  end
31
46
  end
32
47
 
@@ -36,6 +51,16 @@ module Hotdog
36
51
  end
37
52
  FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
38
53
  end
54
+
55
+ private
56
+ def schedule_downtime(scope, options={})
57
+ code, schedule = dog.schedule_downtime(scope, :start => options[:start].to_i, :end => (options[:start]+options[:downtime]).to_i)
58
+ logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, options[:start].to_i, (options[:start]+options[:downtime]).to_i, code.inspect, schedule.inspect])
59
+ if code.to_i / 100 != 2
60
+ raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect])
61
+ end
62
+ schedule
63
+ end
39
64
  end
40
65
  end
41
66
  end
@@ -57,7 +57,7 @@ module Hotdog
57
57
  end
58
58
 
59
59
  def get_hosts_with_search_tags(result, node)
60
- drilldown = ->(n){
60
+ drilldown = ->(n) {
61
61
  case
62
62
  when n[:left] && n[:right] then drilldown.(n[:left]) + drilldown.(n[:right])
63
63
  when n[:expression] then drilldown.(n[:expression])
@@ -691,7 +691,8 @@ module Hotdog
691
691
  when :OR
692
692
  if expressions.all? { |expression| TagExpressionNode === expression }
693
693
  values = expressions.group_by { |expression| expression.class }.values.flat_map { |expressions|
694
- if query_without_condition = expressions.first.maybe_query_without_condition(options)
694
+ query_without_condition = expressions.first.maybe_query_without_condition(options)
695
+ if query_without_condition
695
696
  condition_length = expressions.map { |expression| expression.condition_values(options).length }.max
696
697
  expressions.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / condition_length).flat_map { |expressions|
697
698
  q = query_without_condition.sub(/\s*;\s*\z/, "") + " WHERE " + expressions.map { |expression| "( %s )" % expression.condition(options) }.join(" OR ") + ";"
@@ -800,7 +801,8 @@ module Hotdog
800
801
  end
801
802
 
802
803
  def maybe_query(options={})
803
- if query_without_condition = maybe_query_without_condition(options)
804
+ query_without_condition = maybe_query_without_condition(options)
805
+ if query_without_condition
804
806
  query_without_condition.sub(/\s*;\s*\z/, "") + " WHERE " + condition(options) + ";"
805
807
  else
806
808
  nil
@@ -838,7 +840,8 @@ module Hotdog
838
840
  end
839
841
 
840
842
  def evaluate(environment, options={})
841
- if q = maybe_query(options)
843
+ q = maybe_query(options)
844
+ if q
842
845
  values = environment.execute(q, condition_values(options)).map { |row| row.first }
843
846
  if values.empty?
844
847
  if options[:did_fallback]
@@ -964,7 +967,8 @@ module Hotdog
964
967
 
965
968
  def maybe_fallback(options={})
966
969
  fallback = GlobHostNode.new(to_glob(attribute), separator)
967
- if query = fallback.maybe_query(options)
970
+ query = fallback.maybe_query(options)
971
+ if query
968
972
  QueryExpressionNode.new(query, fallback.condition_values(options))
969
973
  else
970
974
  nil
@@ -991,7 +995,8 @@ module Hotdog
991
995
 
992
996
  def maybe_fallback(options={})
993
997
  fallback = GlobTagNode.new(to_glob(identifier), to_glob(attribute), separator)
994
- if query = fallback.maybe_query(options)
998
+ query = fallback.maybe_query(options)
999
+ if query
995
1000
  QueryExpressionNode.new(query, fallback.condition_values(options))
996
1001
  else
997
1002
  nil
@@ -1018,7 +1023,8 @@ module Hotdog
1018
1023
 
1019
1024
  def maybe_fallback(options={})
1020
1025
  fallback = GlobTagNameNode.new(to_glob(identifier), separator)
1021
- if query = fallback.maybe_query(options)
1026
+ query = fallback.maybe_query(options)
1027
+ if query
1022
1028
  QueryExpressionNode.new(query, fallback.condition_values(options))
1023
1029
  else
1024
1030
  nil
@@ -1045,7 +1051,8 @@ module Hotdog
1045
1051
 
1046
1052
  def maybe_fallback(options={})
1047
1053
  fallback = GlobTagValueNode.new(to_glob(attribute), separator)
1048
- if query = fallback.maybe_query(options)
1054
+ query = fallback.maybe_query(options)
1055
+ if query
1049
1056
  QueryExpressionNode.new(query, fallback.condition_values(options))
1050
1057
  else
1051
1058
  nil
@@ -1072,7 +1079,8 @@ module Hotdog
1072
1079
 
1073
1080
  def maybe_fallback(options={})
1074
1081
  fallback = GlobNode.new(to_glob(identifier), separator)
1075
- if query = fallback.maybe_query(options)
1082
+ query = fallback.maybe_query(options)
1083
+ if query
1076
1084
  QueryExpressionNode.new(query, fallback.condition_values(options))
1077
1085
  else
1078
1086
  nil
@@ -1110,7 +1118,8 @@ module Hotdog
1110
1118
 
1111
1119
  def maybe_fallback(options={})
1112
1120
  fallback = GlobHostNode.new(to_glob(attribute), separator)
1113
- if query = fallback.maybe_query(options)
1121
+ query = fallback.maybe_query(options)
1122
+ if query
1114
1123
  QueryExpressionNode.new(query, fallback.condition_values(options))
1115
1124
  else
1116
1125
  nil
@@ -1137,7 +1146,8 @@ module Hotdog
1137
1146
 
1138
1147
  def maybe_fallback(options={})
1139
1148
  fallback = GlobTagNode.new(to_glob(identifier), to_glob(attribute), separator)
1140
- if query = fallback.maybe_query(options)
1149
+ query = fallback.maybe_query(options)
1150
+ if query
1141
1151
  QueryExpressionNode.new(query, fallback.condition_values(options))
1142
1152
  else
1143
1153
  nil
@@ -1164,7 +1174,8 @@ module Hotdog
1164
1174
 
1165
1175
  def maybe_fallback(options={})
1166
1176
  fallback = GlobTagNameNode.new(to_glob(identifier), separator)
1167
- if query = fallback.maybe_query(options)
1177
+ query = fallback.maybe_query(options)
1178
+ if query
1168
1179
  QueryExpressionNode.new(query, fallback.condition_values(options))
1169
1180
  else
1170
1181
  nil
@@ -1191,7 +1202,8 @@ module Hotdog
1191
1202
 
1192
1203
  def maybe_fallback(options={})
1193
1204
  fallback = GlobTagValueNode.new(to_glob(attribute), separator)
1194
- if query = fallback.maybe_query(options)
1205
+ query = fallback.maybe_query(options)
1206
+ if query
1195
1207
  QueryExpressionNode.new(query, fallback.condition_values(options))
1196
1208
  else
1197
1209
  nil
@@ -1218,7 +1230,8 @@ module Hotdog
1218
1230
 
1219
1231
  def maybe_fallback(options={})
1220
1232
  fallback = GlobNode.new(to_glob(identifier), separator)
1221
- if query = fallback.maybe_query(options)
1233
+ query = fallback.maybe_query(options)
1234
+ if query
1222
1235
  QueryExpressionNode.new(query, fallback.condition_values(options))
1223
1236
  else
1224
1237
  nil
@@ -61,7 +61,7 @@ module Hotdog
61
61
  end
62
62
 
63
63
  result0 = evaluate(node, self)
64
- result, fields = get_hosts_with_search_tags(result0, node)
64
+ result, _fields = get_hosts_with_search_tags(result0, node)
65
65
  hosts = filter_hosts(result.flatten)
66
66
  validate_hosts!(hosts)
67
67
  run_main(hosts, options)
@@ -77,9 +77,9 @@ module Hotdog
77
77
  filtered_hosts = Parallel.map(hosts, in_threads: parallelism(hosts)) { |host|
78
78
  cmdline = build_command_string(host, options[:filter_command], options)
79
79
  [host, exec_command(host, cmdline, output: false)]
80
- }.select { |host, stat|
80
+ }.select { |_host, stat|
81
81
  stat
82
- }.map { |host, stat|
82
+ }.map { |host, _stat|
83
83
  host
84
84
  }
85
85
  if hosts == filtered_hosts
@@ -9,16 +9,16 @@ module Hotdog
9
9
  show_tags(result)
10
10
  else
11
11
  tags = args.map { |tag| split_tag(tag) }
12
- if tags.all? { |tag_name, tag_value| tag_value.empty? }
12
+ if tags.all? { |_tag_name, tag_value| tag_value.empty? }
13
13
  result = tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |tags|
14
14
  q = "SELECT value FROM tags " \
15
- "WHERE %s;" % tags.map { |tag_name, tag_value| glob?(tag_name) ? "LOWER(name) GLOB LOWER(?)" : "name = ?" }.join(" OR ")
16
- execute(q, tags.map { |tag_name, tag_value| tag_name }).map { |value| [value] }
15
+ "WHERE %s;" % tags.map { |tag_name, _tag_value| glob?(tag_name) ? "LOWER(name) GLOB LOWER(?)" : "name = ?" }.join(" OR ")
16
+ execute(q, tags.map { |tag_name, _tag_value| tag_name }).map { |value| [value] }
17
17
  }
18
18
  else
19
19
  result = tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 2).flat_map { |tags|
20
20
  q = "SELECT value FROM tags " \
21
- "WHERE %s;" % tags.map { |tag_name, tag_value| (glob?(tag_name) or glob?(tag_value)) ? "( LOWER(name) GLOB LOWER(?) AND LOWER(value) GLOB LOWER(?) )" : "( name = ? AND value = ? )" }.join(" OR ")
21
+ "WHERE %s;" % tags.map { |tag_name, tag_value| (glob?(tag_name) or glob?(tag_value)) ? "( LOWER(name) GLOB LOWER(?) AND LOWER(value) GLOB LOWER(?) )" : "( name = ? AND value = ? )" }.join(" OR ")
22
22
  execute(q, tags).map { |value| [value] }
23
23
  }
24
24
  end
@@ -5,6 +5,16 @@ require "fileutils"
5
5
  module Hotdog
6
6
  module Commands
7
7
  class Up < BaseCommand
8
+ def define_options(optparse, options={})
9
+ options[:retry] = 5
10
+ optparse.on("--retry NUM") do |v|
11
+ options[:retry] = v.to_i
12
+ end
13
+ optparse.on("--retry-delay SECONDS") do |v|
14
+ options[:retry_delay] = v.to_i
15
+ end
16
+ end
17
+
8
18
  def run(args=[], options={})
9
19
  scopes = args.map { |arg|
10
20
  if arg.index(":").nil?
@@ -13,9 +23,19 @@ module Hotdog
13
23
  arg
14
24
  end
15
25
  }
16
- code, all_downtimes = dog.get_all_downtimes()
17
- if code.to_i / 100 != 2
18
- raise("dog.get_all_downtimes() returns [%s, %s]" % [code.inspect, all_downtimes.inspect])
26
+ all_downtimes = nil
27
+ if 0 < options[:retry]
28
+ options[:retry].times do |i|
29
+ begin
30
+ all_downtimes = get_all_downtimes(options)
31
+ break
32
+ rescue => error
33
+ logger.warn(error.to_s)
34
+ sleep(options[:retry_delay] || (1<<i))
35
+ end
36
+ end
37
+ else
38
+ all_downtimes = get_all_downtimes(options)
19
39
  end
20
40
 
21
41
  cancel_downtimes = all_downtimes.select { |downtime|
@@ -23,9 +43,18 @@ module Hotdog
23
43
  }
24
44
 
25
45
  cancel_downtimes.each do |downtime|
26
- code, cancel = dog.cancel_downtime(downtime["id"])
27
- if code.to_i / 100 != 2
28
- raise("dog.cancel_downtime(%s) returns [%s, %s]" % [downtime["id"].inspect, code.inspect, cancel.inspect])
46
+ if 0 < options[:retry]
47
+ options[:retry].times do |i|
48
+ begin
49
+ cancel_downtime(downtime["id"], options)
50
+ break
51
+ rescue => error
52
+ logger.warn(error.to_s)
53
+ sleep(options[:retry_delay] || (1<<i))
54
+ end
55
+ end
56
+ else
57
+ cancel_downtime(downtime["id"], options)
29
58
  end
30
59
  end
31
60
 
@@ -35,6 +64,23 @@ module Hotdog
35
64
  end
36
65
  FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
37
66
  end
67
+
68
+ private
69
+ def get_all_downtimes(options={})
70
+ code, all_downtimes = dog.get_all_downtimes()
71
+ if code.to_i / 100 != 2
72
+ raise("dog.get_all_downtimes() returns [%s, %s]" % [code.inspect, all_downtimes.inspect])
73
+ end
74
+ all_downtimes
75
+ end
76
+
77
+ def cancel_downtime(id, options={})
78
+ code, cancel = dog.cancel_downtime(id)
79
+ if code.to_i / 100 != 2
80
+ raise("dog.cancel_downtime(%s) returns [%s, %s]" % [id.inspect, code.inspect, cancel.inspect])
81
+ end
82
+ cancel
83
+ end
38
84
  end
39
85
  end
40
86
  end
@@ -80,7 +80,7 @@ module Hotdog
80
80
  else
81
81
  if 0 < tags.length
82
82
  fields = tags.map { |tag|
83
- tag_name, tag_value = split_tag(tag)
83
+ tag_name, _tag_value = split_tag(tag)
84
84
  tag_name
85
85
  }
86
86
  get_hosts_fields(host_ids, fields)
@@ -294,7 +294,7 @@ module Hotdog
294
294
  response = uri.open("User-Agent" => "hotdog/#{Hotdog::VERSION}") { |fp| fp.read }
295
295
  [name, MultiJson.load(response)]
296
296
  rescue OpenURI::HTTPError => error
297
- code, body = error.io.status
297
+ code, _body = error.io.status
298
298
  raise(RuntimeError.new("dog.get_#{name}() returns [#{code.inspect}, ...]"))
299
299
  end
300
300
  }]
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-21 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.35.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.35.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: dogapi
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +159,8 @@ extensions: []
145
159
  extra_rdoc_files: []
146
160
  files:
147
161
  - ".gitignore"
162
+ - ".rubocop.yml"
163
+ - ".rubocop_todo.yml"
148
164
  - ".travis.yml"
149
165
  - Gemfile
150
166
  - LICENSE.txt
@@ -214,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
230
  version: '0'
215
231
  requirements: []
216
232
  rubyforge_project:
217
- rubygems_version: 2.4.5.1
233
+ rubygems_version: 2.5.1
218
234
  signing_key:
219
235
  specification_version: 4
220
236
  summary: Yet another command-line tool for Datadog
@@ -240,3 +256,4 @@ test_files:
240
256
  - spec/parser/regexp_expression_spec.rb
241
257
  - spec/parser/string_expression_spec.rb
242
258
  - spec/spec_helper.rb
259
+ has_rdoc: