Class: Clusta::Runner
- Inherits:
-
Object
- Object
- Clusta::Runner
- Defined in:
- lib/clusta/runner.rb
Constant Summary collapse
- RUN_ARG_REGEXP =
/--run=./
Instance Method Summary collapse
-
#initialize(name, argv) ⇒ Runner
constructor
A new instance of Runner.
- #list_geometry! ⇒ Object
- #list_transforms! ⇒ Object
- #load_geometry! ⇒ Object
- #load_transforms! ⇒ Object
- #print_help! ⇒ Object
- #rb_files_within(key, &block) ⇒ Object
- #run! ⇒ Object
- #run_map_reduce! ⇒ Object
- #run_transform! ⇒ Object
Constructor Details
#initialize(name, argv) ⇒ Runner
Returns a new instance of Runner.
19 20 21 22 |
# File 'lib/clusta/runner.rb', line 19 def initialize name, argv @name = name @argv = argv end |
Instance Method Details
#list_geometry! ⇒ Object
79 80 81 |
# File 'lib/clusta/runner.rb', line 79 def list_geometry! puts Clusta::Geometry.listing end |
#list_transforms! ⇒ Object
75 76 77 |
# File 'lib/clusta/runner.rb', line 75 def list_transforms! puts Clusta::Transforms.listing end |
#load_geometry! ⇒ Object
55 56 57 58 59 |
# File 'lib/clusta/runner.rb', line 55 def load_geometry! rb_files_within(:geometry_path) do |path| Clusta::Geometry.load_from(path) end end |
#load_transforms! ⇒ Object
49 50 51 52 53 |
# File 'lib/clusta/runner.rb', line 49 def load_transforms! rb_files_within(:transforms_path) do |path| Clusta::Transforms.load_from(path) end end |
#print_help! ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/clusta/runner.rb', line 102 def print_help! begin s = Wukong::Script.new(nil, nil) rescue RuntimeError => e raise Error.new(e.) end s.run end |
#rb_files_within(key, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/clusta/runner.rb', line 61 def rb_files_within key, &block return if Settings[key].nil? || Settings[key].empty? Settings[key].split(':').each do |dir| = File.(dir) unless File.directory?() $stderr.puts("WARNING: #{} is not a directory") next end Dir[File.join(, '*.rb')].each do |path| yield path end end end |
#run! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/clusta/runner.rb', line 24 def run! begin Settings.resolve! case when Settings[:list_transforms] load_transforms! list_transforms! when Settings[:list_geometry] load_geometry! list_geometry! when Settings[:transform] load_transforms! load_geometry! run_transform! when Settings[:map_command] || Settings[:reduce_command] run_map_reduce! else print_help! end rescue Clusta::Error => e $stderr.puts "ERROR: #{e.}" exit(1) end end |
#run_map_reduce! ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/clusta/runner.rb', line 91 def run_map_reduce! ::ARGV.replace(@argv) ::ARGV.push('--run=local') unless ARGV.any? { |arg| arg =~ self.class::RUN_ARG_REGEXP } begin s = Wukong::Script.new(nil, nil) rescue RuntimeError => e raise Error.new(e.) end s.run end |
#run_transform! ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/clusta/runner.rb', line 83 def run_transform! transform = Clusta::Transforms.from_name(Settings[:transform]) ::ARGV.replace(@argv) ::ARGV.push('--run=local') unless ARGV.any? { |arg| arg =~ self.class::RUN_ARG_REGEXP } script = Clusta::Transforms.script_for(transform) script.run end |