Class: DeepTest::Distributed::LandingShip

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/distributed/landing_ship.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ LandingShip

Returns a new instance of LandingShip.



4
5
6
# File 'lib/deep_test/distributed/landing_ship.rb', line 4

def initialize(config)
  @config = config
end

Instance Method Details

#deploy_agentsObject



32
33
34
35
36
37
38
39
40
# File 'lib/deep_test/distributed/landing_ship.rb', line 32

def deploy_agents
  @wire.send_message Beachhead::DeployAgents
  begin
    message = @wire.next_message :timeout => 1
    raise "Unexpected message from Beachhead: #{message.inspect}" unless message.body == Beachhead::Done
  rescue Telegraph::NoMessageAvailable
    retry
  end
end

#establish_beachhead(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/deep_test/distributed/landing_ship.rb', line 12

def establish_beachhead(options)
  command  = "#{ssh_command(options)} '#{spawn_command(options)}' 2>&1"
  DeepTest.logger.debug { "Establishing Beachhead: #{command}" }
  
  output = `#{command}`
  output.each do |line|
    if DeepTest.logger.level == Logger::DEBUG
      puts output
    end
    if line =~ /Beachhead port: (.+)/
      @wire = Telegraph::Wire.connect(@config[:address], $1.to_i)
    end
  end
  raise "LandingShip unable to establish Beachhead.  Output from #{@config[:address]} was:\n#{output}" unless @wire
end

#load_files(files) ⇒ Object



28
29
30
# File 'lib/deep_test/distributed/landing_ship.rb', line 28

def load_files(files)
  @wire.send_message Beachhead::LoadFiles.new(files)
end

#push_code(options) ⇒ Object



8
9
10
# File 'lib/deep_test/distributed/landing_ship.rb', line 8

def push_code(options)
  RSync.push(@config[:address], options.sync_options, options.mirror_path)
end

#spawn_command(options) ⇒ Object



52
53
54
55
56
57
# File 'lib/deep_test/distributed/landing_ship.rb', line 52

def spawn_command(options)
  "#{ShellEnvironment.} && " + 
  "cd #{options.mirror_path} && " + 
  "OPTIONS=#{options.to_command_line} " + 
  "ruby lib/deep_test/distributed/establish_beachhead.rb" 
end

#ssh_command(options) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/deep_test/distributed/landing_ship.rb', line 42

def ssh_command(options)
  username_option = if options.sync_options[:username]
                      " -l #{options.sync_options[:username]}"
                    else
                      ""
                    end

  "ssh -4 #{@config[:address]}#{username_option}"
end