Module: Swineherd::Script::Common
- Included in:
- HadoopScript, PigScript, RScript, WukongScript
- Defined in:
- lib/swineherd/script.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#input ⇒ Object
Returns the value of attribute input.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
-
#cmd ⇒ Object
This depends on the type of script.
-
#env ⇒ Object
Allows for setting the environment the script will be ran in.
- #initialize(source, input = [], output = [], options = {}, attributes = {}) ⇒ Object
-
#local_cmd ⇒ Object
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.
-
#refresh! ⇒ Object
So we can reuse ourselves.
-
#run(mode = :hadoop) ⇒ Object
Default is to run with hadoop.
- #script ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/swineherd/script.rb', line 9 def attributes @attributes end |
#input ⇒ Object
Returns the value of attribute input.
9 10 11 |
# File 'lib/swineherd/script.rb', line 9 def input @input end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/swineherd/script.rb', line 9 def @options end |
#output ⇒ Object
Returns the value of attribute output.
9 10 11 |
# File 'lib/swineherd/script.rb', line 9 def output @output end |
Instance Method Details
#cmd ⇒ Object
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 |
#env ⇒ Object
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 = [], = {}, attributes ={}) @source = source @input = input @output = output @options = @attributes = attributes end |
#local_cmd ⇒ Object
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 |
#script ⇒ Object
25 26 27 |
# File 'lib/swineherd/script.rb', line 25 def script @script ||= Template.new(@source, @attributes).substitute! end |