wukong-hadoop 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +5 -0
- data/Gemfile +2 -0
- data/LICENSE.md +95 -0
- data/Rakefile +0 -3
- data/bin/wu-hadoop +1 -11
- data/examples/counter.rb +1 -1
- data/lib/wukong-hadoop.rb +73 -6
- data/lib/wukong-hadoop/runner.rb +210 -0
- data/lib/wukong-hadoop/{driver → runner}/hadoop_invocation.rb +2 -7
- data/lib/wukong-hadoop/{driver → runner}/local_invocation.rb +0 -0
- data/lib/wukong-hadoop/{driver → runner}/map_logic.rb +4 -2
- data/lib/wukong-hadoop/runner/overwritables.rb +35 -0
- data/lib/wukong-hadoop/{driver → runner}/reduce_logic.rb +3 -2
- data/lib/wukong-hadoop/version.rb +1 -1
- data/spec/spec_helper.rb +11 -4
- data/spec/wukong-hadoop/hadoop_mode_spec.rb +11 -19
- data/spec/wukong-hadoop/local_mode_spec.rb +6 -6
- data/spec/wukong-hadoop/{driver_spec.rb → runner_spec.rb} +35 -33
- data/spec/wukong-hadoop/{wu_hadoop_spec.rb → wu-hadoop_spec.rb} +4 -4
- data/spec/wukong-hadoop_spec.rb +5 -0
- data/wukong-hadoop.gemspec +1 -1
- metadata +18 -19
- data/lib/wukong-hadoop/configuration.rb +0 -137
- data/lib/wukong-hadoop/driver.rb +0 -191
- data/lib/wukong-hadoop/driver/inputs_and_outputs.rb +0 -27
- data/spec/support/driver_helper.rb +0 -15
- data/spec/support/integration_helper.rb +0 -39
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# License for Wukong-Hadoop
|
2
|
+
|
3
|
+
The wukong code is __Copyright (c) 2011, 2012 Infochimps, Inc__
|
4
|
+
|
5
|
+
This code is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an **AS IS** BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
10
|
+
|
11
|
+
__________________________________________________________________________
|
12
|
+
|
13
|
+
# Apache License
|
14
|
+
|
15
|
+
|
16
|
+
Apache License
|
17
|
+
Version 2.0, January 2004
|
18
|
+
http://www.apache.org/licenses/
|
19
|
+
|
20
|
+
_TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION_
|
21
|
+
|
22
|
+
## 1. Definitions.
|
23
|
+
|
24
|
+
* **License** shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
25
|
+
|
26
|
+
* **Licensor** shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
27
|
+
|
28
|
+
* **Legal Entity** shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
29
|
+
|
30
|
+
* **You** (or **Your**) shall mean an individual or Legal Entity exercising permissions granted by this License.
|
31
|
+
|
32
|
+
* **Source** form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
33
|
+
|
34
|
+
* **Object** form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
35
|
+
|
36
|
+
* **Work** shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
37
|
+
|
38
|
+
* **Derivative Works** shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
39
|
+
|
40
|
+
* **Contribution** shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
41
|
+
|
42
|
+
* **Contributor** shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
43
|
+
|
44
|
+
## 2. Grant of Copyright License.
|
45
|
+
|
46
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
47
|
+
|
48
|
+
## 3. Grant of Patent License.
|
49
|
+
|
50
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
51
|
+
|
52
|
+
## 4. Redistribution.
|
53
|
+
|
54
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
55
|
+
|
56
|
+
- (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
57
|
+
- (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
58
|
+
- (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
59
|
+
- (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
60
|
+
|
61
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
62
|
+
|
63
|
+
## 5. Submission of Contributions.
|
64
|
+
|
65
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
66
|
+
|
67
|
+
## 6. Trademarks.
|
68
|
+
|
69
|
+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
70
|
+
|
71
|
+
## 7. Disclaimer of Warranty.
|
72
|
+
|
73
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
74
|
+
|
75
|
+
## 8. Limitation of Liability.
|
76
|
+
|
77
|
+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
78
|
+
|
79
|
+
## 9. Accepting Warranty or Additional Liability.
|
80
|
+
|
81
|
+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
82
|
+
|
83
|
+
_END OF TERMS AND CONDITIONS_
|
84
|
+
|
85
|
+
## APPENDIX: How to apply the Apache License to your work.
|
86
|
+
|
87
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets `[]` replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
88
|
+
|
89
|
+
> Copyright [yyyy] [name of copyright owner]
|
90
|
+
>
|
91
|
+
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
92
|
+
>
|
93
|
+
> http://www.apache.org/licenses/LICENSE-2.0
|
94
|
+
>
|
95
|
+
> Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
data/Rakefile
CHANGED
data/bin/wu-hadoop
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'wukong-hadoop'
|
4
|
-
|
5
|
-
require 'wukong/boot'
|
6
|
-
Wukong.boot!(settings)
|
7
|
-
|
8
|
-
settings[:command_prefix] = 'bundle exec' if Wukong.in_deploy_pack?
|
9
|
-
|
10
|
-
if settings.rest.empty?
|
11
|
-
settings.dump_help
|
12
|
-
exit(1)
|
13
|
-
end
|
14
|
-
Wukong::Hadoop::Driver.run(settings, *settings.rest)
|
4
|
+
Wukong::Hadoop::HadoopRunner.run
|
data/examples/counter.rb
CHANGED
data/lib/wukong-hadoop.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'configliere'
|
2
|
-
require 'pathname'
|
3
|
-
require 'rbconfig'
|
4
1
|
require 'wukong'
|
5
2
|
|
6
3
|
module Wukong
|
@@ -12,10 +9,80 @@ module Wukong
|
|
12
9
|
# lets you execute Ruby files containing Wukong processors as well
|
13
10
|
# as built-in Wukong widgets.
|
14
11
|
module Hadoop
|
12
|
+
include Plugin
|
13
|
+
|
14
|
+
# Configure the given settings object for use with Wukong::Hadoop.
|
15
|
+
#
|
16
|
+
# Will only add settings if the `program_name` is `wu-hadoop`.
|
17
|
+
#
|
18
|
+
# @param [Configliere::Param] settings the settings to configure
|
19
|
+
# @param [String] program_name the name of the currently executing program
|
20
|
+
def self.configure settings, program_name
|
21
|
+
return unless program_name == 'wu-hadoop'
|
22
|
+
|
23
|
+
# Hadoop Options
|
24
|
+
settings.define :hadoop_home, wukong_hadoop: true, description: 'Path to hadoop installation. HADOOP_HOME/bin/hadoop is used to run hadoop.', env_var: 'HADOOP_HOME', default: '/usr/lib/hadoop'
|
25
|
+
settings.define :hadoop_runner, wukong_hadoop: true, description: 'Path to hadoop executable. Use this for non-standard hadoop installations.'
|
26
|
+
|
27
|
+
# Translate simplified args to their hairy hadoop equivalents
|
28
|
+
settings.define :io_sort_mb, wukong_hadoop: true, jobconf: true, description: 'io.sort.mb'
|
29
|
+
settings.define :io_sort_record_percent, wukong_hadoop: true, jobconf: true, description: 'io.sort.record.percent'
|
30
|
+
settings.define :job_name, wukong_hadoop: true, jobconf: true, description: 'mapred.job.name'
|
31
|
+
settings.define :key_field_separator, wukong_hadoop: true, jobconf: true, description: 'map.output.key.field.separator'
|
32
|
+
settings.define :map_speculative, wukong_hadoop: true, jobconf: true, description: 'mapred.map.tasks.speculative.execution'
|
33
|
+
settings.define :reduce_speculative, wukong_hadoop: true, jobconf: true, description: 'mapred.reduce.tasks.speculative.execution'
|
34
|
+
settings.define :map_tasks, wukong_hadoop: true, jobconf: true, description: 'mapred.map.tasks'
|
35
|
+
settings.define :max_maps_per_cluster, wukong_hadoop: true, jobconf: true, description: 'mapred.max.maps.per.cluster'
|
36
|
+
settings.define :max_maps_per_node, wukong_hadoop: true, jobconf: true, description: 'mapred.max.maps.per.node'
|
37
|
+
settings.define :max_node_map_tasks, wukong_hadoop: true, jobconf: true, description: 'mapred.tasktracker.map.tasks.maximum'
|
38
|
+
settings.define :max_node_reduce_tasks, wukong_hadoop: true, jobconf: true, description: 'mapred.tasktracker.reduce.tasks.maximum'
|
39
|
+
settings.define :max_record_length, wukong_hadoop: true, jobconf: true, description: 'mapred.linerecordreader.maxlength'
|
40
|
+
settings.define :max_reduces_per_cluster, wukong_hadoop: true, jobconf: true, description: 'mapred.max.reduces.per.cluster'
|
41
|
+
settings.define :max_reduces_per_node, wukong_hadoop: true, jobconf: true, description: 'mapred.max.reduces.per.node'
|
42
|
+
settings.define :max_tracker_failures, wukong_hadoop: true, jobconf: true, description: 'mapred.max.tracker.failures'
|
43
|
+
settings.define :max_map_attempts, wukong_hadoop: true, jobconf: true, description: 'mapred.map.max.attempts'
|
44
|
+
settings.define :max_reduce_attempts, wukong_hadoop: true, jobconf: true, description: 'mapred.reduce.max.attempts'
|
45
|
+
settings.define :min_split_size, wukong_hadoop: true, jobconf: true, description: 'mapred.min.split.size'
|
46
|
+
settings.define :output_field_separator, wukong_hadoop: true, jobconf: true, description: 'stream.map.output.field.separator'
|
47
|
+
settings.define :partition_fields, wukong_hadoop: true, jobconf: true, description: 'num.key.fields.for.partition'
|
48
|
+
settings.define :reduce_tasks, wukong_hadoop: true, jobconf: true, description: 'mapred.reduce.tasks'
|
49
|
+
settings.define :respect_exit_status, wukong_hadoop: true, jobconf: true, description: 'stream.non.zero.exit.is.failure'
|
50
|
+
settings.define :reuse_jvms, wukong_hadoop: true, jobconf: true, description: 'mapred.job.reuse.jvm.num.tasks'
|
51
|
+
settings.define :sort_fields, wukong_hadoop: true, jobconf: true, description: 'stream.num.map.output.key.fields'
|
52
|
+
settings.define :timeout, wukong_hadoop: true, jobconf: true, description: 'mapred.task.timeout'
|
53
|
+
settings.define :noempty, wukong_hadoop: true, description: "Don't create zero-byte reduce files"
|
54
|
+
settings.define :split_on_xml_tag, wukong_hadoop: true, description: "Parse XML document by specifying the tag name: 'anything found between <tag> and </tag> will be treated as one record for map tasks'"
|
55
|
+
settings.define :input_format, wukong_hadoop: true, description: 'Fully qualified Java class name defining an alternative InputFormat.'
|
56
|
+
settings.define :output_format, wukong_hadoop: true, description: 'Fully qualified Java class name defining an alternative OutputFormat.'
|
57
|
+
settings.define :java_opts, wukong_hadoop: true, description: 'Additional Java options to be passed to hadoop streaming.', :type => Array, :default => []
|
58
|
+
settings.define :files, wukong_hadoop: true, description: "Comma-separated list of files (or globs) to be copied to the MapReduce cluster (-files).", :type => Array, :default => []
|
59
|
+
settings.define :jars, wukong_hadoop: true, description: "Comma-separated list of jars (or globs) to include on the Hadoop CLASSPATH (-libjars).", :type => Array, :default => []
|
60
|
+
settings.define :archives, wukong_hadoop: true, description: "Comma-separated list of archives to be unarchived on each worker (-archives).", :type => Array, :default => []
|
61
|
+
|
62
|
+
# Options given on the command-line
|
63
|
+
settings.define :mode, description: "Run in either 'hadoop' or 'local' mode", wukong_hadoop: true, :default => 'hadoop'
|
64
|
+
settings.define :map_command, description: "Shell command to run as mapper, in place of a constructed wu-local command", wukong_hadoop: true
|
65
|
+
settings.define :reduce_command, description: "Shell command to run as reducer, in place of a constructed wu-local command", wukong_hadoop: true
|
66
|
+
settings.define :sort_command, description: "Shell command to run as sorter (only in `local' mode)", wukong_hadoop: true, :default => 'sort'
|
67
|
+
settings.define :command_prefix, description: "Prefix to insert before all Wukong commands", wukong_hadoop: true
|
68
|
+
settings.define :mapper, description: "Name of processor to use as a mapper", wukong_hadoop: true
|
69
|
+
settings.define :reducer, description: "Name of processor to use as a reducer", wukong_hadoop: true
|
70
|
+
settings.define :gemfile, description: "Specify an alternative Gemfile to execute this wukong script with", wukong_hadoop: true
|
71
|
+
settings.define :dry_run, description: "Echo the command that will be run, but don't run it", wukong_hadoop: true, :type => :boolean, :default => false
|
72
|
+
settings.define :rm, description: "Recursively remove the destination directory.", wukong_hadoop: true, :type => :boolean, :default => false
|
73
|
+
settings.define :input, description: "Comma-separated list of input paths", wukong_hadoop: true
|
74
|
+
settings.define :output, description: "Output path.", wukong_hadoop: true
|
75
|
+
end
|
76
|
+
|
77
|
+
# Boots the Wukong::Hadoop plugin.
|
78
|
+
#
|
79
|
+
# @param [Configliere::Param] settings the settings to boot from
|
80
|
+
# @param [String] root the root directory to boot in
|
81
|
+
def self.boot settings, root
|
82
|
+
end
|
83
|
+
|
15
84
|
end
|
16
85
|
end
|
17
86
|
|
18
|
-
|
19
|
-
require 'wukong-hadoop/configuration'
|
20
|
-
require 'wukong-hadoop/driver'
|
87
|
+
require 'wukong-hadoop/runner'
|
21
88
|
require 'wukong-hadoop/extensions'
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require_relative("runner/overwritables")
|
3
|
+
require_relative("runner/map_logic")
|
4
|
+
require_relative("runner/reduce_logic")
|
5
|
+
require_relative("runner/local_invocation")
|
6
|
+
require_relative("runner/hadoop_invocation")
|
7
|
+
module Wukong
|
8
|
+
module Hadoop
|
9
|
+
|
10
|
+
# The <tt>Hadoop::Runner</tt> class contains the logic to examine
|
11
|
+
# arguments and construct command lines which it will execute to
|
12
|
+
# create the desired behavior.
|
13
|
+
#
|
14
|
+
# The Hadoop::Runner will introspect on its arguments to guess (if
|
15
|
+
# not given) the processors to use as mapper and reducer in a
|
16
|
+
# map/reduce job. It will also decide whether to run that job in
|
17
|
+
# local or Hadoop mode. These decisions result in a command which
|
18
|
+
# it will ultimately execute.
|
19
|
+
class HadoopRunner < Wukong::Runner
|
20
|
+
|
21
|
+
usage "PROCESSOR|FLOW [PROCESSOR|FLOW]"
|
22
|
+
|
23
|
+
description <<EOF
|
24
|
+
wu-hadoop is a tool to model and launch Wukong processors as
|
25
|
+
map/reduce workflows within the Hadoop framework.
|
26
|
+
|
27
|
+
Use wu-hadoop with existing processors in `local' mode to test the
|
28
|
+
logic of your job, reading from the specified --input and printing to
|
29
|
+
STDOUT:
|
30
|
+
|
31
|
+
$ wu-hadoop examples/word_count.rb --mode=local --input=examples/sonnet_18.txt
|
32
|
+
a 2
|
33
|
+
all 1
|
34
|
+
and 2
|
35
|
+
...
|
36
|
+
|
37
|
+
where it is assumed that your mapper is called 'mapper' and your
|
38
|
+
reducer 'reducer'. You can also cat in data:
|
39
|
+
|
40
|
+
$ cat examples/sonnet_18.txt | wu-hadoop examples/word_count.rb --mode=local
|
41
|
+
|
42
|
+
Or pass options directly:
|
43
|
+
|
44
|
+
$ wu-hadoop examples/word_count.rb --mode=local --input=examples/sonnet_18.txt --fold_case --min_length=3
|
45
|
+
all 1
|
46
|
+
and 5
|
47
|
+
art 1
|
48
|
+
brag 1
|
49
|
+
...
|
50
|
+
|
51
|
+
Or define both processors in separate files:
|
52
|
+
|
53
|
+
$ wu-hadoop examples/tokenizer.rb examples/counter.rb --mode=local --input=examples/sonnet_18.txt
|
54
|
+
|
55
|
+
Or by name:
|
56
|
+
|
57
|
+
$ wu-hadoop examples/processors.rb --mode=local --input=examples/sonnet_18.txt --mapper=tokenizer --reducer=counter
|
58
|
+
|
59
|
+
Or just by command:
|
60
|
+
|
61
|
+
$ wu-hadoop processors.rb --mapper=tokenizer --reduce_command='uniq -c' ...
|
62
|
+
$ wu-hadoop processors.rb --map_command='cut -f3' --reducer=counter ...
|
63
|
+
$ wu-hadoop --map_command='cut -f3' --reduce_command='uniq -c' ...
|
64
|
+
|
65
|
+
If you don't specify a --reducer explicitly, and you didn't give two
|
66
|
+
separate arguments, and no processor named :reducer exists in the
|
67
|
+
environment, then we assume you are launching a map-only job and
|
68
|
+
'mapred.tasktracker.reduce.tasks.maximum' will correspondingly be set
|
69
|
+
to 0:
|
70
|
+
|
71
|
+
$ wu-hadoop examples/tokenizer.rb --mode=local --input=examples/sonnet_18.txt
|
72
|
+
Shall
|
73
|
+
I
|
74
|
+
compare
|
75
|
+
thee
|
76
|
+
...
|
77
|
+
|
78
|
+
You can achieve this directly with the --reduce_tasks=0 option.
|
79
|
+
|
80
|
+
Many other Hadoop options have been wrapped with similarly friendly
|
81
|
+
names below. These are ignored when running in `local' mode.
|
82
|
+
|
83
|
+
Some options (like `--sort_command') only make sense in `local' mode.
|
84
|
+
These are ignored in `hadoop' mode.
|
85
|
+
EOF
|
86
|
+
|
87
|
+
include Logging
|
88
|
+
include Overwritables
|
89
|
+
include MapLogic
|
90
|
+
include ReduceLogic
|
91
|
+
include HadoopInvocation
|
92
|
+
include LocalInvocation
|
93
|
+
|
94
|
+
# Validate that no more than two arguments were given and that
|
95
|
+
# explicit input & output arguments were given if we're in
|
96
|
+
# Hadoop mode.
|
97
|
+
#
|
98
|
+
# @raise [Wukong::Error] if validations fail
|
99
|
+
# @return [true]
|
100
|
+
def validate
|
101
|
+
raise Error.new("Cannot provide more than two arguments") if args.length > 2
|
102
|
+
if mode == :hadoop && (input_paths.nil? || input_paths.empty? || output_path.nil? || output_path.empty?)
|
103
|
+
raise Error.new("Explicit --input and --output paths are required to run a job in Hadoop mode.")
|
104
|
+
end
|
105
|
+
true
|
106
|
+
end
|
107
|
+
|
108
|
+
# Run this command.
|
109
|
+
def run
|
110
|
+
if mode == :local
|
111
|
+
log.info "Launching local!"
|
112
|
+
execute_command!(local_commandline)
|
113
|
+
else
|
114
|
+
remove_output_path! if settings[:rm] || settings[:overwrite]
|
115
|
+
hadoop_commandline
|
116
|
+
log.info "Launching Hadoop!"
|
117
|
+
execute_command!(hadoop_commandline)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# What mode is this runner in?
|
122
|
+
#
|
123
|
+
# @return [:hadoop, :local]
|
124
|
+
def mode
|
125
|
+
settings[:mode].to_s == 'local' ? :local : :hadoop
|
126
|
+
end
|
127
|
+
|
128
|
+
# Were mapper and/or reducer named by a single argument?
|
129
|
+
#
|
130
|
+
# @return [true, false]
|
131
|
+
def single_job_arg?
|
132
|
+
args.size == 1
|
133
|
+
end
|
134
|
+
|
135
|
+
# Were mapper and/or reducer named by separate arguments?
|
136
|
+
#
|
137
|
+
# @return [true, false]
|
138
|
+
def separate_map_and_reduce_args?
|
139
|
+
args.size == 2
|
140
|
+
end
|
141
|
+
|
142
|
+
# Is there a processor registered with the given `name`?
|
143
|
+
#
|
144
|
+
# @param [#to_s] name
|
145
|
+
# @return [true, false]
|
146
|
+
def processor_registered? name
|
147
|
+
Wukong.registry.registered?(name.to_s.to_sym)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Return the guessed name of a processor at the given `path`.
|
151
|
+
#
|
152
|
+
# @param [String] path
|
153
|
+
# @return [String]
|
154
|
+
def processor_name_from_file(path)
|
155
|
+
File.basename(path, '.rb')
|
156
|
+
end
|
157
|
+
|
158
|
+
# Does the given `path` contain a processor named after itself?
|
159
|
+
#
|
160
|
+
# @param [String] path
|
161
|
+
# @return [true, false]
|
162
|
+
def file_is_processor?(path)
|
163
|
+
return false unless path
|
164
|
+
processor_registered?(processor_name_from_file(path))
|
165
|
+
end
|
166
|
+
|
167
|
+
# The prefix to insert befor all invocations of the
|
168
|
+
# <tt>wu-local</tt> runner.
|
169
|
+
#
|
170
|
+
# @return [String]
|
171
|
+
def command_prefix
|
172
|
+
settings[:command_prefix]
|
173
|
+
end
|
174
|
+
|
175
|
+
# Returns parameters to pass to an invocation of
|
176
|
+
# <tt>wu-local</tt>.
|
177
|
+
#
|
178
|
+
# Parameters like <tt>--reduce_tasks</tt> which are relevant to
|
179
|
+
# Wukong-Hadoop will be interpreted and *not* passed. Others
|
180
|
+
# will be passed unmodified.
|
181
|
+
#
|
182
|
+
# @return [String]
|
183
|
+
def non_wukong_hadoop_params_string
|
184
|
+
params_to_pass.reject do |param, val|
|
185
|
+
params_to_pass.definition_of(param, :wukong_hadoop)
|
186
|
+
end.map do |param,val|
|
187
|
+
"--#{param}=#{Shellwords.escape(val.to_s)}"
|
188
|
+
end.join(" ")
|
189
|
+
end
|
190
|
+
|
191
|
+
# Execute a command composed of the given parts.
|
192
|
+
#
|
193
|
+
# Will print the command instead of the <tt>--dry_run</tt>
|
194
|
+
# option was given.
|
195
|
+
#
|
196
|
+
# @param [Array<String>] argv
|
197
|
+
def execute_command!(*argv)
|
198
|
+
command = argv.flatten.reject(&:blank?).join(" \\\n ")
|
199
|
+
if settings[:dry_run]
|
200
|
+
log.info("Dry run:")
|
201
|
+
puts command
|
202
|
+
else
|
203
|
+
puts `#{command}`
|
204
|
+
raise Error.new("Command failed!") unless $?.success?
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -6,11 +6,6 @@ module Wukong
|
|
6
6
|
# streaming}[http://hadoop.apache.org/docs/r0.15.2/streaming.html].
|
7
7
|
module HadoopInvocation
|
8
8
|
|
9
|
-
# Raise an error unless we have input and output.
|
10
|
-
def ensure_input_and_output!
|
11
|
-
raise Error.new("Explicit --input and --output paths are required to run a job in Hadoop mode.") if input_paths.nil? || input_paths.empty? || output_path.nil? || output_path.empty?
|
12
|
-
end
|
13
|
-
|
14
9
|
# Remove the output path.
|
15
10
|
#
|
16
11
|
# Will not actually do anything if the <tt>--dry_run</tt> option
|
@@ -120,7 +115,7 @@ module Wukong
|
|
120
115
|
:reduce_tasks, :respect_exit_status,
|
121
116
|
:reuse_jvms, :timeout,
|
122
117
|
:max_tracker_failures, :max_map_attempts,
|
123
|
-
:max_reduce_attempts
|
118
|
+
:max_reduce_attempts, :reduce_speculative
|
124
119
|
].map do |opt|
|
125
120
|
defn = settings.definition_of(opt, :description)
|
126
121
|
val = settings[opt]
|
@@ -180,7 +175,7 @@ module Wukong
|
|
180
175
|
# :nodoc:
|
181
176
|
def hadoop_recycle_env
|
182
177
|
use_alternative_gemfile if settings[:gemfile]
|
183
|
-
%w[BUNDLE_GEMFILE].map{ |var| %Q{-cmdenv '#{var}=#{ENV[var]}'} if ENV[var] }.compact
|
178
|
+
%w[BUNDLE_GEMFILE LANG].map{ |var| %Q{-cmdenv '#{var}=#{ENV[var]}'} if ENV[var] }.compact
|
184
179
|
end
|
185
180
|
|
186
181
|
# :nodoc:
|