Commit 40c4c205 authored by John E. Vincent's avatar John E. Vincent

yeah I forgot all these

parent 78e22223
......@@ -44,10 +44,11 @@ task :sample, :redis_url do |t, args|
Ohm::connect(:url => args.redis_url)
Ohm::redis.flushdb
puts "Creating watchers..."
Noah::Watcher.create :endpoint => "http://localhost:3000/webhook", :pattern => "//noah/application"
Noah::Watcher.create :endpoint => "http://localhost:3001/webhook", :pattern => "//noah/configuration"
Noah::Watcher.create :endpoint => "http://localhost:3002/webhook", :pattern => "//noah/host"
Noah::Watcher.create :endpoint => "http://localhost:3003/webhook", :pattern => "//noah/service"
Noah::Watcher.create :endpoint => "dummy://applications", :pattern => "//noah/applications"
Noah::Watcher.create :endpoint => "dummy://configurations", :pattern => "//noah/configurations"
Noah::Watcher.create :endpoint => "dummy://hosts", :pattern => "//noah/hosts"
Noah::Watcher.create :endpoint => "dummy://services", :pattern => "//noah/services"
Noah::Watcher.create :endpoint => "dummy://ephemerals", :pattern => "//noah/ephemerals"
puts "Creating Host entry for 'localhost'"
h = Noah::Host.create(:name => 'localhost', :status => "up")
if h.save
......
......@@ -20,8 +20,9 @@ rescue LoadError => e
exit
end
#LOGGER = Logger.new('rundeck-test.log')
LOGGER = Logger.new(STDOUT)
Noah::Log.logger = Logger.new(STDOUT)
LOGGER = Noah::Log.logger
LOGGER.progname = __FILE__
EventMachine.run do
EM.error_handler do |e|
......@@ -38,7 +39,7 @@ EventMachine.run do
r = EventMachine::Hiredis::Client.connect
r.errback{|x| logger.error("Unable to connect to redis: #{x}")}
logger.debug("Starting up")
r.psubscribe("//noah/*")
r.psubscribe("*")
r.on(:pmessage) do |pattern, event, message|
noah.reread_watchers if event =~ /^\/\/noah\/watcher\/.*/
noah.broker("#{event}|#{message}") unless noah.watchers == 0
......
......@@ -16,6 +16,7 @@ require 'haml'
require 'yaml'
require 'sinatra/base'
require File.join(File.dirname(__FILE__), 'noah', 'log')
require File.join(File.dirname(__FILE__), 'noah', 'custom_watcher')
require File.join(File.dirname(__FILE__), 'noah','validations')
require File.join(File.dirname(__FILE__), 'noah','models')
......
......@@ -13,7 +13,8 @@ module Noah
@@agents = Noah::Watchers.agents
def initialize
@logger = LOGGER
@logger = Noah::Log.logger
@logger.progname = self.class.name
@logger.debug("Initializing with #{@@watchers.size} registered watches")
@logger.debug("#{@@agents} agents registered")
if EventMachine.reactor_running?
......
require 'logger'
module Noah::Agents
module Base
class << self
class <<self
PREFIX = "base"
NAME = "base-agent"
end
......@@ -16,6 +14,11 @@ module Noah::Agents
module AgentClassMethods
def logger
Noah::Log.logger.progname = self.name
Noah::Log.logger
end
def find_watched_patterns!(watchlist)
watched_patterns = []
watchlist.find_all do |w|
......@@ -25,5 +28,14 @@ module Noah::Agents
watched_patterns
end
def notify(event, message, watch_list)
logger.info("Worker Initiated")
logger.debug("got event - #{event}")
watched_patterns = find_watched_patterns!(watch_list)
matches = watched_patterns.find_all {|w| event =~ /^#{w}/}
logger.debug("Found #{matches.size} matches for #{event}")
self.callback!(matches, message)
end
end
end
......@@ -5,19 +5,13 @@ module Noah::Agents
include Noah::Agents::Base
PREFIX = "dummy://"
NAME = "dummy"
NAME = self.name
def self.notify(event, message, watch_list)
logger = LOGGER
logger.info("#{NAME}: Worker initiated")
logger.debug("#{NAME}: got event - #{event}")
watched_patterns = find_watched_patterns!(watch_list)
matches = watched_patterns.find_all {|w| event =~ /^#{w}/}
logger.debug("#{NAME}: Found #{matches.size} matches for #{event}")
def self.callback!(matches, message)
EM::Iterator.new(matches).each do |watch, iter|
p, ep = watch.split("|")
logger.info("#{NAME}: Sending message to: #{ep} for pattern: #{p}")
logger.debug("#{NAME}: message received: #{message}")
logger.info("Sending message to: #{ep} for pattern: #{p}")
logger.debug("message received: #{message}")
iter.next
end
end
......
......@@ -5,24 +5,18 @@ module Noah::Agents
include Noah::Agents::Base
PREFIX = "http://"
NAME = "http"
NAME = self.name
def self.notify(event, message, watch_list)
logger = LOGGER
logger.info("#{NAME}: Worker initiated")
logger.debug("#{NAME}: got event - #{event}")
watched_patterns = find_watched_patterns!(watch_list)
matches = watched_patterns.find_all {|w| event =~ /^#{w}/}
logger.debug("#{NAME}: Found #{matches.size} matches for #{event}")
def self.callback!(matches, message)
EM::Iterator.new(matches, 100).each do |watch, iter|
p, ep = watch.split("|")
logger.info("#{NAME}: Sending message to (#{ep}) for pattern (#{p})")
logger.info("Sending message to (#{ep}) for pattern (#{p})")
http = EM::HttpRequest.new(ep, :connection_timeout => 2, :inactivity_timeout => 4).post :body => message
http.callback {
logger.info("#{NAME}: Message posted to #{ep} successfully")
logger.info("Message posted to #{ep} successfully")
}
http.errback {
logger.error("#{NAME}: Something went wrong with #{ep}")
logger.error("Something went wrong with #{ep}")
}
iter.next
end
......
......@@ -67,7 +67,7 @@ module Noah
protected
def patternize_me
name.match(/^\//) ? n = name.gsub(/^\//, '') : n = name
"//noah/#{self.class_to_lower}/#{n}"
"//noah/#{self.class_to_lower}s/#{n}"
end
def stash_name
......
......@@ -14,6 +14,11 @@ RSpec.configure do |config|
config.after(:all, :populate_sample_data => true) {Ohm::redis.flushdb }
config.before(:all, :populate_sample_data => true) do
Ohm::redis.flushdb
Noah::Watcher.create :endpoint => "dummy://applications", :pattern => "//noah/applications"
Noah::Watcher.create :endpoint => "dummy://configurations", :pattern => "//noah/configurations"
Noah::Watcher.create :endpoint => "dummy://hosts", :pattern => "//noah/hosts"
Noah::Watcher.create :endpoint => "dummy://services", :pattern => "//noah/services"
Noah::Watcher.create :endpoint => "dummy://ephemerals", :pattern => "//noah/ephemerals"
h = Noah::Host.create(:name => 'localhost', :status => "up")
if h.save
%w[redis noah].each do |service|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment