td 0.11.3 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTZmYjMxNzU1OTk3MzQ0MzcyMGU5NzRhNzdkZjZhM2Q4ZTFlNDEyMw==
4
+ NTM4MDYwMmE3YThiODA3Njc0ZmVhMDA4ODY5Yjk5NmZiOWNiZDFhNQ==
5
5
  data.tar.gz: !binary |-
6
- NzFhNTY5YjIyNmRlYTUzNzk1YWIxY2Q1MzMxMzc1YjFhODkxZmY4ZA==
6
+ MzM2MDI0MjAxZjc0Mjk2M2QwZDEyYTM1Y2NmNzhlYzkyY2YyNDBmYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTZkZGQyMWFkYjcxMDE2NWI2ZWEwZTVjNDQ5ODQ4YzYxMjMwOTJmZTI1Njc4
10
- MGI4YWU1NzgzOTRmNjQ3ZDE5YjUxMTY2ZjhlMDM5Y2MxMmFjMWE4ZTEwNWM3
11
- ZmZlYzM5ODRmYTQ0MTE0ZmRkMmFmNTNmNGYyMDU5MDhjNzRhOGE=
9
+ MGQ3YWY3NTRhMDJmNzU4OWMwY2M2YmY0ODliZTAwM2E3MTIwZGVkYjUxNWVk
10
+ Y2ZiYjhiNDQxOGQ2YjExZTg0ZDU2NjRiZTQ4YTZmY2E1YTc2YWQzZDI0MGU3
11
+ ZWM1OGZhZGU1NzQ2NTgzNzYyOTQwZWFjNzdiYmE0M2E5ZGJlZDg=
12
12
  data.tar.gz: !binary |-
13
- OWI1OGZjYTE4ODBjZDc4YWFiMDJhZWNmYmVlNjg3OTdkODA4Y2FlMjkyMDY5
14
- OGY3M2M1N2QzYTMwMGFiZDhhM2RhZTQ3ODVkMjgxNWE0MGYzZjFhM2Y3Y2Ux
15
- OGZiYTU0ZTFiOWEyZGYzZTgyMmRmMTFhOTY0Mzc2ZDM4Y2NlN2Q=
13
+ MzRlMTE0NDdiNjE5YmMzNGEyN2MyZjRmNDgyNjIxYjU1MjllNTc2YjA5YmJh
14
+ OTQ4OTY2M2QxNjEzNDQ3NThjMTE2NzdiZjFhODU5NGJjY2U1YzNjOGRjYmY2
15
+ NDU1NDZlMzNkMTgwNDlhZDRhOWRhOGQ1Y2Y1OGE2NTliZTc5ZmI=
data/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ == 2014-09-25 version 0.11.4
2
+
3
+ * Expand file path containing wildcards and not escaped by the underlying shell
4
+ * Add a global '-r / --retry-post-requests' option to enable the td-client-ruby
5
+ retrying mechanism for post request.
6
+ Note: -r option must be right after 'td' before subcommands like: td -r query
7
+ WARNING: enabling this option can lead to unexpected results because the
8
+ retrying mechanism can caused the creation of duplicated resources since the
9
+ POST methods are not idempotent.
10
+
1
11
  == 2014-07-31 version 0.11.3
2
12
 
3
13
  * Support name updates for schedules using sched:update command
@@ -32,6 +32,9 @@ module Command
32
32
  unless opts.has_key?(:ssl)
33
33
  opts[:ssl] = Config.secure
34
34
  end
35
+ unless opts.has_key?(:retry_post_requests)
36
+ opts[:retry_post_requests] = Config.retry_post_requests
37
+ end
35
38
 
36
39
  # apikey is mandatory
37
40
  apikey = Config.apikey
@@ -373,17 +376,23 @@ EOS
373
376
  end
374
377
 
375
378
  def update(curr_size)
376
- ratio = (curr_size.to_f * 100 / @size).round(1)
377
- if ratio >= (@last_perc_step + @perc_step) &&
378
- (!@min_periodicity || (time = Time.now.to_i) - @last_time >= @min_periodicity)
379
- msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)} / #{ratio}%"
380
- print "\r" + " " * (msg.length + 10)
379
+ if @size.nil? || @size == 0
380
+ msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)}"
381
381
  print msg
382
- @last_perc_step = ratio
383
- @last_time = time
384
382
  true
385
383
  else
386
- false
384
+ ratio = (curr_size.to_f * 100 / @size).round(1)
385
+ if ratio >= (@last_perc_step + @perc_step) &&
386
+ (!@min_periodicity || (time = Time.now.to_i) - @last_time >= @min_periodicity)
387
+ msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)} / #{ratio}%"
388
+ print "\r" + " " * (msg.length + 10)
389
+ print msg
390
+ @last_perc_step = ratio
391
+ @last_time = time
392
+ true
393
+ else
394
+ false
395
+ end
387
396
  end
388
397
  end
389
398
 
@@ -116,6 +116,9 @@ module Command
116
116
  render_opts[:vertical] = b
117
117
  }
118
118
  op.on('-o', '--output PATH', 'write result to the file') {|s|
119
+ unless Dir.exist?(File.dirname(s))
120
+ s = File.expand_path(s)
121
+ end
119
122
  output = s
120
123
  format = 'tsv' if format.nil?
121
124
  }
@@ -190,14 +193,34 @@ module Command
190
193
  end
191
194
  end
192
195
 
196
+ # up to 7 retries with exponential (base 2) back-off starting at 'retry_delay'
197
+ retry_delay = 5
198
+ max_cumul_retry_delay = 200
199
+ cumul_retry_delay = 0
200
+
193
201
  if wait && !job.finished?
194
202
  wait_job(job)
195
203
  if [:hive, :pig, :impala, :presto].include?(job.type) && !exclude
196
204
  puts "Result :"
205
+
197
206
  begin
198
207
  show_result(job, output, limit, format, render_opts)
199
208
  rescue TreasureData::NotFoundError => e
200
209
  # Got 404 because result not found.
210
+ rescue TreasureData::APIError, # HTTP status code 500 or more
211
+ Errno::ECONNREFUSED, Errno::ECONNRESET, Timeout::Error, EOFError => e
212
+ # don't retry on 300 and 400 errors
213
+ if e.class == TreasureData::APIError && e.message !~ /^5\d\d:\s+/
214
+ raise e
215
+ end
216
+ if cumul_retry_delay > max_cumul_retry_delay
217
+ raise e
218
+ end
219
+ $stderr.puts "Error #{e.class}: #{e.message}. Retrying after #{retry_delay} seconds..."
220
+ sleep retry_delay
221
+ cumul_retry_delay += retry_delay
222
+ retry_delay *= 2
223
+ retry
201
224
  end
202
225
  end
203
226
 
@@ -208,6 +231,20 @@ module Command
208
231
  show_result(job, output, limit, format, render_opts)
209
232
  rescue TreasureData::NotFoundError => e
210
233
  # Got 404 because result not found.
234
+ rescue TreasureData::APIError,
235
+ Errno::ECONNREFUSED, Errno::ECONNRESET, Timeout::Error, EOFError => e
236
+ # don't retry on 300 and 400 errors
237
+ if e.class == TreasureData::APIError && e.message !~ /^5\d\d:\s+/
238
+ raise e
239
+ end
240
+ if cumul_retry_delay > max_cumul_retry_delay
241
+ raise e
242
+ end
243
+ $stderr.puts "Error #{e.class}: #{e.message}. Retrying after #{retry_delay} seconds..."
244
+ sleep retry_delay
245
+ cumul_retry_delay += retry_delay
246
+ retry_delay *= 2
247
+ retry
211
248
  end
212
249
  end
213
250
 
@@ -229,7 +266,7 @@ module Command
229
266
  end
230
267
  end
231
268
 
232
- puts "Use '-v' option to show detailed messages." unless verbose
269
+ puts "\rUse '-v' option to show detailed messages." + " " * 20 unless verbose
233
270
  end
234
271
 
235
272
  def job_status(op)
@@ -303,7 +303,7 @@ module List
303
303
  add_list 'user:apikey:list', %w[name], 'Show API keys of an user'
304
304
  add_list 'user:apikey:add', %w[name], 'Add an API key to an user'
305
305
  add_list 'user:apikey:remove', %w[name apikey], 'Remove an API key from an user'
306
- add_list 'user:password:change', %w[name], 'Change password'
306
+ add_list 'user:password:change', %w[name], 'Change password for any user (must be an Administrator)'
307
307
 
308
308
  add_list 'acl:list', %w[], 'Show list of access controls'
309
309
  add_list 'acl:grant', %w[subject action scope], 'Grant an access control'
@@ -1,4 +1,3 @@
1
-
2
1
  module TreasureData
3
2
  module Command
4
3
 
@@ -28,6 +27,9 @@ module Command
28
27
  render_opts[:vertical] = b
29
28
  }
30
29
  op.on('-o', '--output PATH', 'write result to the file') {|s|
30
+ unless Dir.exist?(File.dirname(s))
31
+ s = File.expand_path(s)
32
+ end
31
33
  output = s
32
34
  format = 'tsv' if format.nil?
33
35
  }
@@ -74,6 +74,7 @@ EOF
74
74
  insecure = nil
75
75
  $verbose = false
76
76
  #$debug = false
77
+ retry_post_requests = false
77
78
 
78
79
  op.on('-c', '--config PATH', "path to the configuration file (default: ~/.td/td.conf)") {|s|
79
80
  config_path = s
@@ -107,6 +108,12 @@ EOF
107
108
  return usage nil
108
109
  }
109
110
 
111
+ op.on('-r', '--retry-post-requests', "retry on failed post requests.",
112
+ "Warning: can cause resource duplication, such as duplicated job submissions.",
113
+ TrueClass) {|b|
114
+ retry_post_requests = b
115
+ }
116
+
110
117
  op.on('--version', "show version") {
111
118
  puts op.version
112
119
  return 0
@@ -134,6 +141,9 @@ EOF
134
141
  if insecure
135
142
  Config.secure = false
136
143
  end
144
+ if retry_post_requests
145
+ Config.retry_post_requests = true
146
+ end
137
147
  rescue
138
148
  return usage $!.to_s
139
149
  end
@@ -349,7 +349,9 @@ module Command
349
349
  to = nil
350
350
  wait = false
351
351
 
352
- op.on('-t', '--to TIME', 'end time of logs to delete in Unix time multiple of 3600 (1 hour)') {|s|
352
+ op.on('-t', '--to TIME', 'end time of logs to delete in Unix time multiple of 3600 (1 hour)',
353
+ ' or Ruby time string format (e.g. \'2014-07-01 14:00:00 JST\') where',
354
+ ' the minutes and seconds are required to be 0.') {|s|
353
355
  if s.to_i.to_s == s
354
356
  # UNIX time
355
357
  to = s.to_i
@@ -358,7 +360,9 @@ module Command
358
360
  to = Time.parse(s).to_i
359
361
  end
360
362
  }
361
- op.on('-f', '--from TIME', 'start time of logs to delete in Unix time multiple of 3600 (1 hour)') {|s|
363
+ op.on('-f', '--from TIME', 'start time of logs to delete in Unix time multiple of 3600 (1 hour)',
364
+ ' or Ruby time string format (e.g. \'2014-07-01 13:00:00 JST\') where',
365
+ ' the minutes and seconds are required to be 0.') {|s|
362
366
  if s.to_i.to_s == s
363
367
  from = s.to_i
364
368
  else
@@ -383,7 +387,8 @@ module Command
383
387
  end
384
388
 
385
389
  if from % 3600 != 0 || to % 3600 != 0
386
- $stderr.puts "Time for the -f / --from and -t / --to options must be a multiple of 3600 (1 hour)"
390
+ $stderr.puts "Time for the -f / --from and -t / --to options must either be a multiple of 3600 (1 hour)\n" +
391
+ " or be expressed in Ruby time string format where the minutes and seconds are 0"
387
392
  exit 1
388
393
  end
389
394
 
data/lib/td/config.rb CHANGED
@@ -22,6 +22,7 @@ class Config
22
22
  @@endpoint = nil if @@endpoint == ""
23
23
  @@cl_endpoint = false # flag to indicate whether an endpoint has been provided through the command-line
24
24
  @@secure = true
25
+ @@retry_post_requests = false
25
26
 
26
27
  def initialize
27
28
  @path = nil
@@ -117,6 +118,15 @@ class Config
117
118
  end
118
119
 
119
120
 
121
+ def self.retry_post_requests
122
+ @@retry_post_requests
123
+ end
124
+
125
+ def self.retry_post_requests=(retry_post_requests)
126
+ @@retry_post_requests = retry_post_requests
127
+ end
128
+
129
+
120
130
  def self.apikey
121
131
  @@apikey || Config.read['account.apikey']
122
132
  end
data/lib/td/updater.rb CHANGED
@@ -11,7 +11,7 @@ module Updater
11
11
 
12
12
  def self.raise_error(message)
13
13
  # TODO: Replace better Exception class
14
- raise RuntimeError.new(message)
14
+ raise Command::UpdateError, message
15
15
  end
16
16
 
17
17
  # copied from TreasureData::Helpers to avoid load issue.
@@ -132,8 +132,7 @@ module Updater
132
132
  when Net::HTTPSuccess then response.body
133
133
  when Net::HTTPRedirection then fetch(response['Location'])
134
134
  else
135
- raise Command::UpdateError,
136
- "An error occurred when fetching from '#{url}'."
135
+ raise_error "An error occurred when fetching from '#{url}'."
137
136
  response.error!
138
137
  end
139
138
  end
@@ -290,9 +289,9 @@ module Updater
290
289
  end
291
290
  return stream_fetch(response['Location'], binfile, &progress)
292
291
  else
293
- raise Command::UpdateError,
294
- "An error occurred when fetching from '#{uri}' " +
295
- "(#{response.class.to_s}: #{response.message})."
292
+ raise_error
293
+ "An error occurred when fetching from '#{uri}' " +
294
+ "(#{response.class.to_s}: #{response.message})."
296
295
  return false
297
296
  end
298
297
  }
data/lib/td/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TreasureData
2
- TOOLBELT_VERSION = '0.11.3'
2
+ TOOLBELT_VERSION = '0.11.4'
3
3
  end
data/td.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "yajl-ruby", "~> 1.1"
22
22
  gem.add_dependency "hirb", ">= 0.4.5"
23
23
  gem.add_dependency "parallel", "~> 0.6.1"
24
- gem.add_dependency "td-client", "~> 0.8.63"
24
+ gem.add_dependency "td-client", "~> 0.8.64"
25
25
  gem.add_dependency "td-logger", "~> 0.3.21"
26
26
  gem.add_dependency "rubyzip", "~> 0.9.9"
27
27
  gem.add_development_dependency "rake", "~> 0.9"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Treasure Data, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -102,14 +102,14 @@ dependencies:
102
102
  requirements:
103
103
  - - ~>
104
104
  - !ruby/object:Gem::Version
105
- version: 0.8.63
105
+ version: 0.8.64
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ~>
111
111
  - !ruby/object:Gem::Version
112
- version: 0.8.63
112
+ version: 0.8.64
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: td-logger
115
115
  requirement: !ruby/object:Gem::Requirement