td-client 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ == 2011-09-09 version 0.8.1
3
+
4
+ * Added Client#kill method
5
+ * Client.authenticate throws AuthError instead of APIError when
6
+ status code is 400
7
+
8
+
2
9
  == 2011-08-21 version 0.8.0
3
10
 
4
11
  * First release
@@ -141,6 +141,11 @@ class Client
141
141
  @api.job_result_each(job_id, &block)
142
142
  end
143
143
 
144
+ # => former_status:String
145
+ def kill(job_id)
146
+ @api.kill(job_id)
147
+ end
148
+
144
149
  # => time:Flaot
145
150
  def import(db_name, table_name, format, stream, size)
146
151
  @api.import(db_name, table_name, format, stream, size)
@@ -274,6 +274,17 @@ class API
274
274
  return body
275
275
  end
276
276
 
277
+ def kill(job_id)
278
+ code, body, res = post("/v3/job/kill/#{e job_id}")
279
+ if code != "200"
280
+ raise_error("Get job result failed", res)
281
+ end
282
+ # TODO format check
283
+ js = JSON.load(body)
284
+ former_status = js['former_status']
285
+ return former_status
286
+ end
287
+
277
288
  # => jobId:String
278
289
  def hive_query(q, db=nil)
279
290
  code, body, res = post("/v3/job/issue/hive/#{e db}", {'query'=>q})
@@ -311,7 +322,11 @@ class API
311
322
  def authenticate(user, password)
312
323
  code, body, res = post("/v3/user/authenticate", {'user'=>user, 'password'=>password})
313
324
  if code != "200"
314
- raise_error("Authentication failed", res)
325
+ if code == "400"
326
+ raise_error("Authentication failed", res, AuthError)
327
+ else
328
+ raise_error("Authentication failed", res)
329
+ end
315
330
  end
316
331
  # TODO format check
317
332
  js = JSON.load(body)
@@ -423,13 +438,15 @@ class API
423
438
  return http, header
424
439
  end
425
440
 
426
- def raise_error(msg, res)
441
+ def raise_error(msg, res, klass=nil)
427
442
  begin
428
443
  js = JSON.load(res.body)
429
444
  msg = js['message']
430
445
  error_code = js['error_code']
431
446
 
432
- if res.code == "404"
447
+ if klass
448
+ raise klass, "#{error_code}: #{msg}"
449
+ elsif res.code == "404"
433
450
  raise NotFoundError, "#{error_code}: #{msg}"
434
451
  elsif res.code == "409"
435
452
  raise AlreadyExistsError, "#{error_code}: #{msg}"
@@ -438,7 +455,9 @@ class API
438
455
  end
439
456
 
440
457
  rescue
441
- if res.code == "404"
458
+ if klass
459
+ raise klass, "#{error_code}: #{msg}"
460
+ elsif res.code == "404"
442
461
  raise NotFoundError, "#{msg}: #{res.body}"
443
462
  elsif res.code == "409"
444
463
  raise AlreadyExistsError, "#{msg}: #{res.body}"
@@ -126,6 +126,14 @@ class Schema
126
126
  end
127
127
 
128
128
  class Job < Model
129
+ STATUS_QUEUED = "queued"
130
+ STATUS_BOOTING = "booting"
131
+ STATUS_RUNNING = "running"
132
+ STATUS_SUCCESS = "success"
133
+ STATUS_ERROR = "error"
134
+ STATUS_KILLED = "killed"
135
+ FINISHED_STATUS = [STATUS_SUCCESS, STATUS_ERROR, STATUS_KILLED]
136
+
129
137
  def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=nil, result=nil)
130
138
  super(client)
131
139
  @job_id = job_id
@@ -145,6 +153,10 @@ class Job < Model
145
153
  # TODO
146
154
  end
147
155
 
156
+ def kill!
157
+ # TODO
158
+ end
159
+
148
160
  def query
149
161
  update_status! unless @query
150
162
  @query
@@ -199,7 +211,7 @@ class Job < Model
199
211
 
200
212
  def finished?
201
213
  update_status! unless @status
202
- if @status == "success" || @status == "error"
214
+ if FINISHED_STATUS.include?(@status)
203
215
  return true
204
216
  else
205
217
  return false
@@ -220,6 +232,11 @@ class Job < Model
220
232
  @status == "error"
221
233
  end
222
234
 
235
+ def killed?
236
+ update_status! unless @status
237
+ @status == "killed"
238
+ end
239
+
223
240
  def update_status!
224
241
  query, status, url, debug, start_at, end_at = @client.job_status(@job_id)
225
242
  @query = query
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sadayuki Furuhashi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-21 00:00:00 +09:00
18
+ date: 2011-09-09 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency