Class: TreasureData::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/td/client.rb,
lib/td/client/version.rb

Constant Summary collapse

VERSION =
'0.8.66'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey, opts = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
# File 'lib/td/client.rb', line 19

def initialize(apikey, opts={})
  @api = API.new(apikey, opts)
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



23
24
25
# File 'lib/td/client.rb', line 23

def api
  @api
end

Class Method Details

.authenticate(user, password, opts = {}) ⇒ Object



8
9
10
11
12
# File 'lib/td/client.rb', line 8

def self.authenticate(user, password, opts={})
  api = API.new(nil, opts)
  apikey = api.authenticate(user, password)
  new(apikey)
end

.server_status(opts = {}) ⇒ Object



14
15
16
17
# File 'lib/td/client.rb', line 14

def self.server_status(opts={})
  api = API.new(nil, opts)
  api.server_status
end

Instance Method Details

#access_controlsObject

> [User]



376
377
378
379
380
381
# File 'lib/td/client.rb', line 376

def access_controls
  list = @api.list_access_controls
  list.map {|subject,action,scope,grant_option|
    AccessControl.new(self, subject, action, scope, grant_option)
  }
end

#accountObject

> Account



44
45
46
47
# File 'lib/td/client.rb', line 44

def 
  , plan, storage, guaranteed_cores, maximum_cores, created_at = @api.
  return Account.new(self, , plan, storage, guaranteed_cores, maximum_cores, created_at)
end

#add_apikey(user) ⇒ Object

> true



356
357
358
# File 'lib/td/client.rb', line 356

def add_apikey(user)
  @api.add_apikey(user)
end

#add_user(name, org, email, password) ⇒ Object

> true



336
337
338
# File 'lib/td/client.rb', line 336

def add_user(name, org, email, password)
  @api.add_user(name, org, email, password)
end

#apikeyObject



25
26
27
# File 'lib/td/client.rb', line 25

def apikey
  @api.apikey
end

#bulk_import(name) ⇒ Object

> BulkImport



234
235
236
237
# File 'lib/td/client.rb', line 234

def bulk_import(name)
  data = @api.show_bulk_import(name)
  BulkImport.new(self, data)
end

#bulk_import_delete_part(name, part_name) ⇒ Object

> nil



252
253
254
# File 'lib/td/client.rb', line 252

def bulk_import_delete_part(name, part_name)
  @api.bulk_import_delete_part(name, part_name)
end

#bulk_import_error_records(name, &block) ⇒ Object



229
230
231
# File 'lib/td/client.rb', line 229

def bulk_import_error_records(name, &block)
  @api.bulk_import_error_records(name, &block)
end

#bulk_import_upload_part(name, part_name, stream, size) ⇒ Object

> nil



247
248
249
# File 'lib/td/client.rb', line 247

def bulk_import_upload_part(name, part_name, stream, size)
  @api.bulk_import_upload_part(name, part_name, stream, size)
end

#bulk_importsObject

> [BulkImport]



240
241
242
243
244
# File 'lib/td/client.rb', line 240

def bulk_imports
  @api.list_bulk_imports.map {|data|
    BulkImport.new(self, data)
  }
end

#change_email(user, email) ⇒ Object

> true



346
347
348
# File 'lib/td/client.rb', line 346

def change_email(user, email)
  @api.change_email(user, email)
end

#change_my_password(old_password, password) ⇒ Object

> true



371
372
373
# File 'lib/td/client.rb', line 371

def change_my_password(old_password, password)
  @api.change_my_password(old_password, password)
end

#change_password(user, password) ⇒ Object

> true



366
367
368
# File 'lib/td/client.rb', line 366

def change_password(user, password)
  @api.change_password(user, password)
end

#commit_bulk_import(name) ⇒ Object

> nil



224
225
226
# File 'lib/td/client.rb', line 224

def commit_bulk_import(name)
  @api.commit_bulk_import(name)
end

#core_utilization(from, to) ⇒ Object



49
50
51
52
# File 'lib/td/client.rb', line 49

def core_utilization(from, to)
  from, to, interval, history = @api.(from, to)
  return from, to, interval, history
end

#create_bulk_import(name, database, table, opts = {}) ⇒ Object

> nil



198
199
200
# File 'lib/td/client.rb', line 198

def create_bulk_import(name, database, table, opts={})
  @api.create_bulk_import(name, database, table, opts)
end

#create_database(db_name, opts = {}) ⇒ Object

> true



34
35
36
# File 'lib/td/client.rb', line 34

def create_database(db_name, opts={})
  @api.create_database(db_name, opts)
end

#create_item_table(db_name, table_name, primary_key, primary_key_type) ⇒ Object

> true



79
80
81
# File 'lib/td/client.rb', line 79

def create_item_table(db_name, table_name, primary_key, primary_key_type)
  @api.create_item_table(db_name, table_name, primary_key, primary_key_type)
end

#create_log_table(db_name, table_name) ⇒ Object

> true



74
75
76
# File 'lib/td/client.rb', line 74

def create_log_table(db_name, table_name)
  @api.create_log_table(db_name, table_name)
end

#create_result(name, url, opts = {}) ⇒ Object

> true



318
319
320
# File 'lib/td/client.rb', line 318

def create_result(name, url, opts={})
  @api.create_result(name, url, opts)
end

#create_schedule(name, opts) ⇒ Object

> first_time:Time

Raises:

  • (ArgumentError)


261
262
263
264
265
266
# File 'lib/td/client.rb', line 261

def create_schedule(name, opts)
  raise ArgumentError, "'cron' option is required" unless opts[:cron] || opts['cron']
  raise ArgumentError, "'query' option is required" unless opts[:query] || opts['query']
  start = @api.create_schedule(name, opts)
  return Time.parse(start)
end

#database(db_name) ⇒ Object

> Database

Raises:



63
64
65
66
67
68
69
70
71
# File 'lib/td/client.rb', line 63

def database(db_name)
  m = @api.list_databases
  m.each {|name,(count, created_at, updated_at, org, permission)|
    if name == db_name
      return Database.new(self, name, nil, count, created_at, updated_at, org, permission)
    end
  }
  raise NotFoundError, "Database '#{db_name}' does not exist"
end

#databasesObject

> [Database]



55
56
57
58
59
60
# File 'lib/td/client.rb', line 55

def databases
  m = @api.list_databases
  m.map {|db_name,(count, created_at, updated_at, org, permission)|
    Database.new(self, db_name, nil, count, created_at, updated_at, org, permission)
  }
end

#delete_bulk_import(name) ⇒ Object

> nil



203
204
205
# File 'lib/td/client.rb', line 203

def delete_bulk_import(name)
  @api.delete_bulk_import(name)
end

#delete_database(db_name) ⇒ Object

> true



39
40
41
# File 'lib/td/client.rb', line 39

def delete_database(db_name)
  @api.delete_database(db_name)
end

#delete_result(name) ⇒ Object

> true



323
324
325
# File 'lib/td/client.rb', line 323

def delete_result(name)
  @api.delete_result(name)
end

#delete_schedule(name) ⇒ Object

> true



269
270
271
# File 'lib/td/client.rb', line 269

def delete_schedule(name)
  @api.delete_schedule(name)
end

#delete_table(db_name, table_name) ⇒ Object

> type:Symbol



99
100
101
# File 'lib/td/client.rb', line 99

def delete_table(db_name, table_name)
  @api.delete_table(db_name, table_name)
end

#export(db_name, table_name, storage_type, opts = {}) ⇒ Object

> Job



186
187
188
189
# File 'lib/td/client.rb', line 186

def export(db_name, table_name, storage_type, opts={})
  job_id = @api.export(db_name, table_name, storage_type, opts)
  Job.new(self, job_id, :export, nil)
end

#freeze_bulk_import(name) ⇒ Object

> nil



208
209
210
# File 'lib/td/client.rb', line 208

def freeze_bulk_import(name)
  @api.freeze_bulk_import(name)
end

#grant_access_control(subject, action, scope, grant_option) ⇒ Object

> true



384
385
386
# File 'lib/td/client.rb', line 384

def grant_access_control(subject, action, scope, grant_option)
  @api.grant_access_control(subject, action, scope, grant_option)
end

#history(name, from = nil, to = nil) ⇒ Object

ScheduledJob


287
288
289
290
291
292
293
# File 'lib/td/client.rb', line 287

def history(name, from=nil, to=nil)
  result = @api.history(name, from, to)
  result.map {|scheduled_at,job_id,type,status,query,start_at,end_at,result_url,priority,database|
    # TODO org
    ScheduledJob.new(self, scheduled_at, job_id, type, query, status, nil, nil, start_at, end_at, nil, result_url, nil, priority, nil, nil, database)
  }
end

#import(db_name, table_name, format, stream, size, unique_id = nil) ⇒ Object

> time:Flaot



304
305
306
# File 'lib/td/client.rb', line 304

def import(db_name, table_name, format, stream, size, unique_id=nil)
  @api.import(db_name, table_name, format, stream, size, unique_id)
end

#job(job_id) ⇒ Object

> Job



147
148
149
150
151
152
153
# File 'lib/td/client.rb', line 147

def job(job_id)
  job_id = job_id.to_s
  type, query, status, url, debug, start_at, end_at, cpu_time,
    result_size, result_url, hive_result_schema, priority, retry_limit, org, db = @api.show_job(job_id)
  Job.new(self, job_id, type, query, status, url, debug, start_at, end_at, cpu_time,
          result_size, nil, result_url, hive_result_schema, priority, retry_limit, org, db)
end

#job_result(job_id) ⇒ Object



161
162
163
# File 'lib/td/client.rb', line 161

def job_result(job_id)
  @api.job_result(job_id)
end

#job_result_each(job_id, &block) ⇒ Object

> nil



171
172
173
# File 'lib/td/client.rb', line 171

def job_result_each(job_id, &block)
  @api.job_result_each(job_id, &block)
end

#job_result_each_with_compr_size(job_id, &block) ⇒ Object

> nil



176
177
178
# File 'lib/td/client.rb', line 176

def job_result_each_with_compr_size(job_id, &block)
  @api.job_result_each_with_compr_size(job_id, &block)
end

#job_result_format(job_id, format, io = nil, &block) ⇒ Object

> result:String



166
167
168
# File 'lib/td/client.rb', line 166

def job_result_format(job_id, format, io=nil, &block)
  @api.job_result_format(job_id, format, io, &block)
end

#job_status(job_id) ⇒ Object

> status:String



156
157
158
# File 'lib/td/client.rb', line 156

def job_status(job_id)
  return @api.job_status(job_id)
end

#jobs(from = nil, to = nil, status = nil, conditions = nil) ⇒ Object

> [Job]



137
138
139
140
141
142
143
144
# File 'lib/td/client.rb', line 137

def jobs(from=nil, to=nil, status=nil, conditions=nil)
  results = @api.list_jobs(from, to, status, conditions)
  results.map {|job_id, type, status, query, start_at, end_at, cpu_time,
               result_size, result_url, priority, retry_limit, org, db|
    Job.new(self, job_id, type, query, status, nil, nil, start_at, end_at, cpu_time,
            result_size, nil, result_url, nil, priority, retry_limit, org, db)
  }
end

#kill(job_id) ⇒ Object

> former_status:String



181
182
183
# File 'lib/td/client.rb', line 181

def kill(job_id)
  @api.kill(job_id)
end

#list_apikeys(user) ⇒ Object

> [apikey:String]



351
352
353
# File 'lib/td/client.rb', line 351

def list_apikeys(user)
  @api.list_apikeys(user)
end

#list_bulk_import_parts(name) ⇒ Object



256
257
258
# File 'lib/td/client.rb', line 256

def list_bulk_import_parts(name)
  @api.list_bulk_import_parts(name)
end

#partial_delete(db_name, table_name, to, from, opts = {}) ⇒ Object

> Job



192
193
194
195
# File 'lib/td/client.rb', line 192

def partial_delete(db_name, table_name, to, from, opts={})
  job_id = @api.partial_delete(db_name, table_name, to, from, opts)
  Job.new(self, job_id, :partialdelete, nil)
end

#perform_bulk_import(name) ⇒ Object

> Job



218
219
220
221
# File 'lib/td/client.rb', line 218

def perform_bulk_import(name)
  job_id = @api.perform_bulk_import(name)
  Job.new(self, job_id, :bulk_import, nil)
end

#query(db_name, q, result_url = nil, priority = nil, retry_limit = nil, opts = {}) ⇒ Object

> Job

Raises:

  • (ArgumentError)


128
129
130
131
132
133
134
# File 'lib/td/client.rb', line 128

def query(db_name, q, result_url=nil, priority=nil, retry_limit=nil, opts={})
  # for compatibility, assume type is hive unless specifically specified
  type = opts[:type] || opts['type'] || :hive
  raise ArgumentError, "The specified query type is not supported: #{type}" unless [:hive, :pig, :impala, :presto].include?(type)
  job_id = @api.query(q, type, db_name, result_url, priority, retry_limit, opts)
  Job.new(self, job_id, type, q)
end

#remove_apikey(user, apikey) ⇒ Object

> true



361
362
363
# File 'lib/td/client.rb', line 361

def remove_apikey(user, apikey)
  @api.remove_apikey(user, apikey)
end

#remove_user(user) ⇒ Object

> true



341
342
343
# File 'lib/td/client.rb', line 341

def remove_user(user)
  @api.remove_user(user)
end

#resultsObject

> [Result]



309
310
311
312
313
314
315
# File 'lib/td/client.rb', line 309

def results
  results = @api.list_result
  rs = results.map {|name,url,organizations|
    Result.new(self, name, url, organizations)
  }
  return rs
end

#revoke_access_control(subject, action, scope) ⇒ Object

> true



389
390
391
# File 'lib/td/client.rb', line 389

def revoke_access_control(subject, action, scope)
  @api.revoke_access_control(subject, action, scope)
end

#run_schedule(name, time, num) ⇒ Object

ScheduledJob


296
297
298
299
300
301
# File 'lib/td/client.rb', line 296

def run_schedule(name, time, num)
  results = @api.run_schedule(name, time, num)
  results.map {|job_id,type,scheduled_at|
    ScheduledJob.new(self, scheduled_at, job_id, type, nil)
  }
end

#schedulesObject

Schedule


274
275
276
277
278
279
# File 'lib/td/client.rb', line 274

def schedules
  result = @api.list_schedules
  result.map {|name,cron,query,database,result_url,timezone,delay,next_time,priority,retry_limit,org_name|
    Schedule.new(self, name, cron, query, database, result_url, timezone, delay, next_time, priority, retry_limit, org_name)
  }
end

#server_statusObject



29
30
31
# File 'lib/td/client.rb', line 29

def server_status
  @api.server_status
end

#swap_table(db_name, table_name1, table_name2) ⇒ Object

> true



84
85
86
# File 'lib/td/client.rb', line 84

def swap_table(db_name, table_name1, table_name2)
  @api.swap_table(db_name, table_name1, table_name2)
end

#table(db_name, table_name) ⇒ Object

> Table

Raises:



114
115
116
117
118
119
120
121
# File 'lib/td/client.rb', line 114

def table(db_name, table_name)
  tables(db_name).each {|t|
    if t.name == table_name
      return t
    end
  }
  raise NotFoundError, "Table '#{db_name}.#{table_name}' does not exist"
end

#tables(db_name) ⇒ Object

> [Table]



104
105
106
107
108
109
110
111
# File 'lib/td/client.rb', line 104

def tables(db_name)
  m = @api.list_tables(db_name)
  m.map {|table_name, (type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days, primary_key, primary_key_type)|
    schema = Schema.new.from_json(schema)
    Table.new(self, db_name, table_name, type, schema, count, created_at, updated_at,
      estimated_storage_size, last_import, last_log_timestamp, expire_days, primary_key, primary_key_type)
  }
end

#tail(db_name, table_name, count, to = nil, from = nil, &block) ⇒ Object



123
124
125
# File 'lib/td/client.rb', line 123

def tail(db_name, table_name, count, to=nil, from=nil, &block)
  @api.tail(db_name, table_name, count, to, from, &block)
end

#test_access_control(user, action, scope) ⇒ Object

> true



394
395
396
# File 'lib/td/client.rb', line 394

def test_access_control(user, action, scope)
  @api.test_access_control(user, action, scope)
end

#unfreeze_bulk_import(name) ⇒ Object

> nil



213
214
215
# File 'lib/td/client.rb', line 213

def unfreeze_bulk_import(name)
  @api.unfreeze_bulk_import(name)
end

#update_expire(db_name, table_name, expire_days) ⇒ Object

> true



94
95
96
# File 'lib/td/client.rb', line 94

def update_expire(db_name, table_name, expire_days)
  @api.update_expire(db_name, table_name, expire_days)
end

#update_schedule(name, params) ⇒ Object



281
282
283
284
# File 'lib/td/client.rb', line 281

def update_schedule(name, params)
  @api.update_schedule(name, params)
  nil
end

#update_schema(db_name, table_name, schema) ⇒ Object

> true



89
90
91
# File 'lib/td/client.rb', line 89

def update_schema(db_name, table_name, schema)
  @api.update_schema(db_name, table_name, schema.to_json)
end

#usersObject

> [User]



328
329
330
331
332
333
# File 'lib/td/client.rb', line 328

def users
  list = @api.list_users
  list.map {|name,org,roles,email|
    User.new(self, name, org, roles, email)
  }
end