Class: Rubadoop::MapReduce::CallJava

Inherits:
BaseDsl
  • Object
show all
Defined in:
lib/rubadoop/map_reduce/call_java.rb

Instance Attribute Summary collapse

Attributes inherited from BaseDsl

#params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDsl

#has_param?, #optional_param

Constructor Details

#initialize(params = {}) ⇒ CallJava

Returns a new instance of CallJava.



20
21
22
# File 'lib/rubadoop/map_reduce/call_java.rb', line 20

def initialize(params = {})
  super(params)
end

Instance Attribute Details

#archivesObject

Returns the value of attribute archives.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def archives
  @archives
end

#argsObject

Returns the value of attribute args.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def args
  @args
end

#confsObject

Returns the value of attribute confs.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def confs
  @confs
end

#envsObject

Returns the value of attribute envs.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def envs
  @envs
end

#filesObject

Returns the value of attribute files.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def files
  @files
end

#jarObject

Returns the value of attribute jar.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def jar
  @jar
end

#main_classObject

Returns the value of attribute main_class.



4
5
6
# File 'lib/rubadoop/map_reduce/call_java.rb', line 4

def main_class
  @main_class
end

Class Method Details

.new_java_call(params = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rubadoop/map_reduce/call_java.rb', line 7

def new_java_call(params = {}, &block)
  builder = CallJava.new(params)
  if block_given?
    if block.arity == 1
      yield builder
    else
      builder.instance_eval &block
    end
  end
  builder
end

Instance Method Details

#archive(location, symlink) ⇒ Object



58
59
60
61
# File 'lib/rubadoop/map_reduce/call_java.rb', line 58

def archive(location, symlink)
  @archives ||= []
  @archives << "#{location}##{symlink}"
end

#arg(*value) ⇒ Object



48
49
50
51
# File 'lib/rubadoop/map_reduce/call_java.rb', line 48

def arg(*value)
  @args ||= []
  @args.concat value
end

#conf(name, value) ⇒ Object



29
30
31
32
# File 'lib/rubadoop/map_reduce/call_java.rb', line 29

def conf(name, value)
  @confs ||= {}
  @confs[name.to_sym] = value
end

#conf_concat(name, value) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubadoop/map_reduce/call_java.rb', line 34

def conf_concat(name, value)
  @confs ||= {}
  prev_value = @confs[name.to_sym]
  if prev_value
    if prev_value.kind_of?(Array)
      prev_value << value
    else
      @confs[name.to_sym] = [prev_value, value]
    end
  else
    @confs[name.to_sym] = value
  end
end

#env(name, value) ⇒ Object



24
25
26
27
# File 'lib/rubadoop/map_reduce/call_java.rb', line 24

def env(name, value)
  @envs ||= {}
  @envs[name.to_sym] = value
end

#file(location, symlink) ⇒ Object



53
54
55
56
# File 'lib/rubadoop/map_reduce/call_java.rb', line 53

def file(location, symlink)
  @files ||= []
  @files << "#{location}##{symlink}"
end

#to_hObject



95
96
97
98
99
100
101
102
# File 'lib/rubadoop/map_reduce/call_java.rb', line 95

def to_h
  validate
  built = {}
  [:@jar, :@main_class, :@envs, :@args, :@confs, :@files, :@archives].each { |entry|
    built[entry.to_s.delete("@").to_sym] = instance_variable_get(entry)
  }
  built
end

#to_hadoop_cli(opts = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rubadoop/map_reduce/call_java.rb', line 63

def to_hadoop_cli(opts = {})
  validate
  cmd = []
  unless opts[:skip_jar]
    cmd.concat ["hadoop", "jar", jar]
    cmd << @main_class unless @main_class.nil?
  end

  @confs.each { |key, value|
    if value.kind_of?(Array)
      value.each { |entry|
        cmd. << "-D#{key}=#{entry}"
      }
    else
      cmd. << "-D#{key}=#{value}"
    end
  } if @confs
  @envs.each { |key, value|
    cmd.concat ['-cmdenv', "#{key}=#{value}"]
  } if @envs
  @files.each { |entry|
    cmd.concat ['-cacheFile', "#{entry}"]
  } if @files
  @archives.each { |entry|
    cmd.concat ['-cacheArchive', "#{entry}"]
  } if @archives
  unless opts[:skip_args]
    cmd.concat @args if @args
  end
  cmd
end

#validateObject



104
105
106
107
108
# File 'lib/rubadoop/map_reduce/call_java.rb', line 104

def validate
  [:@jar].each { |property|
    raise "Missing #{property}" if instance_variable_get(property).nil?
  }
end