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.



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

def attributes
  @attributes
end

#inputObject

Returns the value of attribute input.



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

def input
  @input
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#outputObject

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#cmdObject

This depends on the type of script



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

def cmd
  raise "Override this in subclass!"
end

#envObject

Allows for setting the environment the script will be ran in



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

def env
  ENV
end

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



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

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.



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

def local_cmd
  raise "Override this in subclass!"
end

#refresh!Object

So we can reuse ourselves



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

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

#run(mode = :hadoop) ⇒ Object

Default is to run with hadoop



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

def run mode=:hadoop
  case mode
  when :local then
    sh local_cmd do |res, ok|
      Log.info("Exit status was #{ok}")
      raise "Local mode script failed with exit status #{ok}" if ok != 0
    end
  when :hadoop then
    sh cmd do |res, ok|
      Log.info("Exit status was #{ok}")
      raise "Hadoop mode script failed with exit status #{ok}" if ok != 0
    end
  end
end

#scriptObject



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

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