mortar 0.15.36 → 0.15.37

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mortar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.36
4
+ version: 0.15.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mortar Data
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.13
33
+ version: 0.8.14
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
- version: 0.8.13
40
+ version: 0.8.14
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: netrc
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -249,7 +249,6 @@ files:
249
249
  - lib/mortar/local/params.rb
250
250
  - lib/mortar/local/pig.rb
251
251
  - lib/mortar/local/python.rb
252
- - lib/mortar/local/sqoop.rb
253
252
  - lib/mortar/pigversion.rb
254
253
  - lib/mortar/plugin.rb
255
254
  - lib/mortar/project.rb
@@ -304,7 +303,6 @@ files:
304
303
  - lib/mortar/templates/script/runpig.sh
305
304
  - lib/mortar/templates/script/runpython.sh
306
305
  - lib/mortar/templates/script/runstillson.sh
307
- - lib/mortar/templates/script/sqoop.sh
308
306
  - lib/mortar/templates/udf/python_udf.py
309
307
  - lib/mortar/updater.rb
310
308
  - lib/mortar/version.rb
@@ -337,7 +335,6 @@ files:
337
335
  - spec/mortar/local/params_spec.rb
338
336
  - spec/mortar/local/pig_spec.rb
339
337
  - spec/mortar/local/python_spec.rb
340
- - spec/mortar/local/sqoop_spec.rb
341
338
  - spec/mortar/plugin_spec.rb
342
339
  - spec/mortar/project_spec.rb
343
340
  - spec/mortar/s3_spec.rb
@@ -365,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
365
362
  version: '0'
366
363
  requirements: []
367
364
  rubyforge_project:
368
- rubygems_version: 2.4.4
365
+ rubygems_version: 2.4.8
369
366
  signing_key:
370
367
  specification_version: 4
371
368
  summary: Client library and CLI to interact with the Mortar service.
@@ -1,162 +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 "erb"
18
- require 'tempfile'
19
- require "mortar/helpers"
20
- require "mortar/local/installutil"
21
-
22
- class Mortar::Local::Sqoop
23
- include Mortar::Local::InstallUtil
24
- include Mortar::Helpers
25
-
26
- def install_or_update
27
- @command = "#{local_install_directory}/python/bin/python"
28
- if should_do_install?
29
- action "Installing sqoop to #{local_install_directory_name}" do
30
- do_install
31
- end
32
- elsif should_do_update?
33
- action "Updating to latest sqoop in #{local_install_directory_name}" do
34
- do_install
35
- end
36
- end
37
- true
38
- end
39
-
40
- def sqoop_url
41
- default_url = full_host + "/" + "resource/sqoop"
42
- return ENV.fetch('SQOOP_DISTRO_URL', default_url)
43
- end
44
-
45
- def should_do_install?
46
- return (not (File.exists?(sqoop_directory)))
47
- end
48
-
49
- def should_do_update?
50
- return is_newer_version('sqoop', sqoop_url)
51
- end
52
-
53
- def sqoop_directory
54
- return "#{local_install_directory}/sqoop"
55
- end
56
-
57
- def sqoop_dir_in_tgz
58
- "sqoop-1.4.4-mortar"
59
- end
60
-
61
- def do_install
62
- local_tgz = File.join(local_install_directory, "sqoop-1.4.4-mortar.tar.gz")
63
- if File.exists?(local_tgz)
64
- FileUtils.rm(local_tgz)
65
- end
66
- download_file(sqoop_url, local_tgz)
67
-
68
- if File.exists?(sqoop_directory)
69
- FileUtils.rm_rf(sqoop_directory)
70
- end
71
-
72
- extract_tgz(local_tgz, local_install_directory)
73
-
74
- FileUtils.mv(File.join(local_install_directory, sqoop_dir_in_tgz), sqoop_directory)
75
-
76
- # This has been seening coming out of the tgz w/o +x so we do
77
- # here to be sure it has the necessary permissions
78
- FileUtils.chmod(0755, "#{sqoop_directory}/bin/sqoop")
79
- FileUtils.chmod(0755, "#{sqoop_directory}/hadoop/bin/hadoop")
80
-
81
- File.delete(local_tgz)
82
- note_install("sqoop")
83
- end
84
-
85
- def sqoop_command_script_template_path
86
- File.expand_path("../../templates/script/sqoop.sh", __FILE__)
87
- end
88
-
89
- def hadoop_home
90
- "#{sqoop_directory}/hadoop"
91
- end
92
-
93
- def export(connstr, s3dest, options)
94
- template_params = sqoop_export_template_parameters(connstr, s3dest, options)
95
- return run_templated_script(sqoop_command_script_template_path, template_params)
96
- end
97
-
98
- def sqoop_export_template_parameters(connstr, s3dest, options)
99
- pig = Mortar::Local::Pig.new()
100
- parameters = {
101
- "sqoop_dir" => sqoop_directory,
102
- "jdb_conn_string" => connstr,
103
- "destination" => s3dest,
104
- "hadoop_home" => hadoop_home,
105
- "classpath" => pig.template_params_classpath,
106
- "postgres_jar" => "#{pig.lib_directory}/lib-cluster/postgresql.jar",
107
- "jdbc_conn" => connstr,
108
- "s3dest" => s3dest,
109
- "project_root" => project_root,
110
- "sqoop_opts" => sqoop_java_options
111
- }
112
- parameters["dbtable"] = options[:dbtable] if options[:dbtable]
113
- parameters["sqlquery"] = options[:sqlquery] if options[:sqlquery]
114
- parameters["inc_column"] = options[:inc_column] if options[:inc_column]
115
- parameters["inc_value"] = options[:inc_value] if options[:inc_value]
116
- if options[:inc_value] and 0 == options[:inc_value].to_i
117
- parameters[:inc_mode] = "lastmodified"
118
- elsif options[:inc_value]
119
- parameters[:inc_mode] = "append"
120
- end
121
- parameters["dbuser"] = options[:username] if options[:username]
122
- parameters["dbpass"] = options[:password] if options[:password]
123
- parameters["jdbcdriver"] = options[:jdbcdriver] if options[:jdbcdriver]
124
- parameters["driverjar"] = options[:driverjar] if options[:driverjar]
125
- parameters["direct_import"] = true if options[:direct]
126
- return parameters
127
- end
128
-
129
- def sqoop_java_options
130
- opts = {}
131
- opts['fs.s3n.awsAccessKeyId'] = ENV['AWS_ACCESS_KEY']
132
- opts['fs.s3n.awsSecretAccessKey'] = ENV['AWS_SECRET_KEY']
133
- opts['fs.s3.awsAccessKeyId'] = ENV['AWS_ACCESS_KEY']
134
- opts['fs.s3.awsSecretAccessKey'] = ENV['AWS_SECRET_KEY']
135
- opts['fs.s3.impl'] = 'org.apache.hadoop.fs.s3native.NativeS3FileSystem'
136
- opts['fs.s3n.impl'] = 'org.apache.hadoop.fs.s3native.NativeS3FileSystem'
137
- return opts
138
- end
139
-
140
- # So this part kind of sucks. In order to partition a query across multiple map
141
- # reduce tasks sqoop does a query to to find the range of identifiying values,
142
- # divides this range across the number of tasks to be executed and then modifies
143
- # the query for each m/r task. To do this Sqoop needs to know at what point in the
144
- # query that it should place its portion of the where clause. This is done via the
145
- # $CONDITIONS marker. So that's well and good when you're running sqoop on a cluster
146
- # but our users will be running on their own machine and don't know or care for this
147
- # parrallel queries stuff. So to make their lives easier we make a best effort to
148
- # add the clause for them in a safe way.
149
- def prep_query(original_query)
150
- if original_query.include? "$CONDITIONS"
151
- return original_query
152
- elsif original_query.downcase.include? "where"
153
- idxwhere = original_query.downcase.index("where")
154
- select_where = original_query[0..idxwhere+"where".length-1]
155
- clause = original_query[idxwhere+"where".length+1..original_query.length]
156
- return "#{select_where} (#{clause}) AND \$CONDITIONS"
157
- else
158
- return "#{original_query} WHERE \$CONDITIONS"
159
- end
160
- end
161
-
162
- end
@@ -1,40 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- export HADOOP_CLASSPATH="<%= @project_root %>/lib/*:<%= @postgres_jar %>"
6
- <% if @driverjar %>
7
- export HADOOP_CLASSPATH="$HADOOP_CLASSPATH:<%= @driverjar %>"
8
- <% end %>
9
- export HADOOP_COMMON_HOME="<%= @hadoop_home %>"
10
- export HADOOP_MAPRED_HOME="<%= @hadoop_home %>"
11
- export HADOOP_HOME_WARN_SUPPRESS="t"
12
-
13
- # Only setting these to get rid of warnings that sqoop is showing
14
- export HCAT_HOME="<%= @hadoop_home %>"
15
- export HBASE_HOME="<%= @hadoop_home %>"
16
-
17
- SQOOP_OPTS="<% @sqoop_opts.each do |k,v| %>-D<%= k %>=<%= v %> <% end %>"
18
- OPTARGS='<%= "--driver #{@jdbcdriver}" if @jdbcdriver %>'
19
- OPTARGS="$OPTARGS <%= "--username #{@dbuser}" if @dbuser %>"
20
- OPTARGS="$OPTARGS <%= "--password #{@dbpass}" if @dbpass %>"
21
- OPTARGS="$OPTARGS <%= "--direct" if @direct_import %>"
22
- <% if @inc_column and @inc_value %>
23
- OPTARGS="$OPTARGS --incremental <%= @inc_mode %>"
24
- OPTARGS="$OPTARGS --check-column <%= @inc_column %> "
25
- SQOOP_OPTS="$SQOOP_OPTS -Dsqoop.test.import.rootDir=<%= @s3dest %>/.tmp"
26
- <% end %>
27
-
28
- export HADOOP_OPTS="$SQOOP_OPTS";
29
-
30
- <%= @sqoop_dir %>/bin/sqoop \
31
- import \
32
- $SQOOP_OPTS \
33
- <%= "--table #{@dbtable}" if @dbtable %> \
34
- <%= "--query '#{@sqlquery}'" if @sqlquery %> \
35
- -m 1 \
36
- --connect <%= @jdbc_conn %> \
37
- --target-dir <%= @s3dest %> \
38
- $OPTARGS \
39
- <% if @inc_column and @inc_value %>--last-value '<%= @inc_value %>'<% end %>
40
-
@@ -1,57 +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/local/sqoop'
20
- require 'launchy'
21
-
22
-
23
- module Mortar::Local
24
- describe Sqoop do
25
-
26
- context "prepare query" do
27
-
28
- it "adds a where clause if none exists" do
29
- sqoop = Mortar::Local::Sqoop.new
30
- expect(sqoop.prep_query("SELECT * FROM customers")).to eq("SELECT * FROM customers WHERE \$CONDITIONS")
31
- end
32
-
33
- it "wraps existing where clause and appends condition" do
34
- original = "SELECT * FROM customers WHERE customer_id = 1"
35
- expected = "SELECT * FROM customers WHERE (customer_id = 1) AND \$CONDITIONS"
36
- sqoop = Mortar::Local::Sqoop.new
37
- expect(sqoop.prep_query(original)).to eq(expected)
38
- end
39
-
40
- it "wraps a complex where clause and appends condition" do
41
- original = "SELECT * FROM customers WHERE (customer_id = 1 and customer_name = 'tom') or customer_id=2"
42
- expected = "SELECT * FROM customers WHERE ((customer_id = 1 and customer_name = 'tom') or customer_id=2) AND \$CONDITIONS"
43
- sqoop = Mortar::Local::Sqoop.new
44
- expect(sqoop.prep_query(original)).to eq(expected)
45
- end
46
-
47
- it "does nothing if the user was polite enough to supply the clause themselves" do
48
- query = "SELECT * FROM customers WHERE (customer_id = 1) AND \$CONDITIONS"
49
- sqoop = Mortar::Local::Sqoop.new
50
- expect(sqoop.prep_query(query)).to eq(query)
51
- end
52
-
53
-
54
- end
55
-
56
- end
57
- end