td 0.10.31 → 0.10.32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/lib/td/command/job.rb +37 -3
- data/lib/td/command/list.rb +1 -0
- data/lib/td/command/query.rb +9 -2
- data/lib/td/command/sched.rb +25 -5
- data/lib/td/command/table.rb +60 -3
- data/lib/td/version.rb +1 -1
- metadata +13 -13
data/ChangeLog
CHANGED
data/lib/td/command/job.rb
CHANGED
@@ -5,6 +5,27 @@ module Command
|
|
5
5
|
# TODO
|
6
6
|
JOB_WAIT_MAX_RETRY_COUNT_ON_NETWORK_ERROR = 10
|
7
7
|
|
8
|
+
PRIORITY_FORMAT_MAP = {
|
9
|
+
-2 => 'VERY LOW',
|
10
|
+
-1 => 'LOW',
|
11
|
+
0 => 'NORMAL',
|
12
|
+
1 => 'HIGH',
|
13
|
+
2 => 'VERY HIGH',
|
14
|
+
}
|
15
|
+
|
16
|
+
PRIORITY_PARSE_MAP = {
|
17
|
+
/\Avery[ _\-]?low\z/i => -2,
|
18
|
+
/\A-2\z/ => -2,
|
19
|
+
/\Alow\z/i => -1,
|
20
|
+
/\A-1\z/ => -1,
|
21
|
+
/\Anorm(?:al)?\z/i => 0,
|
22
|
+
/\A[\-\+]?0\z/ => 0,
|
23
|
+
/\Ahigh\z/i => 1,
|
24
|
+
/\A[\+]?1\z/ => 1,
|
25
|
+
/\Avery[ _\-]?high\z/i => 2,
|
26
|
+
/\A[\+]?2\z/ => 2,
|
27
|
+
}
|
28
|
+
|
8
29
|
def job_list(op)
|
9
30
|
page = 0
|
10
31
|
skip = 0
|
@@ -41,10 +62,11 @@ module Command
|
|
41
62
|
jobs.each {|job|
|
42
63
|
start = job.start_at
|
43
64
|
elapsed = cmd_format_elapsed(start, job.end_at)
|
44
|
-
|
65
|
+
priority = job_priority_name_of(job.priority)
|
66
|
+
rows << {:JobID => job.job_id, :Status => job.status, :Type => job.type, :Query => job.query.to_s, :Start => (start ? start.localtime : ''), :Elapsed => elapsed, :Priority => priority, :Result => job.result_url}
|
45
67
|
}
|
46
68
|
|
47
|
-
puts cmd_render_table(rows, :fields => [:JobID, :Status, :Start, :Elapsed
|
69
|
+
puts cmd_render_table(rows, :fields => [:JobID, :Status, :Start, :Elapsed, :Priority, :Result, :Type, :Query])
|
48
70
|
end
|
49
71
|
|
50
72
|
def job_show(op)
|
@@ -79,8 +101,9 @@ module Command
|
|
79
101
|
#puts "URL : #{job.url}"
|
80
102
|
puts "Status : #{job.status}"
|
81
103
|
puts "Type : #{job.type}"
|
104
|
+
puts "Priority : #{job_priority_name_of(job.priority)}"
|
105
|
+
puts "Result : #{job.result_url}"
|
82
106
|
puts "Query : #{job.query}"
|
83
|
-
puts "Result table : #{job.result_url}"
|
84
107
|
|
85
108
|
if wait && !job.finished?
|
86
109
|
wait_job(job)
|
@@ -248,6 +271,17 @@ module Command
|
|
248
271
|
|
249
272
|
puts cmd_render_table(rows, opts)
|
250
273
|
end
|
274
|
+
|
275
|
+
def job_priority_name_of(id)
|
276
|
+
PRIORITY_FORMAT_MAP[id] || 'NORMAL'
|
277
|
+
end
|
278
|
+
|
279
|
+
def job_priority_id_of(name)
|
280
|
+
PRIORITY_PARSE_MAP.each_pair {|pattern,id|
|
281
|
+
return id if pattern.match(name)
|
282
|
+
}
|
283
|
+
return nil
|
284
|
+
end
|
251
285
|
end
|
252
286
|
end
|
253
287
|
|
data/lib/td/command/list.rb
CHANGED
@@ -223,6 +223,7 @@ module List
|
|
223
223
|
add_list 'table:import', %w[db table files_], 'Parse and import files to a table', 'table:import example_db table1 --apache access.log', 'table:import example_db table1 --json -t time - < test.json'
|
224
224
|
add_list 'table:export', %w[db table], 'Dump logs in a table to the specified storage', 'table:export example_db table1 --s3-bucket mybucket -k KEY_ID -s SECRET_KEY'
|
225
225
|
add_list 'table:tail', %w[db table], 'Get recently imported logs', 'table:tail example_db table1', 'table:tail example_db table1 -t "2011-01-02 03:04:05" -n 30'
|
226
|
+
add_list 'table:partial_delete', %w[db table], 'Delete logs from the table within the specified time range', 'table:partial_delete example_db table1 --from 1341000000 --to 1341003600'
|
226
227
|
|
227
228
|
add_list 'bulk_import:list', %w[], 'List bulk import sessions', 'bulk_import:list'
|
228
229
|
add_list 'bulk_import:show', %w[name], 'Show list of uploaded parts', 'bulk_import:show'
|
data/lib/td/command/query.rb
CHANGED
@@ -10,6 +10,7 @@ module Command
|
|
10
10
|
result_url = nil
|
11
11
|
result_user = nil
|
12
12
|
result_ask_password = false
|
13
|
+
priority = nil
|
13
14
|
|
14
15
|
op.on('-d', '--database DB_NAME', 'use the database (required)') {|s|
|
15
16
|
db_name = s
|
@@ -35,6 +36,12 @@ module Command
|
|
35
36
|
op.on('-p', '--password', 'ask password for the result URL') {|s|
|
36
37
|
result_ask_password = true
|
37
38
|
}
|
39
|
+
op.on('-P', '--priority PRIORITY', 'set priority') {|s|
|
40
|
+
priority = job_priority_id_of(s)
|
41
|
+
unless priority
|
42
|
+
raise "unknown priority #{s.inspect} should be -2 (very-low), -1 (low), 0 (normal), 1 (high) or 2 (very-high)"
|
43
|
+
end
|
44
|
+
}
|
38
45
|
|
39
46
|
sql = op.cmd_parse
|
40
47
|
|
@@ -53,7 +60,7 @@ module Command
|
|
53
60
|
# local existance check
|
54
61
|
get_database(client, db_name)
|
55
62
|
|
56
|
-
job = client.query(db_name, sql, result_url)
|
63
|
+
job = client.query(db_name, sql, result_url, priority)
|
57
64
|
|
58
65
|
$stderr.puts "Job #{job.job_id} is queued."
|
59
66
|
$stderr.puts "Use '#{$prog} job:show #{job.job_id}' to show the status."
|
@@ -69,7 +76,7 @@ module Command
|
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
72
|
-
require 'td/command/job' # wait_job
|
79
|
+
require 'td/command/job' # wait_job, job_priority_id_of
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
data/lib/td/command/sched.rb
CHANGED
@@ -3,6 +3,8 @@ module TreasureData
|
|
3
3
|
module Command
|
4
4
|
|
5
5
|
def sched_list(op)
|
6
|
+
require 'td/command/job' # job_priority_name_of
|
7
|
+
|
6
8
|
op.cmd_parse
|
7
9
|
|
8
10
|
client = get_client
|
@@ -11,13 +13,13 @@ module Command
|
|
11
13
|
|
12
14
|
rows = []
|
13
15
|
scheds.each {|sched|
|
14
|
-
rows << {:Name => sched.name, :Cron => sched.cron, :Timezone => sched.timezone, :Delay => sched.delay, :Result => sched.result_url, :Database => sched.database, :Query => sched.query, :"Next schedule" => sched.next_time ? sched.next_time.localtime : nil }
|
16
|
+
rows << {:Name => sched.name, :Cron => sched.cron, :Timezone => sched.timezone, :Delay => sched.delay, :Priority => job_priority_name_of(sched.priority), :Result => sched.result_url, :Database => sched.database, :Query => sched.query, :"Next schedule" => sched.next_time ? sched.next_time.localtime : nil }
|
15
17
|
}
|
16
18
|
rows = rows.sort_by {|map|
|
17
19
|
map[:Name]
|
18
20
|
}
|
19
21
|
|
20
|
-
puts cmd_render_table(rows, :fields => [:Name, :Cron, :Timezone, :"Next schedule", :Delay, :Result, :Database, :Query], :max_width=>500)
|
22
|
+
puts cmd_render_table(rows, :fields => [:Name, :Cron, :Timezone, :"Next schedule", :Delay, :Priority, :Result, :Database, :Query], :max_width=>500)
|
21
23
|
end
|
22
24
|
|
23
25
|
def sched_create(op)
|
@@ -27,6 +29,7 @@ module Command
|
|
27
29
|
result_url = nil
|
28
30
|
result_user = nil
|
29
31
|
result_ask_password = false
|
32
|
+
priority = nil
|
30
33
|
|
31
34
|
op.on('-d', '--database DB_NAME', 'use the database (required)') {|s|
|
32
35
|
db_name = s
|
@@ -46,6 +49,12 @@ module Command
|
|
46
49
|
op.on('-p', '--password', 'ask password for the result URL') {|s|
|
47
50
|
result_ask_password = true
|
48
51
|
}
|
52
|
+
op.on('-P', '--priority PRIORITY', 'set priority') {|s|
|
53
|
+
priority = job_priority_id_of(s)
|
54
|
+
unless priority
|
55
|
+
raise "unknown priority #{s.inspect} should be -2 (very-low), -1 (low), 0 (normal), 1 (high) or 2 (very-high)"
|
56
|
+
end
|
57
|
+
}
|
49
58
|
|
50
59
|
name, cron, sql = op.cmd_parse
|
51
60
|
|
@@ -65,7 +74,7 @@ module Command
|
|
65
74
|
get_database(client, db_name)
|
66
75
|
|
67
76
|
begin
|
68
|
-
first_time = client.create_schedule(name, :cron=>cron, :query=>sql, :database=>db_name, :result=>result_url, :timezone=>timezone, :delay=>delay)
|
77
|
+
first_time = client.create_schedule(name, :cron=>cron, :query=>sql, :database=>db_name, :result=>result_url, :timezone=>timezone, :delay=>delay, :priority=>priority)
|
69
78
|
rescue AlreadyExistsError
|
70
79
|
cmd_debug_error $!
|
71
80
|
$stderr.puts "Schedule '#{name}' already exists."
|
@@ -99,6 +108,7 @@ module Command
|
|
99
108
|
result = nil
|
100
109
|
timezone = nil
|
101
110
|
delay = nil
|
111
|
+
priority = nil
|
102
112
|
|
103
113
|
op.on('-s', '--schedule CRON', 'change the schedule') {|s|
|
104
114
|
cron = s
|
@@ -118,6 +128,12 @@ module Command
|
|
118
128
|
op.on('-D', '--delay SECONDS', 'change the delay time of the schedule', Integer) {|i|
|
119
129
|
delay = i
|
120
130
|
}
|
131
|
+
op.on('-P', '--priority PRIORITY', 'set priority') {|s|
|
132
|
+
priority = job_priority_id_of(s)
|
133
|
+
unless priority
|
134
|
+
raise "unknown priority #{s.inspect} should be -2 (very-low), -1 (low), 0 (normal), 1 (high) or 2 (very-high)"
|
135
|
+
end
|
136
|
+
}
|
121
137
|
|
122
138
|
name = op.cmd_parse
|
123
139
|
|
@@ -128,6 +144,7 @@ module Command
|
|
128
144
|
params['result'] = result if result
|
129
145
|
params['timezone'] = timezone if timezone
|
130
146
|
params['delay'] = delay.to_s if delay
|
147
|
+
params['priority'] = priority.to_s if priority
|
131
148
|
|
132
149
|
if params.empty?
|
133
150
|
$stderr.puts op.to_s
|
@@ -149,6 +166,8 @@ module Command
|
|
149
166
|
end
|
150
167
|
|
151
168
|
def sched_history(op)
|
169
|
+
require 'td/command/job' # job_priority_name_of
|
170
|
+
|
152
171
|
page = 0
|
153
172
|
skip = 0
|
154
173
|
|
@@ -186,16 +205,17 @@ module Command
|
|
186
205
|
puts "Delay : #{s.delay} sec"
|
187
206
|
puts "Next : #{s.next_time}"
|
188
207
|
puts "Result : #{s.result_url}"
|
208
|
+
puts "Priority : #{job_priority_name_of(s.priority)}"
|
189
209
|
puts "Database : #{s.database}"
|
190
210
|
puts "Query : #{s.query}"
|
191
211
|
end
|
192
212
|
|
193
213
|
rows = []
|
194
214
|
history.each {|j|
|
195
|
-
rows << {:Time => j.scheduled_at.localtime, :JobID => j.job_id, :Status => j.status, :Result=>j.result_url}
|
215
|
+
rows << {:Time => j.scheduled_at.localtime, :JobID => j.job_id, :Status => j.status, :Priority => job_priority_name_of(j.priority), :Result=>j.result_url}
|
196
216
|
}
|
197
217
|
|
198
|
-
puts cmd_render_table(rows, :fields => [:JobID, :Time, :Status, :Result])
|
218
|
+
puts cmd_render_table(rows, :fields => [:JobID, :Time, :Status, :Priority, :Result])
|
199
219
|
end
|
200
220
|
|
201
221
|
def sched_run(op)
|
data/lib/td/command/table.rb
CHANGED
@@ -134,7 +134,7 @@ module Command
|
|
134
134
|
|
135
135
|
op.on('-t', '--to TIME', 'end time of logs to get') {|s|
|
136
136
|
if s.to_i.to_s == s
|
137
|
-
to = s
|
137
|
+
to = s.to_i
|
138
138
|
else
|
139
139
|
require 'time'
|
140
140
|
to = Time.parse(s).to_i
|
@@ -142,7 +142,7 @@ module Command
|
|
142
142
|
}
|
143
143
|
op.on('-f', '--from TIME', 'start time of logs to get') {|s|
|
144
144
|
if s.to_i.to_s == s
|
145
|
-
from = s
|
145
|
+
from = s.to_i
|
146
146
|
else
|
147
147
|
require 'time'
|
148
148
|
from = Time.parse(s).to_i
|
@@ -193,7 +193,6 @@ module Command
|
|
193
193
|
puts row.to_json
|
194
194
|
}
|
195
195
|
end
|
196
|
-
|
197
196
|
end
|
198
197
|
|
199
198
|
def table_export(op)
|
@@ -254,6 +253,64 @@ module Command
|
|
254
253
|
end
|
255
254
|
end
|
256
255
|
|
256
|
+
def table_partial_delete(op)
|
257
|
+
from = nil
|
258
|
+
to = nil
|
259
|
+
wait = false
|
260
|
+
|
261
|
+
op.on('-t', '--to TIME', 'end time of logs to delete') {|s|
|
262
|
+
if s.to_i.to_s == s
|
263
|
+
# UNIX time
|
264
|
+
to = s.to_i
|
265
|
+
else
|
266
|
+
require 'time'
|
267
|
+
to = Time.parse(s).to_i
|
268
|
+
end
|
269
|
+
}
|
270
|
+
op.on('-f', '--from TIME', 'start time of logs to delete') {|s|
|
271
|
+
if s.to_i.to_s == s
|
272
|
+
from = s.to_i
|
273
|
+
else
|
274
|
+
require 'time'
|
275
|
+
from = Time.parse(s).to_i
|
276
|
+
end
|
277
|
+
}
|
278
|
+
op.on('-w', '--wait', 'wait for finishing the job', TrueClass) {|b|
|
279
|
+
wait = b
|
280
|
+
}
|
281
|
+
|
282
|
+
db_name, table_name = op.cmd_parse
|
283
|
+
|
284
|
+
unless from
|
285
|
+
$stderr.puts "-f, --from TIME option is required"
|
286
|
+
exit 1
|
287
|
+
end
|
288
|
+
|
289
|
+
unless to
|
290
|
+
$stderr.puts "-t, --to TIME option is required"
|
291
|
+
exit 1
|
292
|
+
end
|
293
|
+
|
294
|
+
if from % 3600 != 0 || to % 3600 != 0
|
295
|
+
$stderr.puts "time must be a multiple of 3600 (1 hour)"
|
296
|
+
exit 1
|
297
|
+
end
|
298
|
+
|
299
|
+
client = get_client
|
300
|
+
|
301
|
+
table = get_table(client, db_name, table_name)
|
302
|
+
|
303
|
+
job = client.partial_delete(db_name, table_name, to, from)
|
304
|
+
|
305
|
+
$stderr.puts "Partial delete job #{job.job_id} is queued."
|
306
|
+
$stderr.puts "Use '#{$prog} job:show #{job.job_id}' to show the status."
|
307
|
+
|
308
|
+
if wait && !job.finished?
|
309
|
+
wait_job(job)
|
310
|
+
puts "Status : #{job.status}"
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
257
314
|
require 'td/command/import' # table:import
|
258
315
|
require 'td/command/export' # table:export
|
259
316
|
require 'td/command/job' # wait_job
|
data/lib/td/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.32
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70143943515280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70143943515280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70143943514700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.4.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70143943514700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: hirb
|
38
|
-
requirement: &
|
38
|
+
requirement: &70143943514000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,21 +43,21 @@ dependencies:
|
|
43
43
|
version: 0.4.5
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70143943514000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: td-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &70143943509200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.8.
|
54
|
+
version: 0.8.19
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70143943509200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: td-logger
|
60
|
-
requirement: &
|
60
|
+
requirement: &70143943508660 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.3.12
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70143943508660
|
69
69
|
description: CLI to manage data on Treasure Data, the Hadoop-based cloud data warehousing
|
70
70
|
email: support@treasure-data.com
|
71
71
|
executables:
|