zillabyte-cli 0.1.24 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTZjYWM4MDcxZTUyNzM4MGZiMGQyZTAyN2U4YTlkNzViZGQ1MWEyMw==
5
- data.tar.gz: !binary |-
6
- NTEwZDVkZjFmMmZjNjU2NWFkNTRkMjgwODRhYWI3MWE5NDA1NDBlOA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YmExNmVlMmZmYmE5YWM4ZjdiMmJmMzBjM2M5ZTkwNzBjODE3MTNmNzI5ZTM3
10
- NjBlNzVlYTg4ZWQxMGI3MDAzMzRkZjI5NzIyOTY0ZDQ2YWVlNDhhMTMwMjIw
11
- M2E0MTFiODFjZjQ5NzJkZGQxMTJiNjhhMmMyMzM4MTJhOWJlZGI=
12
- data.tar.gz: !binary |-
13
- YWU0MjQyY2Q1OGFkYzkyODE1NjMyZjVmODQ2NTFjZGNhOGY1M2I0ODNjNjdl
14
- MzFhMjM4ODRjMTU3ZDVlNjE0N2U5ZTI3YWViZGEyOTc1YzZjNzc4ZWRiYWNk
15
- MTBjZWE3ZGQ0MjcxNWZiYWQyYTYwZGZhN2JhYjRiNzkyZjc5Njg=
2
+ SHA1:
3
+ metadata.gz: 66964b9f8b93fb6a6f3f5dff18c3438343abe0b4
4
+ data.tar.gz: 4e1c94b820e4bd17a7ffa399a9246a4dfdde60c4
5
+ SHA512:
6
+ metadata.gz: a2ff53bb4bca1a177decd0d4c5a4ab21d1af0374f860bc379a0bb60ead1fcd8a891a65590d2fac1ed9f2003791bed616bf53b80d44208f8632b4ff63941f4939
7
+ data.tar.gz: f6395c7ecfc73eb452268f6fed21780fc761d18e8d917dca2cf385fe0f20668bce955b816cb186b668a76f02ee524e518065074e887fed718c3210b9ff99bd20
@@ -0,0 +1,5 @@
1
+ require "zillabyte-cli/version"
2
+ require "zillabyte/api"
3
+ require "zillabyte/cli"
4
+ require "zillabyte/common"
5
+ require "zillabyte/queries"
@@ -1,5 +1,5 @@
1
1
  module Zillabyte
2
2
  module CLI
3
- VERSION = "0.1.24"
3
+ VERSION = "0.1.25"
4
4
  end
5
5
  end
@@ -82,78 +82,4 @@ class Zillabyte::API::Apps < Zillabyte::API::Flows
82
82
  res.body
83
83
  end
84
84
 
85
-
86
- # POST /apps
87
- #
88
- def push_directory(dir, session = nil, options = {})
89
- require("zillabyte/common/tar")
90
- type = options[:output_type]
91
- # Get the meta info
92
- options[:local_flag] = 1
93
- hash = Zillabyte::API::Flows.get_rich_meta_info_from_script(dir, session, options)
94
- if hash["flow_type"] == "component"
95
- session.error("To push up a component please use git. The \"zillabyte push\" command is only supported for apps.") if session
96
- end
97
-
98
- if hash.nil?
99
- session.error("unable to extract app meta information", type) if session
100
- end
101
-
102
- if hash["error"]
103
- session.error(hash["error_message"], type) if session
104
- end
105
-
106
- # Tar up everything...
107
- hash['ignore_files'] ||= []
108
- hash['ignore_files'] << "info_to_ruby.in"
109
- hash['ignore_files'] << "vEnv"
110
-
111
- top_dir = hash['top_dir'] || "."
112
- ignore_files = hash['ignore_files'] || []
113
- session.display("packaging directory... ", false) if session && type.nil?
114
- tar = Zillabyte::Common::Tar.tar(top_dir, ignore_files)
115
- session.display("done") if session && type.nil?
116
-
117
- hash.delete('pwd')
118
-
119
- options = {
120
- :name => hash['name'],
121
- :meta => hash,
122
- # :tar => Base64.encode64(tar.read)
123
- }.merge(options)
124
-
125
- session.display("uploading #{tar.size} bytes... ", false) if session && type.nil?
126
- res = @api.request(
127
- :expects => 200,
128
- :method => :post,
129
- :path => "/apps",
130
- :body => options.to_json
131
- )
132
-
133
-
134
- if(res.body['uri'])
135
- require("net/http")
136
- uri = URI(res.body['uri'])
137
- try_again = 1
138
- while(try_again)
139
- Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
140
- request = Net::HTTP::Put.new(uri.request_uri)
141
- request.body_stream = tar
142
- request['Content-Length'] = request.body_stream.size
143
- request['Content-Type'] = ''
144
- response = http.request(request)
145
- if response.code.to_i >= 300
146
- try_again = 1
147
- break
148
- end
149
- try_again = nil
150
- end
151
- end
152
- res.body.delete('uri')
153
- end
154
- session.display("done")if session && type.nil?
155
- res.body
156
-
157
- end
158
-
159
85
  end
@@ -135,7 +135,68 @@ class Zillabyte::API::Flows < Zillabyte::API::Base
135
135
  hash
136
136
 
137
137
  end
138
-
138
+
139
+ # POST /apps OR /components
140
+ #
141
+ def push_directory(dir, hash, session = nil, options = {})
142
+ require("zillabyte/common/tar")
143
+ type = options[:output_type]
144
+ flow_type = hash["flow_type"]
145
+
146
+ # Tar up everything...
147
+ hash['ignore_files'] ||= []
148
+ hash['ignore_files'] << "info_to_ruby.in"
149
+ hash['ignore_files'] << "vEnv"
150
+
151
+ top_dir = hash['top_dir'] || "."
152
+ ignore_files = hash['ignore_files'] || []
153
+ session.display("packaging directory... ", false) if session && type.nil?
154
+ tar = Zillabyte::Common::Tar.tar(top_dir, ignore_files)
155
+ session.display("done") if session && type.nil?
156
+
157
+ hash.delete('pwd')
158
+
159
+ options = {
160
+ :name => hash['name'],
161
+ :meta => hash,
162
+ # :tar => Base64.encode64(tar.read)
163
+ }.merge(options)
164
+
165
+ session.display("uploading #{tar.size} bytes... ", false) if session && type.nil?
166
+ res = @api.request(
167
+ :expects => 200,
168
+ :method => :post,
169
+ :path => "/#{flow_type}s",
170
+ :body => options.to_json
171
+ )
172
+
173
+
174
+ if(res.body['uri'])
175
+ require("net/http")
176
+
177
+ uri = URI(res.body['uri'])
178
+ try_again = 1
179
+ while(try_again)
180
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
181
+ request = Net::HTTP::Put.new(uri.request_uri)
182
+ request.body_stream = tar
183
+ request['Content-Length'] = request.body_stream.size
184
+ request['Content-Type'] = ''
185
+ response = http.request(request)
186
+ if response.code.to_i >= 300
187
+ try_again = 1
188
+ break
189
+ end
190
+ try_again = nil
191
+ end
192
+ end
193
+ res.body.delete('uri')
194
+ end
195
+ session.display("done")if session && type.nil?
196
+ res.body
197
+
198
+ end
199
+
139
200
  ####################################################IMPORTANT####################################################
140
201
  # #
141
202
  # get_rich_meta_info_from_script only works with zillabyte apps:push now! The pipe "info_to_ruby.in" is #
@@ -150,6 +211,7 @@ class Zillabyte::API::Flows < Zillabyte::API::Base
150
211
  if hash.nil?
151
212
  return {"status" => "error", "error" => "invalid_directory", "error_message" => "The specified directory (#{dir}) does not appear to contain a valid Zillabyte configuration file."}
152
213
  end
214
+ hash["flow_type"] = "app" if hash["flow_type"].nil? # default to app
153
215
 
154
216
  type = options[:output_type]
155
217
 
@@ -189,8 +251,7 @@ class Zillabyte::API::Flows < Zillabyte::API::Base
189
251
  session.error("the underlying app did not return a valid result. command: #{command} error: #{e.message}", type) if session
190
252
  exit
191
253
  end
192
-
193
-
254
+
194
255
  # Merge with the new info
195
256
  return hash.merge(meta)
196
257
 
@@ -0,0 +1,12 @@
1
+ require "zillabyte/cli/base"
2
+
3
+ # manage custom logs
4
+ #
5
+ class Zillabyte::Command::Logs < Zillabyte::Command::Base
6
+
7
+
8
+
9
+
10
+
11
+
12
+ end
@@ -0,0 +1,43 @@
1
+ require "zillabyte/cli/base"
2
+ require 'readline'
3
+ # REPL console for zillabyte commands
4
+ #
5
+ class Zillabyte::Command::Repl < Zillabyte::Command::Base
6
+
7
+ # repl
8
+ #
9
+ # start a console session for zillabyte
10
+ # --quiet # HIDDEN
11
+ # --history HISTORY# HIDDEN hack to allow history for readline
12
+ def index
13
+ if !options[:quiet]
14
+ v = `zillabyte version`
15
+ display "\n#{v}Type q,exit or Ctrl+D to quit\n\n"
16
+ end
17
+ server = `echo $ZILLABYTE_API_HOST` || ""
18
+ prompt = ""
19
+ if server && server.chomp.length > 0
20
+ prompt = "#{server.chomp} "
21
+ end
22
+ prompt += "zillabyte $ "
23
+ if options[:history]
24
+ #p options[:history]
25
+ history = JSON.parse(options[:history])
26
+ history.last(50).each do |his|
27
+ # TODO: Handle single quotes ??
28
+ Readline::HISTORY << his
29
+ end
30
+ end
31
+ # TODO: Add tab completion for basic commands, app/relation names etc.
32
+ while cmd = Readline.readline(prompt, true)
33
+ if cmd && cmd.length > 0
34
+ if cmd.downcase == "exit" || cmd.downcase == "q"
35
+ display "" # TODO Make Ctrl+D print a newline too
36
+ return
37
+ else
38
+ exec "zillabyte #{cmd}; zillabyte repl --quiet --history '#{Readline::HISTORY.to_a.to_json}'"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -184,35 +184,8 @@ class Zillabyte::Command::Apps < Zillabyte::Command::Flows
184
184
  # $ zillabyte apps:push .
185
185
  #
186
186
  def push
187
-
188
- since = Time.now.utc.to_s
189
- dir = options[:directory]
190
- if dir.nil?
191
- dir = Dir.pwd
192
- else
193
- dir = File.expand_path(dir)
194
- end
195
- options[:directory] = dir
196
- type = options[:output_type]
197
-
198
- res = api.apps.push_directory dir, session, options
199
-
200
- if res['error']
201
- error("error: #{res['error_message']}", type)
202
- else
203
- display "app ##{res['id']} #{res['action']}" if type.nil?
204
- end
205
-
206
- display "Starting up your app...please wait..." if type.nil?
207
- sleep(2) # wait for kill command
208
-
209
- hash = self.api.logs.get(res['id'], nil, options)
210
- fetch_logs(hash, "_ALL_", ["App deployed", "STOP_LOGGING"])
211
-
212
- display "{}" if type == "json"
213
-
187
+ super
214
188
  end
215
- alias_command "push", "apps:push"
216
189
 
217
190
 
218
191
  # apps:pull ID DIR
@@ -218,71 +218,8 @@ class Zillabyte::Command::Components < Zillabyte::Command::Flows
218
218
  #
219
219
  # $ zillabyte components:push .
220
220
  #
221
- # HIDDEN: This is only meant for local testing. You must be an admin.
222
221
  def push
223
-
224
- since = Time.now.utc.to_s
225
- dir = options[:directory] || Dir.pwd
226
- dir = File.expand_path(dir)
227
-
228
- require("zillabyte/api/flows")
229
- hash = Zillabyte::API::Flows.get_rich_meta_info_from_script(dir, session, options)
230
- name = hash['name']
231
-
232
- options[:directory] = dir
233
- options[:component_id] = dir
234
- options[:schema] = hash
235
- options[:meta] = hash
236
- options[:name] = name
237
- type = options[:output_type]
238
-
239
- # Push the component...
240
- session.display("packaging directory... ") if session && type.nil?
241
- require("zillabyte/common/tar")
242
- tar = Zillabyte::Common::Tar.tar(dir)
243
-
244
- # Create the component
245
- res = self.api.request(
246
- :expects => 200,
247
- :method => :post,
248
- :path => "/components/",
249
- :body => options.to_json
250
- ).body
251
-
252
- error("error: #{res['error_message']}", type) if res['error']
253
- comp_id = res['id']
254
-
255
- # Push the tar...
256
- if(res['uri'])
257
- require("net/http")
258
- uri = URI(res['uri'])
259
- try_again = 1
260
- while(try_again)
261
- Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
262
- request = Net::HTTP::Put.new(uri.request_uri)
263
- request.body_stream = tar
264
- request['Content-Length'] = request.body_stream.size
265
- request['Content-Type'] = ''
266
- response = http.request(request)
267
- if response.code.to_i >= 300
268
- try_again = 1
269
- break
270
- end
271
- try_again = nil
272
- end
273
- end
274
- res.delete('uri')
275
- session.display( "pushed")
276
- else
277
- error "unable to push"
278
- end
279
-
280
- sleep 2
281
- hash = self.api.logs.get(comp_id, nil, options)
282
- fetch_logs(hash, "_ALL_", ["Component registered", "STOP_LOGGING"])
283
-
284
- display "{}" if type == "json"
285
-
222
+ super
286
223
  end
287
224
 
288
225
  end
@@ -39,6 +39,8 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
39
39
 
40
40
  end
41
41
 
42
+
43
+
42
44
  # flows:pull ID DIR
43
45
  #
44
46
  # Pulls a flow source to a directory.
@@ -87,6 +89,63 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
87
89
  end
88
90
  alias_command "pull", "flows:pull"
89
91
 
92
+ # flows:push [DIR]
93
+ #
94
+ # Uploads a flow.
95
+ #
96
+ # --config CONFIG_FILE # Use the given config file
97
+ # --directory DIR # Flow directory
98
+ # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
99
+ #
100
+ def push
101
+ since = Time.now.utc.to_s
102
+ dir = options[:directory]
103
+ if dir.nil?
104
+ dir = Dir.pwd
105
+ else
106
+ dir = File.expand_path(dir)
107
+ end
108
+ options[:directory] = dir
109
+ type = options[:output_type]
110
+
111
+ # Get the meta info
112
+ require('zillabyte/api/flows')
113
+ options[:local_flag] = 1
114
+ hash = Zillabyte::API::Flows.get_rich_meta_info_from_script(dir, session, options)
115
+ if hash.nil?
116
+ session.error("unable to extract #{flow_type} meta information", type) if session
117
+ end
118
+
119
+ if hash["error"]
120
+ session.error(hash["error_message"], type) if session
121
+ end
122
+
123
+ flow_type = hash["flow_type"]
124
+
125
+ res = api.flows.push_directory dir, hash, session, options
126
+
127
+ if res['error']
128
+ error("error: #{res['error_message']}", type)
129
+ else
130
+ display "#{flow_type} ##{res['id']} #{res['action']}" if type.nil?
131
+ end
132
+
133
+ display "Setting up your #{flow_type}...please wait..." if type.nil?
134
+ sleep(2) # wait for kill command
135
+
136
+ hash = self.api.logs.get(res['id'], nil, options)
137
+ if flow_type == "app"
138
+ fetch_logs(hash, "_ALL_", ["App deployed", "STOP_LOGGING"])
139
+ elsif flow_type == "component"
140
+ fetch_logs(hash, "_ALL_", ["Component registered", "STOP_LOGGING"])
141
+ end
142
+
143
+ display "{}" if type == "json"
144
+
145
+ end
146
+ alias_command "push", "flows:push"
147
+
148
+
90
149
  # flows:prep [DIR]
91
150
  #
92
151
  # Performs any necessary initialization for the flow.
@@ -599,49 +658,13 @@ class Zillabyte::Command::Flows < Zillabyte::Command::Base
599
658
  end
600
659
 
601
660
  def fetch_logs(hash, operation=nil, exit_on=nil)
602
- require("colorize")
603
- require("pty")
604
- def color_for(operation_name)
605
- @color_map[operation_name] ||= @all_colors[ @color_map.size % @all_colors.size ]
606
- @color_map[operation_name]
607
- end
608
- ip = hash["server"] || ENV["ZILLABYTE_API_HOST"] #Quick fix for logs on zilla machines
609
- exit_on = [exit_on] unless exit_on.is_a?(Array)
610
-
611
- @color_map = {}
612
- @all_colors = [:green, :yellow, :magenta, :cyan, :light_black, :light_green, :light_yellow, :light_blue, :light_magenta, :light_cyan]
613
- if(hash["server"] == "localhost")
614
- cmd = "tail -n 500 -F /tmp/flows/f#{hash["flow"]}/flow_logs/flow_#{hash["flow"]}.log"
615
- else
616
- cmd = "curl -G http://#{hash["flow"]}:#{hash["token"]}@#{ip}:#{hash["port"]}/getLogs?flow=#{hash["flow"]}"
617
- end
618
-
619
- begin
620
- PTY.spawn( cmd ) do |r, w, pid|
621
- r.each do |line|
622
- begin
623
- op = line.match(/\[(.*?)\]/)[0].to_s[1...-1]
624
-
625
- op_name = op.split(".")[0]
626
- next if op_name != operation and operation != "_ALL_"
627
- line_split = line.split("[")
628
- print line_split[0] + "[" + op.colorize(color_for(op)) + line_split[1..-1].join("[")[op.length..-1] unless line.include?("[HIDDEN]")
629
-
630
- done = false
631
- exit_on.each do |exit_str|
632
- if line.include? exit_str
633
- done = true
634
- break
635
- end
636
- end
637
- break if done
638
- rescue Exception => e
639
- next
640
- end
641
- end
642
- end
643
- rescue PTY::ChildExited => e
644
- end
661
+ require "zillabyte/common/log_fetcher"
662
+ LogFetcher.fetch_logs(hash, operation, exit_on)
663
+ end
664
+
665
+ def fetch_logs_async(hash, operation=nil, exit_on=nil)
666
+ require "zillabyte/common/log_fetcher"
667
+ LogFetcher.fetch_logs_async(hash, operation, exit_on)
645
668
  end
646
669
 
647
670
  end
@@ -17,10 +17,11 @@ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
17
17
  # queries without listing any inputs on the command line. Each line
18
18
  # of the file should correspond to a unique query.
19
19
  #
20
- # --async # Run the command asynchronously
21
- # --input_file INTPUT_FILE # Input csv file containing parameters for multiple queries
22
- # --output_file OUTPUT_FILE # Output csv file containing query parameters and run ids
23
- # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
20
+ # --async # Run the command asynchronously
21
+ # --input_file INTPUT_FILE # Input csv file containing parameters for multiple queries
22
+ # --output_file OUTPUT_FILE # Output csv file containing query parameters and run ids
23
+ # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
24
+ # --no_logs # Don't show log output
24
25
  #
25
26
  # Examples:
26
27
  #
@@ -43,6 +44,7 @@ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
43
44
  type = options[:output_type]
44
45
  file = options[:input_file]
45
46
  out_file = options[:output_file]
47
+ no_logs = options[:no_logs] || type
46
48
 
47
49
  component_args = []
48
50
  if file
@@ -65,7 +67,9 @@ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
65
67
  error("error: #{res['error_message']}", type)
66
68
  else
67
69
  if type.nil?
68
- display "Request submitted to component ##{res['id']}."
70
+ display "Request submitted to component ##{res['id']}. "
71
+ display "No output file given. Use --output_file to capture raw output" unless out_file
72
+ display "Use --no_logs to skip log output." unless no_logs
69
73
  end
70
74
 
71
75
  if res["execute_ids"]
@@ -87,7 +91,7 @@ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
87
91
  # Sync -- poll until it's done...
88
92
  if res["execute_ids"]
89
93
  run_ids = res["execute_ids"].values
90
- wait_for_results(component_id, run_ids, type, input_par_for_id)
94
+ wait_for_results(component_id, run_ids, type, input_par_for_id, no_logs)
91
95
  end
92
96
  end
93
97
  end
@@ -174,15 +178,26 @@ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
174
178
  private
175
179
 
176
180
 
177
- def wait_for_results(component_id, run_ids, type, input_par_for_id = nil)
181
+ def wait_for_results(component_id, run_ids, type, input_par_for_id = nil, no_logs = false)
182
+
183
+ # Fetch the logs...
184
+ hash = self.api.logs.get(component_id, nil)
185
+ logs = fetch_logs_async(hash, "_ALL_") unless no_logs
186
+
178
187
  while run_ids.length > 0
179
188
  res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
180
189
  if res['error']
181
190
  error("error: #{res['error_message']}", type)
191
+ elsif res['not_found']
192
+ error("Not found.")
182
193
  else
183
194
  res["results"].each do |id, res|
195
+ break if ["not_found", "error"].member?(res["status"].downcase)
184
196
  next if ["running", "waiting"].member?(res["status"].downcase)
185
197
  if type.nil?
198
+ display ""
199
+ display "*"*79
200
+ display
186
201
  display "Query #{input_par_for_id ? input_par_for_id[id] : id}:"
187
202
  if res["data"].size == 0
188
203
  display "\t NO OUTPUT"
@@ -196,6 +211,9 @@ class Zillabyte::Command::RPC < Zillabyte::Command::Flows
196
211
  # poll again
197
212
  sleep(2)
198
213
  end
214
+
215
+ # Terminate logging...
216
+ logs.stop() unless no_logs
199
217
  end
200
218
 
201
219
  def get_run_ids_from_command_line_or_file(file)
@@ -0,0 +1,27 @@
1
+ import zillabyte
2
+
3
+ def prep(controller):
4
+ return
5
+
6
+ # This is the heart of your algorithm. It's processed on every
7
+ # web page. This algorithm is run in parallel on possibly hundreds
8
+ # of machines.
9
+ def execute(controller, tup):
10
+ if("hello world" in tup.values["html"]):
11
+ controller.emit("has_hello_world",{"url":tup.values["url"]})
12
+ return
13
+
14
+ zillabyte.simple_function(\
15
+ # This directive instructs zillabyte to give your function every
16
+ # web page in our known universe. Your function will have access
17
+ # to two fields: URL and HTML
18
+ matches = "select * from web_pa", \
19
+
20
+ # This directive tells Zillabyte what kind of data your function
21
+ # produces. In this case, we're saying we will emit a tuple that
22
+ # is one-column wide and contains the field 'URL'
23
+ emits = [["has_hello_world", [{"url":"string"}]]], \
24
+
25
+ prepare = prep, \
26
+ execute = execute\
27
+ )
@@ -0,0 +1,93 @@
1
+ class LogFetcher
2
+
3
+ def initialize
4
+ require("colorize")
5
+ require("pty")
6
+ @color_map = {}
7
+ @all_colors = [:green, :yellow, :magenta, :cyan, :light_black, :light_green, :light_yellow, :light_blue, :light_magenta, :light_cyan]
8
+ @terminate = false
9
+ @pid = nil
10
+ end
11
+
12
+ def color_for(operation_name)
13
+ @color_map[operation_name] ||= @all_colors[ @color_map.size % @all_colors.size ]
14
+ @color_map[operation_name]
15
+ end
16
+
17
+
18
+
19
+ def run_sync(hash, operation=nil, exit_on=nil)
20
+
21
+ ip = hash["server"] || ENV["ZILLABYTE_API_HOST"] #Quick fix for logs on zilla machines
22
+ exit_on = [exit_on] unless exit_on.is_a?(Array)
23
+
24
+ @color_map = {}
25
+
26
+ if(hash["server"] == "localhost")
27
+ cmd = "tail -n 500 -F /tmp/flows/f#{hash["flow"]}/flow_logs/flow_#{hash["flow"]}.log"
28
+ else
29
+ cmd = "curl -G http://#{hash["flow"]}:#{hash["token"]}@#{ip}:#{hash["port"]}/getLogs?flow=#{hash["flow"]}"
30
+ end
31
+
32
+ begin
33
+ PTY.spawn( cmd ) do |r, w, pid|
34
+ @pid = pid;
35
+ break if @terminate
36
+ r.each do |line|
37
+ begin
38
+ op = line.match(/\[(.*?)\]/)[0].to_s[1...-1]
39
+
40
+ op_name = op.split(".")[0]
41
+ next if op_name != operation and operation != "_ALL_"
42
+ line_split = line.split("[")
43
+ print line_split[0] + "[" + op.colorize(color_for(op)) + line_split[1..-1].join("[")[op.length..-1] unless line.include?("[HIDDEN]")
44
+
45
+ done = false
46
+ exit_on.each do |exit_str|
47
+ if line.include? exit_str
48
+ done = true
49
+ break
50
+ end
51
+ end
52
+ break if done
53
+ rescue Exception => e
54
+ next
55
+ end
56
+ end
57
+ end
58
+ rescue PTY::ChildExited => e
59
+ end
60
+ end
61
+
62
+
63
+ def start_async(hash, operation, exit_on)
64
+
65
+ Signal.trap("SIGINT") do
66
+ self.stop()
67
+ exit()
68
+ end
69
+
70
+ @thread = Thread.new do
71
+ run_sync(hash, operation, exit_on)
72
+ end
73
+ end
74
+
75
+ def stop
76
+ @terminate = true
77
+ Process.kill("SIGKILL", @pid) rescue nil
78
+ end
79
+
80
+
81
+ def self.fetch_logs(hash, operation=nil, exit_on=nil)
82
+ lf = LogFetcher.new
83
+ lf.run_sync(hash, operation, exit_on)
84
+ lf
85
+ end
86
+
87
+ def self.fetch_logs_async(hash, operation=nil, exit_on=nil)
88
+ lf = LogFetcher.new
89
+ lf.start_async(hash, operation, exit_on)
90
+ lf
91
+ end
92
+
93
+ end
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillabyte-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - zillabyte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-02 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: netrc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.7.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.7.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.6.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.6.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: excon
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.31'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.31'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: terminal-table
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activesupport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.2.11
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.2.11
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: multi_json
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '1.3'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: colorize
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0.6'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.6'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: indentation
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0.1'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.1'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: mkfifo
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ! '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ! '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  description: The Official Zillabyte CLI Gem
@@ -173,9 +173,16 @@ executables:
173
173
  extensions: []
174
174
  extra_rdoc_files: []
175
175
  files:
176
+ - Gemfile
177
+ - LICENSE
178
+ - README.md
176
179
  - bin/zb
177
180
  - bin/zbd
178
181
  - bin/zillabyte
182
+ - lib/#zillabyte-cli.rb#
183
+ - lib/zillabyte-cli.rb
184
+ - lib/zillabyte-cli/version.rb
185
+ - lib/zillabyte/api.rb
179
186
  - lib/zillabyte/api/apps.rb
180
187
  - lib/zillabyte/api/base.rb
181
188
  - lib/zillabyte/api/components.rb
@@ -189,8 +196,10 @@ files:
189
196
  - lib/zillabyte/api/settings.rb
190
197
  - lib/zillabyte/api/sources.rb
191
198
  - lib/zillabyte/api/zillalogs.rb
192
- - lib/zillabyte/api.rb
193
199
  - lib/zillabyte/auth.rb
200
+ - lib/zillabyte/cli.rb
201
+ - lib/zillabyte/cli/#logs.rb#
202
+ - lib/zillabyte/cli/#repl.rb#
194
203
  - lib/zillabyte/cli/apps.rb
195
204
  - lib/zillabyte/cli/auth.rb
196
205
  - lib/zillabyte/cli/base.rb
@@ -215,67 +224,69 @@ files:
215
224
  - lib/zillabyte/cli/templates/apps/python/app.py
216
225
  - lib/zillabyte/cli/templates/apps/python/requirements.txt
217
226
  - lib/zillabyte/cli/templates/apps/python/zillabyte.conf.yaml
218
- - lib/zillabyte/cli/templates/apps/ruby/app.rb.erb
219
227
  - lib/zillabyte/cli/templates/apps/ruby/Gemfile
220
228
  - lib/zillabyte/cli/templates/apps/ruby/README.md
229
+ - lib/zillabyte/cli/templates/apps/ruby/app.rb.erb
221
230
  - lib/zillabyte/cli/templates/apps/ruby/zillabyte.conf.yaml
222
231
  - lib/zillabyte/cli/templates/components/js/simple_function.js
223
232
  - lib/zillabyte/cli/templates/components/js/zillabyte.conf.yaml
224
233
  - lib/zillabyte/cli/templates/components/python/component.py
225
234
  - lib/zillabyte/cli/templates/components/python/requirements.txt
226
235
  - lib/zillabyte/cli/templates/components/python/zillabyte.conf.yaml
227
- - lib/zillabyte/cli/templates/components/ruby/component.rb.erb
228
236
  - lib/zillabyte/cli/templates/components/ruby/Gemfile
237
+ - lib/zillabyte/cli/templates/components/ruby/component.rb.erb
229
238
  - lib/zillabyte/cli/templates/components/ruby/zillabyte.conf.yaml
239
+ - lib/zillabyte/cli/templates/python/#simple_function.py#
230
240
  - lib/zillabyte/cli/untitled.md
231
241
  - lib/zillabyte/cli/version.rb
232
242
  - lib/zillabyte/cli/zillalogs.rb
233
- - lib/zillabyte/cli.rb
234
243
  - lib/zillabyte/command.rb
244
+ - lib/zillabyte/common.rb
245
+ - lib/zillabyte/common/log_fetcher.rb
235
246
  - lib/zillabyte/common/session.rb
236
247
  - lib/zillabyte/common/tar.rb
237
- - lib/zillabyte/common.rb
238
248
  - lib/zillabyte/helpers.rb
239
249
  - lib/zillabyte/queries.rb
250
+ - lib/zillabyte/runner.rb
240
251
  - lib/zillabyte/runner/app_runner.rb
241
252
  - lib/zillabyte/runner/component_operation.rb
242
253
  - lib/zillabyte/runner/component_runner.rb
243
254
  - lib/zillabyte/runner/multilang_operation.rb
244
255
  - lib/zillabyte/runner/operation.rb
245
- - lib/zillabyte/runner.rb
246
- - lib/zillabyte-cli/version.rb
247
- - lib/zillabyte-cli.rb
248
- - LICENSE
249
- - README.md
256
+ - zillabyte-cli.gemspec
250
257
  - zillabyte_emails.csv
251
258
  - zillaconf.json
252
- - Gemfile
253
- - zillabyte-cli.gemspec
254
259
  homepage: http://www.zillabyte.com
255
260
  licenses:
256
261
  - MIT
257
262
  metadata: {}
258
- post_install_message: ! "\nGetting Started with Zillabyte\n==============================\n\n(1)
259
- Register for an auth token at http://zillabyte.com\n(2) Log in by running 'zillabyte
260
- login' in the command line\n(3) Build an empty app by running 'zillabyte apps:init'\n
261
- \ Or... check out our Quick Starts by visiting http://docs.zillabyte.com/\n\nQuestions,
262
- comments? Please visit us at http://docs.zillabyte.com\n"
263
+ post_install_message: |2
264
+
265
+ Getting Started with Zillabyte
266
+ ==============================
267
+
268
+ (1) Register for an auth token at http://zillabyte.com
269
+ (2) Log in by running 'zillabyte login' in the command line
270
+ (3) Build an empty app by running 'zillabyte apps:init'
271
+ Or... check out our Quick Starts by visiting http://docs.zillabyte.com/
272
+
273
+ Questions, comments? Please visit us at http://docs.zillabyte.com
263
274
  rdoc_options: []
264
275
  require_paths:
265
276
  - lib
266
277
  required_ruby_version: !ruby/object:Gem::Requirement
267
278
  requirements:
268
- - - ! '>='
279
+ - - ">="
269
280
  - !ruby/object:Gem::Version
270
281
  version: '0'
271
282
  required_rubygems_version: !ruby/object:Gem::Requirement
272
283
  requirements:
273
- - - ! '>='
284
+ - - ">="
274
285
  - !ruby/object:Gem::Version
275
286
  version: '0'
276
287
  requirements: []
277
288
  rubyforge_project:
278
- rubygems_version: 2.0.7
289
+ rubygems_version: 2.2.2
279
290
  signing_key:
280
291
  specification_version: 4
281
292
  summary: The Official Zillabyte CLI Gem