Module: Swineherd::Script::Common

Included in:
HadoopScript, PigScript, RScript, WukongScript
Defined in:
lib/swineherd/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/swineherd/script.rb', line 10

def attributes
  @attributes
end

#inputObject

Returns the value of attribute input.



10
11
12
# File 'lib/swineherd/script.rb', line 10

def input
  @input
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/swineherd/script.rb', line 10

def options
  @options
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/swineherd/script.rb', line 10

def output
  @output
end

Instance Method Details

#cmdObject

This depends on the type of script



42
43
44
# File 'lib/swineherd/script.rb', line 42

def cmd
  raise "Override this in subclass!"
end

#envObject

Allows for setting the environment the script will be ran in



22
23
24
# File 'lib/swineherd/script.rb', line 22

def env
  ENV
end

#initialize(source, input = [], output = [], options = {}, attributes = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/swineherd/script.rb', line 11

def initialize(source, input = [], output = [], options = {}, attributes ={})
  @source     = source
  @input      = input
  @output     = output
  @options    = options
  @attributes = attributes
end

#local_cmdObject

Override this in subclass to decide how script runs in ‘local’ mode Best practice is that it needs to be able to run on a laptop w/o hadoop.



51
52
53
# File 'lib/swineherd/script.rb', line 51

def local_cmd
  raise "Override this in subclass!"
end

#refresh!Object

So we can reuse ourselves



33
34
35
36
37
# File 'lib/swineherd/script.rb', line 33

def refresh!
  @script = nil
  @output = []
  @input  = []
end

#run(mode = :hadoop) ⇒ Object

Default is to run with hadoop



58
59
60
61
62
63
64
65
66
67
# File 'lib/swineherd/script.rb', line 58

def run mode=:hadoop
  command = case mode
  when :local then local_cmd
  when :hadoop then cmd
  end

  sh command do |ok, status|
    ok or raise "#{mode.to_s.capitalize} mode script failed with exit status #{status}"
  end
end

#scriptObject



26
27
28
# File 'lib/swineherd/script.rb', line 26

def script
  @script ||= Template.new(@source, @attributes).substitute!
end