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_cmd ⇒ Object
- #hadoop_home ⇒ Object
-
#initialize(args = []) ⇒ Client
constructor
A new instance of Client.
- #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 14 |
# File 'lib/jruby-on-hadoop/client.rb', line 7 def initialize(args=[]) @args = args parse_args # env check hadoop_home and hadoop_cmd ENV['HADOOP_CLASSPATH'] = "#{lib_path}:#{File.dirname(@script_path)}" 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
33 34 35 36 |
# File 'lib/jruby-on-hadoop/client.rb', line 33 def cmd "#{hadoop_cmd} jar #{main_jar_path} #{JAVA_MAIN_CLASS}" + " -libjars #{opt_libjars} -files #{opt_files} #{mapred_args}" end |
#hadoop_cmd ⇒ Object
22 23 24 25 26 27 |
# File 'lib/jruby-on-hadoop/client.rb', line 22 def hadoop_cmd hadoop = `which hadoop 2>/dev/null` hadoop = "#{hadoop_home}/bin/hadoop" if hadoop.nil? or hadoop.empty? raise 'cannot find hadoop command' unless hadoop hadoop.chomp end |
#hadoop_home ⇒ Object
16 17 18 19 20 |
# File 'lib/jruby-on-hadoop/client.rb', line 16 def hadoop_home home = ENV['HADOOP_HOME'] raise 'HADOOP_HOME is not set' if home.nil? or home.empty? home end |
#lib_path ⇒ Object
66 67 68 |
# File 'lib/jruby-on-hadoop/client.rb', line 66 def lib_path JRubyOnHadoop.lib_path end |
#main_jar_path ⇒ Object
62 63 64 |
# File 'lib/jruby-on-hadoop/client.rb', line 62 def main_jar_path JRubyOnHadoop.jar_path end |
#mapred_args ⇒ Object
46 47 48 49 50 51 |
# File 'lib/jruby-on-hadoop/client.rb', line 46 def mapred_args args = "--script #{@script} " args += "#{@inputs} " if @inputs args += "#{@outputs}" if @outputs args end |
#opt_files ⇒ Object
58 59 60 |
# File 'lib/jruby-on-hadoop/client.rb', line 58 def opt_files @files.join(',') end |
#opt_libjars ⇒ Object
53 54 55 56 |
# File 'lib/jruby-on-hadoop/client.rb', line 53 def opt_libjars # jruby jars [JRubyJars.core_jar_path, JRubyJars.stdlib_jar_path].join(',') end |
#parse_args ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/jruby-on-hadoop/client.rb', line 38 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
29 30 31 |
# File 'lib/jruby-on-hadoop/client.rb', line 29 def run exec cmd end |