Skip to content

Commit

Permalink
fix up remote env parsing to provide access to hadoop properties and …
Browse files Browse the repository at this point in the history
…local vars
  • Loading branch information
andykent committed Oct 27, 2009
1 parent 48c5915 commit 26e2e87
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.4.995
0.4.996
10 changes: 9 additions & 1 deletion bin/mandy-hadoop
Expand Up @@ -48,6 +48,13 @@ def gemfile(file)
File.exist?(path) ? path : nil
end

def set_env(opts_string)
opts_string.split(' ').each do |pair|
key, value = pair.split("=")
ENV[key] = value
end
end

file = ARGV[0]
filename = File.basename(file)
inputs = ARGV[1].split(",")
Expand All @@ -56,8 +63,9 @@ input = inputs.map {|path| "-input \"#{path}\""}.join(" ")
output_folder = ARGV[2]
config = absolute_path(options.config || 'cluster.xml')
puts "Packaging code for distribution..."
payload = Mandy::Packer.pack(file, options.payload || ARGV[0], gemfile(options.gemfile))
payload = Mandy::Packer.pack(file, options.payload || ARGV[0], gemfile(options.gemfile))
cmdenv = options.cmdenv
set_env(cmdenv)

at_exit do
puts
Expand Down
4 changes: 2 additions & 2 deletions lib/mandy/job.rb
Expand Up @@ -12,8 +12,8 @@ def find_by_name(name)
end

def parameter(name)
return find_json_param(name) if json_provided?
ENV[name.to_s]
param = find_json_param(name) if json_provided?
param || ENV[name.to_s]
end

private
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/examples/parameterised_job_spec.rb
Expand Up @@ -5,14 +5,15 @@

Mandy.job "#{Mandy.parameter(:prefix)} Parameterised job" do
map do |key, value|
emit(key, parameter(:argument))
emit(key, "#{parameter(:argument)} #{parameter(:name)}")
end
end

describe "Parameterised example" do
before(:all) do
ENV["json"] = nil
@runner = Mandy::TestRunner.new("Test Parameterised job", :parameters => {:argument => "hello world"})
ENV['name'] = 'Andy'
@runner = Mandy::TestRunner.new("Test Parameterised job", :parameters => {:argument => "hello"})
end

after(:all) do
Expand All @@ -22,7 +23,7 @@
describe "Mapper" do
it "should emit parameter as value" do
@runner.map("key\tvalue") do |mapper|
mapper.should_receive(:emit).with("key", "hello world")
mapper.should_receive(:emit).with("key", "hello Andy")
end
end
end
Expand Down

0 comments on commit 26e2e87

Please sign in to comment.