zillabyte-cli 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGE2NDJmZDQxOTAzNGE1YTYwYWE2MzZkNjFmODc5YmRhMDFlMTliZQ==
4
+ ZWRmMzQwZmQ1ZWZkN2I5YmYyMDlmYTg0YmI5MDNjZmU1N2YxMjBiZA==
5
5
  data.tar.gz: !binary |-
6
- ZDc5YzRhNzYwMjRmNDE4OTc3NzI3ZWQxNWJmNDA0OWY0ZWI0NjY4Yg==
6
+ NWViMWY3ZWU3NTIyZGFlYzBkNWNlOTcxNDlhYWYxZDMwYjk3NWM2Ng==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGI5MWJkNTkzZDY2ZjYxNGRkNThkNTM3YWExNzRhYmFhZTY2OTRlZjlhY2Yy
10
- NzZkYTFiMzdkZDFhMmI3NWE4NjYwMWY3MjBhYzVkM2YzNThhMDE4Y2I5NWU0
11
- ODI0MTZkN2E5MWRhMDQ1MWZmYTRiNzRkNTk3Yzc3MmZlOGNhZTI=
9
+ NTEzNWQ3NzVkMDE5ZjM5MmU0YmQ2YjU4ZmRhY2JiMDM0ZDc2OTBkYThlNzU3
10
+ MTkyYjNlNDkwYmZlNDRiOGE4N2IyNWJkNzZkYzYyYmVlNTRlZjgwYTJjODNm
11
+ ZDg1NWNjMWJhOTg1MjFhMzA0ODZkZTIzNzk5N2RhNzBiMzczYzY=
12
12
  data.tar.gz: !binary |-
13
- MTFiNzgxNTgwOWMyNzAzNWI1Zjg5YTQ1NWNiYTVlZDVmNDYzZDY3NTFmYTgx
14
- ZjMyMDRiZTc4N2NlNTk1MDFjZGEzNmFkZWRmNjJlZjE3NTNhMDRhYTZmNGRm
15
- ZjZjZmM1OTg3YzU1ZGU2MDZiZjg4YjE0NmU4Yjc2MDdiM2Q0ZTY=
13
+ YzJjOTg5MjZkMDRjMmFhODcxNjYzYzYwYjM3YmI4Njc3YTIzMjQwYjY2MTM1
14
+ NzY3YjkyZTgxYzA0ZWM5M2I1MzlmYjIwNjY1OTNhODJhYWI1MjkwYzgzNTY1
15
+ YzczNGU0OTljMzc0ZTU5YzE3MmNmZTliMjhlM2RiZWExNmZhMTc=
@@ -354,7 +354,6 @@ class Zillabyte::Command::Apps < Zillabyte::Command::Flows
354
354
  elsif trigger_forever
355
355
  response = api.apps.run_forever(app_id, options)
356
356
  else
357
- require("date")
358
357
  # List the apps
359
358
  response = api.apps.list_cycles(app_id, options)
360
359
  # TODO List the sequence number for this app.
@@ -75,7 +75,7 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
75
75
  def list
76
76
  type = options[:output_type]
77
77
 
78
- headings = ["id", "name", "state", "inputs", "outputs", "scope"]
78
+ headings = ["id", "name", "state", "inputs", "outputs"]
79
79
  rows = api.component.list.map do |row|
80
80
  if headings.size == 0
81
81
  headings = row.keys
@@ -133,16 +133,6 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
133
133
  super
134
134
  end
135
135
 
136
- # components:kill ID
137
- #
138
- # Kills the given component rpc.
139
- #
140
- # --config CONFIG_FILE # Use the given config file
141
- # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
142
- #
143
- def kill
144
- super
145
- end
146
136
 
147
137
  # components:info [DIR]
148
138
  #
@@ -295,165 +285,4 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
295
285
 
296
286
  end
297
287
 
298
-
299
- # components:rpc [ID] [INPUT_1] [INPUT_2] ...
300
- #
301
- # Submits a single query to the rpc. The input parameters MUST be
302
- # listed in the same order as that given in the component inputs.
303
- # TO SUBMIT MULTIPLE queries, use the --input_file switch to specify
304
- # a csv file containing the queries without listing any inputs on
305
- # the command line. Each line of the file should correspond to a
306
- # unique query.
307
- #
308
- # --async # Run the command asynchronously
309
- # --input_file INTPUT_FILE # Input csv file containing parameters for multiple queries
310
- # --output_file OUTPUT_FILE # Output csv file containing query parameters and run ids
311
- #
312
- # Examples:
313
- #
314
- # Single query:
315
- # $ zillabyte components:rpc 'web_screenshot' 'google.com'
316
- #
317
- # Multiple queries:
318
- # $ zillabyte components:rpc 'web_screenshot' --file 'url_list.csv'
319
- #
320
- def rpc
321
- require("csv")
322
-
323
- component_id = options[:id] || shift_argument
324
- async = options[:async] || false
325
-
326
- if component_id.nil?
327
- component_id = read_name_from_conf(options)
328
- end
329
-
330
- type = options[:output_type]
331
- file = options[:input_file]
332
- out_file = options[:output_file]
333
-
334
- component_args = []
335
- if file
336
- CSV.foreach(file) {|line| component_args << line}
337
- else
338
- args = []
339
- while(true) do
340
- next_arg = shift_argument
341
- break if next_arg.nil?
342
- args << next_arg
343
- end
344
- component_args << args if !args.empty?
345
- end
346
-
347
- opts = {:rpc_inputs => component_args} if component_args.size != 0
348
- res = api.components.rpc(component_id, opts)
349
-
350
- input_par_for_id = {}
351
- if res['error']
352
- error("error: #{res['error_message']}", type)
353
- else
354
- if type.nil?
355
- display "Request submitted to component ##{res['id']}."
356
- end
357
-
358
- if res["execute_ids"]
359
- input_par_for_id = res["execute_ids"].invert
360
- if out_file
361
- CSV.open(out_file, "w") {|csv| res["execute_ids"].to_a.each {|elem| csv << elem}}
362
- end
363
- end
364
- end
365
-
366
- if async
367
- # Async -- return right away..
368
- display "The run ids are (query: run_id):"
369
- res["execute_ids"].each do |pars, id|
370
- display "\t #{pars}: #{id}"
371
- end
372
- display "Please use \"zillabyte components:results [run id]\" to check on the status of your query and to retrieve your results.\nYou may also wish to check \"zillabyte logs\" for errors."
373
- else
374
- # Sync -- poll until it's done...
375
- if res["execute_ids"]
376
- run_ids = res["execute_ids"].values
377
- while true
378
- res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
379
- if res['error']
380
- error("error: #{res['error_message']}", type)
381
- else
382
- if res["results"].detect{|id, res| ["running", "waiting"].member?(res["status"].downcase)}
383
- # poll again
384
- sleep(2)
385
- else
386
- if type.nil?
387
- # All results are done (or rather, not 'running). Display them
388
- res["results"].each do |id, hash|
389
- display "Query #{input_par_for_id[id]}:"
390
- if hash["data"].size == 0
391
- display "\t NO OUTPUT"
392
- else
393
- display "\t #{hash["data"].to_json()}"
394
- end
395
- end
396
- end
397
- break
398
- end
399
- end
400
- end
401
- end
402
- end
403
- end
404
- alias_command "rpc", "components:rpc"
405
-
406
-
407
-
408
- # components:results [ID] [RUN_ID_1] [RUN_ID_2] ...
409
- #
410
- # Gets the result of rpc requests corresponding to RUN_ID if it is
411
- # done running, otherwise gets current run status. A list of RUN_IDs
412
- # may also be specified in an input csv file like that generated by
413
- # components:rpc with the --output_file flag.
414
- #
415
- # --input_file INTPUT_FILE # Input csv file containing query parameters and run ids (this can be generated automatically by components:rpc using the --output_file flag)
416
- #
417
- def results
418
- component_id = options[:id] || shift_argument
419
-
420
- if component_id.nil?
421
- component_id = read_name_from_conf(options)
422
- end
423
-
424
- type = options[:output_type]
425
- file = options[:input_file]
426
-
427
- run_ids = []
428
- if file
429
- CSV.foreach(file) do |line|
430
- run_ids << line[1]
431
- end
432
- else
433
- while(true) do
434
- next_arg = shift_argument
435
- break if next_arg.nil?
436
- run_ids << next_arg
437
- end
438
- end
439
-
440
- res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
441
- if res['error']
442
- error("error: #{res['error_message']}", type)
443
- else
444
- if type.nil?
445
- res["results"].each do |id, hash|
446
- display "#{id}: #{hash["status"]}"
447
- if hash["status"] == "complete"
448
- if hash["data"].size == 0
449
- display "\t NO OUTPUT"
450
- else
451
- display "\t #{hash["data"]}"
452
- end
453
- end
454
- end
455
- end
456
- end
457
- end
458
-
459
288
  end
@@ -35,12 +35,20 @@ class Zillabyte::Command::Data < Zillabyte::Command::Base
35
35
  :path => "/relations"
36
36
  )
37
37
 
38
- headings = []
38
+ headings = ["id", "name","rows"]
39
39
  rows = response.body.map do |row|
40
40
  headings = row.keys if headings.size == 0
41
- row["columns"] = row["columns"].map{|c| c['type']}.join(',')
41
+ row["columns"] = row["columns"].map{|c|c['type']}.join(',')
42
42
  row["aliases"] = row["aliases"].map{|a| a['name']}.join(',')
43
- vals = row.values_at *headings
43
+
44
+ row = row.keep_if {|col,val| headings.include? col}
45
+ vals = row.map do |col,val|
46
+ if col == "rows"
47
+ require("zillabyte/cli/helpers/table_output_builder")
48
+ val = TableOutputBuilder.format_row_count(val)
49
+ end
50
+ val
51
+ end
44
52
  vals
45
53
  end
46
54
 
@@ -4,7 +4,7 @@ require("zillabyte/cli/base")
4
4
  #
5
5
  class Zillabyte::Command::Help < Zillabyte::Command::Base
6
6
 
7
- PRIMARY_NAMESPACES = %w( data query apps components logs )
7
+ PRIMARY_NAMESPACES = %w( data query apps components rpc logs )
8
8
 
9
9
  # help
10
10
  def index(*direct_args)
@@ -18,8 +18,29 @@ module Zillabyte; module Helpers; class TableOutputBuilder
18
18
  return out.to_json
19
19
  end
20
20
 
21
- def self.build_terminal_table(headings, rows)
22
- require("terminal-table")
23
- Terminal::Table.new(:headings => headings, :rows => rows).to_s
21
+ def self.build_terminal_table(headings, rows)
22
+ require("terminal-table")
23
+
24
+ table = Terminal::Table.new(:headings => headings, :rows => rows).to_s
25
+ end
26
+
27
+ def self.format_row_count(val)
28
+
29
+ val = val.to_i
30
+ if val > 1000000000
31
+ val = (val/1000000000).to_s + "B"
32
+ elsif val > 1000000
33
+ val = (val/1000000).to_s + "M"
34
+ elsif val > 1000
35
+ val = (val/1000).to_s + "K"
24
36
  end
37
+ val
38
+ end
39
+
40
+
41
+
42
+
43
+
44
+
45
+
25
46
  end; end; end
@@ -0,0 +1,218 @@
1
+ require 'yaml'
2
+ require "zillabyte/cli/flows"
3
+ require "zillabyte/cli/config"
4
+ require "zillabyte/common"
5
+
6
+ # remote procedure call a component
7
+ #
8
+ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
9
+
10
+ # rpc
11
+ #
12
+ # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
13
+ #
14
+ def index
15
+ self.rpc
16
+ end
17
+
18
+ # rpc:start ID [INPUT_1] [INPUT_2] ...
19
+ #
20
+ # Starts the rpc and optionally submits the inputs from the command
21
+ # line. The input parameters MUST be listed in the same order as
22
+ # that given in the component inputs. TO SUBMIT MULTIPLE queries,
23
+ # use the --input_file switch to specify a CSV file containing the
24
+ # queries without listing any inputs on the command line. Each line
25
+ # of the file should correspond to a unique query.
26
+ #
27
+ # --async # Run the command asynchronously
28
+ # --input_file INTPUT_FILE # Input csv file containing parameters for multiple queries
29
+ # --output_file OUTPUT_FILE # Output csv file containing query parameters and run ids
30
+ # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
31
+ #
32
+ # Examples:
33
+ #
34
+ # Single query:
35
+ # $ zillabyte rpc 'web_screenshot' 'google.com'
36
+ #
37
+ # Multiple queries:
38
+ # $ zillabyte rpc 'web_screenshot' --input_file 'url_list.csv'
39
+ #
40
+ def start
41
+ require("csv")
42
+
43
+ component_id = options[:id] || shift_argument
44
+ async = options[:async] || false
45
+
46
+ if component_id.nil?
47
+ component_id = read_name_from_conf(options)
48
+ end
49
+
50
+ type = options[:output_type]
51
+ file = options[:input_file]
52
+ out_file = options[:output_file]
53
+
54
+ component_args = []
55
+ if file
56
+ CSV.foreach(file) {|line| component_args << line}
57
+ else
58
+ args = []
59
+ while(true) do
60
+ next_arg = shift_argument
61
+ break if next_arg.nil?
62
+ args << next_arg
63
+ end
64
+ component_args << args if !args.empty?
65
+ end
66
+
67
+ opts = {:rpc_inputs => component_args} if component_args.size != 0
68
+ res = api.components.rpc(component_id, opts)
69
+
70
+ input_par_for_id = {}
71
+ if res['error']
72
+ error("error: #{res['error_message']}", type)
73
+ else
74
+ if type.nil?
75
+ display "Request submitted to component ##{res['id']}."
76
+ end
77
+
78
+ if res["execute_ids"]
79
+ input_par_for_id = res["execute_ids"].invert
80
+ if out_file
81
+ CSV.open(out_file, "w") {|csv| res["execute_ids"].to_a.each {|elem| csv << elem}}
82
+ end
83
+ end
84
+ end
85
+
86
+ if async
87
+ # Async -- return right away..
88
+ display "The run ids are (query: run_id):"
89
+ res["execute_ids"].each do |pars, id|
90
+ display "\t #{pars}: #{id}"
91
+ end
92
+ display "Please use \"zillabyte rpc:status\" and \"zillabyte rpc:results\" to check on the status of your query and to retrieve your results.\nYou may also wish to check \"zillabyte logs\" for errors."
93
+ else
94
+ # Sync -- poll until it's done...
95
+ if res["execute_ids"]
96
+ run_ids = res["execute_ids"].values
97
+ wait_for_results(component_id, run_ids, type, input_par_for_id)
98
+ end
99
+ end
100
+ end
101
+
102
+
103
+ # rpc:results ID RUN_ID
104
+ #
105
+ # Returns results from the RPC for the input corresponding to
106
+ # RUN_ID. If the result is not available yet, this method waits
107
+ # until it is. Alternatively, a list of RUN_IDs may be supplied
108
+ # in a CSV with 2 columns: ["query",run_id] using --input_file.
109
+ # This file can be generated by "zillabyte rpc" if --output_file
110
+ # is specified.
111
+ #
112
+ # --input_file INTPUT_FILE # Input csv file containing queries and run_ids
113
+ #
114
+ def results
115
+ component_id = options[:id] || shift_argument
116
+
117
+ if component_id.nil?
118
+ component_id = read_name_from_conf(options)
119
+ end
120
+
121
+ type = options[:output_type]
122
+ file = options[:input_file]
123
+
124
+ run_ids = get_run_ids_from_command_line_or_file(file)
125
+ wait_for_results(component_id, run_ids, type)
126
+ end
127
+
128
+ # rpc:status ID RUN_ID
129
+ #
130
+ # Returns the current status of the RPC query corresponding to
131
+ # RUN_ID. Alternatively, a list of RUN_IDs may be supplied in a
132
+ # CSV with 2 columns: ["query",run_id] using --input_file. This
133
+ # file can be generated by "zillabyte rpc" if --output_file is
134
+ # specified.
135
+ #
136
+ # --input_file INTPUT_FILE # Input csv file containing queries and run_ids
137
+ #
138
+ def status
139
+
140
+ component_id = options[:id] || shift_argument
141
+ if component_id.nil?
142
+ component_id = read_name_from_conf(options)
143
+ end
144
+
145
+ type = options[:output_type]
146
+ file = options[:input_file]
147
+
148
+ run_ids = get_run_ids_from_command_line_or_file(file)
149
+
150
+ res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
151
+ if res['error']
152
+ error("error: #{res['error_message']}", type)
153
+ else
154
+ if type.nil?
155
+ res["results"].each do |id, hash|
156
+ display "#{id}: #{hash["status"]}"
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ # rpc:kill ID
163
+ #
164
+ # Kills the RPC.
165
+ #
166
+ # --config CONFIG_FILE # Use the given config file
167
+ # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
168
+ #
169
+ def kill
170
+ super
171
+ end
172
+
173
+
174
+ private
175
+
176
+
177
+ def wait_for_results(component_id, run_ids, type, input_par_for_id = nil)
178
+ while run_ids.length > 0
179
+ res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
180
+ if res['error']
181
+ error("error: #{res['error_message']}", type)
182
+ else
183
+ res["results"].each do |id, res|
184
+ next if ["running", "waiting"].member?(res["status"].downcase)
185
+ if type.nil?
186
+ display "Query #{input_par_for_id ? input_par_for_id[id] : id}:"
187
+ if res["data"].size == 0
188
+ display "\t NO OUTPUT"
189
+ else
190
+ display "\t #{res["data"].to_json()}"
191
+ end
192
+ end
193
+ run_ids.delete id
194
+ end
195
+ end
196
+ # poll again
197
+ sleep(2)
198
+ end
199
+ end
200
+
201
+ def get_run_ids_from_command_line_or_file(file)
202
+ run_ids = []
203
+ if file
204
+ require("csv")
205
+ CSV.foreach(file) do |line|
206
+ run_ids << line[1]
207
+ end
208
+ else
209
+ while(true) do
210
+ next_arg = shift_argument
211
+ break if next_arg.nil?
212
+ run_ids << next_arg
213
+ end
214
+ end
215
+ return run_ids
216
+ end
217
+
218
+ end
@@ -1,5 +1,5 @@
1
1
  module Zillabyte
2
2
  module CLI
3
- VERSION = "0.1.19"
3
+ VERSION = "0.1.20"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillabyte-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - zillabyte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -209,6 +209,7 @@ files:
209
209
  - lib/zillabyte/cli/nuke.rb
210
210
  - lib/zillabyte/cli/query.rb
211
211
  - lib/zillabyte/cli/repl.rb
212
+ - lib/zillabyte/cli/rpc.rb
212
213
  - lib/zillabyte/cli/sources.rb
213
214
  - lib/zillabyte/cli/templates/apps/js/simple_function.js
214
215
  - lib/zillabyte/cli/templates/apps/js/zillabyte.conf.yaml