Skip to content

Commit

Permalink
ansible_tower event catcher
Browse files Browse the repository at this point in the history
  • Loading branch information
durandom committed Jan 13, 2017
1 parent e938b1d commit baed4bf
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher < ManageIQ::Providers::BaseManager::EventCatcher
require_nested :Runner
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Runner < ManageIQ::Providers::BaseManager::EventCatcher::Runner
def stop_event_monitor
event_monitor_handle.stop
end

def monitor_events
event_monitor_handle.start
event_monitor_handle.poll do |event|
_log.debug { "#{log_prefix} Received event #{event.id}" }
event_monitor_running
@queue.enq event
end
ensure
stop_event_monitor
end

def queue_event(event)
_log.info "#{log_prefix} Caught event [#{event.id}]"
event_hash = ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventParser.event_to_hash(event, @cfg[:ems_id])
EmsEvent.add_queue('add', @cfg[:ems_id], event_hash)
end

private

def event_monitor_handle
@event_monitor_handle ||= begin
ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Stream.new(@ems)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Stream
class ProviderUnreachable < ManageIQ::Providers::BaseManager::EventCatcher::Runner::TemporaryFailure
end

def initialize(ems)
@ems = ems
@last_activity = nil
@stop_polling = false
end

def start
@stop_polling = false
end

def stop
@stop_polling = true
end

def poll
@ems.with_provider_connection do |ansible|
catch(:stop_polling) do
begin
loop do
ansible.api.activity_stream.all(filter).each do |activity|
throw :stop_polling if @stop_polling
yield activity
@last_activity = activity
end
sleep(20)
end
rescue => exception
raise ProviderUnreachable, exception.message
end
end
end
end

private

def filter
{
:order_by => 'timestamp',
:timestamp__gt => @last_activity ? @last_activity.timestamp : 1.minute.ago.to_s(:db)
}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventParser
def self.event_to_hash(event, ems_id)
{
:event_type => event.operation,
:source => "ANSIBLE_TOWER",
:message => event.changes.to_s,
:timestamp => event.timestamp,
:full_data => event.to_h,
:ems_id => ems_id
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module MiqServer::WorkerManagement::Monitor::ClassNames
ManageIQ::Providers::Vmware::InfraManager::RefreshWorker
ManageIQ::Providers::Nuage::NetworkManager::RefreshWorker
ManageIQ::Providers::Amazon::CloudManager::EventCatcher
ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher
ManageIQ::Providers::Azure::CloudManager::EventCatcher
ManageIQ::Providers::Hawkular::MiddlewareManager::EventCatcher
ManageIQ::Providers::Google::CloudManager::EventCatcher
Expand Down Expand Up @@ -130,6 +131,7 @@ module MiqServer::WorkerManagement::Monitor::ClassNames
ManageIQ::Providers::StorageManager::CinderManager::EventCatcher
ManageIQ::Providers::Amazon::CloudManager::EventCatcher
ManageIQ::Providers::Azure::CloudManager::EventCatcher
ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher
ManageIQ::Providers::Hawkular::MiddlewareManager::EventCatcher
ManageIQ::Providers::Google::CloudManager::EventCatcher
ManageIQ::Providers::Kubernetes::ContainerManager::EventCatcher
Expand Down

0 comments on commit baed4bf

Please sign in to comment.