td-client 0.8.69 → 0.8.70
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/td/client.rb +7 -4
- data/lib/td/client/api/bulk_load.rb +22 -55
- data/lib/td/client/api/job.rb +3 -1
- data/lib/td/client/model.rb +5 -1
- data/lib/td/client/version.rb +1 -1
- data/spec/td/client/bulk_load_spec.rb +63 -45
- data/spec/td/client/job_api_spec.rb +3 -1
- data/spec/td/client/model_job_spec.rb +37 -0
- data/spec/td/client/spec_resources.rb +1 -0
- data/spec/td/client_spec.rb +45 -0
- metadata +6 -3
- data/lib/td/client/api/to_hash_struct.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ec9013fc056a1f4bcd364a56ca5d19c704884de
|
4
|
+
data.tar.gz: 0ec13bda51e5ea8f5d35573406bbe7386efaccb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 333b6b5e408515f0a0523d6c4057274232255e8c4da8904fa383eb69e7d78b5d679454317ff21efc0ebc0df0e870fdd99fe316a3a2880bbf24e3281602807260
|
7
|
+
data.tar.gz: 9f2fd6c88a7e8624aba8b89997cce43f1b88e08a3e364b5789367c823f95b10a99bfcc9787058716d68abeaa451ffe7e00f99f54b39321cf6e76fe9c23aff76f
|
data/lib/td/client.rb
CHANGED
@@ -192,9 +192,11 @@ class Client
|
|
192
192
|
def jobs(from=nil, to=nil, status=nil, conditions=nil)
|
193
193
|
results = @api.list_jobs(from, to, status, conditions)
|
194
194
|
results.map {|job_id, type, status, query, start_at, end_at, cpu_time,
|
195
|
-
result_size, result_url, priority, retry_limit, org, db
|
195
|
+
result_size, result_url, priority, retry_limit, org, db,
|
196
|
+
duration|
|
196
197
|
Job.new(self, job_id, type, query, status, nil, nil, start_at, end_at, cpu_time,
|
197
|
-
result_size, nil, result_url, nil, priority, retry_limit, org, db
|
198
|
+
result_size, nil, result_url, nil, priority, retry_limit, org, db,
|
199
|
+
duration)
|
198
200
|
}
|
199
201
|
end
|
200
202
|
|
@@ -298,9 +300,10 @@ class Client
|
|
298
300
|
end
|
299
301
|
|
300
302
|
# @param [String] name
|
303
|
+
# @param [Hash] opts options for API
|
301
304
|
# @return [Job]
|
302
|
-
def perform_bulk_import(name)
|
303
|
-
job_id = @api.perform_bulk_import(name)
|
305
|
+
def perform_bulk_import(name, opts={})
|
306
|
+
job_id = @api.perform_bulk_import(name, opts)
|
304
307
|
Job.new(self, job_id, :bulk_import, nil)
|
305
308
|
end
|
306
309
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'td/client/api/to_hash_struct'
|
2
|
-
|
3
1
|
class TreasureData::API
|
4
2
|
module BulkLoad
|
5
3
|
|
@@ -42,65 +40,40 @@ module BulkLoad
|
|
42
40
|
# "table": table_name
|
43
41
|
# }
|
44
42
|
|
45
|
-
## Resource definitions
|
46
|
-
|
47
|
-
class BulkLoad < ToHashStruct.new(:config, :name, :cron, :timezone, :delay, :time_column, :database, :table)
|
48
|
-
class BulkLoadSessionConfig < ToHashStruct.new(:type, :access_key_id, :secret_access_key, :endpoint, :bucket, :path_prefix, :parser, :decoders)
|
49
|
-
def validate_self
|
50
|
-
validate_presence_of :type
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
model_property :config, BulkLoadSessionConfig
|
55
|
-
|
56
|
-
def validate_self
|
57
|
-
validate_presence_of :config
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class BulkLoadPreview < ToHashStruct.new(:schema, :records)
|
62
|
-
end
|
63
|
-
|
64
|
-
class Job < ToHashStruct.new(:job_id, :account_id, :type, :status, :cpu_time, :config, :records, :schema, :database, :table, :priority, :created_at, :updated_at, :start_at, :end_at)
|
65
|
-
model_property :config, BulkLoad::BulkLoadSessionConfig
|
66
|
-
end
|
67
|
-
|
68
|
-
## API definitions
|
69
|
-
|
70
43
|
LIST = '/v3/bulk_loads'
|
71
44
|
SESSION = LIST + '/%s'
|
72
45
|
JOB = SESSION + '/jobs'
|
73
46
|
|
74
|
-
# job:
|
47
|
+
# job: Hash -> Hash
|
75
48
|
def bulk_load_guess(job)
|
76
49
|
# retry_request = true
|
77
50
|
path = LIST + '/guess'
|
78
|
-
res = api { post(path, job.
|
51
|
+
res = api { post(path, job.to_json) }
|
79
52
|
unless res.ok?
|
80
53
|
raise_error('BulkLoad configuration guess failed', res)
|
81
54
|
end
|
82
|
-
|
55
|
+
JSON.load(res.body)
|
83
56
|
end
|
84
57
|
|
85
|
-
# job:
|
58
|
+
# job: Hash -> Hash
|
86
59
|
def bulk_load_preview(job)
|
87
60
|
# retry_request = true
|
88
61
|
path = LIST + '/preview'
|
89
|
-
res = api { post(path, job.
|
62
|
+
res = api { post(path, job.to_json) }
|
90
63
|
unless res.ok?
|
91
64
|
raise_error('BulkLoad job preview failed', res)
|
92
65
|
end
|
93
|
-
|
66
|
+
JSON.load(res.body)
|
94
67
|
end
|
95
68
|
|
96
|
-
# job:
|
69
|
+
# job: Hash -> String (job_id)
|
97
70
|
def bulk_load_issue(database, table, job)
|
98
71
|
type = 'bulkload'
|
99
72
|
job = job.dup
|
100
73
|
job['database'] = database
|
101
74
|
job['table'] = table
|
102
75
|
path = "/v3/job/issue/#{e type}/#{e database}"
|
103
|
-
res = api { post(path, job.
|
76
|
+
res = api { post(path, job.to_json) }
|
104
77
|
unless res.ok?
|
105
78
|
raise_error('BulkLoad job issuing failed', res)
|
106
79
|
end
|
@@ -108,16 +81,16 @@ module BulkLoad
|
|
108
81
|
js['job_id'].to_s
|
109
82
|
end
|
110
83
|
|
111
|
-
# nil -> [
|
84
|
+
# nil -> [Hash]
|
112
85
|
def bulk_load_list
|
113
86
|
res = api { get(LIST) }
|
114
87
|
unless res.ok?
|
115
88
|
raise_error("BulkLoadSession list retrieve failed", res)
|
116
89
|
end
|
117
|
-
|
90
|
+
JSON.load(res.body)
|
118
91
|
end
|
119
92
|
|
120
|
-
# name: String, database: String, table: String, job:
|
93
|
+
# name: String, database: String, table: String, job: Hash -> Hash
|
121
94
|
def bulk_load_create(name, database, table, job, opts = {})
|
122
95
|
job = job.dup
|
123
96
|
job['name'] = name
|
@@ -126,51 +99,51 @@ module BulkLoad
|
|
126
99
|
end
|
127
100
|
job['database'] = database
|
128
101
|
job['table'] = table
|
129
|
-
res = api { post(LIST, job.
|
102
|
+
res = api { post(LIST, job.to_json) }
|
130
103
|
unless res.ok?
|
131
104
|
raise_error("BulkLoadSession: #{name} create failed", res)
|
132
105
|
end
|
133
|
-
|
106
|
+
JSON.load(res.body)
|
134
107
|
end
|
135
108
|
|
136
|
-
# name: String ->
|
109
|
+
# name: String -> Hash
|
137
110
|
def bulk_load_show(name)
|
138
111
|
path = session_path(name)
|
139
112
|
res = api { get(path) }
|
140
113
|
unless res.ok?
|
141
114
|
raise_error("BulkLoadSession: #{name} retrieve failed", res)
|
142
115
|
end
|
143
|
-
|
116
|
+
JSON.load(res.body)
|
144
117
|
end
|
145
118
|
|
146
|
-
# name: String, job:
|
119
|
+
# name: String, job: Hash -> Hash
|
147
120
|
def bulk_load_update(name, job)
|
148
121
|
path = session_path(name)
|
149
|
-
res = api { put(path, job.
|
122
|
+
res = api { put(path, job.to_json) }
|
150
123
|
unless res.ok?
|
151
124
|
raise_error("BulkLoadSession: #{name} update failed", res)
|
152
125
|
end
|
153
|
-
|
126
|
+
JSON.load(res.body)
|
154
127
|
end
|
155
128
|
|
156
|
-
# name: String ->
|
129
|
+
# name: String -> Hash
|
157
130
|
def bulk_load_delete(name)
|
158
131
|
path = session_path(name)
|
159
132
|
res = api { delete(path) }
|
160
133
|
unless res.ok?
|
161
134
|
raise_error("BulkLoadSession: #{name} delete failed", res)
|
162
135
|
end
|
163
|
-
|
136
|
+
JSON.load(res.body)
|
164
137
|
end
|
165
138
|
|
166
|
-
# name: String -> [
|
139
|
+
# name: String -> [Hash]
|
167
140
|
def bulk_load_history(name)
|
168
141
|
path = job_path(name)
|
169
142
|
res = api { get(path) }
|
170
143
|
unless res.ok?
|
171
144
|
raise_error("history of BulkLoadSession: #{name} retrieve failed", res)
|
172
145
|
end
|
173
|
-
|
146
|
+
JSON.load(res.body)
|
174
147
|
end
|
175
148
|
|
176
149
|
def bulk_load_run(name, scheduled_time = nil)
|
@@ -195,11 +168,5 @@ private
|
|
195
168
|
JOB % e(name)
|
196
169
|
end
|
197
170
|
|
198
|
-
def to_ary(res, klass)
|
199
|
-
JSON.parse(res.body).map { |bulk_load|
|
200
|
-
klass.from_hash(bulk_load)
|
201
|
-
}
|
202
|
-
end
|
203
|
-
|
204
171
|
end
|
205
172
|
end
|
data/lib/td/client/api/job.rb
CHANGED
@@ -35,8 +35,10 @@ module Job
|
|
35
35
|
result_url = m['result']
|
36
36
|
priority = m['priority']
|
37
37
|
retry_limit = m['retry_limit']
|
38
|
+
duration = m['duration']
|
38
39
|
result << [job_id, type, status, query, start_at, end_at, cpu_time,
|
39
|
-
result_size, result_url, priority, retry_limit, nil, database
|
40
|
+
result_size, result_url, priority, retry_limit, nil, database,
|
41
|
+
duration]
|
40
42
|
}
|
41
43
|
return result
|
42
44
|
end
|
data/lib/td/client/model.rb
CHANGED
@@ -381,9 +381,10 @@ class Job < Model
|
|
381
381
|
# @param [Fixnum] retry_limit
|
382
382
|
# @param [String] org_name
|
383
383
|
# @param [String] db_name
|
384
|
+
# @param [Fixnum] duration
|
384
385
|
def initialize(client, job_id, type, query, status=nil, url=nil, debug=nil, start_at=nil, end_at=nil, cpu_time=nil,
|
385
386
|
result_size=nil, result=nil, result_url=nil, hive_result_schema=nil, priority=nil, retry_limit=nil,
|
386
|
-
org_name=nil, db_name=nil)
|
387
|
+
org_name=nil, db_name=nil, duration=nil)
|
387
388
|
super(client)
|
388
389
|
@job_id = job_id
|
389
390
|
@type = type
|
@@ -401,6 +402,7 @@ class Job < Model
|
|
401
402
|
@priority = priority
|
402
403
|
@retry_limit = retry_limit
|
403
404
|
@db_name = db_name
|
405
|
+
@duration = duration
|
404
406
|
end
|
405
407
|
|
406
408
|
# @!attribute [r] job_id
|
@@ -410,8 +412,10 @@ class Job < Model
|
|
410
412
|
# @!attribute [r] retry_limit
|
411
413
|
# @!attribute [r] org_name
|
412
414
|
# @!attribute [r] db_name
|
415
|
+
# @!attribute [r] duration
|
413
416
|
attr_reader :job_id, :type, :result_url
|
414
417
|
attr_reader :priority, :retry_limit, :org_name, :db_name
|
418
|
+
attr_reader :duration
|
415
419
|
|
416
420
|
def wait(timeout=nil)
|
417
421
|
# TODO
|
data/lib/td/client/version.rb
CHANGED
@@ -114,8 +114,8 @@ describe 'BulkImport API' do
|
|
114
114
|
with(:body => original_config.to_json).
|
115
115
|
to_return(:body => guessed_config.to_json)
|
116
116
|
api.bulk_load_guess(
|
117
|
-
|
118
|
-
).
|
117
|
+
original_config
|
118
|
+
).should == guessed_config
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'raises an error' do
|
@@ -124,24 +124,56 @@ describe 'BulkImport API' do
|
|
124
124
|
to_return(:status => 500, :body => guessed_config.to_json)
|
125
125
|
expect {
|
126
126
|
api.bulk_load_guess(
|
127
|
-
|
127
|
+
original_config
|
128
128
|
)
|
129
129
|
}.to raise_error(TreasureData::APIError)
|
130
130
|
end
|
131
131
|
|
132
|
-
it '
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
it 'perform redo on 500 error' do
|
133
|
+
stub_api_request(:post, '/v3/bulk_loads/guess').
|
134
|
+
with(:body => original_config.to_json).
|
135
|
+
to_return(:status => 500, :body => guessed_config.to_json)
|
136
|
+
begin
|
137
|
+
retry_api.bulk_load_guess(
|
138
|
+
original_config
|
139
|
+
).should != nil
|
140
|
+
rescue TreasureData::APIError => e
|
141
|
+
e.message.should =~ /^500: BulkLoad configuration guess failed/
|
142
|
+
end
|
137
143
|
end
|
138
144
|
|
139
|
-
it '
|
140
|
-
|
141
|
-
|
145
|
+
it 'perform retries on connection failure' do
|
146
|
+
api = retry_api
|
147
|
+
api.instance_eval { @api }.stub(:post).and_raise(SocketError.new('>>'))
|
148
|
+
begin
|
149
|
+
retry_api.bulk_load_guess(
|
150
|
+
original_config
|
151
|
+
)
|
152
|
+
rescue SocketError => e
|
153
|
+
e.message.should == '>> (Retried 1 times in 1 seconds)'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'guess with old format' do
|
159
|
+
it 'returns guessed json' do
|
160
|
+
stub_api_request(:post, '/v3/bulk_loads/guess').
|
161
|
+
with(:body => original_config.to_json).
|
162
|
+
to_return(:body => guessed_config.to_json)
|
163
|
+
api.bulk_load_guess(
|
164
|
+
original_config
|
165
|
+
).should == guessed_config
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'raises an error' do
|
169
|
+
stub_api_request(:post, '/v3/bulk_loads/guess').
|
170
|
+
with(:body => original_config.to_json).
|
171
|
+
to_return(:status => 500, :body => guessed_config.to_json)
|
142
172
|
expect {
|
143
|
-
api.bulk_load_guess(
|
144
|
-
|
173
|
+
api.bulk_load_guess(
|
174
|
+
original_config
|
175
|
+
)
|
176
|
+
}.to raise_error(TreasureData::APIError)
|
145
177
|
end
|
146
178
|
|
147
179
|
it 'perform redo on 500 error' do
|
@@ -150,7 +182,7 @@ describe 'BulkImport API' do
|
|
150
182
|
to_return(:status => 500, :body => guessed_config.to_json)
|
151
183
|
begin
|
152
184
|
retry_api.bulk_load_guess(
|
153
|
-
|
185
|
+
original_config
|
154
186
|
).should != nil
|
155
187
|
rescue TreasureData::APIError => e
|
156
188
|
e.message.should =~ /^500: BulkLoad configuration guess failed/
|
@@ -162,7 +194,7 @@ describe 'BulkImport API' do
|
|
162
194
|
api.instance_eval { @api }.stub(:post).and_raise(SocketError.new('>>'))
|
163
195
|
begin
|
164
196
|
retry_api.bulk_load_guess(
|
165
|
-
|
197
|
+
original_config
|
166
198
|
)
|
167
199
|
rescue SocketError => e
|
168
200
|
e.message.should == '>> (Retried 1 times in 1 seconds)'
|
@@ -176,8 +208,8 @@ describe 'BulkImport API' do
|
|
176
208
|
with(:body => guessed_config.to_json).
|
177
209
|
to_return(:body => preview_result.to_json)
|
178
210
|
api.bulk_load_preview(
|
179
|
-
|
180
|
-
).
|
211
|
+
guessed_config
|
212
|
+
).should == preview_result
|
181
213
|
end
|
182
214
|
|
183
215
|
it 'raises an error' do
|
@@ -186,17 +218,10 @@ describe 'BulkImport API' do
|
|
186
218
|
to_return(:status => 500, :body => preview_result.to_json)
|
187
219
|
expect {
|
188
220
|
api.bulk_load_preview(
|
189
|
-
|
221
|
+
guessed_config
|
190
222
|
)
|
191
223
|
}.to raise_error(TreasureData::APIError)
|
192
224
|
end
|
193
|
-
|
194
|
-
it 'raises on validation error' do
|
195
|
-
config = TreasureData::API::BulkLoad::BulkLoad.from_hash({})
|
196
|
-
expect {
|
197
|
-
api.bulk_load_preview(config)
|
198
|
-
}.to raise_error(ArgumentError)
|
199
|
-
end
|
200
225
|
end
|
201
226
|
|
202
227
|
describe 'issue' do
|
@@ -210,16 +235,9 @@ describe 'BulkImport API' do
|
|
210
235
|
api.bulk_load_issue(
|
211
236
|
'database',
|
212
237
|
'table',
|
213
|
-
|
238
|
+
guessed_config
|
214
239
|
).should == '12345'
|
215
240
|
end
|
216
|
-
|
217
|
-
it 'raises on validation error' do
|
218
|
-
config = TreasureData::API::BulkLoad::BulkLoad.from_hash({})
|
219
|
-
expect {
|
220
|
-
api.bulk_load_issue(config)
|
221
|
-
}.to raise_error(ArgumentError)
|
222
|
-
end
|
223
241
|
end
|
224
242
|
|
225
243
|
describe 'list' do
|
@@ -228,7 +246,7 @@ describe 'BulkImport API' do
|
|
228
246
|
to_return(:body => [bulk_load_session, bulk_load_session].to_json)
|
229
247
|
result = api.bulk_load_list
|
230
248
|
result.size.should == 2
|
231
|
-
result.first.
|
249
|
+
result.first.should == bulk_load_session
|
232
250
|
end
|
233
251
|
|
234
252
|
it 'returns empty' do
|
@@ -254,13 +272,13 @@ describe 'BulkImport API' do
|
|
254
272
|
'nahi_test_1',
|
255
273
|
'database',
|
256
274
|
'table',
|
257
|
-
|
275
|
+
guessed_config,
|
258
276
|
{
|
259
277
|
cron: '@daily',
|
260
278
|
timezone: 'Asia/Tokyo',
|
261
279
|
delay: 3600
|
262
280
|
}
|
263
|
-
).
|
281
|
+
).should == bulk_load_session
|
264
282
|
end
|
265
283
|
|
266
284
|
it 'accepts empty option' do
|
@@ -275,8 +293,8 @@ describe 'BulkImport API' do
|
|
275
293
|
'nahi_test_1',
|
276
294
|
'database',
|
277
295
|
'table',
|
278
|
-
|
279
|
-
).
|
296
|
+
guessed_config
|
297
|
+
).should == bulk_load_session
|
280
298
|
end
|
281
299
|
|
282
300
|
it 'accepts time_column option' do
|
@@ -292,11 +310,11 @@ describe 'BulkImport API' do
|
|
292
310
|
'nahi_test_1',
|
293
311
|
'database',
|
294
312
|
'table',
|
295
|
-
|
313
|
+
guessed_config,
|
296
314
|
{
|
297
315
|
time_column: 'c0'
|
298
316
|
}
|
299
|
-
).
|
317
|
+
).should == bulk_load_session
|
300
318
|
end
|
301
319
|
end
|
302
320
|
|
@@ -304,7 +322,7 @@ describe 'BulkImport API' do
|
|
304
322
|
it 'returns bulk_load_session' do
|
305
323
|
stub_api_request(:get, '/v3/bulk_loads/nahi_test_1').
|
306
324
|
to_return(:body => bulk_load_session.to_json)
|
307
|
-
api.bulk_load_show('nahi_test_1').
|
325
|
+
api.bulk_load_show('nahi_test_1').should == bulk_load_session
|
308
326
|
end
|
309
327
|
end
|
310
328
|
|
@@ -315,8 +333,8 @@ describe 'BulkImport API' do
|
|
315
333
|
to_return(:body => bulk_load_session.to_json)
|
316
334
|
api.bulk_load_update(
|
317
335
|
'nahi_test_1',
|
318
|
-
|
319
|
-
).
|
336
|
+
bulk_load_session
|
337
|
+
).should == bulk_load_session
|
320
338
|
end
|
321
339
|
end
|
322
340
|
|
@@ -324,7 +342,7 @@ describe 'BulkImport API' do
|
|
324
342
|
it 'returns updated bulk_load_session' do
|
325
343
|
stub_api_request(:delete, '/v3/bulk_loads/nahi_test_1').
|
326
344
|
to_return(:body => bulk_load_session.to_json)
|
327
|
-
api.bulk_load_delete('nahi_test_1').
|
345
|
+
api.bulk_load_delete('nahi_test_1').should == bulk_load_session
|
328
346
|
end
|
329
347
|
end
|
330
348
|
|
@@ -334,7 +352,7 @@ describe 'BulkImport API' do
|
|
334
352
|
to_return(:body => [bulk_load_job, bulk_load_job].to_json)
|
335
353
|
result = api.bulk_load_history('nahi_test_1')
|
336
354
|
result.size.should == 2
|
337
|
-
result.first.
|
355
|
+
result.first.should == bulk_load_job
|
338
356
|
end
|
339
357
|
end
|
340
358
|
|
@@ -30,7 +30,8 @@ describe 'Job API' do
|
|
30
30
|
|
31
31
|
jobs = api.list_jobs
|
32
32
|
jobs[i..i].map {|job_id, type, status, query, start_at, end_at, cpu_time,
|
33
|
-
result_size, result_url, priority, retry_limit, org, db
|
33
|
+
result_size, result_url, priority, retry_limit, org, db,
|
34
|
+
duration|
|
34
35
|
job_id.should == job['job_id']
|
35
36
|
type.should == job['type']
|
36
37
|
status.should == job['status']
|
@@ -44,6 +45,7 @@ describe 'Job API' do
|
|
44
45
|
retry_limit.should == job['retry_limit']
|
45
46
|
org.should == job['organization']
|
46
47
|
db.should == job['database']
|
48
|
+
duration.should == job['duration']
|
47
49
|
}
|
48
50
|
end
|
49
51
|
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'td/client/spec_resources'
|
3
|
+
|
4
|
+
describe 'Job Model' do
|
5
|
+
include_context 'spec symbols'
|
6
|
+
include_context 'common helper'
|
7
|
+
include_context 'job resources'
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_api_request(:post, "/v3/user/authenticate").
|
11
|
+
to_return(:body => {'apikey' => 'apikey'}.to_json)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#client' do
|
15
|
+
subject do
|
16
|
+
Job.new(client, *arguments).client
|
17
|
+
end
|
18
|
+
|
19
|
+
let :client do
|
20
|
+
Client.authenticate('user', 'password')
|
21
|
+
end
|
22
|
+
|
23
|
+
let :arguments do
|
24
|
+
job_attributes = raw_jobs.first
|
25
|
+
[
|
26
|
+
'job_id', 'type', 'query', 'status', 'url', 'debug',
|
27
|
+
'start_at', 'end_at', 'cpu_time', 'result_size', 'result', 'result_url',
|
28
|
+
'hive_result_schema', 'priority', 'retry_limit', 'org_name', 'db_name',
|
29
|
+
'duration'
|
30
|
+
].map {|name| job_attributes[name]}
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns Job object having client' do
|
34
|
+
expect(subject).to eq client
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'td/client/spec_resources'
|
3
|
+
|
4
|
+
describe 'Command' do
|
5
|
+
include_context 'spec symbols'
|
6
|
+
include_context 'common helper'
|
7
|
+
include_context 'job resources'
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_api_request(:post, "/v3/user/authenticate").
|
11
|
+
to_return(:body => {'apikey' => 'apikey'}.to_json)
|
12
|
+
end
|
13
|
+
|
14
|
+
let :client do
|
15
|
+
Client.authenticate('user', 'password')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#job' do
|
19
|
+
before do
|
20
|
+
stub_api_request(:get, "/v3/job/list").to_return(:body => {'jobs' => raw_jobs}.to_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'return jobs created with API result' do
|
24
|
+
jobs = client.jobs
|
25
|
+
|
26
|
+
expect(jobs).to be_kind_of Array
|
27
|
+
jobs.each.with_index do |job, i|
|
28
|
+
expect(job.job_id).to eq raw_jobs[i]['job_id']
|
29
|
+
expect(job.type).to eq raw_jobs[i]['type']
|
30
|
+
expect(job.status).to eq raw_jobs[i]['status']
|
31
|
+
expect(job.query).to eq raw_jobs[i]['query']
|
32
|
+
expect(job.start_at).to eq Time.parse(raw_jobs[i]['start_at'])
|
33
|
+
expect(job.end_at).to eq Time.parse(raw_jobs[i]['end_at'])
|
34
|
+
expect(job.cpu_time).to eq raw_jobs[i]['cpu_time']
|
35
|
+
expect(job.result_size).to eq raw_jobs[i]['result_size']
|
36
|
+
expect(job.result_url).to eq raw_jobs[i]['result_url']
|
37
|
+
expect(job.priority).to eq raw_jobs[i]['priority']
|
38
|
+
expect(job.retry_limit).to eq raw_jobs[i]['retry_limit']
|
39
|
+
expect(job.org_name).to eq raw_jobs[i]['organization']
|
40
|
+
expect(job.db_name).to eq raw_jobs[i]['database']
|
41
|
+
expect(job.duration).to eq raw_jobs[i]['duration']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.70
|
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: 2015-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -223,7 +223,6 @@ files:
|
|
223
223
|
- lib/td/client/api/schedule.rb
|
224
224
|
- lib/td/client/api/server_status.rb
|
225
225
|
- lib/td/client/api/table.rb
|
226
|
-
- lib/td/client/api/to_hash_struct.rb
|
227
226
|
- lib/td/client/api/user.rb
|
228
227
|
- lib/td/client/api_error.rb
|
229
228
|
- lib/td/client/compat_gzip_reader.rb
|
@@ -241,6 +240,7 @@ files:
|
|
241
240
|
- spec/td/client/export_api_spec.rb
|
242
241
|
- spec/td/client/import_api_spec.rb
|
243
242
|
- spec/td/client/job_api_spec.rb
|
243
|
+
- spec/td/client/model_job_spec.rb
|
244
244
|
- spec/td/client/partial_delete_api_spec.rb
|
245
245
|
- spec/td/client/result_api_spec.rb
|
246
246
|
- spec/td/client/sched_api_spec.rb
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- spec/td/client/table_api_spec.rb
|
250
250
|
- spec/td/client/user_api_spec.rb
|
251
251
|
- spec/td/client_sched_spec.rb
|
252
|
+
- spec/td/client_spec.rb
|
252
253
|
homepage: http://treasuredata.com/
|
253
254
|
licenses: []
|
254
255
|
metadata: {}
|
@@ -283,6 +284,7 @@ test_files:
|
|
283
284
|
- spec/td/client/export_api_spec.rb
|
284
285
|
- spec/td/client/import_api_spec.rb
|
285
286
|
- spec/td/client/job_api_spec.rb
|
287
|
+
- spec/td/client/model_job_spec.rb
|
286
288
|
- spec/td/client/partial_delete_api_spec.rb
|
287
289
|
- spec/td/client/result_api_spec.rb
|
288
290
|
- spec/td/client/sched_api_spec.rb
|
@@ -290,4 +292,5 @@ test_files:
|
|
290
292
|
- spec/td/client/table_api_spec.rb
|
291
293
|
- spec/td/client/user_api_spec.rb
|
292
294
|
- spec/td/client_sched_spec.rb
|
295
|
+
- spec/td/client_spec.rb
|
293
296
|
has_rdoc: false
|
@@ -1,82 +0,0 @@
|
|
1
|
-
class TreasureData::API
|
2
|
-
class ToHashStruct < Struct
|
3
|
-
module ClassModule
|
4
|
-
def parse_json(body)
|
5
|
-
begin
|
6
|
-
js = JSON.load(body)
|
7
|
-
rescue
|
8
|
-
raise "Unexpected API response: #{$!}"
|
9
|
-
end
|
10
|
-
unless js.is_a?(Hash)
|
11
|
-
raise "Unexpected API response: #{body}"
|
12
|
-
end
|
13
|
-
js
|
14
|
-
end
|
15
|
-
|
16
|
-
def from_json(json)
|
17
|
-
from_hash(parse_json(json))
|
18
|
-
end
|
19
|
-
|
20
|
-
def from_hash(hash)
|
21
|
-
return new if hash.nil?
|
22
|
-
new(*members.map { |sym|
|
23
|
-
v = hash[sym] || hash[sym.to_s]
|
24
|
-
model.key?(sym) ? model[sym].from_hash(v) : v
|
25
|
-
})
|
26
|
-
end
|
27
|
-
|
28
|
-
def model_property(key, klass)
|
29
|
-
model[key.to_sym] = klass
|
30
|
-
end
|
31
|
-
|
32
|
-
def model
|
33
|
-
@model ||= {}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
extend ClassModule
|
37
|
-
|
38
|
-
def to_h
|
39
|
-
self.class.members.inject({}) { |r, e|
|
40
|
-
v = obj_to_h(self[e])
|
41
|
-
r[e.to_s] = v unless v.nil?
|
42
|
-
r
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_json
|
47
|
-
to_h.to_json
|
48
|
-
end
|
49
|
-
|
50
|
-
def validate
|
51
|
-
validate_self
|
52
|
-
values.each do |v|
|
53
|
-
v.validate if v.is_a?(ToHashStruct)
|
54
|
-
end
|
55
|
-
self
|
56
|
-
end
|
57
|
-
|
58
|
-
def validate_self
|
59
|
-
# define as required
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def validate_presence_of(key)
|
65
|
-
unless self.send(key)
|
66
|
-
raise ArgumentError.new("#{key} required")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def obj_to_h(obj)
|
71
|
-
if obj.nil?
|
72
|
-
nil
|
73
|
-
elsif Array === obj
|
74
|
-
obj.map { |e| obj_to_h(e) }
|
75
|
-
elsif obj.respond_to?(:to_h)
|
76
|
-
obj.to_h
|
77
|
-
else
|
78
|
-
obj
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|