lib/flapjack/coordinator.rb in flapjack-0.7.18 vs lib/flapjack/coordinator.rb in flapjack-0.7.19

- old
+ new

@@ -1,39 +1,29 @@ #!/usr/bin/env ruby require 'eventmachine' require 'em-synchrony' +require 'syslog' + require 'flapjack/configuration' require 'flapjack/patches' -require 'flapjack/executive' require 'flapjack/redis_pool' +require 'flapjack/logger' require 'flapjack/pikelet' -require 'flapjack/executive' module Flapjack class Coordinator def initialize(config) @config = config @redis_options = config.for_redis @pikelets = [] - # TODO convert this to use flapjack-logger - logger_name = "flapjack-coordinator" - @logger = Log4r::Logger.new(logger_name) - - formatter = Log4r::PatternFormatter.new(:pattern => "%d [%l] :: #{logger_name} :: %m", - :date_pattern => "%Y-%m-%dT%H:%M:%S%z") - - [Log4r::StdoutOutputter, Log4r::SyslogOutputter].each do |outp_klass| - outp = outp_klass.new(logger_name) - outp.formatter = formatter - @logger.add(outp) - end + @logger = Flapjack::Logger.new("flapjack-coordinator") end def start(options = {}) @boot_time = Time.now @@ -45,10 +35,11 @@ def stop return if @stopping @stopping = true remove_pikelets(@pikelets, :shutdown => true) + # Syslog.close if Syslog.opened? # TODO revisit in threading branch end # NB: global config options (e.g. daemonize, pidfile, # logfile, redis options) won't be checked on reload. # should we do a full restart if some of these change? @@ -171,16 +162,35 @@ end }.resume end def pikelets(config_env) - return {} unless config_env - exec_cfg = config_env.has_key?('executive') && config_env['executive']['enabled'] ? - {'executive' => config_env['executive']} : - {} - return exec_cfg unless config_env && config_env['gateways'] && + config = {} + return config unless config_env + + # backwards-compatible with config file for previous 'executive' pikelet + exec_cfg = nil + if config_env.has_key?('executive') && config_env['executive']['enabled'] + exec_cfg = config_env['executive'] + end + ['processor', 'notifier'].each do |k| + if exec_cfg + if config_env.has_key?(k) + # need to allow for new config fields to override old settings if both present + merged = exec_cfg.merge(config_env[k]) + config.update(k => merged) if merged['enabled'] + else + config.update(k => exec_cfg) + end + else + next unless (config_env.has_key?(k) && config_env[k]['enabled']) + config.update(k => config_env[k]) + end + end + + return config unless config_env && config_env['gateways'] && !config_env['gateways'].nil? - exec_cfg.merge( config_env['gateways'].select {|k, v| + config.merge( config_env['gateways'].select {|k, v| Flapjack::Pikelet.is_pikelet?(k) && v['enabled'] } ) end end