Class: TreasureData::Client
- Inherits:
-
Object
- Object
- TreasureData::Client
- Defined in:
- lib/td/client.rb,
lib/td/client/version.rb
Constant Summary collapse
- VERSION =
'0.8.70'
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Class Method Summary collapse
-
.authenticate(user, password, opts = {}) ⇒ Client
Instance of this class.
-
.server_status(opts = {}) ⇒ String
HTTP status code of server returns.
Instance Method Summary collapse
- #access_controls ⇒ Array<AccessControl>
- #account ⇒ Account
- #add_apikey(user) ⇒ true
- #add_user(name, org, email, password) ⇒ true
-
#apikey ⇒ String
API key.
- #bulk_import(name) ⇒ BulkImport
- #bulk_import_delete_part(name, part_name) ⇒ nil
- #bulk_import_error_records(name, &block) ⇒ Hash
- #bulk_import_upload_part(name, part_name, stream, size) ⇒ nil
- #bulk_imports ⇒ Array<BulkImport>
-
#bulk_load_create(name, database, table, job, opts = {}) ⇒ Object
name: String, database: String, table: String, job: BulkLoad -> BulkLoad.
-
#bulk_load_delete(name) ⇒ Object
name: String -> BulkLoad.
-
#bulk_load_guess(job) ⇒ Object
> BulkLoad::Job.
-
#bulk_load_history(name) ⇒ Object
name: String -> [Job].
-
#bulk_load_issue(database, table, job) ⇒ Object
> String.
-
#bulk_load_list ⇒ Object
nil -> [BulkLoad].
-
#bulk_load_preview(job) ⇒ Object
> BulkLoad::Job.
- #bulk_load_run(name, scheduled_time = nil) ⇒ Object
-
#bulk_load_show(name) ⇒ Object
name: String -> BulkLoad.
-
#bulk_load_update(name, job) ⇒ Object
name: String, job: BulkLoad -> BulkLoad.
- #change_email(user, email) ⇒ true
- #change_my_password(old_password, password) ⇒ true
- #change_password(user, password) ⇒ true
- #commit_bulk_import(name) ⇒ nil
-
#core_utilization(from, to) ⇒ Array
From, to, interval, history.
- #create_bulk_import(name, database, table, opts = {}) ⇒ nil
- #create_database(db_name, opts = {}) ⇒ true
- #create_item_table(db_name, table_name, primary_key, primary_key_type) ⇒ true
- #create_log_table(db_name, table_name) ⇒ true
- #create_result(name, url, opts = {}) ⇒ true
- #create_schedule(name, opts) ⇒ Time
- #database(db_name) ⇒ Database
-
#databases ⇒ Array
Databases.
- #delete_bulk_import(name) ⇒ nil
- #delete_database(db_name) ⇒ Symbol
- #delete_result(name) ⇒ true
- #delete_schedule(name) ⇒ Array
- #delete_table(db_name, table_name) ⇒ Symbol
- #export(db_name, table_name, storage_type, opts = {}) ⇒ Job
- #freeze_bulk_import(name) ⇒ nil
- #grant_access_control(subject, action, scope, grant_option) ⇒ true
- #history(name, from = nil, to = nil) ⇒ Array<ScheduledJob>
- #import(db_name, table_name, format, stream, size, unique_id = nil) ⇒ Float
-
#initialize(apikey, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #job(job_id) ⇒ Job
- #job_result(job_id) ⇒ Object
- #job_result_each(job_id, &block) ⇒ nil
- #job_result_each_with_compr_size(job_id, &block) ⇒ nil
- #job_result_format(job_id, format, io = nil, &block) ⇒ String
-
#job_status(job_id) ⇒ String
HTTP status code.
- #jobs(from = nil, to = nil, status = nil, conditions = nil) ⇒ Job
-
#kill(job_id) ⇒ String
Former_status.
- #list_apikeys(user) ⇒ Array<String>
- #list_bulk_import_parts(name) ⇒ Array
- #partial_delete(db_name, table_name, to, from, opts = {}) ⇒ Job
- #perform_bulk_import(name, opts = {}) ⇒ Job
- #query(db_name, q, result_url = nil, priority = nil, retry_limit = nil, opts = {}) ⇒ Job
- #remove_apikey(user, apikey) ⇒ true
- #remove_user(user) ⇒ true
- #results ⇒ Array<Result>
- #revoke_access_control(subject, action, scope) ⇒ true
- #run_schedule(name, time, num) ⇒ Array<ScheduledJob>
- #schedules ⇒ Array<Schedule>
-
#server_status ⇒ String
HTTP status code of server returns.
-
#swap_table(db_name, table_name1, table_name2) ⇒ true
Swap table names.
- #table(db_name, table_name) ⇒ Table
-
#tables(db_name) ⇒ Array
Tables.
- #tail(db_name, table_name, count, to = nil, from = nil, &block) ⇒ Array?
- #test_access_control(user, action, scope) ⇒ Array
- #unfreeze_bulk_import(name) ⇒ nil
- #update_expire(db_name, table_name, expire_days) ⇒ true
- #update_schedule(name, params) ⇒ nil
- #update_schema(db_name, table_name, schema) ⇒ true
- #users ⇒ Array<User>
Constructor Details
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
32 33 34 |
# File 'lib/td/client.rb', line 32 def api @api end |
Class Method Details
Instance Method Details
#access_controls ⇒ Array<AccessControl>
522 523 524 525 526 527 |
# File 'lib/td/client.rb', line 522 def access_controls list = @api.list_access_controls list.map {|subject,action,scope,grant_option| AccessControl.new(self, subject, action, scope, grant_option) } end |
#account ⇒ Account
58 59 60 61 |
# File 'lib/td/client.rb', line 58 def account account_id, plan, storage, guaranteed_cores, maximum_cores, created_at = @api.show_account return Account.new(self, account_id, plan, storage, guaranteed_cores, maximum_cores, created_at) end |
#add_apikey(user) ⇒ true
496 497 498 |
# File 'lib/td/client.rb', line 496 def add_apikey(user) @api.add_apikey(user) end |
#add_user(name, org, email, password) ⇒ true
471 472 473 |
# File 'lib/td/client.rb', line 471 def add_user(name, org, email, password) @api.add_user(name, org, email, password) end |
#apikey ⇒ String
Returns API key.
35 36 37 |
# File 'lib/td/client.rb', line 35 def apikey @api.apikey end |
#bulk_import(name) ⇒ BulkImport
325 326 327 328 |
# File 'lib/td/client.rb', line 325 def bulk_import(name) data = @api.show_bulk_import(name) BulkImport.new(self, data) end |
#bulk_import_delete_part(name, part_name) ⇒ nil
349 350 351 |
# File 'lib/td/client.rb', line 349 def bulk_import_delete_part(name, part_name) @api.bulk_import_delete_part(name, part_name) end |
#bulk_import_error_records(name, &block) ⇒ Hash
319 320 321 |
# File 'lib/td/client.rb', line 319 def bulk_import_error_records(name, &block) @api.bulk_import_error_records(name, &block) end |
#bulk_import_upload_part(name, part_name, stream, size) ⇒ nil
342 343 344 |
# File 'lib/td/client.rb', line 342 def bulk_import_upload_part(name, part_name, stream, size) @api.bulk_import_upload_part(name, part_name, stream, size) end |
#bulk_imports ⇒ Array<BulkImport>
331 332 333 334 335 |
# File 'lib/td/client.rb', line 331 def bulk_imports @api.list_bulk_imports.map {|data| BulkImport.new(self, data) } end |
#bulk_load_create(name, database, table, job, opts = {}) ⇒ Object
name: String, database: String, table: String, job: BulkLoad -> BulkLoad
575 576 577 |
# File 'lib/td/client.rb', line 575 def bulk_load_create(name, database, table, job, opts = {}) @api.bulk_load_create(name, database, table, job, opts) end |
#bulk_load_delete(name) ⇒ Object
name: String -> BulkLoad
590 591 592 |
# File 'lib/td/client.rb', line 590 def bulk_load_delete(name) @api.bulk_load_delete(name) end |
#bulk_load_guess(job) ⇒ Object
> BulkLoad::Job
555 556 557 |
# File 'lib/td/client.rb', line 555 def bulk_load_guess(job) @api.bulk_load_guess(job) end |
#bulk_load_history(name) ⇒ Object
name: String -> [Job]
595 596 597 |
# File 'lib/td/client.rb', line 595 def bulk_load_history(name) @api.bulk_load_history(name) end |
#bulk_load_issue(database, table, job) ⇒ Object
> String
565 566 567 |
# File 'lib/td/client.rb', line 565 def bulk_load_issue(database, table, job) @api.bulk_load_issue(database, table, job) end |
#bulk_load_list ⇒ Object
nil -> [BulkLoad]
570 571 572 |
# File 'lib/td/client.rb', line 570 def bulk_load_list @api.bulk_load_list end |
#bulk_load_preview(job) ⇒ Object
> BulkLoad::Job
560 561 562 |
# File 'lib/td/client.rb', line 560 def bulk_load_preview(job) @api.bulk_load_preview(job) end |
#bulk_load_run(name, scheduled_time = nil) ⇒ Object
599 600 601 |
# File 'lib/td/client.rb', line 599 def bulk_load_run(name, scheduled_time = nil) @api.bulk_load_run(name, scheduled_time) end |
#bulk_load_show(name) ⇒ Object
name: String -> BulkLoad
580 581 582 |
# File 'lib/td/client.rb', line 580 def bulk_load_show(name) @api.bulk_load_show(name) end |
#bulk_load_update(name, job) ⇒ Object
name: String, job: BulkLoad -> BulkLoad
585 586 587 |
# File 'lib/td/client.rb', line 585 def bulk_load_update(name, job) @api.bulk_load_update(name, job) end |
#change_email(user, email) ⇒ true
484 485 486 |
# File 'lib/td/client.rb', line 484 def change_email(user, email) @api.change_email(user, email) end |
#change_my_password(old_password, password) ⇒ true
517 518 519 |
# File 'lib/td/client.rb', line 517 def change_my_password(old_password, password) @api.change_my_password(old_password, password) end |
#change_password(user, password) ⇒ true
510 511 512 |
# File 'lib/td/client.rb', line 510 def change_password(user, password) @api.change_password(user, password) end |
#commit_bulk_import(name) ⇒ nil
312 313 314 |
# File 'lib/td/client.rb', line 312 def commit_bulk_import(name) @api.commit_bulk_import(name) end |
#core_utilization(from, to) ⇒ Array
Returns from, to, interval, history.
66 67 68 69 |
# File 'lib/td/client.rb', line 66 def core_utilization(from, to) from, to, interval, history = @api.account_core_utilization(from, to) return from, to, interval, history end |
#create_bulk_import(name, database, table, opts = {}) ⇒ nil
280 281 282 |
# File 'lib/td/client.rb', line 280 def create_bulk_import(name, database, table, opts={}) @api.create_bulk_import(name, database, table, opts) end |
#create_database(db_name, opts = {}) ⇒ true
47 48 49 |
# File 'lib/td/client.rb', line 47 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) ⇒ true
101 102 103 |
# File 'lib/td/client.rb', line 101 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) ⇒ true
92 93 94 |
# File 'lib/td/client.rb', line 92 def create_log_table(db_name, table_name) @api.create_log_table(db_name, table_name) end |
#create_result(name, url, opts = {}) ⇒ true
448 449 450 |
# File 'lib/td/client.rb', line 448 def create_result(name, url, opts={}) @api.create_result(name, url, opts) end |
#create_schedule(name, opts) ⇒ Time
362 363 364 365 366 367 |
# File 'lib/td/client.rb', line 362 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) ⇒ Database
81 82 83 84 85 86 87 88 89 |
# File 'lib/td/client.rb', line 81 def database(db_name) m = @api.list_databases m.each {|name,(count, created_at, updated_at, org, )| if name == db_name return Database.new(self, name, nil, count, created_at, updated_at, org, ) end } raise NotFoundError, "Database '#{db_name}' does not exist" end |
#databases ⇒ Array
Returns databases.
72 73 74 75 76 77 |
# File 'lib/td/client.rb', line 72 def databases m = @api.list_databases m.map {|db_name,(count, created_at, updated_at, org, )| Database.new(self, db_name, nil, count, created_at, updated_at, org, ) } end |
#delete_bulk_import(name) ⇒ nil
286 287 288 |
# File 'lib/td/client.rb', line 286 def delete_bulk_import(name) @api.delete_bulk_import(name) end |
#delete_database(db_name) ⇒ Symbol
53 54 55 |
# File 'lib/td/client.rb', line 53 def delete_database(db_name) @api.delete_database(db_name) end |
#delete_result(name) ⇒ true
454 455 456 |
# File 'lib/td/client.rb', line 454 def delete_result(name) @api.delete_result(name) end |
#delete_schedule(name) ⇒ Array
371 372 373 |
# File 'lib/td/client.rb', line 371 def delete_schedule(name) @api.delete_schedule(name) end |
#delete_table(db_name, table_name) ⇒ Symbol
134 135 136 |
# File 'lib/td/client.rb', line 134 def delete_table(db_name, table_name) @api.delete_table(db_name, table_name) end |
#export(db_name, table_name, storage_type, opts = {}) ⇒ Job
259 260 261 262 |
# File 'lib/td/client.rb', line 259 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) ⇒ nil
292 293 294 |
# File 'lib/td/client.rb', line 292 def freeze_bulk_import(name) @api.freeze_bulk_import(name) end |
#grant_access_control(subject, action, scope, grant_option) ⇒ true
534 535 536 |
# File 'lib/td/client.rb', line 534 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) ⇒ Array<ScheduledJob>
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/td/client.rb', line 395 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| job_param = [job_id, type, query, status, nil, nil, # url, debug start_at, end_at, nil, # cpu_time nil, nil, # result_size, result result_url, nil, # hive_result_schema priority, nil, # retry_limit nil, # TODO org_name database] ScheduledJob.new(self, scheduled_at, *job_param) } end |
#import(db_name, table_name, format, stream, size, unique_id = nil) ⇒ Float
431 432 433 |
# File 'lib/td/client.rb', line 431 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) ⇒ Job
205 206 207 208 209 210 211 |
# File 'lib/td/client.rb', line 205 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
221 222 223 |
# File 'lib/td/client.rb', line 221 def job_result(job_id) @api.job_result(job_id) end |
#job_result_each(job_id, &block) ⇒ nil
237 238 239 |
# File 'lib/td/client.rb', line 237 def job_result_each(job_id, &block) @api.job_result_each(job_id, &block) end |
#job_result_each_with_compr_size(job_id, &block) ⇒ nil
244 245 246 |
# File 'lib/td/client.rb', line 244 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) ⇒ String
230 231 232 |
# File 'lib/td/client.rb', line 230 def job_result_format(job_id, format, io=nil, &block) @api.job_result_format(job_id, format, io, &block) end |
#job_status(job_id) ⇒ String
Returns HTTP status code.
215 216 217 |
# File 'lib/td/client.rb', line 215 def job_status(job_id) return @api.job_status(job_id) end |
#jobs(from = nil, to = nil, status = nil, conditions = nil) ⇒ Job
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/td/client.rb', line 192 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, duration| 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, duration) } end |
#kill(job_id) ⇒ String
Returns former_status.
250 251 252 |
# File 'lib/td/client.rb', line 250 def kill(job_id) @api.kill(job_id) end |
#list_apikeys(user) ⇒ Array<String>
490 491 492 |
# File 'lib/td/client.rb', line 490 def list_apikeys(user) @api.list_apikeys(user) end |
#list_bulk_import_parts(name) ⇒ Array
355 356 357 |
# File 'lib/td/client.rb', line 355 def list_bulk_import_parts(name) @api.list_bulk_import_parts(name) end |
#partial_delete(db_name, table_name, to, from, opts = {}) ⇒ Job
270 271 272 273 |
# File 'lib/td/client.rb', line 270 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, opts = {}) ⇒ Job
305 306 307 308 |
# File 'lib/td/client.rb', line 305 def perform_bulk_import(name, opts={}) job_id = @api.perform_bulk_import(name, opts) Job.new(self, job_id, :bulk_import, nil) end |
#query(db_name, q, result_url = nil, priority = nil, retry_limit = nil, opts = {}) ⇒ Job
179 180 181 182 183 184 185 |
# File 'lib/td/client.rb', line 179 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) ⇒ true
503 504 505 |
# File 'lib/td/client.rb', line 503 def remove_apikey(user, apikey) @api.remove_apikey(user, apikey) end |
#remove_user(user) ⇒ true
477 478 479 |
# File 'lib/td/client.rb', line 477 def remove_user(user) @api.remove_user(user) end |
#results ⇒ Array<Result>
436 437 438 439 440 441 442 |
# File 'lib/td/client.rb', line 436 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) ⇒ true
542 543 544 |
# File 'lib/td/client.rb', line 542 def revoke_access_control(subject, action, scope) @api.revoke_access_control(subject, action, scope) end |
#run_schedule(name, time, num) ⇒ Array<ScheduledJob>
417 418 419 420 421 422 |
# File 'lib/td/client.rb', line 417 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 |
#schedules ⇒ Array<Schedule>
376 377 378 379 380 381 |
# File 'lib/td/client.rb', line 376 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_status ⇒ String
Returns HTTP status code of server returns.
40 41 42 |
# File 'lib/td/client.rb', line 40 def server_status @api.server_status end |
#swap_table(db_name, table_name1, table_name2) ⇒ true
Swap table names
111 112 113 |
# File 'lib/td/client.rb', line 111 def swap_table(db_name, table_name1, table_name2) @api.swap_table(db_name, table_name1, table_name2) end |
#table(db_name, table_name) ⇒ Table
152 153 154 155 156 157 158 159 |
# File 'lib/td/client.rb', line 152 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) ⇒ Array
Returns Tables.
140 141 142 143 144 145 146 147 |
# File 'lib/td/client.rb', line 140 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, , 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, , expire_days, primary_key, primary_key_type) } end |
#tail(db_name, table_name, count, to = nil, from = nil, &block) ⇒ Array?
168 169 170 |
# File 'lib/td/client.rb', line 168 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) ⇒ Array
550 551 552 |
# File 'lib/td/client.rb', line 550 def test_access_control(user, action, scope) @api.test_access_control(user, action, scope) end |
#unfreeze_bulk_import(name) ⇒ nil
298 299 300 |
# File 'lib/td/client.rb', line 298 def unfreeze_bulk_import(name) @api.unfreeze_bulk_import(name) end |
#update_expire(db_name, table_name, expire_days) ⇒ true
127 128 129 |
# File 'lib/td/client.rb', line 127 def update_expire(db_name, table_name, expire_days) @api.update_expire(db_name, table_name, expire_days) end |
#update_schedule(name, params) ⇒ nil
386 387 388 389 |
# File 'lib/td/client.rb', line 386 def update_schedule(name, params) @api.update_schedule(name, params) nil end |
#update_schema(db_name, table_name, schema) ⇒ true
119 120 121 |
# File 'lib/td/client.rb', line 119 def update_schema(db_name, table_name, schema) @api.update_schema(db_name, table_name, schema.to_json) end |