Class: JRubyOnHadoop::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby-on-hadoop/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filesObject (readonly)

Returns the value of attribute files.



5
6
7
# File 'lib/jruby-on-hadoop/client.rb', line 5

def files
  @files
end

#inputsObject (readonly)

Returns the value of attribute inputs.



5
6
7
# File 'lib/jruby-on-hadoop/client.rb', line 5

def inputs
  @inputs
end

#outputsObject (readonly)

Returns the value of attribute outputs.



5
6
7
# File 'lib/jruby-on-hadoop/client.rb', line 5

def outputs
  @outputs
end

#scriptObject (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

#cmdObject



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_classpathObject



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_cmdObject



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_homeObject



15
16
17
# File 'lib/jruby-on-hadoop/client.rb', line 15

def hadoop_home
  ENV['HADOOP_HOME']
end

#jruby_jarsObject



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_pathObject



62
# File 'lib/jruby-on-hadoop/client.rb', line 62

def lib_path; JRubyOnHadoop.lib_path end

#main_jar_pathObject



61
# File 'lib/jruby-on-hadoop/client.rb', line 61

def main_jar_path; JRubyOnHadoop.jar_path end

#mapred_argsObject



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_filesObject



60
# File 'lib/jruby-on-hadoop/client.rb', line 60

def opt_files; @files.join(',') end

#opt_libjarsObject



59
# File 'lib/jruby-on-hadoop/client.rb', line 59

def opt_libjars; jruby_jars.join(',') end

#parse_argsObject



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

#runObject



31
32
33
# File 'lib/jruby-on-hadoop/client.rb', line 31

def run
  exec cmd
end