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
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

#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



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_cmdObject



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_homeObject



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_pathObject



66
67
68
# File 'lib/jruby-on-hadoop/client.rb', line 66

def lib_path
  JRubyOnHadoop.lib_path
end

#main_jar_pathObject



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

def main_jar_path
  JRubyOnHadoop.jar_path
end

#mapred_argsObject



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_filesObject



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

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

#opt_libjarsObject



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_argsObject



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

#runObject



29
30
31
# File 'lib/jruby-on-hadoop/client.rb', line 29

def run
  exec cmd
end