Class: JRubyOnHadoop::Client
- Inherits:
-
Object
- Object
- JRubyOnHadoop::Client
- Defined in:
- lib/jruby-on-hadoop/client.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
- #cmd ⇒ Object
- #hadoop_classpath ⇒ Object
- #hadoop_cmd ⇒ Object
- #hadoop_home ⇒ Object
-
#initialize(args = []) ⇒ Client
constructor
A new instance of Client.
- #jruby_jars ⇒ Object
- #lib_path ⇒ Object
- #main_jar_path ⇒ Object
- #mapred_args ⇒ Object
- #opt_files ⇒ Object
- #opt_libjars ⇒ Object
- #parse_args ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args = []) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 |
# File 'lib/jruby-on-hadoop/client.rb', line 7 def initialize(args=[]) @args = args parse_args # env get / set and check hadoop_home and hadoop_cmd and hadoop_classpath end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/jruby-on-hadoop/client.rb', line 5 def files @files end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
5 6 7 |
# File 'lib/jruby-on-hadoop/client.rb', line 5 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
5 6 7 |
# File 'lib/jruby-on-hadoop/client.rb', line 5 def outputs @outputs end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
5 6 7 |
# File 'lib/jruby-on-hadoop/client.rb', line 5 def script @script end |
Instance Method Details
#cmd ⇒ Object
35 36 37 38 |
# File 'lib/jruby-on-hadoop/client.rb', line 35 def cmd "#{hadoop_cmd} jar #{main_jar_path} #{JAVA_MAIN_CLASS}" + " -libjars #{opt_libjars} -files #{opt_files} #{mapred_args}" end |
#hadoop_classpath ⇒ Object
26 27 28 29 |
# File 'lib/jruby-on-hadoop/client.rb', line 26 def hadoop_classpath ENV['HADOOP_CLASSPATH'] = ([lib_path, File.dirname(@script_path)] + jruby_jars).join(':') end |
#hadoop_cmd ⇒ Object
19 20 21 22 23 24 |
# File 'lib/jruby-on-hadoop/client.rb', line 19 def hadoop_cmd hadoop = `which hadoop 2>/dev/null` hadoop = "#{hadoop_home}/bin/hadoop" if hadoop.empty? and (!hadoop_home.empty?) raise 'cannot find hadoop command' if hadoop.empty? hadoop.chomp end |
#hadoop_home ⇒ Object
15 16 17 |
# File 'lib/jruby-on-hadoop/client.rb', line 15 def hadoop_home ENV['HADOOP_HOME'] end |
#jruby_jars ⇒ Object
55 56 57 |
# File 'lib/jruby-on-hadoop/client.rb', line 55 def jruby_jars [JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path] end |
#lib_path ⇒ Object
62 |
# File 'lib/jruby-on-hadoop/client.rb', line 62 def lib_path; JRubyOnHadoop.lib_path end |
#main_jar_path ⇒ Object
61 |
# File 'lib/jruby-on-hadoop/client.rb', line 61 def main_jar_path; JRubyOnHadoop.jar_path end |
#mapred_args ⇒ Object
48 49 50 51 52 53 |
# File 'lib/jruby-on-hadoop/client.rb', line 48 def mapred_args args = "--script #{@script} " args += "#{@inputs} " if @inputs args += "#{@outputs}" if @outputs args end |
#opt_files ⇒ Object
60 |
# File 'lib/jruby-on-hadoop/client.rb', line 60 def opt_files; @files.join(',') end |
#opt_libjars ⇒ Object
59 |
# File 'lib/jruby-on-hadoop/client.rb', line 59 def opt_libjars; jruby_jars.join(',') end |
#parse_args ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/jruby-on-hadoop/client.rb', line 40 def parse_args @script_path = @args.size > 0 ? @args[0] : 'mapred.rb' @script = File.basename(@script_path) @inputs = @args[1] if @args.size == 3 @outputs = @args[2] if @args.size == 3 @files = [@script_path, JRubyOnHadoop.wrapper_ruby_file] end |
#run ⇒ Object
31 32 33 |
# File 'lib/jruby-on-hadoop/client.rb', line 31 def run exec cmd end |