zillabyte-cli 0.0.24 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +6 -14
  2. data/lib/#zillabyte-cli.rb# +5 -0
  3. data/lib/zillabyte/api/apps.rb +16 -132
  4. data/lib/zillabyte/api/components.rb +115 -0
  5. data/lib/zillabyte/api/flows.rb +121 -0
  6. data/lib/zillabyte/api/keys.rb +70 -0
  7. data/lib/zillabyte/api.rb +15 -2
  8. data/lib/zillabyte/auth.rb +43 -16
  9. data/lib/zillabyte/cli/#logs.rb# +12 -0
  10. data/lib/zillabyte/cli/#repl.rb# +43 -0
  11. data/lib/zillabyte/cli/apps.rb +52 -893
  12. data/lib/zillabyte/cli/auth.rb +3 -8
  13. data/lib/zillabyte/cli/base.rb +28 -7
  14. data/lib/zillabyte/cli/components.rb +245 -0
  15. data/lib/zillabyte/cli/flows.rb +549 -0
  16. data/lib/zillabyte/cli/git.rb +38 -0
  17. data/lib/zillabyte/cli/help.rb +11 -4
  18. data/lib/zillabyte/cli/keys.rb +177 -0
  19. data/lib/zillabyte/cli/query.rb +0 -1
  20. data/lib/zillabyte/cli/relations.rb +2 -1
  21. data/lib/zillabyte/cli/templates/{js → apps/js}/simple_function.js +0 -0
  22. data/lib/zillabyte/cli/templates/{js → apps/js}/zillabyte.conf.yaml +0 -0
  23. data/lib/zillabyte/cli/templates/apps/python/app.py +17 -0
  24. data/lib/zillabyte/cli/templates/{python → apps/python}/requirements.txt +0 -0
  25. data/lib/zillabyte/cli/templates/{python → apps/python}/zillabyte.conf.yaml +1 -1
  26. data/lib/zillabyte/cli/templates/{ruby → apps/ruby}/Gemfile +0 -0
  27. data/lib/zillabyte/cli/templates/{ruby → apps/ruby}/app.rb +1 -1
  28. data/lib/zillabyte/cli/templates/{ruby → apps/ruby}/zillabyte.conf.yaml +0 -0
  29. data/lib/zillabyte/cli/templates/python/{simple_function.py → #simple_function.py#} +3 -6
  30. data/lib/zillabyte/common/session.rb +3 -1
  31. data/lib/zillabyte/helpers.rb +64 -1
  32. data/lib/zillabyte/runner/app_runner.rb +226 -0
  33. data/lib/zillabyte/runner/component_operation.rb +529 -0
  34. data/lib/zillabyte/runner/component_runner.rb +244 -0
  35. data/lib/zillabyte/runner/multilang_operation.rb +1133 -0
  36. data/lib/zillabyte/runner/operation.rb +11 -0
  37. data/lib/zillabyte/runner.rb +6 -0
  38. data/lib/zillabyte-cli/version.rb +1 -1
  39. data/zillabyte-cli.gemspec +1 -0
  40. metadata +83 -52
@@ -10,22 +10,17 @@ class Zillabyte::Command::Auth < Zillabyte::Command::Base
10
10
 
11
11
  # auth:login
12
12
  #
13
- # sets the Zillabyte auth token
13
+ # set the authentication token
14
14
  #
15
- # --auth_token TOKEN # provide the token
16
15
  def login
17
- if options[:auth_token]
18
- Zillabyte::Auth.login( options[:auth_token])
19
- else
20
- Zillabyte::Auth.ask_for_and_save_credentials
21
- end
16
+ Zillabyte::Auth.ask_for_and_save_credentials
22
17
  end
23
18
 
24
19
  alias_command "login", "auth:login"
25
20
 
26
21
  # auth:logout
27
22
  #
28
- # sets the Zillabyte auth token
23
+ # clear the authentication token
29
24
  #
30
25
  def logout
31
26
  Zillabyte::Auth.logout
@@ -3,8 +3,8 @@ require "zillabyte/api"
3
3
  require "zillabyte/command"
4
4
  require "action_view"
5
5
 
6
- class Zillabyte::Command::Base
7
- include Zillabyte::Helpers
6
+ class Zillabyte::Command::Base
7
+ include Zillabyte::Helpers
8
8
  include ActionView::Helpers::DateHelper
9
9
 
10
10
  def self.namespace
@@ -19,8 +19,12 @@ class Zillabyte::Command::Base
19
19
  @options = options
20
20
  end
21
21
 
22
+ def api
23
+ @__api ||= Zillabyte::API.new(:api_key => Zillabyte::Auth.api_key, :session => self)
24
+ end
25
+
22
26
 
23
- protected
27
+ protected
24
28
 
25
29
  def self.inherited(klass)
26
30
  unless klass == Zillabyte::Command::Base
@@ -140,10 +144,27 @@ protected
140
144
  Zillabyte::Command.validate_arguments!
141
145
  end
142
146
 
143
- def api
144
- @__api ||= Zillabyte::API.new(:api_key => Zillabyte::Auth.api_key, :session => self)
145
- end
146
-
147
+
148
+ def git_remotes(base_dir=Dir.pwd)
149
+ remotes = {}
150
+ original_dir = Dir.pwd
151
+ Dir.chdir(base_dir)
152
+
153
+ return unless File.exists?(".git")
154
+ git("remote -v").split("\n").each do |remote|
155
+ name, url, method = remote.split(/\s/)
156
+ if url =~ /^git@#{Zillabyte::Auth.git_host}(?:[\.\w]*):([\w\d-]+)\.git$/
157
+ remotes[name] = $1
158
+ end
159
+ end
160
+
161
+ Dir.chdir(original_dir)
162
+ if remotes.empty?
163
+ nil
164
+ else
165
+ remotes
166
+ end
167
+ end
147
168
 
148
169
 
149
170
  def session
@@ -0,0 +1,245 @@
1
+ require 'yaml'
2
+ require "zillabyte/cli/flows"
3
+ require "zillabyte/cli/config"
4
+ require "zillabyte/common"
5
+
6
+ # manage custom components
7
+ #
8
+ class Zillabyte::Command::Components < Zillabyte::Command::Flows
9
+
10
+ # components
11
+ #
12
+ # list custom components
13
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
14
+ #
15
+ def index
16
+ self.list
17
+ end
18
+
19
+
20
+
21
+ # components
22
+ #
23
+ # list custom components
24
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
25
+ def list
26
+ type = options[:output_type]
27
+
28
+ headings = ["id", "name", "state", "inputs", "outputs"]
29
+ rows = api.component.list.map do |row|
30
+ if headings.size == 0
31
+ headings = row.keys
32
+ headings.delete("rel_dir")
33
+ end
34
+
35
+ v = row.values_at *headings
36
+ v
37
+ end
38
+
39
+ display "components:\n" if type.nil?
40
+ display TableOutputBuilder.build_table(headings, rows, type)
41
+ display "Total number of components: " + rows.length.to_s if type.nil?
42
+ end
43
+
44
+
45
+ # components:pull ID DIR
46
+ #
47
+ # pulls a component source to a directory.
48
+ #
49
+ # --force # pulls even if the directory exists
50
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
51
+ # --directory DIR # Directory of the component
52
+ #
53
+ # Examples:
54
+ #
55
+ # $ zillabyte components:pull .
56
+ #
57
+ def pull
58
+ super
59
+ end
60
+
61
+ # components:status [DIR]
62
+ #
63
+ # fetches detailed status of the component
64
+ #
65
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
66
+ # --directory DIR # Directory of the component
67
+ #
68
+ def status
69
+ super
70
+ end
71
+
72
+
73
+
74
+ # components:delete ID
75
+ #
76
+ # deletes a component.
77
+ #
78
+ # -f, --force # don't ask for confirmation
79
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
80
+ #
81
+ def delete
82
+ super
83
+ end
84
+
85
+ # components:kill ID
86
+ #
87
+ # kills the given component rpc
88
+ #
89
+ # --config CONFIG_FILE # use the given config file
90
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
91
+ #
92
+ def kill
93
+ id = options[:id] || shift_argument
94
+ type = options[:output_type]
95
+
96
+ if id.nil?
97
+ id = read_name_from_conf(options)
98
+ options[:is_name] = true
99
+ elsif !(id =~ /^\d*$/)
100
+ options[:is_name] = true
101
+ end
102
+
103
+ display "Killing component ##{id}...please wait..." if type.nil?
104
+ api.components.kill(id, options)
105
+
106
+ if type == "json"
107
+ display "{}"
108
+ else
109
+ display "Component ##{id} killed"
110
+ end
111
+ end
112
+
113
+ # components:info [DIR]
114
+ #
115
+ # outputs the info for the component in the dir.
116
+ #
117
+ # --pretty # Pretty prints the info output
118
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
119
+ # --directory DIR # Directory of the component
120
+ #
121
+ def info
122
+ super
123
+ end
124
+
125
+
126
+ # components:test
127
+ #
128
+ # tests a local component with sample data
129
+ #
130
+ # --config CONFIG_FILE # use the given config file
131
+ # --input INPUT_FILE # uses a CSV for component input
132
+ # --output OUTPUT_FILE # write output to a CSV
133
+ # --directory DIR # app directory
134
+ #
135
+ def test
136
+ super
137
+ end
138
+
139
+ # components:prep [DIR]
140
+ #
141
+ # performs any necessary initialization for the component
142
+ #
143
+ # --directory DIR # component directory
144
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
145
+ #
146
+ def prep
147
+ super
148
+ end
149
+
150
+ # components:errors ID
151
+ #
152
+ # show recent errors generated by the componeny rpc
153
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
154
+ #
155
+ def errors
156
+ super
157
+ end
158
+
159
+ # components:live_run [OPERATION_NAME] [PIPE_NAME] [DIR]
160
+ #
161
+ # runs a local component with live data
162
+ #
163
+ # --config CONFIG_FILE # use the given config file
164
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
165
+ # --directory DIR # Directory of the component
166
+ #
167
+ # HIDDEN:
168
+ def live_run
169
+ super
170
+ end
171
+
172
+ # components:rpc [ID] [QUERY_1_INPUT_1,QUERY_1_INPUT_2,...] [QUERY_2_INPUT_1,QUERY_2_INPUT_2,...], ...
173
+ #
174
+ # runs a component as an rpc
175
+ #
176
+ # --output_type OUTPUT_TYPE # specify an output type i.e. json
177
+ def rpc
178
+ component_id = options[:id] || shift_argument
179
+
180
+ if component_id.nil?
181
+ component_id = read_name_from_conf(options)
182
+ options[:is_name] = true
183
+ elsif !(component_id =~ /^\d*$/)
184
+ options[:is_name] = true
185
+ end
186
+
187
+ type = options[:output_type]
188
+
189
+ component_args = []
190
+ while(true) do
191
+ next_arg = shift_argument
192
+ break if next_arg.nil?
193
+ component_args << next_arg.split(",")
194
+ end
195
+
196
+ res = api.components.rpc(component_id, {:rpc_inputs => component_args})
197
+ if res['error']
198
+ error("error: #{res['error_message']}", type)
199
+ else
200
+ if type.nil?
201
+ display "Request submitted to component ##{res['id']}. The run ids are (query: run_id):"
202
+ res["execute_ids"].each do |pars, id|
203
+ display "\t #{pars}: #{id}"
204
+ end
205
+ 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."
206
+ end
207
+ end
208
+ end
209
+
210
+ # components:results [ID] [RUN_ID]
211
+ #
212
+ # gets the result of an rpc request if it is done running, otherwise gets current run status
213
+ #
214
+ def results
215
+ component_id = options[:id] || shift_argument
216
+
217
+ if component_id.nil?
218
+ component_id = read_name_from_conf(options)
219
+ options[:is_name] = true
220
+ elsif !(component_id =~ /^\d*$/)
221
+ options[:is_name] = true
222
+ end
223
+
224
+ type = options[:output_type]
225
+
226
+ run_ids = []
227
+ while(true) do
228
+ next_arg = shift_argument
229
+ break if next_arg.nil?
230
+ run_ids << next_arg
231
+ end
232
+
233
+ res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
234
+ if res['error']
235
+ error("error: #{res['error_message']}", type)
236
+ else
237
+ if type.nil?
238
+ res["results"].each do |id, hash|
239
+ display "#{id}: #{hash["status"]}"
240
+ display "\t #{hash["data"]}" if hash["status"] == "complete"
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end