mza-launch-pad 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +41 -0
- data/README +13 -0
- data/Rakefile +29 -0
- data/bin/launch-pad +14 -0
- data/bin/lp-monitor +90 -0
- data/config/aws_default.yml +2 -0
- data/examples/align_control.rb +4 -0
- data/examples/dispatch.rb +19 -0
- data/examples/monitor.rb +31 -0
- data/examples/queue.rb +18 -0
- data/examples/retrieve.rb +43 -0
- data/examples/set.rb +3 -0
- data/history.txt +4 -0
- data/launch-pad.gemspec +38 -0
- data/lib/launch-pad/command/haproxy.rb +41 -0
- data/lib/launch-pad/command/host.rb +27 -0
- data/lib/launch-pad/command.rb +23 -0
- data/lib/launch-pad/exception/undefined_registration_exception.rb +4 -0
- data/lib/launch-pad/models/node.rb +2 -0
- data/lib/launch-pad/parser.rb +29 -0
- data/lib/launch-pad.rb +16 -0
- data/lib/migrations/create_nodes.rb +13 -0
- data/lib/turbo/getter.rb +35 -0
- data/lib/turbo/key.rb +37 -0
- data/lib/turbo/message.rb +19 -0
- data/lib/turbo/queue.rb +38 -0
- data/lib/turbo/setter.rb +37 -0
- data/lib/turbo.rb +10 -0
- data/post_install.txt +3 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/expected/haproxy.conf +35 -0
- data/test/files/haproxy.erb +32 -0
- data/test/files/keys.yml +2 -0
- data/test/haproxy.rb +26 -0
- data/test/key_test.rb +21 -0
- data/test/parser_test.rb +27 -0
- data/test/runner.rb +3 -0
- data/test/test_helper.rb +17 -0
- metadata +117 -0
data/Manifest.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Manifest.txt
|
2
|
+
README
|
3
|
+
Rakefile
|
4
|
+
bin/launch-pad
|
5
|
+
bin/lp-monitor
|
6
|
+
config/aws.yml
|
7
|
+
config/aws_default.yml
|
8
|
+
examples/align_control.rb
|
9
|
+
examples/dispatch.rb
|
10
|
+
examples/monitor.rb
|
11
|
+
examples/queue.rb
|
12
|
+
examples/retrieve.rb
|
13
|
+
examples/set.rb
|
14
|
+
history.txt
|
15
|
+
launch-pad.gemspec
|
16
|
+
lib/launch-pad.rb
|
17
|
+
lib/launch-pad/command.rb
|
18
|
+
lib/launch-pad/command/haproxy.rb
|
19
|
+
lib/launch-pad/command/host.rb
|
20
|
+
lib/launch-pad/exception/undefined_registration_exception.rb
|
21
|
+
lib/launch-pad/models/node.rb
|
22
|
+
lib/launch-pad/parser.rb
|
23
|
+
lib/migrations/create_nodes.rb
|
24
|
+
lib/turbo.rb
|
25
|
+
lib/turbo/getter.rb
|
26
|
+
lib/turbo/key.rb
|
27
|
+
lib/turbo/message.rb
|
28
|
+
lib/turbo/queue.rb
|
29
|
+
lib/turbo/setter.rb
|
30
|
+
post_install.txt
|
31
|
+
script/console
|
32
|
+
script/destroy
|
33
|
+
script/generate
|
34
|
+
test/expected/haproxy.conf
|
35
|
+
test/files/haproxy.erb
|
36
|
+
test/files/keys.yml
|
37
|
+
test/haproxy.rb
|
38
|
+
test/key_test.rb
|
39
|
+
test/parser_test.rb
|
40
|
+
test/runner.rb
|
41
|
+
test/test_helper.rb
|
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Launch Pad
|
2
|
+
----------
|
3
|
+
|
4
|
+
Launch Pad is a gem for automated launching, monitoring and running of distributed
|
5
|
+
tasks using Amazon Web Services. It is the sister project to Mission Control
|
6
|
+
(http://github.com/mza/mission-control), a web application for managing distributed computation on elastic clusters.
|
7
|
+
|
8
|
+
Launch Pad is an open source project, available under the MIT license (see doc/license.txt).
|
9
|
+
|
10
|
+
The latest version of the Launch Pad source code is available here:
|
11
|
+
+ http://github.com/mza/launch-pad
|
12
|
+
|
13
|
+
(c) 2008, Matt Wood : greenisgood.co.uk
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/launch-pad'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('launch-pad', LaunchPad::VERSION) do |p|
|
7
|
+
p.developer('Matt Wood', 'matt.j.wood@gmail.com')
|
8
|
+
p.changes = p.paragraphs_of("history.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'post_install.txt'
|
10
|
+
p.rubyforge_name = p.name
|
11
|
+
p.summary = "Something summary"
|
12
|
+
# p.extra_deps = [
|
13
|
+
# ['activesupport','>= 2.0.2'],
|
14
|
+
# ]
|
15
|
+
p.extra_dev_deps = [
|
16
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
17
|
+
]
|
18
|
+
|
19
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
20
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
21
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
22
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
26
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
27
|
+
|
28
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
29
|
+
# task :default => [:spec, :features]
|
data/bin/launch-pad
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'daemons'
|
5
|
+
|
6
|
+
command = ARGV[0]
|
7
|
+
queue = ARGV[1]
|
8
|
+
root_dir = ARGV[2]
|
9
|
+
|
10
|
+
puts "Starting lp-monitor with queue: #{queue}"
|
11
|
+
|
12
|
+
options = { :ARGV => [command, '--', queue, root_dir]}
|
13
|
+
|
14
|
+
Daemons.run("/usr/local/bin/lp-monitor", options)
|
data/bin/lp-monitor
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'right_aws'
|
5
|
+
require 'turbo'
|
6
|
+
require 'launch-pad'
|
7
|
+
require 'yaml'
|
8
|
+
require 'active_record'
|
9
|
+
require 'sqlite3'
|
10
|
+
control_queue = ARGV[0]
|
11
|
+
root_dir = ARGV[1]
|
12
|
+
|
13
|
+
if control_queue.nil?
|
14
|
+
puts "No queue name specified: exiting"
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
host = `hostname`
|
19
|
+
|
20
|
+
puts "#{host} monitoring #{control_queue}"
|
21
|
+
puts "Root directory: #{root_dir}"
|
22
|
+
|
23
|
+
Turbo::Key.configuration = "#{root_dir}/config/aws.yml"
|
24
|
+
|
25
|
+
ActiveRecord::Base.establish_connection({
|
26
|
+
:adapter => "sqlite3",
|
27
|
+
:dbfile => "#{root_dir}/db/database.sqlite"
|
28
|
+
})
|
29
|
+
|
30
|
+
queue = Turbo::Queue.new(control_queue)
|
31
|
+
queue.send(%q{register: haproxy})
|
32
|
+
queue.send(%q{
|
33
|
+
register: host
|
34
|
+
name: ec2-1-2-3-4.amazonaws.com
|
35
|
+
role: api
|
36
|
+
})
|
37
|
+
|
38
|
+
queue.send(%q{
|
39
|
+
unregister: host
|
40
|
+
name: ec2-1-2-3-4.amazonaws.com
|
41
|
+
role: api
|
42
|
+
})
|
43
|
+
|
44
|
+
activity = nil
|
45
|
+
rebuild_config = false
|
46
|
+
|
47
|
+
loop do
|
48
|
+
|
49
|
+
puts "Checking queue"
|
50
|
+
|
51
|
+
if queue.messages?
|
52
|
+
for message in queue.messages
|
53
|
+
puts "MESSAGE: #{message} (cleared)"
|
54
|
+
message.clear
|
55
|
+
command = LaunchPad::Parser.parse(message)
|
56
|
+
|
57
|
+
begin
|
58
|
+
command.activate
|
59
|
+
puts "Command activated: complete (#{command.sets_activity?})"
|
60
|
+
rescue LaunchPad::UndefinedRegistrationException => e
|
61
|
+
puts "Command not defined: #{e}"
|
62
|
+
end
|
63
|
+
|
64
|
+
if command.sets_activity?
|
65
|
+
activity = command
|
66
|
+
puts "Activity reset to: #{activity.class.to_s}"
|
67
|
+
end
|
68
|
+
|
69
|
+
if command.invalidates_config?
|
70
|
+
puts "Marking configuration for rebuild"
|
71
|
+
rebuild_config = true
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
puts "Rebuild? #{rebuild_config}"
|
77
|
+
|
78
|
+
if rebuild_config == true
|
79
|
+
puts "Rebuilding..."
|
80
|
+
unless activity.nil?
|
81
|
+
puts "Rebuilding configuration"
|
82
|
+
activity.rebuild_config :with_templates => "#{root_dir}/templates", :to => "#{root_dir}/config"
|
83
|
+
end
|
84
|
+
rebuild_config = false
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
sleep 5
|
90
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'right_aws'
|
3
|
+
require 'turbo/key'
|
4
|
+
|
5
|
+
include Turbo
|
6
|
+
|
7
|
+
sqs = RightAws::SqsGen2.new(Key.access, Key.secret)
|
8
|
+
jobs = sqs.queue('jobqueue')
|
9
|
+
|
10
|
+
file = ARGV[0]
|
11
|
+
|
12
|
+
puts "Available messages: #{jobs.size}"
|
13
|
+
|
14
|
+
unless file.blank?
|
15
|
+
puts "Posting: #{file}"
|
16
|
+
jobs.send_message(file)
|
17
|
+
else
|
18
|
+
puts "Nothing to post."
|
19
|
+
end
|
data/examples/monitor.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'right_aws'
|
3
|
+
require 'turbo/key'
|
4
|
+
|
5
|
+
include Turbo
|
6
|
+
|
7
|
+
sqs = RightAws::SqsGen2.new(Key.access, Key.secret)
|
8
|
+
jobs = sqs.queue('jobqueue')
|
9
|
+
messages = sqs.queue('eventqueue')
|
10
|
+
progress = sqs.queue('progressqueue')
|
11
|
+
|
12
|
+
puts "Genome alignment: queue monitor"
|
13
|
+
puts "-------------------------------"
|
14
|
+
puts ""
|
15
|
+
puts "Jobs pending: #{jobs.size}"
|
16
|
+
puts "Status updates: #{messages.size}"
|
17
|
+
puts "Progress updates: #{progress.size}"
|
18
|
+
|
19
|
+
if messages.size > 0
|
20
|
+
for i in 0..messages.size
|
21
|
+
message = messages.pop
|
22
|
+
puts "Status update: #{message}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if progress.size > 0
|
27
|
+
for i in 0..progress.size
|
28
|
+
message = progress.pop
|
29
|
+
puts "Progress update: #{message}"
|
30
|
+
end
|
31
|
+
end
|
data/examples/queue.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'right_aws'
|
3
|
+
require 'turbo'
|
4
|
+
|
5
|
+
include Turbo
|
6
|
+
|
7
|
+
sqs = RightAws::SqsGen2.new(Key.access, Key.secret)
|
8
|
+
|
9
|
+
host = "ec2-67-202-19-202.compute-1.amazonaws.com"
|
10
|
+
message = "SRR002677.over60.fastq.02"
|
11
|
+
|
12
|
+
messages = sqs.queue('eventqueue')
|
13
|
+
|
14
|
+
# messages.send_message("Start: #{message} : #{host}")
|
15
|
+
messages.send_message("Complete: #{message} : #{host}")
|
16
|
+
|
17
|
+
# messages = sqs.queue('progressqueue')
|
18
|
+
# messages.send_message("Update: Thu Nov 13 14:18:57 UTC 2008\n10434\n : ec2-67-202-19-202.compute-1.amazonaws.com")
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'right_aws'
|
3
|
+
require 'turbo'
|
4
|
+
|
5
|
+
class Runner
|
6
|
+
|
7
|
+
def self.run(name, key, secret)
|
8
|
+
Turbo::Getter.from_s3 :bucket => "sanger_fastq", :named => name, :to => "/data/fastq/#{name}"
|
9
|
+
result = `/usr/local/bin/ssaha2 -kmer 13 -skip 4 -seeds 4 -diff -1 -output cigar -disk 0 -score 45 -save /data/hashtable /data/fastq/#{name} > /data/results/#{name}.output`
|
10
|
+
result = `/bin/tar -zcf /data/zipped/#{name}.tar.gz /data/results/#{name}.output`
|
11
|
+
s3 = RightAws::S3.new(key, secret)
|
12
|
+
bucket = s3.bucket("sanger_alignment_results", true)
|
13
|
+
key = RightAws::S3::Key.create(bucket, name)
|
14
|
+
key.put name
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
host = `hostname`
|
20
|
+
|
21
|
+
sqs = RightAws::SqsGen2.new(Turbo::Key.access, Turbo::Key.secret)
|
22
|
+
|
23
|
+
loop do
|
24
|
+
|
25
|
+
jobs = sqs.queue('jobqueue')
|
26
|
+
messages = sqs.queue('eventqueue')
|
27
|
+
|
28
|
+
if jobs.size > 0
|
29
|
+
message = jobs.pop
|
30
|
+
|
31
|
+
unless message.blank?
|
32
|
+
messages.send_message("Start: #{message} : #{host}")
|
33
|
+
|
34
|
+
Runner.run(message.to_s, aws_access_key_id, aws_secret_access_key)
|
35
|
+
|
36
|
+
messages.send_message("Complete: #{message} : #{host}")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
sleep 5
|
42
|
+
|
43
|
+
end
|
data/examples/set.rb
ADDED
data/history.txt
ADDED
data/launch-pad.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{launch-pad}
|
5
|
+
s.version = "0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Matt Wood"]
|
9
|
+
s.date = %q{2009-02-15}
|
10
|
+
s.email = ["matt.j.wood@gmail.com"]
|
11
|
+
s.executables = ["launch-pad", "lp-monitor"]
|
12
|
+
s.extra_rdoc_files = ["Manifest.txt", "history.txt", "post_install.txt"]
|
13
|
+
s.files = ["Manifest.txt", "README", "Rakefile", "bin/launch-pad", "bin/lp-monitor", "config/aws.yml", "config/aws_default.yml", "examples/align_control.rb", "examples/dispatch.rb", "examples/monitor.rb", "examples/queue.rb", "examples/retrieve.rb", "examples/set.rb", "history.txt", "launch-pad.gemspec", "lib/launch-pad.rb", "lib/launch-pad/command.rb", "lib/launch-pad/command/haproxy.rb", "lib/launch-pad/command/host.rb", "lib/launch-pad/exception/undefined_registration_exception.rb", "lib/launch-pad/models/node.rb", "lib/launch-pad/parser.rb", "lib/migrations/create_nodes.rb", "lib/turbo.rb", "lib/turbo/getter.rb", "lib/turbo/key.rb", "lib/turbo/message.rb", "lib/turbo/queue.rb", "lib/turbo/setter.rb", "post_install.txt", "script/console", "script/destroy", "script/generate", "test/expected/haproxy.conf", "test/files/haproxy.erb", "test/files/keys.yml", "test/haproxy.rb", "test/key_test.rb", "test/parser_test.rb", "test/runner.rb", "test/test_helper.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.post_install_message = %q{post_install.txt}
|
16
|
+
s.rdoc_options = ["--main", "README"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{launch-pad}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Something summary}
|
21
|
+
s.test_files = ["test/test_helper.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
29
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
32
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
36
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module LaunchPad
|
4
|
+
class Haproxy < Command
|
5
|
+
|
6
|
+
def activate(options = {})
|
7
|
+
begin
|
8
|
+
CreateNodes.migrate(:up)
|
9
|
+
rescue ActiveRecord::StatementInvalid => e
|
10
|
+
puts "Migration failed: #{e}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def sets_activity?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def rebuild_config(options = {})
|
19
|
+
location = options[:with_templates]
|
20
|
+
to = options[:to]
|
21
|
+
puts "Rebuilding Haproxy config with: #{location}"
|
22
|
+
template = ERB.new File.read("#{location}/haproxy.erb")
|
23
|
+
result = template.result(binding)
|
24
|
+
File.open("#{to}/haproxy.conf", 'w') do |f|
|
25
|
+
f.write result
|
26
|
+
end
|
27
|
+
puts "Config file saved - restarting haproxy"
|
28
|
+
`killall haproxy`
|
29
|
+
`haproxy -f #{to}/haproxy.conf`
|
30
|
+
end
|
31
|
+
|
32
|
+
def servers_for(role, options = {})
|
33
|
+
response = ""
|
34
|
+
Node.all.each_with_index do |node,index|
|
35
|
+
response = response + "server #{role}_#{options[:type]}_#{index} #{node.name} cookie app1inst1 check inter 2000 rise 2 fall 5\n"
|
36
|
+
end
|
37
|
+
response
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LaunchPad
|
2
|
+
class Host < Command
|
3
|
+
|
4
|
+
def activate
|
5
|
+
response = true
|
6
|
+
|
7
|
+
if !options[:register].nil?
|
8
|
+
puts "New host: #{options[:name]}"
|
9
|
+
node = Node.new :name => options[:name], :role => options[:role]
|
10
|
+
response = node.save
|
11
|
+
elsif !options[:unregister].nil?
|
12
|
+
puts "Unregistering host: #{options[:name]}"
|
13
|
+
node = Node.find_by_name options[:name]
|
14
|
+
unless node.nil?
|
15
|
+
response = node.delete
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
response
|
20
|
+
end
|
21
|
+
|
22
|
+
def invalidates_config?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LaunchPad
|
2
|
+
class Command
|
3
|
+
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
def initialize(incoming)
|
7
|
+
self.options = incoming
|
8
|
+
end
|
9
|
+
|
10
|
+
def activate
|
11
|
+
puts "Executing: #{self.class}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def sets_activity?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def invalidates_config?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module LaunchPad
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
include LaunchPad
|
8
|
+
|
9
|
+
def self.parse(message)
|
10
|
+
commands = nil
|
11
|
+
|
12
|
+
incoming = YAML::load(message.to_s).symbolize_keys
|
13
|
+
|
14
|
+
key = :register
|
15
|
+
unless incoming[:unregister].nil?
|
16
|
+
key = :unregister
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
command = "LaunchPad::#{incoming[key].camelize}".constantize.new(incoming)
|
21
|
+
rescue NameError => exception
|
22
|
+
raise UndefinedRegistrationException.new exception
|
23
|
+
end
|
24
|
+
|
25
|
+
command
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/launch-pad.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'launch-pad/parser'
|
5
|
+
require 'launch-pad/command'
|
6
|
+
require 'launch-pad/command/haproxy'
|
7
|
+
require 'launch-pad/command/host'
|
8
|
+
require 'launch-pad/exception/undefined_registration_exception'
|
9
|
+
|
10
|
+
require 'active_record'
|
11
|
+
require 'launch-pad/models/node'
|
12
|
+
require 'migrations/create_nodes'
|
13
|
+
|
14
|
+
module LaunchPad
|
15
|
+
VERSION = '0.2'
|
16
|
+
end
|
data/lib/turbo/getter.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Turbo
|
2
|
+
class Getter
|
3
|
+
|
4
|
+
include AWS::S3
|
5
|
+
|
6
|
+
def self.from_s3(options)
|
7
|
+
|
8
|
+
bucket_name = options[:bucket]
|
9
|
+
object_name = options[:named]
|
10
|
+
settings = {}
|
11
|
+
|
12
|
+
settings[:access_key_id] = Turbo::Key.access
|
13
|
+
settings[:secret_access_key] = Turbo::Key.secret
|
14
|
+
|
15
|
+
file = ARGV[0]
|
16
|
+
|
17
|
+
puts "Establishing connection to S3"
|
18
|
+
Base.establish_connection!(
|
19
|
+
:access_key_id => settings[:access_key_id],
|
20
|
+
:secret_access_key => settings[:secret_access_key]
|
21
|
+
)
|
22
|
+
|
23
|
+
bucket = Bucket.find(bucket_name)
|
24
|
+
|
25
|
+
puts "Current bucket store: #{bucket.objects.size}"
|
26
|
+
puts "Downloading: #{file}"
|
27
|
+
open(options[:to], 'w') do |outfile|
|
28
|
+
S3Object.stream(object_name, bucket_name) do |chunk|
|
29
|
+
outfile.write chunk
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/turbo/key.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Turbo
|
2
|
+
class Key
|
3
|
+
|
4
|
+
@@settings = nil
|
5
|
+
@@file = File.dirname(__FILE__) + "/../../config/aws.yml"
|
6
|
+
|
7
|
+
def self.configuration=(location)
|
8
|
+
@@file = location
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configuration
|
12
|
+
@@file
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.access
|
16
|
+
settings['access_key_id']
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.secret
|
20
|
+
settings['secret_access_key']
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.settings
|
26
|
+
if @@settings.nil?
|
27
|
+
@@settings = load_settings
|
28
|
+
end
|
29
|
+
@@settings
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.load_settings
|
33
|
+
YAML.load(File.open("#{configuration}"))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/turbo/queue.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Turbo
|
2
|
+
class Queue
|
3
|
+
|
4
|
+
attr_accessor :name, :queue
|
5
|
+
|
6
|
+
def initialize(queue_name)
|
7
|
+
self.name = queue_name
|
8
|
+
self.queue = find_or_create(queue_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def send(message)
|
12
|
+
self.queue.send_message(message)
|
13
|
+
end
|
14
|
+
|
15
|
+
def messages
|
16
|
+
all_messages = []
|
17
|
+
self.queue.receive_messages.each do |message|
|
18
|
+
all_messages << Turbo::Message.new(:with => message)
|
19
|
+
end
|
20
|
+
all_messages
|
21
|
+
end
|
22
|
+
|
23
|
+
def messages?
|
24
|
+
self.queue.size == 0 ? false : true
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def sqs
|
30
|
+
RightAws::SqsGen2.new(Key.access, Key.secret)
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_or_create(queue_name)
|
34
|
+
RightAws::SqsGen2::Queue.create(sqs, queue_name, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/turbo/setter.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Turbo
|
2
|
+
class Setter
|
3
|
+
|
4
|
+
include AWS::S3
|
5
|
+
|
6
|
+
def self.to_s3(options)
|
7
|
+
|
8
|
+
bucket_name = options[:bucket]
|
9
|
+
file = options[:from]
|
10
|
+
object_name = options[:named]
|
11
|
+
|
12
|
+
settings = {}
|
13
|
+
|
14
|
+
settings[:access_key_id] = Turbo::Key.access
|
15
|
+
settings[:secret_access_key] = Turbo::Key.secret
|
16
|
+
|
17
|
+
puts "Establishing connection to S3"
|
18
|
+
Base.establish_connection!(
|
19
|
+
:access_key_id => settings[:access_key_id],
|
20
|
+
:secret_access_key => settings[:secret_access_key]
|
21
|
+
)
|
22
|
+
|
23
|
+
begin
|
24
|
+
bucket = Bucket.find(bucket_name)
|
25
|
+
rescue NoSuchBucket
|
26
|
+
bucket = Bucket.create(bucket_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
bucket = Bucket.find(bucket_name)
|
30
|
+
|
31
|
+
puts "Current bucket store: #{bucket.objects.size}"
|
32
|
+
puts "Uploading: #{file} as #{object_name}"
|
33
|
+
S3Object.store(object_name, open(file), bucket_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/turbo.rb
ADDED
data/post_install.txt
ADDED
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/launch-pad.rb'}"
|
9
|
+
puts "Loading launch-pad gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
global
|
2
|
+
log 127.0.0.1 local0
|
3
|
+
log 127.0.0.1 local1 notice
|
4
|
+
#log loghost local0 info
|
5
|
+
maxconn 4096
|
6
|
+
#debug
|
7
|
+
#quiet
|
8
|
+
user haproxy
|
9
|
+
group haproxy
|
10
|
+
|
11
|
+
defaults
|
12
|
+
log global
|
13
|
+
mode http
|
14
|
+
option httplog
|
15
|
+
option dontlognull
|
16
|
+
retries 3
|
17
|
+
redispatch
|
18
|
+
maxconn 2000
|
19
|
+
contimeout 5000
|
20
|
+
clitimeout 50000
|
21
|
+
srvtimeout 50000
|
22
|
+
|
23
|
+
listen api-rewrite api.galaxyzoo.org:80
|
24
|
+
cookie SERVERID rewrite
|
25
|
+
balance roundrobin
|
26
|
+
server api_http_0 node_1.ec2.amazonaws.com cookie app1inst1 check inter 2000 rise 2 fall 5
|
27
|
+
server api_http_1 node_2.ec2.amazonaws.com cookie app1inst1 check inter 2000 rise 2 fall 5
|
28
|
+
|
29
|
+
|
30
|
+
listen api-ssl-rewrite api.galaxyzoo.org:443
|
31
|
+
mode tcp
|
32
|
+
cookie SERVERID rewrite
|
33
|
+
balance roundrobin
|
34
|
+
server api_ssl_0 node_1.ec2.amazonaws.com cookie app1inst1 check inter 2000 rise 2 fall 5
|
35
|
+
server api_ssl_1 node_2.ec2.amazonaws.com cookie app1inst1 check inter 2000 rise 2 fall 5
|
@@ -0,0 +1,32 @@
|
|
1
|
+
global
|
2
|
+
log 127.0.0.1 local0
|
3
|
+
log 127.0.0.1 local1 notice
|
4
|
+
#log loghost local0 info
|
5
|
+
maxconn 4096
|
6
|
+
#debug
|
7
|
+
#quiet
|
8
|
+
user haproxy
|
9
|
+
group haproxy
|
10
|
+
|
11
|
+
defaults
|
12
|
+
log global
|
13
|
+
mode http
|
14
|
+
option httplog
|
15
|
+
option dontlognull
|
16
|
+
retries 3
|
17
|
+
redispatch
|
18
|
+
maxconn 2000
|
19
|
+
contimeout 5000
|
20
|
+
clitimeout 50000
|
21
|
+
srvtimeout 50000
|
22
|
+
|
23
|
+
listen api-rewrite api.galaxyzoo.org:80
|
24
|
+
cookie SERVERID rewrite
|
25
|
+
balance roundrobin
|
26
|
+
<%= servers_for :api, :type => "http" %>
|
27
|
+
|
28
|
+
listen api-ssl-rewrite api.galaxyzoo.org:443
|
29
|
+
mode tcp
|
30
|
+
cookie SERVERID rewrite
|
31
|
+
balance roundrobin
|
32
|
+
<%= servers_for :api, :type => "ssl" %>
|
data/test/files/keys.yml
ADDED
data/test/haproxy.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/test_helper"
|
2
|
+
|
3
|
+
class HaproxyTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include LaunchPad
|
6
|
+
|
7
|
+
def setup
|
8
|
+
ActiveRecord::Base.establish_connection({
|
9
|
+
:adapter => "sqlite3",
|
10
|
+
:dbfile => "#{File.dirname(__FILE__)}/db/test.sqlite"
|
11
|
+
})
|
12
|
+
|
13
|
+
Node.delete_all
|
14
|
+
Node.create :name => "node_1.ec2.amazonaws.com", :role => "api"
|
15
|
+
Node.create :name => "node_2.ec2.amazonaws.com", :role => "api"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_rebuild_config
|
20
|
+
command = Haproxy.new(%q{register: haproxy})
|
21
|
+
command.activate
|
22
|
+
command.rebuild_config :with_templates => "#{File.dirname(__FILE__)}/files/", :to => "#{File.dirname(__FILE__)}/tmp/haproxy_test.conf"
|
23
|
+
assert_file_equal "#{File.dirname(__FILE__)}/expected/haproxy.conf", "#{File.dirname(__FILE__)}/tmp/haproxy_test.conf"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/test/key_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class KeyTest < Test::Unit::TestCase
|
2
|
+
|
3
|
+
include Turbo
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Key.configuration = File.dirname(__FILE__) + "/files/keys.yml"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_configuration_file
|
10
|
+
assert_equal "./test/files/keys.yml", Key.configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_access_key
|
14
|
+
assert_equal "your-access-key", Key.access
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_secret_key
|
18
|
+
assert_equal "your-secret-key", Key.secret
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/parser_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/test_helper"
|
2
|
+
|
3
|
+
class ParserTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include LaunchPad
|
6
|
+
|
7
|
+
def test_yaml
|
8
|
+
message = %q{
|
9
|
+
register: haproxy
|
10
|
+
}
|
11
|
+
command = Parser.parse(message)
|
12
|
+
assert_kind_of Haproxy, command
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_exception
|
16
|
+
|
17
|
+
message = %q{
|
18
|
+
register: nonsense
|
19
|
+
}
|
20
|
+
|
21
|
+
assert_raise UndefinedRegistrationException do
|
22
|
+
command = Parser.parse(message)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/runner.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/turbo'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/launch-pad'
|
4
|
+
|
5
|
+
module Test
|
6
|
+
module Unit
|
7
|
+
class TestCase
|
8
|
+
|
9
|
+
def assert_file_equal(file1, file2)
|
10
|
+
file1_contents = File.new(file1).read
|
11
|
+
file2_contents = File.new(file2).read
|
12
|
+
assert_equal file1_contents, file2_contents
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mza-launch-pad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Wood
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-15 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email:
|
37
|
+
- matt.j.wood@gmail.com
|
38
|
+
executables:
|
39
|
+
- launch-pad
|
40
|
+
- lp-monitor
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- Manifest.txt
|
45
|
+
- history.txt
|
46
|
+
- post_install.txt
|
47
|
+
files:
|
48
|
+
- Manifest.txt
|
49
|
+
- README
|
50
|
+
- Rakefile
|
51
|
+
- bin/launch-pad
|
52
|
+
- bin/lp-monitor
|
53
|
+
- config/aws.yml
|
54
|
+
- config/aws_default.yml
|
55
|
+
- examples/align_control.rb
|
56
|
+
- examples/dispatch.rb
|
57
|
+
- examples/monitor.rb
|
58
|
+
- examples/queue.rb
|
59
|
+
- examples/retrieve.rb
|
60
|
+
- examples/set.rb
|
61
|
+
- history.txt
|
62
|
+
- launch-pad.gemspec
|
63
|
+
- lib/launch-pad.rb
|
64
|
+
- lib/launch-pad/command.rb
|
65
|
+
- lib/launch-pad/command/haproxy.rb
|
66
|
+
- lib/launch-pad/command/host.rb
|
67
|
+
- lib/launch-pad/exception/undefined_registration_exception.rb
|
68
|
+
- lib/launch-pad/models/node.rb
|
69
|
+
- lib/launch-pad/parser.rb
|
70
|
+
- lib/migrations/create_nodes.rb
|
71
|
+
- lib/turbo.rb
|
72
|
+
- lib/turbo/getter.rb
|
73
|
+
- lib/turbo/key.rb
|
74
|
+
- lib/turbo/message.rb
|
75
|
+
- lib/turbo/queue.rb
|
76
|
+
- lib/turbo/setter.rb
|
77
|
+
- post_install.txt
|
78
|
+
- script/console
|
79
|
+
- script/destroy
|
80
|
+
- script/generate
|
81
|
+
- test/expected/haproxy.conf
|
82
|
+
- test/files/haproxy.erb
|
83
|
+
- test/files/keys.yml
|
84
|
+
- test/haproxy.rb
|
85
|
+
- test/key_test.rb
|
86
|
+
- test/parser_test.rb
|
87
|
+
- test/runner.rb
|
88
|
+
- test/test_helper.rb
|
89
|
+
has_rdoc: true
|
90
|
+
homepage:
|
91
|
+
post_install_message: post_install.txt
|
92
|
+
rdoc_options:
|
93
|
+
- --main
|
94
|
+
- README
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
version:
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
version:
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project: launch-pad
|
112
|
+
rubygems_version: 1.2.0
|
113
|
+
signing_key:
|
114
|
+
specification_version: 2
|
115
|
+
summary: Something summary
|
116
|
+
test_files:
|
117
|
+
- test/test_helper.rb
|