(QENG-1906) Refactor initialize to allow config passing

Prior to this commit, several pieces of vmpooler performed configuration
and initialization steps within 'initialize'. This made it difficult to
pass in mock objects for testing purposes.

This commit performs a single configuration and passes the results to
the various pieces of vmpooler.
This commit is contained in:
Colin 2015-03-27 13:37:52 -07:00
parent 34fd054a48
commit 1408f35867
7 changed files with 141 additions and 109 deletions

View file

@ -5,10 +5,27 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rubygems' unless defined?(Gem)
require 'lib/vmpooler'
Thread.new { Vmpooler::API.new.execute! }
Thread.new { Vmpooler::Janitor.new.execute! }
Thread.new { Vmpooler::PoolManager.new.execute! }
config = Vmpooler.config
redis_host = config[:redis]['server']
redis_ttl = config[:redis]['data_ttl']
logger_file = config[:config]['logfile']
graphite = defined? config[:graphite]['server'] ? config[:graphite]['server'] : nil
api = Thread.new {
thr = Vmpooler::API.new
thr.helpers.configure(config, Vmpooler.new_redis(redis_host))
thr.helpers.execute!
}
janitor = Thread.new {
Vmpooler::Janitor.new(Vmpooler.new_logger(logger_file), Vmpooler.new_redis(redis_host), redis_ttl).execute!
}
manager = Thread.new {
Vmpooler::PoolManager.new(config,
config[:pools],
Vmpooler.new_logger(logger_file),
Vmpooler.new_redis(redis_host),
Vmpooler.new_graphite(graphite)).execute!
}
[api, janitor, manager].each { |t| t.join }
loop do
sleep(10)
end