gd_bam 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/bam.orig +369 -0
  2. data/lib/bam/version.rb +1 -1
  3. data/lib/runtime.rb.orig +748 -0
  4. metadata +272 -284
data/bin/bam.orig ADDED
@@ -0,0 +1,369 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'bam'
4
+
5
+ include GLI::App
6
+
7
+ program_desc 'Describe your application here'
8
+
9
+ version Bam::VERSION
10
+
11
+ # desc 'Describe some switch here'
12
+ # switch [:s,:switch]
13
+ #
14
+ desc 'Verbose'
15
+ default_value false
16
+ arg_name 'verbose'
17
+ switch [:v,:verbose]
18
+
19
+ desc 'Http logger'
20
+ default_value false
21
+ arg_name 'logger'
22
+ switch [:l,:logger]
23
+
24
+ desc 'Generates clover project based on information in current directory. The default ouptut is the directory ./clover-project'
25
+ # arg_name 'Describe arguments to new here'
26
+ command :generate do |c|
27
+
28
+ c.desc 'generate only specified flow'
29
+ c.arg_name 'only'
30
+ c.flag :only
31
+
32
+ c.action do |global_options,options,args|
33
+ GoodData::Bam::Commands::clobber_etl_project('.')
34
+ GoodData::Bam::Commands::setup_etl_project('.', PARAMS.merge(options).merge({:project_name => "etl-#{PARAMS[:project_name]}"}))
35
+ GoodData::Bam::Commands::generate('.', PARAMS.merge(options).merge({
36
+ :project_name => "etl-#{PARAMS[:project_name]}",
37
+ :graph_repos => [
38
+ GoodData::Bam::Repository.create(:type => :file, :base => Pathname('./local_graphs').expand_path),
39
+ GoodData::Bam::Repository.create(:type => :file, :base => GoodData::CloverGenerator::BAM_DEFINED_GRAPHS_ROOT)
40
+ ]}))
41
+ end
42
+ end
43
+
44
+ desc 'Jacks into SF.'
45
+ # arg_name 'Describe arguments to new here'
46
+ command :sf_jack_in do |c|
47
+
48
+ c.action do |global_options,options,args|
49
+ GoodData::Bam::Commands::sf_jack_in(PARAMS)
50
+ end
51
+ end
52
+
53
+ desc 'Jacks into project.'
54
+ # arg_name 'Describe arguments to new here'
55
+ command :project_jack_in do |c|
56
+
57
+ c.action do |global_options,options,args|
58
+ GoodData::Bam::Commands::project_jack_in(PARAMS)
59
+ end
60
+ end
61
+
62
+
63
+ desc 'Validatates connection to SalesForce.'
64
+ # arg_name 'Describe arguments to new here'
65
+ command :sf_validate_connection do |c|
66
+
67
+ c.action do |global_options,options,args|
68
+ GoodData::Bam::Commands::sf_validate_connection(PARAMS)
69
+ end
70
+ end
71
+
72
+
73
+ desc 'Generate data validator.'
74
+ # arg_name 'Describe arguments to new here'
75
+ command :generate_validator do |c|
76
+ c.action do |global_options,options,args|
77
+ GoodData::Bam::Commands::generate_validators('.', PARAMS.merge(options).merge({
78
+ :project_name => "validator-#{PARAMS[:project_name]}",
79
+ :graph_repos => [
80
+ GoodData::Bam::Repository.create(:type => :file, :base => './local_graphs'),
81
+ GoodData::Bam::Repository.create(:type => :file, :base => GoodData::CloverGenerator::BAM_DEFINED_GRAPHS_ROOT)
82
+ ]
83
+ }))
84
+ end
85
+ end
86
+
87
+ desc 'Run data validator.'
88
+ # arg_name 'Describe arguments to new here'
89
+ command :run_validator do |c|
90
+
91
+ c.desc 'Checker process ID'
92
+ c.arg_name 'process'
93
+ c.flag :process
94
+
95
+ c.action do |global_options,options,args|
96
+ process = options[:process]
97
+ files = args.map {|f| Pathname(f)}
98
+ files.each do |f|
99
+ fail "Provded file \"#{f}\" does not exist." unless File.exist?(f)
100
+ end
101
+ fail "You need to specify process" if process.blank?
102
+
103
+ GoodData::Bam::Commands::connect_to_gd()
104
+ GoodData::Bam::Commands::run_validator(process, files, PARAMS)
105
+ end
106
+ end
107
+
108
+
109
+ desc 'Generates clover project for downloaders.'
110
+ # arg_name 'Describe arguments to new here'
111
+ command :generate_downloaders do |c|
112
+
113
+ c.desc 's3 backup'
114
+ c.arg_name 'backup'
115
+ c.flag :backup
116
+
117
+ c.action do |global_options,options,args|
118
+ params = global_options[:user_params]
119
+ params = PARAMS.merge({
120
+ :project_name => "downloaders-#{PARAMS[:project_name]}",
121
+ :graph_repos => [
122
+ GoodData::Bam::Repository.create(:type => :file, :base => './local_graphs'),
123
+ GoodData::Bam::Repository.create(:type => :file, :base => GoodData::CloverGenerator::BAM_DEFINED_GRAPHS_ROOT)]
124
+ })
125
+ GoodData::Bam::Commands::generate_downloaders(".", params)
126
+ end
127
+ end
128
+
129
+ desc 'Validates that the tap has the fields it is claimed it should have. This is supposed to make the mitigate errors during deploy.'
130
+ # arg_name 'Describe arguments to new here'
131
+ command :sf_taps_validate do |c|
132
+ c.action do |global_options,options,args|
133
+ verbose = global_options[:v]
134
+ params = PARAMS.merge({
135
+ :graph_repos => [
136
+ GoodData::Bam::Repository.create(:type => :file, :base => './local_graphs'),
137
+ GoodData::Bam::Repository.create(:type => :file, :base => GoodData::CloverGenerator::BAM_DEFINED_GRAPHS_ROOT)]})
138
+ result = GoodData::Bam::Commands::validate_sf_taps(params)
139
+
140
+ error = false
141
+ result.each_pair do |obj, fields|
142
+ if fields.empty?
143
+ puts HighLine::color("GOOD", :green) + " #{obj}"
144
+ else
145
+ error = true
146
+ puts HighLine::color("BAD", :red) + " #{obj} [" + fields.join(', ') + "]"
147
+ end
148
+ end
149
+ exit_now!("Errors found",exit_code=1) if error
150
+ end
151
+ end
152
+
153
+ desc "Prepares params.prm file for debugging that particular graph"
154
+ command :debug do |c|
155
+ c.action do |global_options,options,args|
156
+ fail "Arguments should be passed as \"project\" \"flow\" \"graph\"" if args.length < 3
157
+ GoodData::Bam::Commands::set_up_debug(args.first, args[1], args[2])
158
+ end
159
+ end
160
+
161
+ desc 'Validates that the tap has the fields it is claimed it should have. This is supposed to make the mitigate errors during deploy.'
162
+ # arg_name 'Describe arguments to new here'
163
+ command :docs do |c|
164
+ c.action do |global_options,options,args|
165
+ GoodData::Bam::Commands::generate_docs
166
+ end
167
+ end
168
+
169
+ desc 'Lists processes for the project.'
170
+ # arg_name 'Describe arguments to new here'
171
+ command :procs do |c|
172
+
173
+ c.desc 'procs for all projects'
174
+ c.arg_name 'all'
175
+ c.switch :all
176
+
177
+ c.action do |global_options,options,args|
178
+ out = GoodData::Bam::Commands::procs_list(options)
179
+ out.each do |proc|
180
+ puts proc.join(',')
181
+ end
182
+ end
183
+ end
184
+
185
+
186
+ desc 'Creates project'
187
+ command :project do |c|
188
+
189
+ c.desc 'blueprint name. Currently support goodsales'
190
+ c.arg_name 'blueprint'
191
+ c.flag :blueprint
192
+
193
+ c.desc 'token'
194
+ c.arg_name 'token'
195
+ c.flag :token
196
+
197
+ c.action do |global_options,options,args|
198
+ fail "You need to specify token to create a project" if options[:token].nil?
199
+
200
+ GoodData::Bam::Commands::connect_to_gd()
201
+ pid = case options[:blueprint]
202
+ when "goodsales"
203
+ "nt935rwzls50zfqwy6dh62tabu8h0ocy"
204
+ end
205
+
206
+ params = PARAMS.merge({:token => options[:token]})
207
+
208
+ new_project = if pid
209
+ GoodData::Bam::Commands.clone_project(pid, params)
210
+ else
211
+ GoodData::Bam::Commands.create_project(params)
212
+ end
213
+
214
+ puts "Your project pid is #{new_project}"
215
+ end
216
+
217
+ end
218
+
219
+
220
+ desc 'Generates structures'
221
+ arg_name 'what you want to generate project, tap, flow, sink'
222
+ command :scaffold do |c|
223
+
224
+ c.desc 'blueprint name. Currently support goodsales'
225
+ c.arg_name 'blueprint'
226
+ c.flag :blueprint
227
+
228
+ c.desc 'from dataset'
229
+ c.arg_name 'from dataset'
230
+ c.flag :from_dataset
231
+
232
+ c.action do |global_options,options,args|
233
+ command = args.first
234
+ fail "You did not provide what I should scaffold. I can generate project, tap, flow, sink, graph_template nothing else" unless ["project", "tap", "flow", "sink", "graph_template"].include?(command)
235
+ case command
236
+ when "project"
237
+ directory = args[1]
238
+ fail "Directory has to be provided as an argument. See help" if directory.nil?
239
+ if options[:blueprint].nil?
240
+ GoodData::Bam::Commands::setup_bash_structure(directory)
241
+ else
242
+ case options[:blueprint]
243
+ when "goodsales"
244
+ system "git clone git://github.com/gooddata/goodsales_base.git #{directory}"
245
+ end
246
+ end
247
+ when "flow"
248
+ name = args[1]
249
+ fail "Name of the flow has to be provided as an argument. See help" if name.nil?
250
+ GoodData::Bam::Commands::setup_flow(name)
251
+ when "tap"
252
+ name = args[1]
253
+ fail "Name of the tap has to be provided as an argument. See help" if name.nil?
254
+ GoodData::Bam::Commands::setup_tap(name)
255
+ when "sink"
256
+ <<<<<<< Updated upstream
257
+ name = args[1]
258
+ fail "Name of the sink has to be provided as an argument. See help" if name.nil?
259
+ GoodData::Bam::Commands::setup_sink(name)
260
+ =======
261
+ # name = args[1]
262
+ # fail "Name of the sink has to be provided as an argument. See help" if name.nil?
263
+ # GoodData::CloverGenerator.setup_sink(name)
264
+
265
+ dataset_name = options[:from_dataset]
266
+ GoodData::CloverGenerator.connect_to_gd()
267
+ sets = GoodData.get("/gdc/md/#{PARAMS[]}/data/sets")
268
+ dataset = sets['dataSetsInfo']['sets'].find {|ds| ds['meta']['title'] == dataset_name}
269
+
270
+ binding.pry
271
+ >>>>>>> Stashed changes
272
+ when "graph_template"
273
+ name = args[1]
274
+ target = args[2]
275
+ fail "Name of the template has to be provided as an argument. See help" if name.nil?
276
+ fail "Name of the target has to be provided as an argument. See help" if target.nil?
277
+ GoodData::Bam::Commands::generate_graph_template(name, target)
278
+ end
279
+ end
280
+ end
281
+
282
+ desc 'Runs the project on server'
283
+ command :model_sync do |c|
284
+
285
+ c.desc 'do not execute'
286
+ c.arg_name 'dry'
287
+ c.switch :dry
288
+
289
+ c.action do |global_options,options,args|
290
+ GoodData::Bam::Commands::model_sync(options)
291
+ end
292
+ end
293
+
294
+
295
+ desc 'Deploys the project on server and schedules it'
296
+ command :deploy do |c|
297
+
298
+ c.desc 'existing process id under which it is going to be redeployed'
299
+ c.arg_name 'process'
300
+ c.flag :process
301
+
302
+ c.desc 'name of the process'
303
+ c.arg_name 'name'
304
+ c.flag :name
305
+
306
+ c.action do |global_options,options,args|
307
+ dir = args.first
308
+ fail "You have to specify directory to deploy as an argument" if dir.nil?
309
+ fail "Specified directory does not exist" unless File.exist?(dir)
310
+
311
+ GoodData::Bam::Commands::connect_to_gd()
312
+ options = global_options.merge(options)
313
+ response = GoodData::Bam::Commands::deploy(dir, options)
314
+ end
315
+ end
316
+
317
+ desc 'Runs the project on server'
318
+ command :run do |c|
319
+
320
+ c.desc 'email to addresses when the run is finished'
321
+ c.arg_name 'email'
322
+ c.flag :email
323
+
324
+ c.action do |global_options,options,args|
325
+
326
+ dir = args.first
327
+ fail "You have to specify directory to deploy as an argument" if dir.nil?
328
+ fail "Specified directory does not exist" unless File.exist?(dir)
329
+
330
+ options = global_options.merge(options)
331
+ GoodData::Bam::Commands::connect_to_gd()
332
+ GoodData::Bam::Commands::run(dir, options)
333
+ end
334
+ end
335
+
336
+
337
+ pre do |global_options,command,options,args|
338
+
339
+ logger = Logger.new(STDOUT) if global_options[:l]
340
+ GoodData.logger = logger
341
+ params = GoodData::Bam::Utils::get_user_params('.')
342
+ s3_backup = GoodData::Bam::Utils::should_backup_to_s3?(params)
343
+ PARAMS = params.merge({:s3_backup => s3_backup})
344
+
345
+ # Pre logic here
346
+ # Return true to proceed; false to abort and not call the
347
+ # chosen command
348
+ # Use skips_pre before a command to skip this block
349
+ # on that command only
350
+
351
+ true
352
+ end
353
+
354
+ post do |global_options,command,options,args|
355
+ # Post logic here
356
+ # Use skips_post before a command to skip this
357
+ # block on that command only
358
+ verbose = global_options[:v]
359
+ puts HighLine::color("DONE", :green) if verbose
360
+ end
361
+
362
+ on_error do |exception|
363
+ pp exception.backtrace
364
+ # Error logic here
365
+ # return false to skip default error handling
366
+ true
367
+ end
368
+
369
+ exit run(ARGV)
data/lib/bam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bam
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end