mortar 0.15.19 → 0.15.20
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.
- data/lib/mortar/command/local.rb +5 -5
- data/lib/mortar/local/controller.rb +14 -12
- data/lib/mortar/project.rb +0 -4
- data/lib/mortar/version.rb +1 -1
- data/spec/mortar/command/local_spec.rb +7 -7
- data/spec/mortar/local/controller_spec.rb +24 -1
- metadata +8 -12
- data/lib/mortar/command/fixtures.rb +0 -100
- data/lib/mortar/templates/characterize/fixtures/gitkeep +0 -0
- data/lib/mortar/templates/project/fixtures/gitkeep +0 -0
- data/spec/mortar/command/fixtures_spec.rb +0 -136
data/lib/mortar/command/local.rb
CHANGED
@@ -40,7 +40,7 @@ class Mortar::Command::Local < Mortar::Command::Base
|
|
40
40
|
Dir.chdir(project_root)
|
41
41
|
|
42
42
|
ctrl = Mortar::Local::Controller.new
|
43
|
-
ctrl.install_and_configure(pig_version)
|
43
|
+
ctrl.install_and_configure(pig_version, nil, true)
|
44
44
|
end
|
45
45
|
|
46
46
|
# local:run SCRIPT
|
@@ -253,7 +253,7 @@ class Mortar::Command::Local < Mortar::Command::Base
|
|
253
253
|
ctrl = Mortar::Local::Controller.new
|
254
254
|
luigi_params = pig_parameters.sort_by { |p| p['name'] }
|
255
255
|
luigi_params = luigi_params.map { |arg| ["--#{arg['name']}", "#{arg['value']}"] }.flatten
|
256
|
-
ctrl.run_luigi(script, luigi_params)
|
256
|
+
ctrl.run_luigi(pig_version, script, luigi_params)
|
257
257
|
end
|
258
258
|
|
259
259
|
# local:sqoop_table dbtype database-name table s3-destination
|
@@ -294,7 +294,7 @@ class Mortar::Command::Local < Mortar::Command::Base
|
|
294
294
|
connstr = jdbc_conn(dbtype, dbhost, physdb)
|
295
295
|
|
296
296
|
ctrl = Mortar::Local::Controller.new
|
297
|
-
ctrl.sqoop_export_table(connstr, dbtable, s3dest, options)
|
297
|
+
ctrl.sqoop_export_table(pig_version, connstr, dbtable, s3dest, options)
|
298
298
|
end
|
299
299
|
|
300
300
|
# local:sqoop_query dbtype database-name query s3-destination
|
@@ -335,7 +335,7 @@ class Mortar::Command::Local < Mortar::Command::Base
|
|
335
335
|
connstr = jdbc_conn(dbtype, dbhost, physdb)
|
336
336
|
|
337
337
|
ctrl = Mortar::Local::Controller.new
|
338
|
-
ctrl.sqoop_export_query(connstr, query, s3dest, options)
|
338
|
+
ctrl.sqoop_export_query(pig_version, connstr, query, s3dest, options)
|
339
339
|
end
|
340
340
|
|
341
341
|
# local:sqoop_incremental dbtype database-name table column value s3-destination
|
@@ -384,7 +384,7 @@ class Mortar::Command::Local < Mortar::Command::Base
|
|
384
384
|
connstr = jdbc_conn(dbtype, dbhost, physdb)
|
385
385
|
|
386
386
|
ctrl = Mortar::Local::Controller.new
|
387
|
-
ctrl.sqoop_export_incremental(connstr, table, column, max_value, s3dest, options)
|
387
|
+
ctrl.sqoop_export_incremental(pig_version, connstr, table, column, max_value, s3dest, options)
|
388
388
|
end
|
389
389
|
|
390
390
|
|
@@ -114,11 +114,12 @@ EOF
|
|
114
114
|
|
115
115
|
# Main entry point to perform installation and configuration necessary
|
116
116
|
# to run pig on the users local machine
|
117
|
-
def install_and_configure(pig_version=nil, command=nil)
|
117
|
+
def install_and_configure(pig_version=nil, command=nil, install_sqoop=false)
|
118
118
|
#To support old watchtower plugins we'll accept nil pig_version
|
119
119
|
if pig_version.nil?
|
120
120
|
pig_version = Mortar::PigVersion::Pig09.new
|
121
121
|
end
|
122
|
+
|
122
123
|
java = Mortar::Local::Java.new()
|
123
124
|
unless java.check_install
|
124
125
|
error(NO_JAVA_ERROR_MESSAGE)
|
@@ -145,9 +146,10 @@ EOF
|
|
145
146
|
jy = Mortar::Local::Jython.new()
|
146
147
|
jy.install_or_update()
|
147
148
|
|
148
|
-
|
149
|
-
|
150
|
-
|
149
|
+
if install_sqoop
|
150
|
+
sqoop = Mortar::Local::Sqoop.new()
|
151
|
+
sqoop.install_or_update()
|
152
|
+
end
|
151
153
|
|
152
154
|
ensure_local_install_dirs_in_gitignore
|
153
155
|
end
|
@@ -205,31 +207,31 @@ EOF
|
|
205
207
|
pig.launch_repl(pig_version, pig_parameters)
|
206
208
|
end
|
207
209
|
|
208
|
-
def run_luigi(luigi_script, user_script_args)
|
209
|
-
install_and_configure(
|
210
|
+
def run_luigi(pig_version, luigi_script, user_script_args)
|
211
|
+
install_and_configure(pig_version, 'luigi')
|
210
212
|
py = Mortar::Local::Python.new()
|
211
213
|
py.run_luigi_script(luigi_script, user_script_args)
|
212
214
|
end
|
213
215
|
|
214
|
-
def sqoop_export_table(connstr, dbtable, s3dest, options)
|
216
|
+
def sqoop_export_table(pig_version, connstr, dbtable, s3dest, options)
|
215
217
|
require_aws_keys
|
216
|
-
install_and_configure(
|
218
|
+
install_and_configure(pig_version, 'sqoop', true)
|
217
219
|
sqoop = Mortar::Local::Sqoop.new()
|
218
220
|
options[:dbtable] = dbtable
|
219
221
|
sqoop.export(connstr, s3dest, options)
|
220
222
|
end
|
221
223
|
|
222
|
-
def sqoop_export_query(connstr, query, s3dest, options)
|
224
|
+
def sqoop_export_query(pig_version, connstr, query, s3dest, options)
|
223
225
|
require_aws_keys
|
224
|
-
install_and_configure(
|
226
|
+
install_and_configure(pig_version, 'sqoop', true)
|
225
227
|
sqoop = Mortar::Local::Sqoop.new()
|
226
228
|
options[:sqlquery] = sqoop.prep_query(query)
|
227
229
|
sqoop.export(connstr, s3dest, options)
|
228
230
|
end
|
229
231
|
|
230
|
-
def sqoop_export_incremental(connstr, dbtable, column, max_value, s3dest, options)
|
232
|
+
def sqoop_export_incremental(pig_version, connstr, dbtable, column, max_value, s3dest, options)
|
231
233
|
require_aws_keys
|
232
|
-
install_and_configure(
|
234
|
+
install_and_configure(pig_version, 'sqoop', true)
|
233
235
|
sqoop = Mortar::Local::Sqoop.new()
|
234
236
|
options[:dbtable] = dbtable
|
235
237
|
options[:inc_column] = column
|
data/lib/mortar/project.rb
CHANGED
data/lib/mortar/version.rb
CHANGED
@@ -299,7 +299,7 @@ STDERR
|
|
299
299
|
mock(u).run_luigi_script(luigi_script, %W{--myoption 2 --myotheroption 3})
|
300
300
|
end
|
301
301
|
any_instance_of(Mortar::Local::Controller) do |u|
|
302
|
-
mock(u).install_and_configure(
|
302
|
+
mock(u).install_and_configure(is_a(Mortar::PigVersion::Pig09),'luigi')
|
303
303
|
end
|
304
304
|
stderr, stdout = execute("local:luigi some_luigi_script -p myoption=2 -p myotheroption=3", p)
|
305
305
|
stderr.should == ""
|
@@ -347,7 +347,7 @@ STDERR
|
|
347
347
|
dbtable = "customers"
|
348
348
|
s3dest = "s3n://a-bucket/a-directory"
|
349
349
|
any_instance_of(Mortar::Local::Controller) do |c|
|
350
|
-
mock(c).sqoop_export_table(connstr, dbtable, s3dest, {})
|
350
|
+
mock(c).sqoop_export_table(is_a(Mortar::PigVersion::Pig09), connstr, dbtable, s3dest, {:host => "foobar.com"})
|
351
351
|
end
|
352
352
|
stderr, stdout = execute "local:sqoop_table mysql mydb #{dbtable} #{s3dest} --host foobar.com"
|
353
353
|
end
|
@@ -357,7 +357,7 @@ STDERR
|
|
357
357
|
dbtable = "customers"
|
358
358
|
s3dest = "s3n://a-bucket/a-directory"
|
359
359
|
any_instance_of(Mortar::Local::Controller) do |c|
|
360
|
-
mock(c).sqoop_export_table(connstr, dbtable, s3dest, {})
|
360
|
+
mock(c).sqoop_export_table(is_a(Mortar::PigVersion::Pig09), connstr, dbtable, s3dest, {})
|
361
361
|
end
|
362
362
|
stderr, stdout = execute "local:sqoop_table mysql mydb #{dbtable} #{s3dest}"
|
363
363
|
end
|
@@ -402,7 +402,7 @@ STDERR
|
|
402
402
|
query = "select_*_from_customers"
|
403
403
|
s3dest = "s3n://a-bucket/a-directory"
|
404
404
|
any_instance_of(Mortar::Local::Controller) do |c|
|
405
|
-
mock(c).sqoop_export_query(connstr, query, s3dest, {})
|
405
|
+
mock(c).sqoop_export_query(is_a(Mortar::PigVersion::Pig09), connstr, query, s3dest, {:host => "foobar.com"})
|
406
406
|
end
|
407
407
|
stderr, stdout = execute "local:sqoop_query mysql mydb #{query} #{s3dest} --host foobar.com"
|
408
408
|
stderr.should == ''
|
@@ -413,7 +413,7 @@ STDERR
|
|
413
413
|
query = "select_*_from_customers"
|
414
414
|
s3dest = "s3n://a-bucket/a-directory"
|
415
415
|
any_instance_of(Mortar::Local::Controller) do |c|
|
416
|
-
mock(c).sqoop_export_query(connstr, query, s3dest, {})
|
416
|
+
mock(c).sqoop_export_query(is_a(Mortar::PigVersion::Pig09), connstr, query, s3dest, {})
|
417
417
|
end
|
418
418
|
stderr, stdout = execute "local:sqoop_query mysql mydb #{query} #{s3dest}"
|
419
419
|
stderr.should == ''
|
@@ -477,7 +477,7 @@ STDERR
|
|
477
477
|
column_value = "12345"
|
478
478
|
s3dest = "s3n://a-bucket/a-directory"
|
479
479
|
any_instance_of(Mortar::Local::Controller) do |c|
|
480
|
-
mock(c).sqoop_export_incremental(connstr, dbtable, column, column_value, s3dest, {})
|
480
|
+
mock(c).sqoop_export_incremental(is_a(Mortar::PigVersion::Pig09), connstr, dbtable, column, column_value, s3dest, {:host => "foobar.com"})
|
481
481
|
end
|
482
482
|
stderr, stdout = execute "local:sqoop_incremental mysql mydb #{dbtable} #{column} #{column_value} #{s3dest} --host foobar.com"
|
483
483
|
end
|
@@ -489,7 +489,7 @@ STDERR
|
|
489
489
|
column_value = "12345"
|
490
490
|
s3dest = "s3n://a-bucket/a-directory"
|
491
491
|
any_instance_of(Mortar::Local::Controller) do |c|
|
492
|
-
mock(c).sqoop_export_incremental(connstr, dbtable, column, column_value, s3dest, {})
|
492
|
+
mock(c).sqoop_export_incremental(is_a(Mortar::PigVersion::Pig09), connstr, dbtable, column, column_value, s3dest, {})
|
493
493
|
end
|
494
494
|
stderr, stdout = execute "local:sqoop_incremental mysql mydb #{dbtable} #{column} #{column_value} #{s3dest}"
|
495
495
|
end
|
@@ -146,12 +146,35 @@ module Mortar::Local
|
|
146
146
|
any_instance_of(Mortar::Local::Jython) do |j|
|
147
147
|
mock(j).install_or_update
|
148
148
|
end
|
149
|
+
|
150
|
+
mock(ctrl).ensure_local_install_dirs_in_gitignore
|
151
|
+
ctrl.install_and_configure
|
152
|
+
end
|
153
|
+
|
154
|
+
it "install sqoop with command" do
|
155
|
+
command = 'command'
|
156
|
+
ctrl = Mortar::Local::Controller.new
|
157
|
+
|
158
|
+
any_instance_of(Mortar::Local::Java) do |j|
|
159
|
+
mock(j).check_install.returns(true)
|
160
|
+
end
|
161
|
+
any_instance_of(Mortar::Local::Pig) do |p|
|
162
|
+
mock(p).install_or_update(is_a(Mortar::PigVersion::Pig012), command)
|
163
|
+
end
|
164
|
+
any_instance_of(Mortar::Local::Python) do |p|
|
165
|
+
mock(p).check_or_install.returns(true)
|
166
|
+
mock(p).check_virtualenv.returns(true)
|
167
|
+
mock(p).setup_project_python_environment.returns(true)
|
168
|
+
end
|
169
|
+
any_instance_of(Mortar::Local::Jython) do |j|
|
170
|
+
mock(j).install_or_update
|
171
|
+
end
|
149
172
|
any_instance_of(Mortar::Local::Sqoop) do |s|
|
150
173
|
mock(s).install_or_update
|
151
174
|
end
|
152
175
|
|
153
176
|
mock(ctrl).ensure_local_install_dirs_in_gitignore
|
154
|
-
ctrl.install_and_configure
|
177
|
+
ctrl.install_and_configure(Mortar::PigVersion::Pig012.new, command, true)
|
155
178
|
end
|
156
179
|
end
|
157
180
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mortar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.8.
|
37
|
+
version: 0.8.4
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.8.
|
45
|
+
version: 0.8.4
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: netrc
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,17 +208,17 @@ dependencies:
|
|
208
208
|
requirement: !ruby/object:Gem::Requirement
|
209
209
|
none: false
|
210
210
|
requirements:
|
211
|
-
- -
|
211
|
+
- - ~>
|
212
212
|
- !ruby/object:Gem::Version
|
213
|
-
version: '0'
|
213
|
+
version: '2.0'
|
214
214
|
type: :development
|
215
215
|
prerelease: false
|
216
216
|
version_requirements: !ruby/object:Gem::Requirement
|
217
217
|
none: false
|
218
218
|
requirements:
|
219
|
-
- -
|
219
|
+
- - ~>
|
220
220
|
- !ruby/object:Gem::Version
|
221
|
-
version: '0'
|
221
|
+
version: '2.0'
|
222
222
|
description: Client library and command-line tool to interact with the Mortar service.
|
223
223
|
email: support@mortardata.com
|
224
224
|
executables:
|
@@ -245,7 +245,6 @@ files:
|
|
245
245
|
- lib/mortar/command/clusters.rb
|
246
246
|
- lib/mortar/command/config.rb
|
247
247
|
- lib/mortar/command/describe.rb
|
248
|
-
- lib/mortar/command/fixtures.rb
|
249
248
|
- lib/mortar/command/generate.rb
|
250
249
|
- lib/mortar/command/help.rb
|
251
250
|
- lib/mortar/command/illustrate.rb
|
@@ -282,7 +281,6 @@ files:
|
|
282
281
|
- lib/mortar/templates/characterize/README.md
|
283
282
|
- lib/mortar/templates/characterize/controlscripts/lib/__init__.py
|
284
283
|
- lib/mortar/templates/characterize/controlscripts/lib/characterize_control.py
|
285
|
-
- lib/mortar/templates/characterize/fixtures/gitkeep
|
286
284
|
- lib/mortar/templates/characterize/gitignore
|
287
285
|
- lib/mortar/templates/characterize/macros/characterize_macro.pig
|
288
286
|
- lib/mortar/templates/characterize/macros/gitkeep
|
@@ -304,7 +302,6 @@ files:
|
|
304
302
|
- lib/mortar/templates/pigscript/python_udf.py
|
305
303
|
- lib/mortar/templates/project/README.md
|
306
304
|
- lib/mortar/templates/project/controlscripts/lib/__init__.py
|
307
|
-
- lib/mortar/templates/project/fixtures/gitkeep
|
308
305
|
- lib/mortar/templates/project/gitignore
|
309
306
|
- lib/mortar/templates/project/lib/gitkeep
|
310
307
|
- lib/mortar/templates/project/macros/gitkeep
|
@@ -333,7 +330,6 @@ files:
|
|
333
330
|
- spec/mortar/command/clusters_spec.rb
|
334
331
|
- spec/mortar/command/config_spec.rb
|
335
332
|
- spec/mortar/command/describe_spec.rb
|
336
|
-
- spec/mortar/command/fixtures_spec.rb
|
337
333
|
- spec/mortar/command/generate_spec.rb
|
338
334
|
- spec/mortar/command/illustrate_spec.rb
|
339
335
|
- spec/mortar/command/jobs_spec.rb
|
@@ -1,100 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Mortar Data Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
require "mortar/command/base"
|
18
|
-
|
19
|
-
# create a reusable fixture.
|
20
|
-
#
|
21
|
-
class Mortar::Command::Fixtures < Mortar::Command::Base
|
22
|
-
|
23
|
-
WARNING_NUM_ROWS = 50
|
24
|
-
|
25
|
-
#fixtures:head [INPUT_URL] [NUM_ROWS] [FIXTURE_NAME]
|
26
|
-
#
|
27
|
-
#Create a reusable fixture [FIXTURE_NAME] made up of [NUM_ROWS]
|
28
|
-
#number of rows from the head of the input file(s) at [INPUT_URL].
|
29
|
-
#
|
30
|
-
# Examples:
|
31
|
-
#
|
32
|
-
# $ mortar fixtures:head s3n://tbmmsd/*.tsv.* 100 samll_song_sample
|
33
|
-
#
|
34
|
-
def head
|
35
|
-
input_url = shift_argument
|
36
|
-
num_rows = shift_argument
|
37
|
-
fixture_name = shift_argument
|
38
|
-
unless input_url && num_rows && fixture_name
|
39
|
-
error("Usage: mortar fixtures:head INPUT_URL NUM_ROWS FIXTURE_NAME\nMust specifiy INPUT_URL, NUM_ROWS, and FIXTURE_NAME.")
|
40
|
-
end
|
41
|
-
if does_fixture_exist(fixture_name)
|
42
|
-
error("Fixture #{fixture_name} already exists.")
|
43
|
-
end
|
44
|
-
unless num_rows.to_i < WARNING_NUM_ROWS
|
45
|
-
warning("Creating fixtures with more than #{WARNING_NUM_ROWS} rows is not recommended. Large local fixtures may cause slowness when using Mortar.")
|
46
|
-
display
|
47
|
-
end
|
48
|
-
validate_arguments!
|
49
|
-
validate_git_based_project!
|
50
|
-
|
51
|
-
fixture_id = nil
|
52
|
-
action("Requesting fixture creation") do
|
53
|
-
fixture_id = api.post_fixture_limit(project.name, fixture_name, input_url, num_rows).body['fixture_id']
|
54
|
-
end
|
55
|
-
|
56
|
-
poll_for_fixture_results(fixture_id)
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def does_fixture_exist(fixture_name)
|
64
|
-
fixture_path = File.join(project.fixtures_path, fixture_name)
|
65
|
-
File.exists?(fixture_path)
|
66
|
-
end
|
67
|
-
|
68
|
-
def poll_for_fixture_results(fixture_id)
|
69
|
-
fixture_result = nil
|
70
|
-
display
|
71
|
-
ticking(polling_interval) do |ticks|
|
72
|
-
fixture_result = api.get_fixture(fixture_id).body
|
73
|
-
is_finished =
|
74
|
-
Mortar::API::Fixtures::STATUSES_COMPLETE.include?(fixture_result["status_code"])
|
75
|
-
|
76
|
-
redisplay("Status: %s %s" % [
|
77
|
-
fixture_result['status_description'] + (is_finished ? "" : "..."),
|
78
|
-
is_finished ? "" : spinner(ticks)],
|
79
|
-
is_finished) # only display newline on last message
|
80
|
-
if is_finished
|
81
|
-
display
|
82
|
-
break
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
case fixture_result['status_code']
|
87
|
-
when Mortar::API::Fixtures::STATUS_FAILED
|
88
|
-
error_message = "Fixture generation failed with #{fixture_result['error_type'] || 'error'}"
|
89
|
-
error_context = get_error_message_context(fixture_result['error_message'] || "")
|
90
|
-
error_message += ":\n\n#{fixture_result['error_message']}\n\n#{error_context}"
|
91
|
-
error(error_message)
|
92
|
-
when Mortar::API::Fixtures::STATUS_CREATED
|
93
|
-
fixture_result['sample_s3_urls'].each do |u|
|
94
|
-
download_to_file(u['url'], "fixtures/#{fixture_result['name']}/#{u['name']}")
|
95
|
-
display
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
File without changes
|
File without changes
|
@@ -1,136 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright 2012 Mortar Data Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
require 'spec_helper'
|
18
|
-
require 'fakefs/spec_helpers'
|
19
|
-
require 'mortar/command/fixtures'
|
20
|
-
require 'mortar/api/fixtures'
|
21
|
-
|
22
|
-
module Mortar::Command
|
23
|
-
describe Fixtures do
|
24
|
-
before(:each) do
|
25
|
-
stub_core
|
26
|
-
@git = Mortar::Git::Git.new
|
27
|
-
end
|
28
|
-
|
29
|
-
context("index") do
|
30
|
-
|
31
|
-
it "errors when missing command" do
|
32
|
-
with_git_initialized_project do |p|
|
33
|
-
stderr, stdout = execute("fixtures:head s3n://tbmmsd/*.tsv.* 5", p, @git)
|
34
|
-
stderr.should == <<-STDERR
|
35
|
-
! Usage: mortar fixtures:head INPUT_URL NUM_ROWS FIXTURE_NAME
|
36
|
-
! Must specifiy INPUT_URL, NUM_ROWS, and FIXTURE_NAME.
|
37
|
-
STDERR
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "requests and reports on a successful fixtures:head" do
|
42
|
-
with_git_initialized_project do |p|
|
43
|
-
fixture_id = "12345abcde"
|
44
|
-
name = "My_pet_fixture"
|
45
|
-
url = "s3://my_pet_fixture"
|
46
|
-
num_rows = "60"
|
47
|
-
|
48
|
-
sample_s3_urls = [ {'url' => "url1",
|
49
|
-
'name' => "url1_name"}]
|
50
|
-
|
51
|
-
mock(Mortar::Auth.api).post_fixture_limit(p.name, name, url, num_rows) {Excon::Response.new(:body => {"fixture_id" => fixture_id})}
|
52
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_PENDING, "status_description" => "Pending"})).ordered
|
53
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_CREATING, "status_description" => "Creating"})).ordered
|
54
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_SAVING, "status_description" => "Uploading"})).ordered
|
55
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_CREATED, "status_description" => "Success", "name" => name, "sample_s3_urls" => sample_s3_urls})).ordered
|
56
|
-
|
57
|
-
any_instance_of(Mortar::Command::Fixtures) do |base|
|
58
|
-
mock(base).download_to_file(sample_s3_urls[0]['url'], "fixtures/#{name}/#{sample_s3_urls[0]['name']}")
|
59
|
-
end
|
60
|
-
|
61
|
-
stderr, stdout = execute("fixtures:head #{url} #{num_rows} #{name} --polling_interval 0.05", p, @git)
|
62
|
-
|
63
|
-
stdout.should == <<-STDOUT
|
64
|
-
WARNING: Creating fixtures with more than 50 rows is not recommended. Large local fixtures may cause slowness when using Mortar.
|
65
|
-
|
66
|
-
Requesting fixture creation... done
|
67
|
-
|
68
|
-
\r\e[0KStatus: Pending... /\r\e[0KStatus: Creating... -\r\e[0KStatus: Uploading... \\\r\e[0KStatus: Success \n\n
|
69
|
-
STDOUT
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "requests and reports on a failed fixtures:head" do
|
75
|
-
with_git_initialized_project do |p|
|
76
|
-
fixture_id = "12345abcde"
|
77
|
-
name = "My_pet_fixture"
|
78
|
-
url = "s3://my_pet_fixture"
|
79
|
-
num_rows = "60"
|
80
|
-
|
81
|
-
sample_s3_urls = [ {'url' => "url1",
|
82
|
-
'name' => "url1_name"}]
|
83
|
-
|
84
|
-
mock(Mortar::Auth.api).post_fixture_limit(p.name, name, url, num_rows) {Excon::Response.new(:body => {"fixture_id" => fixture_id})}
|
85
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_PENDING, "status_description" => "Pending"})).ordered
|
86
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_CREATING, "status_description" => "Creating"})).ordered
|
87
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_SAVING, "status_description" => "Uploading"})).ordered
|
88
|
-
mock(Mortar::Auth.api).get_fixture(fixture_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Fixtures::STATUS_FAILED,
|
89
|
-
"status_description" => "Failed",
|
90
|
-
"name" => name,
|
91
|
-
"error_message" => "This is an error message.",
|
92
|
-
"error_type" => "UserError" })).ordered
|
93
|
-
|
94
|
-
stderr, stdout = execute("fixtures:head #{url} #{num_rows} #{name} --polling_interval 0.05", p, @git)
|
95
|
-
|
96
|
-
stdout.should == <<-STDOUT
|
97
|
-
WARNING: Creating fixtures with more than 50 rows is not recommended. Large local fixtures may cause slowness when using Mortar.
|
98
|
-
|
99
|
-
Requesting fixture creation... done
|
100
|
-
|
101
|
-
\r\e[0KStatus: Pending... /\r\e[0KStatus: Creating... -\r\e[0KStatus: Uploading... \\\r\e[0KStatus: Failed \n
|
102
|
-
STDOUT
|
103
|
-
|
104
|
-
stderr.should == <<-STDERR
|
105
|
-
! Fixture generation failed with UserError:
|
106
|
-
!
|
107
|
-
! This is an error message.
|
108
|
-
STDERR
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
it "tries to create a fixture in an existing directory" do
|
115
|
-
with_git_initialized_project do |p|
|
116
|
-
fixture_id = "12345abcde"
|
117
|
-
name = "My_pet_fixture"
|
118
|
-
url = "s3://my_pet_fixture"
|
119
|
-
num_rows = "60"
|
120
|
-
|
121
|
-
fixtures_dir = File.join(Dir.pwd, "fixtures", name)
|
122
|
-
FileUtils.mkdir_p(fixtures_dir)
|
123
|
-
|
124
|
-
stderr, stdout = execute("fixtures:head #{url} #{num_rows} #{name} --polling_interval 0.05", p, @git)
|
125
|
-
|
126
|
-
stderr.should == <<-STDERR
|
127
|
-
! Fixture #{name} already exists.
|
128
|
-
STDERR
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|